Repository navigation
feat(syntropy): KG-direct tools — 3 kg-mcp tools + 16 new tests (SYN-33 Phase C+D) - #21
Merged
Merged
Conversation
ADR-001-aligned Bearer-auth HTTP client to shrine-diet-bioactivity kg-mcp. Uses the same sj_* ApiToken (from Supabase Vault via openclaw#13) the extension already manages for SJ MCP. No new token type, no broker. Tests (mirror client.test.ts pattern + 1 new): - JSON-RPC envelope shape + Bearer auth header - MCP content array unwrap (JSON + plain text) - JSON-RPC error envelope surfaces error message - HTTP non-OK returns status + body - Network failure returns error - Raw JSON-RPC result fallback (no content array) - ADR-001 §5 paywall response shape passes through unchanged Result: 8/8 tests pass. Part of SYN-33 / SH-Apps#64 Phase C — extension client. Hand-rolled result type for now; KG response codegen comes from Phase A.
3 KG-direct MVP tool factories per SYN-33 plan-of-record: - kg_food_to_bioactives (Food → Bioactives lookup) - kg_compound_lookup (Compound canonical profile + dosage range) - kg_contraindication_check (Multi-pair supplement × medication check) Each tool: - Hand-rolled TypeBox schema (codegen from Phase A schemas will replace) - scope='diet_kg:read' manifest tag (#55 manifest plan contract) - Calls callKgTool with the user's sj_* Bearer (ADR-001 §2) - Renders kg-mcp response (incl. paywall) via standard toAgentResult path Tests assert: 3 tools registered, canonical names, scope tag wired, TypeBox object schemas present, non-empty labels + descriptions. Result: 4/4 tests pass. Part of SYN-33 / SH-Apps#64 Phase D — manifest yamls land separately once the manifest-driven generator from PR #55 stabilizes. The hand-rolled schemas here are the same pattern tools.ts used pre-#14 for MealTypeSchema — OK to ship as-is per the plan-of-record's deferred-codegen note.
config.ts: - Add optional kgBaseUrl + enableKgDirect to ConfigSchema (TypeBox) - Pass through to parseSyntropyConfig return; absent stays absent so downstream can distinguish 'not configured' from 'opted out' - URL validation on kgBaseUrl mirrors syntropyBaseUrl pattern config.test.ts: - 4 new tests: optional absence, wired-through value, URL validation, explicit enableKgDirect=false preserved index.ts: - Import createAllKgTools - Compute kgEnabled = kgBaseUrl !== undefined && enableKgDirect !== false - registerTool callback merges sjTools + kgTools (when enabled) - Startup log shows kg=enabled/disabled state for ops visibility ADR-001 alignment: - Same sj_* Bearer passed to both SJ MCP + kg-mcp (no token exchange) - No metering code in extension; kg-mcp does atomic quota_check_and_debit on its side (ADR-001 §5) Suite total: 80 passed / 3 skipped / 0 failed (was 64 from #15+#20 → now 64 + 8 kg-client + 4 kg-tools + 4 new config = 80) Note: index.ts lifecycle has no direct test (pre-existing gap from #15 plan-of-record §What's still open). Tracked as follow-up. The feature flag (kgEnabled) is computed via config tests; the tool-merge path is covered transitively via kg-tools.test.ts.
…+ paywall (LIVE-gated) 4 new LIVE-gated tests on top of the existing /health probes: - kg_food_to_bioactives round-trip - kg_compound_lookup round-trip - kg_contraindication_check round-trip - ADR-001 §5 paywall shape (requires SJ_TEST_PAYWALL_TOKEN — separate describe so it skips independently if the test-only 0τ user isn't provisioned) Total: 7 LIVE-gated tests (3 existing + 4 new), all skip cleanly without LIVE=1. Standard /health probe + improved status-then-body assertion (skip body fetch on 200 — avoids the small wasted round-trip from openclaw#20 review). Per the SYN-33 plan, this Phase E delivery is intentionally a *smoke* probe — kg-mcp's own test suite (lives in shrine-diet-bioactivity, Phase B work) owns response-shape correctness. We just verify the contract surface from the consumer side. Final suite: 80 passed / 3 skipped (LIVE) → with this commit 80 passed / 7 skipped (LIVE). Run: pnpm test:extensions
|
The formal models extracted constants ( This check is informational (not blocking merges yet). If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements SYN-33 Phase C+D (SH-Apps#64) — the openclaw-extension side of the KG-direct tools plan. ADR-001-aligned: extension uses the same `sj_*` ApiToken (from Supabase Vault via openclaw#13) the existing 9 SJ tools use; kg-mcp does atomic `quota_check_and_debit` server-side per ADR-001 §5; no second token type, no broker.
Built via 4 TDD cycles, one commit per cycle.
TDD cycle log
Each cycle: write failing test → run vitest (RED on cycles 1 & 2) → implement minimal code → run vitest → GREEN → commit.
3 KG-direct MVP tools
All three carry `scope=diet_kg:read` (manifest-driven authz hint per PR #55).
ADR-001 alignment
Feature-flag behavior
The `tools.registerTool` callback now returns `[...sjTools, ...kgTools]` when enabled, so the agent sees both surfaces atomically — no flicker, no half-state.
Test results
```
Test Files 8 passed | 1 skipped (9)
Tests 80 passed | 3 skipped (83)
Duration 1.2s
```
Excluded from local run: `vault.test.ts` (env-side missing `@supabase/supabase-js` in my symlinked node_modules; passes on CI with fresh `pnpm install`).
Coverage matrix vs SYN-33 plan
Follow-ups not in this PR
Test plan for reviewer
Cross-references