@longzai-intelligence-agent-tools/cli 0.0.4 → 0.0.5
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/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import"./rolldown-runtime-BqT_7tdF.js";import{BUILTIN_PLACEHOLDERS as e,CATEGORY_RULES as t,COMMON_SOURCE as n,DEFAULT_SOURCES as r,ENV_KEYS as i,
|
|
2
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{BUILTIN_PLACEHOLDERS as e,CATEGORY_RULES as t,COMMON_SOURCE as n,DEFAULT_SOURCES as r,ENV_KEYS as i,GENERATED_FILE_SUFFIX as a,LZI_DIR as o,ROOT_ENTRY_TEMPLATE as s,SYNTHESIS_RULES as c,VALID_AGENTS as l}from"@longzai-intelligence-agent-tools/core";import{join as u}from"node:path";import{stat as d}from"node:fs/promises";import{loadUnifiedConfig as f}from"@longzai-intelligence-shared-config/core";const p={RED:`\x1B[0;31m`,GREEN:`\x1B[0;32m`,YELLOW:`\x1B[1;33m`,BLUE:`\x1B[0;34m`,RESET:`\x1B[0m`};function m(e){return e.map(e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `)}function h(...e){process.stdout.write(`${m(e)}\n`)}function g(...e){process.stderr.write(`${m(e)}\n`)}async function _(e){return process.stdout.write(e),new Promise(e=>{let t=process.stdin;t.setEncoding(`utf8`),t.resume();let n=r=>{t.removeListener(`data`,n),t.pause(),e(r.toString().trim())};t.once(`data`,n)})}const v=async e=>{let t=u(process.cwd(),o);h(`${p.BLUE}初始化 Agent Tools 源文件结构...${p.RESET}\n`),e.dryRun&&h(`${p.YELLOW}[预览模式] 将创建以下文件:${p.RESET}`);let n=[],a=[];for(let[i,s]of Object.entries(r)){let r=u(t,i);if(await Bun.file(r).exists()){n.push(i),e.dryRun||h(` ${p.YELLOW}跳过${p.RESET} ${i}(已存在)`);continue}if(a.push(i),e.dryRun){h(` ${p.GREEN}将创建${p.RESET} ${o}/${i}`);continue}await Bun.write(r,s,{createPath:!0}),h(` ${p.GREEN}已创建${p.RESET} ${o}/${i}`)}h(``),h(`${p.BLUE}后续步骤:${p.RESET}`),h(` 1. 编辑 ${o}/agents/agent.md,填写共同指令与 {{KEY}} 占位符`),h(` 2. 按需编辑 ${o}/agents/agent.<type>.md,填写各 Agent 专属指令`),h(` 3. 在 ${o}/commands/ rules/ skills/ 下按命名约定添加类别配置`),h(` 4. 创建 .env 文件,配置当前 Agent 类型:`),h(` ${i.AGENT_TYPE}=<${l.join(`|`)}>`),h(` ${i.PLACEHOLDER_PREFIX}<KEY>=<value> (如 LZI_PLACEHOLDER_LZI_ROOT=/path/to/project)`),h(` 5. 运行 lzi-agent-cli sync 同步生成 CLAUDE.md / AGENTS.md 并分发类别配置`),n.length>0&&(h(``),h(`${p.YELLOW}提示: ${n.length} 个文件已存在被跳过${p.RESET}`))},y=`${p.GREEN}存在${p.RESET}`,b=`${p.RED}缺失${p.RESET}`,x=e=>l.some(t=>t===e),S=async e=>Bun.file(e).exists(),ee=async()=>{let e=process.cwd(),r=u(e,o),a=process.env[i.AGENT_TYPE],s=a&&x(a)?a:null;h(`${p.BLUE}=== Agent Tools 状态 ===${p.RESET}\n`),h(s?`当前 Agent: ${p.GREEN}${s}${p.RESET}`:a?`当前 Agent: ${p.RED}${a}(无效,合法值: ${l.join(`, `)})${p.RESET}`:`当前 Agent: ${p.YELLOW}未设置(请在 .env 配置 ${i.AGENT_TYPE})${p.RESET}`),h(``),h(`${p.BLUE}源文件(${r}):${p.RESET}`);let d=new Set;if(d.add(n),s)for(let e of c[s])d.add(e.agentSource);for(let e of d){let t=u(r,e);h(` ${e}: ${await S(t)?y:b}`)}if(h(``),s){h(`${p.BLUE}输出目标(将覆盖):${p.RESET}`);for(let t of c[s]){let n=u(e,t.output),r=await S(n);h(` ${t.output}: ${r?y:b}`)}}else h(`${p.YELLOW}Agent 类型未配置,无法显示输出目标${p.RESET}`);h(``),h(`${p.BLUE}类别配置目录(${r} 下):${p.RESET}`);for(let e of Object.keys(t)){let t=u(r,e);h(` ${e}/: ${await S(t)?y:b}`)}},C=/\{\{([A-Z][A-Z0-9_]*)\}\}/g,w=()=>{let e={};for(let[t,n]of Object.entries(process.env))if(t.startsWith(i.PLACEHOLDER_PREFIX)&&n!==void 0){let r=t.slice(i.PLACEHOLDER_PREFIX.length);e[r]=n}return e},T=()=>{let t={};for(let[n,r]of Object.entries(e))t[n]=r();return t},E=e=>{let t=T(),n=w();return{...t,...n,...e}},D=(e,t)=>e.replace(C,(e,n)=>t[n]??e),O=async e=>{let t=Bun.file(e);return await t.exists()?t.text():null},k=async e=>{try{return await d(e),!0}catch{return!1}},A=async(e,t,n)=>{let r=new Bun.Glob(t),i=[];for await(let t of r.scan({cwd:e,onlyFiles:n}))i.push(t);return i.sort()},j=e=>{let t=e.replace(/\.md$/,``);for(let e of l){let n=`.${e}`;if(t.endsWith(n))return{baseRelPath:`${t.slice(0,-n.length)}.md`,isSpecific:!0,specificType:e}}return{baseRelPath:e,isSpecific:!1,specificType:null}},M=(e,t,n)=>e===``&&t===``?``:t===``?`${e.trimEnd()}\n`:e===``?`${t.trimEnd()}\n`:n===`prepend`?`${t.trimEnd()}\n\n${e.trimEnd()}\n`:`${e.trimEnd()}\n\n${t.trimEnd()}\n`,N=async(e,n,r,i)=>{let s=t[e];if(!s)return[];let c=s[n];if(!c)return[];let l=u(r,o,e);if(!await k(l))return[];let d=await A(l,`**/*.md`,!0),f=new Map;for(let e of d){let{baseRelPath:t,isSpecific:n,specificType:r}=j(e);f.has(t)||f.set(t,{common:null,specifics:new Map});let i=f.get(t);i!==void 0&&(n&&r?i.specifics.set(r,e):i.common=e)}let p=[];for(let[t,{common:r,specifics:o}]of f){let s=o.get(n)??null,d=r===null?null:u(l,r),f=s===null?null:u(l,s);if(d===null&&f===null)continue;let m=d===null?``:await O(d)??``,h=f===null?``:await O(f)??``,g=D(M(m,h,c.mode),i),_=t.replace(/\.md$/,`${a}.md`),v=u(c.ideRoot,e,_);p.push({category:e,agentType:n,output:v,content:g,commonSourcePath:d,agentSourcePath:f})}return p},P=async(e,n,r)=>{let i=u(n,o);if(!await k(i))return[];let a=(await A(i,`*/`,!1)).map(e=>e.replace(/\/$/,``)),s=[];for(let i of a){if(!t[i])continue;let a=await N(i,e,n,r);s.push(...a)}return s},F=async e=>{let t=Bun.file(e);return await t.exists()?t.text():null},I=async(e,t,n)=>{let r=u(t,o,e.commonSource),i=u(t,o,e.agentSource),a=await F(r);if(a===null)throw Error(`共同部分源文件不存在: ${r}`);let s=await F(i);if(s===null)throw Error(`独有部分源文件不存在: ${i}`);let c=D(`${a.trimEnd()}\n\n${s.trimEnd()}\n`,n);return{output:e.output,content:c,commonSourcePath:r,agentSourcePath:i}},L=async(e,t,n)=>{let r=c[e],i=[];for(let e of r){let r=await I(e,t,n);i.push(r)}return i},R=e=>l.some(t=>t===e),z=()=>{let e=process.env[i.AGENT_TYPE];return e?R(e)?e:(g(`错误: ${i.AGENT_TYPE} 值 '${e}' 无效,合法值为: ${l.join(`, `)}`),null):null},B=async()=>{let e=await f({unifiedField:`agentTools`});return e.success?e.config:void 0},V=async()=>{let e=z();return e||(g(`错误: 环境变量 ${i.AGENT_TYPE} 未设置`),g(`请在 .env 中配置,合法值为: ${l.join(`, `)}`),process.exit(1)),{agentType:e,placeholders:(await B())?.placeholders}},H=async(e,t)=>{let n=u(e,t);return Bun.file(n).exists()},U=async(e,t)=>{let n=u(e,t),r=Bun.file(n);return await r.exists()?r.text():null},W=(e,t)=>{let n=[];for(let t of e){let e=t.output.replace(/\.md$/,`${a}.md`),r=`${s.replace(`{{generatedFile}}`,e)}\n`;n.push({output:e,content:t.content,sourceLabel:`${t.commonSourcePath} + ${t.agentSourcePath}`}),n.push({output:t.output,content:r,sourceLabel:`入口占位 → ${e}`})}let r=t.map(e=>{let t=[];return e.commonSourcePath&&t.push(e.commonSourcePath),e.agentSourcePath&&t.push(e.agentSourcePath),{output:e.output,content:e.content,sourceLabel:t.join(` + `)}});return[...n,...r]},G=e=>{h(`${p.BLUE}=== 预览模式(不写入文件) ===${p.RESET}\n`);for(let t of e)h(`${p.GREEN}--- ${t.output} ---${p.RESET}`),h(`${p.YELLOW}源: ${t.sourceLabel}${p.RESET}`),h(``),h(t.content),h(``)},K=async(e,t)=>{h(`${p.BLUE}=== 校验模式(比对产物与真源) ===${p.RESET}\n`);let n=[],r=0;for(let i of t){let t=await U(e,i.output);t===null?n.push(`${i.output} (产物缺失)`):t===i.content?r+=1:n.push(`${i.output} (内容不一致)`)}if(n.length===0){h(`${p.GREEN}✓ 所有产物与真源一致${p.RESET}(${r} 个文件)`);return}h(`${p.RED}✗ 检测到 ${n.length} 处漂移:${p.RESET}`);for(let e of n)h(` ${p.RED}${e}${p.RESET}`);h(``),h(`${p.YELLOW}请运行 lzi-agent-cli sync 重新生成产物${p.RESET}`),process.exit(1)},q=async(e,t)=>{let n=u(e,t.output);await Bun.write(n,t.content),h(`${p.GREEN} ✓${p.RESET} ${t.output}`)},J=async e=>{let t=await V(),n=process.cwd(),r=E(t.placeholders),i=await L(t.agentType,n,r),a=await P(t.agentType,n,r),o=W(i,a);if(e.check){await K(n,o);return}if(e.dryRun){G(o);return}let s=[];for(let e of o)await H(n,e.output)&&s.push(e.output);if(s.length>0&&!e.force){h(`${p.YELLOW}将覆盖以下文件:${p.RESET}`);for(let e of s)h(` ${e}`);if((await _(`
|
|
3
3
|
确认覆盖?(y/N): `)).toLowerCase()!==`y`){h(`已取消`);return}}h(``),h(`${p.BLUE}正在写入...${p.RESET}`);for(let e of o)await q(n,e);h(`\n${p.GREEN}同步完成${p.RESET} (Agent: ${t.agentType},共 ${o.length} 个文件)`)},Y=`lzi-agent-cli`,X=`
|
|
4
4
|
${Y} - Longzai Intelligence Agent Tools
|
|
5
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-agent-tools/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Longzai Intelligence Agent Tools CLI",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"clean": "lzi-dev-cli clean"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@longzai-intelligence-agent-tools/core": "0.0.
|
|
37
|
+
"@longzai-intelligence-agent-tools/core": "0.0.5",
|
|
38
38
|
"@longzai-intelligence-shared-config/core": "^0.0.5"
|
|
39
39
|
}
|
|
40
40
|
}
|