@wix/ditto-codegen-public 1.0.357 → 1.0.358

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.
@@ -0,0 +1,130 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { readFile } from "fs/promises";
3
+ import { join, isAbsolute, relative } from "path";
4
+
5
+ // `wix generate --params <json>` prints one JSON line to stdout (`--params` implies
6
+ // `--json`; see wix-cli commands/generate.tsx). We only depend on `newFiles`; any
7
+ // other shape is treated as a failure and surfaced to the agent verbatim.
8
+ interface GenerateResult {
9
+ success: boolean;
10
+ extensionType?: string;
11
+ newFiles?: string[];
12
+ error?: string;
13
+ }
14
+
15
+ function asResult(raw: string): GenerateResult | null {
16
+ try {
17
+ const parsed = JSON.parse(raw);
18
+ return parsed && typeof parsed === "object" && "success" in parsed
19
+ ? (parsed as GenerateResult)
20
+ : null;
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+
26
+ // Extract the JSON result object from stdout. The CLI prints the result as a
27
+ // single JSON line, but may surround it with unrelated lines (e.g. an npm
28
+ // "Update available" notice box), so we can't assume the whole output is JSON:
29
+ // try the whole output first, then fall back to scanning individual lines.
30
+ function parseGenerateOutput(stdout: string): GenerateResult | null {
31
+ const whole = asResult(stdout.trim());
32
+ if (whole) return whole;
33
+
34
+ for (const line of stdout.split("\n")) {
35
+ const result = asResult(line.trim());
36
+ if (result) return result;
37
+ }
38
+
39
+ return null;
40
+ }
41
+
42
+ export default tool({
43
+ description:
44
+ "Scaffold one or more Wix extensions non-interactively via `wix generate --params`. " +
45
+ "The Wix CLI writes the boilerplate (extension file, config, and registration) " +
46
+ "deterministically, and this tool returns the full contents of every file it created " +
47
+ "so you can edit them directly WITHOUT reading them back. Strongly prefer this over " +
48
+ "hand-writing extension boilerplate.",
49
+ args: {
50
+ extensions: tool.schema
51
+ .array(
52
+ tool.schema.object({
53
+ params: tool.schema
54
+ .object({
55
+ extensionType: tool.schema
56
+ .string()
57
+ .describe("The extension type to generate."),
58
+ })
59
+ .passthrough()
60
+ .describe(
61
+ "The `wix generate --params` config object: `extensionType` plus the " +
62
+ "type-specific fields (e.g. a DATA_COLLECTION needs `collectionName`, an " +
63
+ "EVENT needs an event identifier). Discover the exact fields for each type " +
64
+ "via the wix-app skill or `wix schema generate`.",
65
+ ),
66
+ }),
67
+ )
68
+ .describe(
69
+ "The extensions to scaffold. Each entry runs one `wix generate --params` call; " +
70
+ "pass several to scaffold them in a single tool call.",
71
+ ),
72
+ },
73
+ async execute(args, context) {
74
+ const cwd = context.directory;
75
+ const blocks: string[] = [];
76
+
77
+ for (const { params } of args.extensions) {
78
+ const type =
79
+ typeof params.extensionType === "string" ? params.extensionType : "?";
80
+
81
+ const res = await Bun.$`npx wix generate --params ${JSON.stringify(params)}`
82
+ .cwd(cwd)
83
+ .nothrow()
84
+ .quiet();
85
+
86
+ const stdout = res.stdout.toString();
87
+ const result = parseGenerateOutput(stdout);
88
+
89
+ // No recognizable `--json` result line: the CLI's output contract likely
90
+ // changed. A format change breaks every extension equally, so don't emit
91
+ // per-extension FAILED noise — abort the batch with one message telling the
92
+ // agent to fall back to running `wix generate` itself via bash.
93
+ if (!result) {
94
+ return [
95
+ "=== wix-generate could not read `wix generate` output ===",
96
+ "`wix generate --params` did not return its expected JSON result, so this " +
97
+ "tool can't extract the created files (the CLI output format may have " +
98
+ "changed). Fall back to the bash tool: run " +
99
+ "`npx wix generate --params '<params-json>'` for each extension yourself, " +
100
+ "then read the files it creates.",
101
+ "",
102
+ `Raw output (exit ${res.exitCode}):`,
103
+ stdout.trim() || res.stderr.toString().trim() || "(no output)",
104
+ ].join("\n");
105
+ }
106
+
107
+ const newFiles = result.success ? result.newFiles : undefined;
108
+
109
+ if (!newFiles?.length) {
110
+ const detail =
111
+ result.error ||
112
+ res.stderr.toString().trim() ||
113
+ stdout.trim() ||
114
+ "(no output)";
115
+ blocks.push(`=== FAILED: ${type} (exit ${res.exitCode}) ===\n${detail}`);
116
+ continue;
117
+ }
118
+
119
+ const files = await Promise.all(
120
+ newFiles.map(async (file) => {
121
+ const abs = isAbsolute(file) ? file : join(cwd, file);
122
+ return `--- ${relative(cwd, abs)} ---\n${await readFile(abs, "utf-8")}`;
123
+ }),
124
+ );
125
+ blocks.push(`=== ${result.extensionType ?? type} ===\n${files.join("\n\n")}`);
126
+ }
127
+
128
+ return blocks.join("\n\n");
129
+ },
130
+ });
package/dist/out.js CHANGED
@@ -12170,6 +12170,7 @@ TOOL USAGE:
12170
12170
  - "Building project"
12171
12171
  - \`validate\` for all validation (tsc + build).
12172
12172
  - \`uuid\` to generate UUIDs (supports count param for multiple). Do NOT use bash.
12173
+ - \`wix-generate\` to scaffold extensions non-interactively (wraps \`wix generate --params\`). Prefer it over hand-writing extension boilerplate. It RETURNS the full contents of every file the CLI created, so trust that output and do NOT \`read\`/\`batch-read\` those files afterward. If it returns a \`FAILED\` block, fix the params per the error and retry. Pass an array to scaffold several extensions in one call.
12173
12174
  - \`required-permissions\` to declare the Wix app permissions the generated code needs. Call it ONCE at the end, and ONLY if permissions are actually needed \u2014 don't call it otherwise (see PERMISSIONS).
12174
12175
  - File operations \u2014 pick the BATCH tool whenever you have 2+ files; the single-file variants are 5\u201310\xD7 slower:
12175
12176
  - \`batch-write\` to create N new files in one call. NEVER call \`write\` more than once per turn \u2014 use batch-write instead. \`write\` is reserved for single-file creation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.357",
3
+ "version": "1.0.358",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -29,5 +29,5 @@
29
29
  "esbuild": "^0.27.2",
30
30
  "vitest": "^4.0.16"
31
31
  },
32
- "falconPackageHash": "236fead8ed789d2e79367a542151458b9890fc135b057e67784bb6f9"
32
+ "falconPackageHash": "d71ce4d5b338ba060f5d9cf26324f43ddd3dae5b5120be5e30903e01"
33
33
  }