@funkai/cli 0.1.2 → 0.1.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +21 -0
- package/dist/index.mjs +1538 -2335
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -7
- package/src/commands/generate.ts +1 -1
- package/src/commands/prompts/create.ts +3 -3
- package/src/commands/prompts/generate.ts +10 -5
- package/src/commands/prompts/lint.ts +9 -8
- package/src/commands/prompts/setup.ts +34 -17
- package/src/commands/validate.ts +1 -1
- package/src/index.ts +30 -1
- package/src/lib/prompts/__tests__/extract-variables.test.ts +1 -1
- package/src/lib/prompts/__tests__/flatten.test.ts +1 -1
- package/src/lib/prompts/__tests__/frontmatter.test.ts +1 -1
- package/src/lib/prompts/__tests__/lint.test.ts +5 -5
- package/src/lib/prompts/codegen.ts +47 -20
- package/src/lib/prompts/extract-variables.ts +7 -1
- package/src/lib/prompts/flatten.ts +10 -5
- package/src/lib/prompts/frontmatter.ts +37 -23
- package/src/lib/prompts/paths.ts +2 -2
- package/src/lib/prompts/pipeline.ts +22 -13
package/src/lib/prompts/paths.ts
CHANGED
|
@@ -23,7 +23,7 @@ function extractName(content: string): string | undefined {
|
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const frontmatter = match
|
|
26
|
+
const [, frontmatter] = match;
|
|
27
27
|
const nameLine = frontmatter.split("\n").find((line) => line.startsWith("name:"));
|
|
28
28
|
if (!nameLine) {
|
|
29
29
|
return undefined;
|
|
@@ -74,7 +74,7 @@ function scanDirectory(dir: string, depth: number): DiscoveredPrompt[] {
|
|
|
74
74
|
|
|
75
75
|
if (entry.isFile() && extname(entry.name) === PROMPT_EXT) {
|
|
76
76
|
// oxlint-disable-next-line security/detect-non-literal-fs-filename -- safe: reading prompt file content for name extraction
|
|
77
|
-
const content = readFileSync(fullPath, "
|
|
77
|
+
const content = readFileSync(fullPath, "utf8");
|
|
78
78
|
const name = extractName(content) ?? deriveNameFromPath(fullPath);
|
|
79
79
|
|
|
80
80
|
if (!NAME_RE.test(name)) {
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
import { clean, PARTIALS_DIR } from "@funkai/prompts";
|
|
4
|
+
import { clean, PARTIALS_DIR } from "@funkai/prompts/cli";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type { ParsedPrompt } from "./codegen.js";
|
|
7
7
|
import { extractVariables } from "./extract-variables.js";
|
|
8
8
|
import { flattenPartials } from "./flatten.js";
|
|
9
9
|
import { parseFrontmatter } from "./frontmatter.js";
|
|
10
|
-
import { lintPrompt
|
|
10
|
+
import { lintPrompt } from "./lint.js";
|
|
11
|
+
import type { LintResult } from "./lint.js";
|
|
11
12
|
import { discoverPrompts } from "./paths.js";
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the list of partial directories to search.
|
|
16
|
+
*
|
|
17
|
+
* @param customDir - Custom partials directory path.
|
|
18
|
+
* @returns Array of directories to search for partials.
|
|
19
|
+
*/
|
|
20
|
+
// oxlint-disable-next-line security/detect-non-literal-fs-filename -- safe: checking custom partials directory from CLI config
|
|
21
|
+
function resolvePartialsDirs(customDir: string): readonly string[] {
|
|
22
|
+
if (existsSync(customDir)) {
|
|
23
|
+
return [customDir, PARTIALS_DIR];
|
|
24
|
+
}
|
|
25
|
+
return [PARTIALS_DIR];
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
/**
|
|
14
29
|
* Options for the prompts lint pipeline.
|
|
15
30
|
*/
|
|
@@ -35,14 +50,11 @@ export interface LintPipelineResult {
|
|
|
35
50
|
export function runLintPipeline(options: LintPipelineOptions): LintPipelineResult {
|
|
36
51
|
const discovered = discoverPrompts([...options.roots]);
|
|
37
52
|
const customPartialsDir = resolve(options.partials ?? ".prompts/partials");
|
|
38
|
-
|
|
39
|
-
const partialsDirs = existsSync(customPartialsDir)
|
|
40
|
-
? [customPartialsDir, PARTIALS_DIR]
|
|
41
|
-
: [PARTIALS_DIR];
|
|
53
|
+
const partialsDirs = resolvePartialsDirs(customPartialsDir);
|
|
42
54
|
|
|
43
55
|
const results = discovered.map((d) => {
|
|
44
56
|
// oxlint-disable-next-line security/detect-non-literal-fs-filename -- safe: reading discovered prompt file
|
|
45
|
-
const raw = readFileSync(d.filePath, "
|
|
57
|
+
const raw = readFileSync(d.filePath, "utf8");
|
|
46
58
|
const frontmatter = parseFrontmatter(raw, d.filePath);
|
|
47
59
|
const template = flattenPartials(clean(raw), partialsDirs);
|
|
48
60
|
const templateVars = extractVariables(template);
|
|
@@ -81,14 +93,11 @@ export interface GeneratePipelineResult {
|
|
|
81
93
|
export function runGeneratePipeline(options: GeneratePipelineOptions): GeneratePipelineResult {
|
|
82
94
|
const discovered = discoverPrompts([...options.roots]);
|
|
83
95
|
const customPartialsDir = resolve(options.partials ?? resolve(options.out, "../partials"));
|
|
84
|
-
|
|
85
|
-
const partialsDirs = existsSync(customPartialsDir)
|
|
86
|
-
? [customPartialsDir, PARTIALS_DIR]
|
|
87
|
-
: [PARTIALS_DIR];
|
|
96
|
+
const partialsDirs = resolvePartialsDirs(customPartialsDir);
|
|
88
97
|
|
|
89
98
|
const processed = discovered.map((d) => {
|
|
90
99
|
// oxlint-disable-next-line security/detect-non-literal-fs-filename -- safe: reading discovered prompt file
|
|
91
|
-
const raw = readFileSync(d.filePath, "
|
|
100
|
+
const raw = readFileSync(d.filePath, "utf8");
|
|
92
101
|
const frontmatter = parseFrontmatter(raw, d.filePath);
|
|
93
102
|
const template = flattenPartials(clean(raw), partialsDirs);
|
|
94
103
|
const templateVars = extractVariables(template);
|