@algolia/wizard 0.18.0 → 0.19.0-rc.111.189

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 (3) hide show
  1. package/README.md +0 -14
  2. package/dist/main.js +307 -421
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,22 +12,8 @@ npx @algolia/wizard
12
12
 
13
13
  # run a specific workflow by id
14
14
  npx @algolia/wizard <workflow-id>
15
-
16
- # see all options
17
- npx @algolia/wizard --help
18
15
  ```
19
16
 
20
- ### Options
21
-
22
- | Flag | Effect |
23
- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
- | `--seed <step-id>` | Start the workflow at the step with this id (e.g. `--seed ingestion`), with the earlier steps pre-filled with test data. Pass with no value to print the step ids. |
25
- | `--no-telemetry` | Send no telemetry or analytics for this run. |
26
- | `--reset-on-run` | Wipe this project's wizard state (run state, AI-changes consent, worktrees) before starting, so the run behaves like a first-ever run. Credentials are untouched. |
27
- | `-h`, `--help` | Print usage. |
28
-
29
- `--seed` pre-fills the earlier steps with fabricated data so a single step can be exercised without running the whole workflow — useful for testing a step, not for a real implementation. It replaces any in-progress run for that workflow and pre-grants the AI-changes consent. See [Starting mid-workflow](CONTRIBUTING.md#starting-mid-workflow---seed).
30
-
31
17
  On first run, Wizard checks whether you're signed in to the Algolia CLI. If you aren't, it runs `algolia auth login --non-interactive` — the browser opens for sign-in, and no prompts land in the wizard's terminal. It then asks which Algolia application to work in (skipping the question when the account has only one) and makes it current with `algolia application select`.
32
18
 
33
19
  You'll also be asked once to consent to AI-authored changes to the repository.
package/dist/main.js CHANGED
@@ -251,6 +251,7 @@ var useWizard = create((set, get) => ({
251
251
  _noticeTimer: null,
252
252
  cliOutput: [],
253
253
  targetIndex: null,
254
+ writtenFiles: [],
254
255
  logs: [],
255
256
  error: null,
256
257
  inputReq: null,
@@ -344,6 +345,8 @@ var useWizard = create((set, get) => ({
344
345
  })),
345
346
  clearCliOutput: () => set({ cliOutput: [] }),
346
347
  setTargetIndex: (index) => set({ targetIndex: index }),
348
+ recordWrittenFile: (path) => set((s) => ({ writtenFiles: [...s.writtenFiles, path] })),
349
+ clearWrittenFiles: () => set({ writtenFiles: [] }),
347
350
  logStart: (kind, name, input) => {
348
351
  const id = nanoid();
349
352
  set((s) => ({
@@ -391,6 +394,7 @@ var useWizard = create((set, get) => ({
391
394
  notices: [],
392
395
  cliOutput: [],
393
396
  targetIndex: null,
397
+ writtenFiles: [],
394
398
  logs: [],
395
399
  error: null,
396
400
  inputReq: null,
@@ -1200,7 +1204,7 @@ var accessItems = [
1200
1204
  {
1201
1205
  tag: "WRITE",
1202
1206
  title: "Code changes",
1203
- description: "creates & edits files (search UI, config) in a throwaway git worktree \u2014 your checkout is never touched."
1207
+ description: "creates & edits files (search UI, config) directly in your branch. You are asked to confirm first if it has uncommitted changes."
1204
1208
  },
1205
1209
  {
1206
1210
  tag: "EXEC",
@@ -1215,7 +1219,7 @@ var accessItems = [
1215
1219
  {
1216
1220
  tag: "KEY",
1217
1221
  title: "Credentials",
1218
- description: "writes your Algolia app id and a search-only key (safe to expose) to .env in the worktree."
1222
+ description: "writes your Algolia app id and a search-only key (safe to expose) to .env in your project."
1219
1223
  }
1220
1224
  ];
1221
1225
  var neverItems = [
@@ -2496,6 +2500,7 @@ function writeFileTool(ctx) {
2496
2500
  }
2497
2501
  await mkdir3(dirname4(resolved2.target), { recursive: true });
2498
2502
  await writeFile3(resolved2.target, content, "utf8");
2503
+ useWizard.getState().recordWrittenFile(resolved2.target);
2499
2504
  return `Wrote to ${filePath}`;
2500
2505
  } catch (err) {
2501
2506
  return `Error writing ${filePath}: ${err.message}`;
@@ -3246,7 +3251,7 @@ var anthropic = createAnthropic({
3246
3251
  });
3247
3252
  function generateRecordTool(ctx) {
3248
3253
  return tool10({
3249
- description: "Generate realistic sample records for an entity and write them to a JSON file in the worktree. Provide the entity name and its attributes; this tool asks a model to invent varied, realistic values, each with a unique objectID, and returns the file path to read them from at runtime. Do not invent the record values or objectIDs yourself, and do not inline the returned records into the script \u2014 call this tool and read the file it writes.",
3254
+ description: "Generate realistic sample records for an entity and write them to a JSON file. Provide the entity name and its attributes; this tool asks a model to invent varied, realistic values, each with a unique objectID, and returns the file path to read them from at runtime. Do not invent the record values or objectIDs yourself, and do not inline the returned records into the script \u2014 call this tool and read the file it writes.",
3250
3255
  inputSchema: z17.object({
3251
3256
  entityName: z17.string().describe("Name of the entity to generate records for."),
3252
3257
  attributes: z17.array(z17.string()).describe("Attribute names each record must contain."),
@@ -3604,7 +3609,7 @@ async function runAnalysis(mode, extraInstructions = []) {
3604
3609
  // package.json
3605
3610
  var package_default = {
3606
3611
  name: "@algolia/wizard",
3607
- version: "0.18.0",
3612
+ version: "0.19.0-rc.111.189",
3608
3613
  description: "Magically implement Algolia functionality in your codebase",
3609
3614
  type: "module",
3610
3615
  engines: {
@@ -3971,11 +3976,10 @@ ${JSON.stringify(s.output, null, 2)}`
3971
3976
  function formatReviewSummary(result) {
3972
3977
  const nextStepLines = result.nextSteps.map((step) => {
3973
3978
  const isIngestCommand = step.includes(".algolia-wizard/ingest.sh");
3974
- const isWorktreeCommand = step.includes("/worktrees/");
3975
3979
  return {
3976
3980
  text: `\u2192 ${step}`,
3977
- color: isIngestCommand ? COLORS.brand : isWorktreeCommand ? COLORS.secondary : void 0,
3978
- bold: isIngestCommand || isWorktreeCommand
3981
+ color: isIngestCommand ? COLORS.brand : void 0,
3982
+ bold: isIngestCommand
3979
3983
  };
3980
3984
  });
3981
3985
  return [
@@ -4010,15 +4014,13 @@ ${formatCompletedSteps(ctx.completedSteps)}`,
4010
4014
 
4011
4015
  // src/actions/implement.ts
4012
4016
  import z28 from "zod";
4013
- import { join as join12 } from "node:path";
4017
+ import { join as join12, relative as relative6 } from "node:path";
4014
4018
 
4015
- // src/lib/worktree.ts
4019
+ // src/lib/git.ts
4016
4020
  import { execFile as execFile2 } from "node:child_process";
4017
- import { copyFile, mkdir as mkdir6, readdir as readdir3, readFile as readFile8, stat as stat3, writeFile as writeFile7 } from "node:fs/promises";
4021
+ import { copyFile, mkdir as mkdir6, readFile as readFile8, stat as stat3, writeFile as writeFile7 } from "node:fs/promises";
4018
4022
  import { basename as basename2, dirname as dirname7, isAbsolute as isAbsolute2, join as join10, resolve as resolve3 } from "node:path";
4019
4023
  var MAX_BUFFER = 32 * 1024 * 1024;
4020
- var MAX_WIZARD_WORKTREES = 3;
4021
- var WIZARD_BRANCH_PREFIX = "wizard/implement-";
4022
4024
  function git(args) {
4023
4025
  return new Promise((resolve4, reject) => {
4024
4026
  execFile2("git", args, { maxBuffer: MAX_BUFFER }, (err, stdout, stderr) => {
@@ -4041,44 +4043,7 @@ async function assertGitRepoWithHead(repoRoot) {
4041
4043
  );
4042
4044
  }
4043
4045
  }
4044
- async function isWorkingTreeDirty(repoRoot) {
4045
- const out = await git(["-C", repoRoot, "status", "--porcelain"]);
4046
- return out.trim().length > 0;
4047
- }
4048
- async function pruneOldWorktrees(repoRoot) {
4049
- const dir = join10(stateDir(repoRoot), "worktrees");
4050
- const stale = (await readdir3(dir).catch(() => [])).filter((name) => /^wizard-implement-\d+$/.test(name)).sort().reverse().slice(MAX_WIZARD_WORKTREES - 1);
4051
- for (const slug of stale) {
4052
- const branch = slug.replace("wizard-implement-", WIZARD_BRANCH_PREFIX);
4053
- try {
4054
- await git([
4055
- "-C",
4056
- repoRoot,
4057
- "worktree",
4058
- "remove",
4059
- "--force",
4060
- join10(dir, slug)
4061
- ]);
4062
- await git(["-C", repoRoot, "branch", "-D", branch]);
4063
- } catch (err) {
4064
- logger.warn(
4065
- { branch, err: err.message },
4066
- "createWorktree: failed to prune a stale wizard worktree; continuing"
4067
- );
4068
- }
4069
- }
4070
- }
4071
- async function createWorktree(repoRoot) {
4072
- const branch = `${WIZARD_BRANCH_PREFIX}${Date.now()}`;
4073
- const dirSlug = branch.replace(/\//g, "-");
4074
- const path = join10(stateDir(repoRoot), "worktrees", dirSlug);
4075
- await git(["-C", repoRoot, "worktree", "prune"]);
4076
- await pruneOldWorktrees(repoRoot);
4077
- await mkdir6(dirname7(path), { recursive: true });
4078
- await git(["-C", repoRoot, "worktree", "add", "-b", branch, path, "HEAD"]);
4079
- return { path, branch };
4080
- }
4081
- async function copyUploadIntoWorktree(repoRoot, worktreePath, ingestDir, sourcePath) {
4046
+ async function copyUploadIntoProject(repoRoot, ingestDir, sourcePath) {
4082
4047
  const trimmed = sourcePath.trim();
4083
4048
  if (!trimmed) {
4084
4049
  return { ok: false, reason: "no file path was provided" };
@@ -4092,7 +4057,10 @@ async function copyUploadIntoWorktree(repoRoot, worktreePath, ingestDir, sourceP
4092
4057
  return { ok: false, reason: `"${sourcePath}" does not exist` };
4093
4058
  }
4094
4059
  const relPath = join10(ingestDir, basename2(source));
4095
- const dest = join10(worktreePath, relPath);
4060
+ const dest = join10(repoRoot, relPath);
4061
+ if (resolve3(source) === resolve3(dest)) {
4062
+ return { ok: true, relPath };
4063
+ }
4096
4064
  try {
4097
4065
  await mkdir6(dirname7(dest), { recursive: true });
4098
4066
  await copyFile(source, dest);
@@ -4107,10 +4075,10 @@ async function copyUploadIntoWorktree(repoRoot, worktreePath, ingestDir, sourceP
4107
4075
  function hasEnvVar(content, name) {
4108
4076
  return new RegExp(`^(\\s*(?:export\\s+)?${name})\\s*=`, "m").test(content);
4109
4077
  }
4110
- async function readEnvVar(worktreePath, name) {
4078
+ async function readEnvVar(repoRoot, name) {
4111
4079
  let content;
4112
4080
  try {
4113
- content = await readFile8(join10(worktreePath, ".env"), "utf8");
4081
+ content = await readFile8(join10(repoRoot, ".env"), "utf8");
4114
4082
  } catch (err) {
4115
4083
  if (err.code !== "ENOENT") throw err;
4116
4084
  return void 0;
@@ -4124,8 +4092,8 @@ async function readEnvVar(worktreePath, name) {
4124
4092
  if (!value || value.startsWith("<")) return void 0;
4125
4093
  return value;
4126
4094
  }
4127
- async function writeSearchEnvValues(worktreePath, vars) {
4128
- const target = join10(worktreePath, ".env");
4095
+ async function writeSearchEnvValues(repoRoot, vars) {
4096
+ const target = join10(repoRoot, ".env");
4129
4097
  let existing = "";
4130
4098
  try {
4131
4099
  existing = await readFile8(target, "utf8");
@@ -4140,61 +4108,27 @@ async function writeSearchEnvValues(worktreePath, vars) {
4140
4108
  await writeFile7(target, existing + prefix + lines, "utf8");
4141
4109
  return missing.map((v) => v.name);
4142
4110
  }
4143
- async function listChangedFiles(worktreePath) {
4144
- const raw = await git(["-C", worktreePath, "status", "--porcelain", "-z"]);
4145
- const entries = raw.split("\0");
4146
- const files = [];
4147
- for (let i = 0; i < entries.length; i += 1) {
4148
- const entry = entries[i];
4149
- if (!entry) continue;
4150
- files.push(entry.slice(3));
4151
- if (["R", "C"].includes(entry[0]) || ["R", "C"].includes(entry[1])) i += 1;
4152
- }
4153
- return files;
4154
- }
4155
4111
  function normalizeFindingPaths(findings) {
4156
4112
  return {
4157
4113
  ...findings,
4158
4114
  ingestionAnalysis: findings.ingestionAnalysis?.map((e) => ({
4159
4115
  ...e,
4160
- paths: e.paths.map(toWorktreeRelative)
4116
+ paths: e.paths.map(toRootRelative)
4161
4117
  })),
4162
4118
  searchImplementationAnalysis: findings.searchImplementationAnalysis ? normalizeSearchLocation(findings.searchImplementationAnalysis) : void 0,
4163
4119
  confirmedEntities: findings.confirmedEntities?.map((e) => ({
4164
4120
  ...e,
4165
- paths: e.paths.map(toWorktreeRelative)
4121
+ paths: e.paths.map(toRootRelative)
4166
4122
  }))
4167
4123
  };
4168
4124
  }
4169
4125
  function normalizeSearchLocation(path) {
4170
- const normalized = path ? toWorktreeRelative(path).trim() : "";
4126
+ const normalized = path ? toRootRelative(path).trim() : "";
4171
4127
  return normalized && normalized.toLowerCase() !== "unknown" ? normalized : void 0;
4172
4128
  }
4173
- function toWorktreeRelative(p) {
4129
+ function toRootRelative(p) {
4174
4130
  return p.replace(/^\/+/, "");
4175
4131
  }
4176
- async function confirmDirtyWorkingTree(ctx, repoRoot) {
4177
- const MAX_LISTED_DIRTY_FILES = 10;
4178
- const dirty = await listChangedFiles(repoRoot);
4179
- const shown = dirty.slice(0, MAX_LISTED_DIRTY_FILES);
4180
- const overflow = dirty.length - shown.length;
4181
- const answer = await ctx.requestUserInput({
4182
- prompt: "Proceed using HEAD only? Uncommitted changes will NOT be included in the generated implementation.",
4183
- promptType: "acceptReject",
4184
- options: [],
4185
- messages: [
4186
- `${dirty.length} uncommitted change(s) detected. The wizard builds an isolated worktree from HEAD, so these are ignored:`,
4187
- ...shown.map((file) => ` \u2022 ${file}`),
4188
- ...overflow > 0 ? [` \u2022 \u2026and ${overflow} more`] : [],
4189
- "Commit or stash them first to include them in the implementation."
4190
- ]
4191
- });
4192
- if (answer !== true) {
4193
- throw new Error(
4194
- "implement aborted: commit or stash your changes so they are built into the worktree, then re-run the wizard."
4195
- );
4196
- }
4197
- }
4198
4132
 
4199
4133
  // src/lib/algoliaDocs.ts
4200
4134
  import { readFileSync, readdirSync, existsSync } from "node:fs";
@@ -4254,16 +4188,9 @@ function getFrameworkSpecificDoc(frameworks) {
4254
4188
  return loadAlgoliaDoc("js");
4255
4189
  }
4256
4190
 
4257
- // src/lib/shell.ts
4258
- function shellQuote(value) {
4259
- return "'" + value.replace(/'/g, "'\\''") + "'";
4260
- }
4261
-
4262
4191
  // src/actions/implement.ts
4263
4192
  var implementSchema = z28.object({
4264
- filesChanged: z28.array(z28.string()),
4265
4193
  summary: z28.string(),
4266
- worktreePath: z28.string().optional(),
4267
4194
  ingestCommand: z28.string().optional(),
4268
4195
  ingestScriptRan: z28.boolean().optional(),
4269
4196
  ingestRecordCount: z28.number().optional(),
@@ -4352,9 +4279,8 @@ function searchEnvVars(language, index, appId, searchKey) {
4352
4279
  name: searchKeyVar(language),
4353
4280
  value: searchKey ?? "<your-algolia-search-only-api-key>"
4354
4281
  },
4355
- // Wizard-supplied rather than written into the generated code, because an
4356
- // agent that retypes the name (appending the project name, re-casing it)
4357
- // leaves the UI querying an index that does not exist.
4282
+ // Wizard-supplied rather than written into the generated code: an agent
4283
+ // that retypes the name leaves the UI querying an index that doesn't exist.
4358
4284
  {
4359
4285
  name: searchIndexVar(language),
4360
4286
  value: index
@@ -4363,8 +4289,6 @@ function searchEnvVars(language, index, appId, searchKey) {
4363
4289
  }
4364
4290
  function baseInstructions(input) {
4365
4291
  return [
4366
- // Agents have renamed this (e.g. appending the project name), which the
4367
- // index-scoped keys then reject with a 403.
4368
4292
  `Target Algolia index, to be used exactly as written \u2014 never renamed, re-cased, prefixed, or suffixed: "${input.targetIndex}"`,
4369
4293
  `Project languages and frameworks: ${JSON.stringify(input.language)}`,
4370
4294
  "Make minimal, idiomatic changes; do not touch unrelated code.",
@@ -4382,14 +4306,14 @@ function sourceSpecificInstructions(input) {
4382
4306
  "Add env vars for any local source access (DB URL, API base, file paths) that is not a fixed repo path."
4383
4307
  ],
4384
4308
  fileUpload: [
4385
- `Records come from the developer's file, already copied into the worktree at "${input.uploadFilePath}". Read and parse that exact file.`,
4309
+ `Records come from the developer's file, already copied into the project at "${input.uploadFilePath}". Read and parse that exact file.`,
4386
4310
  "Parse by extension: JSON = array of objects; CSV/TSV = header row maps to keys.",
4387
4311
  "Map parsed columns/fields to the confirmed entity attributes.",
4388
4312
  "Never fabricate, hardcode, or substitute a different file."
4389
4313
  ],
4390
4314
  generated: [
4391
4315
  "No real data source exists; use sample records for each confirmed entity.",
4392
- "Call the generateRecord tool once per entity (entityName, attributes, count 20-50); it invents the values and unique objectIDs and writes them to a JSON file in the worktree, returning the file path. Do not write records or objectIDs yourself.",
4316
+ "Call the generateRecord tool once per entity (entityName, attributes, count 20-50); it invents the values and unique objectIDs and writes them to a JSON file, returning the file path. Do not write records or objectIDs yourself.",
4393
4317
  "In the script, read and parse each returned file path at runtime using your language's standard JSON support, instead of inlining the records as literals.",
4394
4318
  "Add a prominent TODO where the developer swaps the generated records (and the JSON file under `.algolia-wizard/data/`) for their real record source."
4395
4319
  ]
@@ -4438,14 +4362,11 @@ function searchInstructions(input) {
4438
4362
  "If a search box already exists, replace it with yours.",
4439
4363
  `Read the index name from the ${searchIndexVar(input.language)} env var, which the wizard sets to "${input.targetIndex}". Never hardcode an index name or derive one from the project, file, or component name.`,
4440
4364
  "Read the App ID, the search-only API key, and the index name from env vars; never hardcode them. A search-only key is safe to expose client-side.",
4441
- // The key is provisioned only after verification passes, so the agent never
4442
- // sees one. It must also leave .env alone: the wizard reads that file to
4443
- // decide whether a key already exists, and an agent-invented value there
4444
- // would be reused as if it were real.
4365
+ // The key is provisioned only after verification passes, and the wizard
4366
+ // reads .env to decide whether a key already exists an agent-invented
4367
+ // value there would be reused as if it were real.
4445
4368
  `Add Algolia App ID "${input.appId}"; leave the search-only key as a placeholder. Do not create or edit .env \u2014 the wizard writes the resolved key there itself.`,
4446
- // Not the agent's to rename: the wizard writes these exact names into
4447
- // ".env" right after this step, so a renamed prefix would leave the code
4448
- // reading a var the wizard never wrote.
4369
+ // The wizard writes these exact names into .env right after this step.
4449
4370
  `Use exactly these env var names in the code: ${input.searchEnvVars.map(({ name }) => name).join(", ")}.`,
4450
4371
  "Install any Algolia packages you import with the project's own package manager via runShell, and declare them in the project's dependency manifest.",
4451
4372
  "Match the styles of the application as closely as possible.",
@@ -4454,10 +4375,10 @@ function searchInstructions(input) {
4454
4375
  }
4455
4376
  function verificationInstructions(input) {
4456
4377
  return [
4457
- "Verify the Algolia implementation changes in the current worktree.",
4378
+ "Verify the Algolia implementation changes.",
4458
4379
  `Verification tools found in the codebase: ${JSON.stringify(input.findings.verification ?? [])}.`,
4459
4380
  "Run the project's own checks (lint, type check, tests) via runShell, using the commands the project actually defines \u2014 its task runner, manifest scripts, or Makefile. Run every check that applies, not just the first.",
4460
- "This worktree starts with no installed dependencies. If a check fails because packages or modules are missing, install the dependencies via runShell and re-run it rather than changing the code.",
4381
+ "If a check fails because packages or modules are missing, install the dependencies via runShell and re-run it rather than changing the code.",
4461
4382
  "For issues caused by the implementation, make minimal fixes with writeFile and re-run the checks.",
4462
4383
  "Do not make speculative fixes when no checks exist, a check cannot run, or failures are unrelated to these changes \u2014 note the limitation in your summary.",
4463
4384
  "Do not add new Algolia functionality here; only validate and make minimal correctness fixes.",
@@ -4552,11 +4473,11 @@ function ingestFailure(attempt, executions) {
4552
4473
  }
4553
4474
  return { reason: `it failed (exit ${attempt.exitCode ?? "unknown"})`, detail };
4554
4475
  }
4555
- function makeToolContext(worktree, env = async () => ({})) {
4476
+ function makeToolContext(root, env = async () => ({})) {
4556
4477
  return createToolContext(
4557
4478
  DEFAULT_TOOL_LIMITS,
4558
- worktree,
4559
- createShellContext({ env, approve: storeApproval(worktree) })
4479
+ root,
4480
+ createShellContext({ env, approve: storeApproval(root) })
4560
4481
  );
4561
4482
  }
4562
4483
  function verificationRetryInstructions(verification) {
@@ -4564,7 +4485,7 @@ function verificationRetryInstructions(verification) {
4564
4485
  `Implementation insufficient. Address these findings before reporting completion: ${verification.additionalInstructions ?? verification.summary}`
4565
4486
  ];
4566
4487
  }
4567
- async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES, existingWorktreePath) {
4488
+ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES) {
4568
4489
  const repoRoot = process.cwd();
4569
4490
  const scan = ctx.getStepOutput("project-scan");
4570
4491
  const entities = ctx.getStepOutput(
@@ -4630,9 +4551,6 @@ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES, existingWo
4630
4551
  const targetIndex = selected?.selection;
4631
4552
  useWizard.getState().setTargetIndex(targetIndex ?? null);
4632
4553
  await assertGitRepoWithHead(repoRoot);
4633
- if (await isWorkingTreeDirty(repoRoot)) {
4634
- await confirmDirtyWorkingTree(ctx, repoRoot);
4635
- }
4636
4554
  const normalized = normalizeFindingPaths(findings);
4637
4555
  const confirmed2 = normalized.confirmedEntities;
4638
4556
  const searchLocation = normalized.searchImplementationAnalysis;
@@ -4644,314 +4562,288 @@ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES, existingWo
4644
4562
  if (useCases.includes("ingestion")) {
4645
4563
  ingestAppId = appId ?? (await requireApplication()).id;
4646
4564
  }
4647
- const worktree = existingWorktreePath ?? (await createWorktree(repoRoot)).path;
4648
- try {
4649
- process.chdir(worktree);
4650
- let uploadFilePath;
4651
- let uploadWarning;
4652
- if (ingestionSource === "fileUpload") {
4653
- const copied = await copyUploadIntoWorktree(
4654
- repoRoot,
4655
- worktree,
4656
- INGEST_DIR,
4657
- uploadSourcePath ?? ""
4565
+ let uploadFilePath;
4566
+ let uploadWarning;
4567
+ if (ingestionSource === "fileUpload") {
4568
+ const copied = await copyUploadIntoProject(
4569
+ repoRoot,
4570
+ INGEST_DIR,
4571
+ uploadSourcePath ?? ""
4572
+ );
4573
+ if (copied.ok) {
4574
+ uploadFilePath = copied.relPath;
4575
+ } else {
4576
+ ingestionSource = "generated";
4577
+ uploadWarning = `\u26A0\uFE0F Could not use the uploaded file (${copied.reason}); generating sample records instead.`;
4578
+ logger.warn(
4579
+ { reason: copied.reason },
4580
+ "implement: file upload unavailable; falling back to generated sample records"
4658
4581
  );
4659
- if (copied.ok) {
4660
- uploadFilePath = copied.relPath;
4661
- } else {
4662
- ingestionSource = "generated";
4663
- uploadWarning = `\u26A0\uFE0F Could not use the uploaded file (${copied.reason}); generating sample records instead.`;
4664
- logger.warn(
4665
- { reason: copied.reason },
4666
- "implement: file upload unavailable; falling back to generated sample records"
4667
- );
4668
- }
4669
4582
  }
4670
- const input = {
4671
- findings: normalized,
4672
- confirmed: confirmed2,
4673
- searchLocation,
4674
- targetIndex,
4675
- language,
4676
- appId,
4677
- searchEnvVars: searchEnvVars(language, targetIndex, appId),
4678
- ingestDir: INGEST_DIR,
4679
- ingestionSource,
4680
- uploadFilePath,
4681
- searchUiTarget: searchUiTarget(language)
4682
- };
4683
- const summaries = [];
4684
- if (uploadWarning) summaries.push(uploadWarning);
4685
- let envSearchKey;
4686
- let envAppIdMismatch = false;
4687
- if (useCases.includes("search") && appId) {
4688
- const envAppId = await readEnvVar(worktree, appIdVar(language));
4689
- if (envAppId === appId) {
4690
- envSearchKey = await readEnvVar(worktree, searchKeyVar(language));
4691
- } else if (envAppId) {
4692
- envAppIdMismatch = true;
4693
- summaries.push(
4694
- `\u26A0\uFE0F .env already sets ${appIdVar(language)}=${envAppId}, but the active Algolia application is ${appId}. The wizard left those values alone \u2014 update ${appIdVar(language)} and ${searchKeyVar(language)} by hand, or searches will fail.`
4695
- );
4696
- logger.warn(
4697
- { envAppId, appId },
4698
- "implement: .env holds credentials for a different Algolia application; not reusing its search key"
4699
- );
4700
- }
4701
- }
4702
- let finalSearchEnvVars = input.searchEnvVars;
4703
- let agentRuns = 0;
4704
- let ingestCommand;
4705
- let ingestScriptRan = false;
4706
- let ingestRecordCount;
4707
- let ingestDurationMs;
4708
- let ingestOutcomeMessage;
4709
- const ingestKeyAppId = ingestAppId;
4710
- const ingestionTools = ingestKeyAppId ? makeToolContext(worktree, async () => ({
4711
- [APP_ID_VAR]: ingestKeyAppId,
4712
- [API_KEY_VAR]: (await resolveWriteKey(targetIndex, ingestKeyAppId)).key,
4713
- [INDEX_NAME_VAR]: targetIndex
4714
- })) : void 0;
4715
- const searchTools = makeToolContext(worktree);
4716
- async function runImplementationUseCase(currentUseCase, extraInstructions = []) {
4717
- if (agentRuns > 0) ctx.recordStepExecution();
4718
- agentRuns += 1;
4719
- return runAgent({
4720
- instructions: buildAgentInstructions(
4721
- currentUseCase,
4722
- input,
4723
- extraInstructions
4724
- ),
4725
- tools: toolsForUseCase(currentUseCase, input.ingestionSource),
4726
- outputSchema: implementationOutputSchema,
4727
- toolContext: currentUseCase === "ingestion" ? ingestionTools ?? searchTools : searchTools
4728
- });
4583
+ }
4584
+ const input = {
4585
+ findings: normalized,
4586
+ confirmed: confirmed2,
4587
+ searchLocation,
4588
+ targetIndex,
4589
+ language,
4590
+ appId,
4591
+ searchEnvVars: searchEnvVars(language, targetIndex, appId),
4592
+ ingestDir: INGEST_DIR,
4593
+ ingestionSource,
4594
+ uploadFilePath,
4595
+ searchUiTarget: searchUiTarget(language)
4596
+ };
4597
+ const summaries = [];
4598
+ if (uploadWarning) summaries.push(uploadWarning);
4599
+ let envSearchKey;
4600
+ let envAppIdMismatch = false;
4601
+ if (useCases.includes("search") && appId) {
4602
+ const envAppId = await readEnvVar(repoRoot, appIdVar(language));
4603
+ if (envAppId === appId) {
4604
+ envSearchKey = await readEnvVar(repoRoot, searchKeyVar(language));
4605
+ } else if (envAppId) {
4606
+ envAppIdMismatch = true;
4607
+ summaries.push(
4608
+ `\u26A0\uFE0F .env already sets ${appIdVar(language)}=${envAppId}, but the active Algolia application is ${appId}. The wizard left those values alone \u2014 update ${appIdVar(language)} and ${searchKeyVar(language)} by hand, or searches will fail.`
4609
+ );
4610
+ logger.warn(
4611
+ { envAppId, appId },
4612
+ "implement: .env holds credentials for a different Algolia application; not reusing its search key"
4613
+ );
4729
4614
  }
4730
- async function runVerificationUseCase() {
4731
- if (agentRuns > 0) ctx.recordStepExecution();
4732
- agentRuns += 1;
4733
- return runAgent({
4734
- instructions: buildAgentInstructions("verification", input),
4735
- tools: toolsForUseCase("verification"),
4736
- outputSchema: verificationOutputSchema,
4737
- toolContext: searchTools
4738
- });
4615
+ }
4616
+ let finalSearchEnvVars = input.searchEnvVars;
4617
+ let agentRuns = 0;
4618
+ let ingestCommand;
4619
+ let ingestScriptRan = false;
4620
+ let ingestRecordCount;
4621
+ let ingestDurationMs;
4622
+ let ingestOutcomeMessage;
4623
+ const ingestKeyAppId = ingestAppId;
4624
+ const ingestionTools = ingestKeyAppId ? makeToolContext(repoRoot, async () => ({
4625
+ [APP_ID_VAR]: ingestKeyAppId,
4626
+ [API_KEY_VAR]: (await resolveWriteKey(targetIndex, ingestKeyAppId)).key,
4627
+ [INDEX_NAME_VAR]: targetIndex
4628
+ })) : void 0;
4629
+ const searchTools = makeToolContext(repoRoot);
4630
+ async function runImplementationUseCase(currentUseCase, extraInstructions = []) {
4631
+ if (agentRuns > 0) ctx.recordStepExecution();
4632
+ agentRuns += 1;
4633
+ return runAgent({
4634
+ instructions: buildAgentInstructions(
4635
+ currentUseCase,
4636
+ input,
4637
+ extraInstructions
4638
+ ),
4639
+ tools: toolsForUseCase(currentUseCase, input.ingestionSource),
4640
+ outputSchema: implementationOutputSchema,
4641
+ toolContext: currentUseCase === "ingestion" ? ingestionTools ?? searchTools : searchTools
4642
+ });
4643
+ }
4644
+ async function runVerificationUseCase() {
4645
+ if (agentRuns > 0) ctx.recordStepExecution();
4646
+ agentRuns += 1;
4647
+ return runAgent({
4648
+ instructions: buildAgentInstructions("verification", input),
4649
+ tools: toolsForUseCase("verification"),
4650
+ outputSchema: verificationOutputSchema,
4651
+ toolContext: searchTools
4652
+ });
4653
+ }
4654
+ if (useCases.includes("ingestion")) {
4655
+ let ingestFailureDetail;
4656
+ const result = await runImplementationUseCase("ingestion");
4657
+ summaries.push(formatSummary("ingestion", result.summary));
4658
+ ingestCommand = result.ingestCommand;
4659
+ const ingestionContext = ingestionTools ?? searchTools;
4660
+ const executions = ingestionContext.shell.executions;
4661
+ const {
4662
+ run: ingestRun,
4663
+ attempt: ingestAttempt,
4664
+ recordCount
4665
+ } = ingestOutcome(executions, ingestCommand);
4666
+ ingestScriptRan = ingestRun != null;
4667
+ ingestRecordCount = recordCount;
4668
+ ingestDurationMs = ingestRun?.durationMs;
4669
+ if (ingestScriptRan && ingestionContext.reviewed.length === 0) {
4670
+ summaries.push(
4671
+ "\u26A0\uFE0F The ingestion script ran without being shown to you for review. Read it in your project before trusting the index contents."
4672
+ );
4673
+ logger.warn(
4674
+ { ingestCommand },
4675
+ "implement: ingestion ran without a reviewScript call"
4676
+ );
4739
4677
  }
4740
- if (useCases.includes("ingestion")) {
4741
- let ingestFailureDetail;
4742
- const result = await runImplementationUseCase("ingestion");
4743
- summaries.push(formatSummary("ingestion", result.summary));
4744
- ingestCommand = result.ingestCommand;
4745
- const ingestionContext = ingestionTools ?? searchTools;
4746
- const executions = ingestionContext.shell.executions;
4747
- const {
4748
- run: ingestRun,
4749
- attempt: ingestAttempt,
4750
- recordCount
4751
- } = ingestOutcome(executions, ingestCommand);
4752
- ingestScriptRan = ingestRun != null;
4753
- ingestRecordCount = recordCount;
4754
- ingestDurationMs = ingestRun?.durationMs;
4755
- if (ingestScriptRan && ingestionContext.reviewed.length === 0) {
4756
- summaries.push(
4757
- "\u26A0\uFE0F The ingestion script ran without being shown to you for review. Read it in the worktree before trusting the index contents."
4758
- );
4759
- logger.warn(
4760
- { ingestCommand },
4761
- "implement: ingestion ran without a reviewScript call"
4762
- );
4678
+ if (ingestScriptRan) {
4679
+ ingestOutcomeMessage = `\u2705 Ingestion succeeded${ingestRecordCount != null ? ` \u2014 ${ingestRecordCount} record(s) indexed.` : "."}`;
4680
+ if (ingestRecordCount != null) {
4681
+ track("AI Wizard Ingest Successful", {
4682
+ entity_name: confirmed2?.map((e) => e.name).join(", ") || "unknown",
4683
+ record_count: ingestRecordCount,
4684
+ duration_ms: ingestDurationMs ?? 0
4685
+ });
4763
4686
  }
4764
- if (ingestScriptRan) {
4765
- ingestOutcomeMessage = `\u2705 Ingestion succeeded${ingestRecordCount != null ? ` \u2014 ${ingestRecordCount} record(s) indexed.` : "."}`;
4766
- if (ingestRecordCount != null) {
4767
- track("AI Wizard Ingest Successful", {
4768
- entity_name: confirmed2?.map((e) => e.name).join(", ") || "unknown",
4769
- record_count: ingestRecordCount,
4770
- duration_ms: ingestDurationMs ?? 0
4771
- });
4772
- }
4773
- } else {
4774
- const { reason, detail } = ingestFailure(ingestAttempt, executions);
4775
- ingestOutcomeMessage = `\u26A0\uFE0F Records were not indexed \u2014 ${reason}.${ingestCommand ? " Run the command below when you are ready." : ""}`;
4776
- ingestFailureDetail = detail;
4777
- summaries.push(
4778
- `\u26A0\uFE0F Ingestion did not complete: ${reason}.${detail ? `
4687
+ } else {
4688
+ const { reason, detail } = ingestFailure(ingestAttempt, executions);
4689
+ ingestOutcomeMessage = `\u26A0\uFE0F Records were not indexed \u2014 ${reason}.${ingestCommand ? " Run the command below when you are ready." : ""}`;
4690
+ ingestFailureDetail = detail;
4691
+ summaries.push(
4692
+ `\u26A0\uFE0F Ingestion did not complete: ${reason}.${detail ? `
4779
4693
  ${detail}` : ""}`
4780
- );
4781
- logger.warn(
4694
+ );
4695
+ logger.warn(
4696
+ {
4697
+ ingestCommand,
4698
+ reason,
4699
+ approved: ingestAttempt?.approved,
4700
+ exitCode: ingestAttempt?.exitCode,
4701
+ timedOut: ingestAttempt?.timedOut,
4702
+ commandsRun: executions.length
4703
+ },
4704
+ "implement: ingestion script did not complete successfully"
4705
+ );
4706
+ track("Error", {
4707
+ step: "Push Data",
4708
+ error: `ingestion did not complete: ${reason}`,
4709
+ product_area: "AI Wizard"
4710
+ });
4711
+ }
4712
+ const commandMessages = ingestCommand ? [`Ingestion command: ${ingestCommand}`] : [];
4713
+ await ctx.requestUserInput({
4714
+ prompt: "",
4715
+ promptType: "enterToContinue",
4716
+ options: [],
4717
+ // One message per line: Notices.tsx counts a message as one wrapped
4718
+ // line, so an embedded newline overflows the panel's height accounting.
4719
+ messages: [
4720
+ ingestOutcomeMessage,
4721
+ ...ingestFailureDetail?.split("\n").filter((l) => l.trim()) ?? [],
4722
+ ...commandMessages
4723
+ ]
4724
+ });
4725
+ }
4726
+ if (useCases.includes("search")) {
4727
+ let extraInstructions = [];
4728
+ useWizard.getState().clearWrittenFiles();
4729
+ for (let attempt = 1; attempt <= MAX_IMPLEMENT_VERIFICATION_ATTEMPTS; attempt++) {
4730
+ if (attempt > 1) {
4731
+ logger.info(
4782
4732
  {
4783
- ingestCommand,
4784
- reason,
4785
- approved: ingestAttempt?.approved,
4786
- exitCode: ingestAttempt?.exitCode,
4787
- timedOut: ingestAttempt?.timedOut,
4788
- commandsRun: executions.length
4733
+ attempt,
4734
+ maxAttempts: MAX_IMPLEMENT_VERIFICATION_ATTEMPTS,
4735
+ extraInstructions
4789
4736
  },
4790
- "implement: ingestion script did not complete successfully"
4737
+ "implement: retrying search implementation after failed verification"
4791
4738
  );
4792
- track("Error", {
4793
- step: "Push Data",
4794
- error: `ingestion did not complete: ${reason}`,
4795
- product_area: "AI Wizard"
4739
+ }
4740
+ const { summary } = await runImplementationUseCase(
4741
+ "search",
4742
+ extraInstructions
4743
+ );
4744
+ summaries.push(formatSummary("search", summary));
4745
+ const verification = await runVerificationUseCase();
4746
+ summaries.push(formatSummary("verification", verification.summary));
4747
+ if (verification.sufficient) {
4748
+ ctx.setUserInput("implementation", "success");
4749
+ const searchFilesChanged = [
4750
+ ...new Set(useWizard.getState().writtenFiles)
4751
+ ].map((file) => relative6(repoRoot, file));
4752
+ track("AI Wizard Frontend Component Generated", {
4753
+ filePaths: searchFilesChanged
4796
4754
  });
4755
+ track("AI Wizard Wired to UI", {
4756
+ location_heuristic: searchLocation ?? "unknown"
4757
+ });
4758
+ break;
4797
4759
  }
4798
- const commandMessages = [`Open the worktree: cd ${shellQuote(worktree)}`];
4799
- if (ingestCommand) {
4800
- commandMessages.push(`Ingestion command: ${ingestCommand}`);
4760
+ if (attempt === MAX_IMPLEMENT_VERIFICATION_ATTEMPTS) {
4761
+ ctx.setUserInput("implementation", "fail");
4762
+ throw new Error(
4763
+ `Implementation verification failed after ${MAX_IMPLEMENT_VERIFICATION_ATTEMPTS} attempts: ${verification.additionalInstructions ?? verification.summary}`
4764
+ );
4801
4765
  }
4802
- await ctx.requestUserInput({
4803
- prompt: "",
4804
- promptType: "enterToContinue",
4805
- options: [],
4806
- // The wizard never streams command output, so a failed run's tail is the
4807
- // only place the developer sees why it failed. One message per line:
4808
- // the panel's height accounting counts a message as one wrapped line
4809
- // (see Notices.tsx), so an embedded newline overflows it.
4810
- messages: [
4811
- ingestOutcomeMessage,
4812
- ...ingestFailureDetail?.split("\n").filter((l) => l.trim()) ?? [],
4813
- ...commandMessages
4814
- ]
4815
- });
4766
+ extraInstructions = verificationRetryInstructions(verification);
4816
4767
  }
4817
- if (useCases.includes("search")) {
4818
- let extraInstructions = [];
4819
- const preSearchFiles = new Set(await listChangedFiles(worktree));
4820
- for (let attempt = 1; attempt <= MAX_IMPLEMENT_VERIFICATION_ATTEMPTS; attempt++) {
4821
- if (attempt > 1) {
4822
- logger.info(
4823
- {
4824
- attempt,
4825
- maxAttempts: MAX_IMPLEMENT_VERIFICATION_ATTEMPTS,
4826
- extraInstructions
4827
- },
4828
- "implement: retrying search implementation after failed verification"
4829
- );
4830
- }
4831
- const { summary } = await runImplementationUseCase(
4832
- "search",
4833
- extraInstructions
4768
+ let searchKey;
4769
+ let searchKeyError;
4770
+ if (appId) {
4771
+ try {
4772
+ const resolved2 = await resolveSearchOnlyKey(
4773
+ targetIndex,
4774
+ appId,
4775
+ envSearchKey
4776
+ );
4777
+ searchKey = resolved2.key;
4778
+ summaries.push(
4779
+ resolved2.source === "created" ? `Created a new search-only Algolia API key for the "${targetIndex}" index in app ${appId} \u2014 safe to expose in frontend code.` : `Reused the existing search-only Algolia API key for the "${targetIndex}" index in app ${appId}.`
4780
+ );
4781
+ } catch (err) {
4782
+ searchKeyError = err.message;
4783
+ logger.warn(
4784
+ { err: searchKeyError },
4785
+ "implement: could not provision a search-only API key; the .env value stays a placeholder"
4834
4786
  );
4835
- summaries.push(formatSummary("search", summary));
4836
- const verification = await runVerificationUseCase();
4837
- summaries.push(formatSummary("verification", verification.summary));
4838
- if (verification.sufficient) {
4839
- ctx.setUserInput("implementation", "success");
4840
- const searchFilesChanged = (await listChangedFiles(worktree)).filter(
4841
- (file) => !preSearchFiles.has(file)
4842
- );
4843
- track("AI Wizard Frontend Component Generated", {
4844
- filePaths: searchFilesChanged
4845
- });
4846
- track("AI Wizard Wired to UI", {
4847
- location_heuristic: searchLocation ?? "unknown"
4848
- });
4849
- break;
4850
- }
4851
- if (attempt === MAX_IMPLEMENT_VERIFICATION_ATTEMPTS) {
4852
- ctx.setUserInput("implementation", "fail");
4853
- throw new Error(
4854
- `Implementation verification failed after ${MAX_IMPLEMENT_VERIFICATION_ATTEMPTS} attempts: ${verification.additionalInstructions ?? verification.summary}`
4855
- );
4856
- }
4857
- extraInstructions = verificationRetryInstructions(verification);
4858
- }
4859
- let searchKey;
4860
- let searchKeyError;
4861
- if (appId) {
4862
- try {
4863
- const resolved2 = await resolveSearchOnlyKey(
4864
- targetIndex,
4865
- appId,
4866
- envSearchKey
4867
- );
4868
- searchKey = resolved2.key;
4869
- summaries.push(
4870
- resolved2.source === "created" ? `Created a new search-only Algolia API key for the "${targetIndex}" index in app ${appId} \u2014 safe to expose in frontend code.` : `Reused the existing search-only Algolia API key for the "${targetIndex}" index in app ${appId}.`
4871
- );
4872
- } catch (err) {
4873
- searchKeyError = err.message;
4874
- logger.warn(
4875
- { err: searchKeyError },
4876
- "implement: could not provision a search-only API key; the .env value stays a placeholder"
4877
- );
4878
- }
4879
4787
  }
4880
- finalSearchEnvVars = searchEnvVars(
4881
- language,
4882
- targetIndex,
4883
- appId,
4884
- searchKey
4885
- );
4886
- const resolvedSearchEnvVars = finalSearchEnvVars.filter(
4887
- (v) => !v.value.startsWith("<")
4788
+ }
4789
+ finalSearchEnvVars = searchEnvVars(language, targetIndex, appId, searchKey);
4790
+ const resolvedSearchEnvVars = finalSearchEnvVars.filter(
4791
+ (v) => !v.value.startsWith("<")
4792
+ );
4793
+ if (resolvedSearchEnvVars.length > 0) {
4794
+ const written = await writeSearchEnvValues(
4795
+ repoRoot,
4796
+ resolvedSearchEnvVars
4888
4797
  );
4889
- if (resolvedSearchEnvVars.length > 0) {
4890
- const written = await writeSearchEnvValues(
4891
- worktree,
4892
- resolvedSearchEnvVars
4798
+ if (written.length > 0) {
4799
+ summaries.push(`Wrote ${written.join(", ")} to .env.`);
4800
+ }
4801
+ const ignored = await ensureGitIgnored(repoRoot, join12(repoRoot, ".env"));
4802
+ if (ignored === "added") {
4803
+ summaries.push("Added .env to .gitignore.");
4804
+ } else if (ignored === "tracked") {
4805
+ summaries.push(
4806
+ '\u26A0\uFE0F .env is tracked by git, so a .gitignore rule cannot un-stage it. Run "git rm --cached .env" before committing, or the credentials go into history.'
4893
4807
  );
4894
- if (written.length > 0) {
4895
- summaries.push(`Wrote ${written.join(", ")} to .env.`);
4896
- }
4897
- const ignored = await ensureGitIgnored(worktree, join12(worktree, ".env"));
4898
- if (ignored === "added") {
4899
- summaries.push("Added .env to .gitignore.");
4900
- } else if (ignored === "tracked") {
4901
- summaries.push(
4902
- '\u26A0\uFE0F .env is tracked by git, so a .gitignore rule cannot un-stage it. Run "git rm --cached .env" before committing, or the credentials go into history.'
4903
- );
4904
- }
4905
- const stale = [];
4906
- for (const v of resolvedSearchEnvVars) {
4907
- if (written.includes(v.name)) continue;
4908
- const current = await readEnvVar(worktree, v.name);
4909
- if (current && current !== v.value) stale.push(v);
4910
- }
4911
- if (stale.length > 0 && !envAppIdMismatch) {
4912
- summaries.push(
4913
- `\u26A0\uFE0F .env already assigns a different value to ${stale.map((v) => `${v.name} (should be ${v.value})`).join(", ")} \u2014 the wizard left it alone. Fix it by hand, or searches will fail.`
4914
- );
4915
- logger.warn(
4916
- { vars: stale.map((v) => v.name) },
4917
- "implement: .env holds different values for the resolved search credentials; not overwriting them"
4918
- );
4919
- }
4920
4808
  }
4921
- const unresolvedSearchEnvVars = finalSearchEnvVars.filter(
4922
- (v) => v.value.startsWith("<")
4923
- );
4924
- if (unresolvedSearchEnvVars.length > 0) {
4809
+ const stale = [];
4810
+ for (const v of resolvedSearchEnvVars) {
4811
+ if (written.includes(v.name)) continue;
4812
+ const current = await readEnvVar(repoRoot, v.name);
4813
+ if (current && current !== v.value) stale.push(v);
4814
+ }
4815
+ if (stale.length > 0 && !envAppIdMismatch) {
4925
4816
  summaries.push(
4926
- `Could not resolve a value for ${unresolvedSearchEnvVars.map((v) => v.name).join(", ")} \u2014 fill it in manually in .env.` + // Without the reason the line is a dead end.
4927
- (searchKeyError ? ` Reason: ${searchKeyError}` : "")
4817
+ `\u26A0\uFE0F .env already assigns a different value to ${stale.map((v) => `${v.name} (should be ${v.value})`).join(", ")} \u2014 the wizard left it alone. Fix it by hand, or searches will fail.`
4818
+ );
4819
+ logger.warn(
4820
+ { vars: stale.map((v) => v.name) },
4821
+ "implement: .env holds different values for the resolved search credentials; not overwriting them"
4928
4822
  );
4929
4823
  }
4930
- } else {
4931
- ctx.setUserInput("implementation", "success");
4932
4824
  }
4933
- const filesChanged = await listChangedFiles(worktree);
4934
- if (filesChanged.length === 0) {
4935
- logger.warn(
4936
- "implement: agent reported success but no files changed in the worktree"
4825
+ const unresolvedSearchEnvVars = finalSearchEnvVars.filter(
4826
+ (v) => v.value.startsWith("<")
4827
+ );
4828
+ if (unresolvedSearchEnvVars.length > 0) {
4829
+ summaries.push(
4830
+ `Could not resolve a value for ${unresolvedSearchEnvVars.map((v) => v.name).join(", ")} \u2014 fill it in manually in .env.` + (searchKeyError ? ` Reason: ${searchKeyError}` : "")
4937
4831
  );
4938
4832
  }
4939
- return {
4940
- ingestionSource,
4941
- filesChanged,
4942
- summary: summaries.join("\n\n"),
4943
- worktreePath: worktree,
4944
- ...useCases.includes("ingestion") && ingestCommand ? {
4945
- ingestCommand,
4946
- ingestScriptRan,
4947
- ...ingestRecordCount != null ? { ingestRecordCount } : {},
4948
- ...ingestDurationMs != null ? { ingestDurationMs } : {}
4949
- } : {},
4950
- ...useCases.includes("search") ? { searchEnvVars: finalSearchEnvVars } : {}
4951
- };
4952
- } finally {
4953
- process.chdir(repoRoot);
4833
+ } else {
4834
+ ctx.setUserInput("implementation", "success");
4954
4835
  }
4836
+ return {
4837
+ ingestionSource,
4838
+ summary: summaries.join("\n\n"),
4839
+ ...useCases.includes("ingestion") && ingestCommand ? {
4840
+ ingestCommand,
4841
+ ingestScriptRan,
4842
+ ...ingestRecordCount != null ? { ingestRecordCount } : {},
4843
+ ...ingestDurationMs != null ? { ingestDurationMs } : {}
4844
+ } : {},
4845
+ ...useCases.includes("search") ? { searchEnvVars: finalSearchEnvVars } : {}
4846
+ };
4955
4847
  }
4956
4848
 
4957
4849
  // src/workflows/default.ts
@@ -5023,10 +4915,7 @@ var defaultWorkflow = {
5023
4915
  ctx.notify({
5024
4916
  messages: ["Building your Algolia search experience\u2026"]
5025
4917
  });
5026
- const ingestion2 = ctx.getStepOutput(
5027
- "ingestion"
5028
- );
5029
- return implement(ctx, ["search"], ingestion2?.worktreePath);
4918
+ return implement(ctx, ["search"]);
5030
4919
  }
5031
4920
  }),
5032
4921
  defineStep({
@@ -5041,9 +4930,8 @@ var defaultWorkflow = {
5041
4930
  "ingestion"
5042
4931
  );
5043
4932
  return reviewStep(ctx, {
5044
- // The ingestion step already showed the user the exact `ingestCommand`
5045
- // and worktree path as a notice, so nextSteps must not restate it —
5046
- // an LLM-paraphrased command risks being wrong.
4933
+ // ingestCommand was already shown verbatim as a notice; an
4934
+ // LLM-paraphrased restatement in nextSteps risks being wrong.
5047
4935
  nextStepsGuidance: ingestion2?.ingestScriptRan ? "The wizard already ran the ingestion script and records are in the index. Do NOT tell the user to run it again; instead point them at the target index to confirm the records. Do not restate the ingestion command \u2014 the wizard already showed it to them." : "Tell the user to run the ingestion script; do not restate the exact command \u2014 the wizard already showed it to them above."
5048
4936
  });
5049
4937
  }
@@ -5089,7 +4977,6 @@ var selectIndex = {
5089
4977
  selection: "wizard_seed_products"
5090
4978
  };
5091
4979
  var ingestion = {
5092
- filesChanged: ["algolia/ingest.mjs", "algolia/records.json", "package.json"],
5093
4980
  summary: "Generated sample Product records and an ingestion script that pushes them to the target index with algoliasearch.",
5094
4981
  ingestCommand: "node algolia/ingest.mjs",
5095
4982
  ingestScriptRan: true,
@@ -5101,7 +4988,6 @@ var confirmFramework2 = {
5101
4988
  frameworks: projectScan2.frameworks
5102
4989
  };
5103
4990
  var search = {
5104
- filesChanged: ["src/components/Search.tsx", "src/components/Header.tsx", ".env"],
5105
4991
  summary: "Added an InstantSearch-powered search box and results list, mounted in the shared header component.",
5106
4992
  ingestionSource: "generated",
5107
4993
  searchEnvVars: [
@@ -5114,7 +5000,7 @@ var review = {
5114
5000
  "Ingested 25 generated Product records into wizard_seed_products.",
5115
5001
  "Added an InstantSearch search experience to the shared header."
5116
5002
  ],
5117
- reviewPrompt: "Review the Algolia ingestion and search changes in this worktree.",
5003
+ reviewPrompt: "Review the Algolia ingestion and search changes.",
5118
5004
  nextSteps: ["Point the ingestion script at your real product data."]
5119
5005
  };
5120
5006
  var SEEDS = {
@@ -5231,9 +5117,9 @@ Options:
5231
5117
  steps pre-filled with test data. Pass with no value to print
5232
5118
  the step ids. See CONTRIBUTING.md.
5233
5119
  --no-telemetry Send no telemetry or analytics for this run.
5234
- --reset-on-run Wipe this project's wizard state (run state, AI consent,
5235
- worktrees) before starting, so the run behaves like a
5236
- first-ever run. Also drops every API key the wizard has
5120
+ --reset-on-run Wipe this project's wizard state (run state, AI consent)
5121
+ before starting, so the run behaves like a first-ever
5122
+ run. Also drops every API key the wizard has
5237
5123
  stored in your keychain (or, where the platform has none,
5238
5124
  the encrypted file it falls back to \u2014 see CONTRIBUTING.md),
5239
5125
  for this project and any other, so later runs create new
@@ -5273,7 +5159,7 @@ function parseCliArgs(argv) {
5273
5159
  }
5274
5160
 
5275
5161
  // src/lib/resetState.ts
5276
- import { readdir as readdir4, rm as rm2 } from "node:fs/promises";
5162
+ import { readdir as readdir3, rm as rm2 } from "node:fs/promises";
5277
5163
  import { join as join13 } from "node:path";
5278
5164
  var KEEP = ["wizard.log"];
5279
5165
  async function resetProjectState() {
@@ -5281,7 +5167,7 @@ async function resetProjectState() {
5281
5167
  await forgetResolvedKeys();
5282
5168
  let entries;
5283
5169
  try {
5284
- entries = await readdir4(dir);
5170
+ entries = await readdir3(dir);
5285
5171
  } catch {
5286
5172
  return { dir, removed: [] };
5287
5173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.18.0",
3
+ "version": "0.19.0-rc.111.189",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {