// Name: Chrome Tab Link Harvester // Description: Executes JS in the active Google Chrome tab to collect all link hrefs and displays them in an editor. // Author: tayiorbeii // GitHub: tayiorbeii import "@johnlindquist/kit" const activeUrl = await getActiveTab('Google Chrome').catch(() => '') const js = `JSON.stringify(Array.from(document.querySelectorAll('a')).map(a => a.href).filter(Boolean))` const escapeForAppleScript = (s: string) => s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n') const as = ` tell application "Google Chrome" if not (exists front window) then return "" set t to active tab of front window execute t javascript "${escapeForAppleScript(js)}" end tell ` let result = '' try { result = await applescript(as) } catch (e) { await notify('Failed to execute script in Google Chrome') exit() } let hrefs: string[] = [] try { hrefs = JSON.parse(result || '[]') } catch { hrefs = (result || '').split(/\r?\n/).filter(Boolean) } hrefs = Array.from(new Set(hrefs)).filter(Boolean) const header = activeUrl ? `# Links from ${activeUrl}\n\n` : `# Links from active Google Chrome tab\n\n` await editor(header + hrefs.join('\n'))// Name: Save NinjaCat Agent Instructions // Description: Grabs the Instructions textarea from the active NinjaCat Agent Builder tab, opens it in an editor, then saves and commits it to a local git-tracked folder based on the URL. // Author: tayiorbeii // GitHub: tayiorbeii import "@johnlindquist/kit" const activeUrl = await getActiveTab("Google Chrome").catch(() => "") if (!activeUrl || !activeUrl.includes("ninjacat.io") || !/\/agents\/builder\//.test(activeUrl)) { await notify("Active tab is not a NinjaCat Agent Builder page") exit() } const js = ` (() => { const textarea = document.querySelector('textarea[placeholder="Enter the instructions for this agent"]'); let instructions = textarea ? (textarea.value ?? textarea.textContent ?? '') : ''; let title = ''; try { const candidates = Array.from(document.querySelectorAll('div,span,h1,h2,h3')); const marker = candidates.find(el => (el.textContent || '').trim().toUpperCase() === 'AGENT BUILDER'); if (marker) { const parent = marker.parentElement; if (parent) { const nextTitle = parent.querySelector('h1, h2, h3, div[class*="font-bold"]'); if (nextTitle && nextTitle.textContent) title = nextTitle.textContent.trim(); } if (!title && marker.nextElementSibling && marker.nextElementSibling.textContent) { title = marker.nextElementSibling.textContent.trim(); } } } catch (e) {} if (!title) title = document.title || ''; return JSON.stringify({ instructions, title }); })() `.trim() const escapeForAppleScript = (s: string) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n") const as = ` tell application "Google Chrome" if not (exists front window) then return "" set t to active tab of front window execute t javascript "${escapeForAppleScript(js)}" end tell `.trim() let result = "" try { result = await applescript(as) } catch (e) { await notify("Failed to execute script in Google Chrome") exit() } let instructions = "" let title = "" try { const parsed = JSON.parse(result || "{}") instructions = parsed?.instructions || "" title = parsed?.title || "" } catch { // Fallback if page didn't return JSON instructions = result || "" } const edited = await editor({ value: instructions || "", placeholder: "Edit NinjaCat Agent Instructions", scrollTo: "top", shortcuts: [ { name: "Save", key: `${cmd}+s`, onPress: input => submit(input), bar: "right", }, ], onEscape: input => submit(input), onAbandon: input => submit(input), }) const urlObj = new URL(activeUrl) const parts = urlObj.pathname.split("/").filter(Boolean) const id = parts[parts.length - 1] || "unknown" const slugify = (s: string) => s .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") .slice(0, 120) const safeTitle = title ? slugify(title) : "agent" const dirName = id ? `${safeTitle}-${id}` : safeTitle const baseDir = kenvPath("ninjacat-agent-instructions") await ensureDir(baseDir) const agentDir = path.join(baseDir, dirName) await ensureDir(agentDir) const filePath = path.join(agentDir, "instructions.md") await writeFile(filePath, edited ?? "") // Initialize git repo at baseDir if not exists const isGit = await isDir(path.join(baseDir, ".git")) if (!isGit) { try { await exec(`git init`, { cwd: baseDir }) } catch {} } // Commit changes try { const msgTitle = title || `Agent ${id}` const timestamp = formatDate(new Date(), "yyyy-MM-dd HH:mm:ss") await exec(`git add -A`, { cwd: baseDir }) await exec(`git commit -m "${msgTitle} - ${timestamp}"`, { cwd: baseDir }) } catch { // likely no changes to commit; ignore } await revealFile(filePath) await notify(`Saved NinjaCat Agent Instructions: ${dirName}`)