Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
# `@suaveplan/api-secrets-worker-proxy` — worker-side proxy to main-process secrets adapter
**Package**: `@suaveplan/api-secrets-worker-proxy`
**Status**: PROPOSED
**Type**: new-package
**Stage**: 3 (Worker isolation infrastructure)
## Why
Per design doc §5.2a, every capability ships a proxy surface. Secrets are unusually sensitive: a worker reading a value it didn't manifest is a security incident. So the main-side adapter does the allow-check before the value crosses the wire (design doc §5.2b sandboxed gating), and this proxy is the worker-side transport. The proxy MUST NEVER cache a secret value in the worker heap beyond the immediate caller's scope — that's the proxy's job to enforce by not exposing any internal storage.
## What changes
Net-new package.
**ADDED exports:**
- `./client` — `createSecretsProxyClient(port): WorkerProxyOf<SecretsLike>`. Worker-side `ctx.secrets.get(name)` → main-side allow-check + read → marshalled value.
- `./error-codes` — `SECRETS_PROXY_*` codes (`SECRETS_PROXY_NOT_MANIFESTED`, `SECRETS_PROXY_NOT_FOUND`, `SECRETS_PROXY_PORT_CLOSED`).
- `./testing` — paired `MessageChannel` + stub main-side server.
## Out of scope
- **Manifest allowlist enforcement** — main-side per §5.2b.
- **Concrete secrets source** — `api-secrets-env` / `api-secrets-bun` / `api-secrets-vault` are Stages 4 / 8.
- **Secret rotation hooks** — not in foundation scope.
## Source mapping
Genesis-original. Design doc sections: §5.2a, §5.2b.
| Requirement | Design doc section |
|---|---|
| Proxy over abstract `SecretsLike` | §5.2 |
| Non-manifested key rejected main-side | §5.2b |
| No worker-side caching of values | §5.2a (cloneable boundary) |
## Verification approach
- `src/client/client.test.ts` — manifested key returns value; non-manifested throws `SECRETS_PROXY_NOT_MANIFESTED`.
- `src/client/no-cache.test.ts` — calling `get(name)` twice issues two main-side calls (no worker-side caching).
- `tests/conformance/run-secrets-conformance.test.ts` — `runSecretsConformance` from `@suaveplan/api-secrets/testing` passes. **Required before Stage 4 can complete.**
## Migration impact
None — additive only.

View File

@@ -0,0 +1,52 @@
<!-- markdownlint-disable MD024 -->
# Capability Spec Delta: api-secrets-worker-proxy (api-secrets-worker-proxy)
**Package**: `@suaveplan/api-secrets-worker-proxy`
**Status**: PROPOSED
> Every requirement below carries a `**Verified by:**` line at authoring time.
## ADDED Requirements
### Requirement: Proxy preserves SecretsLike surface and forwards every call to main
The package SHALL expose `createSecretsProxyClient(port)` returning a `WorkerProxyOf<SecretsLike>`. Every method call SHALL be marshalled to the main process — there MUST be no worker-side cache of secret values, neither in module state nor in client-instance state. Two sequential `get("X")` calls MUST produce TWO main-side RPC invocations (so a rotated secret is picked up immediately AND a compromised worker cannot exfiltrate cached values).
#### Scenario: two gets produce two RPC calls
- **WHEN** worker code calls `ctx.secrets.get("X")` twice in succession
- **THEN** the stub main-side server records two distinct receive events
**Verified by:** `src/client/no-cache.test.ts::"two gets produce two main-side RPC calls"`
---
### Requirement: Non-manifested key throws reconstructed SECRETS_PROXY_NOT_MANIFESTED
The package SHALL surface main-side rejection of non-manifested keys as `SECRETS_PROXY_NOT_MANIFESTED` reconstructed via `api-worker-rpc`'s error-reconstruction. Manifested keys whose value is absent in the configured source MUST surface as `SECRETS_PROXY_NOT_FOUND` — the two cases are distinct so the operator can tell "your plugin didn't declare this" from "your plugin declared it but the source is missing it."
#### Scenario: non-manifested key is rejected
- **WHEN** worker code calls `ctx.secrets.get("NOT_DECLARED")`
- **THEN** the call rejects with `SuaveplanError` of code `SECRETS_PROXY_NOT_MANIFESTED`
#### Scenario: manifested-but-absent key surfaces SECRETS_PROXY_NOT_FOUND
- **WHEN** the manifest declares `STRIPE_KEY` but the source has no value AND worker calls `ctx.secrets.get("STRIPE_KEY")`
- **THEN** the call rejects with `SECRETS_PROXY_NOT_FOUND`
**Verified by:** `src/client/client.test.ts::"non-manifested key rejects"` AND `src/client/not-found.test.ts::"manifested-but-absent key surfaces NOT_FOUND"`
---
### Requirement: Conformance suite passes against this proxy
The package SHALL be runnable as the surface argument to `runSecretsConformance` from `@suaveplan/api-secrets/testing`. Every scenario MUST pass identically to a direct in-process adapter. This is the Stage-4-precondition gate.
#### Scenario: runSecretsConformance passes
- **WHEN** `runSecretsConformance("worker-proxy", makeFactory)` runs
- **THEN** every scenario passes
**Verified by:** `tests/conformance/run-secrets-conformance.test.ts::"runSecretsConformance passes against proxy"`

