@wayai/cli 0.3.56 → 0.3.57

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.
package/dist/index.js CHANGED
@@ -174,6 +174,11 @@ var init_sentry = __esm({
174
174
  });
175
175
 
176
176
  // src/lib/api-client.ts
177
+ var api_client_exports = {};
178
+ __export(api_client_exports, {
179
+ ApiClient: () => ApiClient,
180
+ ApiError: () => ApiError
181
+ });
177
182
  function isRetryableErrorBody(body) {
178
183
  try {
179
184
  const parsed = JSON.parse(body);
@@ -8230,13 +8235,14 @@ function writeVersionCache(filename, cache) {
8230
8235
  function touchVersionCache(filename) {
8231
8236
  writeVersionCache(filename, { lastCheck: Date.now(), latest: readVersionCache(filename)?.latest ?? null });
8232
8237
  }
8233
- var MAX_AGE_24H_MS, CLI_CACHE_FILE, SKILL_CACHE_FILE;
8238
+ var MAX_AGE_24H_MS, CLI_CACHE_FILE, SKILL_CACHE_FILE, ADMIN_SKILL_CACHE_FILE;
8234
8239
  var init_version_cache = __esm({
8235
8240
  "src/lib/version-cache.ts"() {
8236
8241
  "use strict";
8237
8242
  MAX_AGE_24H_MS = 24 * 60 * 60 * 1e3;
8238
8243
  CLI_CACHE_FILE = "update-check.json";
8239
8244
  SKILL_CACHE_FILE = "skill-update-check.json";
8245
+ ADMIN_SKILL_CACHE_FILE = "admin-skill-update-check.json";
8240
8246
  }
8241
8247
  });
8242
8248
 
@@ -8244,6 +8250,9 @@ var init_version_cache = __esm({
8244
8250
  import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
8245
8251
  import { join as join7 } from "path";
8246
8252
  import * as yaml3 from "js-yaml";
8253
+ function skillInstallPaths(skillName) {
8254
+ return HARNESS_SKILL_DIRS.map((dir) => `${dir}/skills/${skillName}/${SKILL_FILENAME}`);
8255
+ }
8247
8256
  function parseFrontmatterVersion(content) {
8248
8257
  const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
8249
8258
  if (!match) return null;
@@ -8257,9 +8266,9 @@ function parseFrontmatterVersion(content) {
8257
8266
  const v = parsed.version;
8258
8267
  return typeof v === "string" ? v : null;
8259
8268
  }
8260
- function findInstalledSkills(projectRoot) {
8269
+ function findInstalledSkills(projectRoot, paths = SKILL_INSTALL_PATHS) {
8261
8270
  const found = [];
8262
- for (const rel of SKILL_INSTALL_PATHS) {
8271
+ for (const rel of paths) {
8263
8272
  const path22 = join7(projectRoot, rel);
8264
8273
  if (!existsSync5(path22)) continue;
8265
8274
  let version = null;
@@ -8276,20 +8285,28 @@ function lowestInstalledVersion(installs) {
8276
8285
  if (versions.length === 0) return null;
8277
8286
  return versions.reduce((lowest, v) => isNewerVersion(lowest, v) ? v : lowest);
8278
8287
  }
8279
- var DEFAULT_SKILL_RAW_URL, HARNESS_SKILL_DIRS, SKILL_INSTALL_PATHS;
8288
+ var DEFAULT_SKILL_RAW_URL, HARNESS_SKILL_DIRS, SKILL_FILENAME, SKILL_INSTALL_PATHS, ADMIN_SKILL_NAME, ADMIN_SKILL_INSTALL_PATHS;
8280
8289
  var init_skill_version = __esm({
8281
8290
  "src/lib/skill-version.ts"() {
8282
8291
  "use strict";
8283
8292
  init_utils();
8284
8293
  DEFAULT_SKILL_RAW_URL = "https://raw.githubusercontent.com/wayai-pro/wayai-skill/main/skills/wayai/SKILL.md";
8285
8294
  HARNESS_SKILL_DIRS = [".claude", ".opencode", ".agents"];
8286
- SKILL_INSTALL_PATHS = HARNESS_SKILL_DIRS.map(
8287
- (dir) => `${dir}/skills/wayai/SKILL.md`
8288
- );
8295
+ SKILL_FILENAME = "SKILL.md";
8296
+ SKILL_INSTALL_PATHS = skillInstallPaths("wayai");
8297
+ ADMIN_SKILL_NAME = "wayai-admin";
8298
+ ADMIN_SKILL_INSTALL_PATHS = skillInstallPaths(ADMIN_SKILL_NAME);
8289
8299
  }
8290
8300
  });
8291
8301
 
8292
8302
  // src/lib/config.ts
8303
+ var config_exports = {};
8304
+ __export(config_exports, {
8305
+ deleteConfig: () => deleteConfig,
8306
+ getConfigPath: () => getConfigPath,
8307
+ readConfig: () => readConfig,
8308
+ writeConfig: () => writeConfig
8309
+ });
8293
8310
  import * as fs5 from "fs";
8294
8311
  import * as path5 from "path";
8295
8312
  import * as os from "os";
@@ -8299,6 +8316,9 @@ function configDir() {
8299
8316
  function configPath() {
8300
8317
  return path5.join(configDir(), "config.json");
8301
8318
  }
8319
+ function getConfigPath() {
8320
+ return configPath();
8321
+ }
8302
8322
  function readConfig() {
8303
8323
  if (!fs5.existsSync(configPath())) return null;
8304
8324
  try {
@@ -8334,6 +8354,11 @@ function writeConfig(config) {
8334
8354
  // owner-only read/write
8335
8355
  });
8336
8356
  }
8357
+ function deleteConfig() {
8358
+ if (fs5.existsSync(configPath())) {
8359
+ fs5.unlinkSync(configPath());
8360
+ }
8361
+ }
8337
8362
  var init_config = __esm({
8338
8363
  "src/lib/config.ts"() {
8339
8364
  "use strict";
@@ -8628,6 +8653,22 @@ var init_token_store = __esm({
8628
8653
  });
8629
8654
 
8630
8655
  // src/lib/auth.ts
8656
+ var auth_exports = {};
8657
+ __export(auth_exports, {
8658
+ OAUTH_CALLBACK_PORT: () => OAUTH_CALLBACK_PORT,
8659
+ exchangeCodeForTokens: () => exchangeCodeForTokens,
8660
+ expiresInToIso: () => expiresInToIso,
8661
+ generateCodeChallenge: () => generateCodeChallenge,
8662
+ generateCodeVerifier: () => generateCodeVerifier,
8663
+ generateState: () => generateState,
8664
+ getAccessToken: () => getAccessToken,
8665
+ getAuthKitClientId: () => getAuthKitClientId,
8666
+ getAuthKitDomain: () => getAuthKitDomain,
8667
+ refreshAccessToken: () => refreshAccessToken,
8668
+ requireAuth: () => requireAuth,
8669
+ startCallbackServer: () => startCallbackServer,
8670
+ validateToken: () => validateToken
8671
+ });
8631
8672
  import * as crypto2 from "crypto";
8632
8673
  import * as http from "http";
8633
8674
  function generateCodeVerifier() {
@@ -18245,10 +18286,39 @@ async function refreshSkillCache() {
18245
18286
  clearTimeout(timer);
18246
18287
  }
18247
18288
  }
18289
+ async function refreshAdminSkillCache() {
18290
+ let timer;
18291
+ const deadline = new Promise((resolve5) => {
18292
+ timer = setTimeout(resolve5, REFRESH_TIMEOUT_MS);
18293
+ });
18294
+ await Promise.race([deadline, fetchAndCacheAdminSkillVersion().catch(() => {
18295
+ })]);
18296
+ if (timer) clearTimeout(timer);
18297
+ }
18298
+ async function fetchAndCacheAdminSkillVersion() {
18299
+ const [{ readConfig: readConfig2 }, { getAccessToken: getAccessToken2 }, { ApiClient: ApiClient2 }] = await Promise.all([
18300
+ Promise.resolve().then(() => (init_config(), config_exports)),
18301
+ Promise.resolve().then(() => (init_auth(), auth_exports)),
18302
+ Promise.resolve().then(() => (init_api_client(), api_client_exports))
18303
+ ]);
18304
+ const config = readConfig2();
18305
+ if (!config) return;
18306
+ const accessToken = await getAccessToken2(config);
18307
+ const client = new ApiClient2({ apiUrl: config.api_url, accessToken });
18308
+ const res = await client.adminSkillInstall(ADMIN_SKILL_NAME);
18309
+ const latest = parseFrontmatterVersion(res.files[SKILL_FILENAME] ?? "");
18310
+ if (latest) {
18311
+ try {
18312
+ writeVersionCache(ADMIN_SKILL_CACHE_FILE, { lastCheck: Date.now(), latest });
18313
+ } catch {
18314
+ }
18315
+ }
18316
+ }
18248
18317
  async function refreshVersionCaches(opts) {
18249
18318
  await Promise.all([
18250
18319
  opts.cli ? refreshCliCache() : Promise.resolve(),
18251
- opts.skill ? refreshSkillCache() : Promise.resolve()
18320
+ opts.skill ? refreshSkillCache() : Promise.resolve(),
18321
+ opts.adminSkill ? refreshAdminSkillCache() : Promise.resolve()
18252
18322
  ]);
18253
18323
  }
18254
18324
 
@@ -18261,6 +18331,7 @@ import { spawn } from "child_process";
18261
18331
  var REFRESH_COMMAND = "__refresh-version-cache";
18262
18332
  var ENV_REFRESH_CLI = "WAYAI_REFRESH_CLI";
18263
18333
  var ENV_REFRESH_SKILL = "WAYAI_REFRESH_SKILL";
18334
+ var ENV_REFRESH_ADMIN_SKILL = "WAYAI_REFRESH_ADMIN_SKILL";
18264
18335
  function isUpdateCheckDisabled() {
18265
18336
  return Boolean(
18266
18337
  process.env.NO_UPDATE_NOTIFIER || process.env.WAYAI_NO_UPDATE_CHECK || process.env.CI
@@ -18270,6 +18341,7 @@ function scheduleVersionRefresh(opts, entryPath) {
18270
18341
  try {
18271
18342
  if (opts.cli) touchVersionCache(CLI_CACHE_FILE);
18272
18343
  if (opts.skill) touchVersionCache(SKILL_CACHE_FILE);
18344
+ if (opts.adminSkill) touchVersionCache(ADMIN_SKILL_CACHE_FILE);
18273
18345
  spawn(process.execPath, [entryPath, REFRESH_COMMAND], {
18274
18346
  detached: true,
18275
18347
  stdio: "ignore",
@@ -18278,7 +18350,8 @@ function scheduleVersionRefresh(opts, entryPath) {
18278
18350
  env: {
18279
18351
  ...process.env,
18280
18352
  [ENV_REFRESH_CLI]: opts.cli ? "1" : "",
18281
- [ENV_REFRESH_SKILL]: opts.skill ? "1" : ""
18353
+ [ENV_REFRESH_SKILL]: opts.skill ? "1" : "",
18354
+ [ENV_REFRESH_ADMIN_SKILL]: opts.adminSkill ? "1" : ""
18282
18355
  }
18283
18356
  }).unref();
18284
18357
  } catch {
@@ -18293,7 +18366,8 @@ function showUpdateNudges(currentVersion, entryPath) {
18293
18366
  Update available: ${currentVersion} \u2192 ${cliLatest}
18294
18367
  Run \`wayai update\` to update.`);
18295
18368
  }
18296
- const installs = findInstalledSkills(findRepoRootSync() ?? process.cwd());
18369
+ const repoRoot = findRepoRootSync() ?? process.cwd();
18370
+ const installs = findInstalledSkills(repoRoot);
18297
18371
  const localSkillVersion = installs.length > 0 ? lowestInstalledVersion(installs) : null;
18298
18372
  if (localSkillVersion) {
18299
18373
  const skillLatest = readVersionCache(SKILL_CACHE_FILE)?.latest ?? null;
@@ -18303,10 +18377,21 @@ Skill update available: ${localSkillVersion} \u2192 ${skillLatest}
18303
18377
  Run \`npx skills add wayai-pro/wayai-skill -y\` to update.`);
18304
18378
  }
18305
18379
  }
18380
+ const adminInstalls = findInstalledSkills(repoRoot, ADMIN_SKILL_INSTALL_PATHS);
18381
+ const localAdminVersion = adminInstalls.length > 0 ? lowestInstalledVersion(adminInstalls) : null;
18382
+ if (localAdminVersion) {
18383
+ const adminLatest = readVersionCache(ADMIN_SKILL_CACHE_FILE)?.latest ?? null;
18384
+ if (adminLatest && isNewerVersion(adminLatest, localAdminVersion)) {
18385
+ console.error(`
18386
+ Admin skill update available: ${localAdminVersion} \u2192 ${adminLatest}
18387
+ Run \`wayai admin skill install\` to update.`);
18388
+ }
18389
+ }
18306
18390
  const cliStale = isVersionCacheStale(CLI_CACHE_FILE);
18307
18391
  const skillStale = localSkillVersion !== null && isVersionCacheStale(SKILL_CACHE_FILE);
18308
- if (cliStale || skillStale) {
18309
- scheduleVersionRefresh({ cli: cliStale, skill: skillStale }, entryPath);
18392
+ const adminSkillStale = localAdminVersion !== null && isVersionCacheStale(ADMIN_SKILL_CACHE_FILE);
18393
+ if (cliStale || skillStale || adminSkillStale) {
18394
+ scheduleVersionRefresh({ cli: cliStale, skill: skillStale, adminSkill: adminSkillStale }, entryPath);
18310
18395
  }
18311
18396
  } catch {
18312
18397
  }
@@ -18601,7 +18686,8 @@ async function runForeground() {
18601
18686
  if (isBackgroundRefresh) {
18602
18687
  void refreshVersionCaches({
18603
18688
  cli: process.env[ENV_REFRESH_CLI] === "1",
18604
- skill: process.env[ENV_REFRESH_SKILL] === "1"
18689
+ skill: process.env[ENV_REFRESH_SKILL] === "1",
18690
+ adminSkill: process.env[ENV_REFRESH_ADMIN_SKILL] === "1"
18605
18691
  }).finally(() => process.exit(0));
18606
18692
  } else {
18607
18693
  void runForeground();