Keystroke essay reconstruction

From wenmin-wu/ds-skills · View interactive version

Keystroke essay reconstruction is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Replay keystroke activity logs (Input/Replace/Paste/Remove/Move) against a string buffer to reconstruct the evolving essay text

How to use this skill

Skill file

Overview

When a dataset only gives you keystroke events — activity, cursor_position, text_change — and not the final text, you can deterministically rebuild the essay (or at least its anonymized structure) by replaying each event against a running string buffer. This unlocks a whole second feature family: sentence / paragraph / word-length statistics that are impossible to compute from event logs alone. Used in the Kaggle "Linking Writing Processes to Writing Quality" competition to add ~20-40 text-shape features on top of event-based ones.

Quick Start

def reconstruct_essay(df):
    df = df[df['activity'] != 'Nonproduction']
    out = {}
    for uid, g in df.groupby('id'):
        essay = ""
        for act, cur, txt in g[['activity','cursor_position','text_change']].values:
            if act == 'Replace':
                old, new = txt.split(' => ')
                essay = essay[:cur-len(new)] + new + essay[cur-len(new)+len(old):]
            elif act == 'Paste':
                essay = essay[:cur-len(txt)] + txt + essay[cur-len(txt):]
            elif act == 'Remove/Cut':
                essay = essay[:cur] + essay[cur+len(txt):]
            elif 'M' in act:  # Move From [a,b] To [c,d]
                pass  # splice slices per parsed offsets
            else:  # Input
                essay = essay[:cur-len(txt)] + txt + essay[cur-len(txt):]
        out[uid] = essay
    return out

Workflow

  1. Drop Nonproduction rows (mouse clicks, focus changes) — they don't modify text
  2. Group events by session id and iterate in order
  3. For each activity type, splice the buffer at cursor_position using text_change length
  4. Keep the buffer as anonymized characters — the output is a string of q's and whitespace, same shape as the real essay
  5. Feed the reconstructed essay to downstream sentence/paragraph/word statistics

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.