@effect-kit/ai-docgen 0.0.0-stage → 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/LICENSE +22 -0
- package/NOTICE.md +41 -0
- package/README.md +28 -2
- package/dist/Glob.d.ts +43 -0
- package/dist/Glob.d.ts.map +1 -0
- package/dist/Glob.js +40 -0
- package/dist/Glob.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +130 -0
- package/dist/main.js.map +1 -0
- package/package.json +58 -3
- package/src/Glob.ts +48 -0
- package/src/main.ts +190 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Effectful Technologies Inc
|
|
4
|
+
Copyright (c) 2026 Effect Kit Contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Notice
|
|
2
|
+
|
|
3
|
+
This package is an unofficial fork of [`Effect-TS/effect`](https://github.com/Effect-TS/effect),
|
|
4
|
+
directory `packages/tools/ai-docgen`, at commit `e3aca1f1484e623cee09b7f3fa18d6ff5d66c0e8`
|
|
5
|
+
(tag `effect@4.1.5`). It is not affiliated with or endorsed by Effectful Technologies.
|
|
6
|
+
|
|
7
|
+
## Changes from upstream
|
|
8
|
+
|
|
9
|
+
- Renamed to `@effect-kit/ai-docgen`; package metadata points at `effect-kit/tools`.
|
|
10
|
+
- Published: `bin` and `exports` resolve to compiled `dist/*.js` (Node does not strip types inside `node_modules`).
|
|
11
|
+
- Bin renamed from `effect-ai-docgen` to `effect-kit-ai-docgen`; upstream's published bin pointed at a non-existent `dist/bin.js` under the name `effect-ai-codegen`.
|
|
12
|
+
- `--version` reports the package version instead of `0.0.0`.
|
|
13
|
+
- The unused `yaml` dependency is dropped.
|
|
14
|
+
|
|
15
|
+
Re-sync deliberately, in its own commit, and update the commit above.
|
|
16
|
+
|
|
17
|
+
## Upstream license
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
MIT License
|
|
21
|
+
|
|
22
|
+
Copyright (c) 2023 Effectful Technologies Inc
|
|
23
|
+
|
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
26
|
+
in the Software without restriction, including without limitation the rights
|
|
27
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
28
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
29
|
+
furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all
|
|
32
|
+
copies or substantial portions of the Software.
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
35
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
37
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
38
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
39
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
40
|
+
SOFTWARE.
|
|
41
|
+
```
|
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @effect-kit/ai-docgen
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Builds one Markdown file (such as `LLMS.md`) from a directory tree of runnable TypeScript examples.
|
|
4
|
+
Unofficial fork of Effect's internal `@effect/ai-docgen`; see [NOTICE.md](NOTICE.md).
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add -D @effect-kit/ai-docgen
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Use
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
ai-docs/src/
|
|
16
|
+
index.md intro for this level
|
|
17
|
+
01_basics/
|
|
18
|
+
index.md
|
|
19
|
+
010_create.ts inlined: names starting with 0 become a section with the code
|
|
20
|
+
100_more-examples.ts linked: other names become a link with the JSDoc description
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Each example may start with a JSDoc block; `@title` sets the heading, the rest is the description.
|
|
24
|
+
`fixtures/` directories are skipped.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
effect-kit-ai-docgen ai-docs/src -o LLMS.md
|
|
28
|
+
effect-kit-ai-docgen ai-docs/src -o LLMS.md --watch
|
|
29
|
+
```
|
package/dist/Glob.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glob pattern matching service.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import * as GlobLib from "glob";
|
|
10
|
+
declare const GlobError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
11
|
+
readonly _tag: "GlobError";
|
|
12
|
+
} & Readonly<A>;
|
|
13
|
+
/**
|
|
14
|
+
* Error during glob pattern matching.
|
|
15
|
+
*
|
|
16
|
+
* @category errors
|
|
17
|
+
* @since 4.0.0
|
|
18
|
+
*/
|
|
19
|
+
export declare class GlobError extends GlobError_base<{
|
|
20
|
+
readonly pattern: string | ReadonlyArray<string>;
|
|
21
|
+
readonly cause: unknown;
|
|
22
|
+
}> {
|
|
23
|
+
}
|
|
24
|
+
declare const Glob_base: Context.ServiceClass<Glob, "@effect-kit/ai-docgen/Glob", {
|
|
25
|
+
readonly glob: (pattern: string | ReadonlyArray<string>, options?: GlobLib.GlobOptions) => Effect.Effect<Array<string>, GlobError>;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Context service for glob pattern matching used by AI docgen tooling.
|
|
29
|
+
*
|
|
30
|
+
* @category services
|
|
31
|
+
* @since 4.0.0
|
|
32
|
+
*/
|
|
33
|
+
export declare class Glob extends Glob_base {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Layer providing the Glob service.
|
|
37
|
+
*
|
|
38
|
+
* @category layers
|
|
39
|
+
* @since 4.0.0
|
|
40
|
+
*/
|
|
41
|
+
export declare const layer: Layer.Layer<Glob>;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=Glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Glob.d.ts","sourceRoot":"","sources":["../src/Glob.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,MAAM,CAAA;;;;AAE/B;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,eAA8B;IAC3D,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;CAAG;;mBASY,CACb,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,EACvC,OAAO,CAAC,EAAE,OAAO,CAAC,WAAW,KAC1B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;;AAV9C;;;;;GAKG;AACH,qBAAa,IAAK,SAAQ,SAKQ;CAAG;AAErC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAMlC,CAAA"}
|
package/dist/Glob.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glob pattern matching service.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Data from "effect/Data";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as GlobLib from "glob";
|
|
11
|
+
/**
|
|
12
|
+
* Error during glob pattern matching.
|
|
13
|
+
*
|
|
14
|
+
* @category errors
|
|
15
|
+
* @since 4.0.0
|
|
16
|
+
*/
|
|
17
|
+
export class GlobError extends /*#__PURE__*/Data.TaggedError("GlobError") {}
|
|
18
|
+
/**
|
|
19
|
+
* Context service for glob pattern matching used by AI docgen tooling.
|
|
20
|
+
*
|
|
21
|
+
* @category services
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
*/
|
|
24
|
+
export class Glob extends /*#__PURE__*/Context.Service()("@effect-kit/ai-docgen/Glob") {}
|
|
25
|
+
/**
|
|
26
|
+
* Layer providing the Glob service.
|
|
27
|
+
*
|
|
28
|
+
* @category layers
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
export const layer = /*#__PURE__*/Layer.succeed(Glob, {
|
|
32
|
+
glob: (pattern, options) => Effect.tryPromise({
|
|
33
|
+
try: () => GlobLib.glob(pattern, options ?? {}),
|
|
34
|
+
catch: cause => new GlobError({
|
|
35
|
+
pattern,
|
|
36
|
+
cause
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=Glob.js.map
|
package/dist/Glob.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Glob.js","names":[],"sources":["../src/Glob.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,IAAI,MAAM,aAAa;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,OAAO,MAAM,MAAM;AAE/B;;;;;;AAMA,OAAM,MAAO,SAAU,sBAAQ,IAAI,CAAC,WAAW,CAAC,WAAW,CAGzD;AAEF;;;;;;AAMA,OAAM,MAAO,IAAK,sBAAQ,OAAO,CAAC,OAAO,EAKrC,CAAC,4BAA4B,CAAC;AAElC;;;;;;AAMA,OAAO,MAAM,KAAK,gBAAsB,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE;EAC1D,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KACrB,MAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,OAAiC,EAAE,OAAO,IAAI,EAAE,CAA2B;IACnG,KAAK,EAAG,KAAK,IAAK,IAAI,SAAS,CAAC;MAAE,OAAO;MAAE;IAAK,CAAE;GACnD;CACJ,CAAC","ignoreList":[]}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @since 4.0.0
|
|
4
|
+
*/
|
|
5
|
+
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
|
+
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
7
|
+
import * as Array from "effect/Array";
|
|
8
|
+
import * as Argument from "effect/cli/Argument";
|
|
9
|
+
import * as Command from "effect/cli/Command";
|
|
10
|
+
import * as Flag from "effect/cli/Flag";
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import * as FileSystem from "effect/FileSystem";
|
|
13
|
+
import { pipe } from "effect/Function";
|
|
14
|
+
import * as Path from "effect/Path";
|
|
15
|
+
import * as Stream from "effect/Stream";
|
|
16
|
+
import * as String from "effect/String";
|
|
17
|
+
import PackageJson from "../package.json" with { type: "json" };
|
|
18
|
+
const directory = /*#__PURE__*/Argument.Directory("directory", {
|
|
19
|
+
mustExist: true
|
|
20
|
+
});
|
|
21
|
+
const output = /*#__PURE__*/Flag.Path("output").pipe(/*#__PURE__*/Flag.withAlias("o"), /*#__PURE__*/Flag.withDescription("Output file path"));
|
|
22
|
+
const watch = /*#__PURE__*/Flag.Boolean("watch").pipe(/*#__PURE__*/Flag.withAlias("w"), /*#__PURE__*/Flag.withDescription("Watch for file changes and regenerate documentation"), /*#__PURE__*/Flag.withDefault(false));
|
|
23
|
+
Command.make("effect-kit-ai-docgen", {
|
|
24
|
+
directory,
|
|
25
|
+
output,
|
|
26
|
+
watch
|
|
27
|
+
}).pipe(Command.withHandler(Effect.fnUntraced(function* ({
|
|
28
|
+
directory,
|
|
29
|
+
output,
|
|
30
|
+
watch
|
|
31
|
+
}) {
|
|
32
|
+
const fs = yield* FileSystem.FileSystem;
|
|
33
|
+
const markdown = yield* directoryToMarkdown(directory);
|
|
34
|
+
yield* fs.writeFileString(output, markdown);
|
|
35
|
+
if (!watch) return;
|
|
36
|
+
yield* Effect.logInfo("Watching for changes...");
|
|
37
|
+
yield* fs.watch(directory).pipe(Stream.debounce(1000), Stream.tap(() => Effect.logInfo("Changes detected, regenerating documentation...")), Stream.switchMap(() => directoryToMarkdown(directory).pipe(Stream.fromEffect)), Stream.runForEach(Effect.fn(function* (markdown) {
|
|
38
|
+
yield* fs.writeFileString(output, markdown);
|
|
39
|
+
yield* Effect.logInfo("Documentation updated.");
|
|
40
|
+
})));
|
|
41
|
+
})), Command.run({
|
|
42
|
+
version: PackageJson["version"]
|
|
43
|
+
}), Effect.provide(NodeServices.layer), NodeRuntime.runMain);
|
|
44
|
+
const directoryToMarkdown = /*#__PURE__*/Effect.fn("directoryToMarkdown")(function* (directory) {
|
|
45
|
+
const pathService = yield* Path.Path;
|
|
46
|
+
const fs = yield* FileSystem.FileSystem;
|
|
47
|
+
const indexMd = yield* fs.readFileString(pathService.join(directory, "index.md")).pipe(Effect.map(String.trim), Effect.orElseSucceed(() => null));
|
|
48
|
+
const allFiles = yield* fs.readDirectory(directory);
|
|
49
|
+
const hasInlineFiles = allFiles.some(file => pathService.basename(file).startsWith("0") && /\.tsx?$/.test(file));
|
|
50
|
+
const tsFileContent = yield* Effect.forEach(allFiles, Effect.fn(function* (file) {
|
|
51
|
+
const filePath = pathService.join(directory, file);
|
|
52
|
+
const stat = yield* fs.stat(filePath);
|
|
53
|
+
const basename = pathService.basename(filePath);
|
|
54
|
+
if (stat.type === "Directory") {
|
|
55
|
+
if (basename === "fixtures") return null;
|
|
56
|
+
return `${yield* directoryToMarkdown(filePath)}\n`;
|
|
57
|
+
} else if (/\.tsx?$/.test(file)) {
|
|
58
|
+
const metadata = yield* tsFileMetadata(filePath);
|
|
59
|
+
if (metadata.fileNameWithoutExt.startsWith("0")) {
|
|
60
|
+
return `### ${metadata.title}
|
|
61
|
+
|
|
62
|
+
${metadata.description ?? ""}
|
|
63
|
+
|
|
64
|
+
\`\`\`ts
|
|
65
|
+
${metadata.content}
|
|
66
|
+
\`\`\`
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
const relativePath = pathService.relative(process.cwd(), filePath);
|
|
70
|
+
const link = `[${metadata.title}](./${relativePath})`;
|
|
71
|
+
let content = "";
|
|
72
|
+
if (hasInlineFiles && metadata.fileNameWithoutExt.startsWith("10")) {
|
|
73
|
+
content += `### More examples\n\n`;
|
|
74
|
+
}
|
|
75
|
+
content += `- **${link}**`;
|
|
76
|
+
if (metadata.description) {
|
|
77
|
+
if (metadata.description.includes("\n")) {
|
|
78
|
+
const indentedDescription = metadata.description.split("\n").map(line => ` ${line}`).join("\n");
|
|
79
|
+
content += `:\n${indentedDescription}`;
|
|
80
|
+
} else {
|
|
81
|
+
content += `: ${metadata.description}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return content;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}), {
|
|
88
|
+
concurrency: 5
|
|
89
|
+
}).pipe(Effect.map(Array.filter(s => s !== null && s.trim() !== "")), Effect.map(Array.join("\n")), Effect.map(String.trim));
|
|
90
|
+
return indexMd ? `${indexMd}\n\n${tsFileContent}` : tsFileContent;
|
|
91
|
+
});
|
|
92
|
+
const tsFileMetadata = /*#__PURE__*/Effect.fn("tsFileMetadata")(function* (filePath) {
|
|
93
|
+
const pathService = yield* Path.Path;
|
|
94
|
+
const fs = yield* FileSystem.FileSystem;
|
|
95
|
+
let content = yield* fs.readFileString(filePath);
|
|
96
|
+
const fileNameWithoutExt = pathService.basename(filePath, pathService.extname(filePath));
|
|
97
|
+
let title = pipe(fileNameWithoutExt, String.replaceAll(/^\d+/g, ""), String.replaceAll(/[-_]/g, " "), String.trim, String.capitalize);
|
|
98
|
+
const firstDocString = content.indexOf("/**");
|
|
99
|
+
if (firstDocString === -1) {
|
|
100
|
+
return {
|
|
101
|
+
title,
|
|
102
|
+
description: undefined,
|
|
103
|
+
content,
|
|
104
|
+
fileNameWithoutExt
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const linesWithComment = content.slice(firstDocString).split("\n");
|
|
108
|
+
let description = "";
|
|
109
|
+
for (let i = 1; i < linesWithComment.length; i++) {
|
|
110
|
+
const line = linesWithComment[i];
|
|
111
|
+
if (!line.startsWith(" *")) break;
|
|
112
|
+
if (line.endsWith(" */")) {
|
|
113
|
+
content = linesWithComment.slice(i + 1).join("\n").trim();
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const lineContent = line.replace(/^ \*\s?/, "");
|
|
117
|
+
if (lineContent.startsWith("@title")) {
|
|
118
|
+
title = lineContent.replace("@title", "").trim();
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
description += lineContent + "\n";
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
title,
|
|
125
|
+
description: String.trim(description) || undefined,
|
|
126
|
+
content,
|
|
127
|
+
fileNameWithoutExt
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","names":[],"sources":["../src/main.ts"],"sourcesContent":[null],"mappings":";AACA;;;AAGA,OAAO,KAAK,WAAW,MAAM,mCAAmC;AAChE,OAAO,KAAK,YAAY,MAAM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MAChD;IACF;IACA,WAAW,IAAI,WAAW,GAAG,IAAI;EACnC;EAEA,OAAO;IACL,KAAK;IACL,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,SAAS;IAClD,OAAO;IACP;GACQ;AACZ,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-kit/ai-docgen",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Builds an LLMS.md from a directory of runnable TypeScript docs (unofficial fork of Effect's internal @effect/ai-docgen)",
|
|
7
|
+
"homepage": "https://github.com/effect-kit/tools/tree/main/packages/ai-docgen#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/effect-kit/tools.git",
|
|
11
|
+
"directory": "packages/ai-docgen"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/effect-kit/tools/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"effect",
|
|
18
|
+
"llms",
|
|
19
|
+
"documentation",
|
|
20
|
+
"ai",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.19.0"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": [],
|
|
27
|
+
"bin": {
|
|
28
|
+
"effect-kit-ai-docgen": "./dist/main.js"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
"./package.json": "./package.json",
|
|
32
|
+
"./*": "./dist/*.js",
|
|
33
|
+
"./main": null
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"src/**/*.ts",
|
|
37
|
+
"dist/**/*.js",
|
|
38
|
+
"dist/**/*.js.map",
|
|
39
|
+
"dist/**/*.d.ts",
|
|
40
|
+
"dist/**/*.d.ts.map",
|
|
41
|
+
"NOTICE.md",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"provenance": true
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@effect/platform-node": "^4.1.5",
|
|
50
|
+
"effect": "^4.1.5",
|
|
51
|
+
"glob": "^14.0.6"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "26.6.6"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsc -b tsconfig.json && pnpm babel",
|
|
58
|
+
"babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
|
|
59
|
+
"check": "tsc -b tsconfig.json"
|
|
60
|
+
}
|
|
6
61
|
}
|
package/src/Glob.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glob pattern matching service.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "effect/Context"
|
|
7
|
+
import * as Data from "effect/Data"
|
|
8
|
+
import * as Effect from "effect/Effect"
|
|
9
|
+
import * as Layer from "effect/Layer"
|
|
10
|
+
import * as GlobLib from "glob"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Error during glob pattern matching.
|
|
14
|
+
*
|
|
15
|
+
* @category errors
|
|
16
|
+
* @since 4.0.0
|
|
17
|
+
*/
|
|
18
|
+
export class GlobError extends Data.TaggedError("GlobError")<{
|
|
19
|
+
readonly pattern: string | ReadonlyArray<string>
|
|
20
|
+
readonly cause: unknown
|
|
21
|
+
}> {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Context service for glob pattern matching used by AI docgen tooling.
|
|
25
|
+
*
|
|
26
|
+
* @category services
|
|
27
|
+
* @since 4.0.0
|
|
28
|
+
*/
|
|
29
|
+
export class Glob extends Context.Service<Glob, {
|
|
30
|
+
readonly glob: (
|
|
31
|
+
pattern: string | ReadonlyArray<string>,
|
|
32
|
+
options?: GlobLib.GlobOptions
|
|
33
|
+
) => Effect.Effect<Array<string>, GlobError>
|
|
34
|
+
}>()("@effect-kit/ai-docgen/Glob") {}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Layer providing the Glob service.
|
|
38
|
+
*
|
|
39
|
+
* @category layers
|
|
40
|
+
* @since 4.0.0
|
|
41
|
+
*/
|
|
42
|
+
export const layer: Layer.Layer<Glob> = Layer.succeed(Glob, {
|
|
43
|
+
glob: (pattern, options) =>
|
|
44
|
+
Effect.tryPromise({
|
|
45
|
+
try: () => GlobLib.glob(pattern as string | Array<string>, options ?? {}) as Promise<Array<string>>,
|
|
46
|
+
catch: (cause) => new GlobError({ pattern, cause })
|
|
47
|
+
})
|
|
48
|
+
})
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @since 4.0.0
|
|
4
|
+
*/
|
|
5
|
+
import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
|
|
6
|
+
import * as NodeServices from "@effect/platform-node/NodeServices"
|
|
7
|
+
import * as Array from "effect/Array"
|
|
8
|
+
import * as Argument from "effect/cli/Argument"
|
|
9
|
+
import * as Command from "effect/cli/Command"
|
|
10
|
+
import * as Flag from "effect/cli/Flag"
|
|
11
|
+
import * as Effect from "effect/Effect"
|
|
12
|
+
import * as FileSystem from "effect/FileSystem"
|
|
13
|
+
import { pipe } from "effect/Function"
|
|
14
|
+
import * as Path from "effect/Path"
|
|
15
|
+
import type * as PlatformError from "effect/PlatformError"
|
|
16
|
+
import * as Stream from "effect/Stream"
|
|
17
|
+
import * as String from "effect/String"
|
|
18
|
+
import PackageJson from "../package.json" with { type: "json" }
|
|
19
|
+
|
|
20
|
+
const directory = Argument.Directory("directory", { mustExist: true })
|
|
21
|
+
|
|
22
|
+
const output = Flag.Path("output").pipe(
|
|
23
|
+
Flag.withAlias("o"),
|
|
24
|
+
Flag.withDescription("Output file path")
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const watch = Flag.Boolean("watch").pipe(
|
|
28
|
+
Flag.withAlias("w"),
|
|
29
|
+
Flag.withDescription("Watch for file changes and regenerate documentation"),
|
|
30
|
+
Flag.withDefault(false)
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
Command.make("effect-kit-ai-docgen", { directory, output, watch }).pipe(
|
|
34
|
+
Command.withHandler(Effect.fnUntraced(function*({ directory, output, watch }) {
|
|
35
|
+
const fs = yield* FileSystem.FileSystem
|
|
36
|
+
const markdown = yield* directoryToMarkdown(directory)
|
|
37
|
+
yield* fs.writeFileString(output, markdown)
|
|
38
|
+
|
|
39
|
+
if (!watch) return
|
|
40
|
+
|
|
41
|
+
yield* Effect.logInfo("Watching for changes...")
|
|
42
|
+
|
|
43
|
+
yield* fs.watch(directory).pipe(
|
|
44
|
+
Stream.debounce(1000),
|
|
45
|
+
Stream.tap(() => Effect.logInfo("Changes detected, regenerating documentation...")),
|
|
46
|
+
Stream.switchMap(() =>
|
|
47
|
+
directoryToMarkdown(directory).pipe(
|
|
48
|
+
Stream.fromEffect
|
|
49
|
+
)
|
|
50
|
+
),
|
|
51
|
+
Stream.runForEach(Effect.fn(function*(markdown) {
|
|
52
|
+
yield* fs.writeFileString(output, markdown)
|
|
53
|
+
yield* Effect.logInfo("Documentation updated.")
|
|
54
|
+
}))
|
|
55
|
+
)
|
|
56
|
+
})),
|
|
57
|
+
Command.run({
|
|
58
|
+
version: PackageJson["version"]
|
|
59
|
+
}),
|
|
60
|
+
Effect.provide(NodeServices.layer),
|
|
61
|
+
NodeRuntime.runMain
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const directoryToMarkdown = Effect.fn("directoryToMarkdown")(
|
|
65
|
+
function*(
|
|
66
|
+
directory: string
|
|
67
|
+
): Effect.fn.Return<string, PlatformError.PlatformError, FileSystem.FileSystem | Path.Path> {
|
|
68
|
+
const pathService = yield* Path.Path
|
|
69
|
+
const fs = yield* FileSystem.FileSystem
|
|
70
|
+
|
|
71
|
+
const indexMd = yield* fs.readFileString(pathService.join(directory, "index.md")).pipe(
|
|
72
|
+
Effect.map(String.trim),
|
|
73
|
+
Effect.orElseSucceed(() => null)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const allFiles = yield* fs.readDirectory(directory)
|
|
77
|
+
const hasInlineFiles = allFiles.some((file) => pathService.basename(file).startsWith("0") && /\.tsx?$/.test(file))
|
|
78
|
+
|
|
79
|
+
const tsFileContent = yield* Effect.forEach(
|
|
80
|
+
allFiles,
|
|
81
|
+
Effect.fn(function*(file) {
|
|
82
|
+
const filePath = pathService.join(directory, file)
|
|
83
|
+
const stat = yield* fs.stat(filePath)
|
|
84
|
+
const basename = pathService.basename(filePath)
|
|
85
|
+
|
|
86
|
+
if (stat.type === "Directory") {
|
|
87
|
+
if (basename === "fixtures") return null
|
|
88
|
+
return `${yield* directoryToMarkdown(filePath)}\n`
|
|
89
|
+
} else if (/\.tsx?$/.test(file)) {
|
|
90
|
+
const metadata = yield* tsFileMetadata(filePath)
|
|
91
|
+
|
|
92
|
+
if (metadata.fileNameWithoutExt.startsWith("0")) {
|
|
93
|
+
return `### ${metadata.title}
|
|
94
|
+
|
|
95
|
+
${metadata.description ?? ""}
|
|
96
|
+
|
|
97
|
+
\`\`\`ts
|
|
98
|
+
${metadata.content}
|
|
99
|
+
\`\`\`
|
|
100
|
+
`
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const relativePath = pathService.relative(process.cwd(), filePath)
|
|
104
|
+
const link = `[${metadata.title}](./${relativePath})`
|
|
105
|
+
let content = ""
|
|
106
|
+
|
|
107
|
+
if (hasInlineFiles && metadata.fileNameWithoutExt.startsWith("10")) {
|
|
108
|
+
content += `### More examples\n\n`
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
content += `- **${link}**`
|
|
112
|
+
|
|
113
|
+
if (metadata.description) {
|
|
114
|
+
if (metadata.description.includes("\n")) {
|
|
115
|
+
const indentedDescription = metadata.description
|
|
116
|
+
.split("\n")
|
|
117
|
+
.map((line) => ` ${line}`)
|
|
118
|
+
.join("\n")
|
|
119
|
+
content += `:\n${indentedDescription}`
|
|
120
|
+
} else {
|
|
121
|
+
content += `: ${metadata.description}`
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return content
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return null
|
|
128
|
+
}),
|
|
129
|
+
{ concurrency: 5 }
|
|
130
|
+
).pipe(
|
|
131
|
+
Effect.map(Array.filter((s): s is string => s !== null && s.trim() !== "")),
|
|
132
|
+
Effect.map(Array.join("\n")),
|
|
133
|
+
Effect.map(String.trim)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return indexMd ? `${indexMd}\n\n${tsFileContent}` : tsFileContent
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
const tsFileMetadata = Effect.fn("tsFileMetadata")(function*(filePath: string) {
|
|
141
|
+
const pathService = yield* Path.Path
|
|
142
|
+
const fs = yield* FileSystem.FileSystem
|
|
143
|
+
|
|
144
|
+
let content = yield* fs.readFileString(filePath)
|
|
145
|
+
const fileNameWithoutExt = pathService.basename(filePath, pathService.extname(filePath))
|
|
146
|
+
|
|
147
|
+
let title: string = pipe(
|
|
148
|
+
fileNameWithoutExt,
|
|
149
|
+
String.replaceAll(/^\d+/g, ""),
|
|
150
|
+
String.replaceAll(/[-_]/g, " "),
|
|
151
|
+
String.trim,
|
|
152
|
+
String.capitalize
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
const firstDocString = content.indexOf("/**")
|
|
156
|
+
if (firstDocString === -1) {
|
|
157
|
+
return {
|
|
158
|
+
title,
|
|
159
|
+
description: undefined,
|
|
160
|
+
content,
|
|
161
|
+
fileNameWithoutExt
|
|
162
|
+
} as const
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const linesWithComment = content.slice(firstDocString).split("\n")
|
|
166
|
+
|
|
167
|
+
let description = ""
|
|
168
|
+
|
|
169
|
+
for (let i = 1; i < linesWithComment.length; i++) {
|
|
170
|
+
const line = linesWithComment[i]
|
|
171
|
+
if (!line.startsWith(" *")) break
|
|
172
|
+
if (line.endsWith(" */")) {
|
|
173
|
+
content = linesWithComment.slice(i + 1).join("\n").trim()
|
|
174
|
+
break
|
|
175
|
+
}
|
|
176
|
+
const lineContent = line.replace(/^ \*\s?/, "")
|
|
177
|
+
if (lineContent.startsWith("@title")) {
|
|
178
|
+
title = lineContent.replace("@title", "").trim()
|
|
179
|
+
continue
|
|
180
|
+
}
|
|
181
|
+
description += lineContent + "\n"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
title,
|
|
186
|
+
description: String.trim(description) || undefined,
|
|
187
|
+
content,
|
|
188
|
+
fileNameWithoutExt
|
|
189
|
+
} as const
|
|
190
|
+
})
|