@longzai-intelligence-dependencies/cli 0.0.20 → 0.0.21

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.
Files changed (2) hide show
  1. package/dist/index.js +7 -6
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -159,7 +159,7 @@ Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._life
159
159
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
160
160
  - ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=re.resolve(e,t);if(O.existsSync(r))return r;if(n.includes(re.extname(t)))return;let i=n.find(e=>O.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=O.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=re.resolve(re.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=re.basename(this._scriptPath,re.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(re.extname(i)),s;R.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=Pd(R.execArgv).concat(t),s=se.spawn(R.execPath,t,{stdio:`inherit`})):o?(t.unshift(i),t=Pd(R.execArgv).concat(t),s=se.spawn(R.argv[0],t,{stdio:`inherit`})):s=se.spawn(i,t,{stdio:`inherit`}),s.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(e=>{R.on(e,()=>{s.killed===!1&&s.exitCode===null&&s.kill(e)})});let c=this._exitCallback;s.on(`close`,e=>{e??=1,c?c(new Sd(e,`commander.executeSubCommandAsync`,`(close)`)):R.exit(e)}),s.on(`error`,t=>{if(t.code===`ENOENT`)this._checkForMissingExecutable(i,a,e._name);else if(t.code===`EACCES`)throw Error(`'${i}' not executable`);if(!c)R.exit(1);else{let e=new Sd(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=t,c(e)}}),this.runningCommand=s}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic||this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)!==void 0&&this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)([eE][+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l)))this.emit(`option:${o.name()}`,l);else{if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
161
161
  `),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in R.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,R.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new Od(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=Md(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=e.length,i=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${r}: ${e.join(`, `)}.`;this.error(i,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=Md(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>Td(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=re.basename(e,re.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(R.exitCode??0);t===0&&e&&typeof e!=`function`&&e.error&&(t=1),this._exit(t,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
162
- Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function Pd(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk|-wait)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function Fd(){if(R.env.NO_COLOR||R.env.FORCE_COLOR===`0`||R.env.FORCE_COLOR===`false`)return!1;if(R.env.FORCE_COLOR||R.env.CLICOLOR_FORCE!==void 0)return!0}new Nd;let Id;function Ld(){return Id??=xd(`@longzai-intelligence-cli/core/provider`),Id}const Rd={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,cyan:e=>e,magenta:e=>e,gray:e=>e,bold:e=>e,dim:e=>e};let zd={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>Ld().info(e),stop:e=>Ld().info(e)}),note:(e,t)=>{t?Ld().info(`${t}: ${e}`):Ld().info(e)},log:{info:e=>Ld().info(e),success:e=>Ld().info(e),warn:e=>Ld().warn(e),error:e=>Ld().error(e),step:e=>Ld().info(e)}},Bd=Rd;function Vd(e){zd=e}function Hd(e){Bd=e}function Ud(){return zd}function Wd(){return Bd}const Gd=()=>`0.0.20`;function Kd(e){let t=e.version??Gd();e.interaction&&Vd(e.interaction),e.color&&Hd(e.color);let n=new Nd;return n.name(e.name).version(t,`-v, --version`,`输出 ${e.name} 的版本号`),e.description&&n.description(e.description),n}let qd;function Jd(){return qd??=xd(`@longzai-intelligence-cli/core/define-command`),qd}function Yd(e,t){let n=e.commands.find(e=>e.name()===t);return n===void 0?e.command(t):n}function Xd(e,t){if(t.length===1){let n=t[0];if(n===void 0)throw Error(`defineCommand: segments 为空,无法解析命令名`);return e.command(n)}let[n,...r]=t;if(n===void 0)throw Error(`defineCommand: segments 首段为空,无法解析父命令名`);let i=r.pop();if(i===void 0)throw Error(`defineCommand: segments 末段为空,无法解析子命令名`);let a=Yd(e,n);for(let e of r)a=Yd(a,e);return a.command(i)}function Zd(e){return typeof e==`object`&&!!e&&`opts`in e&&typeof e.opts==`function`&&`args`in e&&Array.isArray(e.args)}function Qd(e,t){let n=Xd(e,t.name.split(` `).filter(e=>e.length>0));t.description&&n.description(t.description);for(let e of t.arguments??[])e.description?n.argument(e.signature,e.description):n.argument(e.signature);for(let e of t.options??[])e.defaultValue===void 0?n.option(e.flags,e.description??``):n.option(e.flags,e.description??``,e.defaultValue);n.action(async(...e)=>{let n=e[e.length-1];if(!Zd(n))return;let r=n.opts(),i=n.args,a=t.schema.safeParse(r);if(!a.success){let e=a.error.issues.map(e=>e.message).join(`, `);Jd().error(Wd().red(`参数校验失败: ${e}`)),Ud().log.error(`参数校验失败: ${e}`),process.exit(1)}await t.action(a.data,i)})}var $d=/* @__PURE__ */ D(import.meta.url);function ef(e){let t=S(e);return t.length>1&&t[t.length-1]===E&&(t=t.substring(0,t.length-1)),t}const tf=/[\\/]/g;function nf(e,t){return e.replace(tf,t)}const rf=/^[a-z]:[\\/]$/i;function af(e){return e===`/`||rf.test(e)}function of(e,t){let{resolvePaths:n,normalizePath:r,pathSeparator:i}=t,a=process.platform===`win32`&&e.includes(`/`)||e.startsWith(`.`);return n&&(e=T(e)),(r||a)&&(e=ef(e)),e===`.`?``:nf(e[e.length-1]===i?e:e+i,i)}function sf(e,t){return t+e}function cf(e,t){return function(n,r){return r.startsWith(e)?r.slice(e.length)+n:nf(w(e,r),t.pathSeparator)+t.pathSeparator+n}}function lf(e){return e}function uf(e,t,n){return t+e+n}function df(e,t){let{relativePaths:n,includeBasePath:r}=t;return n&&e?cf(e,t):r?sf:lf}function ff(e){return function(t,n){n.push(t.substring(e.length)||`.`)}}function pf(e){return function(t,n,r){let i=t.substring(e.length)||`.`;r.every(e=>e(i,!0))&&n.push(i)}}const mf=(e,t)=>{t.push(e||`.`)},hf=(e,t,n)=>{let r=e||`.`;n.every(e=>e(r,!0))&&t.push(r)},gf=()=>{};function _f(e,t){let{includeDirs:n,filters:r,relativePaths:i}=t;return n?i?r&&r.length?pf(e):ff(e):r&&r.length?hf:mf:gf}const vf=(e,t,n,r)=>{r.every(t=>t(e,!1))&&n.files++},yf=(e,t,n,r)=>{r.every(t=>t(e,!1))&&t.push(e)},bf=(e,t,n,r)=>{n.files++},xf=(e,t)=>{t.push(e)},Sf=()=>{};function Cf(e){let{excludeFiles:t,filters:n,onlyCounts:r}=e;return t?Sf:n&&n.length?r?vf:yf:r?bf:xf}const wf=e=>e,Tf=()=>[``].slice(0,0);function Ef(e){return e.group?Tf:wf}const Df=(e,t,n)=>{e.push({directory:t,files:n,dir:t})},Of=()=>{};function kf(e){return e.group?Df:Of}const Af=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue(),i.realpath(e,(o,s)=>{if(o)return r.dequeue(a?null:o,t);i.stat(s,(i,o)=>{if(i)return r.dequeue(a?null:i,t);if(o.isDirectory()&&Nf(e,s,t))return r.dequeue(null,t);n(o,s),r.dequeue(null,t)})})},jf=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue();try{let r=i.realpathSync(e),a=i.statSync(r);if(a.isDirectory()&&Nf(e,r,t))return;n(a,r)}catch(e){if(!a)throw e}};function Mf(e,t){return!e.resolveSymlinks||e.excludeSymlinks?null:t?jf:Af}function Nf(e,t,n){if(n.options.useRealPaths)return Pf(t,n);let r=b(e),i=1;for(;r!==n.root&&i<2;){let e=n.symlinks.get(r);e&&(e===t||e.startsWith(t)||t.startsWith(e))?i++:r=b(r)}return n.symlinks.set(e,t),i>1}function Pf(e,t){return t.visited.includes(e+t.options.pathSeparator)}const Ff=e=>e.counts,If=e=>e.groups,Lf=e=>e.paths,Rf=e=>e.paths.slice(0,e.options.maxFiles),zf=(e,t,n)=>(Uf(t,n,e.counts,e.options.suppressErrors),null),Bf=(e,t,n)=>(Uf(t,n,e.paths,e.options.suppressErrors),null),Vf=(e,t,n)=>(Uf(t,n,e.paths.slice(0,e.options.maxFiles),e.options.suppressErrors),null),Hf=(e,t,n)=>(Uf(t,n,e.groups,e.options.suppressErrors),null);function Uf(e,t,n,r){t(e&&!r?e:null,n)}function Wf(e,t){let{onlyCounts:n,group:r,maxFiles:i}=e;return n?t?Ff:zf:r?t?If:Hf:i?t?Rf:Vf:t?Lf:Bf}const Gf={withFileTypes:!0},Kf=(e,t,n,r,i)=>{if(e.queue.enqueue(),r<0)return e.queue.dequeue(null,e);let{fs:a}=e;e.visited.push(t),e.counts.directories++,a.readdir(t||`.`,Gf,(t,a=[])=>{i(a,n,r),e.queue.dequeue(e.options.suppressErrors?null:t,e)})},qf=(e,t,n,r,i)=>{let{fs:a}=e;if(r<0)return;e.visited.push(t),e.counts.directories++;let o=[];try{o=a.readdirSync(t||`.`,Gf)}catch(t){if(!e.options.suppressErrors)throw t}i(o,n,r)};function Jf(e){return e?qf:Kf}var Yf=class{count=0;constructor(e){this.onQueueEmpty=e}enqueue(){return this.count++,this.count}dequeue(e,t){this.onQueueEmpty&&(--this.count<=0||e)&&(this.onQueueEmpty(e,t),e&&(t.controller.abort(),this.onQueueEmpty=void 0))}},Xf=class{_files=0;_directories=0;set files(e){this._files=e}get files(){return this._files}set directories(e){this._directories=e}get directories(){return this._directories}
162
+ Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function Pd(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk|-wait)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function Fd(){if(R.env.NO_COLOR||R.env.FORCE_COLOR===`0`||R.env.FORCE_COLOR===`false`)return!1;if(R.env.FORCE_COLOR||R.env.CLICOLOR_FORCE!==void 0)return!0}new Nd;let Id;function Ld(){return Id??=xd(`@longzai-intelligence-cli/core/provider`),Id}const Rd={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,cyan:e=>e,magenta:e=>e,gray:e=>e,bold:e=>e,dim:e=>e};let zd={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>Ld().info(e),stop:e=>Ld().info(e)}),note:(e,t)=>{t?Ld().info(`${t}: ${e}`):Ld().info(e)},log:{info:e=>Ld().info(e),success:e=>Ld().info(e),warn:e=>Ld().warn(e),error:e=>Ld().error(e),step:e=>Ld().info(e)}},Bd=Rd;function Vd(e){zd=e}function Hd(e){Bd=e}function Ud(){return zd}function Wd(){return Bd}const Gd=()=>`0.0.21`;function Kd(e){let t=e.version??Gd();e.interaction&&Vd(e.interaction),e.color&&Hd(e.color);let n=new Nd;return n.name(e.name).version(t,`-v, --version`,`输出 ${e.name} 的版本号`),e.description&&n.description(e.description),n}let qd;function Jd(){return qd??=xd(`@longzai-intelligence-cli/core/define-command`),qd}function Yd(e,t){let n=e.commands.find(e=>e.name()===t);return n===void 0?e.command(t):n}function Xd(e,t){if(t.length===1){let n=t[0];if(n===void 0)throw Error(`defineCommand: segments 为空,无法解析命令名`);return e.command(n)}let[n,...r]=t;if(n===void 0)throw Error(`defineCommand: segments 首段为空,无法解析父命令名`);let i=r.pop();if(i===void 0)throw Error(`defineCommand: segments 末段为空,无法解析子命令名`);let a=Yd(e,n);for(let e of r)a=Yd(a,e);return a.command(i)}function Zd(e){return typeof e==`object`&&!!e&&`opts`in e&&typeof e.opts==`function`&&`args`in e&&Array.isArray(e.args)}function Qd(e,t){let n=Xd(e,t.name.split(` `).filter(e=>e.length>0));t.description&&n.description(t.description);for(let e of t.arguments??[])e.description?n.argument(e.signature,e.description):n.argument(e.signature);for(let e of t.options??[])e.defaultValue===void 0?n.option(e.flags,e.description??``):n.option(e.flags,e.description??``,e.defaultValue);n.action(async(...e)=>{let n=e[e.length-1];if(!Zd(n))return;let r=n.opts(),i=n.args,a=t.schema.safeParse(r);if(!a.success){let e=a.error.issues.map(e=>e.message).join(`, `);Jd().error(Wd().red(`参数校验失败: ${e}`)),Ud().log.error(`参数校验失败: ${e}`),process.exit(1)}await t.action(a.data,i)})}var $d=/* @__PURE__ */ D(import.meta.url);function ef(e){let t=S(e);return t.length>1&&t[t.length-1]===E&&(t=t.substring(0,t.length-1)),t}const tf=/[\\/]/g;function nf(e,t){return e.replace(tf,t)}const rf=/^[a-z]:[\\/]$/i;function af(e){return e===`/`||rf.test(e)}function of(e,t){let{resolvePaths:n,normalizePath:r,pathSeparator:i}=t,a=process.platform===`win32`&&e.includes(`/`)||e.startsWith(`.`);return n&&(e=T(e)),(r||a)&&(e=ef(e)),e===`.`?``:nf(e[e.length-1]===i?e:e+i,i)}function sf(e,t){return t+e}function cf(e,t){return function(n,r){return r.startsWith(e)?r.slice(e.length)+n:nf(w(e,r),t.pathSeparator)+t.pathSeparator+n}}function lf(e){return e}function uf(e,t,n){return t+e+n}function df(e,t){let{relativePaths:n,includeBasePath:r}=t;return n&&e?cf(e,t):r?sf:lf}function ff(e){return function(t,n){n.push(t.substring(e.length)||`.`)}}function pf(e){return function(t,n,r){let i=t.substring(e.length)||`.`;r.every(e=>e(i,!0))&&n.push(i)}}const mf=(e,t)=>{t.push(e||`.`)},hf=(e,t,n)=>{let r=e||`.`;n.every(e=>e(r,!0))&&t.push(r)},gf=()=>{};function _f(e,t){let{includeDirs:n,filters:r,relativePaths:i}=t;return n?i?r&&r.length?pf(e):ff(e):r&&r.length?hf:mf:gf}const vf=(e,t,n,r)=>{r.every(t=>t(e,!1))&&n.files++},yf=(e,t,n,r)=>{r.every(t=>t(e,!1))&&t.push(e)},bf=(e,t,n,r)=>{n.files++},xf=(e,t)=>{t.push(e)},Sf=()=>{};function Cf(e){let{excludeFiles:t,filters:n,onlyCounts:r}=e;return t?Sf:n&&n.length?r?vf:yf:r?bf:xf}const wf=e=>e,Tf=()=>[``].slice(0,0);function Ef(e){return e.group?Tf:wf}const Df=(e,t,n)=>{e.push({directory:t,files:n,dir:t})},Of=()=>{};function kf(e){return e.group?Df:Of}const Af=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue(),i.realpath(e,(o,s)=>{if(o)return r.dequeue(a?null:o,t);i.stat(s,(i,o)=>{if(i)return r.dequeue(a?null:i,t);if(o.isDirectory()&&Nf(e,s,t))return r.dequeue(null,t);n(o,s),r.dequeue(null,t)})})},jf=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue();try{let r=i.realpathSync(e),a=i.statSync(r);if(a.isDirectory()&&Nf(e,r,t))return;n(a,r)}catch(e){if(!a)throw e}};function Mf(e,t){return!e.resolveSymlinks||e.excludeSymlinks?null:t?jf:Af}function Nf(e,t,n){if(n.options.useRealPaths)return Pf(t,n);let r=b(e),i=1;for(;r!==n.root&&i<2;){let e=n.symlinks.get(r);e&&(e===t||e.startsWith(t)||t.startsWith(e))?i++:r=b(r)}return n.symlinks.set(e,t),i>1}function Pf(e,t){return t.visited.includes(e+t.options.pathSeparator)}const Ff=e=>e.counts,If=e=>e.groups,Lf=e=>e.paths,Rf=e=>e.paths.slice(0,e.options.maxFiles),zf=(e,t,n)=>(Uf(t,n,e.counts,e.options.suppressErrors),null),Bf=(e,t,n)=>(Uf(t,n,e.paths,e.options.suppressErrors),null),Vf=(e,t,n)=>(Uf(t,n,e.paths.slice(0,e.options.maxFiles),e.options.suppressErrors),null),Hf=(e,t,n)=>(Uf(t,n,e.groups,e.options.suppressErrors),null);function Uf(e,t,n,r){t(e&&!r?e:null,n)}function Wf(e,t){let{onlyCounts:n,group:r,maxFiles:i}=e;return n?t?Ff:zf:r?t?If:Hf:i?t?Rf:Vf:t?Lf:Bf}const Gf={withFileTypes:!0},Kf=(e,t,n,r,i)=>{if(e.queue.enqueue(),r<0)return e.queue.dequeue(null,e);let{fs:a}=e;e.visited.push(t),e.counts.directories++,a.readdir(t||`.`,Gf,(t,a=[])=>{i(a,n,r),e.queue.dequeue(e.options.suppressErrors?null:t,e)})},qf=(e,t,n,r,i)=>{let{fs:a}=e;if(r<0)return;e.visited.push(t),e.counts.directories++;let o=[];try{o=a.readdirSync(t||`.`,Gf)}catch(t){if(!e.options.suppressErrors)throw t}i(o,n,r)};function Jf(e){return e?qf:Kf}var Yf=class{count=0;constructor(e){this.onQueueEmpty=e}enqueue(){return this.count++,this.count}dequeue(e,t){this.onQueueEmpty&&(--this.count<=0||e)&&(this.onQueueEmpty(e,t),e&&(t.controller.abort(),this.onQueueEmpty=void 0))}},Xf=class{_files=0;_directories=0;set files(e){this._files=e}get files(){return this._files}set directories(e){this._directories=e}get directories(){return this._directories}
163
163
  /* c8 ignore next 3 */
164
164
  get dirs(){return this._directories}},Zf=class{aborted=!1;abort(){this.aborted=!0}},Qf=class{root;isSynchronous;state;joinPath;pushDirectory;pushFile;getArray;groupFiles;resolveSymlink;walkDirectory;callbackInvoker;constructor(e,t,n){this.isSynchronous=!n,this.callbackInvoker=Wf(t,this.isSynchronous),this.root=of(e,t),this.state={root:af(this.root)?this.root:this.root.slice(0,-1),paths:[``].slice(0,0),groups:[],counts:new Xf,options:t,queue:new Yf((e,t)=>this.callbackInvoker(t,e,n)),symlinks:/* @__PURE__ */ new Map,visited:[``].slice(0,0),controller:new Zf,fs:t.fs||f},this.joinPath=df(this.root,t),this.pushDirectory=_f(this.root,t),this.pushFile=Cf(t),this.getArray=Ef(t),this.groupFiles=kf(t),this.resolveSymlink=Mf(t,this.isSynchronous),this.walkDirectory=Jf(this.isSynchronous)}start(){return this.pushDirectory(this.root,this.state.paths,this.state.options.filters),this.walkDirectory(this.state,this.root,this.root,this.state.options.maxDepth,this.walk),this.isSynchronous?this.callbackInvoker(this.state,null):null}walk=(e,t,n)=>{let{paths:r,options:{filters:i,resolveSymlinks:a,excludeSymlinks:o,exclude:s,maxFiles:c,signal:l,useRealPaths:u,pathSeparator:d},controller:f}=this.state;if(f.aborted||l&&l.aborted||c&&r.length>c)return;let p=this.getArray(this.state.paths);for(let c=0;c<e.length;++c){let l=e[c];if(l.isFile()||l.isSymbolicLink()&&!a&&!o){let e=this.joinPath(l.name,t);this.pushFile(e,p,this.state.counts,i)}else if(l.isDirectory()){let e=uf(l.name,t,this.state.options.pathSeparator);if(s&&s(l.name,e))continue;this.pushDirectory(e,r,i),this.walkDirectory(this.state,e,e,n-1,this.walk)}else if(this.resolveSymlink&&l.isSymbolicLink()){let e=sf(l.name,t);this.resolveSymlink(e,this.state,(t,r)=>{if(t.isDirectory()){if(r=of(r,this.state.options),s&&s(l.name,u?r:e+d))return;this.walkDirectory(this.state,r,u?r:e+d,n-1,this.walk)}else{r=u?r:e;let t=y(r),n=of(b(r),this.state.options);r=this.joinPath(t,n),this.pushFile(r,p,this.state.counts,i)}})}}this.groupFiles(this.state.groups,t,p)}};function $f(e,t){return new Promise((n,r)=>{ep(e,t,(e,t)=>{if(e)return r(e);n(t)})})}function ep(e,t,n){new Qf(e,t,n).start()}function tp(e,t){return new Qf(e,t).start()}var np=class{constructor(e,t){this.root=e,this.options=t}withPromise(){return $f(this.root,this.options)}withCallback(e){ep(this.root,this.options,e)}sync(){return tp(this.root,this.options)}};let rp=null;
