@routinecrew/routinecode 2.31.85 → 2.31.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.sh +10 -0
- package/bin/prompt-vault.dat +1 -1
- package/bin/rc-board.js +58 -0
- package/bin/rc-skills.js +31 -0
- package/bin/setup.js +1 -1
- package/hooks/hooks-config.json +10 -1
- package/hooks/lib/agent_telemetry.py +143 -0
- package/hooks/lib/attest_reader.py +16 -1
- package/hooks/lib/board-golden.json +268 -0
- package/hooks/lib/board.py +503 -0
- package/hooks/lib/board_sync.py +535 -0
- package/hooks/lib/completion_log.py +12 -5
- package/hooks/lib/config_bash_track.py +14 -26
- package/hooks/lib/config_guard.py +133 -4
- package/hooks/lib/design_pick_nudge.py +86 -0
- package/hooks/lib/edit_tracker.py +182 -0
- package/hooks/lib/i18n.py +62 -20
- package/hooks/lib/knowledge_items.py +74 -8
- package/hooks/lib/usage_v2.py +12 -0
- package/hooks/post-agent-return.sh +5 -0
- package/hooks/post-edit-track.sh +19 -28
- package/hooks/post-orch-decision.sh +17 -0
- package/hooks/pre-account-guard.sh +1 -1
- package/hooks/pre-agent-spawn.mjs +1 -1
- package/hooks/pre-agent-spawn.sh +12 -0
- package/hooks/pre-credit-guard.sh +1 -1
- package/hooks/pre-edit-board.sh +44 -0
- package/hooks/pre-edit-check.sh +27 -3
- package/hooks/pre-mark-complete.sh +71 -15
- package/hooks/session-start.sh +62 -3
- package/hooks/skill-knowledge.sh +6 -0
- package/hooks/user-prompt-submit.sh +9 -0
- package/mcp-plan-manager/dist/file-ops.js +1 -1
- package/mcp-routinecode/dist/board.js +1 -0
- package/mcp-routinecode/dist/build-id.js +1 -0
- package/mcp-routinecode/dist/changeset.js +1 -1
- package/mcp-routinecode/dist/config-auth.js +1 -1
- package/mcp-routinecode/dist/config-map/applied.js +1 -0
- package/mcp-routinecode/dist/config-map/arch-graph.js +1 -1
- package/mcp-routinecode/dist/config-map/architect-store.js +1 -7
- package/mcp-routinecode/dist/config-map/audit-cli.js +1 -1
- package/mcp-routinecode/dist/config-map/audit.js +1 -1
- package/mcp-routinecode/dist/config-map/blocks.js +1 -1
- package/mcp-routinecode/dist/config-map/convention-candidates.js +1 -1
- package/mcp-routinecode/dist/config-map/decisions.js +1 -1
- package/mcp-routinecode/dist/config-map/dup-safety.js +1 -1
- package/mcp-routinecode/dist/config-map/field-contract.js +1 -1
- package/mcp-routinecode/dist/config-map/hash.js +1 -1
- package/mcp-routinecode/dist/config-map/index-store.js +62 -5
- package/mcp-routinecode/dist/config-map/link.js +1 -1
- package/mcp-routinecode/dist/config-map/linked-repos.js +1 -1
- package/mcp-routinecode/dist/config-map/maintenance-cli.js +1 -1
- package/mcp-routinecode/dist/config-map/proposals.js +1 -1
- package/mcp-routinecode/dist/config-map/repo-id.js +1 -1
- package/mcp-routinecode/dist/config-map/route-security.js +1 -1
- package/mcp-routinecode/dist/config-map/rule-import.js +1 -1
- package/mcp-routinecode/dist/config-map/shape-eval.js +1 -1
- package/mcp-routinecode/dist/config-map/shape.js +1 -1
- package/mcp-routinecode/dist/config-map/snapshot.js +1 -1
- package/mcp-routinecode/dist/config-map/sole-impl.js +1 -1
- package/mcp-routinecode/dist/config-map/stable-id.js +1 -1
- package/mcp-routinecode/dist/config-map/store.js +1 -1
- package/mcp-routinecode/dist/config-map/swagger-check.js +1 -1
- package/mcp-routinecode/dist/config-map/templates.js +1 -1
- package/mcp-routinecode/dist/contracts.generated.js +1 -1
- package/mcp-routinecode/dist/coverage.js +1 -1
- package/mcp-routinecode/dist/criteria-card.js +1 -0
- package/mcp-routinecode/dist/design-judge.js +1 -0
- package/mcp-routinecode/dist/edit-tracker.js +1 -0
- package/mcp-routinecode/dist/explorer-advisor.js +1 -1
- package/mcp-routinecode/dist/failure-tracker.js +1 -1
- package/mcp-routinecode/dist/file-lock-registry.js +1 -1
- package/mcp-routinecode/dist/file-risk-scorer.js +1 -1
- package/mcp-routinecode/dist/index.js +1 -1
- package/mcp-routinecode/dist/known-solutions.js +1 -1
- package/mcp-routinecode/dist/ledger-miner.js +1 -1
- package/mcp-routinecode/dist/normalize-sig.js +1 -1
- package/mcp-routinecode/dist/observed-draft.js +1 -1
- package/mcp-routinecode/dist/observed-escalation.js +1 -0
- package/mcp-routinecode/dist/pattern-matcher.js +1 -1
- package/mcp-routinecode/dist/route-match.js +1 -1
- package/mcp-routinecode/dist/routines.js +1 -1
- package/mcp-routinecode/dist/rule-engine.js +1 -1
- package/mcp-routinecode/dist/rule-promoter.js +1 -1
- package/mcp-routinecode/dist/session-registry.js +1 -0
- package/mcp-routinecode/dist/skill-pack/sync.js +655 -0
- package/mcp-routinecode/dist/skill-pack/validate.js +278 -0
- package/mcp-routinecode/dist/test-runner.js +1 -1
- package/mcp-routinecode/dist/thinking-judge.js +1 -0
- package/mcp-routinecode/dist/verification.js +1 -1
- package/mcp-routinecode/package.json +1 -1
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/agents/analyzer.md.sealed +1 -1
- package/plugin/agents/architect.md.sealed +1 -1
- package/plugin/agents/crawler.md.sealed +1 -1
- package/plugin/agents/explorer.md.sealed +1 -1
- package/plugin/agents/implementor.md.sealed +1 -1
- package/plugin/agents/looker.md.sealed +1 -1
- package/plugin/agents/planner.md.sealed +1 -1
- package/plugin/agents/recorder.md.sealed +1 -1
- package/plugin/agents/reviewer.md.sealed +1 -1
- package/plugin/agents/verifier.md.sealed +1 -1
- package/plugin/commands/analyze.md.sealed +1 -1
- package/plugin/commands/plan.md.sealed +1 -1
- package/plugin/commands/rc.md.sealed +1 -1
- package/plugin/commands/receipt.md.sealed +1 -1
- package/plugin/commands/recharge.md.sealed +1 -1
- package/plugin/commands/routines.md.sealed +1 -1
- package/plugin/commands/share.md.sealed +1 -1
- package/plugin/routinecode-prompt.md.sealed +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as a17a from'fs';import*as a17b from'path';import{ts}from'ts-morph';import{Resolver}from'./link.js';import{splitIdentifier,singularize}from'./ident-norm.js';const NON_PRODUCT=/(^|\/)(tests?|__tests__|__mocks__|e2e|fixtures?|scripts?|stories)\/|\.(test|spec|stories)\.[cm]?[jt]sx?$|\.d\.ts$/,HTTP_METHODS=new Set(['get','post','put','patch','delete','del','all','head','options','request']),PRIMS=new Set(['string','number','boolean','any','unknown','void','never','null','undefined','object','Date','Record','Object','String','Number','Boolean','Blob','File','FormData','Response']),COMMON_BACKEND=['id','createdAt','updatedAt','deletedAt','created_at','updated_at','deleted_at'],MAX_EVIDENCE=0x5;export function fieldKey(a){return splitIdentifier(a)['join']('');}function singularKey(a){return splitIdentifier(a)['map'](singularize)['join']('');}export function editDistance(c,d,e=0x3){if(Math['abs'](c['length']-d['length'])>e)return e+0x1;let f=Array['from']({'length':d['length']+0x1},(g,h)=>h);for(let g=0x1;g<=c['length'];g++){const h=[g];let k=g;for(let l=0x1;l<=d['length'];l++){h[l]=Math['min'](f[l]+0x1,h[l-0x1]+0x1,f[l-0x1]+(c[g-0x1]===d[l-0x1]?0x0:0x1));if(h[l]<k)k=h[l];}if(k>e)return e+0x1;f=h;}return f[d['length']];}export function matchField(a,b){const c=fieldKey(a),d=Array['from'](b);if(d['some'](i=>fieldKey(i)===c))return{'kind':'exact'};const e=singularKey(a),g=d['filter'](i=>singularKey(i)===e)['sort']();if(g['length'])return{'kind':'near','name':g[0x0],'nearKind':'plural'};const h=c['length']>=0x6?0x2:c['length']>=0x4?0x1:0x0;if(h){const i=d['filter'](l=>{const m=fieldKey(l);return m['length']>=0x4&&editDistance(c,m,h)<=h;}),j=Array['from'](new Set(i))['sort']();if(j['length']===0x1)return{'kind':'near','name':j[0x0],'nearKind':'edit'};}return{'kind':'none'};}class SourceCache{['read'];['parsed']=new Map();constructor(a){this['read']=a;}['get'](a,b){const c=a['name']+'\x00'+b;if(this['parsed']['has'](c))return this['parsed']['get'](c);let d=null;try{const e=this['read'](a['name'],b)??((()=>{try{return a17a['readFileSync'](a17b['join'](a['root'],b),'utf8');}catch{return null;}})());if(e!=null)d=ts['createSourceFile'](b,e,ts['ScriptTarget']['Latest'],!![],/\.[jt]sx$/['test'](b)?ts['ScriptKind']['TSX']:/\.[cm]?js$/['test'](b)?ts['ScriptKind']['JS']:ts['ScriptKind']['TS']);}catch{d=null;}return this['parsed']['set'](c,d),d;}}const lineOf=(a,b)=>a['getLineAndCharacterOfPosition'](b)['line']+0x1,propName=a=>{if(!a)return null;if(ts['isIdentifier'](a)||ts['isStringLiteral'](a)||ts['isNumericLiteral'](a)||ts['isPrivateIdentifier'](a))return a['text'];return null;},entityLast=a=>ts['isIdentifier'](a)?a['text']:a['right']['text'];function walk(a,b){b(a),ts['forEachChild'](a,d=>walk(d,b));}function leafTypeNames(b,c,d=0x0){if(!b||d>0x6)return;if(ts['isTypeReferenceNode'](b)){const e=entityLast(b['typeName']);if(b['typeArguments']?.['length']){if(e==='Omit'||e==='Pick'||e==='Partial'||e==='Required'||e==='Readonly'){leafTypeNames(b['typeArguments'][0x0],c,d+0x1);return;}if(e==='Record'||e==='Map')return;for(const f of b['typeArguments'])leafTypeNames(f,c,d+0x1);return;}if(!PRIMS['has'](e))c['add'](e);return;}if(ts['isArrayTypeNode'](b))return leafTypeNames(b['elementType'],c,d+0x1);if(ts['isUnionTypeNode'](b)){for(const g of b['types'])leafTypeNames(g,c,d+0x1);return;}if(ts['isParenthesizedTypeNode'](b))return leafTypeNames(b['type'],c,d+0x1);if(ts['isTypeLiteralNode'](b)&&d<0x3){for(const h of b['members'])if(ts['isPropertySignature'](h))leafTypeNames(h['type'],c,d+0x2);}}function baseNamesOfType(a,b){if(ts['isTypeReferenceNode'](a)){const c=entityLast(a['typeName']);if((c==='Omit'||c==='Pick'||c==='Partial'||c==='Required'||c==='Readonly')&&a['typeArguments']?.['length'])return baseNamesOfType(a['typeArguments'][0x0],b);if(!PRIMS['has'](c))b['push'](c);}else{if(ts['isIntersectionTypeNode'](a)){for(const d of a['types'])baseNamesOfType(d,b);}else{if(ts['isParenthesizedTypeNode'](a))baseNamesOfType(a['type'],b);}}}function collectTypeDecls(a,b,c){const d=g=>{if(!c['has'](g['name']))c['set'](g['name'],[]);c['get'](g['name'])['push'](g);},f=(g,i)=>{for(const j of g)if((ts['isPropertySignature'](j)||ts['isMethodSignature'](j))&&propName(j['name']))i['set'](propName(j['name']),lineOf(a,j['name']['getStart'](a)));};for(const g of a['statements']){if(ts['isInterfaceDeclaration'](g)){const i=new Map();f(g['members'],i);const j=[];for(const k of g['heritageClauses']??[])for(const l of k['types']){if(ts['isIdentifier'](l['expression'])){const m=l['expression']['text'];if((m==='Omit'||m==='Pick'||m==='Partial')&&l['typeArguments']?.['length'])baseNamesOfType(l['typeArguments'][0x0],j);else j['push'](m);}else{if(ts['isPropertyAccessExpression'](l['expression']))j['push'](l['expression']['name']['text']);}}d({'name':g['name']['text'],'file':b,'line':lineOf(a,g['name']['getStart'](a)),'fields':i,'bases':j,'generic':!!g['typeParameters']?.['length']});}else{if(ts['isTypeAliasDeclaration'](g)){const o=new Map(),p=[],q=r=>{if(ts['isTypeLiteralNode'](r))f(r['members'],o);else{if(ts['isIntersectionTypeNode'](r)){for(const s of r['types'])q(s);}else{if(ts['isParenthesizedTypeNode'](r))q(r['type']);else baseNamesOfType(r,p);}}};q(g['type']);if(!o['size']&&!p['length'])continue;d({'name':g['name']['text'],'file':b,'line':lineOf(a,g['name']['getStart'](a)),'fields':o,'bases':p,'generic':!!g['typeParameters']?.['length']});}}}}class TypeIndex{['byName']=new Map();['subs']=null;['one'](a){const b=this['byName']['get'](a);if(!b?.['length'])return null;if(b['length']===0x1)return b[0x0];const c=d=>Array['from'](d['fields']['keys']())['sort']()['join'](',')+'|'+d['bases']['slice']()['sort']()['join'](',');return b['every'](d=>c(d)===c(b[0x0]))?b[0x0]:null;}['fieldsOf'](a,c=new Set()){if(c['has'](a)||c['size']>0xc)return new Map();c['add'](a);const d=this['one'](a);if(!d)return null;const e=new Map();for(const g of d['bases']){const h=this['fieldsOf'](g,c);if(h){for(const [i,j]of h)e['set'](i,j);}}for(const [l,m]of d['fields'])e['set'](l,{'field':l,'declaredIn':d['name'],'file':d['file'],'line':m});return e;}['subtypesOf'](a){if(!this['subs']){const c=new Map();for(const [e,f]of this['byName'])for(const g of f)for(const h of g['bases']){if(!c['has'](h))c['set'](h,new Set());c['get'](h)['add'](e);}this['subs']=new Map();const d=i=>{if(this['subs']['has'](i))return this['subs']['get'](i);const j=new Set();this['subs']['set'](i,j);for(const k of c['get'](i)??[]){j['add'](k);for(const l of d(k))j['add'](l);}return j;};for(const i of this['byName']['keys']())d(i);}return this['subs']['get'](a)??new Set();}}function typeIndexOf(a,b){const c=new TypeIndex();for(const [d,e]of a['facts']){if(!e['typeDecls']?.['length']||NON_PRODUCT['test'](d))continue;const g=b['get'](a,d);if(g)collectTypeDecls(g,d,c['byName']);}return c;}function enclosingFunction(a){for(let b=a['parent'];b;b=b['parent']){if(ts['isFunctionDeclaration'](b)||ts['isMethodDeclaration'](b)||ts['isFunctionExpression'](b)||ts['isArrowFunction'](b))return b;}return null;}function functionName(a){if((ts['isFunctionDeclaration'](a)||ts['isMethodDeclaration'](a))&&a['name'])return propName(a['name']);const b=a['parent'];if(b&&ts['isVariableDeclaration'](b)&&ts['isIdentifier'](b['name']))return b['name']['text'];if(b&&ts['isPropertyAssignment'](b))return propName(b['name']);return null;}function responseTypesAt(b,c){let d=null;walk(b,h=>{if(d||!ts['isCallExpression'](h))return;if(lineOf(b,h['getStart'](b))!==c&&lineOf(b,h['expression']['getEnd']())!==c)return;const i=h['expression'],j=ts['isPropertyAccessExpression'](i)?i['name']['text']:ts['isIdentifier'](i)?i['text']:'';if(HTTP_METHODS['has'](j['toLowerCase']())||j==='fetch'||h['typeArguments']?.['length'])d=h;});if(!d)return null;const e=d,f=new Set();for(const h of e['typeArguments']??[])leafTypeNames(h,f);const g=enclosingFunction(e);if(g?.['type'])leafTypeNames(g['type'],f);return{'names':f,'fnName':g?functionName(g):null};}function readIndexOf(a,b){const c=new Map(),d=new Set(),e=(g,h)=>{if(!c['has'](g))c['set'](g,[]);c['get'](g)['push']({'file':b,'line':lineOf(a,h)});};return walk(a,f=>{if(ts['isIdentifier'](f))d['add'](f['text']);if(ts['isPropertyAccessExpression'](f)){const g=f['parent'];if(g&&ts['isBinaryExpression'](g)&&g['left']===f&&g['operatorToken']['kind']===ts['SyntaxKind']['EqualsToken'])return;e(f['name']['text'],f['name']['getStart'](a));}else{if(ts['isElementAccessExpression'](f)&&ts['isStringLiteral'](f['argumentExpression']))e(f['argumentExpression']['text'],f['argumentExpression']['getStart'](a));else{if(ts['isBindingElement'](f)&&f['parent']&&ts['isObjectBindingPattern'](f['parent'])){const h=propName(f['propertyName'])??propName(f['name']);if(h)e(h,f['getStart'](a));}}}}),{'byField':c,'idents':d};}function importOfLocal(a,b){for(const c of a['statements']){if(!ts['isImportDeclaration'](c)||!ts['isStringLiteral'](c['moduleSpecifier'])||!c['importClause'])continue;const d=c['moduleSpecifier']['text'],e=c['importClause'];if(e['name']?.['text']===b)return{'spec':d,'imported':'default'};const f=e['namedBindings'];if(f&&ts['isNamespaceImport'](f)&&f['name']['text']===b)return{'spec':d,'imported':'*'};if(f&&ts['isNamedImports'](f)){for(const g of f['elements'])if(g['name']['text']===b)return{'spec':d,'imported':(g['propertyName']??g['name'])['text']};}}return null;}function findFunction(a,b){let c=null;return walk(a,d=>{if(c)return;if((ts['isFunctionDeclaration'](d)||ts['isMethodDeclaration'](d))&&d['name']&&propName(d['name'])===b&&d['body'])c=d;else{if((ts['isVariableDeclaration'](d)||ts['isPropertyAssignment'](d)||ts['isPropertyDeclaration'](d))&&propName(d['name'])===b&&d['initializer']){const e=d['initializer'];if(ts['isArrowFunction'](e)||ts['isFunctionExpression'](e))c=e;}}}),c;}class ChainWalker{['m'];['cache'];['modelNames'];['maxDepth'];['resolver'];constructor(a,b,c,d){this['m']=a,this['cache']=b,this['modelNames']=c,this['maxDepth']=d,this['resolver']=new Resolver(a['root'],new Set(a['facts']['keys']()),[]);}['resolveFile'](a,b){try{const c=this['resolver']['resolve'](a,b);return c['kind']==='file'?c['rel']:null;}catch{return null;}}['shapeOfRoute'](a){const b=this['cache']['get'](this['m'],a['file']);if(!b)return null;const c=(a['method']??'')['toLowerCase']();let d=null;walk(b,j=>{if(d||!ts['isCallExpression'](j)||!ts['isPropertyAccessExpression'](j['expression']))return;const k=j['expression']['name']['text']['toLowerCase']();if(!HTTP_METHODS['has'](k)||c&&c!=='all'&&k!==c&&k!=='all')return;const l=lineOf(b,j['getStart'](b)),m=lineOf(b,j['expression']['name']['getStart'](b));if(l===a['line']||m===a['line'])d=j;});if(!d)return null;const e=d['arguments'];if(!e['length'])return null;const f={'models':new Map(),'shapeTypes':new Set(),'extraKeys':new Set(),'open':![]};let g=e[e['length']-0x1];for(let j=0x0;j<0x4&&ts['isCallExpression'](g)&&g['arguments']['length'];j++)g=g['arguments'][g['arguments']['length']-0x1];if(ts['isArrowFunction'](g)||ts['isFunctionExpression'](g))this['visitFn'](b,a['file'],g,f,0x0,new Set());else this['follow'](b,a['file'],g,f,0x0,new Set());return f;}['follow'](a,b,c,d,f,g){if(f>this['maxDepth'])return;let h=null,i=null;if(ts['isPropertyAccessExpression'](c)){i=c['name']['text'];const n=c['expression'];if(ts['isIdentifier'](n))h=n['text'];else{if(ts['isPropertyAccessExpression'](n)&&n['expression']['kind']===ts['SyntaxKind']['ThisKeyword'])h=n['name']['text'];}}else{if(ts['isIdentifier'](c))i=c['text'];}if(!i)return;let j=null;if(h){if(this['modelNames']['has'](h)){d['models']['set'](h,this['modelNames']['get'](h));return;}const o=importOfLocal(a,h)??this['importByLooseName'](a,h);if(o)j=this['resolveFile'](b,o['spec']);}else{const p=importOfLocal(a,i);if(p){j=this['resolveFile'](b,p['spec']);if(p['imported']!=='default'&&p['imported']!=='*')i=p['imported'];}else j=b;}if(!j)return;const k=j+'#'+i;if(g['has'](k))return;g['add'](k);const l=this['cache']['get'](this['m'],j);if(!l)return;const m=findFunction(l,i);if(m)this['visitFn'](l,j,m,d,f+0x1,g);}['importByLooseName'](a,b){const c=b['toLowerCase']();for(const d of a['statements']){if(!ts['isImportDeclaration'](d)||!ts['isStringLiteral'](d['moduleSpecifier'])||!d['importClause'])continue;const e=d['importClause'],f=[e['name']?.['text'],...e['namedBindings']&&ts['isNamedImports'](e['namedBindings'])?e['namedBindings']['elements']['map'](g=>g['name']['text']):[]];if(f['some'](g=>g&&g['toLowerCase']()===c))return{'spec':d['moduleSpecifier']['text'],'imported':b};}return null;}['visitFn'](a,b,c,d,e,f){if(c['type'])leafTypeNames(c['type'],d['shapeTypes']);if(!c['body'])return;walk(c['body'],g=>{if(ts['isIdentifier'](g)&&this['modelNames']['has'](g['text']))d['models']['set'](g['text'],this['modelNames']['get'](g['text']));if(ts['isTypeReferenceNode'](g))leafTypeNames(g,d['shapeTypes']);if(ts['isPropertyAssignment'](g)||ts['isShorthandPropertyAssignment'](g)||ts['isMethodDeclaration'](g)){const h=propName(g['name']);if(h)d['extraKeys']['add'](h);if(ts['isPropertyAssignment'](g)&&h==='as'&&ts['isStringLiteral'](g['initializer']))d['extraKeys']['add'](g['initializer']['text']);if(ts['isPropertyAssignment'](g)&&h==='attributes'&&ts['isArrayLiteralExpression'](g['initializer']))for(const i of g['initializer']['elements']){if(ts['isStringLiteral'](i))d['extraKeys']['add'](i['text']);else{if(ts['isArrayLiteralExpression'](i)&&i['elements'][0x1]&&ts['isStringLiteral'](i['elements'][0x1]))d['extraKeys']['add'](i['elements'][0x1]['text']);}}}if(ts['isSpreadAssignment'](g)){const j=g['expression'],l=j['getText'](a);if(!/toJSON\(\)|get\(\s*\{\s*plain\s*:\s*true\s*\}\s*\)|dataValues/['test'](l))d['open']=!![];}if((ts['isStringLiteral'](g)||ts['isNoSubstitutionTemplateLiteral'](g)||ts['isTemplateHead'](g)||ts['isTemplateMiddle'](g)||ts['isTemplateTail'](g))&&/\bselect\b/i['test'](g['text'])){d['open']=!![];for(const m of g['text']['matchAll'](/\bAS\s+"?([A-Za-z_][A-Za-z0-9_]*)"?/gi))d['extraKeys']['add'](m[0x1]);}if(ts['isCallExpression'](g)&&ts['isPropertyAccessExpression'](g['expression'])&&g['expression']['name']['text']==='query')d['open']=!![];if(ts['isCallExpression'](g)&&e<this['maxDepth']){const o=g['expression'];if(ts['isPropertyAccessExpression'](o)||ts['isIdentifier'](o))this['follow'](a,b,o,d,e,f);}});}}function modelFieldsOf(a,b){const c=new Set();let d=![];return walk(a,e=>{if(ts['isClassDeclaration'](e)&&e['name']?.['text']===b)for(const f of e['members']){if((ts['isPropertyDeclaration'](f)||ts['isGetAccessorDeclaration'](f))&&!f['modifiers']?.['some'](g=>g['kind']===ts['SyntaxKind']['StaticKeyword'])){const g=propName(f['name']);if(g)c['add'](g);}ts['isMethodDeclaration'](f)&&propName(f['name'])==='toJSON'&&(d=!![],walk(f,h=>{if((ts['isPropertyAssignment'](h)||ts['isShorthandPropertyAssignment'](h))&&propName(h['name']))c['add'](propName(h['name']));}));}if(ts['isCallExpression'](e)&&ts['isPropertyAccessExpression'](e['expression'])){const h=e['expression']['name']['text'],i=e['expression']['expression']['getText'](a),j=h==='init'&&i===b?e['arguments'][0x0]:h==='define'?e['arguments'][0x1]:undefined;if(j&&ts['isObjectLiteralExpression'](j))for(const l of j['properties']){const m=l['name']?propName(l['name']):null;if(m)c['add'](m);}}}),{'fields':c,'customJson':d};}function resourceModelName(a){const b=a['split']('/')['filter'](Boolean)['filter'](d=>!/^(api|v\d+|internal|admin|public)$/['test'](d)&&!d['startsWith'](':')&&!d['startsWith']('{')),c=b[0x0];if(!c)return null;return splitIdentifier(c)['map'](singularize)['map'](d=>d[0x0]['toUpperCase']()+d['slice'](0x1))['join']('');}const AGGREGATE_TYPE=/(List|Page|Paged|Paginated)?(Response|Result|Stats|Statistics|Summary|Comparison|Count|Counts|Overview|Metrics|Analytics|Dashboard|Report|Payload|Envelope|Data)$/,sameName=(c,d)=>fieldKey(c)===fieldKey(d)||singularKey(c)===singularKey(d);export function computeFieldContract(b,c={}){const g={},h=F=>{g[F]=(g[F]??0x0)+0x1;},i=new SourceCache(c['readSource']??(()=>undefined)),j=c['maxDepth']??0x4,l=new Map(b['map'](F=>[F['name'],F])),o=new Map(),p=F=>{let G=o['get'](F['name']);return!G&&(G=typeIndexOf(F,i),o['set'](F['name'],G)),G;},q=new Map(),t=(F,G)=>{const H=F['name']+'\x00'+G;if(!q['has'](H)){const I=i['get'](F,G);q['set'](H,I?readIndexOf(I,G):null);}return q['get'](H);},v=new Map(),w=F=>{let G=v['get'](F['name']);if(!G){G=new Map();for(const [H,I]of F['facts']){if(NON_PRODUCT['test'](H))continue;for(const J of I['models'])if(!G['has'](J['name']))G['set'](J['name'],H);}v['set'](F['name'],G);}return G;},x=new Map(),y=F=>{let G=x['get'](F['name']);return!G&&(G=new ChainWalker(F,i,w(F),j),x['set'](F['name'],G)),G;},z=new Map(),A=(F,G,H)=>{const I=F['name']+'\x00'+G['id']+'\x00'+H;if(z['has'](I))return z['get'](I);const J=[],K=y(F)['shapeOfRoute'](G),L=w(F),M=p(F),N=K?Array['from'](K['extraKeys']):[],O=(Q,R,S,T)=>{const U=new Set(COMMON_BACKEND);let V=0x0;if(L['has'](Q)){const W=i['get'](F,L['get'](Q));if(W){const X=modelFieldsOf(W,Q);for(const Y of X['fields']){U['add'](Y),V++;}if(X['customJson'])T=!![];}}for(const Z of[Q,Q+'Attributes',Q+'Attrs','I'+Q,Q+'Response',Q+'Dto',Q+'ResponseDto']){const a0=M['fieldsOf'](Z);if(a0)for(const a1 of a0['keys']()){U['add'](a1),V++;}}if(V<0x2)return null;for(const a2 of N)U['add'](a2);return{'model':Q,'file':R,'names':U,'open':T,'via':S};};if(K){const Q=Array['from'](K['shapeTypes'])['filter'](V=>L['has'](V)||M['one'](V))['sort'](),R=Array['from'](K['models']['keys']())['sort'](),S=Q['length']?Q:R,T=S['filter'](V=>sameName(V,H)),U=!T['length']&&S['length']===0x1&&!AGGREGATE_TYPE['test'](H);for(const V of T['length']?T:U?S:[]){const W=O(V,L['get'](V)??M['one'](V)?.['file']??'','chain',K['open']);W&&(W['named']=!U,J['push'](W));}}if(!J['length']){const X=resourceModelName(G['routePaths']?.[0x0]??G['routePath']??G['name']['replace'](/^\S+\s+/,'')),Y=Array['from'](L['keys']())['find'](Z=>sameName(Z,H));if(Y&&X&&sameName(Y,X)){const Z=O(Y,L['get'](Y),'name',K?.['open']??!![]);Z&&(Z['named']=!![],J['push'](Z));}}const P=J['length']?J:null;return z['set'](I,P),P;},B=new Map();let C=0x0;const D=new Set();for(const F of b){if(F['hasBackend']||c['only']&&!c['only']['has'](F['name']))continue;const G=new Map(F['cis']['map'](L=>[L['id'],L])),H=F['edges']['filter'](L=>L['type']==='http'&&G['get'](L['from'])?.['kind']==='api-call');if(!H['length'])continue;const I=p(F),J=new Map(),K=new Map();for(const [L,M]of F['facts']){if(NON_PRODUCT['test'](L))continue;for(const N of M['imports'])for(const O of N['named']){if(!J['has'](O['imported']))J['set'](O['imported'],new Set());J['get'](O['imported'])['add'](L);}for(const P of M['usages']){const Q=L+'#'+P['owner'];if(!K['has'](Q))K['set'](Q,new Set());K['get'](Q)['add'](P['local']);}}for(const R of H['sort']((S,T)=>S['from']['localeCompare'](T['from'])||S['to']['localeCompare'](T['to']))){const S=G['get'](R['from']);if(NON_PRODUCT['test'](S['file']))continue;const T=R['to']['indexOf'](':'),U=T>0x0&&l['has'](R['to']['slice'](0x0,T))?R['to']['slice'](0x0,T):null;if(!U||U===F['name']){h('same-member-route');continue;}const V=l['get'](U),W=V['cis']['find'](a0=>a0['id']===R['to']['slice'](T+0x1));if(!W){h('route-ci-missing');continue;}const X=i['get'](F,S['file']);if(!X){h('frontend-unreadable');continue;}const Y=responseTypesAt(X,S['line']);if(!Y||!Y['names']['size']){h('untyped-response');continue;}const Z=new Set();if(Y['fnName'])for(const a0 of J['get'](Y['fnName'])??[]){Z['add'](a0);const a1=F['facts']['get'](a0);if(!a1)continue;for(const a2 of a1['decls'])if(a2['exported']&&K['get'](a0+'#'+a2['name'])?.['has'](Y['fnName'])){for(const a3 of J['get'](a2['name'])??[])Z['add'](a3);}}for(const a4 of Array['from'](Y['names'])['sort']()){const a5=I['fieldsOf'](a4);if(!a5){h(I['byName']['has'](a4)?'ambiguous-type':'type-not-found');continue;}if(I['one'](a4)?.['generic']){h('generic-type');continue;}const a6=A(V,W,a4);if(!a6){h('no-backend-shape');continue;}C++;const a7=new Set([a4,...I['subtypesOf'](a4)]),a8=new Set(Z);for(const [a9,aa]of F['facts']){if(NON_PRODUCT['test'](a9)||a8['has'](a9))continue;if(aa['imports']['some'](ab=>ab['named']['some'](ac=>a7['has'](ac['imported']))))a8['add'](a9);else{if(aa['typeDecls']?.['some'](ab=>a7['has'](ab['name']))){const ab=t(F,a9);if(ab&&Array['from'](a7)['some'](ac=>ab['idents']['has'](ac)&&!(I['byName']['get'](ac)??[])['some'](ad=>ad['file']===a9&&ac===a4)))a8['add'](a9);}}}for(const [ac,ad]of Array['from'](a5)['sort']((ae,af)=>ae[0x0]['localeCompare'](af[0x0]))){const ae=[];for(const ak of Array['from'](a8)['sort']()){if(ak===ad['file'])continue;const al=t(F,ak);for(const am of al?.['byField']['get'](ac)??[])ae['push'](am);}if(!ae['length'])continue;D['add'](ad['file']+'#'+ad['declaredIn']+'.'+ac);let af=null;for(const an of a6){const ao=matchField(ac,an['names']);if(ao['kind']==='exact'){af=null;break;}if(!af||af['match']['kind']==='none'&&ao['kind']==='near')af={'shape':an,'match':ao};}if(!af)continue;const ag=af['match']['kind']==='near'?af['match']:null;if(!ag&&af['shape']['open']){h('open-shape-medium');continue;}const ah=ag&&af['shape']['named']?'high':'medium',ai=F['name']+'\x00'+ad['file']+'\x00'+ad['line']+'\x00'+ac+'\x00'+V['name'];let aj=B['get'](ai);if(!aj)aj={'f':{'member':F['name'],'frontendFile':ad['file'],'line':ad['line'],'type':a4,'declaredIn':ad['declaredIn'],'field':ac,'backendMember':V['name'],'backendModel':af['shape']['model'],'backendFile':af['shape']['file'],...ag?{'suggest':ag['name'],'nearKind':ag['nearKind']}:{},'confidence':ah,'reads':[],'calls':[],'via':af['shape']['via']},'reads':new Map(),'calls':new Map()},B['set'](ai,aj);else ah==='high'&&aj['f']['confidence']==='medium'&&(aj['f']['confidence']='high',ag&&(aj['f']['suggest']=ag['name'],aj['f']['nearKind']=ag['nearKind']));for(const ap of ae)aj['reads']['set'](ap['file']+':'+String(ap['line'])['padStart'](0x6,'0'),ap);aj['calls']['set'](S['file']+':'+String(S['line'])['padStart'](0x6,'0'),{'file':S['file'],'line':S['line'],'name':S['name'],'route':W['file']+':'+W['line']});}}}}const E=Array['from'](B['values']())['map'](aq=>({...aq['f'],'reads':Array['from'](aq['reads']['keys']())['sort']()['slice'](0x0,MAX_EVIDENCE)['map'](ar=>aq['reads']['get'](ar)),'calls':Array['from'](aq['calls']['keys']())['sort']()['slice'](0x0,MAX_EVIDENCE)['map'](ar=>aq['calls']['get'](ar))}))['sort']((aq,ar)=>(aq['confidence']===ar['confidence']?0x0:aq['confidence']==='high'?-0x1:0x1)||aq['member']['localeCompare'](ar['member'])||aq['frontendFile']['localeCompare'](ar['frontendFile'])||aq['line']-ar['line']||aq['field']['localeCompare'](ar['field']));return{'status':'ok','checked':C,'fields':D['size'],'findings':E,'skipped':Object['fromEntries'](Object['keys'](g)['sort']()['map'](aq=>[aq,g[aq]]))};}
|
|
1
|
+
import{isNonProduct}from'./shape-eval.js';import*as a20a from'fs';import*as a20b from'path';import{ts}from'ts-morph';import{Resolver}from'./link.js';import{splitIdentifier,singularize}from'./ident-norm.js';const NON_PRODUCT={'test':a=>isNonProduct(a)||/(^|\/)(scripts?|stories)\//['test'](a)},HTTP_METHODS=new Set(['get','post','put','patch','delete','del','all','head','options','request']),PRIMS=new Set(['string','number','boolean','any','unknown','void','never','null','undefined','object','Date','Record','Object','String','Number','Boolean','Blob','File','FormData','Response']),COMMON_BACKEND=['id','createdAt','updatedAt','deletedAt','created_at','updated_at','deleted_at'],MAX_EVIDENCE=0x5;export function fieldKey(a){return splitIdentifier(a)['join']('');}function singularKey(a){return splitIdentifier(a)['map'](singularize)['join']('');}export function editDistance(c,d,e=0x3){if(Math['abs'](c['length']-d['length'])>e)return e+0x1;let f=Array['from']({'length':d['length']+0x1},(g,h)=>h);for(let g=0x1;g<=c['length'];g++){const h=[g];let k=g;for(let l=0x1;l<=d['length'];l++){h[l]=Math['min'](f[l]+0x1,h[l-0x1]+0x1,f[l-0x1]+(c[g-0x1]===d[l-0x1]?0x0:0x1));if(h[l]<k)k=h[l];}if(k>e)return e+0x1;f=h;}return f[d['length']];}export function matchField(a,b){const c=fieldKey(a),d=Array['from'](b);if(d['some'](i=>fieldKey(i)===c))return{'kind':'exact'};const e=singularKey(a),g=d['filter'](i=>singularKey(i)===e)['sort']();if(g['length'])return{'kind':'near','name':g[0x0],'nearKind':'plural'};const h=c['length']>=0x6?0x2:c['length']>=0x4?0x1:0x0;if(h){const i=d['filter'](l=>{const m=fieldKey(l);return m['length']>=0x4&&editDistance(c,m,h)<=h;}),j=Array['from'](new Set(i))['sort']();if(j['length']===0x1)return{'kind':'near','name':j[0x0],'nearKind':'edit'};}return{'kind':'none'};}class SourceCache{['read'];['parsed']=new Map();constructor(a){this['read']=a;}['get'](a,b){const c=a['name']+'\x00'+b;if(this['parsed']['has'](c))return this['parsed']['get'](c);let d=null;try{const e=this['read'](a['name'],b)??((()=>{try{return a20a['readFileSync'](a20b['join'](a['root'],b),'utf8');}catch{return null;}})());if(e!=null)d=ts['createSourceFile'](b,e,ts['ScriptTarget']['Latest'],!![],/\.[jt]sx$/['test'](b)?ts['ScriptKind']['TSX']:/\.[cm]?js$/['test'](b)?ts['ScriptKind']['JS']:ts['ScriptKind']['TS']);}catch{d=null;}return this['parsed']['set'](c,d),d;}}const lineOf=(a,b)=>a['getLineAndCharacterOfPosition'](b)['line']+0x1,propName=a=>{if(!a)return null;if(ts['isIdentifier'](a)||ts['isStringLiteral'](a)||ts['isNumericLiteral'](a)||ts['isPrivateIdentifier'](a))return a['text'];return null;},entityLast=a=>ts['isIdentifier'](a)?a['text']:a['right']['text'];function walk(a,b){b(a),ts['forEachChild'](a,d=>walk(d,b));}function leafTypeNames(b,c,d=0x0){if(!b||d>0x6)return;if(ts['isTypeReferenceNode'](b)){const e=entityLast(b['typeName']);if(b['typeArguments']?.['length']){if(e==='Omit'||e==='Pick'||e==='Partial'||e==='Required'||e==='Readonly'){leafTypeNames(b['typeArguments'][0x0],c,d+0x1);return;}if(e==='Record'||e==='Map')return;for(const f of b['typeArguments'])leafTypeNames(f,c,d+0x1);return;}if(!PRIMS['has'](e))c['add'](e);return;}if(ts['isArrayTypeNode'](b))return leafTypeNames(b['elementType'],c,d+0x1);if(ts['isUnionTypeNode'](b)){for(const g of b['types'])leafTypeNames(g,c,d+0x1);return;}if(ts['isParenthesizedTypeNode'](b))return leafTypeNames(b['type'],c,d+0x1);if(ts['isTypeLiteralNode'](b)&&d<0x3){for(const h of b['members'])if(ts['isPropertySignature'](h))leafTypeNames(h['type'],c,d+0x2);}}function baseNamesOfType(a,b){if(ts['isTypeReferenceNode'](a)){const c=entityLast(a['typeName']);if((c==='Omit'||c==='Pick'||c==='Partial'||c==='Required'||c==='Readonly')&&a['typeArguments']?.['length'])return baseNamesOfType(a['typeArguments'][0x0],b);if(!PRIMS['has'](c))b['push'](c);}else{if(ts['isIntersectionTypeNode'](a)){for(const d of a['types'])baseNamesOfType(d,b);}else{if(ts['isParenthesizedTypeNode'](a))baseNamesOfType(a['type'],b);}}}function collectTypeDecls(a,b,c){const d=g=>{if(!c['has'](g['name']))c['set'](g['name'],[]);c['get'](g['name'])['push'](g);},f=(g,i)=>{for(const j of g)if((ts['isPropertySignature'](j)||ts['isMethodSignature'](j))&&propName(j['name']))i['set'](propName(j['name']),lineOf(a,j['name']['getStart'](a)));};for(const g of a['statements']){if(ts['isInterfaceDeclaration'](g)){const i=new Map();f(g['members'],i);const j=[];for(const k of g['heritageClauses']??[])for(const l of k['types']){if(ts['isIdentifier'](l['expression'])){const m=l['expression']['text'];if((m==='Omit'||m==='Pick'||m==='Partial')&&l['typeArguments']?.['length'])baseNamesOfType(l['typeArguments'][0x0],j);else j['push'](m);}else{if(ts['isPropertyAccessExpression'](l['expression']))j['push'](l['expression']['name']['text']);}}d({'name':g['name']['text'],'file':b,'line':lineOf(a,g['name']['getStart'](a)),'fields':i,'bases':j,'generic':!!g['typeParameters']?.['length']});}else{if(ts['isTypeAliasDeclaration'](g)){const o=new Map(),p=[],q=r=>{if(ts['isTypeLiteralNode'](r))f(r['members'],o);else{if(ts['isIntersectionTypeNode'](r)){for(const s of r['types'])q(s);}else{if(ts['isParenthesizedTypeNode'](r))q(r['type']);else baseNamesOfType(r,p);}}};q(g['type']);if(!o['size']&&!p['length'])continue;d({'name':g['name']['text'],'file':b,'line':lineOf(a,g['name']['getStart'](a)),'fields':o,'bases':p,'generic':!!g['typeParameters']?.['length']});}}}}class TypeIndex{['byName']=new Map();['subs']=null;['one'](a){const b=this['byName']['get'](a);if(!b?.['length'])return null;if(b['length']===0x1)return b[0x0];const c=d=>Array['from'](d['fields']['keys']())['sort']()['join'](',')+'|'+d['bases']['slice']()['sort']()['join'](',');return b['every'](d=>c(d)===c(b[0x0]))?b[0x0]:null;}['fieldsOf'](a,c=new Set()){if(c['has'](a)||c['size']>0xc)return new Map();c['add'](a);const d=this['one'](a);if(!d)return null;const e=new Map();for(const g of d['bases']){const h=this['fieldsOf'](g,c);if(h){for(const [i,j]of h)e['set'](i,j);}}for(const [l,m]of d['fields'])e['set'](l,{'field':l,'declaredIn':d['name'],'file':d['file'],'line':m});return e;}['subtypesOf'](a){if(!this['subs']){const c=new Map();for(const [e,f]of this['byName'])for(const g of f)for(const h of g['bases']){if(!c['has'](h))c['set'](h,new Set());c['get'](h)['add'](e);}this['subs']=new Map();const d=i=>{if(this['subs']['has'](i))return this['subs']['get'](i);const j=new Set();this['subs']['set'](i,j);for(const k of c['get'](i)??[]){j['add'](k);for(const l of d(k))j['add'](l);}return j;};for(const i of this['byName']['keys']())d(i);}return this['subs']['get'](a)??new Set();}}function typeIndexOf(a,b){const c=new TypeIndex();for(const [d,e]of a['facts']){if(!e['typeDecls']?.['length']||NON_PRODUCT['test'](d))continue;const g=b['get'](a,d);if(g)collectTypeDecls(g,d,c['byName']);}return c;}function enclosingFunction(a){for(let b=a['parent'];b;b=b['parent']){if(ts['isFunctionDeclaration'](b)||ts['isMethodDeclaration'](b)||ts['isFunctionExpression'](b)||ts['isArrowFunction'](b))return b;}return null;}function functionName(a){if((ts['isFunctionDeclaration'](a)||ts['isMethodDeclaration'](a))&&a['name'])return propName(a['name']);const b=a['parent'];if(b&&ts['isVariableDeclaration'](b)&&ts['isIdentifier'](b['name']))return b['name']['text'];if(b&&ts['isPropertyAssignment'](b))return propName(b['name']);return null;}function responseTypesAt(b,c){let d=null;walk(b,h=>{if(d||!ts['isCallExpression'](h))return;if(lineOf(b,h['getStart'](b))!==c&&lineOf(b,h['expression']['getEnd']())!==c)return;const i=h['expression'],j=ts['isPropertyAccessExpression'](i)?i['name']['text']:ts['isIdentifier'](i)?i['text']:'';if(HTTP_METHODS['has'](j['toLowerCase']())||j==='fetch'||h['typeArguments']?.['length'])d=h;});if(!d)return null;const e=d,f=new Set();for(const h of e['typeArguments']??[])leafTypeNames(h,f);const g=enclosingFunction(e);if(g?.['type'])leafTypeNames(g['type'],f);return{'names':f,'fnName':g?functionName(g):null};}function readIndexOf(a,b){const c=new Map(),d=new Set(),e=(g,h)=>{if(!c['has'](g))c['set'](g,[]);c['get'](g)['push']({'file':b,'line':lineOf(a,h)});};return walk(a,f=>{if(ts['isIdentifier'](f))d['add'](f['text']);if(ts['isPropertyAccessExpression'](f)){const g=f['parent'];if(g&&ts['isBinaryExpression'](g)&&g['left']===f&&g['operatorToken']['kind']===ts['SyntaxKind']['EqualsToken'])return;e(f['name']['text'],f['name']['getStart'](a));}else{if(ts['isElementAccessExpression'](f)&&ts['isStringLiteral'](f['argumentExpression']))e(f['argumentExpression']['text'],f['argumentExpression']['getStart'](a));else{if(ts['isBindingElement'](f)&&f['parent']&&ts['isObjectBindingPattern'](f['parent'])){const h=propName(f['propertyName'])??propName(f['name']);if(h)e(h,f['getStart'](a));}}}}),{'byField':c,'idents':d};}function importOfLocal(a,b){for(const c of a['statements']){if(!ts['isImportDeclaration'](c)||!ts['isStringLiteral'](c['moduleSpecifier'])||!c['importClause'])continue;const d=c['moduleSpecifier']['text'],e=c['importClause'];if(e['name']?.['text']===b)return{'spec':d,'imported':'default'};const f=e['namedBindings'];if(f&&ts['isNamespaceImport'](f)&&f['name']['text']===b)return{'spec':d,'imported':'*'};if(f&&ts['isNamedImports'](f)){for(const g of f['elements'])if(g['name']['text']===b)return{'spec':d,'imported':(g['propertyName']??g['name'])['text']};}}return null;}function findFunction(a,b){let c=null;return walk(a,d=>{if(c)return;if((ts['isFunctionDeclaration'](d)||ts['isMethodDeclaration'](d))&&d['name']&&propName(d['name'])===b&&d['body'])c=d;else{if((ts['isVariableDeclaration'](d)||ts['isPropertyAssignment'](d)||ts['isPropertyDeclaration'](d))&&propName(d['name'])===b&&d['initializer']){const e=d['initializer'];if(ts['isArrowFunction'](e)||ts['isFunctionExpression'](e))c=e;}}}),c;}class ChainWalker{['m'];['cache'];['modelNames'];['maxDepth'];['resolver'];constructor(a,b,c,d){this['m']=a,this['cache']=b,this['modelNames']=c,this['maxDepth']=d,this['resolver']=new Resolver(a['root'],new Set(a['facts']['keys']()),[]);}['resolveFile'](a,b){try{const c=this['resolver']['resolve'](a,b);return c['kind']==='file'?c['rel']:null;}catch{return null;}}['shapeOfRoute'](a){const b=this['cache']['get'](this['m'],a['file']);if(!b)return null;const c=(a['method']??'')['toLowerCase']();let d=null;walk(b,j=>{if(d||!ts['isCallExpression'](j)||!ts['isPropertyAccessExpression'](j['expression']))return;const k=j['expression']['name']['text']['toLowerCase']();if(!HTTP_METHODS['has'](k)||c&&c!=='all'&&k!==c&&k!=='all')return;const l=lineOf(b,j['getStart'](b)),m=lineOf(b,j['expression']['name']['getStart'](b));if(l===a['line']||m===a['line'])d=j;});if(!d)return null;const e=d['arguments'];if(!e['length'])return null;const f={'models':new Map(),'shapeTypes':new Set(),'extraKeys':new Set(),'open':![]};let g=e[e['length']-0x1];for(let j=0x0;j<0x4&&ts['isCallExpression'](g)&&g['arguments']['length'];j++)g=g['arguments'][g['arguments']['length']-0x1];if(ts['isArrowFunction'](g)||ts['isFunctionExpression'](g))this['visitFn'](b,a['file'],g,f,0x0,new Set());else this['follow'](b,a['file'],g,f,0x0,new Set());return f;}['follow'](a,b,c,d,f,g){if(f>this['maxDepth'])return;let h=null,i=null;if(ts['isPropertyAccessExpression'](c)){i=c['name']['text'];const n=c['expression'];if(ts['isIdentifier'](n))h=n['text'];else{if(ts['isPropertyAccessExpression'](n)&&n['expression']['kind']===ts['SyntaxKind']['ThisKeyword'])h=n['name']['text'];}}else{if(ts['isIdentifier'](c))i=c['text'];}if(!i)return;let j=null;if(h){if(this['modelNames']['has'](h)){d['models']['set'](h,this['modelNames']['get'](h));return;}const o=importOfLocal(a,h)??this['importByLooseName'](a,h);if(o)j=this['resolveFile'](b,o['spec']);}else{const p=importOfLocal(a,i);if(p){j=this['resolveFile'](b,p['spec']);if(p['imported']!=='default'&&p['imported']!=='*')i=p['imported'];}else j=b;}if(!j)return;const k=j+'#'+i;if(g['has'](k))return;g['add'](k);const l=this['cache']['get'](this['m'],j);if(!l)return;const m=findFunction(l,i);if(m)this['visitFn'](l,j,m,d,f+0x1,g);}['importByLooseName'](a,b){const c=b['toLowerCase']();for(const d of a['statements']){if(!ts['isImportDeclaration'](d)||!ts['isStringLiteral'](d['moduleSpecifier'])||!d['importClause'])continue;const e=d['importClause'],f=[e['name']?.['text'],...e['namedBindings']&&ts['isNamedImports'](e['namedBindings'])?e['namedBindings']['elements']['map'](g=>g['name']['text']):[]];if(f['some'](g=>g&&g['toLowerCase']()===c))return{'spec':d['moduleSpecifier']['text'],'imported':b};}return null;}['visitFn'](a,b,c,d,e,f){if(c['type'])leafTypeNames(c['type'],d['shapeTypes']);if(!c['body'])return;walk(c['body'],g=>{if(ts['isIdentifier'](g)&&this['modelNames']['has'](g['text']))d['models']['set'](g['text'],this['modelNames']['get'](g['text']));if(ts['isTypeReferenceNode'](g))leafTypeNames(g,d['shapeTypes']);if(ts['isPropertyAssignment'](g)||ts['isShorthandPropertyAssignment'](g)||ts['isMethodDeclaration'](g)){const h=propName(g['name']);if(h)d['extraKeys']['add'](h);if(ts['isPropertyAssignment'](g)&&h==='as'&&ts['isStringLiteral'](g['initializer']))d['extraKeys']['add'](g['initializer']['text']);if(ts['isPropertyAssignment'](g)&&h==='attributes'&&ts['isArrayLiteralExpression'](g['initializer']))for(const i of g['initializer']['elements']){if(ts['isStringLiteral'](i))d['extraKeys']['add'](i['text']);else{if(ts['isArrayLiteralExpression'](i)&&i['elements'][0x1]&&ts['isStringLiteral'](i['elements'][0x1]))d['extraKeys']['add'](i['elements'][0x1]['text']);}}}if(ts['isSpreadAssignment'](g)){const j=g['expression'],l=j['getText'](a);if(!/toJSON\(\)|get\(\s*\{\s*plain\s*:\s*true\s*\}\s*\)|dataValues/['test'](l))d['open']=!![];}if((ts['isStringLiteral'](g)||ts['isNoSubstitutionTemplateLiteral'](g)||ts['isTemplateHead'](g)||ts['isTemplateMiddle'](g)||ts['isTemplateTail'](g))&&/\bselect\b/i['test'](g['text'])){d['open']=!![];for(const m of g['text']['matchAll'](/\bAS\s+"?([A-Za-z_][A-Za-z0-9_]*)"?/gi))d['extraKeys']['add'](m[0x1]);}if(ts['isCallExpression'](g)&&ts['isPropertyAccessExpression'](g['expression'])&&g['expression']['name']['text']==='query')d['open']=!![];if(ts['isCallExpression'](g)&&e<this['maxDepth']){const o=g['expression'];if(ts['isPropertyAccessExpression'](o)||ts['isIdentifier'](o))this['follow'](a,b,o,d,e,f);}});}}function modelFieldsOf(a,b){const c=new Set();let d=![];return walk(a,e=>{if(ts['isClassDeclaration'](e)&&e['name']?.['text']===b)for(const f of e['members']){if((ts['isPropertyDeclaration'](f)||ts['isGetAccessorDeclaration'](f))&&!f['modifiers']?.['some'](g=>g['kind']===ts['SyntaxKind']['StaticKeyword'])){const g=propName(f['name']);if(g)c['add'](g);}ts['isMethodDeclaration'](f)&&propName(f['name'])==='toJSON'&&(d=!![],walk(f,h=>{if((ts['isPropertyAssignment'](h)||ts['isShorthandPropertyAssignment'](h))&&propName(h['name']))c['add'](propName(h['name']));}));}if(ts['isCallExpression'](e)&&ts['isPropertyAccessExpression'](e['expression'])){const h=e['expression']['name']['text'],i=e['expression']['expression']['getText'](a),j=h==='init'&&i===b?e['arguments'][0x0]:h==='define'?e['arguments'][0x1]:undefined;if(j&&ts['isObjectLiteralExpression'](j))for(const l of j['properties']){const m=l['name']?propName(l['name']):null;if(m)c['add'](m);}}}),{'fields':c,'customJson':d};}function resourceModelName(a){const b=a['split']('/')['filter'](Boolean)['filter'](d=>!/^(api|v\d+|internal|admin|public)$/['test'](d)&&!d['startsWith'](':')&&!d['startsWith']('{')),c=b[0x0];if(!c)return null;return splitIdentifier(c)['map'](singularize)['map'](d=>d[0x0]['toUpperCase']()+d['slice'](0x1))['join']('');}const AGGREGATE_TYPE=/(List|Page|Paged|Paginated)?(Response|Result|Stats|Statistics|Summary|Comparison|Count|Counts|Overview|Metrics|Analytics|Dashboard|Report|Payload|Envelope|Data)$/,sameName=(c,d)=>fieldKey(c)===fieldKey(d)||singularKey(c)===singularKey(d);export function computeFieldContract(b,c={}){const g={},h=F=>{g[F]=(g[F]??0x0)+0x1;},i=new SourceCache(c['readSource']??(()=>undefined)),j=c['maxDepth']??0x4,l=new Map(b['map'](F=>[F['name'],F])),o=new Map(),p=F=>{let G=o['get'](F['name']);return!G&&(G=typeIndexOf(F,i),o['set'](F['name'],G)),G;},q=new Map(),t=(F,G)=>{const H=F['name']+'\x00'+G;if(!q['has'](H)){const I=i['get'](F,G);q['set'](H,I?readIndexOf(I,G):null);}return q['get'](H);},v=new Map(),w=F=>{let G=v['get'](F['name']);if(!G){G=new Map();for(const [H,I]of F['facts']){if(NON_PRODUCT['test'](H))continue;for(const J of I['models'])if(!G['has'](J['name']))G['set'](J['name'],H);}v['set'](F['name'],G);}return G;},x=new Map(),y=F=>{let G=x['get'](F['name']);return!G&&(G=new ChainWalker(F,i,w(F),j),x['set'](F['name'],G)),G;},z=new Map(),A=(F,G,H)=>{const I=F['name']+'\x00'+G['id']+'\x00'+H;if(z['has'](I))return z['get'](I);const J=[],K=y(F)['shapeOfRoute'](G),L=w(F),M=p(F),N=K?Array['from'](K['extraKeys']):[],O=(Q,R,S,T)=>{const U=new Set(COMMON_BACKEND);let V=0x0;if(L['has'](Q)){const W=i['get'](F,L['get'](Q));if(W){const X=modelFieldsOf(W,Q);for(const Y of X['fields']){U['add'](Y),V++;}if(X['customJson'])T=!![];}}for(const Z of[Q,Q+'Attributes',Q+'Attrs','I'+Q,Q+'Response',Q+'Dto',Q+'ResponseDto']){const a0=M['fieldsOf'](Z);if(a0)for(const a1 of a0['keys']()){U['add'](a1),V++;}}if(V<0x2)return null;for(const a2 of N)U['add'](a2);return{'model':Q,'file':R,'names':U,'open':T,'via':S};};if(K){const Q=Array['from'](K['shapeTypes'])['filter'](V=>L['has'](V)||M['one'](V))['sort'](),R=Array['from'](K['models']['keys']())['sort'](),S=Q['length']?Q:R,T=S['filter'](V=>sameName(V,H)),U=!T['length']&&S['length']===0x1&&!AGGREGATE_TYPE['test'](H);for(const V of T['length']?T:U?S:[]){const W=O(V,L['get'](V)??M['one'](V)?.['file']??'','chain',K['open']);W&&(W['named']=!U,J['push'](W));}}if(!J['length']){const X=resourceModelName(G['routePaths']?.[0x0]??G['routePath']??G['name']['replace'](/^\S+\s+/,'')),Y=Array['from'](L['keys']())['find'](Z=>sameName(Z,H));if(Y&&X&&sameName(Y,X)){const Z=O(Y,L['get'](Y),'name',K?.['open']??!![]);Z&&(Z['named']=!![],J['push'](Z));}}const P=J['length']?J:null;return z['set'](I,P),P;},B=new Map();let C=0x0;const D=new Set();for(const F of b){if(F['hasBackend']||c['only']&&!c['only']['has'](F['name']))continue;const G=new Map(F['cis']['map'](L=>[L['id'],L])),H=F['edges']['filter'](L=>L['type']==='http'&&G['get'](L['from'])?.['kind']==='api-call');if(!H['length'])continue;const I=p(F),J=new Map(),K=new Map();for(const [L,M]of F['facts']){if(NON_PRODUCT['test'](L))continue;for(const N of M['imports'])for(const O of N['named']){if(!J['has'](O['imported']))J['set'](O['imported'],new Set());J['get'](O['imported'])['add'](L);}for(const P of M['usages']){const Q=L+'#'+P['owner'];if(!K['has'](Q))K['set'](Q,new Set());K['get'](Q)['add'](P['local']);}}for(const R of H['sort']((S,T)=>S['from']['localeCompare'](T['from'])||S['to']['localeCompare'](T['to']))){const S=G['get'](R['from']);if(NON_PRODUCT['test'](S['file']))continue;const T=R['to']['indexOf'](':'),U=T>0x0&&l['has'](R['to']['slice'](0x0,T))?R['to']['slice'](0x0,T):null;if(!U||U===F['name']){h('same-member-route');continue;}const V=l['get'](U),W=V['cis']['find'](a0=>a0['id']===R['to']['slice'](T+0x1));if(!W){h('route-ci-missing');continue;}const X=i['get'](F,S['file']);if(!X){h('frontend-unreadable');continue;}const Y=responseTypesAt(X,S['line']);if(!Y||!Y['names']['size']){h('untyped-response');continue;}const Z=new Set();if(Y['fnName'])for(const a0 of J['get'](Y['fnName'])??[]){Z['add'](a0);const a1=F['facts']['get'](a0);if(!a1)continue;for(const a2 of a1['decls'])if(a2['exported']&&K['get'](a0+'#'+a2['name'])?.['has'](Y['fnName'])){for(const a3 of J['get'](a2['name'])??[])Z['add'](a3);}}for(const a4 of Array['from'](Y['names'])['sort']()){const a5=I['fieldsOf'](a4);if(!a5){h(I['byName']['has'](a4)?'ambiguous-type':'type-not-found');continue;}if(I['one'](a4)?.['generic']){h('generic-type');continue;}const a6=A(V,W,a4);if(!a6){h('no-backend-shape');continue;}C++;const a7=new Set([a4,...I['subtypesOf'](a4)]),a8=new Set(Z);for(const [a9,aa]of F['facts']){if(NON_PRODUCT['test'](a9)||a8['has'](a9))continue;if(aa['imports']['some'](ab=>ab['named']['some'](ac=>a7['has'](ac['imported']))))a8['add'](a9);else{if(aa['typeDecls']?.['some'](ab=>a7['has'](ab['name']))){const ab=t(F,a9);if(ab&&Array['from'](a7)['some'](ac=>ab['idents']['has'](ac)&&!(I['byName']['get'](ac)??[])['some'](ad=>ad['file']===a9&&ac===a4)))a8['add'](a9);}}}for(const [ac,ad]of Array['from'](a5)['sort']((ae,af)=>ae[0x0]['localeCompare'](af[0x0]))){const ae=[];for(const ak of Array['from'](a8)['sort']()){if(ak===ad['file'])continue;const al=t(F,ak);for(const am of al?.['byField']['get'](ac)??[])ae['push'](am);}if(!ae['length'])continue;D['add'](ad['file']+'#'+ad['declaredIn']+'.'+ac);let af=null;for(const an of a6){const ao=matchField(ac,an['names']);if(ao['kind']==='exact'){af=null;break;}if(!af||af['match']['kind']==='none'&&ao['kind']==='near')af={'shape':an,'match':ao};}if(!af)continue;const ag=af['match']['kind']==='near'?af['match']:null;if(!ag&&af['shape']['open']){h('open-shape-medium');continue;}const ah=ag&&af['shape']['named']?'high':'medium',ai=F['name']+'\x00'+ad['file']+'\x00'+ad['line']+'\x00'+ac+'\x00'+V['name'];let aj=B['get'](ai);if(!aj)aj={'f':{'member':F['name'],'frontendFile':ad['file'],'line':ad['line'],'type':a4,'declaredIn':ad['declaredIn'],'field':ac,'backendMember':V['name'],'backendModel':af['shape']['model'],'backendFile':af['shape']['file'],...ag?{'suggest':ag['name'],'nearKind':ag['nearKind']}:{},'confidence':ah,'reads':[],'calls':[],'via':af['shape']['via']},'reads':new Map(),'calls':new Map()},B['set'](ai,aj);else ah==='high'&&aj['f']['confidence']==='medium'&&(aj['f']['confidence']='high',ag&&(aj['f']['suggest']=ag['name'],aj['f']['nearKind']=ag['nearKind']));for(const ap of ae)aj['reads']['set'](ap['file']+':'+String(ap['line'])['padStart'](0x6,'0'),ap);aj['calls']['set'](S['file']+':'+String(S['line'])['padStart'](0x6,'0'),{'file':S['file'],'line':S['line'],'name':S['name'],'route':W['file']+':'+W['line']});}}}}const E=Array['from'](B['values']())['map'](aq=>({...aq['f'],'reads':Array['from'](aq['reads']['keys']())['sort']()['slice'](0x0,MAX_EVIDENCE)['map'](ar=>aq['reads']['get'](ar)),'calls':Array['from'](aq['calls']['keys']())['sort']()['slice'](0x0,MAX_EVIDENCE)['map'](ar=>aq['calls']['get'](ar))}))['sort']((aq,ar)=>(aq['confidence']===ar['confidence']?0x0:aq['confidence']==='high'?-0x1:0x1)||aq['member']['localeCompare'](ar['member'])||aq['frontendFile']['localeCompare'](ar['frontendFile'])||aq['line']-ar['line']||aq['field']['localeCompare'](ar['field']));return{'status':'ok','checked':C,'fields':D['size'],'findings':E,'skipped':Object['fromEntries'](Object['keys'](g)['sort']()['map'](aq=>[aq,g[aq]]))};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as a18a from'crypto';const KEYWORDS=new Set(['break','case','catch','class','const','continue','debugger','default','delete','do','else','enum','export','extends','false','finally','for','function','if','import','in','instanceof','new','null','return','super','switch','this','throw','true','try','typeof','var','void','while','with','yield','let','static','await','async','interface','implements','abstract','declare']),REGEX_PREV_KW=new Set(['return','typeof','instanceof','in','of','new','delete','void','throw','case','do','else','yield','await']),isIdStart=a=>/[A-Za-z_$ -]/['test'](a),isIdPart=a=>/[A-Za-z0-9_$ -]/['test'](a);export function tokenize(a){const b=[],f=a['length'];let g=0x0;const h=[],k=()=>b[b['length']-0x1],l=()=>{const q=k();if(!q)return!![];if(q['type']==='num'||q['type']==='str'||q['type']==='tpl'||q['type']==='re')return![];if(q['type']==='id')return![];if(q['type']==='kw')return REGEX_PREV_KW['has'](q['value']);return!(q['value']===')'||q['value']===']'||q['value']==='}');},m=p=>{let q=p;while(q<f){const r=a[q];if(r==='\x5c'){q+=0x2;continue;}if(r==='`')return q+0x1;if(r==='$'&&a[q+0x1]==='{')return q+0x2;q++;}return f;};while(g<f){const p=a[g];if(p==='\x20'||p==='\x09'||p==='\x0a'||p==='\x0d'||p==='\x0c'||p==='\x0b'||p==='\ufeff'){g++;continue;}if(p==='/'&&a[g+0x1]==='/'){while(g<f&&a[g]!=='\x0a')g++;continue;}if(p==='/'&&a[g+0x1]==='*'){const t=a['indexOf']('*/',g+0x2);g=t<0x0?f:t+0x2;continue;}if(p==='}'&&h['length']>0x0&&h[h['length']-0x1]===0x0){h['pop']();const u=m(g+0x1);b['push']({'type':'tpl','value':a['slice'](g,u),'start':g,'end':u});if(a['slice'](u-0x2,u)==='${')h['push'](0x0);g=u;continue;}if(p==='`'){const w=m(g+0x1);b['push']({'type':'tpl','value':a['slice'](g,w),'start':g,'end':w});if(a['slice'](w-0x2,w)==='${')h['push'](0x0);g=w;continue;}if(p==='\x22'||p==='\x27'){let x=g+0x1,y=![];while(x<f){const z=a[x];if(z==='\x5c'){x+=0x2;continue;}if(z==='\x0a')break;if(z===p){y=!![],x++;break;}x++;}y?(b['push']({'type':'str','value':a['slice'](g,x),'start':g,'end':x}),g=x):(b['push']({'type':'punct','value':p,'start':g,'end':g+0x1}),g++);continue;}if(/[0-9]/['test'](p)||p==='.'&&/[0-9]/['test'](a[g+0x1]??'')){let A=g+0x1;while(A<f&&/[0-9A-Za-z_.]/['test'](a[A]))A++;b['push']({'type':'num','value':a['slice'](g,A),'start':g,'end':A}),g=A;continue;}if(isIdStart(p)){let B=g+0x1;while(B<f&&isIdPart(a[B]))B++;const C=a['slice'](g,B);b['push']({'type':KEYWORDS['has'](C)?'kw':'id','value':C,'start':g,'end':B}),g=B;continue;}if(p==='#'&&isIdStart(a[g+0x1]??'')){let D=g+0x1;while(D<f&&isIdPart(a[D]))D++;b['push']({'type':'id','value':a['slice'](g,D),'start':g,'end':D}),g=D;continue;}if(p==='/'&&l()){let E=g+0x1,F=![],G=![];while(E<f){const H=a[E];if(H==='\x5c'){E+=0x2;continue;}if(H==='\x0a')break;if(H==='[')F=!![];else{if(H===']')F=![];else{if(H==='/'&&!F){G=!![],E++;break;}}}E++;}if(G){while(E<f&&/[a-z]/i['test'](a[E]))E++;b['push']({'type':'re','value':a['slice'](g,E),'start':g,'end':E}),g=E;continue;}}const q=a['slice'](g,g+0x4),r=['>>>=','...','===','!==','**=','<<=','>>=','>>>','&&=','||=','??=','=>','==','!=','<=','>=','&&','||','??','?.','++','--','+=','-=','*=','/=','%=','&=','|=','^=','**','<<','>>'];let s=p;for(const I of r){if(q['startsWith'](I)){s=I;break;}}if(h['length']>0x0){if(s==='{')h[h['length']-0x1]++;else{if(s==='}')h[h['length']-0x1]--;}}b['push']({'type':'punct','value':s,'start':g,'end':g+s['length']}),g+=s['length'];}return b;}export function maskSource(a){const b=tokenize(a),c=a['split'](''),d=a['split'](''),f=(h,i,j)=>{for(let l=i;l<j;l++)if(h[l]!=='\x0a')h[l]='\x20';};let g=0x0;for(const h of b){f(c,g,h['start']),f(d,g,h['start']),g=h['end'];if(h['type']==='str')f(d,h['start']+0x1,h['end']-0x1);else{if(h['type']==='tpl'){const i=h['value']['startsWith']('`')||h['value']['startsWith']('}')?h['start']+0x1:h['start'];let j=h['end'];if(h['value']['endsWith']('${'))j-=0x2;else{if(h['value']['endsWith']('`')&&h['value']['length']>0x1)j-=0x1;}f(d,i,j);}}}return f(c,g,a['length']),f(d,g,a['length']),{'code':c['join'](''),'masked':d['join']('')};}function trimDeclTokens(a){let b=0x0,c=a['length'];for(;;){if(b<c&&a[b]['value']==='@'){b++;while(b<c&&(a[b]['type']==='id'||a[b]['type']==='kw'||a[b]['value']==='.'))b++;if(b<c&&a[b]['value']==='('){let d=0x0;for(;b<c;b++){if(a[b]['value']==='(')d++;else{if(a[b]['value']===')'){d--;if(d===0x0){b++;break;}}}}}continue;}if(b<c&&(a[b]['value']==='export'||a[b]['value']==='default'||a[b]['value']==='declare')){b++;continue;}break;}while(c>b&&a[c-0x1]['value']===';')c--;return a['slice'](b,c);}const CONTROL_BEFORE_PAREN=new Set(['if','for','while','switch','with','return','typeof','await','new','in','of','yield','throw','case','delete','void']),PARAM_MODIFIERS=new Set(['public','private','protected','readonly','override']);function matchClose(a,b){const c=a[b]['value'],d=c==='('?')':c==='['?']':'}';let e=0x0;for(let f=b;f<a['length'];f++){const g=a[f]['value'];if(a[f]['type']!=='punct')continue;if(g===c)e++;else{if(g===d){e--;if(e===0x0)return f;}}}return a['length']-0x1;}function collectBindingNames(a,b,c,f){let g=0x0;for(let h=b;h<c;h++){const i=a[h];if(i['type']==='punct'&&(i['value']==='{'||i['value']==='['||i['value']==='(')){g++;continue;}if(i['type']==='punct'&&(i['value']==='}'||i['value']===']'||i['value']===')')){g--;continue;}if(i['type']==='punct'&&i['value']==='='){let l=0x0,m=h+0x1;for(;m<c;m++){const n=a[m]['value'];if(a[m]['type']!=='punct')continue;if(n==='('||n==='['||n==='{')l++;else{if(n===')'||n===']'||n==='}'){if(l===0x0)break;l--;}else{if(n===','&&l===0x0)break;}}}h=m-0x1;continue;}if(i['type']==='punct'&&i['value']===':'&&g===0x0){let o=0x0,p=h+0x1;for(;p<c;p++){const q=a[p]['value'];if(a[p]['type']!=='punct')continue;if(q==='('||q==='['||q==='{'||q==='<')o++;else{if(q===')'||q===']'||q==='}'||q==='>'){if(o===0x0)break;o--;}else{if((q===','||q==='=')&&o===0x0)break;}}}h=p-0x1;continue;}if(i['type']==='id'&&!PARAM_MODIFIERS['has'](i['value'])){const r=a[h+0x1];if(r&&r['value']===':'&&g>0x0)continue;f['add'](i['value']);}}}export function collectLocals(a){const b=new Set();for(let c=0x0;c<a['length'];c++){const d=a[c];if(d['type']==='kw'&&(d['value']==='const'||d['value']==='let'||d['value']==='var')){const e=a[c+0x1];if(!e)continue;if(e['type']==='id')b['add'](e['value']);else{if(e['value']==='{'||e['value']==='[')collectBindingNames(a,c+0x2,matchClose(a,c+0x1),b);}continue;}if(d['type']==='kw'&&(d['value']==='function'||d['value']==='class')){let f=c+0x1;if(a[f]?.['value']==='*')f++;if(a[f]?.['type']==='id')b['add'](a[f]['value']);continue;}if(d['type']==='punct'&&d['value']==='('){const g=a[c-0x1],h=matchClose(a,c),j=a[h+0x1],l=g?.['value']==='catch',m=!g||g['type']!=='kw'||g['value']==='function'||g['value']==='async'||l,n=g&&CONTROL_BEFORE_PAREN['has'](g['value']),o=j&&(j['value']==='=>'||j['value']==='{'||j['value']===':');if(l||m&&!n&&o)collectBindingNames(a,c+0x1,h,b);continue;}if(d['type']==='id'&&a[c+0x1]?.['value']==='=>'&&a[c-0x1]?.['value']!=='.')b['add'](d['value']);}return b;}function digest(a,b){return a+a18a['createHash']('sha1')['update'](b['join']('\x01'))['digest']('hex')['slice'](0x0,0x10);}export function hashDecl(a){const b=trimDeclTokens(tokenize(a)),c=collectLocals(b),d=new Map(),e=[],f=[];for(let g=0x0;g<b['length'];g++){const h=b[g],j=b[g-0x1];if(h['type']==='id'){const k=j&&(j['value']==='.'||j['value']==='?.');if(!k&&c['has'](h['value'])){if(!d['has'](h['value']))d['set'](h['value'],d['size']);e['push']('$'+d['get'](h['value']));}else e['push'](h['value']);f['push']('I');}else{if(h['type']==='num')e['push'](h['value']),f['push']('N');else{if(h['type']==='str'||h['type']==='tpl')e['push'](h['value']),f['push']('S');else h['type']==='re'?(e['push'](h['value']),f['push']('R')):(e['push'](h['value']),f['push'](h['value']));}}}return{'bodyHash':digest('h1:',e),'shapeHash':digest('h2:',f),'tokens':b['length']};}export const STMT_START=new Set(['export','import','const','let','var','function','class','async','interface','enum','declare','abstract','@']);export function exprStmtEnd(a,b,c){let e=0x0;for(let f=b;f<a['length'];f++){const g=a[f];if(g['type']==='punct'){if(g['value']==='('||g['value']==='['||g['value']==='{')e++;else{if(g['value']===')'||g['value']===']'||g['value']==='}')e--;else{if(g['value']===';'&&e===0x0)return f;}}}const h=a[f+0x1];if(!h)return f;if(e===0x0&&f>b&&c['slice'](g['end'],h['start'])['includes']('\x0a')&&STMT_START['has'](h['value'])){if(!(g['type']==='punct'&&/^(=|=>|,|\.|\?|:|\+|-|\*|\/|&&|\|\||\?\?|\(|\[|\{)$/['test'](g['value'])))return f;}}return a['length']-0x1;}export function blockDeclEnd(a,b){let c=b;while(c<a['length']){const d=a[c]['value'];if(a[c]['type']==='punct'&&(d==='('||d==='[')){c=matchClose(a,c)+0x1;continue;}if(a[c]['type']==='punct'&&d==='{')return matchClose(a,c);if(a[c]['type']==='punct'&&d===';')return c;c++;}return a['length']-0x1;}function declaratorAt(c,d,e){const f=c[d];if(!f||d>e)return null;let g;if(f['type']==='id')g=d;else{if(f['type']==='punct'&&(f['value']==='{'||f['value']==='['))g=matchClose(c,d);else return null;}if(g>e)return null;if(g<e){const h=c[g+0x1];if(!(h['type']==='punct'&&(h['value']==='='||h['value']===':'||h['value']==='!')))return null;}return{'start':d,'end':e,'bindEnd':g,'destructured':f['type']!=='id'};}export function splitDeclarators(b,f,g){const h=b[g]?.['type']==='punct'&&b[g]['value']===';'?g-0x1:g;if(f>h)return[];const j=[];let l=0x0;for(let r=f;r<=h;r++){const u=b[r];if(u['type']==='tpl'){if(u['value']['startsWith']('}'))l--;if(u['value']['endsWith']('${'))l++;continue;}if(u['type']!=='punct')continue;if(u['value']==='('||u['value']==='['||u['value']==='{')l++;else{if(u['value']===')'||u['value']===']'||u['value']==='}')l--;else{if(u['value']===','&&l===0x0)j['push'](r);}}}const m=[];let n=f;for(const v of j){m['push']([n,v-0x1]),n=v+0x1;}m['push']([n,h]);const o=[];let p=m[m['length']-0x1];for(let w=m['length']-0x1;w>=0x1;w--){const x=declaratorAt(b,p[0x0],p[0x1]);if(x)o['unshift'](x),p=m[w-0x1];else p=[m[w-0x1][0x0],p[0x1]];}const q=declaratorAt(b,p[0x0],p[0x1]);if(q)o['unshift'](q);return o;}export function declaratorNames(a,b){if(!b['destructured'])return[a[b['start']]['value']];const c=new Set();return collectBindingNames(a,b['start'],b['bindEnd']+0x1,c),Array['from'](c);}export function hashDestructured(a,b){const c=hashDecl(a);return{'bodyHash':digest('h1:',[c['bodyHash'],'\x00'+b]),'shapeHash':digest('h2:',[c['shapeHash'],'\x00'+b]),'tokens':c['tokens']};}export function isStmtStartAt(a,b,c){if(c===0x0)return!![];const d=a[c-0x1];return d['value']===';'||d['value']==='}'||b['slice'](d['end'],a[c]['start'])['includes']('\x0a');}export function legacyStmtHash(a,b){const c=tokenize(a);let d=0x0;const f=g=>isStmtStartAt(c,a,g);for(let g=0x0;g<c['length'];g++){const h=c[g];if(d===0x0&&f(g)&&(h['type']==='kw'||h['value']==='@')){let i=g;while(c[i]?.['value']==='@'){i++;while(c[i]&&(c[i]['type']==='id'||c[i]['type']==='kw'||c[i]['value']==='.'))i++;if(c[i]?.['value']==='(')i=matchClose(c,i)+0x1;}let j=![];c[i]?.['value']==='export'&&(i++,c[i]?.['value']==='default'&&(j=!![],i++));while(c[i]&&(c[i]['value']==='declare'||c[i]['value']==='abstract'))i++;if(c[i]?.['value']==='async'&&c[i+0x1]?.['value']==='function')i++;const l=c[i];let m=-0x1,o=[];if(l&&(l['value']==='function'||l['value']==='class')){let p=i+0x1;if(c[p]?.['value']==='*')p++;o=[c[p]?.['type']==='id'?c[p]['value']:'default'],m=blockDeclEnd(c,p);if(c[m]['value']===';'&&l['value']==='function'){g=m;continue;}}else{if(l&&(l['value']==='const'||l['value']==='let'||l['value']==='var')&&c[i+0x1]?.['value']!=='enum'){m=exprStmtEnd(c,i,a);for(const q of splitDeclarators(c,i+0x1,m))o['push'](...declaratorNames(c,q));}else j&&l&&(m=exprStmtEnd(c,i,a),o=['default']);}if(m>=g){if(o['includes'](b))return hashDecl(a['slice'](c[g]['start'],c[m]['end']))['bodyHash'];g=m;continue;}}if(h['type']==='punct'){if(h['value']==='{'||h['value']==='('||h['value']==='[')d++;else{if(h['value']==='}'||h['value']===')'||h['value']===']')d=Math['max'](0x0,d-0x1);}}}return null;}export function shortHash(a){return a18a['createHash']('sha1')['update'](a)['digest']('hex')['slice'](0x0,0x10);}export function splitIdent(a){return a['replace'](/([a-z0-9])([A-Z])/g,'$1\x20$2')['replace'](/([A-Z]+)([A-Z][a-z])/g,'$1\x20$2')['split'](/[^A-Za-z0-9]+/)['filter'](Boolean)['map'](b=>b['toLowerCase']());}
|
|
1
|
+
import*as a21a from'crypto';const KEYWORDS=new Set(['break','case','catch','class','const','continue','debugger','default','delete','do','else','enum','export','extends','false','finally','for','function','if','import','in','instanceof','new','null','return','super','switch','this','throw','true','try','typeof','var','void','while','with','yield','let','static','await','async','interface','implements','abstract','declare']),REGEX_PREV_KW=new Set(['return','typeof','instanceof','in','of','new','delete','void','throw','case','do','else','yield','await']),isIdStart=a=>/[A-Za-z_$ -]/['test'](a),isIdPart=a=>/[A-Za-z0-9_$ -]/['test'](a);export function tokenize(a){const b=[],f=a['length'];let g=0x0;const h=[],k=()=>b[b['length']-0x1],l=()=>{const q=k();if(!q)return!![];if(q['type']==='num'||q['type']==='str'||q['type']==='tpl'||q['type']==='re')return![];if(q['type']==='id')return![];if(q['type']==='kw')return REGEX_PREV_KW['has'](q['value']);return!(q['value']===')'||q['value']===']'||q['value']==='}');},m=p=>{let q=p;while(q<f){const r=a[q];if(r==='\x5c'){q+=0x2;continue;}if(r==='`')return q+0x1;if(r==='$'&&a[q+0x1]==='{')return q+0x2;q++;}return f;};while(g<f){const p=a[g];if(p==='\x20'||p==='\x09'||p==='\x0a'||p==='\x0d'||p==='\x0c'||p==='\x0b'||p==='\ufeff'){g++;continue;}if(p==='/'&&a[g+0x1]==='/'){while(g<f&&a[g]!=='\x0a')g++;continue;}if(p==='/'&&a[g+0x1]==='*'){const t=a['indexOf']('*/',g+0x2);g=t<0x0?f:t+0x2;continue;}if(p==='}'&&h['length']>0x0&&h[h['length']-0x1]===0x0){h['pop']();const u=m(g+0x1);b['push']({'type':'tpl','value':a['slice'](g,u),'start':g,'end':u});if(a['slice'](u-0x2,u)==='${')h['push'](0x0);g=u;continue;}if(p==='`'){const w=m(g+0x1);b['push']({'type':'tpl','value':a['slice'](g,w),'start':g,'end':w});if(a['slice'](w-0x2,w)==='${')h['push'](0x0);g=w;continue;}if(p==='\x22'||p==='\x27'){let x=g+0x1,y=![];while(x<f){const z=a[x];if(z==='\x5c'){x+=0x2;continue;}if(z==='\x0a')break;if(z===p){y=!![],x++;break;}x++;}y?(b['push']({'type':'str','value':a['slice'](g,x),'start':g,'end':x}),g=x):(b['push']({'type':'punct','value':p,'start':g,'end':g+0x1}),g++);continue;}if(/[0-9]/['test'](p)||p==='.'&&/[0-9]/['test'](a[g+0x1]??'')){let A=g+0x1;while(A<f&&/[0-9A-Za-z_.]/['test'](a[A]))A++;b['push']({'type':'num','value':a['slice'](g,A),'start':g,'end':A}),g=A;continue;}if(isIdStart(p)){let B=g+0x1;while(B<f&&isIdPart(a[B]))B++;const C=a['slice'](g,B);b['push']({'type':KEYWORDS['has'](C)?'kw':'id','value':C,'start':g,'end':B}),g=B;continue;}if(p==='#'&&isIdStart(a[g+0x1]??'')){let D=g+0x1;while(D<f&&isIdPart(a[D]))D++;b['push']({'type':'id','value':a['slice'](g,D),'start':g,'end':D}),g=D;continue;}if(p==='/'&&l()){let E=g+0x1,F=![],G=![];while(E<f){const H=a[E];if(H==='\x5c'){E+=0x2;continue;}if(H==='\x0a')break;if(H==='[')F=!![];else{if(H===']')F=![];else{if(H==='/'&&!F){G=!![],E++;break;}}}E++;}if(G){while(E<f&&/[a-z]/i['test'](a[E]))E++;b['push']({'type':'re','value':a['slice'](g,E),'start':g,'end':E}),g=E;continue;}}const q=a['slice'](g,g+0x4),r=['>>>=','...','===','!==','**=','<<=','>>=','>>>','&&=','||=','??=','=>','==','!=','<=','>=','&&','||','??','?.','++','--','+=','-=','*=','/=','%=','&=','|=','^=','**','<<','>>'];let s=p;for(const I of r){if(q['startsWith'](I)){s=I;break;}}if(h['length']>0x0){if(s==='{')h[h['length']-0x1]++;else{if(s==='}')h[h['length']-0x1]--;}}b['push']({'type':'punct','value':s,'start':g,'end':g+s['length']}),g+=s['length'];}return b;}export function maskSource(a){const b=tokenize(a),c=a['split'](''),d=a['split'](''),f=(h,i,j)=>{for(let l=i;l<j;l++)if(h[l]!=='\x0a')h[l]='\x20';};let g=0x0;for(const h of b){f(c,g,h['start']),f(d,g,h['start']),g=h['end'];if(h['type']==='str')f(d,h['start']+0x1,h['end']-0x1);else{if(h['type']==='tpl'){const i=h['value']['startsWith']('`')||h['value']['startsWith']('}')?h['start']+0x1:h['start'];let j=h['end'];if(h['value']['endsWith']('${'))j-=0x2;else{if(h['value']['endsWith']('`')&&h['value']['length']>0x1)j-=0x1;}f(d,i,j);}}}return f(c,g,a['length']),f(d,g,a['length']),{'code':c['join'](''),'masked':d['join']('')};}function trimDeclTokens(a){let b=0x0,c=a['length'];for(;;){if(b<c&&a[b]['value']==='@'){b++;while(b<c&&(a[b]['type']==='id'||a[b]['type']==='kw'||a[b]['value']==='.'))b++;if(b<c&&a[b]['value']==='('){let d=0x0;for(;b<c;b++){if(a[b]['value']==='(')d++;else{if(a[b]['value']===')'){d--;if(d===0x0){b++;break;}}}}}continue;}if(b<c&&(a[b]['value']==='export'||a[b]['value']==='default'||a[b]['value']==='declare')){b++;continue;}break;}while(c>b&&a[c-0x1]['value']===';')c--;return a['slice'](b,c);}const CONTROL_BEFORE_PAREN=new Set(['if','for','while','switch','with','return','typeof','await','new','in','of','yield','throw','case','delete','void']),PARAM_MODIFIERS=new Set(['public','private','protected','readonly','override']);function matchClose(a,b){const c=a[b]['value'],d=c==='('?')':c==='['?']':'}';let e=0x0;for(let f=b;f<a['length'];f++){const g=a[f]['value'];if(a[f]['type']!=='punct')continue;if(g===c)e++;else{if(g===d){e--;if(e===0x0)return f;}}}return a['length']-0x1;}function collectBindingNames(a,b,c,f){let g=0x0;for(let h=b;h<c;h++){const i=a[h];if(i['type']==='punct'&&(i['value']==='{'||i['value']==='['||i['value']==='(')){g++;continue;}if(i['type']==='punct'&&(i['value']==='}'||i['value']===']'||i['value']===')')){g--;continue;}if(i['type']==='punct'&&i['value']==='='){let l=0x0,m=h+0x1;for(;m<c;m++){const n=a[m]['value'];if(a[m]['type']!=='punct')continue;if(n==='('||n==='['||n==='{')l++;else{if(n===')'||n===']'||n==='}'){if(l===0x0)break;l--;}else{if(n===','&&l===0x0)break;}}}h=m-0x1;continue;}if(i['type']==='punct'&&i['value']===':'&&g===0x0){let o=0x0,p=h+0x1;for(;p<c;p++){const q=a[p]['value'];if(a[p]['type']!=='punct')continue;if(q==='('||q==='['||q==='{'||q==='<')o++;else{if(q===')'||q===']'||q==='}'||q==='>'){if(o===0x0)break;o--;}else{if((q===','||q==='=')&&o===0x0)break;}}}h=p-0x1;continue;}if(i['type']==='id'&&!PARAM_MODIFIERS['has'](i['value'])){const r=a[h+0x1];if(r&&r['value']===':'&&g>0x0)continue;f['add'](i['value']);}}}export function collectLocals(a){const b=new Set();for(let c=0x0;c<a['length'];c++){const d=a[c];if(d['type']==='kw'&&(d['value']==='const'||d['value']==='let'||d['value']==='var')){const e=a[c+0x1];if(!e)continue;if(e['type']==='id')b['add'](e['value']);else{if(e['value']==='{'||e['value']==='[')collectBindingNames(a,c+0x2,matchClose(a,c+0x1),b);}continue;}if(d['type']==='kw'&&(d['value']==='function'||d['value']==='class')){let f=c+0x1;if(a[f]?.['value']==='*')f++;if(a[f]?.['type']==='id')b['add'](a[f]['value']);continue;}if(d['type']==='punct'&&d['value']==='('){const g=a[c-0x1],h=matchClose(a,c),j=a[h+0x1],l=g?.['value']==='catch',m=!g||g['type']!=='kw'||g['value']==='function'||g['value']==='async'||l,n=g&&CONTROL_BEFORE_PAREN['has'](g['value']),o=j&&(j['value']==='=>'||j['value']==='{'||j['value']===':');if(l||m&&!n&&o)collectBindingNames(a,c+0x1,h,b);continue;}if(d['type']==='id'&&a[c+0x1]?.['value']==='=>'&&a[c-0x1]?.['value']!=='.')b['add'](d['value']);}return b;}function digest(a,b){return a+a21a['createHash']('sha1')['update'](b['join']('\x01'))['digest']('hex')['slice'](0x0,0x10);}export function hashDecl(a){const b=trimDeclTokens(tokenize(a)),c=collectLocals(b),d=new Map(),e=[],f=[];for(let g=0x0;g<b['length'];g++){const h=b[g],j=b[g-0x1];if(h['type']==='id'){const k=j&&(j['value']==='.'||j['value']==='?.');if(!k&&c['has'](h['value'])){if(!d['has'](h['value']))d['set'](h['value'],d['size']);e['push']('$'+d['get'](h['value']));}else e['push'](h['value']);f['push']('I');}else{if(h['type']==='num')e['push'](h['value']),f['push']('N');else{if(h['type']==='str'||h['type']==='tpl')e['push'](h['value']),f['push']('S');else h['type']==='re'?(e['push'](h['value']),f['push']('R')):(e['push'](h['value']),f['push'](h['value']));}}}return{'bodyHash':digest('h1:',e),'shapeHash':digest('h2:',f),'tokens':b['length']};}export const STMT_START=new Set(['export','import','const','let','var','function','class','async','interface','enum','declare','abstract','@']);export function exprStmtEnd(a,b,c){let e=0x0;for(let f=b;f<a['length'];f++){const g=a[f];if(g['type']==='punct'){if(g['value']==='('||g['value']==='['||g['value']==='{')e++;else{if(g['value']===')'||g['value']===']'||g['value']==='}')e--;else{if(g['value']===';'&&e===0x0)return f;}}}const h=a[f+0x1];if(!h)return f;if(e===0x0&&f>b&&c['slice'](g['end'],h['start'])['includes']('\x0a')&&STMT_START['has'](h['value'])){if(!(g['type']==='punct'&&/^(=|=>|,|\.|\?|:|\+|-|\*|\/|&&|\|\||\?\?|\(|\[|\{)$/['test'](g['value'])))return f;}}return a['length']-0x1;}export function blockDeclEnd(a,b){let c=b;while(c<a['length']){const d=a[c]['value'];if(a[c]['type']==='punct'&&(d==='('||d==='[')){c=matchClose(a,c)+0x1;continue;}if(a[c]['type']==='punct'&&d==='{')return matchClose(a,c);if(a[c]['type']==='punct'&&d===';')return c;c++;}return a['length']-0x1;}function declaratorAt(c,d,e){const f=c[d];if(!f||d>e)return null;let g;if(f['type']==='id')g=d;else{if(f['type']==='punct'&&(f['value']==='{'||f['value']==='['))g=matchClose(c,d);else return null;}if(g>e)return null;if(g<e){const h=c[g+0x1];if(!(h['type']==='punct'&&(h['value']==='='||h['value']===':'||h['value']==='!')))return null;}return{'start':d,'end':e,'bindEnd':g,'destructured':f['type']!=='id'};}export function splitDeclarators(b,f,g){const h=b[g]?.['type']==='punct'&&b[g]['value']===';'?g-0x1:g;if(f>h)return[];const j=[];let l=0x0;for(let r=f;r<=h;r++){const u=b[r];if(u['type']==='tpl'){if(u['value']['startsWith']('}'))l--;if(u['value']['endsWith']('${'))l++;continue;}if(u['type']!=='punct')continue;if(u['value']==='('||u['value']==='['||u['value']==='{')l++;else{if(u['value']===')'||u['value']===']'||u['value']==='}')l--;else{if(u['value']===','&&l===0x0)j['push'](r);}}}const m=[];let n=f;for(const v of j){m['push']([n,v-0x1]),n=v+0x1;}m['push']([n,h]);const o=[];let p=m[m['length']-0x1];for(let w=m['length']-0x1;w>=0x1;w--){const x=declaratorAt(b,p[0x0],p[0x1]);if(x)o['unshift'](x),p=m[w-0x1];else p=[m[w-0x1][0x0],p[0x1]];}const q=declaratorAt(b,p[0x0],p[0x1]);if(q)o['unshift'](q);return o;}export function declaratorNames(a,b){if(!b['destructured'])return[a[b['start']]['value']];const c=new Set();return collectBindingNames(a,b['start'],b['bindEnd']+0x1,c),Array['from'](c);}export function hashDestructured(a,b){const c=hashDecl(a);return{'bodyHash':digest('h1:',[c['bodyHash'],'\x00'+b]),'shapeHash':digest('h2:',[c['shapeHash'],'\x00'+b]),'tokens':c['tokens']};}export function isStmtStartAt(a,b,c){if(c===0x0)return!![];const d=a[c-0x1];return d['value']===';'||d['value']==='}'||b['slice'](d['end'],a[c]['start'])['includes']('\x0a');}export function legacyStmtHash(a,b){const c=tokenize(a);let d=0x0;const f=g=>isStmtStartAt(c,a,g);for(let g=0x0;g<c['length'];g++){const h=c[g];if(d===0x0&&f(g)&&(h['type']==='kw'||h['value']==='@')){let i=g;while(c[i]?.['value']==='@'){i++;while(c[i]&&(c[i]['type']==='id'||c[i]['type']==='kw'||c[i]['value']==='.'))i++;if(c[i]?.['value']==='(')i=matchClose(c,i)+0x1;}let j=![];c[i]?.['value']==='export'&&(i++,c[i]?.['value']==='default'&&(j=!![],i++));while(c[i]&&(c[i]['value']==='declare'||c[i]['value']==='abstract'))i++;if(c[i]?.['value']==='async'&&c[i+0x1]?.['value']==='function')i++;const l=c[i];let m=-0x1,o=[];if(l&&(l['value']==='function'||l['value']==='class')){let p=i+0x1;if(c[p]?.['value']==='*')p++;o=[c[p]?.['type']==='id'?c[p]['value']:'default'],m=blockDeclEnd(c,p);if(c[m]['value']===';'&&l['value']==='function'){g=m;continue;}}else{if(l&&(l['value']==='const'||l['value']==='let'||l['value']==='var')&&c[i+0x1]?.['value']!=='enum'){m=exprStmtEnd(c,i,a);for(const q of splitDeclarators(c,i+0x1,m))o['push'](...declaratorNames(c,q));}else j&&l&&(m=exprStmtEnd(c,i,a),o=['default']);}if(m>=g){if(o['includes'](b))return hashDecl(a['slice'](c[g]['start'],c[m]['end']))['bodyHash'];g=m;continue;}}if(h['type']==='punct'){if(h['value']==='{'||h['value']==='('||h['value']==='[')d++;else{if(h['value']==='}'||h['value']===')'||h['value']===']')d=Math['max'](0x0,d-0x1);}}}return null;}export function shortHash(a){return a21a['createHash']('sha1')['update'](a)['digest']('hex')['slice'](0x0,0x10);}export function splitIdent(a){return a['replace'](/([a-z0-9])([A-Z])/g,'$1\x20$2')['replace'](/([A-Z]+)([A-Z][a-z])/g,'$1\x20$2')['split'](/[^A-Za-z0-9]+/)['filter'](Boolean)['map'](b=>b['toLowerCase']());}
|
|
@@ -392,6 +392,7 @@ export function loadBaselineLite(storeDir, opts = {}) {
|
|
|
392
392
|
constraints: withProposedConstraints(Array.isArray(b.constraints) ? applyRecordTrust(b.constraints, storeDir, opts, b).constraints : seedLayerConstraintsLite(), storeDir, b.exceptions),
|
|
393
393
|
entrypoints: effectiveEntrypoints(b),
|
|
394
394
|
publicApi: Array.isArray(b.publicApi) ? b.publicApi : DEFAULT_PUBLIC_API,
|
|
395
|
+
...(Array.isArray(b.nonProduct) && b.nonProduct.every((g) => typeof g === "string") ? { nonProduct: b.nonProduct } : {}),
|
|
395
396
|
source: 'file',
|
|
396
397
|
};
|
|
397
398
|
}
|
|
@@ -427,14 +428,41 @@ export function layerOfLite(rel, baseline) {
|
|
|
427
428
|
const defs = baseline.layers?.defs ?? DEFAULT_LAYERS_LITE.defs;
|
|
428
429
|
return defs.find(d => matchGlob(rel, d.match))?.name;
|
|
429
430
|
}
|
|
430
|
-
export
|
|
431
|
-
|
|
431
|
+
export const objOf = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
|
|
432
|
+
/** by 칸이 없거나(구형) 세션을 모르면 예전 그대로, 있으면 그 세션 편집만(출처 모르는 구형 항목 제외) */
|
|
433
|
+
export function trackerViewOf(raw, sid) {
|
|
434
|
+
if (!raw)
|
|
435
|
+
return { files: [], ts: {}, first: {}, heads: {} };
|
|
436
|
+
const ts = objOf(raw.ts);
|
|
437
|
+
const by = objOf(raw.by);
|
|
438
|
+
if (!sid || !raw.by || typeof raw.by !== 'object') {
|
|
439
|
+
return {
|
|
440
|
+
files: Array.isArray(raw.files) ? raw.files.filter((f) => typeof f === 'string') : [],
|
|
441
|
+
ts, first: objOf(raw.first), heads: objOf(raw.heads),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
const mine = objOf(by[sid]);
|
|
445
|
+
const files = Object.keys(mine);
|
|
432
446
|
return {
|
|
433
|
-
files
|
|
434
|
-
ts:
|
|
435
|
-
|
|
447
|
+
files,
|
|
448
|
+
ts: Object.fromEntries(files.filter((f) => typeof ts[f] === 'number').map((f) => [f, ts[f]])),
|
|
449
|
+
first: { ...mine },
|
|
450
|
+
heads: { ...objOf(objOf(raw.sheads)[sid]) },
|
|
436
451
|
};
|
|
437
452
|
}
|
|
453
|
+
/** 이 프로세스의 세션 ID — 세션 등록소(<board>/sessions/<pid>.json, session-registry.ts 와 같은 위치). 없으면 null */
|
|
454
|
+
export function trackerSessionId() {
|
|
455
|
+
const env = Number(process.env.ROUTINECODE_SESSION_PID);
|
|
456
|
+
const pid = Number.isInteger(env) && env > 1 ? env : process.ppid;
|
|
457
|
+
const root = process.env.ROUTINECODE_BOARD_DIR || path.join(homeDir(), '.routinecode', 'board');
|
|
458
|
+
const d = readJson(path.join(root, 'sessions', `${pid}.json`));
|
|
459
|
+
return d && typeof d.session === 'string' && d.session ? d.session.slice(0, 12) : null;
|
|
460
|
+
}
|
|
461
|
+
/** 이 세션의 편집 기록(다른 세션 편집은 이 태스크 평가 대상이 아니다) */
|
|
462
|
+
export function readTracker(sid = trackerSessionId()) {
|
|
463
|
+
const v = trackerViewOf(readJson(path.join(knowledgeDir(), 'edit-tracker.json')), sid);
|
|
464
|
+
return { files: v.files, ts: v.ts, heads: v.heads };
|
|
465
|
+
}
|
|
438
466
|
/** 개입 출력 면제(정비 러너·청사진 관리자·기록자 헤드리스) — block 제약 deny 는 면제하지 않는다 */
|
|
439
467
|
export function interventionExempt() {
|
|
440
468
|
return process.env.ROUTINECODE_ARCHITECT === '1' || process.env.ROUTINECODE_MAINTENANCE === '1' || process.env.ROUTINECODE_RECORDER === '1';
|
|
@@ -732,6 +760,35 @@ export function verifyCertLibSig(sha256, kid, sig, keys) {
|
|
|
732
760
|
return false;
|
|
733
761
|
}
|
|
734
762
|
}
|
|
763
|
+
// ── 디자인 스킬 팩 서명 검증 (설계 23 §3·§5.1 — growth sign-skillpack) ─────────────────────────
|
|
764
|
+
// 같은 레코드 키 목록, 서명 대상은 도메인 분리 페이로드 "rc-skillpack-v1\n"+sha256. cert-lib·결정 레코드 서명과 서로 통과하지 않는다.
|
|
765
|
+
export const SKILLPACK_SIG_DOMAIN = 'rc-skillpack-v1\n';
|
|
766
|
+
/** 팩 다이제스트 서명 대상 바이트 — growth record-signing.service.signSkillPack·knowledge skill-pack.signer 와 바이트 동일 */
|
|
767
|
+
export function skillPackSigPayload(sha256) {
|
|
768
|
+
return Buffer.from(SKILLPACK_SIG_DOMAIN + sha256, 'utf8');
|
|
769
|
+
}
|
|
770
|
+
/** 팩 다이제스트 서명 검증 — verifyCertLibSig 와 같은 형태, 키 목록 없음·kid 없음·목록에 없는 kid·형식 오류 = false (fail-closed) */
|
|
771
|
+
export function verifySkillPackSig(sha256, kid, sig, keys) {
|
|
772
|
+
if (typeof sha256 !== 'string' || !SHA256_HEX_RE.test(sha256))
|
|
773
|
+
return false;
|
|
774
|
+
if (typeof kid !== 'string' || !KID_RE.test(kid))
|
|
775
|
+
return false;
|
|
776
|
+
if (typeof sig !== 'string' || !sig)
|
|
777
|
+
return false;
|
|
778
|
+
const ring = ringOf(keys);
|
|
779
|
+
const b64 = ring.get(kid);
|
|
780
|
+
if (!b64)
|
|
781
|
+
return false;
|
|
782
|
+
const key = pubKeyObject(b64);
|
|
783
|
+
if (!key)
|
|
784
|
+
return false;
|
|
785
|
+
try {
|
|
786
|
+
return crypto.verify(null, skillPackSigPayload(sha256), key, Buffer.from(sig, 'base64'));
|
|
787
|
+
}
|
|
788
|
+
catch {
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
735
792
|
// ── 최신 판정 규칙 (계약 v2 §3.5 — 서버 K7 `latest-decision.ts` 와 같은 함수, 골든 벡터 공유) ─────────
|
|
736
793
|
// 같은 subject id 레코드를 (decidedAt 오름차순, 상태 우선순위 approved < deferred < rejected) 로 정렬해 마지막 1건.
|
|
737
794
|
// 같은 ms 동률이면 더 보수적인(권한을 낮추는) 상태가 이긴다. 두 키까지 같으면 입력 순서상 뒤의 것(안정 정렬).
|