Files
.sune/inline-commit.sune

1 line
5.1 KiB
Plaintext

[{"id":"jbcwown","name":"Inline Commit","pinned":false,"avatar":"","url":"gh://multipleof4/.sune/inline-commit.sune","updatedAt":1757665015898,"settings":{"model":"google/gemini-2.5-pro","temperature":"","top_p":"","top_k":"","frequency_penalty":"","repetition_penalty":"","min_p":"","top_a":"","verbosity":"","reasoning_effort":"default","system_prompt":"","html":"<!--\nSune: GitHub Commit Helper\nVersion: 1.4\n-->\n<div id=\"sune_github_commit\" x-data=\"{v:'1.4'}\" class=\"hidden\"></div>\n<script>\n(()=>{\n const suneEl=document.getElementById('sune_github_commit');\n if(!suneEl){console.error(\"Sune container not found.\");return}\n const SUNE_NAME='[Sune: GitHub Commit Helper]', SUNE_V=suneEl.getAttribute('x-data').match(/v:'(.*?)'/)[1];\n console.log(`${SUNE_NAME} Initializing v${SUNE_V}`);\n\n const findAndEnhance=async e=>{\n if(!e?.detail?.message)return;\n const {id,role}=e.detail.message;\n if(role!=='assistant')return;\n console.log(`${SUNE_NAME} Event 'sune:newSuneResponse' received for assistant message id: ${id}`);\n \n await new Promise(r=>setTimeout(r,100)); // DOM update grace period\n const bubble=window.getBubbleById(id);\n if(!bubble){console.log(`${SUNE_NAME} Bubble not found for id: ${id}`);return}\n\n console.log(`${SUNE_NAME} Bubble found, scanning for commit targets...`);\n bubble.querySelectorAll('pre').forEach(pre=>{\n const labelEl=pre.previousElementSibling;\n if(!labelEl||labelEl.tagName!=='P'||labelEl.querySelector('button'))return;\n const match=labelEl.innerHTML.match(/`([a-zA-Z0-9.\\-_]+)\\/([a-zA-Z0-9.\\-_]+)@([a-zA-Z0-9.\\-_]+)\\/([^`]+)`/);\n if(!match)return;\n\n const[_,owner,repo,branch,path]=match;\n const code=pre.querySelector('code')?.innerText;\n if(!code){console.log(`${SUNE_NAME} Code block found, but no code content.`);return}\n console.log(`${SUNE_NAME} Found match:`,{owner,repo,branch,path});\n\n const btn=document.createElement('button');\n btn.className='ml-2 inline-flex items-center gap-1.5 rounded-md bg-slate-100 px-2 py-1 text-xs font-medium text-slate-700 hover:bg-slate-200 transition-colors';\n btn.innerHTML='<i data-lucide=\"github\" class=\"h-3.5 w-3.5\"></i> Commit';\n labelEl.append(btn);\n lucide.createIcons();\n console.log(`${SUNE_NAME} Appending commit button for ${path}`);\n btn.onclick=()=>commitFile(btn,owner,repo,branch,path,code);\n });\n };\n\n const commitFile=async(btn,owner,repo,branch,path,content)=>{\n console.log(`${SUNE_NAME} commitFile called:`, {owner,repo,branch,path});\n const token=window.USER?.githubToken;\n if(!token){console.error(`${SUNE_NAME} GitHub token not set.`);alert('GitHub token not set in Account Settings > API.');return}\n btn.disabled=true;\n btn.innerHTML='<span class=\"relative flex h-3 w-3\"><span class=\"animate-ping absolute inline-flex h-full w-full rounded-full bg-sky-400 opacity-75\"></span><span class=\"relative inline-flex rounded-full h-3 w-3 bg-sky-500\"></span></span> Committing...';\n\n const URL=`https://api.github.com/repos/${owner}/${repo}/contents/${path}`, H={'Authorization':`Bearer ${token}`,'Accept':'application/vnd.github.v3+json'};\n try{\n let sha;\n const r=await fetch(`${URL}?ref=${branch}`,{headers:H});\n if(r.ok)sha=(await r.json()).sha;\n else if(r.status!==404)throw new Error(`GET failed: ${r.statusText}`);\n\n const body={message:`feat: update file via SuneBuilderGPT`,content:btoa(unescape(encodeURIComponent(content))),sha,branch};\n const pr=await fetch(URL,{method:'PUT',headers:H,body:JSON.stringify(body)});\n \n if(!pr.ok)throw new Error(`PUT failed: ${(await pr.json()).message}`);\n \n btn.className=btn.className.replace(/bg-slate-100 text-slate-700 hover:bg-slate-200/,'bg-green-100 text-green-800');\n btn.innerHTML='<i data-lucide=\"check\" class=\"h-3.5 w-3.5\"></i> Success';\n }catch(err){\n console.error(`${SUNE_NAME} GitHub Commit Failed:`,err);\n btn.className=btn.className.replace(/bg-slate-100 text-slate-700 hover:bg-slate-200/,'bg-red-100 text-red-800');\n btn.innerHTML='<i data-lucide=\"x\" class=\"h-3.5 w-3.5\"></i> Failed';\n setTimeout(()=>{\n btn.disabled=false;\n btn.className='ml-2 inline-flex items-center gap-1.5 rounded-md bg-slate-100 px-2 py-1 text-xs font-medium text-slate-700 hover:bg-slate-200 transition-colors';\n btn.innerHTML='<i data-lucide=\"github\" class=\"h-3.5 w-3.5\"></i> Commit';\n lucide.createIcons();\n },3e3);\n }finally{lucide.createIcons()}\n };\n\n const listener=e=>findAndEnhance(e);\n // Correctly access the global `el` object from the window scope\n window.el.composer.addEventListener('sune:newSuneResponse',listener);\n suneEl.addEventListener('sune:unmount',()=>{\n console.log(`${SUNE_NAME} Unmounting and removing event listener.`);\n window.el.composer.removeEventListener('sune:newSuneResponse',listener);\n });\n})();\n</script>\n","extension_html":"<sune src='https://raw.githubusercontent.com/sune-org/store/refs/heads/main/sync.sune' private></sune>","hide_composer":false},"storage":{}}]