@aigne/doc-smith 0.9.8-alpha.2 → 0.9.8-alpha.4
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/CLAUDE.md +43 -0
- package/README.md +94 -250
- package/aigne.yaml +2 -149
- package/doc-smith/SKILL.md +117 -0
- package/doc-smith/references/changeset_schema.md +118 -0
- package/doc-smith/references/document_structure_schema.md +139 -0
- package/doc-smith/references/document_update_guide.md +193 -0
- package/doc-smith/references/structure_confirmation_guide.md +133 -0
- package/doc-smith/references/structure_planning_guide.md +146 -0
- package/doc-smith/references/user_intent_guide.md +172 -0
- package/doc-smith.yaml +114 -0
- package/main-system-prompt.md +56 -0
- package/package.json +3 -69
- package/scripts/README.md +90 -0
- package/scripts/install.sh +86 -0
- package/scripts/uninstall.sh +52 -0
- package/CHANGELOG.md +0 -994
- package/LICENSE +0 -93
- package/agentic-agents/common/base-info.md +0 -53
- package/agentic-agents/common/planner.md +0 -168
- package/agentic-agents/common/worker.md +0 -93
- package/agentic-agents/create/index.yaml +0 -118
- package/agentic-agents/create/objective.md +0 -44
- package/agentic-agents/create/set-custom-prompt.mjs +0 -27
- package/agentic-agents/detail/index.yaml +0 -95
- package/agentic-agents/detail/objective.md +0 -9
- package/agentic-agents/detail/set-custom-prompt.mjs +0 -88
- package/agentic-agents/predict-resources/index.yaml +0 -44
- package/agentic-agents/predict-resources/instructions.md +0 -61
- package/agentic-agents/structure/design-rules.md +0 -39
- package/agentic-agents/structure/index.yaml +0 -86
- package/agentic-agents/structure/objective.md +0 -14
- package/agentic-agents/structure/review-criteria.md +0 -55
- package/agentic-agents/structure/set-custom-prompt.mjs +0 -78
- package/agentic-agents/utils/init-workspace-cache.mjs +0 -171
- package/agentic-agents/utils/load-base-sources.mjs +0 -20
- package/agentic-agents/workspace-cache-sharing-design.md +0 -671
- package/agents/chat/chat-system.md +0 -38
- package/agents/chat/index.mjs +0 -59
- package/agents/chat/skills/generate-document.yaml +0 -15
- package/agents/chat/skills/list-documents.mjs +0 -15
- package/agents/chat/skills/update-document.yaml +0 -24
- package/agents/clear/choose-contents.mjs +0 -192
- package/agents/clear/clear-auth-tokens.mjs +0 -88
- package/agents/clear/clear-deployment-config.mjs +0 -49
- package/agents/clear/clear-document-config.mjs +0 -36
- package/agents/clear/clear-document-structure.mjs +0 -102
- package/agents/clear/clear-generated-docs.mjs +0 -142
- package/agents/clear/clear-media-description.mjs +0 -129
- package/agents/clear/index.yaml +0 -26
- package/agents/create/analyze-diagram-type-llm.yaml +0 -160
- package/agents/create/analyze-diagram-type.mjs +0 -297
- package/agents/create/check-document-structure.yaml +0 -30
- package/agents/create/check-need-generate-structure.mjs +0 -105
- package/agents/create/document-structure-tools/add-document.mjs +0 -85
- package/agents/create/document-structure-tools/delete-document.mjs +0 -116
- package/agents/create/document-structure-tools/move-document.mjs +0 -109
- package/agents/create/document-structure-tools/update-document.mjs +0 -84
- package/agents/create/generate-diagram-image.yaml +0 -60
- package/agents/create/generate-structure.yaml +0 -117
- package/agents/create/index.yaml +0 -49
- package/agents/create/refine-document-structure.yaml +0 -12
- package/agents/create/replace-d2-with-image.mjs +0 -625
- package/agents/create/update-document-structure.yaml +0 -54
- package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
- package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
- package/agents/create/user-add-document/index.yaml +0 -46
- package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
- package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
- package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
- package/agents/create/user-remove-document/index.yaml +0 -40
- package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
- package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
- package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
- package/agents/create/user-review-document-structure.mjs +0 -140
- package/agents/create/utils/init-current-content.mjs +0 -34
- package/agents/create/utils/merge-document-structures.mjs +0 -30
- package/agents/evaluate/code-snippet.mjs +0 -97
- package/agents/evaluate/document-structure.yaml +0 -67
- package/agents/evaluate/document.yaml +0 -82
- package/agents/evaluate/generate-report.mjs +0 -85
- package/agents/evaluate/index.yaml +0 -46
- package/agents/history/index.yaml +0 -6
- package/agents/history/view.mjs +0 -78
- package/agents/init/check.mjs +0 -16
- package/agents/init/index.mjs +0 -275
- package/agents/init/validate.mjs +0 -16
- package/agents/localize/choose-language.mjs +0 -107
- package/agents/localize/index.yaml +0 -58
- package/agents/localize/record-translation-history.mjs +0 -23
- package/agents/localize/translate-document.yaml +0 -24
- package/agents/localize/translate-multilingual.yaml +0 -51
- package/agents/media/batch-generate-media-description.yaml +0 -46
- package/agents/media/generate-media-description.yaml +0 -50
- package/agents/media/load-media-description.mjs +0 -256
- package/agents/prefs/index.mjs +0 -203
- package/agents/publish/index.yaml +0 -26
- package/agents/publish/publish-docs.mjs +0 -356
- package/agents/publish/translate-meta.mjs +0 -103
- package/agents/schema/document-structure-item.yaml +0 -26
- package/agents/schema/document-structure-refine-item.yaml +0 -23
- package/agents/schema/document-structure.yaml +0 -29
- package/agents/update/batch-generate-document.yaml +0 -27
- package/agents/update/batch-update-document.yaml +0 -7
- package/agents/update/check-diagram-flag.mjs +0 -116
- package/agents/update/check-document.mjs +0 -162
- package/agents/update/check-generate-diagram.mjs +0 -106
- package/agents/update/check-sync-image-flag.mjs +0 -55
- package/agents/update/check-update-is-single.mjs +0 -53
- package/agents/update/document-tools/update-document-content.mjs +0 -303
- package/agents/update/generate-diagram.yaml +0 -63
- package/agents/update/generate-document.yaml +0 -70
- package/agents/update/handle-document-update.yaml +0 -103
- package/agents/update/index.yaml +0 -79
- package/agents/update/pre-check-generate-diagram.yaml +0 -44
- package/agents/update/save-and-translate-document.mjs +0 -76
- package/agents/update/sync-images-and-exit.mjs +0 -148
- package/agents/update/update-document-detail.yaml +0 -71
- package/agents/update/update-single/update-single-document-detail.mjs +0 -280
- package/agents/update/update-single-document.yaml +0 -7
- package/agents/update/user-review-document.mjs +0 -272
- package/agents/utils/action-success.mjs +0 -16
- package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
- package/agents/utils/analyze-feedback-intent.mjs +0 -136
- package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
- package/agents/utils/check-detail-result.mjs +0 -38
- package/agents/utils/check-feedback-refiner.mjs +0 -81
- package/agents/utils/choose-docs.mjs +0 -293
- package/agents/utils/document-icon-generate.yaml +0 -52
- package/agents/utils/document-title-streamline.yaml +0 -48
- package/agents/utils/ensure-document-icons.mjs +0 -129
- package/agents/utils/exit.mjs +0 -6
- package/agents/utils/feedback-refiner.yaml +0 -50
- package/agents/utils/find-item-by-path.mjs +0 -114
- package/agents/utils/find-user-preferences-by-path.mjs +0 -37
- package/agents/utils/format-document-structure.mjs +0 -35
- package/agents/utils/generate-document-or-skip.mjs +0 -41
- package/agents/utils/handle-diagram-operations.mjs +0 -263
- package/agents/utils/load-all-document-content.mjs +0 -30
- package/agents/utils/load-document-all-content.mjs +0 -84
- package/agents/utils/load-sources.mjs +0 -405
- package/agents/utils/map-reasoning-effort-level.mjs +0 -15
- package/agents/utils/post-generate.mjs +0 -144
- package/agents/utils/read-current-document-content.mjs +0 -46
- package/agents/utils/save-doc-translation.mjs +0 -61
- package/agents/utils/save-doc.mjs +0 -88
- package/agents/utils/save-output.mjs +0 -26
- package/agents/utils/save-sidebar.mjs +0 -51
- package/agents/utils/skip-if-content-exists.mjs +0 -27
- package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
- package/agents/utils/transform-detail-data-sources.mjs +0 -45
- package/agents/utils/update-branding.mjs +0 -84
- package/assets/report-template/report.html +0 -198
- package/docs-mcp/analyze-content-relevance.yaml +0 -50
- package/docs-mcp/analyze-docs-relevance.yaml +0 -59
- package/docs-mcp/docs-search.yaml +0 -42
- package/docs-mcp/get-docs-detail.mjs +0 -41
- package/docs-mcp/get-docs-structure.mjs +0 -16
- package/docs-mcp/read-doc-content.mjs +0 -119
- package/prompts/common/document/content-rules-core.md +0 -20
- package/prompts/common/document/markdown-syntax-rules.md +0 -65
- package/prompts/common/document/media-file-list-usage-rules.md +0 -18
- package/prompts/common/document/openapi-usage-rules.md +0 -189
- package/prompts/common/document/role-and-personality.md +0 -16
- package/prompts/common/document/user-preferences.md +0 -9
- package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
- package/prompts/common/document-structure/document-icon-generate.md +0 -116
- package/prompts/common/document-structure/document-structure-rules.md +0 -43
- package/prompts/common/document-structure/document-title-streamline.md +0 -86
- package/prompts/common/document-structure/glossary.md +0 -7
- package/prompts/common/document-structure/intj-traits.md +0 -5
- package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
- package/prompts/common/document-structure/output-constraints.md +0 -18
- package/prompts/common/document-structure/user-locale-rules.md +0 -10
- package/prompts/common/document-structure/user-preferences.md +0 -9
- package/prompts/detail/custom/admonition-usage-rules.md +0 -94
- package/prompts/detail/custom/code-block-usage-rules.md +0 -163
- package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
- package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
- package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
- package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
- package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
- package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
- package/prompts/detail/diagram/generate-image-system.md +0 -135
- package/prompts/detail/diagram/generate-image-user.md +0 -32
- package/prompts/detail/diagram/guide.md +0 -29
- package/prompts/detail/diagram/official-examples.md +0 -712
- package/prompts/detail/diagram/pre-check.md +0 -23
- package/prompts/detail/diagram/role-and-personality.md +0 -2
- package/prompts/detail/diagram/rules.md +0 -46
- package/prompts/detail/diagram/system-prompt.md +0 -1139
- package/prompts/detail/diagram/user-prompt.md +0 -43
- package/prompts/detail/generate/detail-example.md +0 -457
- package/prompts/detail/generate/document-rules.md +0 -45
- package/prompts/detail/generate/system-prompt.md +0 -61
- package/prompts/detail/generate/user-prompt.md +0 -99
- package/prompts/detail/jsx/rules.md +0 -6
- package/prompts/detail/update/system-prompt.md +0 -121
- package/prompts/detail/update/user-prompt.md +0 -41
- package/prompts/evaluate/document-structure.md +0 -93
- package/prompts/evaluate/document.md +0 -149
- package/prompts/media/media-description/system-prompt.md +0 -43
- package/prompts/media/media-description/user-prompt.md +0 -17
- package/prompts/structure/check-document-structure.md +0 -93
- package/prompts/structure/document-rules.md +0 -21
- package/prompts/structure/find-documents-to-add-links.md +0 -52
- package/prompts/structure/generate/system-prompt.md +0 -13
- package/prompts/structure/generate/user-prompt.md +0 -137
- package/prompts/structure/review/structure-review-system.md +0 -81
- package/prompts/structure/structure-example.md +0 -89
- package/prompts/structure/structure-getting-started.md +0 -10
- package/prompts/structure/update/system-prompt.md +0 -93
- package/prompts/structure/update/user-prompt.md +0 -43
- package/prompts/translate/admonition.md +0 -20
- package/prompts/translate/code-block.md +0 -33
- package/prompts/translate/glossary.md +0 -6
- package/prompts/translate/translate-document.md +0 -305
- package/prompts/utils/analyze-document-feedback-intent.md +0 -54
- package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
- package/prompts/utils/feedback-refiner.md +0 -105
- package/types/document-schema.mjs +0 -55
- package/types/document-structure-schema.mjs +0 -261
- package/utils/auth-utils.mjs +0 -275
- package/utils/blocklet.mjs +0 -104
- package/utils/check-document-has-diagram.mjs +0 -95
- package/utils/conflict-detector.mjs +0 -149
- package/utils/constants/index.mjs +0 -620
- package/utils/constants/linter.mjs +0 -102
- package/utils/d2-utils.mjs +0 -198
- package/utils/debug.mjs +0 -3
- package/utils/delete-diagram-images.mjs +0 -99
- package/utils/deploy.mjs +0 -86
- package/utils/docs-finder-utils.mjs +0 -623
- package/utils/evaluate/report-utils.mjs +0 -132
- package/utils/extract-api.mjs +0 -32
- package/utils/file-utils.mjs +0 -960
- package/utils/history-utils.mjs +0 -203
- package/utils/icon-map.mjs +0 -26
- package/utils/image-compress.mjs +0 -75
- package/utils/kroki-utils.mjs +0 -173
- package/utils/linter/index.mjs +0 -50
- package/utils/load-config.mjs +0 -107
- package/utils/markdown/index.mjs +0 -26
- package/utils/markdown-checker.mjs +0 -694
- package/utils/mermaid-validator.mjs +0 -140
- package/utils/mermaid-worker-pool.mjs +0 -250
- package/utils/mermaid-worker.mjs +0 -233
- package/utils/openapi/index.mjs +0 -28
- package/utils/preferences-utils.mjs +0 -175
- package/utils/request.mjs +0 -10
- package/utils/store/index.mjs +0 -45
- package/utils/sync-diagram-to-translations.mjs +0 -262
- package/utils/upload-files.mjs +0 -231
- package/utils/utils.mjs +0 -1354
package/utils/image-compress.mjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import sharp from "sharp";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { debug } from "./debug.mjs";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Compress an image using sharp
|
|
7
|
-
* Supports JPEG, PNG, and WebP formats
|
|
8
|
-
* @param {string} inputPath - Path to the input image file
|
|
9
|
-
* @param {object} options - Compression options
|
|
10
|
-
* @param {number} options.quality - Compression quality (0-100, default: 80)
|
|
11
|
-
* @param {string} options.outputFormat - Output format: 'jpeg', 'png', 'webp' (default: auto-detect from input)
|
|
12
|
-
* @param {string} options.outputPath - Output path for compressed image (if not provided, creates temp file)
|
|
13
|
-
* @returns {Promise<string>} - Path to the compressed image (outputPath if provided, or temp path, or inputPath if compression fails)
|
|
14
|
-
*/
|
|
15
|
-
export async function compressImage(inputPath, options = {}) {
|
|
16
|
-
const { quality = 80, outputFormat, outputPath } = options;
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const inputExt = path.extname(inputPath).toLowerCase();
|
|
20
|
-
|
|
21
|
-
// Determine output format
|
|
22
|
-
let format = outputFormat;
|
|
23
|
-
if (!format) {
|
|
24
|
-
// Auto-detect from input extension
|
|
25
|
-
if (inputExt === ".jpg" || inputExt === ".jpeg") {
|
|
26
|
-
format = "jpeg";
|
|
27
|
-
} else if (inputExt === ".png") {
|
|
28
|
-
format = "png";
|
|
29
|
-
} else if (inputExt === ".webp") {
|
|
30
|
-
format = "webp";
|
|
31
|
-
} else {
|
|
32
|
-
// Default to JPEG for unknown formats
|
|
33
|
-
format = "jpeg";
|
|
34
|
-
debug(`Unknown image format ${inputExt}, defaulting to JPEG`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Determine output path
|
|
39
|
-
let finalOutputPath = outputPath;
|
|
40
|
-
if (!finalOutputPath) {
|
|
41
|
-
// If no output path provided, create temp file in same directory as input
|
|
42
|
-
const outputExt = format === "jpeg" ? ".jpg" : format === "png" ? ".png" : ".webp";
|
|
43
|
-
const inputDir = path.dirname(inputPath);
|
|
44
|
-
const inputBase = path.basename(inputPath, path.extname(inputPath));
|
|
45
|
-
finalOutputPath = path.join(inputDir, `${inputBase}.compressed${outputExt}`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Create sharp instance and compress
|
|
49
|
-
let sharpInstance = sharp(inputPath);
|
|
50
|
-
|
|
51
|
-
// Apply format-specific compression options
|
|
52
|
-
if (format === "jpeg") {
|
|
53
|
-
// mozjpeg is a valid sharp option for better JPEG compression
|
|
54
|
-
const jpegOptions = { quality, mozjpeg: true };
|
|
55
|
-
sharpInstance = sharpInstance.jpeg(jpegOptions);
|
|
56
|
-
} else if (format === "png") {
|
|
57
|
-
sharpInstance = sharpInstance.png({ quality, compressionLevel: 9 });
|
|
58
|
-
} else if (format === "webp") {
|
|
59
|
-
sharpInstance = sharpInstance.webp({ quality });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Write compressed image directly to output path
|
|
63
|
-
await sharpInstance.toFile(finalOutputPath);
|
|
64
|
-
|
|
65
|
-
debug(
|
|
66
|
-
`✅ Image compressed: ${inputPath} -> ${finalOutputPath} (format: ${format}, quality: ${quality})`,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
return finalOutputPath;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
debug(`⚠️ Failed to compress image ${inputPath}: ${error.message}`);
|
|
72
|
-
// Return original path if compression fails
|
|
73
|
-
return inputPath;
|
|
74
|
-
}
|
|
75
|
-
}
|
package/utils/kroki-utils.mjs
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
import Debug from "debug";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
|
-
import { glob } from "glob";
|
|
6
|
-
import pMap from "p-map";
|
|
7
|
-
import { joinURL } from "ufo";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
D2_CONFIG,
|
|
11
|
-
DOC_SMITH_DIR,
|
|
12
|
-
FILE_CONCURRENCY,
|
|
13
|
-
KROKI_CONCURRENCY,
|
|
14
|
-
TMP_ASSETS_DIR,
|
|
15
|
-
TMP_DIR,
|
|
16
|
-
} from "./constants/index.mjs";
|
|
17
|
-
import { getContentHash } from "./utils.mjs";
|
|
18
|
-
import { d2CodeBlockRegex } from "./d2-utils.mjs";
|
|
19
|
-
|
|
20
|
-
const debug = Debug("doc-smith");
|
|
21
|
-
|
|
22
|
-
export async function getChart({ chart = "d2", format = "svg", content, strict }) {
|
|
23
|
-
const baseUrl = "https://chart.abtnet.io";
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const res = await fetch(joinURL(baseUrl, chart, format), {
|
|
27
|
-
method: "POST",
|
|
28
|
-
body: content,
|
|
29
|
-
headers: {
|
|
30
|
-
Accept: "image/svg+xml",
|
|
31
|
-
"Content-Type": "text/plain",
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
if (strict && !res.ok) {
|
|
35
|
-
throw new Error(`Could not fetch the chart: ${res.status} ${res.statusText}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const data = await res.text();
|
|
39
|
-
return data;
|
|
40
|
-
} catch (err) {
|
|
41
|
-
if (strict) throw err;
|
|
42
|
-
|
|
43
|
-
console.error(`Could not generate the chart from: ${baseUrl}`, err);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function getD2Svg({ content, strict = false }) {
|
|
49
|
-
const svgContent = await getChart({
|
|
50
|
-
chart: "d2",
|
|
51
|
-
format: "svg",
|
|
52
|
-
content,
|
|
53
|
-
strict,
|
|
54
|
-
});
|
|
55
|
-
return svgContent;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function saveD2Assets({ markdown, docsDir }) {
|
|
59
|
-
if (!markdown) {
|
|
60
|
-
return markdown;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const { replaced } = await runIterator({
|
|
64
|
-
input: markdown,
|
|
65
|
-
regexp: d2CodeBlockRegex,
|
|
66
|
-
replace: true,
|
|
67
|
-
fn: async ([_match, _code]) => {
|
|
68
|
-
const assetDir = path.join(docsDir, "../", TMP_ASSETS_DIR, "d2");
|
|
69
|
-
await fs.ensureDir(assetDir);
|
|
70
|
-
const d2Content = [D2_CONFIG, _code].join("\n");
|
|
71
|
-
const fileName = `${getContentHash(d2Content)}.svg`;
|
|
72
|
-
const svgPath = path.join(assetDir, fileName);
|
|
73
|
-
|
|
74
|
-
if (await fs.pathExists(svgPath)) {
|
|
75
|
-
debug("Asset cache found, skipping generation", svgPath);
|
|
76
|
-
} else {
|
|
77
|
-
try {
|
|
78
|
-
debug("Generating d2 diagram", svgPath);
|
|
79
|
-
if (debug.enabled) {
|
|
80
|
-
const d2FileName = `${getContentHash(d2Content)}.d2`;
|
|
81
|
-
const d2Path = path.join(assetDir, d2FileName);
|
|
82
|
-
await fs.writeFile(d2Path, d2Content, { encoding: "utf8" });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const svg = await getD2Svg({ content: d2Content });
|
|
86
|
-
if (svg) {
|
|
87
|
-
await fs.writeFile(svgPath, svg, { encoding: "utf8" });
|
|
88
|
-
}
|
|
89
|
-
} catch (error) {
|
|
90
|
-
debug("Could not generate the D2 diagram:", error);
|
|
91
|
-
return _code;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return `})`;
|
|
95
|
-
},
|
|
96
|
-
options: { concurrency: KROKI_CONCURRENCY },
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return replaced;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export async function beforePublishHook({ docsDir }) {
|
|
103
|
-
// Process each markdown file to save the d2 svg assets.
|
|
104
|
-
const mdFilePaths = await glob("**/*.md", { cwd: docsDir });
|
|
105
|
-
await pMap(
|
|
106
|
-
mdFilePaths,
|
|
107
|
-
async (filePath) => {
|
|
108
|
-
let finalContent = await fs.readFile(path.join(docsDir, filePath), { encoding: "utf8" });
|
|
109
|
-
finalContent = await saveD2Assets({ markdown: finalContent, docsDir });
|
|
110
|
-
|
|
111
|
-
await fs.writeFile(path.join(docsDir, filePath), finalContent, { encoding: "utf8" });
|
|
112
|
-
},
|
|
113
|
-
{ concurrency: FILE_CONCURRENCY },
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function runIterator({ input, regexp, fn = () => {}, options, replace = false }) {
|
|
118
|
-
if (!input) return input;
|
|
119
|
-
const matches = [...input.matchAll(regexp)];
|
|
120
|
-
const results = [];
|
|
121
|
-
await pMap(
|
|
122
|
-
matches,
|
|
123
|
-
async (...args) => {
|
|
124
|
-
const resultItem = await fn(...args);
|
|
125
|
-
results.push(resultItem);
|
|
126
|
-
},
|
|
127
|
-
options,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
let replaced = input;
|
|
131
|
-
if (replace) {
|
|
132
|
-
let index = 0;
|
|
133
|
-
replaced = replaced.replace(regexp, () => {
|
|
134
|
-
return results[index++];
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
results,
|
|
140
|
-
replaced,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export async function checkD2Content({ content }) {
|
|
145
|
-
await ensureTmpDir();
|
|
146
|
-
const assetDir = path.join(DOC_SMITH_DIR, TMP_DIR, TMP_ASSETS_DIR, "d2");
|
|
147
|
-
await fs.ensureDir(assetDir);
|
|
148
|
-
const d2Content = [D2_CONFIG, content].join("\n");
|
|
149
|
-
const fileName = `${getContentHash(d2Content)}.svg`;
|
|
150
|
-
const svgPath = path.join(assetDir, fileName);
|
|
151
|
-
|
|
152
|
-
if (debug.enabled) {
|
|
153
|
-
const d2FileName = `${getContentHash(d2Content)}.d2`;
|
|
154
|
-
const d2Path = path.join(assetDir, d2FileName);
|
|
155
|
-
await fs.writeFile(d2Path, d2Content, { encoding: "utf8" });
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (await fs.pathExists(svgPath)) {
|
|
159
|
-
debug("Asset cache found, skipping generation", svgPath);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const svg = await getD2Svg({ content: d2Content, strict: true });
|
|
164
|
-
await fs.writeFile(svgPath, svg, { encoding: "utf8" });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export async function ensureTmpDir() {
|
|
168
|
-
const tmpDir = path.join(DOC_SMITH_DIR, TMP_DIR);
|
|
169
|
-
if (!(await fs.pathExists(path.join(tmpDir, ".gitignore")))) {
|
|
170
|
-
await fs.ensureDir(tmpDir);
|
|
171
|
-
await fs.writeFile(path.join(tmpDir, ".gitignore"), "**/*", { encoding: "utf8" });
|
|
172
|
-
}
|
|
173
|
-
}
|
package/utils/linter/index.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { LINTER_API_URL } from "../constants/linter.mjs";
|
|
2
|
-
|
|
3
|
-
export async function lintCode({ code, linter = "biome-lint", suffix = ".js" }) {
|
|
4
|
-
if (!code) {
|
|
5
|
-
throw new Error("Code parameter is required");
|
|
6
|
-
}
|
|
7
|
-
const timeout = 30 * 1000;
|
|
8
|
-
let filename = `code${suffix}`;
|
|
9
|
-
if (suffix === ".dockerfile") {
|
|
10
|
-
filename = "Dockerfile";
|
|
11
|
-
}
|
|
12
|
-
const testData = {
|
|
13
|
-
filename,
|
|
14
|
-
content: code,
|
|
15
|
-
options: {
|
|
16
|
-
validate_all: true,
|
|
17
|
-
fix: false,
|
|
18
|
-
log_level: "INFO",
|
|
19
|
-
timeout,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
try {
|
|
23
|
-
const controller = new AbortController();
|
|
24
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
25
|
-
|
|
26
|
-
const response = await fetch(`${LINTER_API_URL}/${linter}/json`, {
|
|
27
|
-
method: "POST",
|
|
28
|
-
headers: {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
},
|
|
31
|
-
body: JSON.stringify(testData),
|
|
32
|
-
signal: controller.signal,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
clearTimeout(timeoutId);
|
|
36
|
-
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const data = await response.json();
|
|
42
|
-
if (!data) {
|
|
43
|
-
throw new Error("Invalid response data");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return data;
|
|
47
|
-
} catch (error) {
|
|
48
|
-
throw new Error(`Linting failed: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
package/utils/load-config.mjs
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { parse } from "yaml";
|
|
5
|
-
import { processConfigFields, resolveFileReferences } from "./utils.mjs";
|
|
6
|
-
import { DEFAULT_EXCLUDE_PATTERNS } from "./constants/index.mjs";
|
|
7
|
-
import { findInvalidSourcePaths, toDisplayPath } from "./file-utils.mjs";
|
|
8
|
-
|
|
9
|
-
export default async function loadConfig({ config, appUrl }) {
|
|
10
|
-
const configPath = path.isAbsolute(config) ? config : path.join(process.cwd(), config);
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
// Check if config file exists
|
|
14
|
-
await fs.access(configPath);
|
|
15
|
-
} catch (_error) {
|
|
16
|
-
console.log(`The config file was not found at: ${configPath}`);
|
|
17
|
-
console.log("You can run 'aigne doc init' to create a new config file.");
|
|
18
|
-
throw new Error(`The config file was not found at: ${configPath}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// Read and parse YAML file
|
|
23
|
-
const configContent = await fs.readFile(configPath, "utf-8");
|
|
24
|
-
let parsedConfig = parse(configContent);
|
|
25
|
-
|
|
26
|
-
// Resolve file references (@ prefixed values)
|
|
27
|
-
parsedConfig = await resolveFileReferences(parsedConfig);
|
|
28
|
-
|
|
29
|
-
// Read DOC-SMITH.md if exists in current working directory
|
|
30
|
-
const docSmithVariants = ["DOC-SMITH.md", "doc-smith.md", "DocSmith.md"];
|
|
31
|
-
let docSmithContent = "";
|
|
32
|
-
for (const variant of docSmithVariants) {
|
|
33
|
-
const docSmithPath = path.join(process.cwd(), variant);
|
|
34
|
-
try {
|
|
35
|
-
const content = await fs.readFile(docSmithPath, "utf-8");
|
|
36
|
-
if (content && content.trim()) {
|
|
37
|
-
docSmithContent = content.trim();
|
|
38
|
-
console.log(`✓ Found ${chalk.cyan(variant)}, custom rules loaded`);
|
|
39
|
-
break; // Use the first found file
|
|
40
|
-
}
|
|
41
|
-
} catch (error) {
|
|
42
|
-
if (error.code !== "ENOENT") {
|
|
43
|
-
// File exists but can't be read (permission issue, etc.)
|
|
44
|
-
console.warn(`⚠️ Found ${variant} but failed to read: ${error.message}`);
|
|
45
|
-
}
|
|
46
|
-
// ENOENT means file doesn't exist, continue to next variant
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Append DOC-SMITH content to rules if found
|
|
51
|
-
if (docSmithContent) {
|
|
52
|
-
const existingRules = parsedConfig.rules || "";
|
|
53
|
-
parsedConfig.rules = existingRules
|
|
54
|
-
? `${existingRules}\n\n${docSmithContent}`
|
|
55
|
-
: docSmithContent;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (appUrl) {
|
|
59
|
-
parsedConfig.appUrl = appUrl.includes("://") ? appUrl : `https://${appUrl}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Parse new configuration fields and convert keys to actual content
|
|
63
|
-
const processedConfig = await processConfigFields(parsedConfig);
|
|
64
|
-
|
|
65
|
-
// Validate sourcePaths against exclude patterns
|
|
66
|
-
const sourcesPath = processedConfig.sourcesPath || parsedConfig.sourcesPath;
|
|
67
|
-
if (sourcesPath) {
|
|
68
|
-
const excludePatterns = [
|
|
69
|
-
...DEFAULT_EXCLUDE_PATTERNS,
|
|
70
|
-
...(processedConfig.excludePatterns || parsedConfig.excludePatterns || []),
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
const { excluded, notFound } = await findInvalidSourcePaths(sourcesPath, excludePatterns);
|
|
74
|
-
|
|
75
|
-
if (excluded.length > 0 || notFound.length > 0) {
|
|
76
|
-
const warnings = [];
|
|
77
|
-
|
|
78
|
-
if (excluded.length > 0) {
|
|
79
|
-
warnings.push(
|
|
80
|
-
`⚠️ These paths were excluded (ignored by config):\n${excluded.map((p) => ` - ${chalk.yellow(p)}`).join("\n")}`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (notFound.length > 0) {
|
|
85
|
-
warnings.push(
|
|
86
|
-
`🚫 These paths were skipped because they do not exist:\n${notFound.map((p) => ` - ${chalk.red(p)}`).join("\n")}`,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
warnings.push(
|
|
91
|
-
`💡 Tip: You can remove these paths in ${chalk.cyan(toDisplayPath(configPath))}`,
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
console.warn(`${warnings.join("\n\n")}\n`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
lastGitHead: parsedConfig.lastGitHead || "",
|
|
100
|
-
...parsedConfig,
|
|
101
|
-
...processedConfig,
|
|
102
|
-
};
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.error(`I encountered an error while parsing the config file: ${error.message}`);
|
|
105
|
-
throw new Error(`I could not parse the config file: ${error.message}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
package/utils/markdown/index.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import remarkGfm from "remark-gfm";
|
|
2
|
-
import remarkParse from "remark-parse";
|
|
3
|
-
import { unified } from "unified";
|
|
4
|
-
import { visit } from "unist-util-visit";
|
|
5
|
-
import { VFile } from "vfile";
|
|
6
|
-
|
|
7
|
-
export function traverseMarkdownAst({ ast, test, visitor }) {
|
|
8
|
-
if (!ast || !test || !visitor) {
|
|
9
|
-
throw new Error("Required parameters missing: ast, test, and visitor must be provided");
|
|
10
|
-
}
|
|
11
|
-
visit(ast, test, visitor);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getMarkdownAst({ markdown }) {
|
|
15
|
-
if (!markdown || typeof markdown !== "string") {
|
|
16
|
-
throw new Error("Invalid markdown input: must be a non-empty string");
|
|
17
|
-
}
|
|
18
|
-
const file = new VFile({ value: markdown });
|
|
19
|
-
const processor = unified().use(remarkParse).use(remarkGfm);
|
|
20
|
-
try {
|
|
21
|
-
const ast = processor.parse(file);
|
|
22
|
-
return ast;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw new Error(`Failed to parse markdown: ${error.message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|