{"record":{"id":"1b20023a3c03fcd4","repo":"jackwener/OpenCLI","slug":"session-is-a-required-positional-argument-openc","errorCode":null,"errorMessage":"<session> is a required positional argument: opencli browser <session> <command>","messagePattern":"<session> is a required positional argument: opencli browser <session> <command>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":680,"sourceCode":"}\n\nfunction getCommandOption(command: Command | undefined, option: string): unknown {\n  let current: Command | undefined = command;\n  while (current) {\n    const opts = current.opts();\n    if (Object.prototype.hasOwnProperty.call(opts, option) && opts[option] !== undefined) return opts[option];\n    current = current.parent as Command | undefined;\n  }\n  return undefined;\n}\n\nfunction getBrowserSession(command?: Command): string {\n  // The CLI surface is `opencli browser <session> <subcommand>`. main.ts rewrites\n  // argv to insert `--session <name>` before commander parses it; this helper\n  // reads back the rewritten flag.\n  const raw = getCommandOption(command, 'session');\n  if (typeof raw === 'string' && raw.trim()) return raw.trim();\n  throw new Error('<session> is a required positional argument: opencli browser <session> <command>');\n}\n\nfunction getBrowserProfileSelection(command?: Command): ProfileSelection | undefined {\n  const raw = getCommandOption(command, 'profile');\n  return resolveProfileSelection(typeof raw === 'string' && raw.trim() ? raw.trim() : undefined);\n}\n\nfunction getPageSession(page: import('./types.js').IPage): string {\n  const session = (page as unknown as { session?: unknown }).session;\n  if (typeof session === 'string' && session.trim()) return session.trim();\n  throw new Error('Browser page is missing a session');\n}\n\nfunction getPageScope(page: import('./types.js').IPage): string {\n  // Scope is keyed by the SELECTED profile (explicit or preferred), matching\n  // getBrowserPage's targetScope — reading only the explicit contextId would\n  // save and look up the remembered tab under different keys whenever the\n  // profile came from the config default.","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L662-L698","documentation":"The `opencli browser` command group requires a session name positional: `opencli browser <session> <command>`. main.ts rewrites argv to insert `--session <name>` before commander parses; this helper throws when that flag is absent or empty/whitespace. It guarantees every browser subcommand operates on an identified session.","triggerScenarios":"Invoking a browser subcommand without the session positional, e.g. `opencli browser tab list` instead of `opencli browser mysession tab list`, or passing an empty/whitespace-only session value.","commonSituations":"Copy-pasted commands that dropped the session argument; scripting wrappers that build argv dynamically and skip an empty session; users of older CLI versions where session was optional.","solutions":["Add the session positional: opencli browser <session> tab list","Verify the session name is non-empty (quotes around it in shell scripts)","Check how main.ts rewrites argv if invoking programmatically — ensure the session positional is present in raw argv","Run opencli browser --help to confirm the required positional syntax"],"exampleFix":"// before\nopencli browser tab list\n// after\nopencli browser my-session tab list","handlingStrategy":"validation","validationCode":"const args = ['browser', session, 'tab', 'list'];\nif (!session || !session.trim()) throw new Error('browser commands require a non-empty <session> positional');","typeGuard":"function hasSession(s: unknown): s is string {\n  return typeof s === 'string' && s.trim().length > 0;\n}","tryCatchPattern":"try {\n  await run(['opencli', 'browser', session, 'tab', 'list']);\n} catch (e) {\n  if (String((e as Error).message).includes('required positional argument')) {\n    console.error('Usage: opencli browser <session> <command>');\n  }\n  throw e;\n}","preventionTips":["Always include the session positional immediately after `browser` in scripts","Quote session names to avoid shell word-splitting on empty variables","Use \"${session:?}\" in bash to fail early on unset/empty session variables","Check `opencli browser --help` when upgrading — the positional contract may change"],"tags":["cli","missing-argument","commander"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}