coze_lab 0.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 +75 -0
- package/index.js +4996 -0
- package/package.json +35 -0
- package/scripts/claude-code/cozeloop_hook.py +1303 -0
- package/scripts/codex/cozeloop_hook.py +1051 -0
- package/scripts/openclaw/dist/cozeloop-exporter.js +442 -0
- package/scripts/openclaw/dist/index.js +1315 -0
- package/scripts/openclaw/dist/span-manager.js +77 -0
- package/scripts/openclaw/dist/types.js +1 -0
- package/scripts/openclaw/openclaw.plugin.json +55 -0
- package/scripts/openclaw/package.json +45 -0
- package/scripts/shared/cozeloop_refresh.py +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @cozeloop/onboard
|
|
2
|
+
|
|
3
|
+
Configure local AI agents (Claude Code, Codex, OpenClaw) to report traces to CozeLoop.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# First-time setup — triggers browser OAuth authorization
|
|
9
|
+
npx @cozeloop/onboard --agent=<type>
|
|
10
|
+
|
|
11
|
+
# Auth-only commands (no agent configuration)
|
|
12
|
+
npx @cozeloop/onboard --login # Device Code login only
|
|
13
|
+
npx @cozeloop/onboard --status # Show current authorization status
|
|
14
|
+
npx @cozeloop/onboard --refresh # Force-refresh the access token
|
|
15
|
+
npx @cozeloop/onboard --logout # Clear cached credentials
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Parameters
|
|
19
|
+
|
|
20
|
+
| Parameter | Required | Values / Effect |
|
|
21
|
+
|-----------|----------|-----------------|
|
|
22
|
+
| `--agent` | ✓ (for setup) | `claude-code`, `codex`, `openclaw` |
|
|
23
|
+
| `--login` | — | Run the Device Code login flow only |
|
|
24
|
+
| `--status` | — | Print local token status (valid / expiring / expired) |
|
|
25
|
+
| `--refresh` | — | Force-refresh the access token via `refresh_token` |
|
|
26
|
+
| `--logout` | — | Clears cached credentials |
|
|
27
|
+
|
|
28
|
+
> **Note — traces are collected into a shared CozeLoop workspace.**
|
|
29
|
+
> All traces from this tool are uploaded to a single fixed workspace
|
|
30
|
+
> (`COZELOOP_WORKSPACE_ID`) maintained by the CozeLoop team — they are **not**
|
|
31
|
+
> sent to each user's personal workspace. The OAuth authorization only proves
|
|
32
|
+
> your identity for trace ingestion; it does not select a workspace.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## What it does
|
|
36
|
+
|
|
37
|
+
1. **Authorization** — Checks `~/.cozeloop/credentials.json` for a cached OAuth token.
|
|
38
|
+
- Token valid → skip authorization, proceed.
|
|
39
|
+
- Token expiring (< 10 min) → silently refresh via `refresh_token`.
|
|
40
|
+
- No token / refresh failed → launches Device Code OAuth flow: opens browser, displays verification URL, polls until user approves.
|
|
41
|
+
2. **Agent detection** — Verifies the specified agent binary is installed locally.
|
|
42
|
+
3. **Environment checks** — Python ≥ 3.8 + `cozeloop` SDK (Claude Code & Codex only; SDK auto-installed via pip if missing), agent version whitelist check.
|
|
43
|
+
4. **Hook configuration** — Writes hook scripts and config files for the selected agent.
|
|
44
|
+
|
|
45
|
+
## Per-agent hook files
|
|
46
|
+
|
|
47
|
+
| Agent | Hook script | Config file | Credentials |
|
|
48
|
+
|-------|------------|-------------|-------------|
|
|
49
|
+
| `claude-code` | `~/.claude/hooks/cozeloop_hook.py` | `~/.claude/settings.json` | `.claude/settings.local.json` (project-scoped) |
|
|
50
|
+
| `codex` | `~/.codex/hooks/cozeloop_hook.py` | `~/.codex/hooks.json` | `~/.codex/hooks/cozeloop.env` |
|
|
51
|
+
| `openclaw` | — (Node.js plugin) | `~/.openclaw/openclaw.json` | inline in config |
|
|
52
|
+
|
|
53
|
+
## Token lifecycle
|
|
54
|
+
|
|
55
|
+
OAuth tokens are stored in `~/.cozeloop/credentials.json` (mode 600).
|
|
56
|
+
|
|
57
|
+
**At hook execution time** (Claude Code / Codex), the Python hook script automatically:
|
|
58
|
+
1. Reads `~/.cozeloop/credentials.json`
|
|
59
|
+
2. If the token expires in < 10 minutes, calls the Coze refresh API
|
|
60
|
+
3. Updates `credentials.json` with the new token
|
|
61
|
+
4. Passes the fresh token to the CozeLoop SDK before uploading traces
|
|
62
|
+
|
|
63
|
+
This means traces continue to upload without interruption even across token expiry, as long as the refresh token is still valid.
|
|
64
|
+
|
|
65
|
+
**For OpenClaw**, the token is read from `openclaw.json` at startup. Re-run `npx @cozeloop/onboard --agent=openclaw` to refresh it if OpenClaw reports auth errors.
|
|
66
|
+
|
|
67
|
+
## Supported versions
|
|
68
|
+
|
|
69
|
+
| Agent | Supported versions |
|
|
70
|
+
|-------|--------------------|
|
|
71
|
+
| `claude-code` | 1.2.x, 1.3.x, 1.4.x, 2.0.x, 2.1.x |
|
|
72
|
+
| `codex` | 0.134.x, 1.0.x, 1.1.x |
|
|
73
|
+
| `openclaw` | 2026.3.x, 2026.4.x, 2026.5.x |
|
|
74
|
+
|
|
75
|
+
Versions outside this list will show a yellow warning but onboarding will continue.
|