{"record":{"id":"f45d15be370c49ba","repo":"jackwener/OpenCLI","slug":"action-not-available","errorCode":"ACTION_NOT_AVAILABLE","errorMessage":"ACTION_NOT_AVAILABLE","messagePattern":"ACTION_NOT_AVAILABLE","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/write-shared.js","lineNumber":210,"sourceCode":"      || (state && state.initialState && state.initialState.me && state.initialState.me.slug);\n    if (typeof slugFromState === 'string' && slugFromState) return { slug: slugFromState };\n\n    const navScopes = Array.from(document.querySelectorAll(navScopeSelector));\n    const slug = findCurrentUserSlugFromRoots(navScopes, true) || findCurrentUserSlugFromRoots([document], false);\n    if (slug) return { slug };\n\n    var avatarImgs = document.querySelectorAll('header img[alt*=\"\\\\u4e3b\\\\u9875\"]');\n    for (var ai = 0; ai < avatarImgs.length; ai++) {\n      var altMatch = (avatarImgs[ai].alt || '').match(/\\\\u70b9\\\\u51fb\\\\u6253\\\\u5f00(.+?)\\\\u7684\\\\u4e3b\\\\u9875/);\n      if (altMatch) return { slug: altMatch[1] };\n    }\n    return null;\n  })()`;\n}\nexport async function resolveCurrentUserIdentity(page) {\n    const identity = await page.evaluate(buildResolveCurrentUserIdentityJs());\n    if (!identity?.slug) {\n        throw new CliError('ACTION_NOT_AVAILABLE', 'Could not resolve the logged-in Zhihu user identity before write');\n    }\n    return identity.slug;\n}\nexport function buildResultRow(message, targetType, target, outcome, extra = {}) {\n    for (const key of Object.keys(extra)) {\n        if (RESULT_ROW_RESERVED_KEYS.has(key)) {\n            throw new CliError('INVALID_INPUT', `Result extra field cannot overwrite reserved key: ${key}`);\n        }\n    }\n    return [{ status: 'success', outcome, message, target_type: targetType, target, ...extra }];\n}\nexport const __test__ = {\n    requireExecute,\n    resolvePayload,\n    resolveCurrentUserIdentity,\n    resolveCurrentUserSlugFromDom,\n    buildResultRow,\n};","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/write-shared.js#L192-L228","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the controlled Chrome/Chromium browser and log in to zhihu.com, then retry","Verify login by loading zhihu.com manually and confirming your profile is visible","Update the opencli zhihu adapter if Zhihu changed its page layout (check for a newer version)","Retry later if Zhihu is serving an anti-bot or verification page"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await zhihuWrite(args);\n} catch (e) {\n  if (e?.code === 'ACTION_NOT_AVAILABLE') {\n    // prompt user to log in to zhihu.com in the controlled browser, then retry\n  }\n  throw e;\n}","preventionTips":["Confirm you are logged into zhihu.com in the controlled browser before write commands","Re-login when cookies expire; check profile page loads","Keep the zhihu adapter updated for Zhihu DOM changes","Avoid incognito/fresh profiles that lack the session"],"tags":["authentication","scraping","zhihu"],"backgroundTag":"user-identity-unresolved","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}