@auto-engineer/narrative 0.13.3 → 0.15.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.
Files changed (240) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/README.md +151 -99
  4. package/dist/scripts/convert-flow-exec.js +2 -2
  5. package/dist/scripts/convert-flow-exec.js.map +1 -1
  6. package/dist/scripts/convert-flow-helper.js +3 -4
  7. package/dist/scripts/convert-flow-helper.js.map +1 -1
  8. package/dist/scripts/convert-flow.js +4 -4
  9. package/dist/scripts/convert-flow.js.map +1 -1
  10. package/dist/scripts/print-schema.js +1 -1
  11. package/dist/scripts/print-schema.js.map +1 -1
  12. package/dist/src/commands/export-schema-helper.js +9 -9
  13. package/dist/src/commands/export-schema-helper.js.map +1 -1
  14. package/dist/src/commands/export-schema.d.ts.map +1 -1
  15. package/dist/src/commands/export-schema.js +49 -68
  16. package/dist/src/commands/export-schema.js.map +1 -1
  17. package/dist/src/data-narrative-builders.d.ts +1 -1
  18. package/dist/src/data-narrative-builders.d.ts.map +1 -1
  19. package/dist/src/data-narrative-builders.js +13 -19
  20. package/dist/src/data-narrative-builders.js.map +1 -1
  21. package/dist/src/fluent-builder.d.ts.map +1 -1
  22. package/dist/src/fluent-builder.js +2 -2
  23. package/dist/src/fluent-builder.js.map +1 -1
  24. package/dist/src/fluent-builder.specs.js +2 -2
  25. package/dist/src/fluent-builder.specs.js.map +1 -1
  26. package/dist/src/getNarratives.cache.specs.js +5 -5
  27. package/dist/src/getNarratives.cache.specs.js.map +1 -1
  28. package/dist/src/getNarratives.d.ts +1 -1
  29. package/dist/src/getNarratives.d.ts.map +1 -1
  30. package/dist/src/getNarratives.js +6 -3
  31. package/dist/src/getNarratives.js.map +1 -1
  32. package/dist/src/getNarratives.specs.js +6 -6
  33. package/dist/src/getNarratives.specs.js.map +1 -1
  34. package/dist/src/id/addAutoIds.d.ts +1 -1
  35. package/dist/src/id/addAutoIds.d.ts.map +1 -1
  36. package/dist/src/id/addAutoIds.js.map +1 -1
  37. package/dist/src/id/addAutoIds.specs.js +1 -1
  38. package/dist/src/id/addAutoIds.specs.js.map +1 -1
  39. package/dist/src/id/hasAllIds.d.ts +1 -1
  40. package/dist/src/id/hasAllIds.d.ts.map +1 -1
  41. package/dist/src/id/hasAllIds.specs.js +1 -1
  42. package/dist/src/id/hasAllIds.specs.js.map +1 -1
  43. package/dist/src/id/index.d.ts +1 -1
  44. package/dist/src/id/index.d.ts.map +1 -1
  45. package/dist/src/id/index.js +1 -1
  46. package/dist/src/id/index.js.map +1 -1
  47. package/dist/src/index.d.ts +14 -17
  48. package/dist/src/index.d.ts.map +1 -1
  49. package/dist/src/index.js +8 -10
  50. package/dist/src/index.js.map +1 -1
  51. package/dist/src/integration-export-registry.d.ts +2 -2
  52. package/dist/src/integration-export-registry.d.ts.map +1 -1
  53. package/dist/src/integration-registry.d.ts +1 -1
  54. package/dist/src/integration-registry.d.ts.map +1 -1
  55. package/dist/src/integration-registry.js +1 -0
  56. package/dist/src/integration-registry.js.map +1 -1
  57. package/dist/src/loader/fs-path.js +2 -2
  58. package/dist/src/loader/fs-path.js.map +1 -1
  59. package/dist/src/loader/graph.d.ts +2 -2
  60. package/dist/src/loader/graph.d.ts.map +1 -1
  61. package/dist/src/loader/graph.js +2 -2
  62. package/dist/src/loader/graph.js.map +1 -1
  63. package/dist/src/loader/index.d.ts +1 -1
  64. package/dist/src/loader/index.d.ts.map +1 -1
  65. package/dist/src/loader/index.js +5 -5
  66. package/dist/src/loader/index.js.map +1 -1
  67. package/dist/src/loader/resolver.js +1 -1
  68. package/dist/src/loader/resolver.js.map +1 -1
  69. package/dist/src/loader/runtime-cjs.d.ts.map +1 -1
  70. package/dist/src/loader/runtime-cjs.js +2 -2
  71. package/dist/src/loader/runtime-cjs.js.map +1 -1
  72. package/dist/src/loader/ts-utils.js +5 -5
  73. package/dist/src/loader/ts-utils.js.map +1 -1
  74. package/dist/src/model-to-narrative.specs.js +73 -98
  75. package/dist/src/model-to-narrative.specs.js.map +1 -1
  76. package/dist/src/narrative-context.d.ts +4 -4
  77. package/dist/src/narrative-context.d.ts.map +1 -1
  78. package/dist/src/narrative-context.js +2 -2
  79. package/dist/src/narrative-context.js.map +1 -1
  80. package/dist/src/narrative-context.specs.js +118 -3
  81. package/dist/src/narrative-context.specs.js.map +1 -1
  82. package/dist/src/narrative-registry.d.ts +1 -1
  83. package/dist/src/narrative-registry.d.ts.map +1 -1
  84. package/dist/src/narrative-registry.js +1 -1
  85. package/dist/src/narrative-registry.js.map +1 -1
  86. package/dist/src/narrative.d.ts +3 -3
  87. package/dist/src/narrative.d.ts.map +1 -1
  88. package/dist/src/narrative.js +15 -17
  89. package/dist/src/narrative.js.map +1 -1
  90. package/dist/src/node.d.ts +1 -1
  91. package/dist/src/node.d.ts.map +1 -1
  92. package/dist/src/node.js +1 -1
  93. package/dist/src/node.js.map +1 -1
  94. package/dist/src/samples/items.narrative.js +2 -2
  95. package/dist/src/samples/items.narrative.js.map +1 -1
  96. package/dist/src/samples/mixed-given-types.narrative.js +1 -1
  97. package/dist/src/samples/mixed-given-types.narrative.js.map +1 -1
  98. package/dist/src/samples/place-order.narrative.js +1 -1
  99. package/dist/src/samples/place-order.narrative.js.map +1 -1
  100. package/dist/src/samples/questionnaires.narrative.js +1 -1
  101. package/dist/src/samples/questionnaires.narrative.js.map +1 -1
  102. package/dist/src/samples/test-with-ids.narrative.js +1 -1
  103. package/dist/src/samples/test-with-ids.narrative.js.map +1 -1
  104. package/dist/src/schema-test.js +1 -1
  105. package/dist/src/schema-test.js.map +1 -1
  106. package/dist/src/schema.d.ts +264 -264
  107. package/dist/src/slice-builder.d.ts.map +1 -1
  108. package/dist/src/slice-builder.js +1 -1
  109. package/dist/src/slice-builder.js.map +1 -1
  110. package/dist/src/transformers/model-to-narrative/ast/emit-helpers.d.ts +1 -1
  111. package/dist/src/transformers/model-to-narrative/ast/emit-helpers.d.ts.map +1 -1
  112. package/dist/src/transformers/model-to-narrative/formatting/sort-types.js +1 -1
  113. package/dist/src/transformers/model-to-narrative/formatting/sort-types.js.map +1 -1
  114. package/dist/src/transformers/model-to-narrative/generators/compose.d.ts +1 -1
  115. package/dist/src/transformers/model-to-narrative/generators/compose.d.ts.map +1 -1
  116. package/dist/src/transformers/model-to-narrative/generators/compose.js +4 -4
  117. package/dist/src/transformers/model-to-narrative/generators/compose.js.map +1 -1
  118. package/dist/src/transformers/model-to-narrative/generators/flow.d.ts +1 -1
  119. package/dist/src/transformers/model-to-narrative/generators/flow.d.ts.map +1 -1
  120. package/dist/src/transformers/model-to-narrative/generators/flow.js.map +1 -1
  121. package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts +1 -1
  122. package/dist/src/transformers/model-to-narrative/generators/gwt.d.ts.map +1 -1
  123. package/dist/src/transformers/model-to-narrative/generators/gwt.js +47 -57
  124. package/dist/src/transformers/model-to-narrative/generators/gwt.js.map +1 -1
  125. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.d.ts +2 -0
  126. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.d.ts.map +1 -0
  127. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.js +142 -0
  128. package/dist/src/transformers/model-to-narrative/generators/gwt.specs.js.map +1 -0
  129. package/dist/src/transformers/model-to-narrative/generators/imports.d.ts +1 -1
  130. package/dist/src/transformers/model-to-narrative/generators/imports.d.ts.map +1 -1
  131. package/dist/src/transformers/model-to-narrative/generators/imports.js +0 -4
  132. package/dist/src/transformers/model-to-narrative/generators/imports.js.map +1 -1
  133. package/dist/src/transformers/model-to-narrative/generators/types.d.ts +1 -1
  134. package/dist/src/transformers/model-to-narrative/generators/types.d.ts.map +1 -1
  135. package/dist/src/transformers/model-to-narrative/index.d.ts +1 -1
  136. package/dist/src/transformers/model-to-narrative/index.d.ts.map +1 -1
  137. package/dist/src/transformers/model-to-narrative/index.js +1 -1
  138. package/dist/src/transformers/model-to-narrative/index.js.map +1 -1
  139. package/dist/src/transformers/narrative-to-model/assemble.d.ts +1 -1
  140. package/dist/src/transformers/narrative-to-model/assemble.d.ts.map +1 -1
  141. package/dist/src/transformers/narrative-to-model/example-shapes.d.ts +1 -1
  142. package/dist/src/transformers/narrative-to-model/example-shapes.d.ts.map +1 -1
  143. package/dist/src/transformers/narrative-to-model/index.d.ts +2 -2
  144. package/dist/src/transformers/narrative-to-model/index.d.ts.map +1 -1
  145. package/dist/src/transformers/narrative-to-model/index.js +5 -5
  146. package/dist/src/transformers/narrative-to-model/index.js.map +1 -1
  147. package/dist/src/transformers/narrative-to-model/inlining.d.ts +2 -2
  148. package/dist/src/transformers/narrative-to-model/inlining.d.ts.map +1 -1
  149. package/dist/src/transformers/narrative-to-model/integrations.d.ts +2 -2
  150. package/dist/src/transformers/narrative-to-model/integrations.d.ts.map +1 -1
  151. package/dist/src/transformers/narrative-to-model/integrations.js +3 -3
  152. package/dist/src/transformers/narrative-to-model/integrations.js.map +1 -1
  153. package/dist/src/transformers/narrative-to-model/messages.d.ts +2 -2
  154. package/dist/src/transformers/narrative-to-model/messages.d.ts.map +1 -1
  155. package/dist/src/transformers/narrative-to-model/messages.js +1 -1
  156. package/dist/src/transformers/narrative-to-model/messages.js.map +1 -1
  157. package/dist/src/transformers/narrative-to-model/normalize.d.ts +1 -1
  158. package/dist/src/transformers/narrative-to-model/normalize.d.ts.map +1 -1
  159. package/dist/src/transformers/narrative-to-model/spec-processors.d.ts +3 -3
  160. package/dist/src/transformers/narrative-to-model/spec-processors.d.ts.map +1 -1
  161. package/dist/src/transformers/narrative-to-model/spec-processors.js +2 -2
  162. package/dist/src/transformers/narrative-to-model/spec-processors.js.map +1 -1
  163. package/dist/src/transformers/narrative-to-model/type-inference.d.ts +1 -1
  164. package/dist/src/transformers/narrative-to-model/type-inference.d.ts.map +1 -1
  165. package/dist/src/transformers/narrative-to-model/type-inference.js +1 -1
  166. package/dist/src/transformers/narrative-to-model/type-inference.js.map +1 -1
  167. package/dist/src/transformers/narrative-to-model/type-inference.specs.js +1 -1
  168. package/dist/src/transformers/narrative-to-model/type-inference.specs.js.map +1 -1
  169. package/dist/src/transformers/narrative-to-model/zod-adapter.d.ts +2 -2
  170. package/dist/src/transformers/narrative-to-model/zod-adapter.d.ts.map +1 -1
  171. package/dist/src/types.d.ts +1 -1
  172. package/dist/src/types.d.ts.map +1 -1
  173. package/dist/tsconfig.tsbuildinfo +1 -1
  174. package/package.json +5 -12
  175. package/scripts/convert-flow-exec.ts +2 -2
  176. package/scripts/convert-flow-helper.ts +3 -4
  177. package/scripts/convert-flow.ts +4 -4
  178. package/scripts/print-schema.ts +2 -2
  179. package/src/commands/export-schema-helper.ts +10 -12
  180. package/src/commands/export-schema.ts +50 -70
  181. package/src/data-narrative-builders.ts +8 -11
  182. package/src/fluent-builder.specs.ts +2 -2
  183. package/src/fluent-builder.ts +6 -6
  184. package/src/getNarratives.cache.specs.ts +6 -6
  185. package/src/getNarratives.specs.ts +6 -6
  186. package/src/getNarratives.ts +13 -5
  187. package/src/id/addAutoIds.specs.ts +2 -2
  188. package/src/id/addAutoIds.ts +1 -1
  189. package/src/id/hasAllIds.specs.ts +1 -1
  190. package/src/id/hasAllIds.ts +1 -1
  191. package/src/id/index.ts +1 -1
  192. package/src/index.ts +61 -54
  193. package/src/integration-export-registry.ts +2 -2
  194. package/src/integration-registry.ts +2 -1
  195. package/src/loader/fs-path.ts +2 -2
  196. package/src/loader/graph.ts +9 -9
  197. package/src/loader/index.ts +7 -7
  198. package/src/loader/resolver.ts +1 -1
  199. package/src/loader/runtime-cjs.ts +3 -3
  200. package/src/loader/ts-utils.ts +5 -5
  201. package/src/model-to-narrative.specs.ts +76 -99
  202. package/src/narrative-context.specs.ts +138 -4
  203. package/src/narrative-context.ts +6 -7
  204. package/src/narrative-registry.ts +2 -2
  205. package/src/narrative.ts +27 -33
  206. package/src/node.ts +1 -2
  207. package/src/samples/items.narrative.ts +3 -3
  208. package/src/samples/mixed-given-types.narrative.ts +2 -2
  209. package/src/samples/place-order.narrative.ts +1 -1
  210. package/src/samples/questionnaires.narrative.ts +10 -10
  211. package/src/samples/test-with-ids.narrative.ts +2 -2
  212. package/src/schema-test.ts +1 -1
  213. package/src/slice-builder.ts +2 -2
  214. package/src/transformers/model-to-narrative/ast/emit-helpers.ts +1 -1
  215. package/src/transformers/model-to-narrative/formatting/sort-types.ts +1 -1
  216. package/src/transformers/model-to-narrative/generators/compose.ts +5 -5
  217. package/src/transformers/model-to-narrative/generators/flow.ts +9 -9
  218. package/src/transformers/model-to-narrative/generators/gwt.specs.ts +157 -0
  219. package/src/transformers/model-to-narrative/generators/gwt.ts +80 -122
  220. package/src/transformers/model-to-narrative/generators/imports.ts +0 -4
  221. package/src/transformers/model-to-narrative/generators/types.ts +1 -1
  222. package/src/transformers/model-to-narrative/index.ts +2 -2
  223. package/src/transformers/narrative-to-model/assemble.ts +1 -1
  224. package/src/transformers/narrative-to-model/example-shapes.ts +1 -1
  225. package/src/transformers/narrative-to-model/index.ts +7 -7
  226. package/src/transformers/narrative-to-model/inlining.ts +2 -2
  227. package/src/transformers/narrative-to-model/integrations.ts +5 -5
  228. package/src/transformers/narrative-to-model/messages.ts +3 -3
  229. package/src/transformers/narrative-to-model/normalize.ts +1 -1
  230. package/src/transformers/narrative-to-model/spec-processors.ts +4 -4
  231. package/src/transformers/narrative-to-model/type-inference.specs.ts +2 -2
  232. package/src/transformers/narrative-to-model/type-inference.ts +2 -2
  233. package/src/transformers/narrative-to-model/zod-adapter.ts +2 -2
  234. package/src/types.ts +1 -1
  235. package/dist/src/commands/export-schema-runner.d.ts +0 -3
  236. package/dist/src/commands/export-schema-runner.d.ts.map +0 -1
  237. package/dist/src/commands/export-schema-runner.js +0 -53
  238. package/dist/src/commands/export-schema-runner.js.map +0 -1
  239. package/eslint.config.ts +0 -12
  240. package/src/commands/export-schema-runner.ts +0 -74
