/** * Import a pi session shared as a gist by the issue-analysis CI workflow * (.github/workflows/issue-analysis.yml) and switch to it. * * The CI job runs in a high-entropy checkout directory; this command rewrites * the recorded cwd to the local checkout, installs the session file into the * current session directory, and switches to it. * * Usage: * /import-repro b4d100022aefb12f25dd2d8485e0a82a * /import-repro https://gist.github.com/mitsuhiko/b4d100022aefb12f25dd2d8485e0a82a * /import-repro https://pi.dev/session/#b4d100022aefb12f25dd2d8485e0a82a * * pi "/import-repro " */ import { Buffer } from "node:buffer"; import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { basename, isAbsolute, join, resolve } from "node:path"; import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent"; const GIST_ID_RE = /^[0-9a-fA-F]{20,}$/; const GIST_URL_RE = /^https:\/\/gist\.github\.com\/(?:[^/]+\/)?([0-9a-fA-F]{20,})(?:[/#?].*)?$/; const SHARE_URL_RE = /^https:\/\/pi\.dev\/session\/#([0-9a-fA-F]{20,})(?:[/#?].*)?$/; const SESSION_DATA_RE = /