@cuylabs/agent-physical-capx 5.0.2 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,39 +1,63 @@
1
1
  # @cuylabs/agent-physical-capx
2
2
 
3
- CaP-X adapter for `@cuylabs/agent-physical`.
3
+ `agents-ts` adapter for CaP-X Code-as-Policies sessions.
4
4
 
5
- CaP-X stays the Python robotics runtime. `capx-agent-runtime` runs in the CaP-X
6
- Python environment and owns the CaP-X checkout, YAML config, simulator/API
7
- servers, and policy-code execution. This TypeScript package is the `agents-ts`
8
- client: it turns that runtime service into `agent-core` tools and an
9
- `@cuylabs/agent-physical` session.
5
+ [CaP-X](https://github.com/capgym/cap-x) is the Python robotics runtime.
6
+ The [CaP-X Agent Runtime](https://github.com/cuylabs-ai/capx-agent-runtime)
7
+ runs next to CaP-X and exposes one selected CaP-X task over HTTP. This package
8
+ connects `agent-core` to that runtime service and turns the live CaP-X session
9
+ into typed physical tools.
10
10
 
11
- ## Boundary
11
+ ```text
12
+ agent-core model loop
13
+ -> @cuylabs/agent-physical-capx tools
14
+ -> capx-agent-runtime HTTP server
15
+ -> CaP-X Python runtime, selected YAML config, simulator or robot
16
+ ```
12
17
 
13
- Use `capx-agent-runtime` directly when you want any agent harness to call CaP-X
14
- over HTTP or MCP. Use this package when your harness is `agents-ts` and you want
15
- CaP-X exposed as typed physical tools.
18
+ Use `capx-agent-runtime` directly when an agent harness should call CaP-X over
19
+ HTTP or MCP. Use this package when the harness is `agents-ts`.
16
20
 
17
- The TypeScript adapter does not know the CaP-X checkout path or YAML config.
18
- Those belong to the Python runtime service because that process owns the
19
- simulator packages, CUDA dependencies, model assets, perception services, and
20
- CaP-X environment. Start the runtime service first:
21
+ ## Ownership Boundary
21
22
 
22
- ```bash
23
- cd /path/to/cap-x
24
- uv run --no-sync --active capx-agent-runtime serve \
25
- --repo-path "$(pwd)" \
26
- --config-path env_configs/cube_stack/franka_robosuite_cube_stack.yaml \
27
- --host 127.0.0.1 \
28
- --port 8210
29
- ```
23
+ The runtime server owns the robotics side:
24
+
25
+ - CaP-X clone and selected YAML config.
26
+ - Simulator or robot dependencies.
27
+ - CUDA, perception services, and model assets.
28
+ - Output directory and skill-library path.
29
+ - Execution of submitted Python Code-as-Policies programs.
30
+
31
+ This TypeScript package owns the `agents-ts` side:
32
+
33
+ - `CapxSession`, which maps to one live runtime session.
34
+ - `capx_*` tools for `agent-core`.
35
+ - Approval-aware policy-code execution through `agent-core`.
36
+ - Mapping observations, rendered frames, turn history, and artifacts into
37
+ model-usable context.
38
+
39
+ ## Quick Start
30
40
 
31
- Then point TypeScript at the service:
41
+ First start the
42
+ [CaP-X Agent Runtime](https://github.com/cuylabs-ai/capx-agent-runtime) on the
43
+ machine that has CaP-X, CUDA, and the selected simulator or robot stack
44
+ installed. The runtime docs cover the workstation setup, server command,
45
+ config selection, Docker path, and validation steps:
46
+
47
+ 1. Prepare the GPU workstation with
48
+ [Workstation Setup](https://github.com/cuylabs-ai/capx-agent-runtime/blob/main/docs/workstation-setup.md).
49
+ 2. Start and validate the runtime server with
50
+ [Runtime Server](https://github.com/cuylabs-ai/capx-agent-runtime/blob/main/docs/runtime-server.md).
51
+
52
+ Then install the TypeScript packages in your `agents-ts` application and point
53
+ this adapter at the running runtime server:
32
54
 
33
55
  ```bash
34
56
  npm install @cuylabs/agent-core @cuylabs/agent-physical @cuylabs/agent-physical-capx
35
57
  ```
36
58
 
59
+ Create an agent that connects to the running runtime service:
60
+
37
61
  ```ts
38
62
  import { createCapxAgent } from "@cuylabs/agent-physical-capx";
39
63
 
@@ -50,15 +74,39 @@ const { agent, session } = await createCapxAgent({
50
74
  });
51
75
  ```
52
76
 
53
- `toolExecutionMode: "plan"` does not mean the model only writes a textual
54
- plan. It means `agent-core` asks the model for tool calls, then dispatches
55
- those tools itself. That keeps approval, serial execution of unsafe tools, and
56
- tool-result persistence under the harness instead of letting the AI SDK execute
57
- tools inline. The model can still reason normally in either mode.
77
+ `startSession: true` creates one live CaP-X runtime session. Keep using that
78
+ same session across observe, execute, observe turns unless the host decides to
79
+ reset or stop it.
80
+
81
+ `toolExecutionMode: "plan"` is an `agent-core` dispatch setting. It does not
82
+ make the model write only a textual plan. The model can still call tools, but
83
+ `agent-core` receives those planned tool calls first, applies approval and
84
+ scheduling policy, executes the approved tools, then records the tool results
85
+ for the next model step.
86
+
87
+ ## Runtime Loop
88
+
89
+ The external agent owns reasoning and code generation. CaP-X owns robotics
90
+ execution.
91
+
92
+ ```text
93
+ start CapxSession
94
+ -> capx_observe returns task prompt, state, frame, and codeContext
95
+ -> agent writes one Python policy-code step
96
+ -> capx_run_policy_code submits that code to the live runtime session
97
+ -> agent observes the result, reward, artifacts, and next frame
98
+ -> host or agent continues, reports completion, resets, or stops
99
+ ```
100
+
101
+ `capx_run_policy_code` is the tool that performs physical work. It can mutate a
102
+ simulator or move hardware, so it should stay approval-gated and dispatched by
103
+ the host harness.
58
104
 
59
105
  ## Tools
60
106
 
61
- The generated tools are prefixed with `capx_`:
107
+ This package generates the `agent-core` tools below. They are the
108
+ TypeScript-facing tool surface for a `CapxSession`; internally they call the
109
+ `capx-agent-runtime` HTTP API.
62
110
 
63
111
  - `capx_status`
64
112
  - `capx_observe`
@@ -67,88 +115,79 @@ The generated tools are prefixed with `capx_`:
67
115
  - `capx_run_policy_code` when `enablePolicyCodeExecution: true`
68
116
  - `capx_turn_history`
69
117
 
70
- `agent-core` owns the loop: observe the CaP-X prompt/state, write Python policy
71
- code, execute it through `capx_run_policy_code`, inspect reward/stdout/stderr
72
- and artifacts, then continue, reset, or stop. CaP-X owns YAML loading,
73
- perception servers, Python helper APIs, simulator/robot integration, rewards,
74
- videos, and task completion.
118
+ The raw runtime server exposes HTTP endpoints such as `/sessions`,
119
+ `/sessions/{id}/observe`, `/sessions/{id}/execute-code`,
120
+ `/sessions/{id}/artifacts`, and `/sessions/{id}/turns`. Its optional MCP
121
+ wrapper has its own MCP-native tool names. The list above is the smaller
122
+ `agents-ts` default surface.
75
123
 
76
- One `CapxSession` maps to one live `capx-agent-runtime` session. The agent
77
- should keep using that same session across observe/run/observe turns. Reset and
78
- new-session creation are host/runtime control decisions, not part of the
79
- default model-facing tool set.
124
+ The default model-facing surface is intentionally small. It gives the agent
125
+ enough context to write better Code-as-Policies Python without exposing every
126
+ runtime operation as a separate robot-action tool.
80
127
 
81
- ## Mental Model
128
+ ## CaP-X Skills
82
129
 
83
- Think of this package as the `agents-ts` client for CaP-X Code-as-Policies:
130
+ There are two different skill concepts:
84
131
 
85
- 1. `capx-agent-runtime` starts the CaP-X environment from a server-owned YAML
86
- config.
87
- 2. `CapxSession.start()` creates one live runtime session over HTTP.
88
- 3. `capx_observe` gives the agent the task prompt, current state, rendered
89
- frame when requested, last-step result, and `codeContext`.
90
- 4. The agent writes Python policy code using that observed CaP-X context.
91
- 5. `capx_run_policy_code` submits the selected Python code to the same live
92
- runtime session.
93
- 6. The agent observes again and either continues, reports completion, or asks
94
- the host to reset/stop when appropriate.
132
+ - `agent-core` skills are `SKILL.md` instruction packs that teach the model how
133
+ to use the CaP-X tools.
134
+ - CaP-X skills are Python helper functions in the runtime skill library.
95
135
 
96
- ## Skills
136
+ The default agent tool surface exposes CaP-X skill-library information through
137
+ `capx_observe` as policy-code context. Programmatic clients can still use
138
+ `CapxLiveRuntime` to inspect, extract, or inject runtime skills deliberately
139
+ with host approval.
97
140
 
98
- `agent-core` skills are `SKILL.md` instruction packs. CaP-X skills are Python
99
- helper functions in the runtime. The default agent tool surface keeps those as
100
- policy-code context returned by `capx_observe`, not as separate robot tools.
101
- Programmatic clients can still call the runtime skill-library endpoints through
102
- `CapxLiveRuntime` when they intentionally want to inspect source, extract
103
- helpers, or inject promoted functions with host approval.
141
+ ## Examples
104
142
 
105
- ## Setup
143
+ The runnable examples live in [examples/README.md](./examples/README.md).
144
+ They show the service-first flow, environment variables, approval modes,
145
+ multi-turn solving, video artifacts, and recovery behavior.
106
146
 
107
- Install `capx-agent-runtime` into the same Python environment as CaP-X:
147
+ From a local `agents-ts` checkout:
108
148
 
109
149
  ```bash
110
- git clone --recurse-submodules https://github.com/capgym/cap-x.git cap-x
111
- cd cap-x
112
-
113
- uv venv .venv
114
- source .venv/bin/activate
115
- uv sync
116
- uv sync --extra robosuite
117
- uv pip install "capx-agent-runtime[server] @ git+https://github.com/cuylabs-ai/capx-agent-runtime.git@<runtime-commit-sha>"
150
+ cd packages/agent-physical-capx
151
+ cp examples/.env.example examples/.env
118
152
  ```
119
153
 
120
- Choose the CaP-X environment setup that matches the config passed to
121
- `capx-agent-runtime serve`: Robosuite, LIBERO-PRO, or BEHAVIOR/Isaac Sim.
154
+ Set at least:
122
155
 
123
- The runtime service also provides a console and schema:
156
+ ```bash
157
+ OPENAI_API_KEY=...
158
+ OPENAI_MODEL=gpt-4o-mini
159
+ CAPX_RUNTIME_SERVER_URL=http://127.0.0.1:8210
160
+ ```
124
161
 
125
- ```text
126
- http://127.0.0.1:8210/
127
- http://127.0.0.1:8210/schema/openapi.json
162
+ Run the single-turn solver in observe-only mode:
163
+
164
+ ```bash
165
+ npx tsx examples/01-capx-runtime-solver.ts
128
166
  ```
129
167
 
130
- ## Expected Cube-Stack Run
168
+ Allow policy-code execution in simulation:
131
169
 
132
- With the default `franka_robosuite_cube_stack.yaml` server config, the
133
- multi-turn example can complete the task through the live runtime path:
170
+ ```bash
171
+ CAPX_ALLOW_DESTRUCTIVE=1 \
172
+ npx tsx examples/01-capx-runtime-solver.ts
173
+ ```
174
+
175
+ Run the multi-turn autosolver:
134
176
 
135
177
  ```bash
136
- cd packages/agent-physical-capx
137
178
  CAPX_ALLOW_DESTRUCTIVE=1 \
138
179
  CAPX_POLICY_EXECUTION_RECORD_VIDEO=1 \
139
180
  CAPX_MAX_SOLVER_TURNS=6 \
140
- CAPX_RECOVER_ON_RUNTIME_ERROR=reset \
141
- CAPX_MAX_RUNTIME_RESETS=1 \
142
181
  CAPX_STOP_ON_EXIT=1 \
143
- pnpm exec tsx examples/02-capx-runtime-autosolve.ts
182
+ npx tsx examples/02-capx-runtime-autosolve.ts
144
183
  ```
145
184
 
146
- A successful result reports `executionOk=true`, `taskCompleted=true`,
147
- `reward=1`, `terminated=true`, and `sandboxRc=0`. The runtime writes the
148
- executed `code.py`, summary/log artifacts, rendered images, a per-turn MP4,
149
- and, after stop-on-exit, `video_session_combined.mp4`.
185
+ With the default cube-stack runtime config, a successful run reports
186
+ `executionOk=true`, `taskCompleted=true`, `reward=1`, `terminated=true`, and
187
+ `sandboxRc=0`. Generated code, logs, rendered images, and videos are listed
188
+ through `capx_artifacts` and the runtime console.
150
189
 
151
- ## Docs
190
+ ## More Docs
152
191
 
153
192
  - [docs/README.md](./docs/README.md)
154
193
  - [docs/how-it-works.md](./docs/how-it-works.md)
package/dist/agent.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Agent, createAgent } from '@cuylabs/agent-core';
2
2
  import { PhysicalSessionStartOptions } from '@cuylabs/agent-physical';
3
- import { i as CapxSession, m as createCapxPhysicalTools, a as CapxSessionOptions } from './session-BxaROlXW.js';
3
+ import { i as CapxSession, m as createCapxPhysicalTools, a as CapxSessionOptions } from './session-BwE260Mn.js';
4
4
  import '@cuylabs/agent-core/tool';
5
5
 
6
6
  type AgentConstructionConfig = Parameters<typeof createAgent>[0];
package/dist/agent.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  createCapxAgent,
4
4
  defaultCapxAgentApproval,
5
5
  defaultCapxAgentSystemPrompt
6
- } from "./chunk-C53NNB7T.js";
7
- import "./chunk-MYO63CWO.js";
6
+ } from "./chunk-F3JNO443.js";
7
+ import "./chunk-EBBHF633.js";
8
8
  export {
9
9
  capxAgentSkillRoot,
10
10
  createCapxAgent,
@@ -18,9 +18,6 @@ var DEFAULT_RUNTIME_REQUEST_TIMEOUT_MS = 1e6;
18
18
  function normalizeBaseUrl(value) {
19
19
  return value.replace(/\/+$/, "");
20
20
  }
21
- function resolveOutputDir(options, fallback) {
22
- return options.outputDir ?? fallback;
23
- }
24
21
  function withoutUndefined(value) {
25
22
  return Object.fromEntries(
26
23
  Object.entries(value).filter(([, item]) => item !== void 0)
@@ -249,12 +246,11 @@ function mapArtifactKind(kind) {
249
246
  }
250
247
 
251
248
  // src/live-runtime/index.ts
252
- var DEFAULT_OUTPUT_DIR = "outputs/agent-physical-capx-live";
253
249
  var CapxLiveRuntime = class {
254
250
  constructor(options, id = `capx-live-${randomUUID2()}`) {
255
251
  this.options = options;
256
252
  this.id = id;
257
- this.outputDir = resolveOutputDir(options, DEFAULT_OUTPUT_DIR);
253
+ this.outputDir = options.outputDir;
258
254
  this.#client = new CapxRuntimeHttpClient(options);
259
255
  }
260
256
  id;
@@ -432,12 +428,12 @@ var CapxLiveRuntime = class {
432
428
  }
433
429
  },
434
430
  metadata: {
435
- capx: {
431
+ capx: withoutUndefined({
436
432
  executionMode: "live-runtime",
437
433
  runtimeServer: "capx-agent-runtime",
438
434
  runtimeServerUrl: this.#client.baseUrl,
439
435
  outputDir: this.outputDir
440
- }
436
+ })
441
437
  }
442
438
  };
443
439
  }
@@ -866,4 +862,4 @@ export {
866
862
  createCapxSession,
867
863
  createCapxPhysicalTools
868
864
  };
869
- //# sourceMappingURL=chunk-MYO63CWO.js.map
865
+ //# sourceMappingURL=chunk-EBBHF633.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/session.ts","../src/live-runtime/index.ts","../src/live-runtime/http-client.ts","../src/live-runtime/utils.ts","../src/live-runtime/mappers.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { Tool } from \"@cuylabs/agent-core/tool\";\nimport {\n createPhysicalSessionTools,\n type PhysicalArtifact,\n type PhysicalCapability,\n type PhysicalExecutionRequest,\n type PhysicalExecutionTrace,\n type PhysicalListArtifactsOptions,\n type PhysicalObservation,\n type PhysicalObserveOptions,\n type PhysicalSession,\n type PhysicalSessionStartOptions,\n type PhysicalSessionState,\n type PhysicalToolOptions,\n} from \"@cuylabs/agent-physical\";\nimport { z } from \"zod\";\nimport { CapxLiveRuntime } from \"./live-runtime/index.js\";\nimport type { CapxSessionOptions } from \"./types.js\";\n\nconst RUNTIME_DEFAULT_TASK_ID = \"capx-agent-runtime-defaults\";\nconst RUNTIME_DEFAULT_TASK_DESCRIPTION =\n \"CaP-X config managed by capx-agent-runtime\";\n\nexport class CapxSession implements PhysicalSession {\n readonly id: string;\n readonly options: CapxSessionOptions;\n readonly capabilities?: readonly PhysicalCapability[];\n readonly executeCode?: (\n request: PhysicalExecutionRequest,\n ) => Promise<PhysicalExecutionTrace>;\n\n #status: PhysicalSessionState[\"status\"] = \"idle\";\n #startedAt: number | undefined;\n #updatedAt = Date.now();\n #message: string | undefined;\n #liveRuntime: CapxLiveRuntime | undefined;\n\n constructor(options: CapxSessionOptions, id = `capx-${randomUUID()}`) {\n this.options = {\n mode: \"runtime\",\n physicalMode: \"unknown\",\n policyExecutionMode: \"live-runtime\",\n ...options,\n };\n this.id = id;\n if (this.options.enablePolicyCodeExecution) {\n this.capabilities = [\n {\n name: \"capx_live_runtime_policy_code\",\n description:\n \"Execute supplied Python policy code through capx-agent-runtime in a live CaP-X environment.\",\n safety: {\n riskLevel: \"dangerous\",\n requiresApproval: true,\n requiresHumanPresence: this.options.physicalMode === \"hardware\",\n allowedModes:\n this.options.physicalMode === \"hardware\"\n ? [\"hardware\"]\n : [\"simulation\", \"hybrid\", \"unknown\"],\n },\n metadata: {\n capx: {\n executionMode: \"live-runtime\",\n activeProcessInjection: false,\n activeRuntimeSession: true,\n runtimeServer: \"capx-agent-runtime\",\n loopOwner: \"agent-core\",\n },\n },\n },\n ];\n this.executeCode = (request) => this.#executePolicyCode(request);\n }\n }\n\n #runtime(): CapxLiveRuntime {\n if (!this.#liveRuntime) {\n this.#liveRuntime = new CapxLiveRuntime(\n this.options,\n `${this.id}-runtime`,\n );\n }\n return this.#liveRuntime;\n }\n\n async #ensureLiveRuntime(): Promise<CapxLiveRuntime> {\n const runtime = this.#runtime();\n await runtime.start();\n return runtime;\n }\n\n async #executePolicyCode(\n request: PhysicalExecutionRequest,\n ): Promise<PhysicalExecutionTrace> {\n this.#status = \"running\";\n this.#updatedAt = Date.now();\n try {\n return await this.#runtime().execute(request);\n } finally {\n this.#status = \"ready\";\n this.#updatedAt = Date.now();\n }\n }\n\n getState(): PhysicalSessionState {\n return {\n sessionId: this.id,\n status: this.#status,\n task: this.options.task ?? {\n id: RUNTIME_DEFAULT_TASK_ID,\n description: RUNTIME_DEFAULT_TASK_DESCRIPTION,\n environment: \"capx\",\n mode: this.options.physicalMode,\n },\n mode: this.options.physicalMode,\n startedAt: this.#startedAt,\n updatedAt: this.#updatedAt,\n message: this.#message,\n metadata: {\n capx: {\n mode: this.options.mode,\n runtimeServerUrl: this.options.runtimeServerUrl,\n policyExecution: {\n enabled: this.options.enablePolicyCodeExecution ?? false,\n mode: this.options.enablePolicyCodeExecution\n ? \"live-runtime\"\n : \"none\",\n activeProcessInjection: false,\n activeRuntimeSession: true,\n runtimeServer: \"capx-agent-runtime\",\n loopOwner: \"agent-core\",\n },\n },\n },\n };\n }\n\n async start(\n options?: PhysicalSessionStartOptions,\n ): Promise<PhysicalSessionState> {\n if (this.#status === \"running\" || this.#status === \"ready\") {\n return this.getState();\n }\n\n this.#startedAt = Date.now();\n this.#updatedAt = this.#startedAt;\n this.#message = undefined;\n\n if (options?.task) {\n this.options.task = options.task;\n }\n\n this.#status = \"starting\";\n await this.#ensureLiveRuntime();\n this.#status = \"ready\";\n this.#message =\n \"Connected to capx-agent-runtime live session; agent-core owns the trial loop.\";\n this.#updatedAt = Date.now();\n return this.getState();\n }\n\n async observe(\n options: PhysicalObserveOptions = {},\n ): Promise<PhysicalObservation> {\n const items: PhysicalObservation[\"items\"] = [];\n const state = this.getState();\n if (this.#liveRuntime) {\n const observation = await this.#liveRuntime.observe();\n if (observation.taskPrompt) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:task-prompt\",\n text: observation.taskPrompt,\n timestamp: Date.now(),\n });\n }\n if (observation.multiTurnPrompt) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:multi-turn-prompt\",\n text: observation.multiTurnPrompt,\n timestamp: Date.now(),\n });\n }\n if (observation.fullPrompt) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:full-prompt\",\n text: JSON.stringify(observation.fullPrompt, null, 2),\n timestamp: Date.now(),\n });\n }\n if (observation.runtimeConfig) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:config\",\n text: JSON.stringify(observation.runtimeConfig, null, 2),\n timestamp: Date.now(),\n });\n }\n if (observation.codeContext) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:code-context\",\n text: JSON.stringify(observation.codeContext, null, 2),\n timestamp: Date.now(),\n });\n }\n if (observation.lastStep) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:last-step\",\n text: JSON.stringify(observation.lastStep, null, 2),\n timestamp: Date.now(),\n });\n }\n if (options.includeImages) {\n try {\n const frame = await this.#liveRuntime.renderFrame(\"main\");\n if (frame.dataUrl) {\n items.push({\n kind: \"rgb\",\n source: \"capx:runtime:main-camera\",\n dataUrl: frame.dataUrl,\n width: frame.width,\n height: frame.height,\n mimeType: frame.mimeType,\n frame: \"camera\",\n timestamp: frame.timestamp ? frame.timestamp * 1000 : Date.now(),\n });\n }\n } catch (error) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:render-error\",\n text: error instanceof Error ? error.message : String(error),\n timestamp: Date.now(),\n });\n }\n }\n } else {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:session\",\n text: \"No live CaP-X runtime session has started. The host application must call session.start() or createCapxAgent({ startSession: true }) before the agent can observe or solve the current CaP-X trial.\",\n timestamp: Date.now(),\n });\n }\n if (this.#liveRuntime?.stdoutTail) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:stdout\",\n text: this.#liveRuntime.stdoutTail,\n timestamp: this.#updatedAt,\n });\n }\n if (this.#liveRuntime?.stderrTail) {\n items.push({\n kind: \"text\",\n source: \"capx:runtime:stderr\",\n text: this.#liveRuntime.stderrTail,\n timestamp: this.#updatedAt,\n });\n }\n\n if (options.includeArtifacts && this.listArtifacts) {\n const artifacts = await this.listArtifacts({ limit: options.maxItems });\n for (const artifact of artifacts) {\n items.push({\n kind: \"artifact\",\n source: \"capx:outputs\",\n data: artifact,\n timestamp: this.#updatedAt,\n });\n }\n }\n\n const maxItems = options.maxItems ?? items.length;\n const selected = items.slice(0, maxItems);\n return {\n sessionId: this.id,\n status: state.status,\n taskId: state.task?.id,\n summary:\n selected.length === 0\n ? \"No CaP-X output has been captured yet.\"\n : `${selected.length} CaP-X observation item(s) captured.`,\n items: selected,\n metadata: state.metadata,\n timestamp: Date.now(),\n };\n }\n\n async reset(\n options?: PhysicalSessionStartOptions,\n ): Promise<PhysicalSessionState> {\n if (options?.task) {\n this.options.task = options.task;\n }\n this.#status = \"starting\";\n const runtime = await this.#ensureLiveRuntime();\n await runtime.reset(this.options.policyExecutionTrial);\n this.#status = \"ready\";\n this.#message = \"Reset capx-agent-runtime live session.\";\n this.#updatedAt = Date.now();\n return this.getState();\n }\n\n async listArtifacts(\n options: PhysicalListArtifactsOptions = {},\n ): Promise<PhysicalArtifact[]> {\n const runtime = await this.#ensureLiveRuntime();\n const artifacts = await runtime.listArtifacts(options.limit ?? 50);\n return options.kind\n ? artifacts.filter((artifact) => artifact.kind === options.kind)\n : artifacts;\n }\n\n async getRuntimeTurnHistory(): Promise<unknown[]> {\n if (!this.#liveRuntime) {\n return [];\n }\n return this.#liveRuntime.turnHistory();\n }\n\n async getRuntimeSkillLibrary() {\n if (!this.#liveRuntime) {\n return {\n summary: \"No live CaP-X runtime session has started.\",\n total: 0,\n promoted: 0,\n skills: [],\n };\n }\n return this.#liveRuntime.skillLibrary();\n }\n\n async extractRuntimeSkills(\n options: {\n code?: string;\n taskName?: string;\n } = {},\n ) {\n const runtime = await this.#ensureLiveRuntime();\n return runtime.extractSkills(options);\n }\n\n async injectRuntimeSkillLibrary(minOccurrences = 2) {\n const runtime = await this.#ensureLiveRuntime();\n return runtime.injectSkillLibrary(minOccurrences);\n }\n\n async stop(reason?: string): Promise<PhysicalSessionState> {\n this.#message = reason ?? \"Stop requested.\";\n this.#updatedAt = Date.now();\n\n if (this.#liveRuntime) {\n this.#status = \"stopping\";\n await this.#liveRuntime.stop();\n this.#liveRuntime = undefined;\n this.#status = \"stopped\";\n this.#updatedAt = Date.now();\n return this.getState();\n }\n\n this.#status = \"stopped\";\n return this.getState();\n }\n}\n\nexport function createCapxSession(options: CapxSessionOptions): CapxSession {\n return new CapxSession(options);\n}\n\nexport function createCapxPhysicalTools(\n session: PhysicalSession | CapxSession,\n options: PhysicalToolOptions = {},\n) {\n const tools = createPhysicalSessionTools(session, {\n prefix: \"capx\",\n ...options,\n });\n if (\n session instanceof CapxSession &&\n session.options.policyExecutionMode === \"live-runtime\"\n ) {\n tools.push(createCapxTurnHistoryTool(session, options));\n }\n return tools;\n}\n\nfunction capxToolName(name: string, options?: PhysicalToolOptions): string {\n return `${options?.prefix ?? \"capx\"}_${name}`;\n}\n\nfunction createCapxTurnHistoryTool(\n session: CapxSession,\n options?: PhysicalToolOptions,\n) {\n return Tool.define(\n capxToolName(\"turn_history\", options),\n {\n description:\n \"List policy-code turns executed through the live CaP-X runtime session.\",\n parameters: z.object({}),\n capabilities: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n execute: async () => {\n const turns = await session.getRuntimeTurnHistory();\n return {\n title: \"CaP-X Turn History\",\n output:\n turns.length === 0\n ? \"No CaP-X runtime turns have executed yet.\"\n : `${turns.length} CaP-X runtime turn(s).`,\n metadata: {\n physical: {\n sessionId: session.id,\n },\n capx: {\n turns,\n },\n },\n };\n },\n },\n {\n capabilitiesHint: {\n parallelSafe: true,\n readOnly: true,\n riskLevel: \"safe\",\n },\n },\n );\n}\n","import { randomUUID } from \"node:crypto\";\nimport type {\n PhysicalArtifact,\n PhysicalExecutionRequest,\n PhysicalExecutionTrace,\n} from \"@cuylabs/agent-physical\";\nimport { CapxRuntimeHttpClient } from \"./http-client.js\";\nimport {\n mapExecutionResult,\n mapFrame,\n mapObservation,\n mapRuntimeArtifact,\n mapSkillExtraction,\n mapSkillInjection,\n} from \"./mappers.js\";\nexport type {\n RuntimeCodeAffordance,\n RuntimeCodeContext,\n RuntimeExecutionResult,\n RuntimeFrame,\n RuntimeObservation,\n RuntimeSkillExtraction,\n RuntimeSkillInjection,\n RuntimeSkillLibrary,\n RuntimeTurn,\n} from \"./schema.js\";\nimport type {\n RuntimeArtifactsResponse,\n RuntimeCreateSessionResponse,\n RuntimeExecutionResponse,\n RuntimeFrame,\n RuntimeFrameResponse,\n RuntimeObservation,\n RuntimeObservationResponse,\n RuntimeSkillExtraction,\n RuntimeSkillExtractionResponse,\n RuntimeSkillInjection,\n RuntimeSkillInjectionResponse,\n RuntimeSkillLibrary,\n RuntimeSkillLibraryResponse,\n RuntimeTurn,\n RuntimeTurnHistoryResponse,\n} from \"./schema.js\";\nimport { failedTrace, withoutUndefined } from \"./utils.js\";\nimport type { CapxSessionOptions } from \"../types.js\";\n\nexport class CapxLiveRuntime {\n readonly id: string;\n readonly outputDir: string | undefined;\n\n #client: CapxRuntimeHttpClient;\n #sessionId: string | undefined;\n #lastObservation: RuntimeObservation | undefined;\n\n constructor(\n readonly options: CapxSessionOptions,\n id = `capx-live-${randomUUID()}`,\n ) {\n this.id = id;\n this.outputDir = options.outputDir;\n this.#client = new CapxRuntimeHttpClient(options);\n }\n\n get stdoutTail(): string {\n return this.#client.stdoutTail;\n }\n\n get stderrTail(): string {\n return this.#client.stderrTail;\n }\n\n get running(): boolean {\n return this.#sessionId !== undefined && this.#client.ready;\n }\n\n async start(): Promise<RuntimeObservation> {\n if (this.#sessionId && this.#lastObservation) {\n return this.#lastObservation;\n }\n\n try {\n await this.#client.ensureStarted();\n const response = await this.#client.request<RuntimeCreateSessionResponse>(\n \"POST\",\n \"/sessions\",\n this.#sessionOptionsPayload(),\n );\n const sessionId = response.sessionId ?? response.session_id;\n if (!sessionId) {\n throw new Error(\"capx-agent-runtime did not return a session id.\");\n }\n this.#sessionId = sessionId;\n this.#lastObservation = mapObservation(response.observation);\n return this.#lastObservation;\n } catch (error) {\n await this.stop();\n throw error;\n }\n }\n\n async observe(): Promise<RuntimeObservation> {\n await this.start();\n const response = await this.#client.request<RuntimeObservationResponse>(\n \"GET\",\n `/sessions/${this.#requireSessionId()}/observe`,\n undefined,\n this.options.runtimeServerRequestTimeoutMs,\n );\n const observation = mapObservation(response.observation);\n this.#lastObservation = observation;\n return observation;\n }\n\n async renderFrame(camera = \"main\"): Promise<RuntimeFrame> {\n await this.start();\n const response = await this.#client.request<RuntimeFrameResponse>(\n \"GET\",\n `/sessions/${this.#requireSessionId()}/render?camera=${encodeURIComponent(camera)}`,\n undefined,\n this.options.runtimeServerRequestTimeoutMs,\n );\n return mapFrame(response);\n }\n\n async turnHistory(): Promise<RuntimeTurn[]> {\n await this.start();\n const response = await this.#client.request<RuntimeTurnHistoryResponse>(\n \"GET\",\n `/sessions/${this.#requireSessionId()}/turns`,\n undefined,\n this.options.runtimeServerRequestTimeoutMs,\n );\n return response.turns ?? [];\n }\n\n async skillLibrary(): Promise<RuntimeSkillLibrary> {\n await this.start();\n return await this.#client.request<RuntimeSkillLibraryResponse>(\n \"GET\",\n `/sessions/${this.#requireSessionId()}/skill-library`,\n undefined,\n this.options.runtimeServerRequestTimeoutMs,\n );\n }\n\n async extractSkills(\n options: {\n code?: string;\n taskName?: string;\n } = {},\n ): Promise<RuntimeSkillExtraction> {\n await this.start();\n const response = await this.#client.request<RuntimeSkillExtractionResponse>(\n \"POST\",\n `/sessions/${this.#requireSessionId()}/skill-library/extract`,\n withoutUndefined({\n code: options.code,\n task_name: options.taskName,\n }),\n this.options.runtimeServerRequestTimeoutMs,\n );\n return mapSkillExtraction(response);\n }\n\n async injectSkillLibrary(minOccurrences = 2): Promise<RuntimeSkillInjection> {\n await this.start();\n const response = await this.#client.request<RuntimeSkillInjectionResponse>(\n \"POST\",\n `/sessions/${this.#requireSessionId()}/skill-library/inject`,\n {\n min_occurrences: minOccurrences,\n },\n this.options.runtimeServerRequestTimeoutMs,\n );\n return mapSkillInjection(response);\n }\n\n async listArtifacts(limit = 50): Promise<PhysicalArtifact[]> {\n await this.start();\n const response = await this.#client.request<RuntimeArtifactsResponse>(\n \"GET\",\n `/sessions/${this.#requireSessionId()}/artifacts`,\n undefined,\n this.options.runtimeServerRequestTimeoutMs,\n );\n const artifacts = response.artifacts ?? [];\n const baseUrl = this.#client.requireBaseUrl();\n return artifacts\n .slice(0, limit)\n .map((artifact) => mapRuntimeArtifact(artifact, baseUrl));\n }\n\n async reset(trial?: number): Promise<RuntimeObservation> {\n await this.start();\n const response = await this.#client.request<RuntimeObservationResponse>(\n \"POST\",\n `/sessions/${this.#requireSessionId()}/reset`,\n withoutUndefined({ trial }),\n this.options.runtimeServerRequestTimeoutMs,\n );\n const observation = mapObservation(response.observation);\n this.#lastObservation = observation;\n return observation;\n }\n\n async execute(\n request: PhysicalExecutionRequest,\n ): Promise<PhysicalExecutionTrace> {\n const preflightFailure = this.#validateExecutionRequest(request);\n if (preflightFailure) {\n return preflightFailure;\n }\n if (request.dryRun) {\n return dryRunTrace(request);\n }\n\n await this.start();\n const startedAt = Date.now();\n const traceId = `capx-live-${randomUUID()}`;\n const response = await this.#client.request<RuntimeExecutionResponse>(\n \"POST\",\n `/sessions/${this.#requireSessionId()}/execute-code`,\n { code: request.code },\n request.timeoutMs ??\n this.options.policyExecutionTimeoutMs ??\n this.options.runtimeServerRequestTimeoutMs,\n );\n const result = mapExecutionResult(response.result) ?? {\n success: false,\n stderr: \"capx-agent-runtime returned no execution result.\",\n };\n this.#lastObservation = {\n ...this.#lastObservation,\n lastStep: result,\n };\n\n return {\n id: traceId,\n startedAt,\n completedAt: Date.now(),\n request,\n stdout: result.stdout ?? \"\",\n stderr: result.stderr ?? \"\",\n artifacts: await this.#listExecutionArtifacts(),\n outcome: {\n success: result.success,\n reward: result.reward,\n taskCompleted: result.taskCompleted ?? undefined,\n terminated: result.terminated,\n truncated: result.truncated,\n metadata: {\n sandboxRc: result.sandboxRc,\n elapsedMs: result.elapsedMs,\n codePath: result.codePath,\n diagnostics: result.diagnostics,\n runtimeServer: \"capx-agent-runtime\",\n },\n },\n metadata: {\n capx: withoutUndefined({\n executionMode: \"live-runtime\",\n runtimeServer: \"capx-agent-runtime\",\n runtimeServerUrl: this.#client.baseUrl,\n outputDir: this.outputDir,\n }),\n },\n };\n }\n\n async stop(): Promise<void> {\n const sessionId = this.#sessionId;\n this.#sessionId = undefined;\n this.#lastObservation = undefined;\n await this.#client.stop(sessionId);\n }\n\n #sessionOptionsPayload(): Record<string, unknown> {\n return withoutUndefined({\n trial: this.options.policyExecutionTrial,\n output_dir: this.options.outputDir,\n record_video: this.options.policyExecutionRecordVideo,\n start_api_servers: this.options.policyExecutionStartApiServers,\n skill_library_path: this.options.skillLibraryPath,\n });\n }\n\n #validateExecutionRequest(\n request: PhysicalExecutionRequest,\n ): PhysicalExecutionTrace | undefined {\n if (request.language && request.language !== \"python\") {\n return failedTrace(\n request,\n `CaP-X live runtime only supports Python, got ${request.language}.`,\n );\n }\n if (\n this.options.physicalMode === \"hardware\" &&\n !this.options.allowHardwarePolicyExecution\n ) {\n return failedTrace(\n request,\n \"Hardware policy execution is blocked. Set allowHardwarePolicyExecution to opt in.\",\n { physicalMode: this.options.physicalMode },\n );\n }\n return undefined;\n }\n\n async #listExecutionArtifacts(): Promise<PhysicalArtifact[]> {\n try {\n return await this.listArtifacts(50);\n } catch {\n return [];\n }\n }\n\n #requireSessionId(): string {\n if (!this.#sessionId) {\n throw new Error(\"capx-agent-runtime session is not started.\");\n }\n return this.#sessionId;\n }\n}\n\nfunction dryRunTrace(\n request: PhysicalExecutionRequest,\n): PhysicalExecutionTrace {\n const now = Date.now();\n return {\n id: `capx-live-${randomUUID()}`,\n startedAt: now,\n completedAt: now,\n request,\n stdout: \"Dry run accepted; code was not executed.\",\n outcome: {\n success: true,\n metadata: {\n dryRun: true,\n },\n },\n metadata: {\n capx: {\n executionMode: \"live-runtime\",\n runtimeServer: \"capx-agent-runtime\",\n },\n },\n };\n}\n","import { setTimeout as sleep } from \"node:timers/promises\";\nimport type { CapxSessionOptions } from \"../types.js\";\nimport {\n DEFAULT_RUNTIME_REQUEST_TIMEOUT_MS,\n normalizeBaseUrl,\n} from \"./utils.js\";\n\nexport class CapxRuntimeHttpClient {\n #baseUrl: string | undefined;\n\n constructor(readonly options: CapxSessionOptions) {}\n\n get baseUrl(): string | undefined {\n return this.#baseUrl;\n }\n\n get stdoutTail(): string {\n return \"\";\n }\n\n get stderrTail(): string {\n return \"\";\n }\n\n get ready(): boolean {\n return this.#baseUrl !== undefined;\n }\n\n async ensureStarted(): Promise<void> {\n if (this.#baseUrl) {\n return;\n }\n\n this.#baseUrl = normalizeBaseUrl(this.options.runtimeServerUrl);\n await this.#waitForHealth(\n this.options.runtimeServerStartupTimeoutMs ?? 5_000,\n );\n }\n\n async request<T = unknown>(\n method: \"GET\" | \"POST\",\n route: string,\n body?: Record<string, unknown>,\n timeoutMs = this.options.runtimeServerRequestTimeoutMs ??\n this.options.policyExecutionTimeoutMs ??\n DEFAULT_RUNTIME_REQUEST_TIMEOUT_MS,\n ): Promise<T> {\n const baseUrl = this.requireBaseUrl();\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n timer.unref();\n try {\n const response = await fetch(`${baseUrl}${route}`, {\n method,\n headers: body\n ? {\n \"content-type\": \"application/json\",\n }\n : undefined,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n if (!response.ok) {\n const text = await response.text();\n throw new Error(\n `capx-agent-runtime ${method} ${route} failed with ${response.status}: ${text}`,\n );\n }\n return (await response.json()) as T;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async stop(sessionId?: string): Promise<void> {\n if (!sessionId || !this.#baseUrl) {\n return;\n }\n try {\n await this.request(\"POST\", `/sessions/${sessionId}/stop`, {}, 5_000);\n } catch {\n // A local stop request should not mask the caller's original shutdown path.\n }\n }\n\n requireBaseUrl(): string {\n if (!this.#baseUrl) {\n throw new Error(\"capx-agent-runtime base URL is not configured.\");\n }\n return this.#baseUrl;\n }\n\n async #waitForHealth(timeoutMs: number): Promise<void> {\n const started = Date.now();\n let lastError: unknown;\n while (Date.now() - started < timeoutMs) {\n try {\n await this.request(\"GET\", \"/health\", undefined, 1_000);\n return;\n } catch (error) {\n lastError = error;\n await sleep(250);\n }\n }\n\n throw new Error(\n `Timed out waiting for capx-agent-runtime health after ${timeoutMs}ms. ${String(\n lastError,\n )}`,\n );\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type {\n PhysicalExecutionRequest,\n PhysicalExecutionTrace,\n} from \"@cuylabs/agent-physical\";\n\nexport const DEFAULT_RUNTIME_REQUEST_TIMEOUT_MS = 1_000_000;\n\nexport function normalizeBaseUrl(value: string): string {\n return value.replace(/\\/+$/, \"\");\n}\n\nexport function withoutUndefined(\n value: Record<string, unknown>,\n): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(value).filter(([, item]) => item !== undefined),\n );\n}\n\nexport function failedTrace(\n request: PhysicalExecutionRequest,\n reason: string,\n metadata: Record<string, unknown> = {},\n): PhysicalExecutionTrace {\n const now = Date.now();\n return {\n id: `capx-live-${randomUUID()}`,\n startedAt: now,\n completedAt: now,\n request,\n stderr: reason,\n outcome: {\n success: false,\n reason,\n },\n metadata,\n };\n}\n","import type { PhysicalArtifact } from \"@cuylabs/agent-physical\";\nimport type {\n RuntimeApiExecutionResult,\n RuntimeApiObservation,\n RuntimeApiCodeAffordance,\n RuntimeApiCodeContext,\n RuntimeArtifactResponse,\n RuntimeCodeAffordance,\n RuntimeCodeContext,\n RuntimeExecutionResult,\n RuntimeFrame,\n RuntimeFrameResponse,\n RuntimeObservation,\n RuntimeSkillExtraction,\n RuntimeSkillExtractionResponse,\n RuntimeSkillInjection,\n RuntimeSkillInjectionResponse,\n} from \"./schema.js\";\n\nexport function mapExecutionResult(\n result: RuntimeApiExecutionResult | null | undefined,\n): RuntimeExecutionResult | null {\n if (!result) {\n return null;\n }\n return {\n success: result.success ?? false,\n reward: result.reward ?? undefined,\n terminated: result.terminated,\n truncated: result.truncated,\n sandboxRc: result.sandboxRc ?? result.sandbox_rc,\n stdout: result.stdout,\n stderr: result.stderr,\n taskCompleted: result.taskCompleted ?? result.task_completed,\n codePath: result.codePath ?? result.code_path,\n elapsedMs: result.elapsedMs ?? result.elapsed_ms,\n error: result.error,\n diagnostics: result.diagnostics,\n };\n}\n\nexport function mapObservation(\n observation: RuntimeApiObservation | undefined,\n): RuntimeObservation {\n if (!observation) {\n return {};\n }\n return {\n trial: observation.trial,\n taskPrompt: observation.taskPrompt ?? observation.task_prompt ?? undefined,\n multiTurnPrompt:\n observation.multiTurnPrompt ?? observation.multi_turn_prompt ?? undefined,\n fullPrompt: observation.fullPrompt ?? observation.full_prompt,\n resetInfo: observation.resetInfo ?? observation.reset_info,\n lastStep: mapExecutionResult(observation.lastStep ?? observation.last_step),\n runtimeConfig:\n observation.runtimeConfig ?? observation.runtime_config ?? undefined,\n codeContext: mapCodeContext(\n observation.codeContext ?? observation.code_context,\n ),\n };\n}\n\nfunction mapCodeContext(\n context: RuntimeApiCodeContext | null | undefined,\n): RuntimeCodeContext | undefined {\n if (!context) {\n return undefined;\n }\n return {\n policyLanguage: context.policyLanguage ?? context.policy_language,\n executionModel: context.executionModel ?? context.execution_model,\n submitVia: context.submitVia ?? context.submit_via,\n affordances: context.affordances?.map(mapCodeAffordance),\n skillLibrarySummary:\n context.skillLibrarySummary ?? context.skill_library_summary,\n skillLibraryDocs: context.skillLibraryDocs ?? context.skill_library_docs,\n };\n}\n\nfunction mapCodeAffordance(\n affordance: RuntimeApiCodeAffordance,\n): RuntimeCodeAffordance {\n return {\n name: affordance.name,\n description: affordance.description,\n inputSchema: affordance.inputSchema ?? affordance.input_schema,\n source: affordance.source,\n symbol: affordance.symbol,\n tags: affordance.tags,\n metadata: affordance.metadata,\n };\n}\n\nexport function mapFrame(\n frame: RuntimeFrameResponse | undefined,\n): RuntimeFrame {\n if (!frame) {\n return {};\n }\n return {\n source: frame.source,\n mimeType: frame.mimeType ?? frame.mime_type,\n encoding: frame.encoding,\n data: frame.data,\n dataUrl: frame.dataUrl ?? frame.data_url,\n width: frame.width ?? undefined,\n height: frame.height ?? undefined,\n timestamp: frame.timestamp,\n };\n}\n\nexport function mapRuntimeArtifact(\n artifact: RuntimeArtifactResponse,\n baseUrl: string,\n): PhysicalArtifact {\n const relativePath = artifact.path ?? \"artifact\";\n const relativeUrl = artifact.url ?? \"\";\n return {\n id: `capx-runtime:${relativePath}`,\n kind: mapArtifactKind(artifact.kind),\n uri: relativeUrl.startsWith(\"http\")\n ? relativeUrl\n : `${baseUrl}${relativeUrl}`,\n label: relativePath,\n metadata: {\n capx: {\n path: relativePath,\n sizeBytes: artifact.sizeBytes ?? artifact.size_bytes,\n modifiedTime: artifact.modifiedTime ?? artifact.modified_time,\n kind: artifact.kind,\n },\n },\n };\n}\n\nexport function mapSkillExtraction(\n response: RuntimeSkillExtractionResponse,\n): RuntimeSkillExtraction {\n return {\n path: response.path,\n taskName: response.taskName ?? response.task_name,\n newSkills: response.newSkills ?? response.new_skills ?? [],\n total: response.total,\n };\n}\n\nexport function mapSkillInjection(\n response: RuntimeSkillInjectionResponse,\n): RuntimeSkillInjection {\n return {\n path: response.path,\n injected: response.injected ?? 0,\n promotedSkills: response.promotedSkills ?? response.promoted_skills ?? [],\n };\n}\n\nfunction mapArtifactKind(kind: string | undefined): PhysicalArtifact[\"kind\"] {\n if (kind === \"image\" || kind === \"video\" || kind === \"json\") {\n return kind;\n }\n if (kind === \"text\") {\n return \"log\";\n }\n return \"other\";\n}\n"],"mappings":";AAAA,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,OAYK;AACP,SAAS,SAAS;;;AChBlB,SAAS,cAAAC,mBAAkB;;;ACA3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O;AAAA,UACL,OAAO;AAAA,UACP,QACE,MAAM,WAAW,IACb,8CACA,GAAG,MAAM,MAAM;AAAA,UACrB,UAAU;AAAA,YACR,UAAU;AAAA,cACR,WAAW,QAAQ;AAAA,YACrB;AAAA,YACA,MAAM;AAAA,cACJ;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,kBAAkB;AAAA,QAChB,cAAc;AAAA,QACd,UAAU;AAAA,QACV,WAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;","names":["randomUUID","randomUUID","randomUUID","randomUUID"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createCapxPhysicalTools,
3
3
  createCapxSession
4
- } from "./chunk-MYO63CWO.js";
4
+ } from "./chunk-EBBHF633.js";
5
5
 
6
6
  // src/agent.ts
7
7
  import { createAgent } from "@cuylabs/agent-core";
@@ -104,4 +104,4 @@ export {
104
104
  defaultCapxAgentApproval,
105
105
  createCapxAgent
106
106
  };
107
- //# sourceMappingURL=chunk-C53NNB7T.js.map
107
+ //# sourceMappingURL=chunk-F3JNO443.js.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PhysicalArtifact, PhysicalExecutionRequest, PhysicalExecutionTrace } from '@cuylabs/agent-physical';
2
- import { C as CapxArtifactDiscoveryOptions, a as CapxSessionOptions, R as RuntimeObservation, b as RuntimeFrame, c as RuntimeTurn, d as RuntimeSkillLibrary, e as RuntimeSkillExtraction, f as RuntimeSkillInjection } from './session-BxaROlXW.js';
3
- export { g as CapxPolicyExecutionMode, h as CapxRunMode, i as CapxSession, j as RuntimeCodeAffordance, k as RuntimeCodeContext, l as RuntimeExecutionResult, m as createCapxPhysicalTools, n as createCapxSession } from './session-BxaROlXW.js';
2
+ import { C as CapxArtifactDiscoveryOptions, a as CapxSessionOptions, R as RuntimeObservation, b as RuntimeFrame, c as RuntimeTurn, d as RuntimeSkillLibrary, e as RuntimeSkillExtraction, f as RuntimeSkillInjection } from './session-BwE260Mn.js';
3
+ export { g as CapxPolicyExecutionMode, h as CapxRunMode, i as CapxSession, j as RuntimeCodeAffordance, k as RuntimeCodeContext, l as RuntimeExecutionResult, m as createCapxPhysicalTools, n as createCapxSession } from './session-BwE260Mn.js';
4
4
  export { CapxAgent, CreateCapxAgentOptions, capxAgentSkillRoot, createCapxAgent, defaultCapxAgentApproval, defaultCapxAgentSystemPrompt } from './agent.js';
5
5
  import '@cuylabs/agent-core/tool';
6
6
  import '@cuylabs/agent-core';
@@ -11,7 +11,7 @@ declare class CapxLiveRuntime {
11
11
  #private;
12
12
  readonly options: CapxSessionOptions;
13
13
  readonly id: string;
14
- readonly outputDir: string;
14
+ readonly outputDir: string | undefined;
15
15
  constructor(options: CapxSessionOptions, id?: string);
16
16
  get stdoutTail(): string;
17
17
  get stderrTail(): string;
package/dist/index.js CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  createCapxAgent,
4
4
  defaultCapxAgentApproval,
5
5
  defaultCapxAgentSystemPrompt
6
- } from "./chunk-C53NNB7T.js";
6
+ } from "./chunk-F3JNO443.js";
7
7
  import {
8
8
  CapxLiveRuntime,
9
9
  CapxSession,
10
10
  createCapxPhysicalTools,
11
11
  createCapxSession
12
- } from "./chunk-MYO63CWO.js";
12
+ } from "./chunk-EBBHF633.js";
13
13
 
14
14
  // src/artifacts.ts
15
15
  import { readdir, stat } from "fs/promises";
@@ -120,7 +120,12 @@ interface CapxSessionOptions {
120
120
  */
121
121
  runtimeServerRequestTimeoutMs?: number;
122
122
  /**
123
- * Override CaP-X output directory.
123
+ * Privileged per-session CaP-X output directory override.
124
+ *
125
+ * Normal clients should omit this and use the runtime server's configured
126
+ * output directory. capx-agent-runtime rejects client-supplied output
127
+ * directories unless the server was started with client path overrides
128
+ * enabled.
124
129
  */
125
130
  outputDir?: string;
126
131
  /**
@@ -159,8 +164,11 @@ interface CapxSessionOptions {
159
164
  */
160
165
  policyExecutionStartApiServers?: boolean;
161
166
  /**
162
- * Optional CaP-X skill library path. Relative paths are resolved by the
163
- * runtime server.
167
+ * Privileged per-session CaP-X skill library path override.
168
+ *
169
+ * Normal clients should omit this and use the runtime server's configured
170
+ * skill library. capx-agent-runtime rejects client-supplied skill library
171
+ * paths unless the server was started with client path overrides enabled.
164
172
  */
165
173
  skillLibraryPath?: string;
166
174
  /**
package/dist/session.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { i as CapxSession, m as createCapxPhysicalTools, n as createCapxSession } from './session-BxaROlXW.js';
1
+ export { i as CapxSession, m as createCapxPhysicalTools, n as createCapxSession } from './session-BwE260Mn.js';
2
2
  import '@cuylabs/agent-core/tool';
3
3
  import '@cuylabs/agent-physical';
package/dist/session.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  CapxSession,
3
3
  createCapxPhysicalTools,
4
4
  createCapxSession
5
- } from "./chunk-MYO63CWO.js";
5
+ } from "./chunk-EBBHF633.js";
6
6
  export {
7
7
  CapxSession,
8
8
  createCapxPhysicalTools,
@@ -12,7 +12,9 @@ code authoring, and the live observe/execute/reset loop.
12
12
  lifecycle, Python execution namespace, rewards, task completion, and artifacts.
13
13
 
14
14
  The TypeScript adapter does not launch CaP-X and does not pass `repoPath` or
15
- `configPath`. Those are runtime-service startup concerns.
15
+ `configPath`. It also omits `outputDir` and `skillLibraryPath` by default.
16
+ Those path choices are runtime-service startup concerns unless a trusted server
17
+ operator explicitly enables client path overrides.
16
18
 
17
19
  ## Recommended Wiring
18
20
 
@@ -79,6 +79,9 @@ The CaP-X YAML chosen by `capx-agent-runtime serve --config-path ...` selects
79
79
  the simulator task, helper API surface, perception/API servers, output
80
80
  directory, recording behavior, and prompt text. The TypeScript adapter does not
81
81
  choose or reload that YAML; it connects to the already-started runtime service.
82
+ It also does not send output or skill-library paths by default. Those are
83
+ server-owned paths unless the runtime server was started with privileged client
84
+ path overrides enabled.
82
85
 
83
86
  The external `agent-core` loop can run multiple turns against any compatible
84
87
  CaP-X config because each `capx_run_policy_code` call executes one Python
@@ -8,7 +8,7 @@ OPENAI_BASE_URL=
8
8
 
9
9
  # Required runtime service URL. Start capx-agent-runtime first, then point this
10
10
  # example at the service or SSH tunnel URL. The TypeScript examples do not
11
- # launch CaP-X or CaP-X Agent0.
11
+ # start CaP-X or select a CaP-X config.
12
12
  CAPX_RUNTIME_SERVER_URL=http://127.0.0.1:8210
13
13
 
14
14
  # Safety switches for the example host. Set CAPX_ALLOW_DESTRUCTIVE=1 to allow
@@ -29,8 +29,9 @@ CAPX_POLICY_EXECUTION_RECORD_VIDEO=
29
29
  CAPX_STOP_ON_EXIT=0
30
30
  CAPX_MAX_SOLVER_TURNS=6
31
31
 
32
- # Optional runtime session overrides. Normally the runtime server startup
33
- # command owns output paths and skill library paths.
34
- CAPX_OUTPUT_DIR=
35
- CAPX_SKILL_LIBRARY_PATH=
32
+ # Privileged runtime session path overrides. Leave blank for normal use.
33
+ # capx-agent-runtime rejects these unless the server was started with
34
+ # --allow-client-path-overrides and matching allowed roots.
35
+ CAPX_SESSION_OUTPUT_DIR=
36
+ CAPX_SESSION_SKILL_LIBRARY_PATH=
36
37
  CAPX_AGENT_PROMPT=