markform 0.1.0 → 0.1.2

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.
Files changed (37) hide show
  1. package/DOCS.md +546 -0
  2. package/README.md +484 -45
  3. package/SPEC.md +2779 -0
  4. package/dist/ai-sdk.d.mts +2 -2
  5. package/dist/ai-sdk.mjs +5 -3
  6. package/dist/{apply-C0vjijlP.mjs → apply-BfAGTHMh.mjs} +1044 -593
  7. package/dist/bin.mjs +6 -3
  8. package/dist/cli-B3NVm6zL.mjs +3904 -0
  9. package/dist/cli.mjs +6 -3
  10. package/dist/{coreTypes-T7dAuewt.d.mts → coreTypes-BXhhz9Iq.d.mts} +2795 -685
  11. package/dist/coreTypes-Dful87E0.mjs +537 -0
  12. package/dist/index.d.mts +196 -18
  13. package/dist/index.mjs +5 -3
  14. package/dist/session-Bqnwi9wp.mjs +110 -0
  15. package/dist/session-DdAtY2Ni.mjs +4 -0
  16. package/dist/shared-D7gf27Tr.mjs +3 -0
  17. package/dist/shared-N_s1M-_K.mjs +176 -0
  18. package/dist/src-BXRkGFpG.mjs +7587 -0
  19. package/examples/celebrity-deep-research/celebrity-deep-research.form.md +912 -0
  20. package/examples/earnings-analysis/earnings-analysis.form.md +6 -1
  21. package/examples/earnings-analysis/earnings-analysis.valid.ts +119 -59
  22. package/examples/movie-research/movie-research-basic.form.md +164 -0
  23. package/examples/movie-research/movie-research-deep.form.md +486 -0
  24. package/examples/movie-research/movie-research-minimal.form.md +73 -0
  25. package/examples/simple/simple-mock-filled.form.md +52 -12
  26. package/examples/simple/simple-skipped-filled.form.md +170 -0
  27. package/examples/simple/simple-with-skips.session.yaml +189 -0
  28. package/examples/simple/simple.form.md +34 -12
  29. package/examples/simple/simple.session.yaml +80 -37
  30. package/examples/startup-deep-research/startup-deep-research.form.md +456 -0
  31. package/examples/startup-research/startup-research-mock-filled.form.md +307 -0
  32. package/examples/startup-research/startup-research.form.md +211 -0
  33. package/package.json +11 -5
  34. package/dist/cli-9fvFySww.mjs +0 -2564
  35. package/dist/src-DBD3Dt4f.mjs +0 -1785
  36. package/examples/political-research/political-research.form.md +0 -233
  37. package/examples/political-research/political-research.mock.lincoln.form.md +0 -355