package/package.json CHANGED
@@ -23,31 +23,24 @@
23
23
  "typescript": "^5.9.2",
24
24
  "zod": "^3.22.4",
25
25
  "zod-to-json-schema": "^3.22.3",
26
- "@auto-engineer/file-store": "0.13.3",
27
- "@auto-engineer/id": "0.13.3",
28
- "@auto-engineer/message-bus": "0.13.3"
26
+ "@auto-engineer/file-store": "0.15.0",
27
+ "@auto-engineer/message-bus": "0.15.0",
28
+ "@auto-engineer/id": "0.15.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.0.0",
32
- "@typescript-eslint/eslint-plugin": "^7.18.0",
33
- "eslint-plugin-sort-keys-fix": "^1.1.2",
34
32
  "fake-indexeddb": "^6.0.0",
35
- "tsx": "^4.20.3",
36
- "@auto-engineer/cli": "0.13.3"
33
+ "tsx": "^4.20.3"
37
34
  },
38
35
  "publishConfig": {
39
36
  "access": "public"
40
37
  },
41
- "version": "0.13.3",
38
+ "version": "0.15.0",
42
39
  "scripts": {
43
40
  "build": "tsx scripts/build.ts",
44
41
  "test": "vitest run --reporter=dot",
45
- "lint": "eslint '{src,scripts}/**/*.ts' --max-warnings 0 --config ./eslint.config.ts",
46
42
  "type-check": "tsc --noEmit",
47
- "format": "prettier --write \"**/*.{js,ts,json,md,yml,yaml}\" --ignore-path ../../.prettierignore --log-level warn",
48
43
  "convert-narrative": "tsx scripts/convert-narrative.ts",
49
- "lint:fix": "eslint '{src,scripts}/**/*.ts' --fix --config ./eslint.config.ts",
50
- "format:fix": "prettier --write \"**/*.{js,ts,json,md,yml,yaml}\" --ignore-path ../../.prettierignore --log-level warn",
51
44
  "link:dev": "pnpm build && pnpm link --global",
52
45
  "unlink:dev": "pnpm unlink --global"
53
46
  }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { getNarratives } from '../src';
