← back to Norma Platform
IG TK-10617: Option A helper — detect logged-in account + delete its posts (owner-check safe)
4c9304aedadbbb7d3cb0b0818b08d780b243f6b5 · 2026-08-17 12:56:45 -0700 · Steve Abrams
Files touched
A agents/instagram-agent/delete-current-account.js
Diff
commit 4c9304aedadbbb7d3cb0b0818b08d780b243f6b5
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Aug 17 12:56:45 2026 -0700
IG TK-10617: Option A helper — detect logged-in account + delete its posts (owner-check safe)
---
agents/instagram-agent/delete-current-account.js | 67 ++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/agents/instagram-agent/delete-current-account.js b/agents/instagram-agent/delete-current-account.js
new file mode 100644
index 0000000..4658214
--- /dev/null
+++ b/agents/instagram-agent/delete-current-account.js
@@ -0,0 +1,67 @@
+#!/usr/bin/env node
+/**
+ * delete-current-account.js — Option A helper (TK-10617).
+ * Detects whichever IG account is logged into the openclaw Chrome RIGHT NOW, and if
+ * that account has undeleted originals in redo-results, deletes them via
+ * delete-originals.js --only <handle> --go (60s-paced, verified).
+ *
+ * SAFE: acts only on whoever Steve chose to log in as. If detection is off, the
+ * delete tool's owner-check (no Delete affordance = not owner) SKIPS every post —
+ * it can never delete another account's content.
+ */
+const { execSync } = require('child_process');
+const fs = require('fs');
+const path = require('path');
+const DATE = '20260814';
+
+function oc(c) { return execSync(`openclaw browser ${c}`, { encoding: 'utf8', timeout: 60000, stdio: ['ignore', 'pipe', 'pipe'] }); }
+let tab = null;
+function openIg() { const o = oc('open "https://www.instagram.com/" --timeout 30000'); tab = (o.match(/id:\s*([A-F0-9]+)/i) || [])[1] || tab; }
+// Robust snapshot: retry until we see a decisive signal (nav avatar OR login form).
+function robustSnap() {
+ for (let i = 0; i < 5; i++) {
+ try { const s = oc(`snapshot --format ai --limit 500 ${tab ? `--target-id ${tab}` : ''}`); if (s && /'s profile picture|Log into Instagram|Mobile number, username/i.test(s)) return s; } catch {}
+ execSync('sleep 2');
+ }
+ return '';
+}
+
+const rows = fs.readFileSync(path.join(__dirname, 'data', `redo-results-${DATE}.jsonl`), 'utf8')
+ .trim().split('\n').filter(Boolean).map((l) => JSON.parse(l)).filter((r) => r.old_permalink);
+const listHandles = new Set(rows.map((r) => r.handle));
+const done = new Set();
+try {
+ fs.readFileSync(path.join(__dirname, 'data', `delete-results-${DATE}.jsonl`), 'utf8')
+ .trim().split('\n').filter(Boolean).forEach((l) => { try { done.add(JSON.parse(l).old_permalink); } catch {} });
+} catch {}
+
+openIg();
+execSync('sleep 4');
+const snap = robustSnap();
+
+// Collect every handle that appears as a "<h>'s profile picture" with a /url: /<h>/,
+// then pick the one that's in our delete list (the logged-in DW account).
+const seen = [];
+for (const m of snap.matchAll(/([A-Za-z0-9_.]+)'s profile picture/g)) if (!seen.includes(m[1])) seen.push(m[1]);
+let handle = seen.find((h) => listHandles.has(h)) || seen[0] || null;
+
+if (!handle) { console.log('❌ No account detected — are you logged in? Log into an account, then re-run.'); process.exit(2); }
+console.log(`🔎 Detected logged-in account: @${handle}`);
+
+if (!listHandles.has(handle)) {
+ console.log(`⚠ @${handle} is NOT in the delete list. Either you're on the wrong account, or detection picked a feed avatar. Log into a target account and re-run.`);
+ console.log(` (delete-list accounts still pending: ${[...listHandles].filter((h) => rows.some((r) => r.handle === h && !done.has(r.old_permalink))).map((h) => '@' + h).join(', ') || 'none'})`);
+ process.exit(0);
+}
+const pending = rows.filter((r) => r.handle === handle && !done.has(r.old_permalink));
+if (!pending.length) {
+ const left = [...listHandles].filter((h) => rows.some((r) => r.handle === h && !done.has(r.old_permalink)));
+ console.log(`✅ @${handle} already fully deleted. Switch to the next account.`);
+ console.log(` Accounts still needing deletes (${left.length}): ${left.map((h) => '@' + h).join(', ')}`);
+ process.exit(0);
+}
+console.log(`🧹 @${handle}: ${pending.length} post(s) to delete — running (60s-paced, verified)…\n`);
+const out = execSync(`node ${JSON.stringify(path.join(__dirname, 'delete-originals.js'))} --only ${handle} --go`, { encoding: 'utf8', timeout: 900000, stdio: ['ignore', 'pipe', 'pipe'] });
+console.log(out);
+const left = [...listHandles].filter((h) => rows.some((r) => r.handle === h && !done.has(r.old_permalink)) && h !== handle);
+console.log(`\n➡ @${handle} done. Next: log into one of (${left.length}): ${left.map((h) => '@' + h).join(', ') || 'none — ALL DONE 🎉'}`);
← 8417463 Fix IG delete: target the Delete BUTTON, not the 'Delete pos
·
back to Norma Platform
·
auto-data-snapshot: 2026-08-17T13:58:50 (1 data files) — age 8293e85 →