toolroll 0.9.137 → 0.9.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import{spawn}from"node:child_process";import{closeSync,existsSync,fstatSync,lstatSync,openSync,constants as fsConstants,readSync,readdirSync,readlinkSync,realpathSync}from"node:fs";import{homedir}from"node:os";import{basename,dirname,isAbsolute,join,relative,resolve,sep}from"node:path";import{fileURLToPath}from"node:url";import{isLeadTokenEnvName,withoutLeadTokenEnv}from"./names.js";const AS="Library/Application Support",CONTAINERS="Library/Containers",GROUPS="Library/Group Containers";export const PROTECTED_STORAGE=[{app:"Slack",darwin:[`${AS}/Slack`,`${CONTAINERS}/com.tinyspeck.slackmacgap`],linux:[".config/Slack","snap/slack",".var/app/com.slack.Slack"]},{app:"Telegram",darwin:[`${AS}/Telegram Desktop`,`${CONTAINERS}/org.telegram.desktop`,`${GROUPS}/6N38VWS5BX.ru.keepcoder.Telegram`,`${CONTAINERS}/ru.keepcoder.Telegram`],linux:[".local/share/TelegramDesktop","snap/telegram-desktop",".var/app/org.telegram.desktop"]},{app:"Discord",darwin:[`${AS}/discord`,`${AS}/discordptb`,`${AS}/discordcanary`],linux:[".config/discord",".config/discordptb",".config/discordcanary","snap/discord",".var/app/com.discordapp.Discord"]},{app:"Teams",darwin:[`${CONTAINERS}/com.microsoft.teams2`,`${GROUPS}/UBF8T346G9.com.microsoft.teams`,`${AS}/Microsoft/Teams`,`${GROUPS}/UBF8T346G9.com.microsoft.oneauth`],linux:[".config/Microsoft/Microsoft Teams",".config/teams-for-linux"]},{app:"WhatsApp",darwin:[`${CONTAINERS}/net.whatsapp.WhatsApp`,`${GROUPS}/group.net.whatsapp.WhatsApp.shared`,`${GROUPS}/group.net.whatsapp.WhatsApp.private`,`${GROUPS}/group.net.whatsapp.family`],linux:[]},{app:"1Password",darwin:[`${GROUPS}/2BUA8C4S2C.com.1password`,`${GROUPS}/group.2BUA8C4S2C.com.1password`,`${GROUPS}/2BUA8C4S2C.com.agilebits`,`${CONTAINERS}/com.1password.1password`,`${CONTAINERS}/com.1password.1password-launcher`,`${CONTAINERS}/com.1password.browser-support`,`${CONTAINERS}/2BUA8C4S2C.com.1password.browser-helper`,`${CONTAINERS}/com.1password.1password.autofill-extension`,`${AS}/1Password`,".config/1Password",".config/op",".op"],linux:[".config/1Password","snap/1password",".var/app/com.onepassword.OnePassword",".config/op",".op"]},{app:"Bitwarden",darwin:[`${AS}/Bitwarden`,`${CONTAINERS}/com.bitwarden.desktop`,`${GROUPS}/LTZ2PFU5D6.com.bitwarden.desktop`,`${AS}/Bitwarden CLI`],linux:[".config/Bitwarden","snap/bitwarden",".var/app/com.bitwarden.desktop",".config/Bitwarden CLI"]},{app:"Chrome",darwin:[`${AS}/Google/Chrome`,`${AS}/Google/Chrome Beta`,`${AS}/Google/Chrome Canary`,`${AS}/Google/Chrome Dev`],linux:[".config/google-chrome",".config/google-chrome-beta",".config/google-chrome-unstable",".var/app/com.google.Chrome"]},{app:"Chromium",darwin:[`${AS}/Chromium`],linux:[".config/chromium","snap/chromium",".var/app/org.chromium.Chromium"]},{app:"Brave",darwin:[`${AS}/BraveSoftware`],linux:[".config/BraveSoftware","snap/brave",".var/app/com.brave.Browser"]},{app:"Edge",darwin:[`${AS}/Microsoft Edge`,`${AS}/Microsoft Edge Beta`,`${AS}/Microsoft Edge Dev`,`${AS}/Microsoft Edge Canary`],linux:[".config/microsoft-edge",".config/microsoft-edge-beta",".config/microsoft-edge-dev",".var/app/com.microsoft.Edge"]},{app:"Arc",darwin:[`${AS}/Arc`],linux:[]},{app:"Firefox",darwin:[`${AS}/Firefox`],linux:[".mozilla/firefox","snap/firefox",".var/app/org.mozilla.firefox"]},{app:"Zen",darwin:[`${AS}/zen`],linux:[".zen",".var/app/app.zen_browser.zen"]},{app:"Vivaldi",darwin:[`${AS}/Vivaldi`,`${AS}/Vivaldi Snapshot`],linux:[".config/vivaldi",".config/vivaldi-snapshot"]},{app:"Opera",darwin:[`${AS}/com.operasoftware.Opera`],linux:[".config/opera"]},{app:"Toolroll shared browser",darwin:[".local/share/toolroll/browser-profiles"],linux:[".local/share/toolroll/browser-profiles"]},{app:"Orion",darwin:[`${AS}/Orion`],linux:[]},{app:"Safari",darwin:["Library/Safari",`${CONTAINERS}/com.apple.Safari`,`${CONTAINERS}/com.apple.Safari.WebApp`,"Library/Cookies","Library/HTTPStorages","Library/WebKit"],linux:[]}];const PROFILE_INDEXES={darwin:[`${AS}/Firefox`,`${AS}/zen`],linux:[".mozilla/firefox","snap/firefox/common/.mozilla/firefox",".var/app/org.mozilla.firefox/.mozilla/firefox",".zen"]},PROTECTED_ENV_PREFIXES=["SLACK_","TELEGRAM_","DISCORD_","TEAMS_","OP_","BW_","BITWARDENCLI_"];export function isProtectedEnvName(name){if(isLeadTokenEnvName(name))return!0;const upper=name.toUpperCase();return PROTECTED_ENV_PREFIXES.some(prefix=>upper.startsWith(prefix))}export function withoutProtectedEnv(env){const out={...env};for(const name of Object.keys(out))isProtectedEnvName(name)&&delete out[name];return out}const PROTECTED_WALK={depth:4,entries:5e3},real=path=>{try{return realpathSync(path)}catch{return resolve(path)}},within=(child,parent)=>{const rel=relative(parent,child);return rel!==""&&!rel.startsWith("..")&&!isAbsolute(rel)},platformOf=platform=>platform==="darwin"?"darwin":platform==="linux"?"linux":null;function tooWide(path,home){return!isAbsolute(path)||path===dirname(path)||path===home||within(home,path)}export function protectedStorageNames(home=homedir(),env=process.env,platform=process.platform){const os=platformOf(platform);if(os===null)return[];const base=real(home),names=new Set,add=path=>{tooWide(path,base)||names.add(path)},relatives=PROTECTED_STORAGE.flatMap(row=>row[os]);for(const one of relatives)add(join(base,one));if(os==="linux"){const absolute=name=>{const value=env[name];return value!==void 0&&isAbsolute(value)?value:null},config=absolute("XDG_CONFIG_HOME"),data=absolute("XDG_DATA_HOME");for(const one of relatives)config!==null&&one.startsWith(".config/")&&add(join(config,one.slice(8))),data!==null&&one.startsWith(".local/share/")&&add(join(data,one.slice(13)))}for(const name of["OP_CONFIG_DIR","BITWARDENCLI_APPDATA_DIR"]){const value=env[name];value!==void 0&&isAbsolute(value)&&add(resolve(value))}for(const index of PROFILE_INDEXES[os])for(const profile of profilesElsewhere(join(base,index)))add(profile);return[...names].sort()}function profilesElsewhere(root){return(profilesIniHere(join(root,"profiles.ini"))??"").split(/\r?\n/).map(line=>/^\s*Path\s*=\s*(.+?)\s*$/i.exec(line)?.[1]??null).filter(path=>path!==null&&isAbsolute(path))}function profilesIniHere(file){try{lstatSync(file)}catch{return null}let fd;try{fd=openSync(file,fsConstants.O_RDONLY|(fsConstants.O_NOFOLLOW??0))}catch{return null}try{const held=fstatSync(fd);if(!held.isFile())return null;const buffer=Buffer.alloc(Math.min(held.size,64*1024));return buffer.subarray(0,readSync(fd,buffer,0,buffer.length,0)).toString("utf8")}catch{return null}finally{closeSync(fd)}}const unwalkedSaid=new Set;export function protectedStorageHere(home=homedir(),env=process.env,platform=process.platform,say=()=>{},list=path=>readdirSync(path,{withFileTypes:!0}),at=()=>{}){const base=real(home),names=protectedStorageNames(base,env,platform),out=new Set,add=path=>{tooWide(path,base)||out.add(path)},unfinished=[];for(const name of names){add(name);try{lstatSync(name)}catch{continue}const root=real(name);add(root),at(root);const walked={complete:!0};for(const target of outwardLinks(name,root,base,say,list,walked))add(target);!walked.complete&&!unfinished.includes(root)&&unfinished.push(root)}return{names,denies:[...out].sort(),unfinished}}export function protectedStorageDenies(home=homedir(),env=process.env,platform=process.platform,say,list){return protectedStorageHere(home,env,platform,say,list).denies}function outwardLinks(name,root,home,say,list,walked){const found=[];let seen=0;const queue=[{path:root,depth:0}];for(;queue.length>0;){const{path,depth}=queue.shift();let entries;try{entries=list(path)}catch(error){walked!==void 0&&!ANSWERED.has(error?.code??"")&&(walked.complete=!1);continue}for(const entry of entries){if(++seen>PROTECTED_WALK.entries)return unwalkedSaid.has(root)||(unwalkedSaid.add(root),say(`toolroll: fence: ${name} holds more than ${PROTECTED_WALK.entries.toLocaleString("en-US")} entries; links past that weren't checked (not fully walked)`)),found;const child=join(path,entry.name);if(entry.isSymbolicLink()){let spelled;try{spelled=resolve(dirname(child),readlinkSync(child))}catch{continue}if(systemMirror(child,root,spelled,home))continue;const target=real(spelled);if(target===root||within(target,root))continue;found.push(target),spelled!==target&&found.push(spelled)}else entry.isDirectory()&&depth+1<PROTECTED_WALK.depth&&queue.push({path:child,depth:depth+1})}}return found}const CONTAINER_MIRRORS=new Set([".CFUserTextEncoding","Desktop","Downloads","Movies","Music","Pictures",...["Audio","Calendars","ColorPickers","ColorSync","Colors","Components","Compositions","Dictionaries","Favorites","Filters","FontCollections","Fonts","Input Methods","KeyBindings","Keyboard Layouts","Keychains","Mail","PDF Services","QuickLook","Sounds","Spelling","Images/People","Application Support/AddressBook","Application Support/iCloud","Application Support/SyncServices","Preferences/com.apple.security.plist","Preferences/com.apple.security_common.plist"].map(one=>`Library/${one}`)]);function systemMirror(link,root,target,home){const app=dirname(root)===real(join(home,CONTAINERS)),group=dirname(root)===real(join(home,GROUPS));if(!app&&!group)return!1;const rel=relative(root,link).split(sep);if(app&&rel[0]!=="Data")return!1;const under=app?rel.slice(1):rel,named=under.join("/");return(CONTAINER_MIRRORS.has(named)||named===`Library/Application Scripts/${root.split(sep).at(-1)}`)&&target===join(home,...under)}const ANSWERED=new Set(["ENOENT","ENOTDIR","EPERM","EACCES"]),STORAGE_LOOK_MS=1e4,LOOK_OUTPUT_MAX=8*1024*1024,STORAGE_ENV=["XDG_CONFIG_HOME","XDG_DATA_HOME","OP_CONFIG_DIR","BITWARDENCLI_APPDATA_DIR"];export class ProtectedStorageRefusal extends Error{apps;why;code="protected-storage";constructor(apps,why,message){super(message),this.apps=apps,this.why=why,this.name="ProtectedStorageRefusal"}}export function storageRefusalOf(error){return error instanceof ProtectedStorageRefusal?error:null}function appsOf(roots,home){const names=roots.map(root=>PROTECTED_STORAGE.find(row=>[...row.darwin,...row.linux].some(one=>real(join(home,one))===root||join(home,one)===root))?.app??basename(root));return[...new Set(names)]}export function storageAccessHolder(env=process.env,execPath=process.execPath,versions=process.versions){if(versions.electron!==void 0)return"the Toolroll app";const service=env.XPC_SERVICE_NAME;if(service!==void 0&&service!==""&&service!=="0")return`the program that keeps Toolroll running (${execPath})`;const terminal=env.TERM_PROGRAM;return terminal!==void 0&&terminal!==""?`the terminal app Toolroll was started from (${terminal.replace(/\.app$/,"")})`:`the program Toolroll runs as (${execPath})`}export function storageRefusalWords(apps,why,holder){const named=apps.length===0?"other apps":apps.length===1?apps[0]:`${apps.slice(0,-1).join(", ")} and ${apps.at(-1)}`,reason=why==="timed-out"?` (the check didn't finish within ${STORAGE_LOOK_MS/1e3} seconds)`:why==="unfinished"?" (some of its folders couldn't be read)":" (the check stopped with an error)";return`Nothing was started: Toolroll couldn't finish checking ${apps.length===0?"other apps'":`${named}'s`} data for links to keep out of the build${reason}. macOS may need to let ${holder} read it: in System Settings → Privacy & Security → Full Disk Access, turn it on for ${holder}, then try again.`}const inFlight=new Map;export async function prepareProtectedStorage(home=homedir(),env=process.env,platform=process.platform,look=lookInChild,holder=storageAccessHolder(env)){const base=real(home),request={home:base,env:Object.fromEntries(STORAGE_ENV.flatMap(name=>env[name]===void 0?[]:[[name,env[name]]])),platform};let answer;if(platform!=="darwin"){const here=protectedStorageHere(base,env,platform,line=>process.stderr.write(`${line}
2
2
  `));answer={kind:"done",storage:{names:here.names,denies:here.denies},unfinished:here.unfinished}}else{const key=JSON.stringify(request);let pending=inFlight.get(key);pending===void 0&&(pending=look(request).finally(()=>inFlight.delete(key)),inFlight.set(key,pending)),answer=await pending}if(answer.kind==="timed-out"){const apps=answer.at===null?[]:appsOf([answer.at],base);throw new ProtectedStorageRefusal(apps,"timed-out",storageRefusalWords(apps,"timed-out",holder))}if(answer.kind==="failed")throw new ProtectedStorageRefusal([],"failed",storageRefusalWords([],"failed",holder));if(answer.unfinished.length>0){const apps=appsOf(answer.unfinished,base);throw new ProtectedStorageRefusal(apps,"unfinished",storageRefusalWords(apps,"unfinished",holder))}return answer.storage}export function storageLookScript(){const beside=fileURLToPath(new URL("./protected-storage-look.js",import.meta.url));return existsSync(beside)?beside:fileURLToPath(new URL("../dist/protected-storage-look.js",import.meta.url))}async function lookInChild(request){return readLook(await spawnLook(process.execPath,[storageLookScript(),JSON.stringify(request)],STORAGE_LOOK_MS))}export function readLook(ran){const lines=ran.stdout.split(`
3
- `),last=[...lines].reverse().find(line=>line.startsWith("at ")),at=last===void 0?null:(()=>{try{const root=JSON.parse(last.slice(3));return typeof root=="string"&&isAbsolute(root)?root:null}catch{return null}})();if(ran.outcome==="timed-out")return{kind:"timed-out",at};if(ran.outcome==="failed")return{kind:"failed",detail:ran.detail};const done=lines.find(line=>line.startsWith("done "));if(done===void 0)return{kind:"failed",detail:"the check gave no answer"};try{const value=JSON.parse(done.slice(5)),paths=one=>Array.isArray(one)&&one.every(path=>typeof path=="string"&&isAbsolute(path))?one:null,names=paths(value.names),denies=paths(value.denies),unfinished=paths(value.unfinished);return names===null||denies===null||unfinished===null?{kind:"failed",detail:"the check's answer can't be read"}:{kind:"done",storage:{names,denies},unfinished}}catch{return{kind:"failed",detail:"the check's answer can't be read"}}}export function spawnLook(command,args,limitMs){return new Promise(settle=>{let stdout="",over=!1,timedOut=!1,settled=!1;const finish=(outcome,detail)=>{settled||(settled=!0,clearTimeout(timer),settle({stdout,outcome,detail}))};let child;try{child=spawn(command,[...args],{stdio:["ignore","pipe","ignore"],env:withoutLeadTokenEnv({...process.env,ELECTRON_RUN_AS_NODE:"1"})})}catch(error){settle({stdout:"",outcome:"failed",detail:error instanceof Error?error.message:String(error)});return}const timer=setTimeout(()=>{timedOut=!0,child.kill("SIGKILL")},limitMs);child.stdout?.setEncoding("utf8"),child.stdout?.on("data",chunk=>{stdout.length+chunk.length>LOOK_OUTPUT_MAX?(over=!0,child.kill("SIGKILL")):stdout+=chunk}),child.on("error",error=>finish("failed",error.message)),child.on("close",(code,signal)=>{timedOut?finish("timed-out",""):over?finish("failed","the check said too much"):code===0&&signal===null?finish("done",""):finish("failed",signal===null?`the check exited with ${code}`:`the check was stopped (${signal})`)})})}
3
+ `),last=[...lines].reverse().find(line=>line.startsWith("at ")),at=last===void 0?null:(()=>{try{const root=JSON.parse(last.slice(3));return typeof root=="string"&&isAbsolute(root)?root:null}catch{return null}})();if(ran.outcome==="timed-out")return{kind:"timed-out",at};if(ran.outcome==="failed")return{kind:"failed",detail:ran.detail};const done=lines.find(line=>line.startsWith("done "));if(done===void 0)return{kind:"failed",detail:"the check gave no answer"};try{const value=JSON.parse(done.slice(5)),paths=one=>Array.isArray(one)&&one.every(path=>typeof path=="string"&&isAbsolute(path))?one:null,names=paths(value.names),denies=paths(value.denies),unfinished=paths(value.unfinished);return names===null||denies===null||unfinished===null?{kind:"failed",detail:"the check's answer can't be read"}:{kind:"done",storage:{names,denies},unfinished}}catch{return{kind:"failed",detail:"the check's answer can't be read"}}}export function spawnLook(command,args,limitMs){return new Promise(settle=>{let stdout="",over=!1,timedOut=!1,settled=!1,backstop;const finish=(outcome,detail)=>{settled||(settled=!0,clearTimeout(timer),backstop!==void 0&&clearTimeout(backstop),settle({stdout,outcome,detail}))};let child;try{child=spawn(command,[...args],{stdio:["ignore","pipe","ignore"],env:withoutLeadTokenEnv({...process.env,ELECTRON_RUN_AS_NODE:"1"})})}catch(error){settle({stdout:"",outcome:"failed",detail:error instanceof Error?error.message:String(error)});return}const killAndSettle=(outcome,detail)=>{try{child.kill("SIGKILL")}catch{}backstop===void 0&&(backstop=setTimeout(()=>{try{child.stdout?.destroy()}catch{}finish(outcome,detail)},2e3),backstop.unref?.())},timer=setTimeout(()=>{timedOut=!0,killAndSettle("timed-out","")},limitMs);child.stdout?.setEncoding("utf8"),child.stdout?.on("data",chunk=>{stdout.length+chunk.length>LOOK_OUTPUT_MAX?(over=!0,killAndSettle("failed","the check said too much")):stdout+=chunk}),child.on("error",error=>finish("failed",error.message)),child.on("close",(code,signal)=>{timedOut?finish("timed-out",""):over?finish("failed","the check said too much"):code===0&&signal===null?finish("done",""):finish("failed",signal===null?`the check exited with ${code}`:`the check was stopped (${signal})`)})})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolroll",
3
- "version": "0.9.137",
3
+ "version": "0.9.139",
4
4
  "description": "Your agents build. You decide. A control plane for coding agents — Claude Code, Codex, Gemini: approve the exact scope once, get results back Ready with the diff, the passing check and screenshots. Runs on your machine.",
5
5
  "directories": {
6
6
  "doc": "docs"