2
+ import path from 'node:path';
3
3
  import { NodeFileStore } from '@auto-engineer/file-store/node';
4
- import path from 'path';
4
+ import { getNarratives } from '../src';
5
5
 
6
6
  const main = async () => {
7
7
  try {
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from 'child_process';
3
- import { resolve, dirname } from 'path';
4
- import { writeFileSync, unlinkSync } from 'fs';
5
- import { join } from 'path';
2
+ import { spawn } from 'node:child_process';
3
+ import { unlinkSync, writeFileSync } from 'node:fs';
4
+ import { dirname, join, resolve } from 'node:path';
6
5
 
7
6
  const main = async () => {
8
7
  const flowPath = process.argv[2];
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { resolve, dirname, relative, join } from 'path';
3
- import { existsSync, writeFileSync, statSync } from 'fs';
4
- import { spawn } from 'child_process';
5
- import { fileURLToPath } from 'url';
2
+ import { spawn } from 'node:child_process';
3
+ import { existsSync, statSync, writeFileSync } from 'node:fs';
4
+ import { dirname, join, relative, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
6
 
7
7
  const runInContext = (flowPath: string, projectRoot: string): Promise<string> => {
8
8
  return new Promise((resolve, reject) => {
@@ -1,13 +1,13 @@
1
+ import { zodToJsonSchema } from 'zod-to-json-schema';
1
2
  import {
2
3
  CommandSliceSchema,
3
- NarrativeSchema,
4
4
  IntegrationSchema,
5
5
  MessageSchema,
6
+ NarrativeSchema,
6
7
  QuerySliceSchema,
7
8
  ReactSliceSchema,
8
9
  } from '../src';
9
10
 
10
- import { zodToJsonSchema } from 'zod-to-json-schema';
11
11
  const schemas = Object.fromEntries(
12
12
  Object.entries({
13
13
  narrative: NarrativeSchema,
@@ -1,6 +1,6 @@
1
+ import { type IExtendedFileStore, NodeFileStore } from '@auto-engineer/file-store/node';
1
2
  import createDebug from 'debug';
2
3
  import { getFs } from './filestore.node';
3
- import { IExtendedFileStore, NodeFileStore } from '@auto-engineer/file-store/node';
4
4
 
5
5
  const debug = createDebug('auto:narrative:export-schema-helper');
6
6
  if ('color' in debug && typeof debug === 'object') {
@@ -25,7 +25,7 @@ const main = async () => {
25
25
  );
26
26
  debug('Importing getNarratives from: %s', projectNarrativePath);
27
27
 
28
- const { pathToFileURL } = await import('url');
28
+ const { pathToFileURL } = await import('node:url');
29
29
  const narrativeModule = (await import(pathToFileURL(projectNarrativePath).href)) as {
30
30
  getNarratives: typeof import('../getNarratives').getNarratives;
31
31
  };
@@ -51,18 +51,16 @@ const main = async () => {
51
51
  await fs.writeText(outPath, json);
52
52
  debug('Schema written to: %s', outPath);
53
53
 
54
- // Output success as JSON for parent process
55
- console.log(
56
- JSON.stringify({
57
- success: true,
58
- outputPath: outPath,
59
- }),
60
- );
54
+ const resultPath = fs.join(contextDir, '.export-result.json');
55
+ await fs.writeText(resultPath, JSON.stringify({ success: true, outputPath: outPath }));
61
56
  } catch (error) {
62
57
  debug('Error occurred: %o', error);
63
-
64
- // Output error as JSON for parent process
65
- console.log(
58
+ const getFileStore = getFs as () => Promise<IExtendedFileStore>;
59
+ const fss: IExtendedFileStore = await getFileStore();
60
+ const resultPath = fss.join(process.argv[2] || process.cwd(), '.context', '.export-result.json');
61
+ await fss.ensureDir(fss.dirname(resultPath));
62
+ await fss.writeText(
63
+ resultPath,
66
64
  JSON.stringify({
67
65
  success: false,
68
66
  error: error instanceof Error ? error.message : 'Unknown error occurred',
@@ -1,4 +1,4 @@
1
- import { type Command, type Event, defineCommandHandler } from '@auto-engineer/message-bus';
1
+ import { type Command, defineCommandHandler, type Event } from '@auto-engineer/message-bus';
2
2
  import createDebug from 'debug';
3
3
 
4
4
  const debug = createDebug('auto:narrative:export-schema');
@@ -33,14 +33,18 @@ export type ExportSchemaEvents = SchemaExportedEvent | SchemaExportFailedEvent;
33
33
 
34
34
  export const commandHandler = defineCommandHandler({
35
35
  name: 'ExportSchema',
36
+ displayName: 'Export Schema',
36
37
  alias: 'export:schema',
37
38
  description: 'Export flow schemas to context directory',
38
39
  category: 'export',
39
40
  icon: 'download',
40
- events: ['SchemaExported', 'SchemaExportFailed'],
41
+ events: [
42
+ { name: 'SchemaExported', displayName: 'Schema Exported' },
43
+ { name: 'SchemaExportFailed', displayName: 'Schema Export Failed' },
44
+ ],
41
45
  fields: {
42
46
  directory: {
43
- description: 'Context directory path',
47
+ description: 'Context directory path (defaults to current working directory)',
44
48
  required: true,
45
49
  },
46
50
  },
@@ -60,7 +64,7 @@ export const commandHandler = defineCommandHandler({
60
64
  export async function handleExportSchemaCommand(
61
65
  command: ExportSchemaCommand,
62
66
  ): Promise<SchemaExportedEvent | SchemaExportFailedEvent> {
63
- const { directory } = command.data;
67
+ const directory = command.data.directory ?? process.cwd();
64
68
 
65
69
  try {
66
70
  // Run the helper script with tsx
@@ -68,76 +72,52 @@ export async function handleExportSchemaCommand(
68
72
  const fs = await getFs();
69
73
  const __dirname = fs.dirname(new URL(import.meta.url).href);
70
74
  const helperScript = fs.join(__dirname, 'export-schema-helper.js');
71
- const { spawn } = await import('child_process');
72
75
 
73
- return new Promise((resolve) => {
74
- const child = spawn('npx', ['tsx', helperScript, directory], {
75
- cwd: directory,
76
- stdio: ['inherit', 'pipe', 'inherit'], // Let stderr go directly to parent process
77
- env: {
78
- ...process.env,
79
- NODE_ENV: process.env.NODE_ENV ?? 'development',
80
- DEBUG: process.env.DEBUG, // Explicitly pass DEBUG env var
81
- DEBUG_COLORS: process.env.DEBUG_COLORS, // Pass color settings
82
- DEBUG_HIDE_DATE: 'true', // Always hide timestamps in child process to match parent
83
- },
84
- shell: true,
85
- });
76
+ const resultPath = fs.join(directory, '.context', '.export-result.json');
86
77
 
87
- let stdout = '';
88
-
89
- child.stdout.on('data', (data: Buffer) => {
90
- stdout += data.toString();
91
- });
92
-
93
- child.on('close', (code) => {
94
- try {
95
- // Extract JSON from stdout - look for the last line that starts with '{'
96
- const lines = stdout.trim().split('\n');
97
- const jsonLine = lines.reverse().find((line) => line.trim().startsWith('{'));
78
+ const { spawnSync } = await import('node:child_process');
79
+ spawnSync('node', [helperScript, directory], {
80
+ cwd: directory,
81
+ encoding: 'utf-8',
82
+ stdio: 'ignore',
83
+ env: {
84
+ ...process.env,
85
+ NODE_ENV: process.env.NODE_ENV ?? 'development',
86
+ DEBUG: process.env.DEBUG,
87
+ DEBUG_COLORS: process.env.DEBUG_COLORS,
88
+ DEBUG_HIDE_DATE: 'true',
89
+ },
90
+ });
98
91
 
99
- if (jsonLine == null) {
100
- throw new Error('No JSON output found');
101
- }
92
+ const resultJson = await fs.readText(resultPath);
93
+ if (resultJson == null) {
94
+ return {
95
+ type: 'SchemaExportFailed',
96
+ data: { directory, error: 'No result file found' },
97
+ timestamp: new Date(),
98
+ requestId: command.requestId,
99
+ correlationId: command.correlationId,
100
+ };
101
+ }
102
102
 
103
- const result = JSON.parse(jsonLine) as { success?: boolean; outputPath?: string; error?: string };
104
- if (result.success === true) {
105
- resolve({
106
- type: 'SchemaExported',
107
- data: {
108
- directory,
109
- outputPath: result.outputPath ?? '',
110
- },
111
- timestamp: new Date(),
112
- requestId: command.requestId,
113
- correlationId: command.correlationId,
114
- });
115
- } else {
116
- resolve({
117
- type: 'SchemaExportFailed',
118
- data: {
119
- directory,
120
- error: result.error ?? 'Unknown error',
121
- },
122
- timestamp: new Date(),
123
- requestId: command.requestId,
124
- correlationId: command.correlationId,
125
- });
126
- }
127
- } catch {
128
- resolve({
129
- type: 'SchemaExportFailed',
130
- data: {
131
- directory,
132
- error: code === 0 ? 'Failed to parse result' : `Process failed with code ${code}`,
133
- },
134
- timestamp: new Date(),
135
- requestId: command.requestId,
136
- correlationId: command.correlationId,
137
- });
138
- }
139
- });
140
- });
103
+ const parsed = JSON.parse(resultJson) as { success?: boolean; outputPath?: string; error?: string };
104
+ if (parsed.success === true) {
105
+ return {
106
+ type: 'SchemaExported',
107
+ data: { directory, outputPath: parsed.outputPath ?? '' },
108
+ timestamp: new Date(),
109
+ requestId: command.requestId,
110
+ correlationId: command.correlationId,
111
+ };
112
+ } else {
113
+ return {
114
+ type: 'SchemaExportFailed',
115
+ data: { directory, error: parsed.error ?? 'Unknown error' },
116
+ timestamp: new Date(),
117
+ requestId: command.requestId,
118
+ correlationId: command.correlationId,
119
+ };
120
+ }
141
121
  } catch (error: unknown) {
142
122
  const message = error instanceof Error ? error.message : String(error);
143
123
  return {
@@ -1,6 +1,6 @@
1
- import type { DataSinkItem, DataSourceItem, MessageTarget, Integration, DefaultRecord } from './types';
2
- import { createIntegrationOrigin } from './types';
3
1
  import { integrationExportRegistry } from './integration-export-registry';
2
+ import type { DataSinkItem, DataSourceItem, DefaultRecord, Integration, MessageTarget } from './types';
3
+ import { createIntegrationOrigin } from './types';
4
4
 
5
5
  // Extended interfaces that add chainable methods
6
6
  export interface ChainableSinkMethods {
@@ -19,19 +19,17 @@ export type ChainableSource = DataSourceItem & ChainableSourceMethods;
19
19
  function createChainableSink(sinkItem: DataSinkItem): ChainableSink {
20
20
  const chainable = sinkItem as ChainableSink;
21
21
 
22
- (chainable as ChainableSinkMethods).additionalInstructions = function (instructions: string): ChainableSink {
23
- return createChainableSink({
22
+ (chainable as ChainableSinkMethods).additionalInstructions = (instructions: string): ChainableSink =>
23
+ createChainableSink({
24
24
  ...sinkItem,
25
25
  _additionalInstructions: instructions,
26
26
  });
27
- };
28
27
 
29
- (chainable as ChainableSinkMethods).withState = function (source: DataSourceItem | ChainableSource): ChainableSink {
30
- return createChainableSink({
28
+ (chainable as ChainableSinkMethods).withState = (source: DataSourceItem | ChainableSource): ChainableSink =>
29
+ createChainableSink({
31
30
  ...sinkItem,
32
31
  _withState: source,
33
32
  });
34
- };
35
33
 
36
34
  return chainable;
37
35
  }
@@ -39,12 +37,11 @@ function createChainableSink(sinkItem: DataSinkItem): ChainableSink {
39
37
  function createChainableSource(sourceItem: DataSourceItem): ChainableSource {
40
38
  const chainable = sourceItem as ChainableSource;
41
39
 
42
- (chainable as ChainableSourceMethods).additionalInstructions = function (instructions: string): ChainableSource {
43
- return createChainableSource({
40
+ (chainable as ChainableSourceMethods).additionalInstructions = (instructions: string): ChainableSource =>
41
+ createChainableSource({
44
42
  ...sourceItem,
45
43
  _additionalInstructions: instructions,
46
44
  });
47
- };
48
45
 
49
46
  return chainable;
50
47
  }
@@ -1,7 +1,7 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
2
  import { command, react } from './fluent-builder';
3
+ import { clearCurrentNarrative, startNarrative } from './narrative-context';
3
4
  import { createIntegration } from './types';
4
- import { startNarrative, clearCurrentNarrative } from './narrative-context';
5
5
 
6
6
  // Test integrations
7
7
  const MailChimp = createIntegration('mailchimp', 'MailChimp');
@@ -1,15 +1,15 @@
1
- import type { Integration } from './types';
1
+ import createDebug from 'debug';
2
+ import { type ASTNode, print } from 'graphql';
3
+ import type { CommandSlice, ExperienceSlice, QuerySlice, ReactSlice } from './index';
2
4
  import {
3
5
  addSlice,
4
- startClientBlock,
5
6
  endClientBlock,
6
- startServerBlock,
7
7
  endServerBlock,
8
8
  getCurrentSlice,
9
+ startClientBlock,
10
+ startServerBlock,
9
11
  } from './narrative-context';
10
- import { CommandSlice, QuerySlice, ReactSlice, ExperienceSlice } from './index';
11
- import { print, ASTNode } from 'graphql';
12
- import createDebug from 'debug';
12
+ import type { Integration } from './types';
13
13
 
14
14
  const debug = createDebug('auto:narrative:fluent-builder');
15
15
  if ('color' in debug && typeof debug === 'object') {
@@ -1,11 +1,11 @@
1
- import { describe, expect, it, beforeEach } from 'vitest';
2
- import { getNarratives, clearGetNarrativesCache } from './getNarratives';
3
- import { InMemoryFileStore, type IFileStore } from '@auto-engineer/file-store';
4
- import * as flowApi from './narrative';
5
- import * as fluent from './fluent-builder';
1
+ import { type IFileStore, InMemoryFileStore } from '@auto-engineer/file-store';
2
+ import gql from 'graphql-tag';
3
+ import { beforeEach, describe, expect, it } from 'vitest';
6
4
  import * as dataBuilders from './data-narrative-builders';
5
+ import * as fluent from './fluent-builder';
6
+ import { clearGetNarrativesCache, getNarratives } from './getNarratives';
7
+ import * as flowApi from './narrative';
7
8
  import * as typesApi from './types';
8
- import gql from 'graphql-tag';
9
9
 
10
10
  const importMap = {
11
11
  '../flow': flowApi,
@@ -1,11 +1,11 @@
1
- import { beforeEach, describe, expect, it } from 'vitest';
2
- import { modelSchema } from './schema';
3
- import { DataSource, Example, Narrative, Model, modelToNarrative, QuerySlice } from './index';
4
- import { fileURLToPath } from 'url';
5
- import path from 'path';
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
6
3
  import { InMemoryFileStore } from '@auto-engineer/file-store';
7
4
  import { NodeFileStore } from '@auto-engineer/file-store/node';
5
+ import { beforeEach, describe, expect, it } from 'vitest';
8
6
  import { getNarratives } from './getNarratives';
7
+ import { type DataSource, type Example, type Model, modelToNarrative, type Narrative, type QuerySlice } from './index';
8
+ import { modelSchema } from './schema';
9
9
 
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = path.dirname(__filename);
@@ -688,7 +688,7 @@ flow('questionnaires-test', () => {
688
688
  validateQuestionnaireBugFix(model);
689
689
  });
690
690
 
691
- it('should convert all given events to eventRef', async function (): Promise<void> {
691
+ it('should convert all given events to eventRef', async (): Promise<void> => {
692
692
  const memoryVfs = new InMemoryFileStore();
693
693
  const todoSummaryFlowContent = `
694
694
  import { flow, query, specs, rule, example, type Event, type State } from '@auto-engineer/narrative';
@@ -1,10 +1,10 @@
1
+ import type { IFileStore } from '@auto-engineer/file-store';
1
2
  import createDebug from 'debug';
3
+ import { sha256 } from 'js-sha256';
4
+ import type { Model, Narrative } from './index';
5
+ import { executeAST } from './loader';
2
6
  import { registry } from './narrative-registry';
3
- import type { Narrative, Model } from './index';
4
7
  import { narrativesToModel } from './transformers/narrative-to-model';
5
- import type { IFileStore } from '@auto-engineer/file-store';
6
- import { executeAST } from './loader';
7
- import { sha256 } from 'js-sha256';
8
8
 
9
9
  const dirnamePosix = (p: string) => {
10
10
  const s = p.replace(/\/+$/, '');
@@ -22,7 +22,15 @@ const CACHE_VERSION = 'v1';
22
22
 
23
23
  function stableStringify(obj: Record<string, unknown>) {
24
24
  const keys = Object.keys(obj).sort();
25
- return JSON.stringify(keys.reduce((a, k) => ((a[k] = obj[k]), a), {} as Record<string, unknown>));
25
+ return JSON.stringify(
26
+ keys.reduce(
27
+ (acc, key) => {
28
+ acc[key] = obj[key];
29
+ return acc;
30
+ },
31
+ {} as Record<string, unknown>,
32
+ ),
33
+ );
26
34
  }
27
35
 
28
36
  function toUint8(view: ArrayBuffer | Uint8Array): Uint8Array {
@@ -1,6 +1,6 @@
1
- import { describe, it, expect } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { Model } from '../index';
2
3
  import { addAutoIds } from './';
3
- import { Model } from '../index';
4
4
 
5
5
  describe('addAutoIds', () => {
6
6
  const flows: Model = {
@@ -1,5 +1,5 @@
1
+ import type { ClientSpecNode, Example, Model, Rule, Slice, Spec, Step } from '../index';
1
2
  import { generateAutoId } from './generators';
2
- import { Model, Slice, Spec, Rule, Example, Step, ClientSpecNode } from '../index';
3
3
 
4
4
  function ensureId(item: { id?: string }): void {
5
5
  if (item.id === undefined || item.id === '') {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { hasAllIds, addAutoIds } from './index';
3
2
  import type { Model } from '../index';
3
+ import { addAutoIds, hasAllIds } from './index';
4
4
 
5
5
  describe('hasAllIds', () => {
6
6
  const createModelWithoutIds = (): Model => ({
@@ -1,4 +1,4 @@
1
- import { Model, Slice, Spec, Rule, Example, Step, ClientSpecNode } from '../index';
1
+ import type { ClientSpecNode, Example, Model, Rule, Slice, Spec, Step } from '../index';
2
2
 
3
3
  function hasValidId(item: { id?: string }): boolean {
4
4
  return item.id !== undefined && item.id !== '';
package/src/id/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { hasAllIds } from './hasAllIds';
2
1
  export { addAutoIds } from './addAutoIds';
2
+ export { hasAllIds } from './hasAllIds';
package/src/index.ts CHANGED
@@ -1,26 +1,25 @@
1
- import { z } from 'zod';
1
+ import type { z } from 'zod';
2
2
 
3
+ // Apollo GraphQL
4
+ export { gql } from 'graphql-tag';
5
+ export { DataSinkSchema, DataSourceSchema, MessageTargetSchema } from './schema';
3
6
  // Core types and utilities
4
7
  export type {
5
- Integration,
8
+ Command,
9
+ DataItem,
6
10
  DataSink,
7
- DataSource,
8
11
  DataSinkItem,
12
+ DataSource,
9
13
  DataSourceItem,
10
- DataItem,
11
- MessageTarget,
12
14
  Destination,
15
+ Event,
16
+ Integration,
17
+ MessageTarget,
13
18
  Origin,
14
19
  State,
15
- Command,
16
- Event,
17
20
  } from './types';
18
- export { MessageTargetSchema, DataSinkSchema, DataSourceSchema } from './schema';
19
21
  export { createIntegration } from './types';
20
22
 
21
- // Apollo GraphQL
22
- export { gql } from 'graphql-tag';
23
-
24
23
  // HTTP GET template literal function
25
24
  export const get = (strings: TemplateStringsArray, ...values: unknown[]) => {
26
25
  return strings.reduce((result, str, i) => {
@@ -29,75 +28,83 @@ export const get = (strings: TemplateStringsArray, ...values: unknown[]) => {
29
28
  }, '');
30
29
  };
31
30
 
31
+ export type { ExportSchemaEvents } from './commands/export-schema';
32
+ export type { FieldSelector } from './data-narrative-builders';
33
+
34
+ // Data narrative builders
35
+ export { sink, source } from './data-narrative-builders';
32
36
  // Fluent API
33
37
  export type {
34
38
  FluentCommandSliceBuilder,
39
+ FluentExperienceSliceBuilder,
35
40
  FluentQuerySliceBuilder,
36
41
  FluentReactionSliceBuilder,
37
- FluentExperienceSliceBuilder,
38
42
  } from './fluent-builder';
39
- export { command, query, react, experience, decide, evolve } from './fluent-builder';
40
-
41
- // Data narrative builders
42
- export { sink, source } from './data-narrative-builders';
43
- export type { FieldSelector } from './data-narrative-builders';
44
-
45
- // Narrative language functions
46
- export { narrative, narrative as flow } from './narrative';
47
- export { client, server, specs, describe, it, should, request, data, rule, example, thenError } from './narrative';
48
- export type { ExampleBuilder, GivenBuilder, WhenBuilder, ThenBuilder } from './narrative';
49
- export type { SliceTypeValueInterface } from './narrative';
50
- export { SliceType } from './narrative';
51
-
43
+ export { command, decide, evolve, experience, query, react } from './fluent-builder';
52
44
  // Narrative conversion utilities
53
45
  export { getNarratives } from './getNarratives';
54
- export { modelToNarrative } from './transformers/model-to-narrative';
55
-
56
- export type { ExportSchemaEvents } from './commands/export-schema';
57
-
58
- // Testing helpers
59
- export { createNarrativeSpec, given as testGiven, when as testWhen } from './testing';
60
-
46
+ export type { ExampleBuilder, GivenBuilder, SliceTypeValueInterface, ThenBuilder, WhenBuilder } from './narrative';
47
+ // Narrative language functions
48
+ export {
49
+ client,
50
+ data,
51
+ describe,
52
+ example,
53
+ it,
54
+ narrative,
55
+ narrative as flow,
56
+ request,
57
+ rule,
58
+ SliceType,
59
+ server,
60
+ should,
61
+ specs,
62
+ thenError,
63
+ } from './narrative';
61
64
  // Schema definitions for progressive narrative creation
62
65
  export {
63
- NarrativeNamesSchema as NarrativeNamesSystemSchema,
64
- SliceNamesSchema as SliceNamesSystemSchema,
65
66
  ClientServerNamesSchema as ClientServerNamesSystemSchema,
66
- modelSchema as SpecsSystemSchema,
67
- MessageFieldSchema,
68
- MessageSchema,
69
67
  CommandSchema,
68
+ CommandSliceSchema,
70
69
  EventSchema,
71
- StateSchema,
70
+ ExampleSchema,
71
+ ExperienceSliceSchema,
72
72
  IntegrationSchema,
73
- CommandSliceSchema,
73
+ MessageFieldSchema,
74
+ MessageSchema,
75
+ modelSchema as SpecsSystemSchema,
76
+ modelSchema,
77
+ NarrativeNamesSchema as NarrativeNamesSystemSchema,
78
+ NarrativeSchema,
74
79
  QuerySliceSchema,
75
80
  ReactSliceSchema,
76
- ExperienceSliceSchema,
77
- SliceSchema,
78
- NarrativeSchema,
79
- modelSchema,
80
- ExampleSchema,
81
81
  RuleSchema,
82
+ SliceNamesSchema as SliceNamesSystemSchema,
83
+ SliceSchema,
82
84
  SpecSchema,
83
- StepSchema,
85
+ StateSchema,
84
86
  StepErrorSchema,
87
+ StepSchema,
85
88
  StepWithDocStringSchema,
86
89
  StepWithErrorSchema,
87
90
  } from './schema';
88
91
 
89
- import {
90
- NarrativeSchema,
91
- SliceSchema,
92
+ // Testing helpers
93
+ export { createNarrativeSpec, given as testGiven, when as testWhen } from './testing';
94
+ export { modelToNarrative } from './transformers/model-to-narrative';
95
+
96
+ import type {
97
+ CommandSliceSchema,
98
+ ExampleSchema,
99
+ ExperienceSliceSchema,
100
+ MessageFieldSchema,
101
+ MessageSchema,
92
102
  modelSchema,
103
+ NarrativeSchema,
93
104
  QuerySliceSchema,
94
105
  ReactSliceSchema,
95
- ExperienceSliceSchema,
96
- MessageSchema,
97
- MessageFieldSchema,
98
- CommandSliceSchema,
99
- ExampleSchema,
100
106
  RuleSchema,
107
+ SliceSchema,
101
108
  SpecSchema,
102
109
  StepSchema,
103
110
  } from './schema';
@@ -114,7 +121,7 @@ export type MessageField = z.infer<typeof MessageFieldSchema>;
114
121
  export type Rule = z.infer<typeof RuleSchema>;
115
122
  export type Spec = z.infer<typeof SpecSchema>;
116
123
  export type Step = z.infer<typeof StepSchema>;
117
- export type { ClientSpecNode } from './schema';
118
124
 
119
125
  // ID assignment utilities
120
126
  export { addAutoIds, hasAllIds } from './id';
127
+ export type { ClientSpecNode } from './schema';