View File

@@ -0,0 +1,66 @@
# Tasks — `@suaveplan/api-secrets-worker-proxy`
> Every checkbox MUST reflect work actually done in this change.
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Spec authoring
- [x] 1.1 Read design doc §5.2, §5.2a, §5.2b
- [x] 1.2 Read umbrella
- [x] 1.3 Read `openspec/AGENTS.md` Sections 13 and 14
- [x] 1.4 Draft `proposal.md`
- [x] 1.5 Draft `specs/api-secrets-worker-proxy/spec.md`
- [ ] 1.6 Every requirement carries `**Verified by:**`
## 2. Implementation
- [ ] 2.1 Scaffold `packages/api/api-secrets-worker-proxy/` (`0.1.0`, deps: `@suaveplan/api-worker-rpc`, `@suaveplan/api-types`, `@suaveplan/error`, `zod`; peer-dep on `@suaveplan/api-secrets`)
- [ ] 2.2 `src/client/` — typed proxy client; explicit no-cache invariant
- [ ] 2.3 `src/error-codes.ts` — `SECRETS_PROXY_*` codes
- [ ] 2.4 `src/testing/` — paired `MessageChannel` + stub server
- [ ] 2.5 `src/index.ts` — namespace re-exports
## 3. Tests
- [ ] 3.1 `src/client/client.test.ts` — manifested key returns value; non-manifested throws `SECRETS_PROXY_NOT_MANIFESTED`
- [ ] 3.2 `src/client/no-cache.test.ts` — two `get(name)` calls produce two main-side RPC calls (no caching)
- [ ] 3.3 `src/client/not-found.test.ts` — manifested but absent key throws `SECRETS_PROXY_NOT_FOUND`
- [ ] 3.4 `tests/conformance/run-secrets-conformance.test.ts` — `runSecretsConformance` passes
- [ ] 3.5 Every `it(...)` carries `{ timeout: 5000 }`
## 4. Documentation
- [ ] 4.1 Sibling `.md` per `.ts` (≥200 words)
- [ ] 4.2 README links every co-located `.md`; explicit no-cache invariant called out
- [ ] 4.3 Update CLAUDE.md
## 5. Pre-archive verification (the 5-gate triple)
- [ ] 5.1 `bun run check` — Biome 0/0/0
- [ ] 5.2 `bunx turbo lint typecheck test --filter=@suaveplan/api-secrets-worker-proxy` — green
- [ ] 5.3 `bunx turbo test:coverage --filter=@suaveplan/api-secrets-worker-proxy` — 100/100/100/100
- [ ] 5.4 `bun scripts/openspec-conformance.ts @suaveplan/api-secrets-worker-proxy` — exit 0
- [ ] 5.5 `bunx turbo build --filter=@suaveplan/api-secrets-worker-proxy` — green
- [ ] 5.6 **Stage-4 conformance gate**: `runSecretsConformance` (from `@suaveplan/api-secrets/testing`) MUST pass under both direct AND worker-proxy surface before Stage 4 can complete
## 6. Pre-archive 7-row checklist
- [ ] 6.1 Generics — `SecretsLike` shape preserved
- [ ] 6.2 Zod at wire boundary
- [ ] 6.3 Every `SECRETS_PROXY_*` code thrown
- [ ] 6.4 Strict-mode behaviors — no-cache invariant tested explicitly
- [ ] 6.5 OTel — N/A here; main-side adapter emits secret-access counters
- [ ] 6.6 Lifecycle dedup — N/A
- [ ] 6.7 No retroactive tick
## 7. Archive
- [ ] 7.1 Fold spec delta into `openspec/specs/api-secrets-worker-proxy/spec.md`
- [ ] 7.2 Move to `openspec/archive/<yyyy-mm-dd>-api-secrets-worker-proxy/`
- [ ] 7.3 Tick Stage-3 row in umbrella
- [ ] 7.4 Refresh `MANIFEST.md`