jackwener/OpenCLI · error · ArgumentError

is required

Error message

is required

What it means

The chat-read command requires an `id` positional argument and normalizes it with parseChatId; the ArgumentError with help text 'is required' is thrown when the id is missing or cannot be parsed into a Kimi chat id. As with maybeNavigateConv, the command navigates with ?chat_enter_method=history so Kimi actually loads the messages.

Source

Thrown at clis/kimi/chat.js:166

// -------- detail --------
cli({
    site: 'kimi',
    name: 'detail',
    access: 'read',
    description: 'Open a Kimi chat by ID and return its visible messages.',
    domain: KIMI_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'id', positional: true, required: true, help: 'Chat ID or full /chat/<id> URL' },
        { name: 'limit', type: 'int', required: false, default: 20 },
    ],
    columns: CHAT_COLUMNS,
    func: async (page, kwargs) => {
        const id = parseChatId(kwargs.id);
        if (!id) throw new ArgumentError('id', 'is required');
        // Same trick as maybeNavigateConv: include chat_enter_method=history
        // to actually trigger Kimi's messages fetch.
        await page.goto(`${KIMI_URL}chat/${id}?chat_enter_method=history`);
        for (let i = 0; i < 15; i++) {
            const ok = await page.evaluate(`(() => {
        const list = document.querySelector('.chat-content-list') || document.querySelector('.message-list');
        return !!list && list.querySelectorAll('.chat-content-item, .segment').length > 0;
      })()`);
            if (ok) break;
            await page.wait(1);
        }
        const turns = await readKimiTurns(page);
        if (!turns.length) {
            throw new EmptyResultError('kimi detail', `No messages found in /chat/${id}.`);
        }
        const limit = Number.isInteger(kwargs?.limit) && kwargs.limit > 0 ? kwargs.limit : 20;
        return turns.slice(0, limit).map((t, i) => ({ Index: i + 1, Role: t.role, Text: (t.text || '').slice(0, 1200) }));
    },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the id or full https://www.kimi.com/chat/<id> URL as the positional `id` argument
  2. Copy ChatId exactly from `kimi history` output
  3. Sanitize the value (trim whitespace, strip trailing punctuation) before passing
  4. Add shell-level validation that id is non-empty before invoking the command

Example fix

// before
await kimiReadChat({ limit: 20 }); // ArgumentError: id is required
// after
await kimiReadChat({ id: 'abc123', limit: 20 });
// or from a URL:
await kimiReadChat({ id: 'https://www.kimi.com/chat/abc123', limit: 20 });
Defensive patterns

Strategy: validation

Validate before calling

function requireKimiId(id) {
  const parsed = typeof id === 'string' ? (id.match(/kimi\.com\/chat\/([A-Za-z0-9_-]+)/)?.[1] || (id.match(/^[A-Za-z0-9_-]+$/) ? id : null)) : null;
  if (!parsed) throw new Error('kimi chat `id` is required: pass a chat id or kimi.com/chat/<id> URL');
  return parsed;
}
const id = requireKimiId(kwargs.id);

Type guard

function hasValidChatId(kwargs) {
  return typeof kwargs?.id === 'string' && kwargs.id.trim().length > 0 &&
    (/^[A-Za-z0-9_-]+$/.test(kwargs.id.trim()) || kwargs.id.includes('kimi.com/chat/'));
}

Try / catch

try {
  await kimiReadChat({ id, limit: 20 });
} catch (e) {
  if (e instanceof ArgumentError && /is required/.test(e.message)) {
    console.error('Usage: kimi read-chat <id|url> [--limit N]');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the command without the positional `id`, with an empty string, or with a value parseChatId cannot resolve (non-Kimi URL, malformed id, extra text around the id).

Common situations: Omitting the positional argument on the CLI; wrapping the id in quotes that include stray characters; pasting a share link in a different URL format; a script building kwargs dynamically and leaving id undefined.

Related errors


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