@crewx/doc 0.1.9-rc.241 → 0.1.9-rc.243
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/cli.js +9 -9
- package/dist/src/engine.js +1 -1
- package/dist/src/okf.js +2 -2
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var J=exports&&exports.__createBinding||(Object.create?(function(c,e,n,s){if(s===void 0)s=n;var g=Object.getOwnPropertyDescriptor(e,n);if(!g||("get"in g?!e.__esModule:g.writable||g.configurable)){g={enumerable:true,get:function(){return e[n]}}}Object.defineProperty(c,s,g)}):(function(c,e,n,s){if(s===void 0)s=n;c[s]=e[n]}));var V=exports&&exports.__setModuleDefault||(Object.create?(function(c,e){Object.defineProperty(c,"default",{enumerable:true,value:e})}):function(c,e){c["default"]=e});var N=exports&&exports.__importStar||(function(){var c=function(e){c=Object.getOwnPropertyNames||function(n){var s=[];for(var g in n)if(Object.prototype.hasOwnProperty.call(n,g))s[s.length]=g;return s};return c(e)};return function(e){if(e&&e.__esModule)return e;var n={};if(e!=null){for(var s=c(e),g=0;g<s.length;g++)if(s[g]!=="default")J(n,e,s[g])}V(n,e);return n}})();Object.defineProperty(exports,"__esModule",{value:true});exports.main=R;const h=N(require("fs"));const $=N(require("path"));const G=require("./src/engine");const _=require("./src/indexer");const P=require("./src/okf");const K=require("@crewx/knowledge-core");let M="unknown";try{const c=h.existsSync($.join(__dirname,"package.json"))?$.join(__dirname,"package.json"):$.join(__dirname,"..","package.json");const e=JSON.parse(h.readFileSync(c,"utf-8"));if(e?.version)M=String(e.version)}catch{}async function H(){try{return await Promise.resolve().then(()=>N(require("@crewx/shared/skill-tracer")))}catch{return null}}function Y(){const c=$.join(__dirname,"..","SKILL.md");if(h.existsSync(c)){process.stdout.write(h.readFileSync(c,"utf-8"))}else{console.log("No SKILL.md found. Use --help for usage.")}}function z(c){console.log(`
|
|
3
3
|
@crewx/doc@${M} - Document management and knowledge tools
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
@@ -33,17 +33,17 @@ Examples:
|
|
|
33
33
|
doc index
|
|
34
34
|
|
|
35
35
|
For detailed usage guide: doc usage
|
|
36
|
-
`)}function
|
|
37
|
-
`:"";const
|
|
38
|
-
`:"";let
|
|
36
|
+
`)}function U(c,e,n=6){try{const s=$.isAbsolute(e)?e:$.resolve(W(),e);const g=h.readFileSync(s,"utf-8");return c.extractHeadings(g,n).slice(0,3).map(A=>A.id)}catch{return[]}}function W(){return process.env.CREWX_WORKSPACE||process.cwd()}function C(c,e){if(c)return;const n=(0,K.formatActions)((0,K.generateNextActions)(e));if(n)console.log(n)}async function R(c){const e=c??process.argv.slice(2);const n=e[0];const s=e.includes("--json");const g=e.filter(t=>t!=="--json");const A=e.includes("--color");const u=!A&&(e.includes("--no-color")||!process.stdout.isTTY||!!process.env.NO_COLOR);const D=new G.DocEngine(u);if(n==="--version"){console.log(M);return}if(n==="usage"){Y();return}if(!n||n==="--help"||n==="-h"||n==="help"){z(u);return}const k=g[1]||"docs";const E=$.isAbsolute(k)?k:$.resolve(W(),k);if(n==="index"){const t=(0,_.indexDocs)(E);const o=t.filter(l=>l.important);const a=t.filter(l=>!l.important);const r=[...o,...a];if(s){console.log(JSON.stringify({success:true,directory:k,count:r.length,documents:r},null,2));return}console.log(`Indexed ${t.length} documents from ${k}/`);for(const l of r){const f=l.important?"\u2B50 ":"";const w=l.tags.length>0?` [${l.tags.join(", ")}]`:"";console.log(` ${f}${l.id} (${l.category})${w} \u2014 ${l.summary}`)}const d=[...new Set(t.flatMap(l=>l.tags))].slice(0,3);const i={commandId:"doc.index",params:{},resultTags:d,resultIds:r.slice(0,3).map(l=>l.id),resultCount:t.length};C(s,i);return}if(n==="stats"){const t=(0,_.indexDocs)(E);const o=t.filter(m=>m.important).length;const a={};for(const m of t){a[m.category]=(a[m.category]??0)+1}const r=Object.entries(a).sort(([,m],[,b])=>b-m);const d=(0,_.collectTags)(t);const i=Object.entries(d).sort(([,m],[,b])=>b-m).slice(0,10);if(s){console.log(JSON.stringify({success:true,directory:k,count:t.length,important_count:o,categories:Object.fromEntries(r),tags:Object.fromEntries(i)},null,2));return}const l=o>0?`, ${o} \u2B50 important`:"";console.log(`Document Stats: ${k}/ (${t.length} docs${l})`);console.log("\nCategories:");for(const[m,b]of r){console.log(` ${m}: ${b}`)}console.log("\nTags TOP 10:");if(i.length===0){console.log(" (none)")}else{for(const[m,b]of i){console.log(` ${m}: ${b}`)}}const f=i.slice(0,3).map(([m])=>m);const w={commandId:"doc.stats",params:{},resultTags:f,resultCount:t.length};C(s,w);return}if(n==="find"){const t=g[1];if(!t){const f=u?"":"\x1B[31m";const w=u?"":"\x1B[0m";console.error(`${f}Error: Query required${w}`);process.exit(1)}const o=g[2]||"docs";const a=(0,_.indexDocs)(o);const r=(0,_.findDocs)(a,t);if(s){console.log(JSON.stringify({success:true,directory:o,query:t,count:r.length,results:r},null,2));return}if(r.length===0){console.log("No results found.")}else{console.log(`Found ${r.length} results:`);for(const f of r){console.log(` [${f._score}] ${f.id} \u2014 ${f.summary}`)}}const d=[...new Set(r.flatMap(f=>f.tags??[]))].slice(0,3);const i=r.slice(0,3).map(f=>f.id);const l={commandId:"doc.find",params:{query:t},resultTags:d,resultIds:i,resultCount:r.length};C(s,l);return}if(n==="graph"){const t=(0,_.indexDocs)(E);const o=(0,_.buildDocGraph)(t);if(s){console.log(JSON.stringify({success:true,directory:k,graph:o},null,2));return}console.log(`Graph: ${o.stats.nodeCount} nodes, ${o.stats.edgeCount} edges`);if(o.edges.length>0){console.log("Edges:");for(const d of o.edges){console.log(` ${d.from} \u2194 ${d.to} (${d.type}, w=${d.weight})`)}}const a=[...new Set(t.flatMap(d=>d.tags))].slice(0,3);const r={commandId:"doc.graph",params:{},resultTags:a,resultCount:o.stats.nodeCount};C(s,r);return}if(n==="tags"){const t=(0,_.indexDocs)(E);const o=(0,_.collectTags)(t);const a=Object.entries(o).sort(([,i],[,l])=>l-i);console.log(`Tags (${a.length} unique):`);for(const[i,l]of a){console.log(` ${i}: ${l}`)}const r=a.slice(0,3).map(([i])=>i);const d={commandId:"doc.tags",params:{},resultTags:r,resultCount:a.length};C(s,d);return}if(n==="properties"){const t=(0,_.indexDocs)(E);const o=(0,_.collectProperties)(t);console.log("Frontmatter properties:");for(const[d,i]of Object.entries(o)){console.log(` ${d}: ${i.join(", ")}`)}const a=[...new Set(t.flatMap(d=>d.tags))].slice(0,3);const r={commandId:"doc.index",params:{},resultTags:a,resultCount:t.length};C(s,r);return}if(n==="create"){const t=e[1];const o=e[2];if(!t||!o){const x=u?"":"\x1B[31m";const q=u?"":"\x1B[0m";console.error(`${x}Error: dir and title are required${q}`);console.error('Usage: doc create <dir> "<title>" [--tags=t1,t2] [--category=cat] [--author=agent] [--body="content"] [--important]');process.exit(1)}const a=e.find(x=>x.startsWith("--tags="));const r=a?a.slice("--tags=".length).split(",").map(x=>x.trim()).filter(Boolean):[];const d=e.find(x=>x.startsWith("--category="));const i=d?d.slice("--category=".length):"general";const l=e.find(x=>x.startsWith("--author="));const f=l?l.slice("--author=".length):"";const w=e.find(x=>x.startsWith("--body="));const m=w?w.slice("--body=".length):"";const b=e.includes("--important");const I=o.trim().replace(/[\s_]+/g,"-").toLowerCase().replace(/[^a-z0-9\uAC00-\uD7AF\u3130-\u318F-]/g,"").replace(/-+/g,"-").replace(/^-+|-+$/g,"");const j=$.join(t,`${I}.md`);if(h.existsSync(j)){const x=u?"":"\x1B[31m";const q=u?"":"\x1B[0m";console.error(`${x}Error: File already exists: ${j}${q}`);process.exit(1)}h.mkdirSync(t,{recursive:true});const y=new Date().toISOString().split("T")[0];const p=r.length>0?`[${r.join(", ")}]`:"[]";const S=f?`author: ${f}
|
|
37
|
+
`:"";const F=b?`important: true
|
|
38
|
+
`:"";let T=`---
|
|
39
39
|
type: document
|
|
40
40
|
summary: ${o}
|
|
41
41
|
category: ${i}
|
|
42
42
|
tags: ${p}
|
|
43
|
-
date: ${
|
|
44
|
-
${S}${
|
|
45
|
-
`;if(m){
|
|
43
|
+
date: ${y}
|
|
44
|
+
${S}${F}---
|
|
45
|
+
`;if(m){T+=`
|
|
46
46
|
${m}
|
|
47
|
-
`}h.writeFileSync(j,
|
|
47
|
+
`}h.writeFileSync(j,T,"utf-8");const O=u?"":"\x1B[32m";const L=u?"":"\x1B[0m";console.log(`${O}Created:${L} ${j}`);const B={commandId:"doc.create",params:{dir:t,title:o},resultTags:r,resultCount:1};C(s,B);return}if(n==="okf"){const t=e[1];const o=e[2];const a=u?"":"\x1B[31m";const r=u?"":"\x1B[32m";const d=u?"":"\x1B[33m";const i=u?"":"\x1B[0m";if(!t||!["init","validate","normalize"].includes(t)){console.error(`${a}Error: okf subcommand required: init | validate | normalize${i}`);console.error("Usage: doc okf <init|validate|normalize> <file> [--type=...] [--title=...] [--tags=...] [--dry-run]");process.exit(1)}if(!o){console.error(`${a}Error: File path required${i}`);process.exit(1)}const l=e.find(p=>p.startsWith("--type="))?.slice("--type=".length);const f=e.find(p=>p.startsWith("--title="))?.slice("--title=".length);const w=e.find(p=>p.startsWith("--description="))?.slice("--description=".length);const m=e.find(p=>p.startsWith("--tags="))?.slice("--tags=".length);const b=m?m.split(",").map(p=>p.trim()).filter(Boolean):void 0;const I=e.includes("--dry-run");const j=W();const y=$.isAbsolute(o)?o:$.resolve(j,o);if(t==="init"){if(h.existsSync(y)){console.error(`${a}Error: File already exists: ${o}${i}`);console.error('Use "doc okf normalize" to update an existing file.');process.exit(1)}const p=f??$.basename(o,$.extname(o)).replace(/[-_]+/g," ").replace(/\b\w/g,T=>T.toUpperCase());const S=`
|
|
48
48
|
# ${p}
|
|
49
|
-
`;const
|
|
49
|
+
`;const F=(0,P.normalizeOkfDocument)(S,{filePath:y,workspaceRoot:j,type:l,title:f,description:w,tags:b});h.mkdirSync($.dirname(y),{recursive:true});h.writeFileSync(y,F,"utf-8");console.log(`${r}Created:${i} ${o}`);return}if(t==="validate"){if(!h.existsSync(y)){console.error(`${a}Error: File not found: ${o}${i}`);process.exit(1)}const p=h.readFileSync(y,"utf-8");const S=(0,P.validateOkfDocument)(p);if(S.length===0){console.log(`${r}OK:${i} ${o} \u2014 OKF frontmatter is valid`);return}const F=S.filter(O=>O.level==="error");const T=S.filter(O=>O.level==="warning");for(const O of T){console.log(`${d}WARN [${O.field}]:${i} ${O.message}`)}for(const O of F){console.error(`${a}ERROR [${O.field}]:${i} ${O.message}`)}if(F.length>0){process.exit(1)}return}if(t==="normalize"){let p="";if(h.existsSync(y)){p=h.readFileSync(y,"utf-8")}const S=(0,P.normalizeOkfDocument)(p,{filePath:y,workspaceRoot:j,type:l,title:f,description:w,tags:b});if(S===p){console.log(`${r}No changes:${i} ${o} is already normalized`);return}if(I){console.log(`${d}[dry-run]${i} Would update: ${o}`);process.stdout.write(S);return}h.mkdirSync($.dirname(y),{recursive:true});h.writeFileSync(y,S,"utf-8");console.log(`${r}Normalized:${i} ${o}`);return}}const v=e[1];if(!v){const t=u?"":"\x1B[31m";const o=u?"":"\x1B[0m";console.error(`${t}Error: File path required${o}`);z(u);process.exit(1)}switch(n){case"toc":{const t=e.find(a=>a.startsWith("--depth="));const o=t?parseInt(t.split("=")[1]??"4",10):4;D.toc(v,{maxDepth:o});C(s,{commandId:"doc.toc",params:{file:v},resultIds:U(D,v,o)});break}case"section":{const t=e[2];if(!t){const o=u?"":"\x1B[31m";const a=u?"":"\x1B[0m";console.error(`${o}Error: Heading selector required${a}`);process.exit(1)}D.section(v,t);C(s,{commandId:"doc.section",params:{file:v,heading:t}});break}case"status":{D.status(v);C(s,{commandId:"doc.toc",params:{file:v},resultIds:U(D,v)});break}case"summary":{D.summary(v);break}default:{const t=u?"":"\x1B[31m";const o=u?"":"\x1B[0m";console.error(`${t}Unknown command: ${n}${o}`);z(u);process.exit(1)}}}if(require.main===module){H().then(c=>{const e=c?{skillVersion:c.getOwnSkillVersion(__dirname)}:{};return c?c.run("crewx/doc",R,e):R()}).catch(c=>{console.error(`Error: ${c.message}`);process.exit(1)})}
|
package/dist/src/engine.js
CHANGED
|
@@ -6,4 +6,4 @@ ${e.red}\u274C Todo:${e.reset} ${s.todo}
|
|
|
6
6
|
${e.yellow}\u26A0\uFE0F Partial:${e.reset} ${s.partial}
|
|
7
7
|
\u{1F6A7} WIP: ${s.wip}
|
|
8
8
|
Unknown: ${s.unknown}
|
|
9
|
-
`)}readFile(t){const e=this.colors;const n=g.isAbsolute(t)?t:g.resolve(process.cwd(),t);if(!h.existsSync(n)){console.error(`${e.red}Error: File not found: ${n}${e.reset}`);process.exit(1)}return h.readFileSync(n,"utf-8")}}exports.DocEngine=$;var w=require("./annotation");Object.defineProperty(exports,"buildAnnotationDigest",{enumerable:true,get:function(){return w.buildAnnotationDigest}});
|
|
9
|
+
`)}readFile(t){const e=this.colors;const n=g.isAbsolute(t)?t:g.resolve(process.env.CREWX_WORKSPACE||process.cwd(),t);if(!h.existsSync(n)){console.error(`${e.red}Error: File not found: ${n}${e.reset}`);process.exit(1)}return h.readFileSync(n,"utf-8")}}exports.DocEngine=$;var w=require("./annotation");Object.defineProperty(exports,"buildAnnotationDigest",{enumerable:true,get:function(){return w.buildAnnotationDigest}});
|
package/dist/src/okf.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var g=exports&&exports.__createBinding||(Object.create?(function(n,e,i,r){if(r===void 0)r=i;var t=Object.getOwnPropertyDescriptor(e,i);if(!t||("get"in t?!e.__esModule:t.writable||t.configurable)){t={enumerable:true,get:function(){return e[i]}}}Object.defineProperty(n,r,t)}):(function(n,e,i,r){if(r===void 0)r=i;n[r]=e[i]}));var p=exports&&exports.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:true,value:e})}):function(n,e){n["default"]=e});var f=exports&&exports.__importStar||(function(){var n=function(e){n=Object.getOwnPropertyNames||function(i){var r=[];for(var t in i)if(Object.prototype.hasOwnProperty.call(i,t))r[r.length]=t;return r};return n(e)};return function(e){if(e&&e.__esModule)return e;var i={};if(e!=null){for(var r=n(e),t=0;t<r.length;t++)if(r[t]!=="default")g(i,e,r[t])}p(i,e);return i}})();Object.defineProperty(exports,"__esModule",{value:true});exports.validateOkfDocument=v;exports.normalizeOkfDocument=
|
|
1
|
+
"use strict";var g=exports&&exports.__createBinding||(Object.create?(function(n,e,i,r){if(r===void 0)r=i;var t=Object.getOwnPropertyDescriptor(e,i);if(!t||("get"in t?!e.__esModule:t.writable||t.configurable)){t={enumerable:true,get:function(){return e[i]}}}Object.defineProperty(n,r,t)}):(function(n,e,i,r){if(r===void 0)r=i;n[r]=e[i]}));var p=exports&&exports.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:true,value:e})}):function(n,e){n["default"]=e});var f=exports&&exports.__importStar||(function(){var n=function(e){n=Object.getOwnPropertyNames||function(i){var r=[];for(var t in i)if(Object.prototype.hasOwnProperty.call(i,t))r[r.length]=t;return r};return n(e)};return function(e){if(e&&e.__esModule)return e;var i={};if(e!=null){for(var r=n(e),t=0;t<r.length;t++)if(r[t]!=="default")g(i,e,r[t])}p(i,e);return i}})();Object.defineProperty(exports,"__esModule",{value:true});exports.validateOkfDocument=v;exports.normalizeOkfDocument=O;const o=f(require("js-yaml"));const u=f(require("path"));const y=["type","title","description","resource","tags","timestamp","crewx"];function m(n){const e=/^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)([\s\S]*)$/;const i=n.match(e);if(!i){return{frontmatter:null,body:n}}return{frontmatter:i[1],body:i[2]}}function h(n,e){const i=o.dump(n,{lineWidth:-1,noRefs:true,sortKeys:false});const r=e.length>0&&!e.startsWith("\n")?"\n":"";return`---
|
|
2
2
|
${i}---
|
|
3
|
-
${r}${e}`}function
|
|
3
|
+
${r}${e}`}function _(n){const e=n.match(/^#[ \t]+(.+)$/m);return e?.[1]?.trim()}function b(n){return u.basename(n,u.extname(n)).replace(/[-_]+/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function v(n){const e=[];const{frontmatter:i}=m(n);if(!i){e.push({level:"error",field:"frontmatter",message:"No YAML frontmatter found"});return e}let r;try{r=o.load(i)}catch(c){const s=c instanceof Error?c.message:String(c);e.push({level:"error",field:"frontmatter",message:`YAML parse error: ${s}`});return e}if(!r||typeof r!=="object"||Array.isArray(r)){e.push({level:"error",field:"frontmatter",message:"Frontmatter must be a YAML object"});return e}const t=r;if(!t["type"]){e.push({level:"error",field:"type",message:'Required field "type" is missing'})}if(!t["title"]){e.push({level:"warning",field:"title",message:'Recommended field "title" is missing'})}if(!t["resource"]){e.push({level:"warning",field:"resource",message:'Recommended field "resource" is missing'})}return e}function O(n,e){const{frontmatter:i,body:r}=m(n);let t={};if(i){try{const a=o.load(i);if(a&&typeof a==="object"&&!Array.isArray(a)){t=a}}catch{}}const c=Object.keys(t).filter(a=>!y.includes(a));const s={};s["type"]=e.type??t["type"]??"Reference";s["title"]=e.title??t["title"]??_(r)??b(e.filePath);s["description"]=e.description!==void 0?e.description:t["description"]??"";if(t["resource"]){s["resource"]=t["resource"]}else{const a=e.workspaceRoot??process.env.CREWX_WORKSPACE??process.cwd();s["resource"]=u.relative(a,e.filePath).replace(/\\/g,"/")}const d=Array.isArray(t["tags"])?t["tags"]:void 0;s["tags"]=e.tags??d??[];if(t["timestamp"]){s["timestamp"]=t["timestamp"]}else{s["timestamp"]=(e.now??new Date).toISOString()}const l=t["crewx"]&&typeof t["crewx"]==="object"&&!Array.isArray(t["crewx"])?{...t["crewx"]}:{};s["crewx"]={highlights:l["highlights"]??[],...l};for(const a of c){s[a]=t[a]}return h(s,r)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewx/doc",
|
|
3
|
-
"version": "0.1.9-rc.
|
|
3
|
+
"version": "0.1.9-rc.243",
|
|
4
4
|
"description": "Markdown TOC extraction and section management for CrewX",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/src/engine.js",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"js-yaml": "^4.1.1",
|
|
37
|
-
"@crewx/shared": "0.0.6-rc.
|
|
38
|
-
"@crewx/knowledge-core": "0.1.17-rc.
|
|
37
|
+
"@crewx/shared": "0.0.6-rc.164",
|
|
38
|
+
"@crewx/knowledge-core": "0.1.17-rc.260"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/js-yaml": "^4.0.9",
|