---
name: slack-backfill
description: >
  Full Slack history backfill from 2022 to present. Searches month by month,
  paginates through all results, and stores messages in WALL-E's brain.
  Use for initial setup or catching up on missed months.
version: 1.0.0
author: wall-e
execution: script
entry: ../../../scripts/slack-backfill.js
args: []
trigger:
  type: manual
requires:
  env:
    - SLACK_OWNER_USER_ID
config:
  mode:
    type: string
    enum: [full, incremental]
    default: full
    description: "full = month-by-month from 2022, incremental = only new messages"
  month:
    type: string
    default: ""
    description: "Single month to backfill (e.g. 2024-09). Empty = all months."
tags: [slack, messaging, backfill, ingestion, history]
permissions:
  - slack:read
  - brain:write
---
# Slack History Backfill

## What This Skill Does

Performs a comprehensive backfill of Slack message history from June 2022
to the present month. Uses Slack search API with pagination (up to 20 pages
per query) to capture all messages.

## How It Works

1. Generate month ranges from 2022-06 to current month
2. For each month, search for messages from the owner (via SLACK_OWNER_HANDLE env var)
3. Paginate through all results (up to 20 pages x 20 results)
4. Parse detailed result format (channel, sender, timestamp, message_ts)
5. Deduplicate using source_id = `slack-{message_ts}`
6. Emit CHECKPOINT after each month for task runner resume support

## Modes

- `full` (default) -- Scans every month from 2022-06 to now. Skips already-ingested messages.
- `incremental` -- Only searches for messages after the latest timestamp in the brain.
- Single month -- Pass a month string like `2024-09` to backfill just that month.

## Checkpoint Support

The script reads `WALL_E_CHECKPOINT` env var to resume from a specific month.
Each completed month emits `CHECKPOINT:YYYY-MM` for the task runner to save.

## Output

Prints progress per month and final summary:
`Total: {before} -> {after} (+{delta})`