165
165
  /* c8 ignore next 6 */
@@ -327,8 +327,9 @@ n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2
327
327
  --- 根清单依赖准入 ---`),t.violations.length===0)return $(`工作区根清单未发现业务依赖`),0;for(let e of t.violations)$(` ${e.dependency} ${e.field}`);return $(`共 ${t.violations.length} 处业务依赖出现在工作区根清单,业务依赖应下沉到实际使用的子包,处置口径见 ADR 0182`),t.violations.length},Mw=async()=>{let e=await LC();return new Set(e.rootManifest?.allowlist??[])},Nw=async()=>{let e=null;try{let t=Ew.safeParse(await Bun.file(`${process.cwd()}/package.json`).json());e=t.success?t.data:null}catch{e=null}if(e===null)return 0;let t=yw(e.workspaces);if(t===null||t.length===0)return 0;let n=await xw(t,Dw),r=new Set(n.map(e=>e.name).filter(e=>typeof e==`string`));if(r.size===0)return 0;$(`
328
328
  --- 自仓引用协议 ---`);let i={relativePath:`package.json`,dependencies:e.dependencies,devDependencies:e.devDependencies},a=bw([i,...n],r);if(a.length===0)return $(`全部自仓引用均使用 workspace 协议`),0;for(let e of a)$(` ${e.manifest} ${e.dependency} ${e.field} ${e.currentVersion}`);return $(`共 ${a.length} 处自仓引用未使用 workspace 协议,修复指引:将引用值恢复为 workspace:* 后执行 bun install`),a.length},Pw=async()=>{let e=null;try{let t=Ew.safeParse(await Bun.file(`${process.cwd()}/package.json`).json());e=t.success?t.data:null}catch{e=null}if(e===null)return 0;let t=yw(e.workspaces);if(t===null||t.length===0)return 0;let n=await xw(t,Ow),r=cw(n,await Fw());if(!r.inScope)return 0;if($(`