@@ -0,0 +1,176 @@
1
+ import YAML from "yaml";
2
+ import { relative } from "node:path";
3
+ import pc from "picocolors";
4
+ import { mkdir } from "node:fs/promises";
5
+
6
+ //#region src/cli/lib/naming.ts
7
+ /**
8
+ * Naming convention utilities for JSON/YAML output.
9
+ *
10
+ * Converts between camelCase (TypeScript internal) and snake_case (JSON/YAML output).
11
+ */
12
+ /**
13
+ * Convert a camelCase string to snake_case.
14
+ *
15
+ * @example
16
+ * toSnakeCase("fieldCount") // "field_count"
17
+ * toSnakeCase("parentFieldId") // "parent_field_id"
18
+ * toSnakeCase("already_snake") // "already_snake"
19
+ */
20
+ function toSnakeCase(str) {
21
+ return str.replace(/([A-Z])/g, "_$1").toLowerCase();
22
+ }
23
+ /**
24
+ * Recursively convert all object keys from camelCase to snake_case.
25
+ *
26
+ * Handles nested objects and arrays. Primitives are returned unchanged.
27
+ */
28
+ function convertKeysToSnakeCase(obj) {
29
+ if (obj === null || obj === void 0) return obj;
30
+ if (Array.isArray(obj)) return obj.map(convertKeysToSnakeCase);
31
+ if (typeof obj === "object") {
32
+ const result = {};
33
+ for (const [key, value] of Object.entries(obj)) {
34
+ const snakeKey = toSnakeCase(key);
35
+ result[snakeKey] = convertKeysToSnakeCase(value);
36
+ }
37
+ return result;
38
+ }
39
+ return obj;
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/cli/lib/shared.ts
44
+ /**
45
+ * Valid format options for Commander choice validation.
46
+ */
47
+ const OUTPUT_FORMATS = [
48
+ "console",
49
+ "plaintext",
50
+ "yaml",
51
+ "json",
52
+ "markform",
53
+ "markdown"
54
+ ];
55
+ /**
56
+ * Extract command context from Commander options.
57
+ */
58
+ function getCommandContext(command) {
59
+ const opts = command.optsWithGlobals();
60
+ return {
61
+ dryRun: opts.dryRun ?? false,
62
+ verbose: opts.verbose ?? false,
63
+ quiet: opts.quiet ?? false,
64
+ format: opts.format ?? "console",
65
+ formsDir: opts.formsDir
66
+ };
67
+ }
68
+ /**
69
+ * Check if output should use colors.
70
+ * Returns true for console format when stdout is a TTY.
71
+ */
72
+ function shouldUseColors(ctx) {
73
+ if (ctx.format === "plaintext" || ctx.format === "yaml" || ctx.format === "json") return false;
74
+ return process.stdout.isTTY && !process.env.NO_COLOR;
75
+ }
76
+ /**
77
+ * Format structured data according to output format.
78
+ *
79
+ * JSON and YAML outputs are converted to snake_case keys for consistency.
80
+ */
81
+ function formatOutput(ctx, data, consoleFormatter) {
82
+ switch (ctx.format) {
83
+ case "json": return JSON.stringify(convertKeysToSnakeCase(data), null, 2);
84
+ case "yaml": return YAML.stringify(convertKeysToSnakeCase(data));
85
+ case "plaintext":
86
+ case "console":
87
+ default:
88
+ if (consoleFormatter) return consoleFormatter(data, shouldUseColors(ctx));
89
+ return YAML.stringify(convertKeysToSnakeCase(data));
90
+ }
91
+ }
92
+ /**
93
+ * Log a dry-run message.
94
+ */
95
+ function logDryRun(message, details) {
96
+ console.log(pc.yellow(`[DRY RUN] ${message}`));
97
+ if (details) console.log(pc.dim(JSON.stringify(details, null, 2)));
98
+ }
99
+ /**
100
+ * Log a verbose message (only shown if --verbose is set).
101
+ */
102
+ function logVerbose(ctx, message) {
103
+ if (ctx.verbose) console.log(pc.dim(message));
104
+ }
105
+ /**
106
+ * Log an info message (hidden if --quiet is set).
107
+ */
108
+ function logInfo(ctx, message) {
109
+ if (!ctx.quiet) console.log(message);
110
+ }
111
+ /**
112
+ * Log an error message (always shown).
113
+ */
114
+ function logError(message) {
115
+ console.error(pc.red(`Error: ${message}`));
116
+ }
117
+ /**
118
+ * Log a success message (hidden if --quiet is set).
119
+ */
120
+ function logSuccess(ctx, message) {
121
+ if (!ctx.quiet) console.log(pc.green(message));
122
+ }
123
+ /**
124
+ * Log a timing message (hidden if --quiet is set).
125
+ */
126
+ function logTiming(ctx, label, durationMs) {
127
+ if (!ctx.quiet) {
128
+ const seconds = (durationMs / 1e3).toFixed(1);
129
+ console.log(pc.cyan(`⏰ ${label}: ${seconds}s`));
130
+ }
131
+ }
132
+ /**
133
+ * Log a warning message (hidden if --quiet is set).
134
+ */
135
+ function logWarn(ctx, message) {
136
+ if (!ctx.quiet) console.log(pc.yellow(`⚠️ ${message}`));
137
+ }
138
+ /**
139
+ * Format a file path for display: relative to cwd, colored green.
140
+ * If the path is within the cwd, shows as relative (e.g., "./simple-filled1.form.md")
141
+ * If outside cwd, shows the absolute path.
142
+ */
143
+ function formatPath(absolutePath, cwd = process.cwd()) {
144
+ const relativePath = relative(cwd, absolutePath);
145
+ const displayPath = relativePath.startsWith("..") ? absolutePath : `./${relativePath}`;
146
+ return pc.green(displayPath);
147
+ }
148
+ /**
149
+ * Read a file and return its contents.
150
+ */
151
+ async function readFile$1(filePath) {
152
+ const { readFile: fsReadFile } = await import("node:fs/promises");
153
+ return fsReadFile(filePath, "utf-8");
154
+ }
155
+ /**
156
+ * Write contents to a file atomically.
157
+ *
158
+ * Uses the atomically library to prevent partial or corrupted files
159
+ * if the process crashes mid-write.
160
+ */
161
+ async function writeFile(filePath, contents) {
162
+ const { writeFile: atomicWriteFile } = await import("atomically");
163
+ await atomicWriteFile(filePath, contents);
164
+ }
165
+ /**
166
+ * Ensure the forms directory exists, creating it if necessary.
167
+ * Uses recursive mkdir so parent directories are created as needed.
168
+ *
169
+ * @param formsDir Absolute path to the forms directory
170
+ */
171
+ async function ensureFormsDir(formsDir) {
172
+ await mkdir(formsDir, { recursive: true });
173
+ }
174
+
175
+ //#endregion
176
+ export { getCommandContext as a, logInfo as c, logVerbose as d, logWarn as f, writeFile as h, formatPath as i, logSuccess as l, shouldUseColors as m, ensureFormsDir as n, logDryRun as o, readFile$1 as p, formatOutput as r, logError as s, OUTPUT_FORMATS as t, logTiming as u };