{"record":{"id":"b08e73a161c9ea54","repo":"google-gemini/gemini-cli","slug":"init-command-content-must-be-a-string","errorCode":null,"errorMessage":"Init command content must be a string.","messagePattern":"Init command content must be a string\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/a2a-server/src/commands/init.ts","lineNumber":98,"sourceCode":"    taskId: string,\n    contextId: string,\n  ): Promise<CommandExecutionResponse> {\n    fs.writeFileSync(geminiMdPath, '', 'utf8');\n\n    if (!context.agentExecutor) {\n      throw new Error('Agent executor not found in context.');\n    }\n    // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion\n    const agentExecutor = context.agentExecutor as CoderAgentExecutor;\n\n    const agentSettings: AgentSettings = {\n      kind: CoderAgentEvent.StateAgentSettingsEvent,\n      workspacePath: process.env['CODER_AGENT_WORKSPACE_PATH']!,\n      autoExecute: true,\n    };\n\n    if (typeof result.content !== 'string') {\n      throw new Error('Init command content must be a string.');\n    }\n    const promptText = result.content;\n\n    const requestContext: RequestContext = {\n      userMessage: {\n        kind: 'message',\n        role: 'user',\n        parts: [{ kind: 'text', text: promptText }],\n        messageId: uuidv4(),\n        taskId,\n        contextId,\n        metadata: {\n          coderAgent: agentSettings,\n        },\n      },\n      taskId,\n      contextId,\n    };","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/a2a-server/src/commands/init.ts#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify performInit is the real implementation from @google/gemini-cli-core and returns a string content for submit_prompt.","In tests, mock performInit to return content as a string literal.","If a newer core legitimately returns structured content, update handleSubmitPromptResult to serialize it (JSON.stringify or extract a text field) instead of throwing."],"exampleFix":"// before\nif (typeof result.content !== 'string') {\n  throw new Error('Init command content must be a string.');\n}\nconst promptText = result.content;\n\n// after (coerce structured content)\nconst promptText = typeof result.content === 'string'\n  ? result.content\n  : JSON.stringify(result.content);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isStringContent(r: { content: unknown }): r is { content: string } {\n  return typeof r.content === 'string';\n}\nif (!isStringContent(result)) {\n  throw new Error('performInit returned non-string content; check @google/gemini-cli-core version.');\n}","tryCatchPattern":null,"preventionTips":["Pin @google/gemini-cli-core to the version whose performInit return type matches InitCommand's expectation.","In tests, mock performInit to return a string content literal.","Add a type test (expectTypeOf) asserting performInit's submit_prompt content is string.","If content legitimately becomes structured, serialize it in handleSubmitPromptResult instead of throwing."],"tags":["init-command","type-validation","defensive-guard"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}