11#!/usr/bin/env bun
22import { existsSync , readFileSync } from 'node:fs' ;
3+ import { homedir } from 'node:os' ;
34import { resolve } from 'node:path' ;
5+ import Ajv from 'ajv' ;
46
57type Baseline = {
68 dependencies : Record < string , string > ;
@@ -14,6 +16,7 @@ function main() {
1416 const cwd = process . cwd ( ) ;
1517 const baselinePath = resolve ( cwd , 'deps-baseline.json' ) ;
1618 const packagePath = resolve ( cwd , 'package.json' ) ;
19+ const contextSchemaPath = resolve ( cwd , 'schemas' , 'wallet-context.v1.schema.json' ) ;
1720
1821 if ( ! existsSync ( baselinePath ) ) {
1922 console . error ( `[deps:check] missing deps-baseline.json at ${ baselinePath } ` ) ;
@@ -44,8 +47,31 @@ function main() {
4447 }
4548 }
4649
50+ const contextPath =
51+ process . env . PORTKEY_SKILL_WALLET_CONTEXT_PATH ||
52+ resolve ( homedir ( ) , '.portkey' , 'skill-wallet' , 'context.v1.json' ) ;
53+ if ( ! existsSync ( contextSchemaPath ) ) {
54+ failures . push ( `missing wallet-context schema: ${ contextSchemaPath } ` ) ;
55+ } else if ( existsSync ( contextPath ) ) {
56+ try {
57+ const schema = readJson < Record < string , unknown > > ( contextSchemaPath ) ;
58+ const contextRaw = readJson < Record < string , unknown > > ( contextPath ) ;
59+ const ajv = new Ajv ( { allErrors : true , strict : false } ) ;
60+ const validate = ajv . compile ( schema ) ;
61+ if ( ! validate ( contextRaw ) ) {
62+ const details = ( validate . errors || [ ] )
63+ . map ( ( err ) => `${ err . instancePath || '/' } ${ err . message || 'invalid' } ` )
64+ . join ( '; ' ) ;
65+ failures . push ( `wallet-context schema validation failed (${ contextPath } ): ${ details } ` ) ;
66+ }
67+ } catch ( error ) {
68+ const message = error instanceof Error ? error . message : String ( error ) ;
69+ failures . push ( `wallet-context parse/validation failed: ${ message } ` ) ;
70+ }
71+ }
72+
4773 if ( failures . length > 0 ) {
48- console . error ( '[deps:check] dependency baseline mismatch :' ) ;
74+ console . error ( '[deps:check] check failed :' ) ;
4975 for ( const failure of failures ) {
5076 console . error ( `- ${ failure } ` ) ;
5177 }
0 commit comments