wiki_flush_pending_commits — MCP Tool · Batch flush de páginas wiki pendientes
wiki_flush_pending_commits
Tipo: MCP Tool (CF Workers, functions/api/mcp/handlers/wiki.ts)
Introducido en: s80 · 2026-05-22 (commit@bd61e31)
LOGGED_TOOLS: { action: 'ingest', entity_type: 'wiki_page' }
Descripción
Consolida todas las páginas wiki parqueadas en bib_wiki_pending_commits para un trigger_ref dado en un único commit a main del workspace, via GitHub Git Data Trees API (o ghPutFile clásico si N=1).
Forma parte del sistema Bibliotecario-Ingest Batch (s80): evita la cascada de 3–5 commits autónomos que antes producía cada PR mergeado.
Parámetros
| Parámetro | Tipo | Requerido | Default | Descripción |
|---|---|---|---|---|
trigger_ref | string | ✅ | — | Identificador del lote (PR#63, commit@abc1234). Clave de partición en bib_wiki_pending_commits. |
actor | string | — | "agent-ingest" | Quién dispara el flush. Aparece en bib_wiki_log. |
message_prefix | string | — | "wiki(batch)" | Prefijo del commit message generado. |
Respuesta
{
ok: boolean;
flushed: number; // N filas procesadas (0 si no había pending)
commit_sha?: string; // SHA del commit creado en main
trigger_ref: string;
creates: string[]; // slugs de operación 'create'
updates: string[]; // slugs de operación 'update'
error?: string; // presente solo en caso de fallo
pending_rows?: number; // presente junto a error
}
Comportamiento interno
Caso N = 0
Devuelve { ok: true, flushed: 0 } inmediatamente. Idempotente.
Caso N = 1
Usa ghPutFile clásico (PUT /repos/{repo}/contents/{path}). Requiere el SHA previo del archivo si la operación es 'update' — lo obtiene con getFileSha.
Caso N > 1
Ejecuta ghCommitMultipleFiles:
GET /git/refs/heads/main → headSha
GET /git/commits/{headSha} → baseTreeSha
POST /git/blobs × N → blobSha[] por archivo
POST /git/trees (base_tree + N entradas) → newTreeSha
POST /git/commits → newCommitSha
PATCH /git/refs/heads/main → fast-forward
Tras commit OK: DELETE FROM bib_wiki_pending_commits WHERE trigger_ref = ?.
Fallo en PATCH ref (422)
Indica que main avanzó mientras el flush estaba en curso (race condition). Las filas no se borran — el caller puede reintentar el flush.
Prerequisitos de entorno
| Variable | Descripción |
|---|---|
env.GH_PAT | Personal Access Token con permisos contents:write en el repo workspace. Sin él el tool devuelve error: 'GH_PAT not configured'. |
bib_wiki_pending_commits | Tabla D1 creada por migrations/0036_wiki_pending_commits.sql. |
Invocación desde bib_ingest.py
flush_raw = call_mcp(
"wiki_flush_pending_commits",
{"trigger_ref": trigger_ref, "actor": "agent-ingest"},
mcp_token,
)
Se llama una sola vez al final del agentic loop, después de que Sonnet haya terminado todas sus llamadas wiki_create_page / wiki_update_page.
Registro en LOGGED_TOOLS (index.ts)
wiki_flush_pending_commits: { action: 'ingest', entity_type: 'wiki_page' },
Esto implica que cada invocación queda trazada en el audit log de acceso del MCP handler.
Véase también
- [[feature—biblioteca—bib-ingest-batch]]
- [[entity—d1—table—bib-wiki-pending-commits]]