16 Commits

Author SHA1 Message Date
xiaomo 9787bb7f39 feat: unified invoke endpoint — sigil.* builtin capabilities (refs #1)
- Add POST /_api/invoke unified entry point for all capabilities
- Support builtin sigil.* capabilities: discover, deploy, remove, inspect, list, status
- External capabilities routed through backend.invoke() as before
- Comprehensive test coverage in s14-unified-invoke.test.ts
- All existing routes preserved for backward compatibility
- Error handling for invalid JSON and missing capability field
2026-04-18 07:18:15 +00:00
xiaoju 69507fa766 feat: AMD风格 capability 组合功能
- 新增  字段支持依赖声明(KvMetaValue、DeployParams)
- 新增 generateWorkerCodeWithDeps() 函数,支持依赖注入 codegen
- 实现递归依赖解析,自动 bundle 依赖代码到主 capability
- 循环依赖检测,防止无限递归
- execute 函数签名扩展为 (input, deps) => result
- 依赖包装为 async (params?) => result 函数
- 支持 schema 参数解析 for 依赖
- 向后兼容:无依赖 capability 不受影响
- 12个测试用例覆盖:基本依赖、多依赖、链式依赖、循环检测、兼容性、API集成

小橘 🍊 (NEKO Team)
2026-04-03 23:17:38 +00:00
xiaoju d80cc1b9e0 security: require auth token for all API endpoints except health — 小橘 🍊
- query, inspect, invoke now require Authorization: Bearer token
- Only /_health remains public (monitoring/uptime checks)
- Data sovereignty: CF resources belong to the user, no anonymous access
2026-04-03 11:54:02 +00:00
xiaoju e86bae8d4a refactor: migrate to Dynamic Workers — fix /run/{name} 404
Root cause: CF blocks Worker-to-Worker fetch on workers.dev (error 1042).
Gateway Worker could not proxy requests to child worker subdomains.

Fix: Replace CF API worker scripts with Dynamic Workers (LOADER binding).
- deploy() writes code to KV only, no CF API calls
- invoke() uses LOADER.get(id, fn) to execute code inline
- remove() clears KV only, no CF API delete
- Removed cf-api.ts, slot management, subdomain routing
- 67/67 tests passing, production verified

Reported-by: 小墨 🖊️ (KUMA)
小橘 🍊(NEKO Team)
2026-04-03 10:57:50 +00:00
xiaoju 9f0c303056 feat: pre-allocated slot pool — zero DNS latency
- Pre-create fixed Worker slots (s-slot-0, s-slot-1, s-slot-2)
- Deploy/page-in only updates slot code, no Worker create/delete
- Subdomain always active, zero DNS propagation delay
- Slot = physical page frame, capability = virtual page
- New endpoint: POST /_api/init-slots
- Clean up old dynamic Worker naming
- 73/73 tests pass
2026-04-03 10:37:47 +00:00
xiaoju 49fb9a8c76 feat: Dynamic Workers LOADER — zero latency invoke — 小橘 🍊
- Replace child Worker subdomain routing with CF Dynamic Workers LOADER
- Code executes inline in Sigil Worker process, no DNS propagation needed
- Deploy → invoke immediately, zero delay
- LOADER.get() caches warm instances by capability+hash
- Remove cf-api.ts (no more child Worker management)
- All 67 tests passing
2026-04-03 10:13:59 +00:00
xiaoju 09e710101d fix: complete Dynamic Workers migration — all 68 tests pass — 小橘 🍊 2026-04-03 09:49:52 +00:00
xiaoju 120e62d7e4 fix: restore missing KV route methods and getWorkerName helper
- Added back KvStore.getRoute/setRoute/deleteRoute methods
- Added back WorkerPool.getWorkerName() private method
- Fixed deploy() to properly set route.worker_name with prefix

Tests passing: 56/68 (82%)
2026-04-03 09:43:19 +00:00
xiaoju ce4c2b7b36 refactor: migrate from CF API worker scripts to Dynamic Workers — 小橘 🍊
- Added worker_loaders binding (LOADER) to wrangler.toml
- Updated WorkerPool to use LOADER.get() instead of CF API deploy/delete
- Removed subdomain-based invoke; now uses Dynamic Workers directly
- Cleaned up config.ts (removed SUBDOMAIN_SUFFIX, PAGE_RATE_LIMIT)
- Simplified cf-api.ts to legacy cleanup only (LegacyCfApi)
- Updated all tests to use createMockLoader instead of createMockCfApi
- Removed PageRateLimitError (no longer needed)
- All API endpoints unchanged; migration is internal implementation only
2026-04-03 09:41:13 +00:00
xiaoju 3709fae5e1 fix: /run/{name} → 302 redirect, bypass CF same-zone fetch limitation
CF Workers cannot fetch() other workers on the same .workers.dev zone.
This caused all /run/{name} routes to return Cloudflare's HTML 404
instead of proxying to the sub-worker.

Fix: replace inline fetch() proxy with a redirect-based approach:
- Default (browser/curl): 302 redirect to sub-worker URL
- Accept: application/json: return JSON with {url, capability, cold_start}

LRU bookkeeping (page-in, access count) still happens in Sigil before
the redirect, so cold capabilities are warmed up transparently.

New backend method: resolveInvoke() — same LRU/page-in logic as invoke()
but returns route info instead of executing the subrequest.

Fixes: https://sigil.shazhou.workers.dev/run/* returning CF 404
Reported-by: 小墨 🖊️
2026-04-03 09:15:58 +00:00
xiaoju fd210c0edd feat: schema + execute abstraction for Agent-friendly deploy
- Agent provides schema (JSON Schema) + execute (function body)
- Sigil auto-generates full Worker code via codegen.ts
- Input parsing: GET query params + POST JSON body, auto type conversion
- Required field validation, default values
- find mode returns schema so Agent knows how to call
- Backward compatible: raw code deploy still works
2026-04-03 08:34:49 +00:00
xiaoju c3f3b822f1 feat: embedding semantic search + MMR for explore
- Use CF Workers AI bge-base-en-v1.5 for embeddings
- Deploy stores capability embedding in KV
- Query uses cosine similarity (find) and MMR (explore)
- Query embedding cached in KV (1h TTL)
- Fallback to string matching for capabilities without embeddings
- Mock embedding service for unit tests
2026-04-03 08:16:27 +00:00
xiaoju 513e84622c feat: unified query API + deploy metadata
- Add description/tags/examples to deploy params
- Replace /_api/list with /_api/query (public, no auth)
- find mode: precise, detailed, default limit=3
- explore mode: diverse, summary, default limit=20
- Relevance scoring + tag-based dedup for explore
- Delete old list endpoint
2026-04-03 08:02:09 +00:00
xiaoju 3705b158bb refactor: simplify to user-level shared capabilities
- Remove agent isolation (data sovereignty belongs to user, not agent)
- Capability naming: ping instead of xiaoju--ping
- Route: /run/{capability} instead of /{agent}/{capability}
- Auth: single deploy-token instead of per-agent tokens
- Delete S10 test (agent isolation no longer exists)
- Clean up old agent-prefixed workers
2026-04-03 05:49:20 +00:00
xiaoju b8b00f235e fix: enforce page-rate-limit on all invoke→page_in paths; loop eviction to prevent used_slots>total_slots; clamp status used_slots; fix S07 test to respect MAX_SLOTS=3 2026-04-03 05:42:03 +00:00
xiaoju f20b19a71e feat: implement Sigil Phase 1 MVP 🔮
- Wrangler project setup (TypeScript + Vitest)
- SigilBackend interface + WorkerPool implementation
- KV store with layered key schema (code/meta/lru/route/auth/stats)
- LRU scheduler with eviction priority (ephemeral_expired > ephemeral > normal > persistent)
- AuthModule: Bearer token validation, agent isolation, deploy cooldown
- Router: /_health, /_api/deploy, /_api/remove, /_api/list, /_api/inspect, /{agent}/{capability}
- 13 test scenarios, all passing (38 tests)
- MockKV + MockCfApi for isolated testing

Tests: 38/38  | Build: 22KB gzip:5KB 

小橘 🍊(NEKO Team)
2026-04-03 04:17:43 +00:00