@algolia/wizard 0.67.0 → 0.69.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 +85 -45
  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.69.0",
1973
1973
  description: "Magically implement Algolia functionality in your codebase",
1974
1974
  type: "module",
1975
1975
  engines: {
@@ -2810,10 +2810,11 @@ import { relative as relative3 } from "node:path";
2810
2810
  import { z as z12 } from "zod";
2811
2811
 
2812
2812
  // src/lib/keychain.ts
2813
+ import { createHash } from "node:crypto";
2813
2814
  import { deletePassword, getPassword, setPassword } from "cross-keychain";
2814
2815
  import { z as z11 } from "zod";
2815
2816
  var SERVICE = "algolia-wizard";
2816
- var account = (userId) => `api-keys:${userId}`;
2817
+ var account = (userId) => `api-keys-${createHash("sha256").update(userId).digest("hex")}`;
2817
2818
  var storedKeysSchema = z11.record(z11.string(), z11.string());
2818
2819
  function entryId(kind, index, appId) {
2819
2820
  return `${kind}:${appId}:${index}`;
@@ -2875,15 +2876,17 @@ function storeKey(kind, userId, index, appId, value) {
2875
2876
  }
2876
2877
  function deleteStoredKeys(userId) {
2877
2878
  return serialized(async () => {
2878
- try {
2879
- await deletePassword(SERVICE, account(userId));
2880
- } catch (err) {
2881
- const message = err.message;
2882
- if (/not found/i.test(message)) return;
2883
- logger.warn(
2884
- { err: message, userId },
2885
- "could not delete the API keys from the keychain"
2886
- );
2879
+ for (const keychainAccount of [account(userId), "api-keys"]) {
2880
+ try {
2881
+ await deletePassword(SERVICE, keychainAccount);
2882
+ } catch (err) {
2883
+ const message = err.message;
2884
+ if (/not found/i.test(message)) continue;
2885
+ logger.warn(
2886
+ { err: message, userId },
2887
+ "could not delete the API keys from the keychain"
2888
+ );
2889
+ }
2887
2890
  }
2888
2891
  });
2889
2892
  }
@@ -3016,10 +3019,10 @@ var GIT_ENV_OVERRIDES = [
3016
3019
  function gitSucceeds(root, args) {
3017
3020
  const env = { ...process.env };
3018
3021
  for (const key of GIT_ENV_OVERRIDES) delete env[key];
3019
- return new Promise((resolve4) => {
3022
+ return new Promise((resolve5) => {
3020
3023
  execFile("git", ["-C", root, ...args], { env }, (err) => {
3021
- if (!err) return resolve4(true);
3022
- resolve4(
3024
+ if (!err) return resolve5(true);
3025
+ resolve5(
3023
3026
  err.code === 1 ? false : void 0
3024
3027
  );
3025
3028
  });
@@ -3303,7 +3306,7 @@ import { relative as relative5 } from "node:path";
3303
3306
  // src/lib/tools/reviewScript.ts
3304
3307
  import { tool as tool8 } from "ai";
3305
3308
  import z15 from "zod";
3306
- import { createHash } from "node:crypto";
3309
+ import { createHash as createHash2 } from "node:crypto";
3307
3310
  import { readFile as readFile7, stat as stat2 } from "node:fs/promises";
3308
3311
  import { relative as relative4 } from "node:path";
3309
3312
 
@@ -3320,7 +3323,7 @@ function serializePrompt(work) {
3320
3323
  var reviewedCommandApprovals = /* @__PURE__ */ new WeakMap();
3321
3324
  async function fileDigest(filePath) {
3322
3325
  const content = await readFile7(filePath);
3323
- return createHash("sha256").update(content).digest("hex");
3326
+ return createHash2("sha256").update(content).digest("hex");
3324
3327
  }
3325
3328
  function grantReviewedCommandApproval(ctx, approval) {
3326
3329
  reviewedCommandApprovals.set(ctx, approval);
@@ -3466,7 +3469,7 @@ var SIGKILL_DELAY_MS = 5e3;
3466
3469
  function runShell(command, opts) {
3467
3470
  const timeoutMs = opts.timeoutMs ?? DEFAULT_SHELL_TIMEOUT_MS;
3468
3471
  const startedAt = Date.now();
3469
- return new Promise((resolve4) => {
3472
+ return new Promise((resolve5) => {
3470
3473
  let output = "";
3471
3474
  let timedOut = false;
3472
3475
  let settled = false;
@@ -3481,7 +3484,7 @@ function runShell(command, opts) {
3481
3484
  settled = true;
3482
3485
  clearTimeout(timer);
3483
3486
  clearTimeout(killTimer);
3484
- resolve4({
3487
+ resolve5({
3485
3488
  exitCode,
3486
3489
  output: truncateText(output.trim()),
3487
3490
  timedOut,
@@ -3738,8 +3741,8 @@ function defaultCreateModel() {
3738
3741
  }
3739
3742
  function approvedCommandHistory(approvedCommands) {
3740
3743
  return Array.from(approvedCommands).map((entry) => {
3741
- const sep2 = entry.indexOf("\0");
3742
- return { cwd: entry.slice(0, sep2), command: entry.slice(sep2 + 1) };
3744
+ const sep3 = entry.indexOf("\0");
3745
+ return { cwd: entry.slice(0, sep3), command: entry.slice(sep3 + 1) };
3743
3746
  });
3744
3747
  }
3745
3748
  async function classifyCommandSafety(createModel, command, cwd, explanation, approvedHistory) {
@@ -4854,7 +4857,7 @@ ${formatCompletedSteps(ctx.completedSteps)}`,
4854
4857
  // src/actions/implement.ts
4855
4858
  import z28 from "zod";
4856
4859
  import { access, mkdir as mkdir5, readFile as readFile8 } from "node:fs/promises";
4857
- import { join as join10, relative as relative6 } from "node:path";
4860
+ import { dirname as dirname5, isAbsolute as isAbsolute3, join as join10, relative as relative6, resolve as resolve4, sep as sep2 } from "node:path";
4858
4861
 
4859
4862
  // src/lib/git.ts
4860
4863
  import { execFile as execFile2 } from "node:child_process";
@@ -4862,7 +4865,7 @@ import { copyFile, mkdir as mkdir4, stat as stat3 } from "node:fs/promises";
4862
4865
  import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute2, join as join8, resolve as resolve3 } from "node:path";
4863
4866
  var MAX_BUFFER = 32 * 1024 * 1024;
4864
4867
  function git(args) {
4865
- return new Promise((resolve4, reject) => {
4868
+ return new Promise((resolve5, reject) => {
4866
4869
  execFile2("git", args, { maxBuffer: MAX_BUFFER }, (err, stdout, stderr) => {
4867
4870
  if (err)
4868
4871
  return reject(
@@ -4870,7 +4873,7 @@ function git(args) {
4870
4873
  `git ${args.join(" ")} failed: ${stderr.toString().trim() || err.message}`
4871
4874
  )
4872
4875
  );
4873
- resolve4(stdout.toString());
4876
+ resolve5(stdout.toString());
4874
4877
  });
4875
4878
  });
4876
4879
  }
@@ -5133,12 +5136,22 @@ function searchInstructions(input) {
5133
5136
  const entity = input.findings.confirmedEntities ? input.findings.confirmedEntities[0].name : null;
5134
5137
  const attributes = input.findings.confirmedEntities ? input.findings.confirmedEntities[0].attributes : null;
5135
5138
  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));
5139
+ const packageManagedInstructions = input.frontendHasPackageJson ? packageSearchInstructions(input) : cdnSearchInstructions(input);
5137
5140
  return [
5138
5141
  "Implement an in-app Algolia search experience.",
5139
5142
  entitySchemaMessage ?? "",
5140
5143
  `Build the search UI for ${input.searchUiTarget}.`,
5141
5144
  "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.",
5145
+ ...packageManagedInstructions,
5146
+ "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.",
5147
+ "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.",
5148
+ "Match the styles of the application as closely as possible.",
5149
+ "The summary should be extremely concise; do not mention manual testing steps."
5150
+ ];
5151
+ }
5152
+ function packageSearchInstructions(input) {
5153
+ const doc = getFrameworkSpecificDoc(frameworksForDoc(input.language));
5154
+ return [
5142
5155
  ...doc ? [
5143
5156
  "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
5157
  doc
@@ -5149,16 +5162,22 @@ function searchInstructions(input) {
5149
5162
  `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
5163
  "If a search box already exists, replace its usage with an import and render of your new component; remove the old implementation.",
5151
5164
  "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
5165
  "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
5166
  `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
5167
  `Set ${SEARCH_CONFIG_APP_ID} to "${input.appId}" and ${SEARCH_CONFIG_INDEX_NAME} to "${input.targetIndex}".`,
5157
5168
  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
5169
  '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."
5170
+ "Install any Algolia packages you import with the project's own package manager via runShell, and declare them in the project's dependency manifest."
5171
+ ];
5172
+ }
5173
+ function cdnSearchInstructions(input) {
5174
+ return [
5175
+ `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.`,
5176
+ `Set window.${SEARCH_CONFIG_APP_ID} to "${input.appId}" and window.${SEARCH_CONFIG_INDEX_NAME} to "${input.targetIndex}".`,
5177
+ 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.`,
5178
+ '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>.',
5179
+ '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.',
5180
+ `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
5181
  ];
5163
5182
  }
5164
5183
  function validationInstructions(input) {
@@ -5170,6 +5189,9 @@ function validationInstructions(input) {
5170
5189
  "Do not run the test suite or any test command.",
5171
5190
  "Do not modify files. Report each implementation issue as a concrete instruction for the next implementation pass.",
5172
5191
  `Available type-check and lint tools: ${JSON.stringify(input.findings.verification ?? [])}.`,
5192
+ ...!input.frontendHasPackageJson ? [
5193
+ "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."
5194
+ ] : [],
5173
5195
  "Always call reportStatus with status=success after validation, even when sufficient=false.",
5174
5196
  "Set sufficient=true only when the search bar is unique, correctly placed, and structurally complete.",
5175
5197
  "Set sufficient=false for an implementation issue. Include concrete additionalInstructions for the next pass.",
@@ -5325,11 +5347,25 @@ async function pathExists(path) {
5325
5347
  return false;
5326
5348
  }
5327
5349
  }
5350
+ async function frontendHasPackageJson(repoRoot, searchLocation) {
5351
+ let directory = repoRoot;
5352
+ if (searchLocation) {
5353
+ const candidate = dirname5(resolve4(repoRoot, searchLocation));
5354
+ const candidateRelative = relative6(repoRoot, candidate);
5355
+ const outsideRoot = candidateRelative === ".." || candidateRelative.startsWith(`..${sep2}`) || isAbsolute3(candidateRelative);
5356
+ if (!outsideRoot) directory = candidate;
5357
+ }
5358
+ for (; ; ) {
5359
+ if (await pathExists(join10(directory, "package.json"))) return true;
5360
+ if (directory === repoRoot) return false;
5361
+ directory = dirname5(directory);
5362
+ }
5363
+ }
5328
5364
  async function resolveBuildCheckPlan(ctx, repoRoot, input) {
5329
5365
  if (!input.findings.verification?.length) {
5330
5366
  return { run: false, installDependencies: false };
5331
5367
  }
5332
- const installDependencies = isJsProject(input.language) && !await pathExists(join10(repoRoot, "node_modules"));
5368
+ const installDependencies = input.frontendHasPackageJson && isJsProject(input.language) && !await pathExists(join10(repoRoot, "node_modules"));
5333
5369
  const accepted = Boolean(
5334
5370
  await ctx.requestUserInput({
5335
5371
  prompt: installDependencies ? MISSING_DEPENDENCIES_PROMPT : BUILD_CHECK_PROMPT,
@@ -5507,7 +5543,11 @@ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES) {
5507
5543
  ingestDir: INGEST_DIR,
5508
5544
  ingestionSource,
5509
5545
  uploadFilePath,
5510
- searchUiTarget: searchUiTarget(language)
5546
+ searchUiTarget: searchUiTarget(language),
5547
+ frontendHasPackageJson: await frontendHasPackageJson(
5548
+ repoRoot,
5549
+ searchLocation
5550
+ )
5511
5551
  };
5512
5552
  let agentRuns = 0;
5513
5553
  let ingestCommand;
@@ -6092,7 +6132,7 @@ function getWorkflow(id) {
6092
6132
  }
6093
6133
 
6094
6134
  // src/ui/Welcome.tsx
6095
- import { dirname as dirname5, join as join11 } from "node:path";
6135
+ import { dirname as dirname6, join as join11 } from "node:path";
6096
6136
  import { fileURLToPath as fileURLToPath2 } from "node:url";
6097
6137
  import { useState as useState10 } from "react";
6098
6138
  import { Box as Box11, Spacer, Text as Text12, useInput as useInput6, useWindowSize as useWindowSize5 } from "ink";
@@ -6124,7 +6164,7 @@ var sidebarItems = [
6124
6164
  // src/ui/Welcome.tsx
6125
6165
  import Image, { TerminalInfoContext, defaultTerminalInfo } from "ink-picture";
6126
6166
  import { jsx as jsx10, jsxs as jsxs11 } from "react/jsx-runtime";
6127
- var IMAGE_PATH = join11(dirname5(fileURLToPath2(import.meta.url)), "algolia.png");
6167
+ var IMAGE_PATH = join11(dirname6(fileURLToPath2(import.meta.url)), "algolia.png");
6128
6168
  var TERMINAL_INFO = {
6129
6169
  ...defaultTerminalInfo,
6130
6170
  supportsUnicode: true,
@@ -7442,11 +7482,11 @@ async function requestTerminalSize(stdout = process.stdout, {
7442
7482
  stdout.write("\x1B[2J\x1B[H");
7443
7483
  }
7444
7484
  function waitForResize(stdout, timeoutMs) {
7445
- return new Promise((resolve4) => {
7485
+ return new Promise((resolve5) => {
7446
7486
  const finish = (didResize) => () => {
7447
7487
  clearTimeout(timer);
7448
7488
  stdout.off("resize", onResize);
7449
- resolve4(didResize);
7489
+ resolve5(didResize);
7450
7490
  };
7451
7491
  const onResize = finish(true);
7452
7492
  const timer = setTimeout(finish(false), timeoutMs);
@@ -7454,15 +7494,15 @@ function waitForResize(stdout, timeoutMs) {
7454
7494
  });
7455
7495
  }
7456
7496
  function delay(ms) {
7457
- return new Promise((resolve4) => {
7458
- setTimeout(resolve4, ms);
7497
+ return new Promise((resolve5) => {
7498
+ setTimeout(resolve5, ms);
7459
7499
  });
7460
7500
  }
7461
7501
 
7462
7502
  // package.json with { type: 'json' }
7463
7503
  var package_default2 = {
7464
7504
  name: "@algolia/wizard",
7465
- version: "0.67.0",
7505
+ version: "0.69.0",
7466
7506
  description: "Magically implement Algolia functionality in your codebase",
7467
7507
  type: "module",
7468
7508
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.67.0",
3
+ "version": "0.69.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {