google-gemini/gemini-cli · error · Error

Init command content must be a string.

Error message

Init command content must be a string.

What it means

Thrown by InitCommand.handleSubmitPromptResult when result.content (from performInit's submit_prompt branch) is not a string. performInit in @google/gemini-cli-core returns a typed union where submit_prompt.content is always a string prompt, so this is a defensive guard against the type being widened to unknown in the handler signature.

Source

Thrown at packages/a2a-server/src/commands/init.ts:98

    taskId: string,
    contextId: string,
  ): Promise<CommandExecutionResponse> {
    fs.writeFileSync(geminiMdPath, '', 'utf8');

    if (!context.agentExecutor) {
      throw new Error('Agent executor not found in context.');
    }
    // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
    const agentExecutor = context.agentExecutor as CoderAgentExecutor;

    const agentSettings: AgentSettings = {
      kind: CoderAgentEvent.StateAgentSettingsEvent,
      workspacePath: process.env['CODER_AGENT_WORKSPACE_PATH']!,
      autoExecute: true,
    };

    if (typeof result.content !== 'string') {
      throw new Error('Init command content must be a string.');
    }
    const promptText = result.content;

    const requestContext: RequestContext = {
      userMessage: {
        kind: 'message',
        role: 'user',
        parts: [{ kind: 'text', text: promptText }],
        messageId: uuidv4(),
        taskId,
        contextId,
        metadata: {
          coderAgent: agentSettings,
        },
      },
      taskId,
      contextId,
    };

View on GitHub (pinned to 5024443c72)

Solutions

  1. Verify performInit is the real implementation from @google/gemini-cli-core and returns a string content for submit_prompt.
  2. In tests, mock performInit to return content as a string literal.
  3. If a newer core legitimately returns structured content, update handleSubmitPromptResult to serialize it (JSON.stringify or extract a text field) instead of throwing.

Example fix

// before
if (typeof result.content !== 'string') {
  throw new Error('Init command content must be a string.');
}
const promptText = result.content;

// after (coerce structured content)
const promptText = typeof result.content === 'string'
  ? result.content
  : JSON.stringify(result.content);
Defensive patterns

Strategy: type-guard

Type guard

function isStringContent(r: { content: unknown }): r is { content: string } {
  return typeof r.content === 'string';
}
if (!isStringContent(result)) {
  throw new Error('performInit returned non-string content; check @google/gemini-cli-core version.');
}

Prevention

When it happens

Trigger: handleSubmitPromptResult receives a result object whose content field is not a string - only realistically reachable if performInit is monkey-patched, a different implementation is substituted, or a future core version changes the submit_prompt payload shape to a structured object.

Common situations: Mocking performInit in a test and returning { type: 'submit_prompt', content: { ... } }; version skew between a2a-server and @google/gemini-cli-core where content became an object.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/b08e73a161c9ea54. Report an issue: GitHub.