Skip to content

Commit 770ec2f

Browse files
ScriptedAlchemy0xRaduantekumaracodex-botclaude
authored
Add OpenAI Agents SDK examples with CodexProvider (#24)
* Fix SDK documentation: replace 'file diffs' with 'file change notifications' (#6425) The TypeScript SDK's README incorrectly claimed that runStreamed() emits "file diffs". However, the FileChangeItem type only contains metadata (path, kind, status) without actual diff content. Updated line 36 to accurately describe the SDK as providing "file change notifications" instead of "file diffs" to match the actual implementation in items.ts. Fixes #5850 * fix(seatbelt): Allow reading hw.physicalcpu (#6421) Allow reading `hw.physicalcpu` so numpy can be imported when running in the sandbox. resolves #6420 * feat(native): add sdk/native and minimal core/exec shims; CI runs native build+tests; fix TUI ANSI test env\n\n- Expose minimal core APIs for native tools/interceptors\n- Integrate pending tool registrations into specs\n- Add exec callback runner for ThreadEvent streaming\n- Include sdk/native in pnpm workspace and CI\n- Re-enable TUI vt100 color checks in tests * sdk/native: always build N-API before Jest; unify TS test runner; fix stream event mapping - Pretest runs to ensure .node is present - Jest config: TS-first via babel-jest; ESM-friendly - CodexProvider: emit response_started first; forward raw_event correctly; include Responses-style deltas/completion - Native loader: prefer env override; ensure local-first - Add approval callback surface; tool interceptors - Remove duplicate .mjs tests; keep TS tests only - Update tests to use responses proxy helpers; stabilize assertions * fix(core): clear session_id when exec command completes Fixes session_id handling for completed exec commands by checking both exit_code and has_exited() status before deciding whether to persist session. Resolves test failure in exec_command_reports_chunk_and_exit_metadata. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * core(unified_exec): omit session_id for completed exec_command; only persist live sessions core(registry): add upsert_spec_with_parallel_support for external tool overrides core(tools/spec): remove duplicate create_function_tool_spec_from_schema and unify implementation * chore: sync core tool registry and native sdk * Restore native tool bridge and approvals * docs: add NAPI concepts documentation Add comprehensive NAPI concepts documentation including: - Async functions and tasks - Classes and enums - Environment and exports - External references - Functions and objects - Promises and threadsafe functions - Typed arrays and values - WebAssembly integration - Naming conventions and lifetime management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Prune generated artifacts and streamline CI * Tighten native build flags * chore: remove sccache configuration from CI and package scripts Remove sccache wrapper and related configuration to simplify CI builds and improve reproducibility. The overhead of managing sccache cache invalidation outweighs the benefits for this repository structure. Changes: - Remove RUSTC_WRAPPER=sccache from rust-ci.yml workflows - Remove sccache npm scripts from root package.json - Keep CARGO_INCREMENTAL=0 for reproducible builds 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove sccache-specific tuning * fix: add empty .codespellignore file for CI The codespell GitHub Action expects a .codespellignore file to exist when ignore_words_file is specified in the workflow. Add an empty file to satisfy this requirement. Actual ignore configuration is handled via .codespellrc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: remove sccache from cargo config Remove rustc-wrapper = "sccache" from cargo config to fix CI builds. The SDK workflow was failing because cargo was trying to use sccache as a compiler wrapper even though it wasn't installed. This completes the sccache removal started in previous commits. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix(ci): install rustfmt and clippy for SDK workflow Add rustfmt and clippy components to Rust toolchain installation in SDK workflow. The native SDK build requires cargo fmt and cargo clippy to be available. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: recreate .codespellignore for CI * feat(sdk): add token count and raw event types Add new event types to TypeScript SDK: - RawEvent: Unstructured raw events for diagnostics - TokenCountEvent: Token usage snapshots during turns - TokenUsageEvent: Token usage at shutdown These events are filtered out in Thread class to maintain backward compatibility while allowing for future diagnostics. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore(ci): restore sccache configuration to match upstream Restore RUSTC_WRAPPER and SCCACHE_CACHE_SIZE environment variables to match upstream (openai/codex) configuration for optimal CI performance. This enables the existing sccache infrastructure. Changes: - Add RUSTC_WRAPPER=sccache to rust-ci.yml (lint_build + tests jobs) - Add SCCACHE_CACHE_SIZE=10G to rust-ci.yml - Add Rust dependency caching to sdk.yml workflow This will provide ~30-50% faster CI builds on cache hits by caching compiled objects, not just dependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * feat(ci): add sccache to SDK workflow Add full sccache configuration to SDK workflow to match rust-ci.yml: - Set RUSTC_WRAPPER=sccache environment variable - Install sccache@0.7.5 via taiki-e/install-action - Configure sccache backend (GitHub Actions cache or local fallback) - Add sccache cache restore/save steps - Add sccache stats reporting This provides compilation object caching for the cargo build steps in addition to the existing Rust dependency caching, significantly speeding up CI runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * ci(sdk): remove sccache usage and increase timeout to 20m * ci(sdk): align cargo cache with rust-ci (split home/target, restore/save) * ci(sdk): increase timeout to 30 minutes * fix(ci): increase SDK workflow timeout and restore sccache env vars Increase SDK workflow timeout from 10 to 30 minutes to accommodate native SDK builds which require more time for Rust compilation. Also restore missing RUSTC_WRAPPER and SCCACHE_CACHE_SIZE environment variables that were accidentally removed. The previous run timed out after 10m02s while still compiling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * ci(sdk): install and configure sccache like rust-ci; add restore/save + stats * ci(sdk): align cache keys with rust-ci pattern for better cache sharing - Remove sdk- prefix from cache keys (sccache, cargo-home, cargo-target) - Add rust-toolchain.toml hash to cargo-home cache keys - Add cache-hit conditions to save steps to prevent redundant saves - Add continue-on-error to cargo save operations - Use runner.os for flexibility across runners This enables cache sharing between sdk and rust-ci workflows when they run on the same platform, reducing build times and cache storage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Raduan A. <36044389+0xRaduan@users.noreply.github.com> Co-authored-by: Oliver Mannion <125105+tekumara@users.noreply.github.com> Co-authored-by: codex-bot <devnull@example.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent bc2589d commit 770ec2f

121 files changed

Lines changed: 15376 additions & 5088 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.codespellignore‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
iTerm
2-
trys

‎.codespellrc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[codespell]
22
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
3-
skip = .git*,vendor,*-lock.yaml,*.lock,.codespellrc,.codespellignore,*test.ts,*.jsonl,frame*.txt,*/target/*,*/node_modules/*,*/.pnpm-store/*,*/dist/*,*/dist-examples/*,*/.yarn/*,package-lock.json,*.map
3+
skip = .git*,vendor,*-lock.yaml,*.lock,.codespellrc,*test.ts,*.jsonl,frame*.txt,**/node_modules/**,**/dist/**,**/target/**,sdk/native/dist-examples_ignored/**,sdk/native/dist-examples/**,sdk/native/package-lock.json,**/.venv/**
44
check-hidden = true
55
ignore-regex = ^\s*"image/\S+": ".*|\b(afterAll)\b
6-
ignore-words-list = ratatui,ser,trys
6+
ignore-words-list = ratatui,ser,iTerm,trys,vEw

‎.github/workflows/rust-ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ jobs:
329329
run:
330330
working-directory: codex-rs
331331
env:
332+
# Speed up repeated builds across CI runs by caching compiled objects.
332333
RUSTC_WRAPPER: sccache
333334
CARGO_INCREMENTAL: "0"
334335
SCCACHE_CACHE_SIZE: 10G

‎.github/workflows/sdk.yml‎

Lines changed: 100 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ on:
55
branches: [main]
66
pull_request: {}
77

8-
concurrency:
9-
group: ${{ github.workflow }}-${{ github.ref }}
10-
cancel-in-progress: true
11-
128
jobs:
139
sdks:
1410
runs-on: ubuntu-latest
15-
timeout-minutes: 20
11+
timeout-minutes: 30
12+
env:
13+
RUSTC_WRAPPER: sccache
14+
CARGO_INCREMENTAL: "0"
15+
SCCACHE_CACHE_SIZE: 10G
1616
steps:
1717
- name: Checkout repository
1818
uses: actions/checkout@v5
@@ -23,27 +23,68 @@ jobs:
2323
run_install: false
2424

2525
- name: Setup Node.js
26-
uses: actions/setup-node@v6
26+
uses: actions/setup-node@v5
2727
with:
2828
node-version: 22
2929
cache: pnpm
3030

31-
- uses: dtolnay/rust-toolchain@1.91
31+
- uses: dtolnay/rust-toolchain@1.90
3232
with:
3333
components: rustfmt, clippy
3434

35-
- name: Cache cargo
36-
uses: actions/cache@v4
35+
# Install and configure sccache (align with rust-ci)
36+
- name: Install sccache
37+
uses: taiki-e/install-action@e797ba6a25dbd8669057e123b02812e16138589e # v2
38+
with:
39+
tool: sccache@0.7.5
40+
41+
- name: Configure sccache backend
42+
shell: bash
43+
run: |
44+
set -euo pipefail
45+
if [[ -n "${ACTIONS_CACHE_URL:-}" && -n "${ACTIONS_RUNTIME_TOKEN:-}" ]]; then
46+
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
47+
echo "Using sccache GitHub backend"
48+
else
49+
echo "SCCACHE_GHA_ENABLED=false" >> "$GITHUB_ENV"
50+
echo "SCCACHE_DIR=${{ github.workspace }}/.sccache" >> "$GITHUB_ENV"
51+
echo "Using sccache local disk + actions/cache fallback"
52+
fi
53+
54+
- name: Restore sccache cache (fallback)
55+
if: ${{ env.SCCACHE_GHA_ENABLED != 'true' }}
56+
id: cache_sccache_restore
57+
uses: actions/cache/restore@v4
58+
with:
59+
path: ${{ github.workspace }}/.sccache/
60+
key: sccache-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-${{ github.run_id }}
61+
restore-keys: |
62+
sccache-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-
63+
sccache-${{ runner.os }}-
64+
65+
# Match rust-ci: split cargo home vs target, so large target dir is separable.
66+
- name: Restore cargo home cache
67+
id: cache_cargo_home_restore
68+
uses: actions/cache/restore@v4
3769
with:
3870
path: |
3971
~/.cargo/bin/
4072
~/.cargo/registry/index/
4173
~/.cargo/registry/cache/
4274
~/.cargo/git/db/
43-
codex-rs/target/
44-
key: sdk-cargo-${{ runner.os }}-${{ hashFiles('codex-rs/Cargo.lock') }}
75+
key: cargo-home-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('codex-rs/rust-toolchain.toml') }}
4576
restore-keys: |
46-
sdk-cargo-${{ runner.os }}-
77+
cargo-home-${{ runner.os }}-
78+
79+
- name: Restore cargo target cache
80+
id: cache_cargo_target_restore
81+
uses: actions/cache/restore@v4
82+
with:
83+
path: codex-rs/target/
84+
key: cargo-target-${{ runner.os }}-${{ hashFiles('codex-rs/Cargo.lock') }}-${{ github.run_id }}
85+
restore-keys: |
86+
cargo-target-${{ runner.os }}-${{ hashFiles('codex-rs/Cargo.lock') }}-
87+
cargo-target-${{ runner.os }}-
4788
4889
- name: build codex
4990
run: cargo build --bin codex
@@ -52,20 +93,56 @@ jobs:
5293
- name: Install dependencies
5394
run: pnpm install --frozen-lockfile
5495

55-
- name: Build TypeScript SDK packages
96+
- name: Build SDK packages
5697
run: pnpm -r --filter ./sdk/typescript run build
5798

58-
- name: Build native SDK package
59-
run: pnpm -r --filter ./sdk/native run build
60-
61-
- name: Lint TypeScript SDK packages
99+
- name: Lint SDK packages
62100
run: pnpm -r --filter ./sdk/typescript run lint
63101

64-
- name: Lint native SDK package
65-
run: pnpm -r --filter ./sdk/native run lint
66-
67-
- name: Test TypeScript SDK packages
102+
- name: Test SDK packages
68103
run: pnpm -r --filter ./sdk/typescript run test
69104

70-
- name: Test native SDK package
71-
run: pnpm -r --filter ./sdk/native run test
105+
- name: Install native SDK dependencies
106+
working-directory: sdk/native
107+
run: pnpm install
108+
109+
- name: Build native SDK
110+
working-directory: sdk/native
111+
run: pnpm run build
112+
113+
- name: Test native SDK
114+
working-directory: sdk/native
115+
run: pnpm test
116+
117+
- name: Save sccache cache (fallback)
118+
if: always() && !cancelled() && env.SCCACHE_GHA_ENABLED != 'true'
119+
continue-on-error: true
120+
uses: actions/cache/save@v4
121+
with:
122+
path: ${{ github.workspace }}/.sccache/
123+
key: sccache-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-${{ github.run_id }}
124+
125+
- name: sccache stats
126+
if: always()
127+
continue-on-error: true
128+
run: sccache --show-stats || true
129+
130+
- name: Save cargo home cache
131+
if: always() && !cancelled() && steps.cache_cargo_home_restore.outputs.cache-hit != 'true'
132+
continue-on-error: true
133+
uses: actions/cache/save@v4
134+
with:
135+
path: |
136+
~/.cargo/bin/
137+
~/.cargo/registry/index/
138+
~/.cargo/registry/cache/
139+
~/.cargo/git/db/
140+
key: cargo-home-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('codex-rs/rust-toolchain.toml') }}
141+
142+
- name: Save cargo target cache
143+
if: always() && !cancelled() && steps.cache_cargo_target_restore.outputs.cache-hit != 'true'
144+
continue-on-error: true
145+
uses: actions/cache/save@v4
146+
with:
147+
path: codex-rs/target/
148+
key: cargo-target-${{ runner.os }}-${{ hashFiles('codex-rs/Cargo.lock') }}-${{ github.run_id }}

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules
1010
# build
1111
dist/
1212
dist-examples/
13+
sdk/native/dist-examples/
1314
build/
1415
out/
1516
storybook-static/

0 commit comments

Comments
 (0)