micro-contracts 0.17.13 → 0.17.14
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/cli-contract.yaml
CHANGED
|
@@ -1332,7 +1332,7 @@ cli_contracts: 0.1.0
|
|
|
1332
1332
|
|
|
1333
1333
|
info:
|
|
1334
1334
|
title: micro-contracts CLI
|
|
1335
|
-
version: 0.17.
|
|
1335
|
+
version: 0.17.14
|
|
1336
1336
|
description: >-
|
|
1337
1337
|
Contract-first OpenAPI toolchain for TypeScript Web/API systems.
|
|
1338
1338
|
Generates contract packages, server routes, and frontend clients
|
|
@@ -2755,7 +2755,7 @@ components:
|
|
|
2755
2755
|
"cli_contracts": "0.1.0",
|
|
2756
2756
|
"info": {
|
|
2757
2757
|
"title": "micro-contracts CLI",
|
|
2758
|
-
"version": "0.17.
|
|
2758
|
+
"version": "0.17.14",
|
|
2759
2759
|
"description": "Contract-first OpenAPI toolchain for TypeScript Web/API systems. Generates contract packages, server routes, and frontend clients from OpenAPI specifications with enforceable guardrails.",
|
|
2760
2760
|
"license": {
|
|
2761
2761
|
"name": "MIT"
|
|
@@ -4668,11 +4668,11 @@ components:
|
|
|
4668
4668
|
`);return}await e.auditOpenapi(i,a)}),r.command("review-published").description("Review published API surface for internal leakage.").option("-c, --config <path>","Path to config file (micro-contracts.config.yaml).").option("-m, --module <name>","Module name to review (default is all modules).").option("-a, --adapter <name>","SDK adapter to use for LLM execution.").option("--model <name>","LLM model override.").option("--fail-on <level>","Minimum severity that causes a non-zero exit.","error").option("-o, --output <file>","Write result to a file instead of stdout.").option("--report-format <fmt>","Output format for the review report.","text").option("-l, --log-file <value>","Write agent progress log to this file path.").option("--show-prompt","Output the constructed prompt without calling the LLM API.",!1).action(async(i,n)=>{let a=n.optsWithGlobals();if(a.introspect){let o=xi("review-published",i);console.log(JSON.stringify(o,null,2));return}if(i.showPrompt){let o=await e.reviewPublished(i,a);typeof o=="string"&&process.stdout.write(o+`
|
|
4669
4669
|
`);return}await e.reviewPublished(i,a)}),r.command("propose-overlays").description("Propose cross-cutting overlay candidates.").option("-c, --config <path>","Path to config file (micro-contracts.config.yaml).").option("-m, --module <name>","Module name to analyze (default is all modules).").option("-a, --adapter <name>","SDK adapter to use for LLM execution.").option("--model <name>","LLM model override.").option("--fail-on <level>","Minimum severity that causes a non-zero exit.","error").option("-o, --output <file>","Write result to a file instead of stdout.").option("--report-format <fmt>","Output format for the proposal report.","json").option("-l, --log-file <value>","Write agent progress log to this file path.").option("--show-prompt","Output the constructed prompt without calling the LLM API.",!1).action(async(i,n)=>{let a=n.optsWithGlobals();if(a.introspect){let o=xi("propose-overlays",i);console.log(JSON.stringify(o,null,2));return}if(i.showPrompt){let o=await e.proposeOverlays(i,a);typeof o=="string"&&process.stdout.write(o+`
|
|
4670
4670
|
`);return}await e.proposeOverlays(i,a)}),r.command("audit-guardrails").description("Audit guardrails configuration for drift and lint coverage.").option("-c, --config <path>","Path to config file (micro-contracts.config.yaml).").option("-g, --guardrails <path>","Path to guardrails.yaml.").option("-a, --adapter <name>","SDK adapter to use for LLM execution.").option("--model <name>","LLM model override.").option("--fail-on <level>","Minimum severity that causes a non-zero exit.","error").option("-o, --output <file>","Write result to a file instead of stdout.").option("--report-format <fmt>","Output format for the audit report.","text").option("-l, --log-file <value>","Write agent progress log to this file path.").option("--show-prompt","Output the constructed prompt without calling the LLM API.",!1).action(async(i,n)=>{let a=n.optsWithGlobals();if(a.introspect){let o=xi("audit-guardrails",i);console.log(JSON.stringify(o,null,2));return}if(i.showPrompt){let o=await e.auditGuardrails(i,a);typeof o=="string"&&process.stdout.write(o+`
|
|
4671
|
-
`);return}await e.auditGuardrails(i,a)}),r.command("extract").description("Extract contract specification for this CLI tool.").argument("[commands...]","Command IDs to extract. Use dot notation.").option("-a, --all","Extract all commands.",!1).option("--include-meta","Include extraction metadata.",!0).option("-F, --format <format>","Output format (yaml or json).","yaml").action(async(i,n
|
|
4672
|
-
`),process.exit(2));let
|
|
4673
|
-
`)}else{let
|
|
4671
|
+
`);return}await e.auditGuardrails(i,a)}),r.command("extract").description("Extract contract specification for this CLI tool.").argument("[commands...]","Command IDs to extract. Use dot notation.").option("-a, --all","Extract all commands.",!1).option("--include-meta","Include extraction metadata.",!0).option("-F, --format <format>","Output format (yaml or json).","yaml").action(async(i,n)=>{i.length===0&&!n.all&&(process.stderr.write(JSON.stringify({code:"INVALID_ARGS",message:"Specify command IDs or use --all"})+`
|
|
4672
|
+
`),process.exit(2));let a=n.format||"yaml",o=JSON.parse(Mj),s=n.all?[]:i;if(s.length===0)if(a==="json"){let l={};n.includeMeta&&(l._meta={source:"embedded",type:"cli-contracts/extract",extractedAt:new Date().toISOString(),specVersion:o.cli_contracts??"0.1.0",commands:["micro-contracts.generate","micro-contracts.lint","micro-contracts.init","micro-contracts.check","micro-contracts.pipeline","micro-contracts.deps","micro-contracts.insights","micro-contracts.guardrails-init","micro-contracts.manifest","micro-contracts.audit-openapi","micro-contracts.review-published","micro-contracts.propose-overlays","micro-contracts.audit-guardrails"]}),Object.assign(l,o),process.stdout.write(JSON.stringify(l,null,2)+`
|
|
4673
|
+
`)}else{let l=[];if(l.push("# micro-contracts extract"),l.push("# source: embedded"),l.push("# type: cli-contracts/command-extract"),n.includeMeta){l.push("---"),l.push("source: embedded"),l.push("type: cli-contracts/command-extract"),l.push("extractedAt: "+new Date().toISOString()),l.push("spec_version: "+(o.cli_contracts??"0.1.0")),l.push("commands:");for(let u of["micro-contracts.generate","micro-contracts.lint","micro-contracts.init","micro-contracts.check","micro-contracts.pipeline","micro-contracts.deps","micro-contracts.insights","micro-contracts.guardrails-init","micro-contracts.manifest","micro-contracts.audit-openapi","micro-contracts.review-published","micro-contracts.propose-overlays","micro-contracts.audit-guardrails"])l.push(" - "+u)}l.push("---"),l.push(Lj),process.stdout.write(l.join(`
|
|
4674
4674
|
`)+`
|
|
4675
|
-
`)}else{let
|
|
4675
|
+
`)}else{let l={cli_contracts:o.cli_contracts,info:o.info,command_sets:{}},u=l.command_sets;for(let[c,d]of Object.entries(o.command_sets??{})){let p=d.commands;if(!p)continue;let f={};for(let[m,h]of Object.entries(p)){let g=c+"."+m;s.some(y=>y===m||y===g||m.startsWith(y+"."))&&(f[m]=h)}if(Object.keys(f).length>0){let m={...d};m.commands=f,u[c]=m}}o.components&&(l.components=o.components),process.stdout.write(JSON.stringify(l,null,2)+`
|
|
4676
4676
|
`)}process.exit(0)}),r}Lp();Ai();import Hn from"fs";import Mr from"path";Ai();function K5(e){let t=e.type;if(t===void 0)return{types:[],nullable:!!e.nullable};let r=Array.isArray(t)?t:[t],i=r.includes("null");return{types:r.filter(a=>a!=="null"),nullable:i||!!e.nullable}}function H5(e){let t=[];if(t.push("/**"),t.push(" * Auto-generated TypeScript types from OpenAPI specification"),t.push(` * Generated from: ${e.info.title} v${e.info.version}`),t.push(" * DO NOT EDIT MANUALLY"),t.push(" */"),t.push(""),t.push(Pme()),t.push(""),e.components?.schemas)for(let[i,n]of Object.entries(e.components.schemas))i!=="ProblemDetails"&&(t.push(Ime(i,n,e)),t.push(""));let r=Rme(e);return r&&(t.push("// Operation-specific types"),t.push(r)),t.join(`
|
|
4677
4677
|
`)}function Pme(){return`/**
|
|
4678
4678
|
* RFC 9457 Problem Details for HTTP APIs
|
|
@@ -5491,7 +5491,7 @@ ${o}`:Array.isArray(a)&&a.length>0?`${r}${n}:
|
|
|
5491
5491
|
${o}`:`${r}${n}: ${o}`}).join(`
|
|
5492
5492
|
`)}return String(e)}var _s={auditOpenapi:"audit-openapi-design",reviewPublished:"audit-published-api",proposeOverlays:"propose-overlay-candidates",auditGuardrails:"audit-guardrails-coverage"};async function Sre(e){let t=await wF(e.config,e.module);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await hs(t,_s.auditOpenapi,r,i),a=vs(n,e.reportFormat??"text");await ys(a,e.output);let o=gs(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Co||a===Do)&&(console.error(ru.red(n.message)),process.exit(a)),n}}async function Ere(e){let t=await SF(e.config,e.module);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await hs(t,_s.reviewPublished,r,i),a=vs(n,e.reportFormat??"text");await ys(a,e.output);let o=gs(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Co||a===Do)&&(console.error(ru.red(n.message)),process.exit(a)),n}}async function $re(e){let t=await EF(e.config,e.module);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await hs(t,_s.proposeOverlays,r,i),a=vs(n,e.reportFormat??"json");await ys(a,e.output);let o=gs(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Co||a===Do)&&(console.error(ru.red(n.message)),process.exit(a)),n}}async function kre(e){let t=await $F(e.config,e.guardrails);if(e.showPrompt)return t;let r={adapter:e.adapter,model:e.model},i={failOn:e.failOn,logFile:e.logFile};try{let n=await hs(t,_s.auditGuardrails,r,i),a=vs(n,e.reportFormat??"text");await ys(a,e.output);let o=gs(n,i);o!==0&&process.exit(o)}catch(n){let a=n.exitCode;throw(a===Co||a===Do)&&(console.error(ru.red(n.message)),process.exit(a)),n}}import bC from"fs";import bs from"path";import{createRequire as _Ie}from"module";Ai();Ai();var bIe=_Ie(import.meta.url),wIe=bIe("../../package.json"),Pre="micro-contracts",SIe="api_contract_declaration",xre=.9;function EIe(e){let t=["micro-contracts.config.yaml","micro-contracts.config.yml","api-framework.config.yaml","api-framework.config.yml"];for(let r of t){let i=bs.join(e,r);if(bC.existsSync(i))return i}return null}function Are(e,t){let r=bs.relative(e,t);return r.startsWith("..")?t:r.split(bs.sep).join("/")}function _C(e){return e.raw}function y6(e,t,r){return`${e}/services/${t}ServiceApi.ts#${r}`}function $Ie(e,t){let r=e.split(`
|
|
5493
5493
|
`);for(let i=0;i<r.length;i++)if(r[i].includes(t))return i+1}function Cre(e,t,r,i,n){let a=i?$Ie(r,i):void 0;return{kind:SIe,detail:e,filePath:t,...a!==void 0?{line:a}:{},...n!==void 0?{symbolId:n}:{}}}function kIe(e){let t=new Map,r=["get","post","put","patch","delete"];for(let i of Object.values(e.paths))for(let n of r){let a=i[n];if(!a?.operationId)continue;let o=a["x-micro-contracts-service"],s=a["x-micro-contracts-method"];typeof o=="string"&&typeof s=="string"&&t.set(a.operationId,{service:o,method:s})}return t}function Dre(e,t,r){return`${e}.${t}.${r}`}function Ore(e,t,r){return`${e}\0${t}\0${r}`}function xIe(e,t){return{symbolId:y6(e,t.service,t.method),filePath:`${e}/services/${t.service}ServiceApi.ts`,startLine:1,endLine:1}}function SC(e,t={}){let r=bs.resolve(e),i=t.configPath?bs.resolve(t.configPath):EIe(r);if(!i)throw new Error("micro-contracts.config.yaml not found. Run from project root or pass --config.");let n=Yo(i);if(!fo(n))throw new Error("Insight provider requires multi-module config with modules.");let a=bs.dirname(i),o=n.defaults??{},s=[],l=new Map;for(let[h,g]of Object.entries(n.modules)){let y=pc(h,g,o),_=bs.resolve(a,y.openapi);if(!bC.existsSync(_))continue;let w=Jo(_),S=Are(r,_),C=Are(r,bs.resolve(r,y.contractOutput));l.set(h,C),s.push({name:h,openapiRel:S,resolved:y,spec:w})}let u=[],c=new Set,d=new Map,p=h=>{d.has(h.name)||d.set(h.name,{domainId:h.name,filePaths:[h.openapiRel,h.resolved.contractOutput]})},f=h=>{let g=_C(h);if(d.has(g))return;let y=l.get(h.module);if(!y)return;let _=s.find(S=>S.name===h.module),w=_?[_.openapiRel,y]:[y];d.set(g,{domainId:g,filePaths:w,symbolIds:[y6(y,h.service,h.method)],symbols:[xIe(y,h)]})},m=(h,g,y,_,w)=>{let S=Dre(h,g,y);if(d.has(S))return;let C=y6(_,g,y);d.set(S,{domainId:S,filePaths:[w,_],symbolIds:[C],symbols:[{symbolId:C,filePath:`${_}/services/${g}ServiceApi.ts`,startLine:1,endLine:1}]})};for(let h of s){p(h);let g=bC.readFileSync(bs.resolve(r,h.openapiRel),"utf-8"),y=Mp(h.spec),_=l.get(h.name),w=kIe(h.spec);for(let S of y.moduleLevelDeps){let C=h.name,D=_C(S),E="api_dependency",A=Ore(C,D,E);c.has(A)||(c.add(A),f(S),u.push({from:C,to:D,kind:E,propagation:"forward",weight:xre,evidence:[Cre(`module declares dependency on ${S.raw}`,h.openapiRel,g,S.raw)]}))}for(let[S,C]of y.operationLevelDeps){let D=w.get(S);if(!D)continue;let E=Dre(h.name,D.service,D.method);m(h.name,D.service,D.method,_,h.openapiRel);for(let A of C){let T=_C(A),P="api_operation_dependency",$=Ore(E,T,P);if(c.has($))continue;c.add($),f(A);let k=y6(_,D.service,D.method);u.push({from:E,to:T,kind:P,propagation:"forward",weight:xre,evidence:[Cre(`operation ${E} declares dependency on ${A.raw}`,h.openapiRel,g,A.raw,k)]})}}}return{source:Pre,sourceVersion:wIe.version,generatedAt:new Date().toISOString(),edges:u,anchorMapping:[...d.values()]}}function AIe(e,t){let{changedFiles:r,artifactIds:i}=t;if(!r?.length&&!i?.length)return e;let n=new Set;if(r?.length){let l=new Set(r);for(let u of e.anchorMapping??[])u.filePaths.some(c=>l.has(c))&&n.add(u.domainId)}if(i?.length)for(let l of i)n.add(l);let a=e.edges.filter(l=>n.has(l.from)||n.has(l.to)),o=new Set;for(let l of a)o.add(l.from),o.add(l.to);let s=(e.anchorMapping??[]).filter(l=>o.has(l.domainId));return{...e,edges:a,anchorMapping:s.length>0?s:void 0}}var wC=class{name=Pre;async provide(t){let r=SC(t.projectRoot);return AIe(r,t)}},eZe=new wC;async function Ire(e){let t=e.format??"json";if(t!=="json")throw new Error(`Unsupported --format: ${t}. Only "json" is supported.`);let r=e.projectRoot??process.cwd(),i=SC(r,{configPath:e.config});process.stdout.write(`${JSON.stringify(i)}
|
|
5494
|
-
`)}var qd={version:"0.17.
|
|
5494
|
+
`)}var qd={version:"0.17.14"};function EC(){let e=["micro-contracts.config.yaml","micro-contracts.config.yml","api-framework.config.yaml","api-framework.config.yml"];for(let t of e){let r=sn.resolve(t);if(wr.existsSync(r))return r}return null}var CIe={generate:async e=>{try{let t,r=e.config?sn.resolve(e.config):EC();r||(console.error("Error: No config file found."),console.error("Create micro-contracts.config.yaml or use --config <path>"),process.exit(1)),wr.existsSync(r)||(console.error(`Config file not found: ${r}`),process.exit(1)),console.log(`Using config: ${r}`),t=Yo(r);let i=e.cache!==!1&&!e.force,n;if(fo(t)&&(n=lg(t,r,qd.version),i)){let a=e.manifestDir||"packages/",o=await bf(a,n);if(o.skip){console.log(`No input changes detected, skipping generation (${o.reason})`);return}}if(await Yb(t,{contractsOnly:e.contractsOnly,serverOnly:e.serverOnly,frontendOnly:e.frontendOnly,docsOnly:e.docsOnly,skipLint:e.skipLint,modules:e.module}),e.manifest!==!1){let{config:a}=Oi();if(a?.generated&&a.generated.length>0){let o=e.manifestDir||"packages/";if(wr.existsSync(o)){let s=e.cache!==!1?n:void 0,{manifest:l,changed:u}=await Oc(o,{generatorVersion:qd.version,inputHash:s}),c=Object.keys(l.files).length;if(u){let d=nl(l,o);console.log(`
|
|
5495
5495
|
Manifest updated: ${d} (${c} files)`)}else console.log(`
|
|
5496
5496
|
Manifest unchanged (${c} files)`)}}}}catch(t){console.error("Generation failed:",t instanceof Error?t.message:t),process.exit(1)}},lint:async e=>{try{let t=sn.resolve(e);wr.existsSync(t)||(console.error(`OpenAPI spec not found: ${t}`),process.exit(1)),console.log(`Linting: ${t}
|
|
5497
5497
|
`);let r=Jo(t),i=Ko(r,{strict:!1});console.log(Xu(i)),i.valid||process.exit(1)}catch(t){console.error("Lint failed:",t instanceof Error?t.message:t),process.exit(1)}},init:async(e,t)=>{console.log(`Initializing module "${e}"${t.screens?" (screen spec)":""}...
|