@guiho/xdocs 0.1.0
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/CHANGELOG.md +1 -0
- package/LICENSE.md +23 -0
- package/jsr.json +12 -0
- package/library/cli.d.ts +8 -0
- package/library/cli.d.ts.map +1 -0
- package/library/cli.js +97 -0
- package/library/commands/generate.d.ts +7 -0
- package/library/commands/generate.d.ts.map +1 -0
- package/library/commands/generate.js +122 -0
- package/library/commands/init.d.ts +7 -0
- package/library/commands/init.d.ts.map +1 -0
- package/library/commands/init.js +71 -0
- package/library/commands/list.d.ts +7 -0
- package/library/commands/list.d.ts.map +1 -0
- package/library/commands/list.js +41 -0
- package/library/commands/merge.d.ts +7 -0
- package/library/commands/merge.d.ts.map +1 -0
- package/library/commands/merge.js +55 -0
- package/library/commands/prompt.d.ts +7 -0
- package/library/commands/prompt.d.ts.map +1 -0
- package/library/commands/prompt.js +19 -0
- package/library/commands/scan.d.ts +7 -0
- package/library/commands/scan.d.ts.map +1 -0
- package/library/commands/scan.js +53 -0
- package/library/commands/tree.d.ts +7 -0
- package/library/commands/tree.d.ts.map +1 -0
- package/library/commands/tree.js +49 -0
- package/library/config.d.ts +24 -0
- package/library/config.d.ts.map +1 -0
- package/library/config.js +126 -0
- package/library/discovery.d.ts +13 -0
- package/library/discovery.d.ts.map +1 -0
- package/library/discovery.js +118 -0
- package/library/errors.d.ts +9 -0
- package/library/errors.d.ts.map +1 -0
- package/library/errors.js +15 -0
- package/library/flags.d.ts +23 -0
- package/library/flags.d.ts.map +1 -0
- package/library/flags.js +96 -0
- package/library/guiho-xdocs-bin.d.ts +6 -0
- package/library/guiho-xdocs-bin.d.ts.map +1 -0
- package/library/guiho-xdocs-bin.js +6 -0
- package/library/guiho-xdocs.d.ts +14 -0
- package/library/guiho-xdocs.d.ts.map +1 -0
- package/library/guiho-xdocs.js +21 -0
- package/library/help.d.ts +12 -0
- package/library/help.d.ts.map +1 -0
- package/library/help.js +165 -0
- package/library/metadata.d.ts +22 -0
- package/library/metadata.d.ts.map +1 -0
- package/library/metadata.js +110 -0
- package/library/prompts.d.ts +15 -0
- package/library/prompts.d.ts.map +1 -0
- package/library/prompts.js +49 -0
- package/library/tree.d.ts +13 -0
- package/library/tree.d.ts.map +1 -0
- package/library/tree.js +114 -0
- package/library/types.d.ts +108 -0
- package/library/types.d.ts.map +1 -0
- package/library/types.js +4 -0
- package/package.json +77 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# GUIHO XDocs Changelog
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
@guiho/xdocs
|
|
2
|
+
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026 Cristóvão GUIHO
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/jsr.json
ADDED
package/library/cli.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
/** Main CLI entry point. */
|
|
5
|
+
export declare const runCli: (rawArgs?: string[]) => Promise<void>;
|
|
6
|
+
/** Run the CLI with error handling. */
|
|
7
|
+
export declare const runCliWithErrorHandling: (rawArgs?: string[]) => Promise<void>;
|
|
8
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../source/cli.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiBH,4BAA4B;AAC5B,eAAO,MAAM,MAAM,GAAU,UAAS,MAAM,EAA0B,KAAG,OAAO,CAAC,IAAI,CAqDpF,CAAA;AAmBD,uCAAuC;AACvC,eAAO,MAAM,uBAAuB,GAAU,UAAU,MAAM,EAAE,KAAG,OAAO,CAAC,IAAI,CAiB9E,CAAA"}
|
package/library/cli.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { XDocsError } from './errors.js';
|
|
6
|
+
import { parseArgs, booleanFlag, stringFlag } from './flags.js';
|
|
7
|
+
import { showHelp, showCommandHelp, showVersion } from './help.js';
|
|
8
|
+
import { runInit } from './commands/init.js';
|
|
9
|
+
import { runScan } from './commands/scan.js';
|
|
10
|
+
import { runGenerate } from './commands/generate.js';
|
|
11
|
+
import { runPrompt } from './commands/prompt.js';
|
|
12
|
+
import { runMerge } from './commands/merge.js';
|
|
13
|
+
import { runTree } from './commands/tree.js';
|
|
14
|
+
import { runList } from './commands/list.js';
|
|
15
|
+
const validCommands = new Set(['init', 'scan', 'generate', 'prompt', 'merge', 'tree', 'list']);
|
|
16
|
+
/** Main CLI entry point. */
|
|
17
|
+
export const runCli = async (rawArgs = process.argv.slice(2)) => {
|
|
18
|
+
const parsed = parseArgs(rawArgs);
|
|
19
|
+
if (booleanFlag(parsed.flags, 'version')) {
|
|
20
|
+
process.stdout.write(showVersion() + '\n');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (booleanFlag(parsed.flags, 'help')) {
|
|
24
|
+
if (parsed.command && validCommands.has(parsed.command)) {
|
|
25
|
+
process.stdout.write(showCommandHelp(parsed.command) + '\n');
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
process.stdout.write(showHelp() + '\n');
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!parsed.command) {
|
|
33
|
+
process.stdout.write(showHelp() + '\n');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!validCommands.has(parsed.command)) {
|
|
37
|
+
throw new XDocsError(`Unknown command: ${parsed.command}\n\nRun \`xdocs --help\` for available commands.`);
|
|
38
|
+
}
|
|
39
|
+
const options = resolveOptions(parsed.flags);
|
|
40
|
+
const command = parsed.command;
|
|
41
|
+
switch (command) {
|
|
42
|
+
case 'init':
|
|
43
|
+
await runInit(options, parsed);
|
|
44
|
+
break;
|
|
45
|
+
case 'scan':
|
|
46
|
+
await runScan(options, parsed);
|
|
47
|
+
break;
|
|
48
|
+
case 'generate':
|
|
49
|
+
await runGenerate(options, parsed);
|
|
50
|
+
break;
|
|
51
|
+
case 'prompt':
|
|
52
|
+
await runPrompt(options, parsed);
|
|
53
|
+
break;
|
|
54
|
+
case 'merge':
|
|
55
|
+
await runMerge(options, parsed);
|
|
56
|
+
break;
|
|
57
|
+
case 'tree':
|
|
58
|
+
await runTree(options, parsed);
|
|
59
|
+
break;
|
|
60
|
+
case 'list':
|
|
61
|
+
await runList(options, parsed);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/** Build XDocsCliOptions from parsed flags. */
|
|
66
|
+
const resolveOptions = (flags) => {
|
|
67
|
+
const cwd = stringFlag(flags, 'cwd') ?? process.cwd();
|
|
68
|
+
const format = stringFlag(flags, 'format') ?? 'text';
|
|
69
|
+
if (format !== 'text' && format !== 'json' && format !== 'markdown') {
|
|
70
|
+
throw new XDocsError(`Invalid --format value: "${format}". Expected text, json, or markdown.`);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
cwd: resolve(cwd),
|
|
74
|
+
config: stringFlag(flags, 'config'),
|
|
75
|
+
format: format,
|
|
76
|
+
verbose: booleanFlag(flags, 'verbose'),
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/** Run the CLI with error handling. */
|
|
80
|
+
export const runCliWithErrorHandling = async (rawArgs) => {
|
|
81
|
+
try {
|
|
82
|
+
await runCli(rawArgs);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error instanceof XDocsError) {
|
|
86
|
+
process.stderr.write(`error: ${error.message}\n`);
|
|
87
|
+
process.exit(error.exitCode);
|
|
88
|
+
}
|
|
89
|
+
if (error instanceof Error) {
|
|
90
|
+
process.stderr.write(`error: ${error.message}\n`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
process.stderr.write('error: An unexpected error occurred.\n');
|
|
94
|
+
}
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the generate command. */
|
|
6
|
+
export declare const runGenerate: (options: XDocsCliOptions, parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../source/commands/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAMnE,gCAAgC;AAChC,eAAO,MAAM,WAAW,GAAU,SAAS,eAAe,EAAE,QAAQ,eAAe,KAAG,OAAO,CAAC,IAAI,CA2BjG,CAAA"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { readdir } from 'node:fs/promises';
|
|
5
|
+
import { relative, resolve } from 'node:path';
|
|
6
|
+
import { writeFile } from 'node:fs/promises';
|
|
7
|
+
import { loadConfigOrDefaults } from '../config.js';
|
|
8
|
+
import { scanProject } from '../discovery.js';
|
|
9
|
+
import { buildTree, renderTree } from '../tree.js';
|
|
10
|
+
import { stringFlag } from '../flags.js';
|
|
11
|
+
/** Run the generate command. */
|
|
12
|
+
export const runGenerate = async (options, parsed) => {
|
|
13
|
+
const config = await loadConfigOrDefaults(options);
|
|
14
|
+
const targetPath = parsed.positionals[0] ? resolve(options.cwd, parsed.positionals[0]) : options.cwd;
|
|
15
|
+
const outputPath = stringFlag(parsed.flags, 'output');
|
|
16
|
+
const result = await scanProject(config);
|
|
17
|
+
const isProjectScope = targetPath === options.cwd;
|
|
18
|
+
let content;
|
|
19
|
+
if (isProjectScope) {
|
|
20
|
+
content = await generateProjectDoc(config.project.name, result.xdocsFiles, config.cwd);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const relTarget = relative(config.cwd, targetPath);
|
|
24
|
+
const relevantFiles = result.xdocsFiles.filter((f) => f.path.startsWith(targetPath));
|
|
25
|
+
content = await generateModuleDoc(relTarget, relevantFiles, config.cwd, targetPath);
|
|
26
|
+
}
|
|
27
|
+
if (outputPath) {
|
|
28
|
+
await writeFile(resolve(options.cwd, outputPath), content, 'utf8');
|
|
29
|
+
process.stdout.write(`generated: ${outputPath}\n`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
process.stdout.write(content);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/** Generate a project-level documentation file. */
|
|
36
|
+
const generateProjectDoc = async (projectName, xdocsFiles, _cwd) => {
|
|
37
|
+
const lines = [
|
|
38
|
+
`# ${projectName}`,
|
|
39
|
+
'',
|
|
40
|
+
'## Project Overview',
|
|
41
|
+
'',
|
|
42
|
+
`This document was generated by xdocs. It describes the full project structure.`,
|
|
43
|
+
'',
|
|
44
|
+
];
|
|
45
|
+
// Tree
|
|
46
|
+
const tree = buildTree(xdocsFiles);
|
|
47
|
+
lines.push('## Hierarchy', '', '```');
|
|
48
|
+
lines.push(renderTree(tree));
|
|
49
|
+
lines.push('```', '');
|
|
50
|
+
// Modules
|
|
51
|
+
lines.push('## Modules', '');
|
|
52
|
+
for (const file of xdocsFiles) {
|
|
53
|
+
if (!file.metadata)
|
|
54
|
+
continue;
|
|
55
|
+
lines.push(`### ${file.metadata.subject}`, '');
|
|
56
|
+
lines.push(file.metadata.description, '');
|
|
57
|
+
lines.push(`Location: \`${file.relativePath}\``, '');
|
|
58
|
+
const fileEntries = Object.entries(file.metadata.files);
|
|
59
|
+
if (fileEntries.length > 0) {
|
|
60
|
+
lines.push('Files:', '');
|
|
61
|
+
for (const [name, desc] of fileEntries) {
|
|
62
|
+
lines.push(`- \`${name}\`: ${desc}`);
|
|
63
|
+
}
|
|
64
|
+
lines.push('');
|
|
65
|
+
}
|
|
66
|
+
if (file.body.trim()) {
|
|
67
|
+
lines.push(file.body.trim(), '');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return lines.join('\n');
|
|
71
|
+
};
|
|
72
|
+
/** Generate a module-level documentation file. */
|
|
73
|
+
const generateModuleDoc = async (moduleName, xdocsFiles, _cwd, targetPath) => {
|
|
74
|
+
const lines = [
|
|
75
|
+
`# ${moduleName}`,
|
|
76
|
+
'',
|
|
77
|
+
];
|
|
78
|
+
// List all files in the target directory
|
|
79
|
+
let dirEntries = [];
|
|
80
|
+
try {
|
|
81
|
+
const entries = await readdir(targetPath);
|
|
82
|
+
dirEntries = entries.filter((e) => !e.startsWith('.'));
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Directory might not exist
|
|
86
|
+
}
|
|
87
|
+
if (xdocsFiles.length > 0) {
|
|
88
|
+
for (const file of xdocsFiles) {
|
|
89
|
+
if (!file.metadata)
|
|
90
|
+
continue;
|
|
91
|
+
lines.push(`## ${file.metadata.subject}`, '');
|
|
92
|
+
lines.push(file.metadata.description, '');
|
|
93
|
+
const fileEntries = Object.entries(file.metadata.files);
|
|
94
|
+
if (fileEntries.length > 0) {
|
|
95
|
+
lines.push('### Files', '');
|
|
96
|
+
for (const [name, desc] of fileEntries) {
|
|
97
|
+
lines.push(`- \`${name}\`: ${desc}`);
|
|
98
|
+
}
|
|
99
|
+
lines.push('');
|
|
100
|
+
}
|
|
101
|
+
if (file.metadata.children.length > 0) {
|
|
102
|
+
lines.push('### Submodules', '');
|
|
103
|
+
for (const child of file.metadata.children) {
|
|
104
|
+
lines.push(`- ${child}`);
|
|
105
|
+
}
|
|
106
|
+
lines.push('');
|
|
107
|
+
}
|
|
108
|
+
if (file.body.trim()) {
|
|
109
|
+
lines.push(file.body.trim(), '');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
lines.push(`No xdocs files found in this directory.`, '');
|
|
115
|
+
lines.push('### Directory contents', '');
|
|
116
|
+
for (const entry of dirEntries) {
|
|
117
|
+
lines.push(`- \`${entry}\``);
|
|
118
|
+
}
|
|
119
|
+
lines.push('');
|
|
120
|
+
}
|
|
121
|
+
return lines.join('\n');
|
|
122
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the init command. */
|
|
6
|
+
export declare const runInit: (options: XDocsCliOptions, _parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../source/commands/init.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA8BnE,4BAA4B;AAC5B,eAAO,MAAM,OAAO,GAAU,SAAS,eAAe,EAAE,SAAS,eAAe,KAAG,OAAO,CAAC,IAAI,CAqC9F,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { writeDefaultConfig } from '../config.js';
|
|
8
|
+
const ROOT_XDOCS_CONTENT = `
|
|
9
|
+
# GUIHO XDocs Documentation
|
|
10
|
+
|
|
11
|
+
## Files
|
|
12
|
+
|
|
13
|
+
## Directories
|
|
14
|
+
`.trim() + '\n';
|
|
15
|
+
const AGENTS_XDOCS_BLOCK = `
|
|
16
|
+
<!-- BEGIN XDOCS — DO NOT EDIT THIS SECTION -->
|
|
17
|
+
## XDocs
|
|
18
|
+
|
|
19
|
+
This project uses xdocs for structured documentation. xdocs files describe
|
|
20
|
+
modules, their purpose, files, and hierarchy.
|
|
21
|
+
|
|
22
|
+
- Configuration: \`xdocs.config.toml\`
|
|
23
|
+
- Root documentation: \`XDOCS.md\`
|
|
24
|
+
- File extensions: \`.docs.md\`, \`.xdocs.md\`
|
|
25
|
+
|
|
26
|
+
When modifying code, check the xdocs configuration for AI behavior mode.
|
|
27
|
+
In "prompt" mode, announce documentation updates and wait for confirmation.
|
|
28
|
+
In "auto" mode, update documentation immediately.
|
|
29
|
+
|
|
30
|
+
Use the xdocs CLI for operations: \`xdocs scan\`, \`xdocs generate\`, \`xdocs tree\`, etc.
|
|
31
|
+
<!-- END XDOCS -->
|
|
32
|
+
`.trim();
|
|
33
|
+
/** Run the init command. */
|
|
34
|
+
export const runInit = async (options, _parsed) => {
|
|
35
|
+
const cwd = options.cwd;
|
|
36
|
+
// 1. Create xdocs.config.toml
|
|
37
|
+
const configPath = resolve(cwd, 'xdocs.config.toml');
|
|
38
|
+
if (existsSync(configPath)) {
|
|
39
|
+
process.stdout.write(`exists: xdocs.config.toml\n`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
await writeDefaultConfig(cwd);
|
|
43
|
+
process.stdout.write(`created: xdocs.config.toml\n`);
|
|
44
|
+
}
|
|
45
|
+
// 2. Create XDOCS.md
|
|
46
|
+
const xdocsPath = resolve(cwd, 'XDOCS.md');
|
|
47
|
+
if (existsSync(xdocsPath)) {
|
|
48
|
+
process.stdout.write(`exists: XDOCS.md\n`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
await writeFile(xdocsPath, ROOT_XDOCS_CONTENT, 'utf8');
|
|
52
|
+
process.stdout.write(`created: XDOCS.md\n`);
|
|
53
|
+
}
|
|
54
|
+
// 3. Update AGENTS.md
|
|
55
|
+
const agentsPath = resolve(cwd, 'AGENTS.md');
|
|
56
|
+
if (existsSync(agentsPath)) {
|
|
57
|
+
const content = await readFile(agentsPath, 'utf8');
|
|
58
|
+
if (content.includes('<!-- BEGIN XDOCS')) {
|
|
59
|
+
process.stdout.write(`exists: AGENTS.md (xdocs section already present)\n`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
await writeFile(agentsPath, content.trimEnd() + '\n\n' + AGENTS_XDOCS_BLOCK + '\n', 'utf8');
|
|
63
|
+
process.stdout.write(`updated: AGENTS.md (added xdocs section)\n`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
await writeFile(agentsPath, '# Agent Instructions\n\n' + AGENTS_XDOCS_BLOCK + '\n', 'utf8');
|
|
68
|
+
process.stdout.write(`created: AGENTS.md\n`);
|
|
69
|
+
}
|
|
70
|
+
process.stdout.write(`\nxdocs initialized.\n`);
|
|
71
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the list command. */
|
|
6
|
+
export declare const runList: (options: XDocsCliOptions, parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../source/commands/list.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAInE,4BAA4B;AAC5B,eAAO,MAAM,OAAO,GAAU,SAAS,eAAe,EAAE,QAAQ,eAAe,KAAG,OAAO,CAAC,IAAI,CA2C7F,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { resolve, relative } from 'node:path';
|
|
5
|
+
import { loadConfigOrDefaults } from '../config.js';
|
|
6
|
+
import { scanProject } from '../discovery.js';
|
|
7
|
+
/** Run the list command. */
|
|
8
|
+
export const runList = async (options, parsed) => {
|
|
9
|
+
const config = await loadConfigOrDefaults(options);
|
|
10
|
+
const targetPath = parsed.positionals[0] ? resolve(options.cwd, parsed.positionals[0]) : options.cwd;
|
|
11
|
+
const result = await scanProject(config);
|
|
12
|
+
const relevantFiles = result.xdocsFiles.filter((f) => f.path.startsWith(targetPath));
|
|
13
|
+
// Collect all files with descriptions from metadata
|
|
14
|
+
const fileList = [];
|
|
15
|
+
for (const xdocsFile of relevantFiles) {
|
|
16
|
+
if (!xdocsFile.metadata)
|
|
17
|
+
continue;
|
|
18
|
+
for (const [fileName, description] of Object.entries(xdocsFile.metadata.files)) {
|
|
19
|
+
fileList.push({
|
|
20
|
+
file: fileName,
|
|
21
|
+
description,
|
|
22
|
+
source: xdocsFile.relativePath,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (options.format === 'json') {
|
|
27
|
+
process.stdout.write(JSON.stringify(fileList, null, 2) + '\n');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (fileList.length === 0) {
|
|
31
|
+
const scope = targetPath === options.cwd ? 'project' : relative(options.cwd, targetPath);
|
|
32
|
+
process.stdout.write(`No documented files found in ${scope}.\n`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const scope = targetPath === options.cwd ? 'project' : relative(options.cwd, targetPath);
|
|
36
|
+
process.stdout.write(`\nfiles in ${scope}:\n\n`);
|
|
37
|
+
for (const entry of fileList) {
|
|
38
|
+
process.stdout.write(` ${entry.file}: ${entry.description}\n`);
|
|
39
|
+
}
|
|
40
|
+
process.stdout.write('\n');
|
|
41
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the merge command. */
|
|
6
|
+
export declare const runMerge: (options: XDocsCliOptions, parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../source/commands/merge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKnE,6BAA6B;AAC7B,eAAO,MAAM,QAAQ,GAAU,SAAS,eAAe,EAAE,QAAQ,eAAe,KAAG,OAAO,CAAC,IAAI,CAyD9F,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { writeFile } from 'node:fs/promises';
|
|
6
|
+
import { loadConfigOrDefaults } from '../config.js';
|
|
7
|
+
import { scanProject } from '../discovery.js';
|
|
8
|
+
import { stringFlag } from '../flags.js';
|
|
9
|
+
/** Run the merge command. */
|
|
10
|
+
export const runMerge = async (options, parsed) => {
|
|
11
|
+
const config = await loadConfigOrDefaults(options);
|
|
12
|
+
const targetPath = parsed.positionals[0] ? resolve(options.cwd, parsed.positionals[0]) : options.cwd;
|
|
13
|
+
const outputPath = stringFlag(parsed.flags, 'output');
|
|
14
|
+
const result = await scanProject(config);
|
|
15
|
+
const relevantFiles = result.xdocsFiles.filter((f) => f.path.startsWith(targetPath));
|
|
16
|
+
if (relevantFiles.length === 0) {
|
|
17
|
+
process.stdout.write('No xdocs files found in the specified path.\n');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const lines = [];
|
|
21
|
+
for (const file of relevantFiles) {
|
|
22
|
+
lines.push(`<!-- source: ${file.relativePath} -->`);
|
|
23
|
+
if (file.metadata) {
|
|
24
|
+
lines.push(`# ${file.metadata.subject}`, '');
|
|
25
|
+
lines.push(file.metadata.description, '');
|
|
26
|
+
const fileEntries = Object.entries(file.metadata.files);
|
|
27
|
+
if (fileEntries.length > 0) {
|
|
28
|
+
lines.push('## Files', '');
|
|
29
|
+
for (const [name, desc] of fileEntries) {
|
|
30
|
+
lines.push(`- \`${name}\`: ${desc}`);
|
|
31
|
+
}
|
|
32
|
+
lines.push('');
|
|
33
|
+
}
|
|
34
|
+
if (file.metadata.children.length > 0) {
|
|
35
|
+
lines.push('## Submodules', '');
|
|
36
|
+
for (const child of file.metadata.children) {
|
|
37
|
+
lines.push(`- ${child}`);
|
|
38
|
+
}
|
|
39
|
+
lines.push('');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (file.body.trim()) {
|
|
43
|
+
lines.push(file.body.trim(), '');
|
|
44
|
+
}
|
|
45
|
+
lines.push('---', '');
|
|
46
|
+
}
|
|
47
|
+
const content = lines.join('\n');
|
|
48
|
+
if (outputPath) {
|
|
49
|
+
await writeFile(resolve(options.cwd, outputPath), content, 'utf8');
|
|
50
|
+
process.stdout.write(`merged: ${outputPath} (${relevantFiles.length} files)\n`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
process.stdout.write(content);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the prompt command. */
|
|
6
|
+
export declare const runPrompt: (_options: XDocsCliOptions, parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../source/commands/prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKnE,8BAA8B;AAC9B,eAAO,MAAM,SAAS,GAAU,UAAU,eAAe,EAAE,QAAQ,eAAe,KAAG,OAAO,CAAC,IAAI,CAehG,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { XDocsError } from '../errors.js';
|
|
5
|
+
import { stringFlag } from '../flags.js';
|
|
6
|
+
import { getPrompt, getPromptNames } from '../prompts.js';
|
|
7
|
+
/** Run the prompt command. */
|
|
8
|
+
export const runPrompt = async (_options, parsed) => {
|
|
9
|
+
const name = stringFlag(parsed.flags, 'name');
|
|
10
|
+
const available = getPromptNames().join(', ');
|
|
11
|
+
if (!name) {
|
|
12
|
+
throw new XDocsError(`Missing --name flag. Usage: xdocs prompt --name=write\n\nAvailable prompts: ${available}`);
|
|
13
|
+
}
|
|
14
|
+
const prompt = getPrompt(name);
|
|
15
|
+
if (!prompt) {
|
|
16
|
+
throw new XDocsError(`Unknown prompt name: "${name}"\n\nAvailable prompts: ${available}`);
|
|
17
|
+
}
|
|
18
|
+
process.stdout.write(prompt.body + '\n');
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the scan command. */
|
|
6
|
+
export declare const runScan: (options: XDocsCliOptions, _parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../source/commands/scan.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAInE,4BAA4B;AAC5B,eAAO,MAAM,OAAO,GAAU,SAAS,eAAe,EAAE,SAAS,eAAe,KAAG,OAAO,CAAC,IAAI,CAoD9F,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { loadConfigOrDefaults } from '../config.js';
|
|
5
|
+
import { scanProject } from '../discovery.js';
|
|
6
|
+
/** Run the scan command. */
|
|
7
|
+
export const runScan = async (options, _parsed) => {
|
|
8
|
+
const config = await loadConfigOrDefaults(options);
|
|
9
|
+
const result = await scanProject(config);
|
|
10
|
+
if (options.format === 'json') {
|
|
11
|
+
process.stdout.write(JSON.stringify({
|
|
12
|
+
totalFiles: result.totalFiles,
|
|
13
|
+
totalDirectories: result.totalDirectories,
|
|
14
|
+
coveredDirectories: result.coveredDirectories,
|
|
15
|
+
uncoveredDirectories: result.uncoveredDirectories,
|
|
16
|
+
xdocsFiles: result.xdocsFiles.map((f) => ({
|
|
17
|
+
path: f.relativePath,
|
|
18
|
+
valid: f.valid,
|
|
19
|
+
subject: f.metadata?.subject ?? null,
|
|
20
|
+
errors: f.errors,
|
|
21
|
+
})),
|
|
22
|
+
uncoveredPaths: result.uncoveredPaths,
|
|
23
|
+
}, null, 2) + '\n');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
process.stdout.write(`\nxdocs scan\n\n`);
|
|
27
|
+
process.stdout.write(`extensions: ${config.extensions.supported.join(', ')}\n`);
|
|
28
|
+
process.stdout.write(`total files scanned: ${result.totalFiles}\n`);
|
|
29
|
+
process.stdout.write(`total directories: ${result.totalDirectories}\n`);
|
|
30
|
+
process.stdout.write(`covered directories: ${result.coveredDirectories}\n`);
|
|
31
|
+
process.stdout.write(`uncovered directories: ${result.uncoveredDirectories}\n`);
|
|
32
|
+
process.stdout.write(`xdocs files found: ${result.xdocsFiles.length}\n`);
|
|
33
|
+
if (result.xdocsFiles.length > 0) {
|
|
34
|
+
process.stdout.write(`\nfiles:\n`);
|
|
35
|
+
for (const file of result.xdocsFiles) {
|
|
36
|
+
const status = file.valid ? 'valid' : 'incomplete';
|
|
37
|
+
const subject = file.metadata?.subject ? ` (${file.metadata.subject})` : '';
|
|
38
|
+
process.stdout.write(` ${file.relativePath} [${status}]${subject}\n`);
|
|
39
|
+
if (options.verbose && file.errors.length > 0) {
|
|
40
|
+
for (const error of file.errors) {
|
|
41
|
+
process.stdout.write(` error: ${error}\n`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (options.verbose && result.uncoveredPaths.length > 0) {
|
|
47
|
+
process.stdout.write(`\nuncovered directories:\n`);
|
|
48
|
+
for (const uncovered of result.uncoveredPaths) {
|
|
49
|
+
process.stdout.write(` ${uncovered}\n`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
process.stdout.write('\n');
|
|
53
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { XDocsCliOptions, XDocsParsedArgs } from '../types.js';
|
|
5
|
+
/** Run the tree command. */
|
|
6
|
+
export declare const runTree: (options: XDocsCliOptions, parsed: XDocsParsedArgs) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../source/commands/tree.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAMnE,4BAA4B;AAC5B,eAAO,MAAM,OAAO,GAAU,SAAS,eAAe,EAAE,QAAQ,eAAe,KAAG,OAAO,CAAC,IAAI,CA0C7F,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Copyright (c) 2026 GUIHO Technologies as represented by Cristóvão GUIHO. All Rights Reserved.
|
|
3
|
+
*/
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { writeFile } from 'node:fs/promises';
|
|
6
|
+
import { loadConfigOrDefaults } from '../config.js';
|
|
7
|
+
import { scanProject } from '../discovery.js';
|
|
8
|
+
import { buildTree, validateTree, renderTree, renderTreeMarkdown } from '../tree.js';
|
|
9
|
+
import { stringFlag } from '../flags.js';
|
|
10
|
+
/** Run the tree command. */
|
|
11
|
+
export const runTree = async (options, parsed) => {
|
|
12
|
+
const config = await loadConfigOrDefaults(options);
|
|
13
|
+
const outputPath = stringFlag(parsed.flags, 'output');
|
|
14
|
+
const result = await scanProject(config);
|
|
15
|
+
const tree = buildTree(result.xdocsFiles);
|
|
16
|
+
// Validate tree integrity
|
|
17
|
+
if (options.verbose) {
|
|
18
|
+
const validation = validateTree(result.xdocsFiles);
|
|
19
|
+
if (validation.warnings.length > 0) {
|
|
20
|
+
process.stderr.write('\nwarnings:\n');
|
|
21
|
+
for (const warning of validation.warnings) {
|
|
22
|
+
process.stderr.write(` ${warning}\n`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (validation.errors.length > 0) {
|
|
26
|
+
process.stderr.write('\nerrors:\n');
|
|
27
|
+
for (const error of validation.errors) {
|
|
28
|
+
process.stderr.write(` ${error}\n`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
let content;
|
|
33
|
+
if (options.format === 'markdown') {
|
|
34
|
+
content = `# Project Hierarchy\n\n${renderTreeMarkdown(tree)}\n`;
|
|
35
|
+
}
|
|
36
|
+
else if (options.format === 'json') {
|
|
37
|
+
content = JSON.stringify(tree, null, 2) + '\n';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
content = renderTree(tree) + '\n';
|
|
41
|
+
}
|
|
42
|
+
if (outputPath) {
|
|
43
|
+
await writeFile(resolve(options.cwd, outputPath), content, 'utf8');
|
|
44
|
+
process.stdout.write(`tree: ${outputPath}\n`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
process.stdout.write(content);
|
|
48
|
+
}
|
|
49
|
+
};
|