coze_lab 0.1.43 → 0.1.45

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
@@ -5,56 +5,52 @@ Configure local AI agents (Claude Code, Codex, OpenClaw) to report traces to Coz
5
5
  ## Usage
6
6
 
7
7
  ```bash
8
- # First-time setup triggers browser OAuth authorization
9
- npx coze_lab --agent=<type>
10
-
11
- # Per-agent setup. Cloud/local is inferred from coze-bridge config or CLOUD_ENV=1.
8
+ # Per-agent setup. Local/cloud is inferred from ~/.coze/agents/<agentId>/config.json.
12
9
  npx coze_lab --agent-id=<agentId>
13
10
 
14
- # Auth-only commands (no agent configuration)
15
- npx coze_lab --login # Device Code login only
16
- npx coze_lab --status # Show current authorization status
17
- npx coze_lab --refresh # Force-refresh the access token
18
- npx coze_lab --logout # Clear cached credentials
11
+ # Cloud compatibility mode when the caller already knows the framework.
12
+ npx coze_lab --cloud --agent=<claude-code|codex|openclaw>
13
+
14
+ # Send a one-off trace selfcheck. Uses --agent-id patToken locally, or env token in cloud.
15
+ npx coze_lab --verify --agent-id=<agentId> --pair-code=<pairCode>
19
16
  ```
20
17
 
21
18
  ### Parameters
22
19
 
23
20
  | Parameter | Required | Values / Effect |
24
21
  |-----------|----------|-----------------|
25
- | `--agent` | (for setup) | `claude-code`, `codex`, `openclaw` |
26
- | `--agent-id` | | Resolve `~/.coze/agents/<agentId>/config.json` and write per-agent config. Cloud mode is inferred from `deployType=cloud`, `CLOUD_ENV=1`, or bridge cloud-only fields |
27
- | `--cloud` | | Backward-compatible override for old manual callers. New callers should rely on `--agent-id` auto-detection |
28
- | `--codex-home` | | Override Codex config home for non-cloud/custom runs |
29
- | `--login` | | Run the Device Code login flow only |
30
- | `--status` | | Print local token status (valid / expiring / expired) |
31
- | `--refresh` | | Force-refresh the access token via `refresh_token` |
32
- | `--logout` | — | Clears cached credentials |
33
-
34
- > **Note — traces are collected into a shared CozeLoop workspace.**
22
+ | `--agent-id` | Local setup | Resolve `~/.coze/agents/<agentId>/config.json`, infer framework/workspace, and read `patToken` for local trace upload |
23
+ | `--agent` | Cloud compatibility only | `claude-code`, `codex`, `openclaw` when no agent config is available |
24
+ | `--cloud` | Optional | Forces cloud mode; token must come from `COZELOOP_API_TOKEN` or `COZE_API_TOKEN` |
25
+ | `--codex-home` | Optional | Override Codex config home for custom cloud runs |
26
+ | `--force` | Optional | Force OpenClaw plugin rewrite/reinstall and gateway restart |
27
+ | `--verify` | Optional | Send a test trace; local requires `--agent-id` with `patToken`, cloud requires env token |
28
+ | `--pair-code` | Optional | Add a trace lookup code to selfcheck metadata |
29
+
30
+ > **Note - traces are collected into a shared CozeLoop workspace.**
35
31
  > All traces from this tool are uploaded to a single fixed workspace
36
- > (`COZELOOP_WORKSPACE_ID`) maintained by the CozeLoop team they are **not**
37
- > sent to each user's personal workspace. The OAuth authorization only proves
38
- > your identity for trace ingestion; it does not select a workspace.
32
+ > (`COZELOOP_WORKSPACE_ID`) maintained by the CozeLoop team; they are not sent
33
+ > to each user's personal workspace.
39
34
 
35
+ ## What It Does
40
36
 
41
- ## What it does
37
+ 1. **Token resolution** - Local mode reads `patToken` from `~/.coze/agents/<agentId>/config.json`. Cloud mode reads `COZELOOP_API_TOKEN` or `COZE_API_TOKEN` from the environment.
38
+ 2. **Agent detection** - Verifies the specified agent binary is installed locally.
39
+ 3. **Environment checks** - Python >= 3.8 + `cozeloop` SDK for Claude Code and Codex; SDK is auto-installed via pip if missing. Agent version whitelist warnings are non-fatal.
40
+ 4. **Hook configuration** - Writes hook scripts and config files for the selected agent.
41
+ 5. **Selfcheck** - Sends a test trace with the resolved token.
42
42
 
43
- 1. **Authorization** Checks `~/.cozeloop/credentials.json` for a cached OAuth token.
44
- - Token valid skip authorization, proceed.
45
- - Token expiring (< 10 min) → silently refresh via `refresh_token`.
46
- - No token / refresh failed → launches Device Code OAuth flow: opens browser, displays verification URL, polls until user approves.
47
- 2. **Agent detection** — Verifies the specified agent binary is installed locally.
48
- 3. **Environment checks** — Python ≥ 3.8 + `cozeloop` SDK (Claude Code & Codex only; SDK auto-installed via pip if missing), agent version whitelist check.
49
- 4. **Hook configuration** — Writes hook scripts and config files for the selected agent.
43
+ There is no Device Code login, OAuth cache, or refresh-token fallback. Legacy
44
+ `--login`, `--status`, `--refresh`, `--logout`, and local `--agent=<type>`
45
+ commands fail with a migration message.
50
46
 
