|
| 1 | +# update-cacache — Update the C/C++ cacache implementation |
| 2 | + |
| 3 | +Update `socket_cacache.h` to match the `@socketsecurity/lib` cacache spec. |
| 4 | +Run when the cacache format changes or cross-platform behavior needs updating. |
| 5 | + |
| 6 | +## What This Updates |
| 7 | + |
| 8 | +| File | Location | |
| 9 | +|------|----------| |
| 10 | +| `socket_cacache.h` | `packages/build-infra/src/socketsecurity/build-infra/socket_cacache.h` | |
| 11 | + |
| 12 | +## Process |
| 13 | + |
| 14 | +1. **Read the reference spec** from `@socketsecurity/lib`: |
| 15 | + - Path resolution: `../socket-sdk-js/node_modules/@socketsecurity/lib/dist/paths/socket.js` |
| 16 | + - Cacache wrapper: `../socket-sdk-js/node_modules/@socketsecurity/lib/dist/cacache.js` |
| 17 | + - Also check ultrathink implementations for consistency: |
| 18 | + - Rust: `../ultrathink/packages/acorn/lang/rust/src/socket_cacache.rs` |
| 19 | + - Go: `../ultrathink/packages/acorn/lang/go/pkg/acorn/socket_cacache.go` |
| 20 | + |
| 21 | +2. **Update `socket_cacache.h`** to match: |
| 22 | + - Path resolution: env var priority (SOCKET_CACACHE_DIR > SOCKET_HOME > HOME/USERPROFILE > tmpdir) |
| 23 | + - Index: `index-v5/{sha256(key)[0:2]}/{sha256(key)[2:4]}/{sha256(key)[4:]}` |
| 24 | + - Lines: `{sha1(json)}\t{json}\n` |
| 25 | + - Content: `content-v2/sha512/{sha512_hex[0:2]}/{sha512_hex[2:4]}/{sha512_hex[4:]}` |
| 26 | + - Integrity: `sha512-{base64_with_padding(sha512(data))}` |
| 27 | + - Deletion: append `"integrity":null` (soft delete, not file delete) |
| 28 | + - Metadata: always present as `{}` (never null, never omitted) |
| 29 | + |
| 30 | +3. **Cross-platform validation**: |
| 31 | + - macOS: HOME → getenv("HOME"), crypto via CommonCrypto |
| 32 | + - Linux: HOME → getenv("HOME"), crypto via OpenSSL |
| 33 | + - Windows: USERPROFILE → getenv("USERPROFILE"), crypto via CryptoAPI |
| 34 | + - Fallback: TEMP/TMP (Windows) or /tmp (Unix) |
| 35 | + |
| 36 | +4. **Compile test**: |
| 37 | + ```bash |
| 38 | + # macOS |
| 39 | + cc -Wall -Wextra -I. test.c -o test -framework Security |
| 40 | + |
| 41 | + # Linux |
| 42 | + cc -Wall -Wextra -I. test.c -o test -lssl -lcrypto |
| 43 | + ``` |
| 44 | + |
| 45 | +5. **Cross-language verification**: |
| 46 | + ```bash |
| 47 | + # C writes, Node.js reads |
| 48 | + ./test_write |
| 49 | + node -e "require('cacache').get('~/.socket/_cacache', 'key').then(r => console.log(r.data))" |
| 50 | + ``` |
| 51 | + |
| 52 | +6. **Run Codex sanity check** — ask Codex to validate against spec. |
| 53 | + |
| 54 | +7. **Commit** with: `fix(build-infra): update socket_cacache.h to match @socketsecurity/lib vX.Y.Z` |
| 55 | + |
| 56 | +## Key Constraints |
| 57 | + |
| 58 | +- Header-only C (static functions) — no .c file needed |
| 59 | +- `extern "C"` wrappers for C++ inclusion |
| 60 | +- No external deps beyond platform crypto |
| 61 | +- Self-contained file I/O helpers (no file_utils.h dependency) |
| 62 | +- Internal functions prefixed `scache_` to avoid namespace collisions |
| 63 | +- Must produce entries readable by Node.js `cacache@20` |
| 64 | + |
| 65 | +## Reference Docs |
| 66 | + |
| 67 | +- Shared cache guide: `../ultrathink/packages/build-infra/docs/shared-cache.md` |
| 68 | +- Platform dirs: `../ultrathink/packages/build-infra/lib/platform-dirs.mjs` |
0 commit comments