pi-gemini-empty-continuation

Pi extension that auto-recovers from Gemini thinking truncation and zero-token empty responses (Antigravity agy/jetski pattern)

Packages

Package details

extension

Install pi-gemini-empty-continuation from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-gemini-empty-continuation
Package
pi-gemini-empty-continuation
Version
1.0.0
Published
Sep 10, 2026
Downloads
268/mo · 268/wk
Author
sususu98
License
MIT
Types
extension
Size
14.2 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./extensions/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-gemini-empty-continuation

npm version Pi Catalog License: MIT

A Pi coding agent extension that auto-recovers from Gemini thinking truncation and zero-token empty responses, ported directly from Google Antigravity (agy / jetski) internal continuation architecture.

English | 中文说明


English

The Problem

Google Gemini (notably Gemini 3.8 Flash) occasionally outputs several thousand tokens of internal reasoning (thought: true), but stops before generating visible text (thought: false with text: "") without calling any tools.

In standard Pi agent runs, this causes the agent loop to interpret the turn as complete (stopReason: "stop"), leaving the user with an empty message bubble and stalled workflow. Generic retry extensions like pi-retry-empty fail to catch this because they only check for zeroTokens (whereas Gemini consumed hundreds or thousands of reasoning tokens).

The Solution: Antigravity Architecture

In Google's official Antigravity CLI (agy), this is solved through a dedicated post-invocation hook: empty_output_continuation_check.go.

This extension faithfully ports that architecture into Pi:

  1. Dual-Scenario Detection (diagnoseEmptyAssistantResponse):
    • Case A (Pure Thinking Truncation): The model generated thoughts, but omitted text and tool calls.
    • Case B (Zero-Token Blank): The model cleanly returned zero tokens without text or tool calls.
  2. Auto-Continuation Step (addContinueStep):
    • Automatically injects an adaptive continuation request via pi.sendUserMessage(..., { deliverAs: "followUp" }).
    • Bounded by a retry counter (maxRetries = 2) to prevent infinite token depletion.
    • Visible in TUI with clear chat messages, status bar progress, and notifications.

Installation

Option 1: Via npm (Recommended)

pi install npm:pi-gemini-empty-continuation

Option 2: Via Git Repository

pi install git:github.com/sususu98/pi-gemini-empty-continuation

Option 3: Local Global Extension

Download extensions/index.ts directly into your global Pi extensions directory:

mkdir -p ~/.pi/agent/extensions
curl -sL https://raw.githubusercontent.com/sususu98/pi-gemini-empty-continuation/main/extensions/index.ts \
  -o ~/.pi/agent/extensions/gemini-empty-continuation.ts

Then run /reload in your active Pi session.

Commands

  • /gemini-continuation — View current status and retry count.
  • /gemini-continuation on / /gemini-continuation off — Enable or disable the extension.
  • /gemini-continuation <N> — Set maximum consecutive retries (default: 2).

中文说明

背景痛点

Google Gemini 系列模型(尤其在 Gemini 3.8 Flash 等开启双通道思考推理的模型上)在长上下文或复杂任务中,偶尔会出现耗费数千 token 进行了深入思考(thought: true),但在输出正文时戛然而止(thought: false 为空字符串),且未触发任何工具调用的现象。

在标准 Pi 会话中,宿主判定该轮次正常结束(stopReason: "stop"),导致界面上只显示思考折叠块,正文区完全空白,需要人工手动打字输入“继续”。而现存的重试插件(如 pi-retry-empty)因检测的是 zeroTokens,会因为 Gemini 产生了思考 token 而彻底漏判。

核心实现:对齐 Google Antigravity (agy)

通过逆向分析 Google 官方 CLI 二进制文件中的 empty_output_continuation_check.go,本插件将官方的双模态防护机制完整移植到 Pi Agent:

  1. 双模态精准诊断 (diagnoseEmptyAssistantResponse)
    • 场景 A(思考截断):检测到 hasThinking === truehasText === false && hasToolCall === false,精准识别只思考不说话的情况。
    • 场景 B(完全 0 token 空白):检测到模型未思考也未输出任何内容(干净的 0 token 停止),同样进行拦截。
  2. 状态机自动续写 (addContinueStep)
    • agent_end 触发时,自动通过 deliverAs: "followUp" 向当前会话投递针对性的续写指令。
    • 具有严格的防死循环保护(默认上限 2 次),达到上限自动报警终止。
    • TUI 完整可见:消息气泡、底栏状态进度、Toast 通知三重视觉感知。

安装与使用

方式 1:通过 npm 安装(推荐)

pi install npm:pi-gemini-empty-continuation

方式 2:通过 Git 仓库安装

pi install git:github.com/sususu98/pi-gemini-empty-continuation

方式 3:作为本地全局扩展安装

直接下载并放入全局扩展目录:

mkdir -p ~/.pi/agent/extensions
curl -sL https://raw.githubusercontent.com/sususu98/pi-gemini-empty-continuation/main/extensions/index.ts \
  -o ~/.pi/agent/extensions/gemini-empty-continuation.ts

在 Pi 对话框中输入 /reload 即可立即热重载生效。

交互指令

  • /gemini-continuation:查看当前拦截状态及连续重试统计。
  • /gemini-continuation on / off:快速开启或关闭自动续写。
  • /gemini-continuation 3:调整最大连续重试次数(默认为 2 次)。

Links

License

MIT © 2026 sususu98