@longzai-intelligence-agent-tools/core 0.0.8 → 0.0.10
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.d.ts +180 -9
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -66,11 +66,95 @@ type VendorRule = {
|
|
|
66
66
|
readonly mode: SynthesisMode;
|
|
67
67
|
};
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* 配置类别同步规则
|
|
70
70
|
*
|
|
71
71
|
* 描述某类别在各 IDE 下的厂商规则。
|
|
72
72
|
*/
|
|
73
73
|
type CategoryRule = Readonly<Record<AgentType, VendorRule>>;
|
|
74
|
+
/**
|
|
75
|
+
* 条目(.lzi/agents/items/ 下的可组合指令片段)
|
|
76
|
+
*
|
|
77
|
+
* 根指令共同部分的条目化拆分单元:agent.md 保持纯 markdown,
|
|
78
|
+
* 条目在 items/ 下独立文件维护,由 sync 自动发现、定序、按内容
|
|
79
|
+
* flavor 解析后并入根指令合成产物。
|
|
80
|
+
*/
|
|
81
|
+
type AgentItem = {
|
|
82
|
+
/**
|
|
83
|
+
* 条目 base 相对路径(相对 items/ 目录,如 lang/typescript.md)
|
|
84
|
+
*/
|
|
85
|
+
readonly baseRelPath: string;
|
|
86
|
+
/**
|
|
87
|
+
* 显式定序值(frontmatter order 元信息),未声明为 null
|
|
88
|
+
*
|
|
89
|
+
* 排序规则:(order, baseRelPath) 升序;未声明(null)排在全部
|
|
90
|
+
* 已声明条目之后,彼此按 baseRelPath 字典序。
|
|
91
|
+
*/
|
|
92
|
+
readonly order: number | null;
|
|
93
|
+
/**
|
|
94
|
+
* 解析后的条目正文(frontmatter 已剥离,trimEnd 后)
|
|
95
|
+
*/
|
|
96
|
+
readonly content: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* 优化建议严重级别
|
|
100
|
+
*
|
|
101
|
+
* high:对费用影响最大的稳定前缀类问题;medium:确定的浪费;low:启发式或收益较小的建议。
|
|
102
|
+
*/
|
|
103
|
+
type OptimizeSeverity = 'high' | 'medium' | 'low';
|
|
104
|
+
/**
|
|
105
|
+
* 优化规则标识
|
|
106
|
+
*
|
|
107
|
+
* 与 OPTIMIZE_RULES 规则表一一对应,依据
|
|
108
|
+
* docs/vendors/tencent-multi-agent-cost-optimization.md 的原文优化点。
|
|
109
|
+
*/
|
|
110
|
+
type OptimizeRuleId = 'volatile-prefix' | 'oversized-common' | 'low-freq-section' | 'type-content-in-common' | 'cross-type-duplicate' | 'inline-code-block' | 'missing-tools-whitelist' | 'missing-index' | 'sequential-instruction' | 'multi-step-git-ops' | 'mcp-over-cli' | 'mcp-data-subagent' | 'agent-split' | 'blind-search' | 'verbose-cli-output';
|
|
111
|
+
/**
|
|
112
|
+
* 优化规则定义
|
|
113
|
+
*
|
|
114
|
+
* 记录严重级别、标题与原文依据(支持文档中的优化点及实测收益)。
|
|
115
|
+
*/
|
|
116
|
+
type OptimizeRule = {
|
|
117
|
+
/**
|
|
118
|
+
* 规则标识
|
|
119
|
+
*/
|
|
120
|
+
readonly id: OptimizeRuleId;
|
|
121
|
+
/**
|
|
122
|
+
* 严重级别
|
|
123
|
+
*/
|
|
124
|
+
readonly severity: OptimizeSeverity;
|
|
125
|
+
/**
|
|
126
|
+
* 建议标题(一行,面向用户)
|
|
127
|
+
*/
|
|
128
|
+
readonly title: string;
|
|
129
|
+
/**
|
|
130
|
+
* 原文依据(docs/vendors 支持文档中的优化点与收益)
|
|
131
|
+
*/
|
|
132
|
+
readonly reference: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* 单条优化建议
|
|
136
|
+
*
|
|
137
|
+
* 只读分析的输出单元:定位到源文件与行号,附具体建议与规则依据。
|
|
138
|
+
* 不携带任何自动修复动作。
|
|
139
|
+
*/
|
|
140
|
+
type OptimizeSuggestion = {
|
|
141
|
+
/**
|
|
142
|
+
* 命中的规则元数据
|
|
143
|
+
*/
|
|
144
|
+
readonly rule: OptimizeRule;
|
|
145
|
+
/**
|
|
146
|
+
* 源文件相对路径(相对 .lzi/)
|
|
147
|
+
*/
|
|
148
|
+
readonly file: string;
|
|
149
|
+
/**
|
|
150
|
+
* 建议锚定行号(1 起)
|
|
151
|
+
*/
|
|
152
|
+
readonly line: number;
|
|
153
|
+
/**
|
|
154
|
+
* 具体建议内容
|
|
155
|
+
*/
|
|
156
|
+
readonly detail: string;
|
|
157
|
+
};
|
|
74
158
|
/**
|
|
75
159
|
* Agent Tools 配置
|
|
76
160
|
*
|
|
@@ -100,6 +184,88 @@ type AgentToolsConfig = {
|
|
|
100
184
|
*/
|
|
101
185
|
declare const DEFAULT_SOURCES: Readonly<Record<string, string>>;
|
|
102
186
|
//#endregion
|
|
187
|
+
//#region src/optimizer.rules.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* 优化阈值常量表
|
|
190
|
+
*
|
|
191
|
+
* 全部规则的量化阈值集中于此,与合成规则表同级,固定不可配,
|
|
192
|
+
* 确保所有项目的优化判定标准一致。阈值依据
|
|
193
|
+
* docs/vendors/tencent-multi-agent-cost-optimization.md 记录的原文实践校准。
|
|
194
|
+
*/
|
|
195
|
+
declare const OPTIMIZE_THRESHOLDS: {
|
|
196
|
+
/**
|
|
197
|
+
* 易变占位符检测的文件头部行数
|
|
198
|
+
*
|
|
199
|
+
* 头部 N 行内出现易变占位符(如 {{DATE}})视为破坏稳定前缀。
|
|
200
|
+
*/
|
|
201
|
+
readonly HEAD_LINES: 30;
|
|
202
|
+
/**
|
|
203
|
+
* 公共源文件(agents/agent.md)行数告警阈值
|
|
204
|
+
*
|
|
205
|
+
* 原文记录 CLAUDE.md 常膨胀到 1000 行以上,400 行为提前告警线。
|
|
206
|
+
*/
|
|
207
|
+
readonly COMMON_MAX_LINES: 400;
|
|
208
|
+
/**
|
|
209
|
+
* 公共源文件估算 token 告警阈值
|
|
210
|
+
*/
|
|
211
|
+
readonly COMMON_MAX_TOKENS: 5000;
|
|
212
|
+
/**
|
|
213
|
+
* 内联代码块行数告警阈值
|
|
214
|
+
*
|
|
215
|
+
* 超过此行数的代码块建议改为文件引用(原文优化一:扁平链接)。
|
|
216
|
+
*/
|
|
217
|
+
readonly CODE_BLOCK_MAX_LINES: 40;
|
|
218
|
+
/**
|
|
219
|
+
* 跨类型重复段落的最小字符数
|
|
220
|
+
*
|
|
221
|
+
* 归一化后长度低于此值的段落不参与重复检测,避免误报短句。
|
|
222
|
+
*/
|
|
223
|
+
readonly DUPLICATE_MIN_CHARS: 60;
|
|
224
|
+
/**
|
|
225
|
+
* 段落相似度阈值(字符二元组 Jaccard 系数)
|
|
226
|
+
*
|
|
227
|
+
* 两段落相似度达到此值视为重复,建议上移公共文件。
|
|
228
|
+
*/
|
|
229
|
+
readonly SIMILARITY_THRESHOLD: 0.85;
|
|
230
|
+
/**
|
|
231
|
+
* 类别目录文件数告警阈值
|
|
232
|
+
*
|
|
233
|
+
* 类别目录下 .md 文件数超过此值且无 INDEX.md 时建议建立索引。
|
|
234
|
+
*/
|
|
235
|
+
readonly CATEGORY_INDEX_MIN_FILES: 5;
|
|
236
|
+
/**
|
|
237
|
+
* 多职责判定所需的最少职能关键词数
|
|
238
|
+
*
|
|
239
|
+
* 公共文件超大且标题命中至少 N 个不同职能词时,建议按职能拆分多 Agent。
|
|
240
|
+
*/
|
|
241
|
+
readonly AGENT_SPLIT_MIN_ROLES: 3;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* 优化规则表
|
|
245
|
+
*
|
|
246
|
+
* 每条规则记录:严重级别、标题、原文依据(docs/vendors 支持文档的优化点与实测收益)。
|
|
247
|
+
* 只读静态分析,仅输出建议;不分析对话数据,不提供自动修复。
|
|
248
|
+
*/
|
|
249
|
+
declare const OPTIMIZE_RULES: Readonly<Record<OptimizeRuleId, OptimizeRule>>;
|
|
250
|
+
/**
|
|
251
|
+
* 严重级别展示顺序
|
|
252
|
+
*
|
|
253
|
+
* 建议输出按 high → medium → low 排列。
|
|
254
|
+
*/
|
|
255
|
+
declare const OPTIMIZE_SEVERITY_ORDER: readonly OptimizeSeverity[];
|
|
256
|
+
/**
|
|
257
|
+
* 构造单条优化建议
|
|
258
|
+
*
|
|
259
|
+
* 供分析服务使用,从 OPTIMIZE_RULES 取规则元数据拼装。
|
|
260
|
+
*
|
|
261
|
+
* @param ruleId - 规则标识
|
|
262
|
+
* @param file - 源文件相对路径(相对 .lzi/)
|
|
263
|
+
* @param line - 建议锚定的行号(1 起)
|
|
264
|
+
* @param detail - 具体建议内容
|
|
265
|
+
* @returns 优化建议对象
|
|
266
|
+
*/
|
|
267
|
+
declare const buildSuggestion: (ruleId: OptimizeRuleId, file: string, line: number, detail: string) => OptimizeSuggestion;
|
|
268
|
+
//#endregion
|
|
103
269
|
//#region src/rules.d.ts
|
|
104
270
|
/**
|
|
105
271
|
* 工作区源文件目录
|
|
@@ -114,18 +280,23 @@ declare const LZI_DIR: '.lzi';
|
|
|
114
280
|
*/
|
|
115
281
|
declare const COMMON_SOURCE: 'agents/agent.md';
|
|
116
282
|
/**
|
|
117
|
-
*
|
|
283
|
+
* 条目目录源路径(相对 .lzi/)
|
|
118
284
|
*
|
|
119
|
-
*
|
|
285
|
+
* agent.md 共同部分的条目化拆分真源:items/ 下每个 .md 文件是一个条目,
|
|
286
|
+
* 支持任意层级子文件夹组织,命名沿用 <path>.md(全类型)+
|
|
287
|
+
* <path>.<type>.md(变体或类型独有)约定。
|
|
288
|
+
*
|
|
289
|
+
* sync 自动发现、按 frontmatter order 元信息定序、按内容 flavor 解析后
|
|
290
|
+
* 并入根指令合成产物(agent.md → items → agent.<type>.md)。
|
|
291
|
+
* items/ 缺失或无产出时,根指令合成行为与无条目机制时完全一致。
|
|
120
292
|
*/
|
|
121
|
-
declare const
|
|
293
|
+
declare const AGENTS_ITEMS_SOURCE_DIR: 'agents/items';
|
|
122
294
|
/**
|
|
123
|
-
*
|
|
295
|
+
* 各 IDE 的配置根目录名
|
|
124
296
|
*
|
|
125
|
-
*
|
|
126
|
-
* 如 monorepo-quality-check.md → monorepo-quality-check.generated.md。
|
|
297
|
+
* IDE 读取指令文件的根目录,源自 docs/vendors/<ide>.md。
|
|
127
298
|
*/
|
|
128
|
-
declare const
|
|
299
|
+
declare const IDE_OUTPUT_DIRS: Readonly<Record<AgentType, string>>;
|
|
129
300
|
/**
|
|
130
301
|
* 根指令文件生成区起始标记
|
|
131
302
|
*
|
|
@@ -207,4 +378,4 @@ declare const AUTO_AGENT_KEYWORD: 'auto';
|
|
|
207
378
|
*/
|
|
208
379
|
declare const detectAgentTypes: (projectRoot: string) => Promise<readonly AgentType[]>;
|
|
209
380
|
//#endregion
|
|
210
|
-
export { AUTO_AGENT_KEYWORD, type AgentToolsConfig, type AgentType, BUILTIN_PLACEHOLDERS, CATEGORY_RULES, COMMON_SOURCE, type Category, type CategoryRule, DEFAULT_SOURCES, ENV_KEYS, GENERATED_BLOCK_BEGIN, GENERATED_BLOCK_END,
|
|
381
|
+
export { AGENTS_ITEMS_SOURCE_DIR, AUTO_AGENT_KEYWORD, type AgentItem, type AgentToolsConfig, type AgentType, BUILTIN_PLACEHOLDERS, CATEGORY_RULES, COMMON_SOURCE, type Category, type CategoryRule, DEFAULT_SOURCES, ENV_KEYS, GENERATED_BLOCK_BEGIN, GENERATED_BLOCK_END, IDE_OUTPUT_DIRS, LZI_DIR, OPTIMIZE_RULES, OPTIMIZE_SEVERITY_ORDER, OPTIMIZE_THRESHOLDS, type OptimizeRule, type OptimizeRuleId, type OptimizeSeverity, type OptimizeSuggestion, SYNTHESIS_RULES, type SynthesisMode, type SynthesisRule, VALID_AGENTS, type VendorRule, buildSuggestion, detectAgentTypes };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,10 @@ import"./rolldown-runtime-BqT_7tdF.js";import{stat as e}from"node:fs/promises";i
|
|
|
31
31
|
此文件的内容仅出现在 zcode 场景的 AGENTS.md 中。
|
|
32
32
|
|
|
33
33
|
<!-- 在此添加 ZCode 专属的指令 -->
|
|
34
|
+
`,"agents/items/.gitkeep":`# 此目录存放条目真源(agent.md 共同部分的条目化拆分)
|
|
35
|
+
# 命名约定:<path>.md(全类型条目)+ <path>.<type>.md(某 IDE 变体或独有条目)
|
|
36
|
+
# 子文件夹任意层级组织;解析后正文为空 = 该条目对该类型暂不产出
|
|
37
|
+
# 定序:条目 frontmatter 元信息 order: <数值>,按 (order, 路径) 升序,未声明者排最后
|
|
34
38
|
`,"commands/.gitkeep":`# 此目录存放自定义命令真源
|
|
35
39
|
# 命名约定:<base>.md(共同)+ <base>.<type>.md(某 IDE 独有)
|
|
36
40
|
# 子目录原样分发到各 IDE 的 commands/ 目录
|
|
@@ -39,4 +43,4 @@ import"./rolldown-runtime-BqT_7tdF.js";import{stat as e}from"node:fs/promises";i
|
|
|
39
43
|
# frontmatter 各 IDE 不同(claude paths / trae alwaysApply+globs),见 docs/vendors/
|
|
40
44
|
`,"skills/.gitkeep":`# 此目录存放技能真源
|
|
41
45
|
# 命名约定:<base>.md(共同)+ <base>.<type>.md(某 IDE 独有)
|
|
42
|
-
`},r=`.lzi`,
|
|
46
|
+
`},r={HEAD_LINES:30,COMMON_MAX_LINES:400,COMMON_MAX_TOKENS:5e3,CODE_BLOCK_MAX_LINES:40,DUPLICATE_MIN_CHARS:60,SIMILARITY_THRESHOLD:.85,CATEGORY_INDEX_MIN_FILES:5,AGENT_SPLIT_MIN_ROLES:3},i={"volatile-prefix":{id:`volatile-prefix`,severity:`high`,title:`易变占位符位于文件头部,破坏稳定前缀`,reference:`原文优化八:稳定前缀设计(实测收益 >85%,对费用影响最大)`},"oversized-common":{id:`oversized-common`,severity:`medium`,title:`公共源文件过大,应渐进式披露拆分`,reference:`原文优化一:渐进式披露(实测收益 >10%)`},"low-freq-section":{id:`low-freq-section`,severity:`low`,title:`低频段落常驻公共文件,建议下沉为按需加载的独立文件`,reference:`原文优化一:渐进式披露,L2 按需层(实测收益 >10%)`},"type-content-in-common":{id:`type-content-in-common`,severity:`medium`,title:`公共文件包含类型专属内容,应移入 agent.<type>.md`,reference:`原文优化六:Agent 专属配置;原则二:减少不相关的`},"cross-type-duplicate":{id:`cross-type-duplicate`,severity:`medium`,title:`各类型独有文件间存在重复段落,建议上移公共文件`,reference:`原文优化九:避免重复加载 Skill(消除隐性重复膨胀);原则三:减少重复的`},"inline-code-block":{id:`inline-code-block`,severity:`low`,title:`大段内联代码块,建议改为文件引用`,reference:`原文优化一:渐进式披露,工具列表用扁平链接替代说明文档搬运`},"missing-tools-whitelist":{id:`missing-tools-whitelist`,severity:`low`,title:`command 源文件未声明 allowed-tools 白名单`,reference:`原文优化六:Agent 专属配置,tools 白名单`},"missing-index":{id:`missing-index`,severity:`low`,title:`类别目录文件较多且无 INDEX.md 索引`,reference:`原文优化四:长期记忆按需索引加载(实测收益 >10%)`},"sequential-instruction":{id:`sequential-instruction`,severity:`low`,title:`指令要求逐个/串行执行,建议固化为脚本或改为并行`,reference:`原文优化二:确定性操作由脚本执行;原文优化十一:工具调用并行化`},"multi-step-git-ops":{id:`multi-step-git-ops`,severity:`medium`,title:`指令要求 Agent 逐步执行 git 流程,建议改用专用工具一次调用`,reference:`原文优化二:确定性操作由脚本执行,一次脚本调用替代多轮模型交互(实测收益 >10%);原文优化十一:串行工具调用每次携带完整上下文`},"mcp-over-cli":{id:`mcp-over-cli`,severity:`medium`,title:`指令指示通过 MCP 工具执行操作,CLI 优先更省 token`,reference:`原文优化二:CLI 优先于 MCP——MCP 的 JSON 结构化返回往往比纯文本 CLI 输出消耗更多 token(实测收益 >10%)`},"mcp-data-subagent":{id:`mcp-data-subagent`,severity:`medium`,title:`指令让主 Agent 直接经 MCP 获取大数据,应数据获取子 Agent 化`,reference:`原文优化三:MCP 数据获取子 Agent 化——数据获取子 Agent 压缩归纳后只把结论返回主 Agent(实测单次交互 message tokens 从 800KB 降到 5K,降幅 90%+)`},"agent-split":{id:`agent-split`,severity:`medium`,title:`公共指令承载多个职能且体量过大,建议按职能拆分为多 Agent`,reference:`原文优化五:单 Agent 拆分为多 Agent——每个 Agent 的 system prompt 与工具集最小化,拆分后总账更优(降低单次交互成本)`},"blind-search":{id:`blind-search`,severity:`low`,title:`指令要求 Agent 盲搜定位代码,建议图谱查询或精确路径引用`,reference:`原文优化七:代码图谱替代盲搜——grep/glob 暴力遍历搜索范围大、读取文件多(实测任务平均耗时降低 30%+,graphify 已在 10+ 项目落地)`},"verbose-cli-output":{id:`verbose-cli-output`,severity:`low`,title:`指令包含高输出 CLI 命令,建议接入 rtk 输出压缩代理`,reference:`原文优化十:rtk 压缩 CLI 输出——构建日志、测试报告、文件列表经 rtk 压缩后再进入模型上下文(实测压缩率 85% 左右)`}},a=[`high`,`medium`,`low`],o=(e,t,n,r)=>({rule:i[e],file:t,line:n,detail:r}),s=`.lzi`,c=`agents/agent.md`,l=`agents/items`,u={claude:`.claude`,trae:`.trae`,zcode:`.zcode`},d=`<!-- BEGIN Lzi Generated(工具维护,请勿手改;修改请编辑 .lzi/ 真源后运行 sync) -->`,f=`<!-- END Lzi Generated -->`,p={claude:[{output:`CLAUDE.md`,commonSource:c,agentSource:`agents/agent.claude.md`}],trae:[{output:`CLAUDE.md`,commonSource:c,agentSource:`agents/agent.claude.md`},{output:`AGENTS.md`,commonSource:c,agentSource:`agents/agent.trae.md`}],zcode:[{output:`AGENTS.md`,commonSource:c,agentSource:`agents/agent.zcode.md`}]},m={commands:{claude:{ideRoot:u.claude,mode:`append`},trae:{ideRoot:u.trae,mode:`append`},zcode:{ideRoot:u.zcode,mode:`append`}},rules:{claude:{ideRoot:u.claude,mode:`prepend`},trae:{ideRoot:u.trae,mode:`prepend`},zcode:{ideRoot:u.zcode,mode:`prepend`}},skills:{claude:{ideRoot:u.claude,mode:`append`},trae:{ideRoot:u.trae,mode:`append`},zcode:{ideRoot:u.zcode,mode:`append`}}},h=[`claude`,`trae`,`zcode`],g={AGENT_TYPE:`LZI_AGENT_TYPE`,PLACEHOLDER_PREFIX:`LZI_PLACEHOLDER_`},_={DATE:()=>new Date().toISOString().slice(0,10),PROJECT_NAME:()=>process.cwd().split(`/`).pop()??``},v=`auto`,y=async t=>{try{return await e(t),!0}catch{return!1}},b=async e=>{let n=t(e,s);if(!await y(n))return[];let r=[];for(let e of h){let i=p[e];(await Promise.all(i.map(async e=>y(t(n,e.agentSource))))).some(e=>e)&&r.push(e)}return r};export{l as AGENTS_ITEMS_SOURCE_DIR,v as AUTO_AGENT_KEYWORD,_ as BUILTIN_PLACEHOLDERS,m as CATEGORY_RULES,c as COMMON_SOURCE,n as DEFAULT_SOURCES,g as ENV_KEYS,d as GENERATED_BLOCK_BEGIN,f as GENERATED_BLOCK_END,u as IDE_OUTPUT_DIRS,s as LZI_DIR,i as OPTIMIZE_RULES,a as OPTIMIZE_SEVERITY_ORDER,r as OPTIMIZE_THRESHOLDS,p as SYNTHESIS_RULES,h as VALID_AGENTS,o as buildSuggestion,b as detectAgentTypes};
|