329
329
  --- 应用包出口形态 ---`),r.violations.length===0)return $(`apps 层应用包 exports 形态全部合规`),0;for(let e of r.violations)$(` ${e.relPath} ${e.extraExits.join(` `)}`);return $(`共 ${r.violations.length} 个 apps 层应用包存在多出口 exports,应用包 exports 只允许无或单一根出口,跨应用复用一律经根出口取件,处置口径见 ADR 0198`),r.violations.length},Fw=async()=>{let e=await LC();return new Set(e.appExports?.allowlist??[])},Iw=async()=>{let e=null;try{let t=Ew.safeParse(await Bun.file(`${process.cwd()}/package.json`).json());e=t.success?t.data:null}catch{e=null}if(e===null)return 0;let t=yw(e.workspaces),n=t===null||t.length===0?[]:await xw(t,kw);$(`
330
- --- 同 scope 版本锁步 ---`);let r={relativePath:`package.json`,dependencies:e.dependencies,devDependencies:e.devDependencies},i=hw([r,...n],await Lw());if(i.length===0)return $(`同 scope 内部分包声明取值全部一致`),0;for(let e of i){$(` ${e.manifest} ${e.scope}`);for(let t of e.members)$(` ${t.dependency} ${t.field} ${t.specifier}`)}return $(`共 ${i.length} 组同 scope 分包声明版本不一致,同 scope 各分包声明取值应完全一致,对齐后执行 bun install,豁免须经特别申请登记于 lzi-dependencies.config.ts 的 lockstep.allowlist`),i.length},Lw=async()=>{let e=await LC();return new Set(e.lockstep?.allowlist??[])},Rw=async e=>{let t=(await LC()).upgrade??{},{packages:n}=await XS({cwd:process.cwd(),mode:`latest`,write:!1,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:e===void 0?t.include??[]:[...e],depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:!1,timediff:!0,nodecompat:!0,loglevel:`silent`,silent:!0,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在校验 Longzai Intelligence 依赖新鲜度...`)}});return n},zw=e=>{let t=/* @__PURE__ */ new Set;for(let n of e)for(let e of n.resolved)e.name.startsWith(Tw)&&e.resolveError!=null&&t.add(e.name);return[...t]},Bw=(e,t,n)=>{let r=0;for(let i of e){let e=i.resolved.filter(e=>!e.update||!e.name.startsWith(Tw)?!1:n?t.has(e.name):!t.has(e.name));if(e.length!==0){r+=e.length,$(`\n${i.name||i.relative}:`);for(let t of e){let e=t.diff??``,r=n?`,回退基线`:``;$(` ${t.name}: ${t.currentVersion} -> ${t.targetVersion} ${e}${r}`)}}}return r};function Vw(e){let t=e;for(;;){if(k(P(t,`longzai-intelligence-globals`))||k(P(t,`lzi-architecture.yaml`)))return t;let e=P(t,`..`);if(e===t)return;t=e}}function Hw(e){return e.filter(e=>k(P(e.path,`package.json`))).map(e=>({name:e.project,dir:e.path}))}async function Uw(e){if(e.projectScope!==void 0){let t=await NC({scopeIds:[e.projectScope]});return t.ok||(IC(`错误: 项目范围解析失败: ${t.error.message}`),IC(`提示: 请确认 .env 配置 LZI_PROJECT_REGISTRY_ROOT 与 LZI_PROJECT_SCOPE_ROOTS`),process.exit(1)),{registryRoot:t.value.registryRoot,scopeId:e.projectScope,projects:Hw(t.value.projects),source:`env`}}let t=Vw(e.cwd??process.cwd());t===void 0&&(IC(`错误: 未定位产品群聚合根(一级子目录应存在 longzai-intelligence-globals 仓)`),IC(`提示: 请自产品群内任意仓库运行,或使用 --project-scope <id> 显式圈定范围`),process.exit(1));let n=ie(t),r=P(t,`longzai-intelligence-project-registry`);k(P(r,`scopes`))||(IC(`错误: registry 声明域缺失: ${P(r,`scopes`)}`),IC(`提示: 请确认 longzai-intelligence-project-registry 仓已在聚合根就位`),process.exit(1));let i=await NC({registryRoot:r,scopeIds:[n],scopeRoots:/* @__PURE__ */ new Map([[n,t]])});return i.ok||(IC(`错误: 项目范围解析失败: ${i.error.message}`),process.exit(1)),{registryRoot:r,scopeId:n,projects:Hw(i.value.projects),source:`structure`}}const Ww=(e,t)=>Bun.spawnSync([`git`,`diff`,`--quiet`,`HEAD`,`--`,t],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Gw=e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`("${t}/[^"]+":\\s*")[^"]*(")`,`g`)},Kw=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),qw=e=>/^[~^]?\d/.test(e),Jw=(e,t)=>`${/^[~^]/.exec(e)?.[0]??``}${t}`,Yw=e=>{let t=Bun.spawnSync([`git`,`ls-files`,`--`,`*/package.json`],{cwd:e,stdout:`pipe`,stderr:`pipe`});return t.exitCode===0?[`package.json`,...(t.stdout?.toString()??``).trim().split(`
331
- `).map(e=>e.trim()).filter(e=>e.length>0).filter(t=>k(P(e,t)))]:[`package.json`]},Xw=(e,t,n)=>Bun.spawnSync([`git`,`commit`,...t,`-m`,n],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Zw=async(e,t,n,r)=>{let i=await Bun.file(e).text(),a=[],o=[],s=[],c;for(t.lastIndex=0;(c=t.exec(i))!==null;){let e=c[0],t=c[1]??``,i=c[2]??``,a=/^"([^"]+)"/.exec(t)?.[1]??``,o=e.slice(t.length,e.length-i.length),l=n(a,o);o!==l&&qw(o)&&!r.has(a)&&s.push({name:a,oldVersion:o,targetVersion:l,prefix:t,suffix:i})}if(s.length===0)return{matchedPackages:a,changes:o};let l=i;for(let e of s){let t=RegExp(`("${Kw(e.name)}":\\s*")[^"]*(")`);l=l.replace(t,`$1${e.targetVersion}$2`),a.push(e.name),o.push({name:e.name,from:e.oldVersion,to:e.targetVersion})}return await Bun.write(e,l),{matchedPackages:a,changes:o}},Qw=async(e,t,n,r)=>{let i=await Bun.file(e).text(),a=[],o=[];t.lastIndex=0;let s;for(;(s=t.exec(i))!==null;){let e=s[0],t=s[1]??``,i=s[2]??``,c=/^"([^"]+)"/.exec(t)?.[1]??``,l=e.slice(t.length,e.length-i.length),u=n(c,l);l!==u&&qw(l)&&!r.has(c)&&(a.push(c),o.push({name:c,from:l,to:u}))}return{matchedPackages:a,changes:o}},$w=async(e,t,n,r,i)=>{let{name:a,dir:o}=e,s=await ww(o),c=Yw(o),l=[],u=[],d=[],f=[];for(let e of c){let r=P(o,e),a=await Qw(r,t,n,s);if(a.matchedPackages.length!==0){if(!Ww(o,e))d.push(e);else{if(i)l.push(...a.matchedPackages),u.push(...a.changes);else{let e=await Zw(r,t,n,s);l.push(...e.matchedPackages),u.push(...e.changes)}f.push(e)}}}return f.length===0?d.length>0?{name:a,dir:o,matchedPackages:l,changes:u,skippedFiles:d,status:`skipped-dirty`,reason:`package.json 已有未提交改动:${d.join(`,`)}`}:{name:a,dir:o,matchedPackages:l,changes:u,status:`skipped-nochange`,reason:`无匹配 scope 或已是目标版本`}:i||Xw(o,f,r)?{name:a,dir:o,matchedPackages:l,changes:u,skippedFiles:d,status:`success`}:{name:a,dir:o,matchedPackages:l,changes:u,skippedFiles:d,status:`failed`,reason:`git commit 失败,文件已修改,需人工介入`}},eT=async(e,t)=>{let n=/* @__PURE__ */ new Set;for(let r of e){let e=Yw(r.dir);for(let i of e){let e=P(r.dir,i),a=await Bun.file(e).text();t.lastIndex=0;let o;for(;(o=t.exec(a))!==null;){let e=o[1]??``,t=/^"([^"]+)"/.exec(e)?.[1];t&&n.add(t)}}}return[...n]},tT=async(e,t)=>{let n=/* @__PURE__ */ new Map,r=[],i=0,a=async e=>{let t=await wx(e),i=t.tags?.latest;if(i===void 0){let n=t.error instanceof Error?t.error.message:t.error??`未找到 dist-tags.latest`;r.push({name:e,reason:n})}else n.set(e,i)},o=async()=>{for(;i<e.length;){let t=e[i];i++,t!==void 0&&await a(t)}},s=Array.from({length:Math.min(t,e.length)},()=>o());if(await Promise.all(s),r.length>0){IC(`${PC.RED}错误: 部分包查询 npm latest 失败,已中止(0 文件改动、0 提交)${PC.RESET}`);for(let e of r)IC(` ${e.name}: ${e.reason}`);process.exit(1)}return n},nT=async e=>{let{scope:t,version:n,message:r,dryRun:i}=e,a=e.concurrency??10,o=await Uw({projectScope:e.projectScope}),s=n===void 0,c=s?`latest(各自 npm 最新)`:n,l=r??(s?`chore: 升级 ${t} 版本至最新`:`chore: 升级 ${t} 版本至 ${n.replace(/^[~^]/,``)}`),u=Gw(t);$(`${PC.BLUE}═══ version upgrade-across ═══${PC.RESET}`),$(`项目获取来源: ${o.source===`structure`?`结构锚点(cwd 上溯聚合根)`:`显式圈定(--project-scope)`}`),$(`registry: ${o.registryRoot}`),$(`项目范围: ${o.scopeId}`),$(`升级范围: ${t} 下的所有包 -> ${c}`),$(`并发数: ${a}`),i&&$(`${PC.YELLOW}[dry-run] 预览模式,不写文件、不提交${PC.RESET}`),$(``);let d=o.projects;$(`发现 ${d.length} 个子项目,并发处理(并发 ${a})...`),$(``);let f;if(s){let e=await eT(d,u);if(e.length===0){$(`${PC.YELLOW}未匹配到任何 ${t} 下的包,结束${PC.RESET}`);return}$(`匹配到 ${e.length} 个 ${t} 下的包,查询 npm latest...`);let n=await tT(e,a);f=(e,t)=>Jw(t,n.get(e)??``)}else{let e=n??``;f=()=>e}let p=[],m=0,h=d.length;await(async(e,t)=>{let n=0,r=async()=>{for(;n<e.length;){let t=e[n];if(n++,t===void 0)break;let r=await $w(t,u,f,l,i);p.push(r),m++;let a=r.status===`success`?`${PC.GREEN}✓${PC.RESET}`:r.status===`failed`?`${PC.RED}✗${PC.RESET}`:`·`;$(` [${m}/${h}] ${a} ${t.name}`)}},a=Array.from({length:Math.min(t,e.length)},()=>r());await Promise.all(a)})(d,a),$(``),rT(p,i)},rT=(e,t)=>{let n=e.filter(e=>e.status===`success`),r=e.filter(e=>e.status===`skipped-dirty`),i=e.filter(e=>e.status===`skipped-nochange`),a=e.filter(e=>e.status===`failed`);$(`${PC.BLUE}═══ 处理结果 ═══${PC.RESET}`);let o=t?`将提交`:`已提交`;$(`${PC.GREEN}✓ ${o}: ${n.length}${PC.RESET}`);for(let e of n){let t=e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `);$(` ${e.name}`),$(` ${t}`),e.skippedFiles!==void 0&&e.skippedFiles.length>0&&$(` ⚠ 脏文件跳过:${e.skippedFiles.join(`,`)}`)}if(r.length>0){$(``),$(`${PC.YELLOW}⚠ 跳过(文件已改动): ${r.length}${PC.RESET}`);for(let e of r)$(` ${e.name}: ${e.reason}`)}if(i.length>0&&($(``),$(`跳过(无匹配/已是目标版本): ${i.length}`)),a.length>0){$(``),$(`${PC.RED}✗ 失败(需人工介入): ${a.length}${PC.RESET}`);for(let e of a)$(` ${e.name}: ${e.reason}`),$(` ${e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `)}`)}$(``),$(`${PC.BLUE}汇总: ${n.length} ${o} / ${r.length} 跳过(dirty) / ${i.length} 跳过(无变更) / ${a.length} 失败${PC.RESET}`),!t&&n.length>0&&($(``),$(`下一步:推送到远程`),$(` bun push-all`)),a.length>0&&(process.exitCode=1)},iT=e=>[`${e}/*`,`${e}-*/*`],aT=Lc([`default`,`major`,`minor`,`patch`,`latest`,`newest`]).default(`default`),oT=async e=>{let t=(await LC()).upgrade??{},n=e.mode||t.mode||`default`,r=aT.safeParse(n),i=r.success?r.data:`default`,a=[...e.scope?iT(e.scope):[],...t.include??[]],{packages:o}=await XS({cwd:process.cwd(),mode:i,write:!e.dryRun&&e.write,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:a,depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:e.locked===!0,timediff:!0,nodecompat:!0,loglevel:`info`,silent:!1,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在检查依赖更新...`)},beforePackageStart:e=>{$(`正在检查 ${e.name||e.relative}...`)},afterPackageEnd:e=>{let t=e.resolved.filter(e=>e.update).length;$(t>0?` ✓ ${e.name||e.relative}: 发现 ${t} 个可更新依赖`:` ✓ ${e.name||e.relative}: 所有依赖已是最新`)},afterPackageWrite:e=>{$(` 📝 已写入 ${e.name||e.relative}`)}}),s=0;$(`
332
- --- 检查结果 ---`);for(let e of o){let t=e.resolved.filter(e=>e.update);if(t.length>0){s+=t.length,$(`\n${e.name||e.relative}:`);for(let e of t){let t=e.diff??``;$(` ${e.name}: ${e.currentVersion} -> ${e.targetVersion} (${t})`)}}}s===0?$(`所有依赖已是最新版本`):($(`\n共发现 ${s} 个可更新依赖`),e.write?$(`已写入 package.json`):$(`使用 --write 参数写入 package.json`))};function sT(e){Qd(e,{name:`upgrade`,description:`检查依赖版本更新`,arguments:[{signature:`[mode]`,description:`升级模式(major/minor/patch/latest/newest)`},{signature:`[scope]`,description:`可选。仅升级指定 scope 族的依赖(如 @longzai-intelligence-oxlint 或族根 @longzai-intelligence),内部展开为 include @scope/* 与 @scope-*/*`}],options:[{flags:`--write`,description:`将更新写入 package.json`},{flags:`--dry-run`,description:`仅预览`},{flags:`--locked`,description:`包含精确锁定版本的依赖(默认跳过以数字开头的精确 pin)`}],schema:Dc({write:_c().optional(),dryRun:_c().optional(),locked:_c().optional()}),action:async(e,t)=>{let n=t[0],r=t[1];await oT({mode:n,write:e.write===!0,dryRun:e.dryRun===!0,locked:e.locked,scope:r})}}),Qd(e,{name:`upgrade-across`,description:`跨产品群批量升级依赖(项目清单经 project-registry 声明域获取)`,options:[{flags:`--scope <scope>`,description:`依赖 scope(必填,如 @longzai-intelligence-builder)`},{flags:`--target <version>`,description:`目标版本号(可选,如 ^0.0.8。省略时自动取每个匹配包的 npm latest)`},{flags:`-m, --message <message>`,description:`自定义提交信息`},{flags:`--project-scope <id>`,description:`显式圈定项目范围(缺省自动取当前 edition 范围)`},{flags:`--concurrency <n>`,description:`并发数(默认 10)`},{flags:`--dry-run`,description:`仅预览(不写文件、不提交)`}],schema:Dc({scope:U().optional(),target:U().optional(),message:U().optional(),config:U().optional(),concurrency:pl().int().positive().optional(),projectScope:U().optional(),dryRun:_c().optional()}),action:async e=>{e.scope||(process.stderr.write(`错误: upgrade-across 需要指定 --scope <@scope>
333
- `),process.stderr.write(`示例: --scope @longzai-intelligence-builder
334
- `),process.exit(1)),await nT({scope:e.scope,version:e.target,message:e.message,projectScope:e.projectScope,concurrency:e.concurrency,dryRun:e.dryRun===!0})}}),Qd(e,{name:`check`,description:`依赖声明聚合检查,覆盖根清单准入、自仓引用协议、应用包出口形态、同 scope 版本锁步与依赖新鲜度`,schema:Dc({}),action:async()=>{await Aw()}})}function cT(e){Qd(e,{name:`hoisting check`,description:`归位三段检查:子包重复声明根依赖、根声明技术栈专属依赖与构建面痕迹引擎声明完备`,schema:Dc({}),action:async()=>{await iw()}})}function lT(e){Qd(e,{name:`overrides check`,description:`检查 package.json 是否声明未豁免的强制版本字段`,schema:Dc({}),action:async()=>{await sw()}})}function uT(e){Qd(e,{name:`boundary check`,description:`检查 packages 层包是否依赖 domains 层领域契约包并校验领域目录层名合规`,schema:Dc({}),action:async()=>{await GC()}})}function dT(){let e=Kd({name:`lzi-dependencies`,description:`Longzai Intelligence 依赖版本管理工具`,version:`0.0.20`});return sT(e),cT(e),lT(e),uT(e),e}async function fT(){await dT().parseAsync(process.argv)}import.meta.main===!0&&await fT();export{dT as buildProgram};
330
+ --- 同 scope 版本锁步 ---`);let r={relativePath:`package.json`,dependencies:e.dependencies,devDependencies:e.devDependencies},i=hw([r,...n],await Lw());if(i.length===0)return $(`同 scope 内部分包声明取值全部一致`),0;for(let e of i){$(` ${e.manifest} ${e.scope}`);for(let t of e.members)$(` ${t.dependency} ${t.field} ${t.specifier}`)}return $(`共 ${i.length} 组同 scope 分包声明版本不一致,同 scope 各分包声明取值应完全一致,对齐后执行 bun install,豁免须经特别申请登记于 lzi-dependencies.config.ts 的 lockstep.allowlist`),i.length},Lw=async()=>{let e=await LC();return new Set(e.lockstep?.allowlist??[])},Rw=async e=>{let t=(await LC()).upgrade??{},{packages:n}=await XS({cwd:process.cwd(),mode:`latest`,write:!1,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:e===void 0?t.include??[]:[...e],depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:!1,timediff:!0,nodecompat:!0,loglevel:`silent`,silent:!0,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在校验 Longzai Intelligence 依赖新鲜度...`)}});return n},zw=e=>{let t=/* @__PURE__ */ new Set;for(let n of e)for(let e of n.resolved)e.name.startsWith(Tw)&&e.resolveError!=null&&t.add(e.name);return[...t]},Bw=(e,t,n)=>{let r=0;for(let i of e){let e=i.resolved.filter(e=>!e.update||!e.name.startsWith(Tw)?!1:n?t.has(e.name):!t.has(e.name));if(e.length!==0){r+=e.length,$(`\n${i.name||i.relative}:`);for(let t of e){let e=t.diff??``,r=n?`,回退基线`:``;$(` ${t.name}: ${t.currentVersion} -> ${t.targetVersion} ${e}${r}`)}}}return r};function Vw(e){let t=e;for(;;){if(k(P(t,`longzai-intelligence-globals`))||k(P(t,`lzi-architecture.yaml`)))return t;let e=P(t,`..`);if(e===t)return;t=e}}function Hw(e){return e.filter(e=>k(P(e.path,`package.json`))).map(e=>({name:e.project,dir:e.path}))}async function Uw(e){if(e.projectScope!==void 0){let t=await NC({scopeIds:[e.projectScope]});return t.ok||(IC(`错误: 项目范围解析失败: ${t.error.message}`),IC(`提示: 请确认 .env 配置 LZI_PROJECT_REGISTRY_ROOT 与 LZI_PROJECT_SCOPE_ROOTS`),process.exit(1)),{registryRoot:t.value.registryRoot,scopeId:e.projectScope,projects:Hw(t.value.projects),source:`env`}}let t=Vw(e.cwd??process.cwd());t===void 0&&(IC(`错误: 未定位产品群聚合根(一级子目录应存在 longzai-intelligence-globals 仓)`),IC(`提示: 请自产品群内任意仓库运行,或使用 --project-scope <id> 显式圈定范围`),process.exit(1));let n=ie(t),r=P(t,`longzai-intelligence-project-registry`);k(P(r,`scopes`))||(IC(`错误: registry 声明域缺失: ${P(r,`scopes`)}`),IC(`提示: 请确认 longzai-intelligence-project-registry 仓已在聚合根就位`),process.exit(1));let i=await NC({registryRoot:r,scopeIds:[n],scopeRoots:/* @__PURE__ */ new Map([[n,t]])});return i.ok||(IC(`错误: 项目范围解析失败: ${i.error.message}`),process.exit(1)),{registryRoot:r,scopeId:n,projects:Hw(i.value.projects),source:`structure`}}const Ww=(e,t)=>Bun.spawnSync([`git`,`diff`,`--quiet`,`HEAD`,`--`,t],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Gw=e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`("${t}/[^"]+":\\s*")[^"]*(")`,`g`)},Kw=e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`("${t}":\\s*")[^"]*(")`,`g`)},qw=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),Jw=e=>/^[~^]?\d/.test(e),Yw=(e,t)=>`${/^[~^]/.exec(e)?.[0]??``}${t}`,Xw=e=>{let t=Bun.spawnSync([`git`,`ls-files`,`--`,`*/package.json`],{cwd:e,stdout:`pipe`,stderr:`pipe`});return t.exitCode===0?[`package.json`,...(t.stdout?.toString()??``).trim().split(`
331
+ `).map(e=>e.trim()).filter(e=>e.length>0).filter(t=>k(P(e,t)))]:[`package.json`]},Zw=(e,t,n)=>Bun.spawnSync([`git`,`commit`,...t,`-m`,n],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,Qw=async(e,t,n,r)=>{let i=await Bun.file(e).text(),a=[],o=[],s=[],c;for(t.lastIndex=0;(c=t.exec(i))!==null;){let e=c[0],t=c[1]??``,i=c[2]??``,a=/^"([^"]+)"/.exec(t)?.[1]??``,o=e.slice(t.length,e.length-i.length),l=n(a,o);o!==l&&Jw(o)&&!r.has(a)&&s.push({name:a,oldVersion:o,targetVersion:l,prefix:t,suffix:i})}if(s.length===0)return{matchedPackages:a,changes:o};let l=i;for(let e of s){let t=RegExp(`("${qw(e.name)}":\\s*")[^"]*(")`);l=l.replace(t,`$1${e.targetVersion}$2`),a.push(e.name),o.push({name:e.name,from:e.oldVersion,to:e.targetVersion})}return await Bun.write(e,l),{matchedPackages:a,changes:o}},$w=async(e,t,n,r)=>{let i=await Bun.file(e).text(),a=[],o=[];t.lastIndex=0;let s;for(;(s=t.exec(i))!==null;){let e=s[0],t=s[1]??``,i=s[2]??``,c=/^"([^"]+)"/.exec(t)?.[1]??``,l=e.slice(t.length,e.length-i.length),u=n(c,l);l!==u&&Jw(l)&&!r.has(c)&&(a.push(c),o.push({name:c,from:l,to:u}))}return{matchedPackages:a,changes:o}},eT=async(e,t,n,r,i)=>{let{name:a,dir:o}=e,s=await ww(o),c=Xw(o),l=[],u=[],d=[],f=[];for(let e of c){let r=P(o,e),a=await $w(r,t,n,s);if(a.matchedPackages.length!==0){if(!Ww(o,e))d.push(e);else{if(i)l.push(...a.matchedPackages),u.push(...a.changes);else{let e=await Qw(r,t,n,s);l.push(...e.matchedPackages),u.push(...e.changes)}f.push(e)}}}return f.length===0?d.length>0?{name:a,dir:o,matchedPackages:l,changes:u,skippedFiles:d,status:`skipped-dirty`,reason:`package.json 已有未提交改动:${d.join(`,`)}`}:{name:a,dir:o,matchedPackages:l,changes:u,status:`skipped-nochange`,reason:`无匹配 scope 或已是目标版本`}:i||Zw(o,f,r)?{name:a,dir:o,matchedPackages:l,changes:u,skippedFiles:d,status:`success`}:{name:a,dir:o,matchedPackages:l,changes:u,skippedFiles:d,status:`failed`,reason:`git commit 失败,文件已修改,需人工介入`}},tT=async(e,t)=>{let n=/* @__PURE__ */ new Set;for(let r of e){let e=Xw(r.dir);for(let i of e){let e=P(r.dir,i),a=await Bun.file(e).text();t.lastIndex=0;let o;for(;(o=t.exec(a))!==null;){let e=o[1]??``,t=/^"([^"]+)"/.exec(e)?.[1];t&&n.add(t)}}}return[...n]},nT=async(e,t)=>{let n=/* @__PURE__ */ new Map,r=[],i=0,a=async e=>{let t=await wx(e),i=t.tags?.latest;if(i===void 0){let n=t.error instanceof Error?t.error.message:t.error??`未找到 dist-tags.latest`;r.push({name:e,reason:n})}else n.set(e,i)},o=async()=>{for(;i<e.length;){let t=e[i];i++,t!==void 0&&await a(t)}},s=Array.from({length:Math.min(t,e.length)},()=>o());if(await Promise.all(s),r.length>0){IC(`${PC.RED}错误: 部分包查询 npm latest 失败,已中止(0 文件改动、0 提交)${PC.RESET}`);for(let e of r)IC(` ${e.name}: ${e.reason}`);process.exit(1)}return n},rT=async e=>{let{scope:t,package:n,version:r,message:i,dryRun:a}=e;if(t===void 0==(n===void 0)){process.stderr.write(`错误: upgrade-across 需要在 --scope <@scope> 与 --package <包名> 之间恰选其一
332
+ `),process.exitCode=1;return}let o=t??n??``,s=e.concurrency??10,c=await Uw({projectScope:e.projectScope}),l=r===void 0,u=l?`latest(各自 npm 最新)`:r,d=i??(l?`chore: 升级 ${o} 版本至最新`:`chore: 升级 ${o} 版本至 ${r.replace(/^[~^]/,``)}`),f=n===void 0?Gw(o):Kw(n);$(`${PC.BLUE}═══ version upgrade-across ═══${PC.RESET}`),$(`项目获取来源: ${c.source===`structure`?`结构锚点(cwd 上溯聚合根)`:`显式圈定(--project-scope)`}`),$(`registry: ${c.registryRoot}`),$(`项目范围: ${c.scopeId}`),$(`升级范围: ${n===void 0?`${o} 下的所有包`:`${o}(精确包名)`} -> ${u}`),$(`并发数: ${s}`),a&&$(`${PC.YELLOW}[dry-run] 预览模式,不写文件、不提交${PC.RESET}`),$(``);let p=c.projects;$(`发现 ${p.length} 个子项目,并发处理(并发 ${s})...`),$(``);let m;if(l){let e=await tT(p,f);if(e.length===0){$(`${PC.YELLOW}未匹配到任何 ${t} 下的包,结束${PC.RESET}`);return}$(`匹配到 ${e.length} 个 ${t} 下的包,查询 npm latest...`);let n=await nT(e,s);m=(e,t)=>Yw(t,n.get(e)??``)}else{let e=r??``;m=()=>e}let h=[],g=0,_=p.length;await(async(e,t)=>{let n=0,r=async()=>{for(;n<e.length;){let t=e[n];if(n++,t===void 0)break;let r=await eT(t,f,m,d,a);h.push(r),g++;let i=r.status===`success`?`${PC.GREEN}✓${PC.RESET}`:r.status===`failed`?`${PC.RED}✗${PC.RESET}`:`·`;$(` [${g}/${_}] ${i} ${t.name}`)}},i=Array.from({length:Math.min(t,e.length)},()=>r());await Promise.all(i)})(p,s),$(``),iT(h,a)},iT=(e,t)=>{let n=e.filter(e=>e.status===`success`),r=e.filter(e=>e.status===`skipped-dirty`),i=e.filter(e=>e.status===`skipped-nochange`),a=e.filter(e=>e.status===`failed`);$(`${PC.BLUE}═══ 处理结果 ═══${PC.RESET}`);let o=t?`将提交`:`已提交`;$(`${PC.GREEN}✓ ${o}: ${n.length}${PC.RESET}`);for(let e of n){let t=e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `);$(` ${e.name}`),$(` ${t}`),e.skippedFiles!==void 0&&e.skippedFiles.length>0&&$(` ⚠ 脏文件跳过:${e.skippedFiles.join(`,`)}`)}if(r.length>0){$(``),$(`${PC.YELLOW}⚠ 跳过(文件已改动): ${r.length}${PC.RESET}`);for(let e of r)$(` ${e.name}: ${e.reason}`)}if(i.length>0&&($(``),$(`跳过(无匹配/已是目标版本): ${i.length}`)),a.length>0){$(``),$(`${PC.RED}✗ 失败(需人工介入): ${a.length}${PC.RESET}`);for(let e of a)$(` ${e.name}: ${e.reason}`),$(` ${e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `)}`)}$(``),$(`${PC.BLUE}汇总: ${n.length} ${o} / ${r.length} 跳过(dirty) / ${i.length} 跳过(无变更) / ${a.length} 失败${PC.RESET}`),!t&&n.length>0&&($(``),$(`下一步:推送到远程`),$(` bun push-all`)),a.length>0&&(process.exitCode=1)},aT=e=>[`${e}/*`,`${e}-*/*`],oT=Lc([`default`,`major`,`minor`,`patch`,`latest`,`newest`]).default(`default`),sT=async e=>{let t=(await LC()).upgrade??{},n=e.mode||t.mode||`default`,r=oT.safeParse(n),i=r.success?r.data:`default`,a=[...e.scope?aT(e.scope):[],...t.include??[]],{packages:o}=await XS({cwd:process.cwd(),mode:i,write:!e.dryRun&&e.write,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:a,depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:e.locked===!0,timediff:!0,nodecompat:!0,loglevel:`info`,silent:!1,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在检查依赖更新...`)},beforePackageStart:e=>{$(`正在检查 ${e.name||e.relative}...`)},afterPackageEnd:e=>{let t=e.resolved.filter(e=>e.update).length;$(t>0?` ✓ ${e.name||e.relative}: 发现 ${t} 个可更新依赖`:` ✓ ${e.name||e.relative}: 所有依赖已是最新`)},afterPackageWrite:e=>{$(` 📝 已写入 ${e.name||e.relative}`)}}),s=0;$(`
333
+ --- 检查结果 ---`);for(let e of o){let t=e.resolved.filter(e=>e.update);if(t.length>0){s+=t.length,$(`\n${e.name||e.relative}:`);for(let e of t){let t=e.diff??``;$(` ${e.name}: ${e.currentVersion} -> ${e.targetVersion} (${t})`)}}}s===0?$(`所有依赖已是最新版本`):($(`\n共发现 ${s} 个可更新依赖`),e.write?$(`已写入 package.json`):$(`使用 --write 参数写入 package.json`))};function cT(e){Qd(e,{name:`upgrade`,description:`检查依赖版本更新`,arguments:[{signature:`[mode]`,description:`升级模式(major/minor/patch/latest/newest)`},{signature:`[scope]`,description:`可选。仅升级指定 scope 族的依赖(如 @longzai-intelligence-oxlint 或族根 @longzai-intelligence),内部展开为 include @scope/* 与 @scope-*/*`}],options:[{flags:`--write`,description:`将更新写入 package.json`},{flags:`--dry-run`,description:`仅预览`},{flags:`--locked`,description:`包含精确锁定版本的依赖(默认跳过以数字开头的精确 pin)`}],schema:Dc({write:_c().optional(),dryRun:_c().optional(),locked:_c().optional()}),action:async(e,t)=>{let n=t[0],r=t[1];await sT({mode:n,write:e.write===!0,dryRun:e.dryRun===!0,locked:e.locked,scope:r})}}),Qd(e,{name:`upgrade-across`,description:`跨产品群批量升级依赖(项目清单经 project-registry 声明域获取)`,options:[{flags:`--scope <scope>`,description:`依赖 scope(与 --package 二选一,如 @longzai-intelligence-builder),升级该 scope 下所有包`},{flags:`--package <name>`,description:`完整包名(与 --scope 二选一,如 @longzai-intelligence-markdown/data-engine),仅升级该包`},{flags:`--target <version>`,description:`目标版本号(可选,如 ^0.0.8。省略时自动取每个匹配包的 npm latest)`},{flags:`-m, --message <message>`,description:`自定义提交信息`},{flags:`--project-scope <id>`,description:`显式圈定项目范围(缺省自动取当前 edition 范围)`},{flags:`--concurrency <n>`,description:`并发数(默认 10)`},{flags:`--dry-run`,description:`仅预览(不写文件、不提交)`}],schema:Dc({scope:U().optional(),target:U().optional(),message:U().optional(),config:U().optional(),package:U().optional(),concurrency:pl().int().positive().optional(),projectScope:U().optional(),dryRun:_c().optional()}),action:async e=>{e.scope===void 0==(e.package===void 0)&&(process.stderr.write(`错误: upgrade-across 需要在 --scope <@scope> 与 --package <包名> 之间恰选其一
334
+ `),process.stderr.write(`示例: --scope @longzai-intelligence-builder 或 --package @longzai-intelligence-markdown/data-engine
335
+ `),process.exit(1)),await rT({scope:e.scope,package:e.package,version:e.target,message:e.message,projectScope:e.projectScope,concurrency:e.concurrency,dryRun:e.dryRun===!0})}}),Qd(e,{name:`check`,description:`依赖声明聚合检查,覆盖根清单准入、自仓引用协议、应用包出口形态、同 scope 版本锁步与依赖新鲜度`,schema:Dc({}),action:async()=>{await Aw()}})}function lT(e){Qd(e,{name:`hoisting check`,description:`归位三段检查:子包重复声明根依赖、根声明技术栈专属依赖与构建面痕迹引擎声明完备`,schema:Dc({}),action:async()=>{await iw()}})}function uT(e){Qd(e,{name:`overrides check`,description:`检查 package.json 是否声明未豁免的强制版本字段`,schema:Dc({}),action:async()=>{await sw()}})}function dT(e){Qd(e,{name:`boundary check`,description:`检查 packages 层包是否依赖 domains 层领域契约包并校验领域目录层名合规`,schema:Dc({}),action:async()=>{await GC()}})}function fT(){let e=Kd({name:`lzi-dependencies`,description:`Longzai Intelligence 依赖版本管理工具`,version:`0.0.21`});return cT(e),lT(e),uT(e),dT(e),e}async function pT(){await fT().parseAsync(process.argv)}import.meta.main===!0&&await pT();export{fT as buildProgram};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-dependencies/cli",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Longzai Intelligence 依赖版本管理 CLI(bin lzi-dependencies)",
5
5
  "keywords": [
6
6
  "cli",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@longzai-intelligence-cli/core": "^0.0.18",
41
- "@longzai-intelligence-dependencies/core": "0.0.20",
41
+ "@longzai-intelligence-dependencies/core": "0.0.21",
42
42
  "@longzai-intelligence-logger/node": "^0.1.11"
43
43
  }
44
44
  }