@algolia/wizard 0.67.0 → 0.68.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 (2) hide show
  1. package/dist/main.js +70 -33
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -48,7 +48,7 @@ function runAlgoliaCli(args, { onOutput, redact } = {}) {
48
48
  const store = useWizard.getState();
49
49
  const command = mask(args.join(" "), redact);
50
50
  const logId = store.logStart("tool", `algolia ${command}`);
51
- return new Promise((resolve4, reject) => {
51
+ return new Promise((resolve5, reject) => {
52
52
  const child = spawn("npx", npxArgs(args), { shell });
53
53
  let stdout = "";
54
54
  let stderr = "";
@@ -71,7 +71,7 @@ function runAlgoliaCli(args, { onOutput, redact } = {}) {
71
71
  splitters.stdout.flush();
72
72
  splitters.stderr.flush();
73
73
  if (code === 0) {
74
- resolve4(stdout);
74
+ resolve5(stdout);
75
75
  } else {
76
76
  const failed = stderr.trim();
77
77
  let detail = "";
@@ -275,15 +275,15 @@ var useWizard = create((set, get) => ({
275
275
  ),
276
276
  openLearnMore: () => set({ homeScreen: "learnMore" }),
277
277
  backToHome: () => set({ homeScreen: "home" }),
278
- waitForStart: () => new Promise((resolve4) => {
278
+ waitForStart: () => new Promise((resolve5) => {
279
279
  if (get().phase !== "idle") {
280
- resolve4();
280
+ resolve5();
281
281
  return;
282
282
  }
283
283
  const unsubscribe = useWizard.subscribe((s) => {
284
284
  if (s.phase !== "idle") {
285
285
  unsubscribe();
286
- resolve4();
286
+ resolve5();
287
287
  }
288
288
  });
289
289
  }),
@@ -385,11 +385,11 @@ var useWizard = create((set, get) => ({
385
385
  (t) => t.id === id ? { ...t, status, durationMs: Date.now() - t.startedAt } : t
386
386
  )
387
387
  })),
388
- requestUserInput: (req) => new Promise((resolve4) => {
388
+ requestUserInput: (req) => new Promise((resolve5) => {
389
389
  set({
390
390
  phase: "awaitingInput",
391
391
  inputReq: req,
392
- _resolve: resolve4
392
+ _resolve: resolve5
393
393
  });
394
394
  }),
395
395
  submitInput: async (value) => {
@@ -1969,7 +1969,7 @@ function identify(traits) {
1969
1969
  // package.json
1970
1970
  var package_default = {
1971
1971
  name: "@algolia/wizard",
1972
- version: "0.67.0",
1972
+ version: "0.68.0",
1973
1973
  description: "Magically implement Algolia functionality in your codebase",
1974
1974
  type: "module",
1975
1975
  engines: {
@@ -3016,10 +3016,10 @@ var GIT_ENV_OVERRIDES = [
3016
3016
  function gitSucceeds(root, args) {
3017
3017
  const env = { ...process.env };
3018
3018
  for (const key of GIT_ENV_OVERRIDES) delete env[key];
3019
- return new Promise((resolve4) => {
3019
+ return new Promise((resolve5) => {
3020
3020
  execFile("git", ["-C", root, ...args], { env }, (err) => {
3021
- if (!err) return resolve4(true);
3022
- resolve4(
3021
+ if (!err) return resolve5(true);
3022
+ resolve5(
3023
3023
  err.code === 1 ? false : void 0
3024
3024
  );
3025
3025
  });
@@ -3466,7 +3466,7 @@ var SIGKILL_DELAY_MS = 5e3;
3466
3466
  function runShell(command, opts) {
3467
3467
  const timeoutMs = opts.timeoutMs ?? DEFAULT_SHELL_TIMEOUT_MS;
3468
3468
  const startedAt = Date.now();
3469
- return new Promise((resolve4) => {
3469
+ return new Promise((resolve5) => {
3470
3470
  let output = "";
3471
3471
  let timedOut = false;
3472
3472
  let settled = false;
@@ -3481,7 +3481,7 @@ function runShell(command, opts) {
3481
3481
  settled = true;
3482
3482
  clearTimeout(timer);
3483
3483
  clearTimeout(killTimer);
3484
- resolve4({
3484
+ resolve5({
3485
3485
  exitCode,
3486
3486
  output: truncateText(output.trim()),
3487
3487
  timedOut,
@@ -3738,8 +3738,8 @@ function defaultCreateModel() {
3738
3738
  }
3739
3739
  function approvedCommandHistory(approvedCommands) {
3740
3740
  return Array.from(approvedCommands).map((entry) => {
3741
- const sep2 = entry.indexOf("\0");
3742
- return { cwd: entry.slice(0, sep2), command: entry.slice(sep2 + 1) };
3741
+ const sep3 = entry.indexOf("\0");
3742
+ return { cwd: entry.slice(0, sep3), command: entry.slice(sep3 + 1) };
3743
3743
  });
3744
3744
  }
3745
3745
  async function classifyCommandSafety(createModel, command, cwd, explanation, approvedHistory) {
@@ -4854,7 +4854,7 @@ ${formatCompletedSteps(ctx.completedSteps)}`,
4854
4854
  // src/actions/implement.ts
4855
4855
  import z28 from "zod";
4856
4856
  import { access, mkdir as mkdir5, readFile as readFile8 } from "node:fs/promises";
4857
- import { join as join10, relative as relative6 } from "node:path";
4857
+ import { dirname as dirname5, isAbsolute as isAbsolute3, join as join10, relative as relative6, resolve as resolve4, sep as sep2 } from "node:path";
4858
4858
 
4859
4859
  // src/lib/git.ts
4860
4860
  import { execFile as execFile2 } from "node:child_process";
@@ -4862,7 +4862,7 @@ import { copyFile, mkdir as mkdir4, stat as stat3 } from "node:fs/promises";
4862
4862
  import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute2, join as join8, resolve as resolve3 } from "node:path";
4863
4863
  var MAX_BUFFER = 32 * 1024 * 1024;
4864
4864
  function git(args) {
4865
- return new Promise((resolve4, reject) => {
4865
+ return new Promise((resolve5, reject) => {
4866
4866
  execFile2("git", args, { maxBuffer: MAX_BUFFER }, (err, stdout, stderr) => {
4867
4867
  if (err)
4868
4868
  return reject(
@@ -4870,7 +4870,7 @@ function git(args) {
4870
4870
  `git ${args.join(" ")} failed: ${stderr.toString().trim() || err.message}`
4871
4871
  )
4872
4872
  );
4873
- resolve4(stdout.toString());
4873
+ resolve5(stdout.toString());
4874
4874
  });
4875
4875
  });
4876
4876
  }
@@ -5133,12 +5133,22 @@ function searchInstructions(input) {
5133
5133
  const entity = input.findings.confirmedEntities ? input.findings.confirmedEntities[0].name : null;
5134
5134
  const attributes = input.findings.confirmedEntities ? input.findings.confirmedEntities[0].attributes : null;
5135
5135
  const entitySchemaMessage = entity && attributes ? `The following entity schema should be used to build the UI: ${JSON.stringify({ entity, attributes })}` : null;
5136
- const doc = getFrameworkSpecificDoc(frameworksForDoc(input.language));
5136
+ const packageManagedInstructions = input.frontendHasPackageJson ? packageSearchInstructions(input) : cdnSearchInstructions(input);
5137
5137
  return [
5138
5138
  "Implement an in-app Algolia search experience.",
5139
5139
  entitySchemaMessage ?? "",
5140
5140
  `Build the search UI for ${input.searchUiTarget}.`,
5141
5141
  "Create search UI only. Do not create or modify ingestion scripts, rake/manage/CLI tasks, migrations, seeders, or other data-loading code, even if the data looks incomplete.",
5142
+ ...packageManagedInstructions,
5143
+ "Meet WCAG AA contrast (4.5:1 body text, 3:1 large text/icons) between the panel's text and its own background, and give the input and the active result a focus indicator visible against whatever sits behind it. Style the panel through the widget's class and CSS-variable overrides (or, when hand-built, the app's existing theme tokens) \u2014 never assume a light surface or reuse the surrounding page's colors unchanged inside the panel.",
5144
+ "The panel takes its width from the input by default, so a small input makes it unreadably narrow: give it a min-width of 320px independent of the input, anchored to the input edge it opens from so widening does not push it off-screen.",
5145
+ "Match the styles of the application as closely as possible.",
5146
+ "The summary should be extremely concise; do not mention manual testing steps."
5147
+ ];
5148
+ }
5149
+ function packageSearchInstructions(input) {
5150
+ const doc = getFrameworkSpecificDoc(frameworksForDoc(input.language));
5151
+ return [
5142
5152
  ...doc ? [
5143
5153
  "Follow the Algolia SDK reference below for client setup, search UI wiring, and Insights instrumentation \u2014 Insights is required, not optional; prefer the reference over prior knowledge:",
5144
5154
  doc
@@ -5149,16 +5159,22 @@ function searchInstructions(input) {
5149
5159
  `Import and render the new component in ${input.searchLocation ? `"${input.searchLocation}"` : "the best, always-rendered layout location (e.g. a header/nav component)"} so it is reachable across the app \u2014 at least a working search input and results panel against the target index.`,
5150
5160
  "If a search box already exists, replace its usage with an import and render of your new component; remove the old implementation.",
5151
5161
  "When rendering results with an existing shared component (e.g. a card), import and reuse that component rather than inlining its markup \u2014 inlining silently drops the styles and behavior its own file provides.",
5152
- "Meet WCAG AA contrast (4.5:1 body text, 3:1 large text/icons) between the panel's text and its own background, and give the input and the active result a focus indicator visible against whatever sits behind it. Style the panel through the widget's class and CSS-variable overrides (or, when hand-built, the app's existing theme tokens) \u2014 never assume a light surface or reuse the surrounding page's colors unchanged inside the panel.",
5153
5162
  "Vendor theme CSS, and any CSS you write against vendor class names, must be global: import the theme from the component's own script module or the app's global stylesheet, and put overrides in a global block (Astro <style is:global>, an unscoped Vue block, a plain global CSS file). Never a framework-scoped style block or a CSS Module \u2014 scoping rewrites the vendor selectors and the widget's runtime DOM carries no scope attribute, so not one rule matches: styling silently does nothing and the build still passes.",
5154
- "The panel takes its width from the input by default, so a small input makes it unreadably narrow: give it a min-width of 320px independent of the input, anchored to the input edge it opens from so widening does not push it off-screen.",
5155
5163
  `Define ${SEARCH_CONFIG_APP_ID}, ${SEARCH_CONFIG_SEARCH_KEY}, and ${SEARCH_CONFIG_INDEX_NAME} as exported constants in a module that fits this project's existing conventions for shared client-side config \u2014 reuse an existing one if it already holds config like this, or add a small new one otherwise. These are PUBLIC values, safe to commit and expose client-side: never read them from an environment variable or a .env* file, and never hardcode them anywhere except in that one module (import them wherever the search client needs them).`,
5156
5164
  `Set ${SEARCH_CONFIG_APP_ID} to "${input.appId}" and ${SEARCH_CONFIG_INDEX_NAME} to "${input.targetIndex}".`,
5157
5165
  input.searchKey ? `Set ${SEARCH_CONFIG_SEARCH_KEY} to "${input.searchKey}".` : `A real search-only key could not be provisioned${input.searchKeyError ? ` (${input.searchKeyError})` : ""} \u2014 set ${SEARCH_CONFIG_SEARCH_KEY} to the placeholder "${SEARCH_KEY_PLACEHOLDER}" and add a prominent TODO for the developer to fill in a real one.`,
5158
5166
  'Report the repo-relative path of that module as "searchConfigFile" in your final status.',
5159
- "Install any Algolia packages you import with the project's own package manager via runShell, and declare them in the project's dependency manifest.",
5160
- "Match the styles of the application as closely as possible.",
5161
- "The summary should be extremely concise; do not mention manual testing steps."
5167
+ "Install any Algolia packages you import with the project's own package manager via runShell, and declare them in the project's dependency manifest."
5168
+ ];
5169
+ }
5170
+ function cdnSearchInstructions(input) {
5171
+ return [
5172
+ `The target frontend has no package.json. Add the search container to its existing HTML or template, create separate classic config and search scripts, define window.${SEARCH_CONFIG_APP_ID}, window.${SEARCH_CONFIG_SEARCH_KEY}, and window.${SEARCH_CONFIG_INDEX_NAME} in the config script, and report that script as "searchConfigFile". Never create package.json, create a component, use imports or exports, or run npm, pnpm, yarn, or bun.`,
5173
+ `Set window.${SEARCH_CONFIG_APP_ID} to "${input.appId}" and window.${SEARCH_CONFIG_INDEX_NAME} to "${input.targetIndex}".`,
5174
+ input.searchKey ? `Set window.${SEARCH_CONFIG_SEARCH_KEY} to "${input.searchKey}".` : `A real search-only key could not be provisioned${input.searchKeyError ? ` (${input.searchKeyError})` : ""} \u2014 set window.${SEARCH_CONFIG_SEARCH_KEY} to the placeholder "${SEARCH_KEY_PLACEHOLDER}" and add a prominent TODO for the developer to fill in a real one.`,
5175
+ 'Load these exact pinned tags in order before the config and search scripts: <script src="https://cdn.jsdelivr.net/npm/algoliasearch@5.59.0/dist/lite/builds/browser.umd.js" integrity="sha256-pduQHl1jn0IaN/BIpSotQm7Y5THdpKcX3Bw6xdRteRw=" crossorigin="anonymous"></script> then <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4.117.0/dist/instantsearch.production.min.js" integrity="sha256-5zhKxAGeH7ThWfnmdD4pS1gsmafE2b8aWRsq8set/dc=" crossorigin="anonymous"></script>.',
5176
+ 'When using the InstantSearch theme, load this exact tag before the application styles: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@8.22.1/themes/satellite-min.css" integrity="sha256-5/eHPZl63VYJSDVOKrOgGe/5+owUkX3uPAW6+XYeLNc=" crossorigin="anonymous">. Never use an unversioned or differently versioned theme URL, and never omit its integrity attribute.',
5177
+ `In that classic search script, use window['algoliasearch/lite'].liteClient and window.instantsearch. Add window.instantsearch.widgets.autocomplete as the only search widget. Configure it with container '#autocomplete', placeholder 'Search...', and an indices array containing one object whose indexName is window.${SEARCH_CONFIG_INDEX_NAME}; put item and noResults functions in its templates option, implement getURL only for an existing route, and match the item template to the entity schema. Keep insights: true and call search.start(). Do not substitute searchBox or hits, omit indices, use imports or exports, or use type="module".`
5162
5178
  ];
5163
5179
  }
5164
5180
  function validationInstructions(input) {
@@ -5170,6 +5186,9 @@ function validationInstructions(input) {
5170
5186
  "Do not run the test suite or any test command.",
5171
5187
  "Do not modify files. Report each implementation issue as a concrete instruction for the next implementation pass.",
5172
5188
  `Available type-check and lint tools: ${JSON.stringify(input.findings.verification ?? [])}.`,
5189
+ ...!input.frontendHasPackageJson ? [
5190
+ "The frontend has no package.json: never create one or run npm, pnpm, yarn, or bun. Validate the CDN implementation by inspecting its HTML or template and classic scripts for the search container, Algolia \u2192 InstantSearch \u2192 config \u2192 search load order, browser globals, autocomplete widget configuration, search.start(), and exact pinned CDN URLs and integrity attributes for every Algolia script or stylesheet. Source inspection is required even when the project has no automated checks. window.instantsearch.widgets.autocomplete is a real widget in the pinned InstantSearch build; do not report its use as an error, and do not fetch a remote bundle or URL to verify it."
5191
+ ] : [],
5173
5192
  "Always call reportStatus with status=success after validation, even when sufficient=false.",
5174
5193
  "Set sufficient=true only when the search bar is unique, correctly placed, and structurally complete.",
5175
5194
  "Set sufficient=false for an implementation issue. Include concrete additionalInstructions for the next pass.",
@@ -5325,11 +5344,25 @@ async function pathExists(path) {
5325
5344
  return false;
5326
5345
  }
5327
5346
  }
5347
+ async function frontendHasPackageJson(repoRoot, searchLocation) {
5348
+ let directory = repoRoot;
5349
+ if (searchLocation) {
5350
+ const candidate = dirname5(resolve4(repoRoot, searchLocation));
5351
+ const candidateRelative = relative6(repoRoot, candidate);
5352
+ const outsideRoot = candidateRelative === ".." || candidateRelative.startsWith(`..${sep2}`) || isAbsolute3(candidateRelative);
5353
+ if (!outsideRoot) directory = candidate;
5354
+ }
5355
+ for (; ; ) {
5356
+ if (await pathExists(join10(directory, "package.json"))) return true;
5357
+ if (directory === repoRoot) return false;
5358
+ directory = dirname5(directory);
5359
+ }
5360
+ }
5328
5361
  async function resolveBuildCheckPlan(ctx, repoRoot, input) {
5329
5362
  if (!input.findings.verification?.length) {
5330
5363
  return { run: false, installDependencies: false };
5331
5364
  }
5332
- const installDependencies = isJsProject(input.language) && !await pathExists(join10(repoRoot, "node_modules"));
5365
+ const installDependencies = input.frontendHasPackageJson && isJsProject(input.language) && !await pathExists(join10(repoRoot, "node_modules"));
5333
5366
  const accepted = Boolean(
5334
5367
  await ctx.requestUserInput({
5335
5368
  prompt: installDependencies ? MISSING_DEPENDENCIES_PROMPT : BUILD_CHECK_PROMPT,
@@ -5507,7 +5540,11 @@ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES) {
5507
5540
  ingestDir: INGEST_DIR,
5508
5541
  ingestionSource,
5509
5542
  uploadFilePath,
5510
- searchUiTarget: searchUiTarget(language)
5543
+ searchUiTarget: searchUiTarget(language),
5544
+ frontendHasPackageJson: await frontendHasPackageJson(
5545
+ repoRoot,
5546
+ searchLocation
5547
+ )
5511
5548
  };
5512
5549
  let agentRuns = 0;
5513
5550
  let ingestCommand;
@@ -6092,7 +6129,7 @@ function getWorkflow(id) {
6092
6129
  }
6093
6130
 
6094
6131
  // src/ui/Welcome.tsx
6095
- import { dirname as dirname5, join as join11 } from "node:path";
6132
+ import { dirname as dirname6, join as join11 } from "node:path";
6096
6133
  import { fileURLToPath as fileURLToPath2 } from "node:url";
6097
6134
  import { useState as useState10 } from "react";
6098
6135
  import { Box as Box11, Spacer, Text as Text12, useInput as useInput6, useWindowSize as useWindowSize5 } from "ink";
@@ -6124,7 +6161,7 @@ var sidebarItems = [
6124
6161
  // src/ui/Welcome.tsx
6125
6162
  import Image, { TerminalInfoContext, defaultTerminalInfo } from "ink-picture";
6126
6163
  import { jsx as jsx10, jsxs as jsxs11 } from "react/jsx-runtime";
6127
- var IMAGE_PATH = join11(dirname5(fileURLToPath2(import.meta.url)), "algolia.png");
6164
+ var IMAGE_PATH = join11(dirname6(fileURLToPath2(import.meta.url)), "algolia.png");
6128
6165
  var TERMINAL_INFO = {
6129
6166
  ...defaultTerminalInfo,
6130
6167
  supportsUnicode: true,
@@ -7442,11 +7479,11 @@ async function requestTerminalSize(stdout = process.stdout, {
7442
7479
  stdout.write("\x1B[2J\x1B[H");
7443
7480
  }
7444
7481
  function waitForResize(stdout, timeoutMs) {
7445
- return new Promise((resolve4) => {
7482
+ return new Promise((resolve5) => {
7446
7483
  const finish = (didResize) => () => {
7447
7484
  clearTimeout(timer);
7448
7485
  stdout.off("resize", onResize);
7449
- resolve4(didResize);
7486
+ resolve5(didResize);
7450
7487
  };
7451
7488
  const onResize = finish(true);
7452
7489
  const timer = setTimeout(finish(false), timeoutMs);
@@ -7454,15 +7491,15 @@ function waitForResize(stdout, timeoutMs) {
7454
7491
  });
7455
7492
  }
7456
7493
  function delay(ms) {
7457
- return new Promise((resolve4) => {
7458
- setTimeout(resolve4, ms);
7494
+ return new Promise((resolve5) => {
7495
+ setTimeout(resolve5, ms);
7459
7496
  });
7460
7497
  }
7461
7498
 
7462
7499
  // package.json with { type: 'json' }
7463
7500
  var package_default2 = {
7464
7501
  name: "@algolia/wizard",
7465
- version: "0.67.0",
7502
+ version: "0.68.0",
7466
7503
  description: "Magically implement Algolia functionality in your codebase",
7467
7504
  type: "module",
7468
7505
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.67.0",
3
+ "version": "0.68.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {