@sitecoreai-labs/sitecoreai-cli 0.1.2 → 0.2.1

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 (65) hide show
  1. package/dist/agents/tasks/agent.js +2 -2
  2. package/dist/agents/tasks/resources.js +2 -2
  3. package/dist/agents/tasks/space.js +1 -1
  4. package/dist/brand/api/auth.d.ts +16 -9
  5. package/dist/brand/api/auth.js +29 -19
  6. package/dist/brand/credential.d.ts +71 -1
  7. package/dist/brand/credential.js +119 -2
  8. package/dist/brand/recipe/diff.js +7 -2
  9. package/dist/brand/recipe/kind.js +0 -0
  10. package/dist/brand/recipe/schema.d.ts +113 -7
  11. package/dist/brand/recipe/schema.js +137 -8
  12. package/dist/brand/seed.d.ts +9 -5
  13. package/dist/brand/seed.js +30 -5
  14. package/dist/brief/api/briefs.d.ts +8 -0
  15. package/dist/brief/api/briefs.js +49 -11
  16. package/dist/brief/index.d.ts +1 -1
  17. package/dist/brief/index.js +2 -1
  18. package/dist/brief/recipe/index.d.ts +11 -2
  19. package/dist/brief/recipe/index.js +17 -3
  20. package/dist/brief/recipe/instance-diff.d.ts +4 -0
  21. package/dist/brief/recipe/instance-diff.js +77 -0
  22. package/dist/brief/recipe/instance-kind.d.ts +4 -0
  23. package/dist/brief/recipe/instance-kind.js +190 -0
  24. package/dist/brief/recipe/instance-schema.d.ts +61 -0
  25. package/dist/brief/recipe/instance-schema.js +68 -0
  26. package/dist/brief/recipe/schema.js +4 -1
  27. package/dist/brief/tasks/index.d.ts +35 -0
  28. package/dist/brief/tasks/index.js +62 -1
  29. package/dist/campaigns/recipe/schema.d.ts +39 -8
  30. package/dist/campaigns/recipe/schema.js +40 -10
  31. package/dist/commands/agents/sync.js +2 -2
  32. package/dist/commands/brand/seed.js +1 -1
  33. package/dist/commands/brand/sync.js +2 -2
  34. package/dist/commands/brief/create.d.ts +2 -0
  35. package/dist/commands/brief/create.js +56 -0
  36. package/dist/commands/brief/index.d.ts +3 -1
  37. package/dist/commands/brief/index.js +11 -1
  38. package/dist/commands/brief/sync.d.ts +9 -6
  39. package/dist/commands/brief/sync.js +54 -22
  40. package/dist/commands/brief/update.d.ts +2 -0
  41. package/dist/commands/brief/update.js +84 -0
  42. package/dist/commands/campaign/sync.js +2 -2
  43. package/dist/mcp/descriptions.js +3 -3
  44. package/dist/mcp/tools/brief-recipe.js +67 -23
  45. package/dist/mcp/tools/brief.js +83 -6
  46. package/dist/recipe/compile/design-parameters-template.js +5 -3
  47. package/dist/recipe/compile/enumeration.js +6 -11
  48. package/dist/recipe/compile/shared.js +12 -12
  49. package/dist/recipe/compile.js +4 -4
  50. package/dist/recipe/io.d.ts +8 -3
  51. package/dist/recipe/io.js +11 -81
  52. package/dist/recipe/items/read-current.js +31 -24
  53. package/dist/recipe/schema/recipe.d.ts +167 -84
  54. package/dist/recipe/schema/recipe.js +130 -46
  55. package/dist/recipe/schema/source-fields.d.ts +20 -0
  56. package/dist/recipe/schema/source-fields.js +25 -1
  57. package/dist/recipe/validate.d.ts +3 -3
  58. package/dist/recipe/validate.js +20 -10
  59. package/dist/sync/aggregate-kinds.js +1 -0
  60. package/dist/sync/aggregate.js +2 -2
  61. package/dist/sync/io.d.ts +13 -3
  62. package/dist/sync/io.js +43 -17
  63. package/dist/sync/typescript-recipe.d.ts +30 -0
  64. package/dist/sync/typescript-recipe.js +112 -0
  65. package/package.json +1 -1
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /**
3
+ * Shared `.recipe.ts` loader.
4
+ *
5
+ * Authored recipes (CMS, brand-kit, agents, campaigns, briefs, etc.) all
6
+ * load through this path so end users can write `.recipe.ts` files with
7
+ * Zod-derived types and `satisfies` checks. The transpile + sandboxed
8
+ * execute machinery is owned by `@/recipe/sandbox` — this module is the
9
+ * thin wrapper that picks between the confined child and the legacy
10
+ * in-process tsx loader, and is consumed by both:
11
+ *
12
+ * - `src/sync/io.ts:loadRecipe` (schema-aware loader used by brand,
13
+ * agents, campaigns, briefs, …)
14
+ * - `src/recipe/io.ts:loadRecipe` (CMS recipe discriminated-union loader)
15
+ *
16
+ * Output is unvalidated — callers Zod-parse the returned value. See
17
+ * docs/recipe-sandbox.md.
18
+ */
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.loadTypeScriptRecipe = exports.isTypeScriptRecipePath = void 0;
24
+ const node_path_1 = __importDefault(require("node:path"));
25
+ const errors_1 = require("../shared/errors");
26
+ const load_1 = require("../recipe/sandbox/load");
27
+ /** Extensions this loader recognizes as TypeScript-source recipes. */
28
+ const TS_EXTENSIONS = new Set([".ts", ".tsx", ".mts", ".cts"]);
29
+ /** Whether the given file path should be loaded via the TypeScript path. */
30
+ const isTypeScriptRecipePath = (filePath) => TS_EXTENSIONS.has(node_path_1.default.extname(filePath).toLowerCase());
31
+ exports.isTypeScriptRecipePath = isTypeScriptRecipePath;
32
+ /**
33
+ * Load a `.recipe.ts` (or `.tsx`/`.mts`/`.cts`) file and return its
34
+ * exported recipe value. By default the file is loaded in a confined
35
+ * child process (see docs/recipe-sandbox.md) so a hostile recipe cannot
36
+ * run with scai's full privileges. `SITECOREAI_RECIPE_SANDBOX=0` forces
37
+ * the legacy in-process loader (useful for debugging — the warning lands
38
+ * on stderr so JSON-mode CLI streams are not corrupted).
39
+ *
40
+ * The result is unvalidated: callers Zod-parse it.
41
+ */
42
+ const loadTypeScriptRecipe = async (filePath) => {
43
+ if ((0, load_1.isRecipeSandboxEnabled)()) {
44
+ return (0, load_1.loadRecipeInSandbox)(filePath);
45
+ }
46
+ warnSandboxDisabled();
47
+ return loadRecipeInProcess(filePath);
48
+ };
49
+ exports.loadTypeScriptRecipe = loadTypeScriptRecipe;
50
+ /**
51
+ * Lazily install tsx's CommonJS require hook *once* per process. Earlier
52
+ * versions of this loader called `register()` and the matching
53
+ * `unregister` cleanup on every load — fine for one-shot CLI runs but
54
+ * wasteful in long-running surfaces (e.g. `scai cli shell`) where N
55
+ * recipe loads = N register/unregister cycles. Once installed, the hook
56
+ * stays for the rest of the process lifetime; recipe changes mid-session
57
+ * therefore require an exit. The per-recipe `require.cache` clear below
58
+ * handles re-imports of the *same* file path within the same process.
59
+ */
60
+ let tsxRegistered = false;
61
+ const ensureTsxRegistered = () => {
62
+ if (tsxRegistered) {
63
+ return;
64
+ }
65
+ /* eslint-disable @typescript-eslint/no-require-imports */
66
+ const tsxApi = require("tsx/cjs/api");
67
+ /* eslint-enable @typescript-eslint/no-require-imports */
68
+ tsxApi.register();
69
+ tsxRegistered = true;
70
+ };
71
+ let sandboxOptOutWarned = false;
72
+ const warnSandboxDisabled = () => {
73
+ if (sandboxOptOutWarned) {
74
+ return;
75
+ }
76
+ sandboxOptOutWarned = true;
77
+ // Stderr (not stdout) — MCP and `--json` callers parse stdout as a
78
+ // structured stream and must not see this warning interleaved.
79
+ process.stderr.write("scai: SITECOREAI_RECIPE_SANDBOX=0 — loading .recipe.ts in-process; " +
80
+ "a hostile recipe runs with scai's full privileges.\n");
81
+ };
82
+ const loadRecipeInProcess = async (filePath) => {
83
+ const absolute = node_path_1.default.resolve(filePath);
84
+ try {
85
+ ensureTsxRegistered();
86
+ if (require.cache[absolute]) {
87
+ delete require.cache[absolute];
88
+ }
89
+ /* eslint-disable @typescript-eslint/no-require-imports */
90
+ const mod = require(absolute);
91
+ /* eslint-enable @typescript-eslint/no-require-imports */
92
+ if (mod.default !== undefined) {
93
+ return mod.default;
94
+ }
95
+ // Fall back to the first non-default exported value.
96
+ for (const key of Object.keys(mod)) {
97
+ if (key !== "default" && mod[key] !== undefined) {
98
+ return mod[key];
99
+ }
100
+ }
101
+ throw (0, errors_1.createScaiError)(`Recipe at ${filePath} has no exports.`, "INPUT_INVALID", {
102
+ hint: "Add `export default <recipe>` (or any named export) to the file.",
103
+ });
104
+ }
105
+ catch (error) {
106
+ // Don't double-wrap our own ScaiErrors (e.g. "Recipe at <path> has no exports.").
107
+ if (error instanceof errors_1.ScaiError) {
108
+ throw error;
109
+ }
110
+ throw (0, errors_1.createScaiError)(`Failed to load recipe TypeScript file ${filePath}: ${error instanceof Error ? error.message : String(error)}`, "INPUT_INVALID", { hint: "Confirm the file compiles standalone (try `pnpm exec tsx <file>`)." });
111
+ }
112
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecoreai-labs/sitecoreai-cli",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "SitecoreAI developer toolkit — a native TypeScript CLI, SDK, and MCP server for deploy, serialization, recipes, publishing, and content operations.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",