51
- ## Per-agent hook files
47
+ ## Per-Agent Hook Files
52
48
 
53
- | Agent | Hook script | Config file | Credentials |
54
- |-------|------------|-------------|-------------|
55
- | `claude-code` | `~/.claude/hooks/cozeloop_hook.py` | `~/.claude/settings.json` | `.claude/settings.local.json` (project-scoped) |
56
- | `codex` | `~/.codex/hooks/cozeloop_hook.py` | `~/.codex/hooks.json` | `~/.codex/hooks/cozeloop.env` |
57
- | `openclaw` | — (Node.js plugin) | `~/.openclaw/openclaw.json` | inline in config |
49
+ | Agent | Hook script | Config file | Token environment |
50
+ |-------|-------------|-------------|-------------------|
51
+ | `claude-code` | `~/.claude/hooks/cozeloop_hook.py` | `~/.claude/settings.json` or agent workspace `.claude/settings.json` | `.claude/settings.local.json` |
52
+ | `codex` | `<CODEX_HOME>/hooks/cozeloop_hook.py` | `<CODEX_HOME>/hooks.json` | `<CODEX_HOME>/hooks/cozeloop.env` |
53
+ | `openclaw` | Node.js plugin | `~/.openclaw/openclaw.json` | inline `authorization` |
58
54
 
59
55
  For cloud Codex with `--agent-id=<agentId>`, Codex hooks are written to
60
56
  `~/.coze/agents/<agentId>/codex-home` by default. The directory is created if it
@@ -66,28 +62,26 @@ Codex home. For cloud Codex, check
66
62
  `~/.coze/agents/<agentId>/codex-home/hooks/cozeloop.log`. If that file is not
67
63
  created after a new Codex turn, Codex did not load or execute the hook.
68
64
 
69
- ## Token lifecycle
65
+ ## Token Lifecycle
70
66
 
71
- OAuth tokens are stored in `~/.cozeloop/credentials.json` (mode 600).
67
+ Local setup requires `~/.coze/agents/<agentId>/config.json` to contain
68
+ `patToken`. Onboarding writes that PAT into the selected agent's hook
69
+ configuration and marks the source as `agent_config.patToken`.
72
70
 
73
- In cloud mode, trace verification and hook uploads prefer
74
- `COZELOOP_API_TOKEN` and fall back to `COZE_API_TOKEN`. The selfcheck result is
75
- authoritative: if the token does not have trace ingest permission, onboard still
76
- writes the hook configuration but reports `verify=fail` with `token_source`.
77
- For Python SDK uploads, `OTEL_ENDPOINT` is not used as the SDK base URL; set
78
- `COZELOOP_API_BASE_URL` only when the SDK ingest endpoint should be overridden.
71
+ Cloud setup and verification prefer `COZELOOP_API_TOKEN` and fall back to
72
+ `COZE_API_TOKEN`. The selfcheck result is authoritative: if the token does not
73
+ have trace ingest permission, cloud onboard still writes hook configuration but
74
+ reports `verify=fail` with `token_source`.
79
75
 
80
- **At hook execution time** (Claude Code / Codex), the Python hook script automatically:
81
- 1. Reads `~/.cozeloop/credentials.json`
82
- 2. If the token expires in < 10 minutes, calls the Coze refresh API
83
- 3. Updates `credentials.json` with the new token
84
- 4. Passes the fresh token to the CozeLoop SDK before uploading traces
76
+ At hook execution time, Claude Code, Codex, and OpenClaw use only the token
77
+ written by onboarding or injected by cloud env. They do not read
78
+ `~/.cozeloop/credentials.json` and do not refresh tokens locally. If a token is
79
+ revoked or rotated, rerun `npx coze_lab --agent-id=<agentId>`.
85
80
 
86
- This means traces continue to upload without interruption even across token expiry, as long as the refresh token is still valid.
87
-
88
- **For OpenClaw**, the token is read from `openclaw.json` at startup. Re-run `npx coze_lab --agent=openclaw` to refresh it if OpenClaw reports auth errors.
81
+ For Python SDK uploads, `OTEL_ENDPOINT` is not used as the SDK base URL; set
82
+ `COZELOOP_API_BASE_URL` only when the SDK ingest endpoint should be overridden.
89
83
 
90
- ## Supported versions
84
+ ## Supported Versions
91
85
 
92
86
  | Agent | Supported versions |
93
87
  |-------|--------------------|
@@ -95,4 +89,4 @@ This means traces continue to upload without interruption even across token expi
95
89
  | `codex` | 0.134.x, 1.0.x, 1.1.x |
96
90
  | `openclaw` | 2026.3.x, 2026.4.x, 2026.5.x |
97
91
 
98
- Versions outside this list will show a yellow warning but onboarding will continue.
92
+ Versions outside this list show a warning but onboarding continues.