@longzai-intelligence-debts/cli 0.0.0-stage → 0.0.2
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 +11 -0
- package/dist/index.js +2 -0
- package/dist/rolldown-runtime-DCIJsbUY.js +2 -0
- package/package.json +52 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import "./rolldown-runtime-DCIJsbUY.js";
|
|
3
|
+
/**
|
|
4
|
+
* debts 内置插件
|
|
5
|
+
*
|
|
6
|
+
* 契约适配层。引擎核不搬家,本文件仅将门禁与读取命令包装为 docs 平台插件
|
|
7
|
+
* 契约形态,供 lzi-docs 宿主经 plugins.debts 声明装载。CLI 侧直接消费引
|
|
8
|
+
* 擎核不变
|
|
9
|
+
*/
|
|
10
|
+
declare const debtsPlugin: import("@longzai-intelligence-docs/core").DocsPlugin;
|
|
11
|
+
export { debtsPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import"./rolldown-runtime-DCIJsbUY.js";import{createCli as e,defineCommand as t}from"@longzai-intelligence-cli/core";import{clackInteraction as n,picocolorsColor as r}from"@longzai-intelligence-cli/standard";import{ASCII_KEBAB_SLUG_PATTERN as i,CANONICAL_DEBT_TYPE_LABELS as a,DEBT_TYPE_KEYS as o,TEMPLATE_FIELDS as s,parseDebtDoc as c,renderDebtTemplate as l,renderDebtTemplateSkeleton as u,renderRegistryReadmeStub as d,runDebtsLint as f,runIndexCheck as p,scanDebtsDir as m,settleDebtDoc as h,waiveDebtDoc as g}from"@longzai-intelligence-debts/ledger";import{definePlugin as _,pluginCommand as v,titleToKebabSlug as y}from"@longzai-intelligence-docs/core";import{parseNumberingPluginConfig as b,runNumberingNext as x}from"@longzai-intelligence-docs/numbering-plugin";import{existsSync as S,mkdirSync as C,readFileSync as w,writeFileSync as T}from"node:fs";import{join as E,relative as D,resolve as O}from"node:path";import*as k from"zod";import{loadLziDebtsConfig as A,renderConfigScaffold as j}from"@longzai-intelligence-debts/config";function M(){return O(process.cwd())}async function N(e){let t=await A(e===void 0?{}:{configPath:e});return t.ok||(process.stderr.write(`错误: ${t.reason}\n`),process.exit(1)),{config:t.config,configFilePath:t.configFilePath}}function P(e){process.stdout.write(`[INFO] ${e}\n`)}function F(e){process.stdout.write(`[SUCCESS] ${e}\n`)}function I(e){process.stdout.write(`${e}\n`)}function L(e){process.stderr.write(`错误: ${e}\n`),process.exit(1)}function R(e,t){let n=null,r=-1;for(let i of e.scopes)for(let e of i.paths)(e===`.`||e===``||t===e||t.startsWith(`${e}/`))&&e.length>r&&(n=i.key,r=e.length);return n}function z(){return new Intl.DateTimeFormat(`en-CA`,{year:`numeric`,month:`2-digit`,day:`2-digit`}).format(/* @__PURE__ */ new Date)}function B(e){t(e,{name:`create`,description:`建档,取号经 numbering 插件,标准模板落盘`,options:[{flags:`--title <title>`,description:`一句话标题,必填`},{flags:`--type <type>`,description:`债务类型键,必填,词表见 template --format json`},{flags:`--slug <slug>`,description:`slug,缺省由标题派生`},{flags:`--source <source>`,description:`来源说明,必填,即头部元数据强制项`},{flags:`--ref <ref>`,description:`关联条目,可选,即头部元数据行`},{flags:`--scope <scope>`,description:`scope key,缺省按 cwd 解析`},{flags:`--dry-run`,description:`只呈现不落盘`},{flags:`--config <path>`,description:`显式配置路径`}],schema:k.looseObject({title:k.string(),type:k.string(),slug:k.string().optional(),source:k.string(),ref:k.string().optional(),scope:k.string().optional(),dryRun:k.boolean().optional(),config:k.string().optional()}),action:async e=>{let t=M(),{config:n}=await N(e.config),r=V(e.type),o=D(t,process.cwd()),s=e.scope??R(n,o)??L(`cwd「${o}」未命中任何 scope 覆盖面,候选:${n.scopes.map(e=>e.key).join(`、`)},或显式 --scope`),c=n.scopes.find(e=>e.key===s)??L(`scope「${s}」未登记`),u=b({scopes:n.scopes.map(e=>({key:e.key,title:e.title,paths:e.paths,registryDir:e.registryDir}))}),d=x({root:t,config:u,scopeKey:s});d.ok||L(d.error);let f=e.slug??y(e.title),p=i.test(f)?f:L(`slug 须为纯 ASCII kebab,中文标题请显式提供 --slug <slug>`),m=l({number:d.number,slug:p,title:e.title,type:r,date:z(),source:e.source,ref:e.ref}),h=E(t,c.registryDir,`${d.number}-${p}.md`);S(h)&&L(`目标已存在:${h},编号或 slug 撞车,重跑取号或换 slug`),e.dryRun?P(`[dry-run] 将落盘 ${h}:\n${m}`):(C(E(t,c.registryDir),{recursive:!0}),T(h,m),F(`已建档:${D(t,h)},scope:${s},编号:${d.number},类型:${a[r]}`),P(`索引行人工登记:lzi-debts index check 报差量并附期望行`))}}),t(e,{name:`settle`,description:`清偿翻态,先回填第四节清偿记录再收口`,options:[{flags:`--number <number>`,description:`债档编号,必填,如 0001`},{flags:`--record <record>`,description:`清偿记录条目,可选,指向操作细节正本`},{flags:`--date <date>`,description:`清偿日期,缺省今日`},{flags:`--config <path>`,description:`显式配置路径`}],schema:k.looseObject({number:k.string(),record:k.string().optional(),date:k.string().optional(),config:k.string().optional()}),action:async e=>{let{config:t}=await N(e.config),n=H(t,e.number),r=h({content:n.content,date:e.date??z(),settleRecord:e.record});r.ok||L(r.error),r.changed?(T(n.absPath,r.content),F(`已清偿翻态:${n.fileRel}`),P(`索引行状态列人工更新:lzi-debts index check 报差量并附期望行`)):P(`债档已为已清偿态,零变更:${n.fileRel}`)}}),t(e,{name:`waive`,description:`豁免翻态,理由须含用户裁定`,options:[{flags:`--number <number>`,description:`债档编号,必填,如 0001`},{flags:`--reason <reason>`,description:`豁免理由,必填,须含「用户裁定」`},{flags:`--date <date>`,description:`豁免日期,缺省今日`},{flags:`--config <path>`,description:`显式配置路径`}],schema:k.looseObject({number:k.string(),reason:k.string(),date:k.string().optional(),config:k.string().optional()}),action:async e=>{let{config:t}=await N(e.config),n=H(t,e.number),r=g({content:n.content,date:e.date??z(),reason:e.reason});r.ok||L(r.error),r.changed?(T(n.absPath,r.content),F(`已豁免翻态:${n.fileRel}`),P(`索引行状态列人工更新:lzi-debts index check 报差量并附期望行`)):P(`债档已为已豁免态,零变更:${n.fileRel}`)}}),t(e,{name:`list`,description:`按头部元数据过滤打印债档清单`,options:[{flags:`--scope <scope>`,description:`限定 scope key`},{flags:`--status <status>`,description:`限定状态中文名,即未清偿、已清偿、已豁免`},{flags:`--type <type>`,description:`限定债务类型键`},{flags:`--config <path>`,description:`显式配置路径`}],schema:k.looseObject({scope:k.string().optional(),status:k.string().optional(),type:k.string().optional(),config:k.string().optional()}),action:async e=>{let t=M(),{config:n}=await N(e.config),r=e.type===void 0?void 0:V(e.type),i=e.scope===void 0?n.scopes:n.scopes.filter(t=>t.key===e.scope);i.length===0&&L(`scope「${e.scope}」未登记`);let o=0;for(let n of i)for(let i of m(E(t,n.registryDir))){let t=c(w(i.absPath,`utf8`)).debt;t===null||e.status!==void 0&&t.statusLabel!==e.status||r!==void 0&&t.typeLabel!==a[r]||(o+=1,process.stdout.write(`${t.number} ${t.typeLabel??`未知类型`} ${t.statusLabel??`未知状态`} ${t.title}\n`))}P(`共 ${o} 项`)}})}function V(e){for(let t of o)if(t===e)return t;return L(`债务类型「${e}」不在词表内,合法值:${o.map(e=>`${e} 即 ${a[e]}`).join(`,`)}`)}function H(e,t){let n=M(),r=[];for(let i of e.scopes)for(let e of m(E(n,i.registryDir)))e.key===t&&r.push({absPath:e.absPath,fileRel:`${i.registryDir}/${e.basename}`,content:w(e.absPath,`utf8`)});if(r.length===0)return L(`编号「${t}」未命中任何债档`);if(r.length>1)return L(`编号「${t}」命中 ${r.length} 个 scope 的债档,存在取号歧义:${r.map(e=>e.fileRel).join(`、`)}`);let i=r[0];return i===void 0?L(`编号「${t}」未命中任何债档`):i}function U(e){t(e,{name:`lint`,description:`注册表 lint,覆盖文件名、H1、词表、固定节、收口一致性,附棘轮基线豁免`,options:[{flags:`--config <path>`,description:`显式配置路径`}],schema:k.looseObject({config:k.string().optional()}),action:async e=>{let t=M(),{config:n}=await N(e.config),r=f({root:t,config:n});for(let e of r.violations)I(`${e.file}:${e.line} [${e.rule}] ${e.message}`);P(`扫描 ${r.fileCount} 文件,豁免 ${r.exemptedCount} 项,基线 ${n.lint.baseline.length} 条`),r.violations.length>0&&L(`lint 违例 ${r.violations.length} 项`),F(`lint 通过,零违例`)}});let n=e.command(`index`).description(`README 索引新鲜度检查,只读,索引表人工维护,工具只检查不写入`),r=k.looseObject({scope:k.string().optional(),config:k.string().optional()});t(n,{name:`check`,description:`索引新鲜度判定,覆盖缺行、多行、slug 漂移,报文附期望行供人工粘贴`,options:[{flags:`--scope <scope>`,description:`限定 scope key`},{flags:`--config <path>`,description:`显式配置路径`}],schema:r,action:async e=>{let t=M(),{config:n}=await N(e.config),r=e.scope===void 0?n.scopes:n.scopes.filter(t=>t.key===e.scope);r.length===0&&L(`scope「${e.scope}」未登记`);let i=0;for(let e of r){let n=p({registryDirAbs:E(t,e.registryDir)});for(let t of n.findings)I(`[index:${t.kind}] [${e.key}] ${t.file} ${t.message}`);if(n.findings.length>0){P(`期望行,scope ${e.key},人工粘贴进 README:`);for(let e of n.expectedLines)P(` ${e}`)}i+=n.findings.length}i>0&&L(`index check 差异 ${i} 项,索引表人工维护,请按期望行修正 README`),F(`index check 通过,${r.length} scope 索引新鲜`)}})}function W(e){t(e,{name:`init`,description:`生成 lzi-debts.config.ts 与注册表 README 存根,幂等不覆盖`,options:[{flags:`--scope <scope>`,description:`scope key,缺省 root`},{flags:`--title <title>`,description:`scope 人类可读名,缺省 全局`},{flags:`--registry-dir <dir>`,description:`注册表目录,缺省 docs/debts`},{flags:`--dry-run`,description:`只呈现不落盘`}],schema:k.looseObject({scope:k.string().optional(),title:k.string().optional(),registryDir:k.string().optional(),dryRun:k.boolean().optional()}),action:async e=>{let t=M(),n=e.scope??`root`,r=e.title??`全局`,i=e.registryDir??`docs/debts`,a=E(t,`lzi-debts.config.ts`),o=E(t,i,`README.md`),s=j({scopeKey:n,scopeTitle:r,registryDir:i});e.dryRun?(P(`[dry-run] 将落盘 ${a}:\n${s}`),P(`[dry-run] 将落盘 ${o},即 README 存根`)):(S(a)?P(`配置已存在,跳过:${a}`):(T(a,s),F(`已生成配置:${a}`)),S(o)?P(`README 已存在,跳过:${o}`):(C(E(t,i),{recursive:!0}),T(o,d(r)),F(`已生成注册表 README 存根:${o}`)))}}),t(e,{name:`template`,description:`标准模板骨架与字段契约`,options:[{flags:`--format <format>`,description:`text 或 json,json 为字段契约供 agent 机读`}],schema:k.looseObject({format:k.enum([`text`,`json`]).optional()}),action:async e=>{e.format===`json`?process.stdout.write(`${JSON.stringify(s,null,2)}\n`):(e.format!==void 0&&L(`不支持的 format:${e.format}`),process.stdout.write(u()))}})}function G(e){W(e),B(e),U(e)}const K=_({name:`debts`,version:`0.0.1`,commands:[()=>J(),()=>Y(),()=>X()]}),q={scopes:[{key:`root`,title:`全局`,paths:[`.`],registryDir:`docs/debts`}],lint:{baseline:[]}};function J(){return v({name:`debts-lint`,description:`debts 注册表 lint,覆盖文件名、H1、词表、固定节、收口一致性`,schema:k.object({}),action:async()=>{let e=f({root:process.cwd(),config:q});for(let t of e.violations)process.stderr.write(`[${t.rule}] ${t.file}:${t.line} ${t.message}\n`);e.violations.length>0&&process.exit(1)}})}function Y(){return v({name:`debts-index-check`,description:`debts README 索引差量,只读,索引行人工登记`,schema:k.object({}),action:async()=>{let e=p({registryDirAbs:`${process.cwd()}/docs/debts`});for(let t of e.findings)process.stderr.write(`[index:${t.kind}] ${t.file} ${t.message}\n`);e.findings.length>0&&process.exit(1)}})}function X(){return v({name:`debts-template`,description:`debts 标准模板字段契约,供 agent 机读`,schema:k.object({}),action:async()=>{process.stdout.write(`${JSON.stringify(s,null,2)}\n`)}})}async function Z(){let t=e({name:`lzi-debts`,description:`Longzai Intelligence Debts CLI,文件化技术债注册表,语义分型与生命周期门禁`,version:`0.0.2`,interaction:n,color:r});G(t),await t.parseAsync(process.argv)}await Z();export{K as debtsPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-debts/cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Longzai Intelligence Debts 工具 CLI",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"debts",
|
|
8
|
+
"lint",
|
|
9
|
+
"longzai-intelligence",
|
|
10
|
+
"registry"
|
|
11
|
+
],
|
|
12
|
+
"license": "UNLICENSED",
|
|
13
|
+
"bin": {
|
|
14
|
+
"lzi-debts": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "lzi-builder",
|
|
30
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
31
|
+
"prepublishOnly": "bun run build:prod",
|
|
32
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
33
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
34
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
35
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
36
|
+
"lint": "lzi-lint lint",
|
|
37
|
+
"lint:fix": "lzi-lint fix",
|
|
38
|
+
"test": "bun test",
|
|
39
|
+
"test:watch": "bun test --watch",
|
|
40
|
+
"test:coverage": "bun test --coverage"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@longzai-intelligence-cli/core": "^0.0.11",
|
|
44
|
+
"@longzai-intelligence-cli/standard": "^0.0.11",
|
|
45
|
+
"@longzai-intelligence-debts/config": "0.0.2",
|
|
46
|
+
"@longzai-intelligence-debts/ledger": "0.0.2",
|
|
47
|
+
"@longzai-intelligence-docs/core": "0.0.22",
|
|
48
|
+
"@longzai-intelligence-docs/numbering-plugin": "0.0.22",
|
|
49
|
+
"zod": "^4.4.3"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/bun": "latest"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/README.md
DELETED