jackwener/OpenCLI · error · CliError

ACTION_NOT_AVAILABLE

ACTION_NOT_AVAILABLE

Error message

ACTION_NOT_AVAILABLE

What it means

resolveCurrentUserIdentity runs injected JS on the logged-in Zhihu page to determine the current user's profile slug, and throws CliError('ACTION_NOT_AVAILABLE') if no slug can be resolved. The write commands need the caller's identity before performing the write; without it the action cannot proceed safely, so the library aborts before touching the site.

Source

Thrown at clis/zhihu/write-shared.js:210

      || (state && state.initialState && state.initialState.me && state.initialState.me.slug);
    if (typeof slugFromState === 'string' && slugFromState) return { slug: slugFromState };

    const navScopes = Array.from(document.querySelectorAll(navScopeSelector));
    const slug = findCurrentUserSlugFromRoots(navScopes, true) || findCurrentUserSlugFromRoots([document], false);
    if (slug) return { slug };

    var avatarImgs = document.querySelectorAll('header img[alt*="\\u4e3b\\u9875"]');
    for (var ai = 0; ai < avatarImgs.length; ai++) {
      var altMatch = (avatarImgs[ai].alt || '').match(/\\u70b9\\u51fb\\u6253\\u5f00(.+?)\\u7684\\u4e3b\\u9875/);
      if (altMatch) return { slug: altMatch[1] };
    }
    return null;
  })()`;
}
export async function resolveCurrentUserIdentity(page) {
    const identity = await page.evaluate(buildResolveCurrentUserIdentityJs());
    if (!identity?.slug) {
        throw new CliError('ACTION_NOT_AVAILABLE', 'Could not resolve the logged-in Zhihu user identity before write');
    }
    return identity.slug;
}
export function buildResultRow(message, targetType, target, outcome, extra = {}) {
    for (const key of Object.keys(extra)) {
        if (RESULT_ROW_RESERVED_KEYS.has(key)) {
            throw new CliError('INVALID_INPUT', `Result extra field cannot overwrite reserved key: ${key}`);
        }
    }
    return [{ status: 'success', outcome, message, target_type: targetType, target, ...extra }];
}
export const __test__ = {
    requireExecute,
    resolvePayload,
    resolveCurrentUserIdentity,
    resolveCurrentUserSlugFromDom,
    buildResultRow,
};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open the controlled Chrome/Chromium browser and log in to zhihu.com, then retry
  2. Verify login by loading zhihu.com manually and confirming your profile is visible
  3. Update the opencli zhihu adapter if Zhihu changed its page layout (check for a newer version)
  4. Retry later if Zhihu is serving an anti-bot or verification page
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await zhihuWrite(args);
} catch (e) {
  if (e?.code === 'ACTION_NOT_AVAILABLE') {
    // prompt user to log in to zhihu.com in the controlled browser, then retry
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling a zhihu write command when the browser session is not logged in, the page.evaluate returns an identity object without a slug, or Zhihu changed its DOM so the injected identity-extraction script (buildResolveCurrentUserIdentityJs) can no longer find the user's profile link.

Common situations: Expired Zhihu login cookies, writing before ever logging into Zhihu in the controlled browser, Zhihu shipping a layout/DOM change that breaks the self-identity extraction selectors, or running against a restricted/incognito profile.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f45d15be370c49ba. Report an issue: GitHub.