@automagik/genie 4.260503.6 → 4.260503.7
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.
package/dist/genie.js
CHANGED
|
@@ -625,7 +625,7 @@ ${bin} set-option -w pane-active-border-style "fg=$COLOR"
|
|
|
625
625
|
${a.repoPath??null}, ${null},
|
|
626
626
|
${a.startedAt??new Date().toISOString()}
|
|
627
627
|
) ON CONFLICT (id) DO NOTHING
|
|
628
|
-
`,await sql`UPDATE agents SET current_executor_id = ${executorId} WHERE id = ${a.id} AND current_executor_id IS NULL`}async function seedWorkers(sql){let filePath=workersJsonPath();if(!needsMigration(filePath))return{agents:0,templates:0};let data=await readJson(filePath);if(!data)return{agents:0,templates:0};let agentCount=0;for(let agent of Object.values(data.workers??{})){if(!agent.id)continue;await upsertAgent(sql,agent),await upsertExecutorFromAgent(sql,agent),agentCount++}let templateCount=0;for(let tpl of Object.values(data.templates??{})){if(!tpl.id)continue;await upsertTemplate(sql,tpl),templateCount++}return{agents:agentCount,templates:templateCount}}function deriveLeader(cfg){if(!cfg.leadAgentId)return null;let at=cfg.leadAgentId.indexOf("@");return at===-1?cfg.leadAgentId:cfg.leadAgentId.slice(0,at)}async function upsertNativeTeam(sql,c){let
|
|
628
|
+
`,await sql`UPDATE agents SET current_executor_id = ${executorId} WHERE id = ${a.id} AND current_executor_id IS NULL`}async function seedWorkers(sql){let filePath=workersJsonPath();if(!needsMigration(filePath))return{agents:0,templates:0};let data=await readJson(filePath);if(!data)return{agents:0,templates:0};let agentCount=0;for(let agent of Object.values(data.workers??{})){if(!agent.id)continue;await upsertAgent(sql,agent),await upsertExecutorFromAgent(sql,agent),agentCount++}let templateCount=0;for(let tpl of Object.values(data.templates??{})){if(!tpl.id)continue;await upsertTemplate(sql,tpl),templateCount++}return{agents:agentCount,templates:templateCount}}function deriveLeader(cfg){if(!cfg.leadAgentId)return null;let at=cfg.leadAgentId.indexOf("@");return at===-1?cfg.leadAgentId:cfg.leadAgentId.slice(0,at)}function isValidTeamMember(s){return MEMBER_UUID_RE.test(s)||s.startsWith("dir:")}async function upsertNativeTeam(sql,c){let rawMemberNames=(c.members??[]).map((m)=>m.name).filter((n)=>typeof n==="string"&&n.length>0),memberNames=rawMemberNames.filter(isValidTeamMember),dropped=rawMemberNames.length-memberNames.length;if(dropped>0)console.warn(`[pg-seed] team "${c.name}": dropped ${dropped} legacy member name(s) failing migration 061 constraint (UUID or dir: prefix required); kept ${memberNames.length}`);await sql`
|
|
629
629
|
INSERT INTO teams (
|
|
630
630
|
name, repo, base_branch, worktree_path, leader,
|
|
631
631
|
members, status, native_team_parent_session_id,
|
|
@@ -656,7 +656,7 @@ ${bin} set-option -w pane-active-border-style "fg=$COLOR"
|
|
|
656
656
|
${msg.timestamp??new Date().toISOString()}
|
|
657
657
|
) ON CONFLICT (id) DO NOTHING
|
|
658
658
|
`}function parseJsonlRecords(content){let records=[];for(let line of content.trim().split(`
|
|
659
|
-
`).filter(Boolean))try{let msg=JSON.parse(line);if(msg.id)records.push(msg)}catch{}return records}async function seedTeamChat(sql,repoPath){let dir=join16(repoPath,".genie","chat");if(!existsSync12(dir))return 0;let files;try{files=await readdir3(dir)}catch{return 0}let count=0;for(let file of files){if(!file.endsWith(".jsonl")||file.endsWith(".migrated"))continue;if(!needsMigration(join16(dir,file)))continue;let teamName=file.replace(".jsonl","").replace(/--/g,"/"),content;try{content=await readFile4(join16(dir,file),"utf-8")}catch{continue}for(let msg of parseJsonlRecords(content))await upsertChatMessage(sql,msg,teamName,repoPath),count++}return count}async function markMigrated(repoPath){let workersPath=workersJsonPath();if(needsMigration(workersPath))await rename(workersPath,`${workersPath}.migrated`);if(!repoPath)return;await renameMatchingFiles(join16(repoPath,".genie","mailbox"),isMailboxFile),await renameMatchingFiles(join16(repoPath,".genie","chat"),(f)=>f.endsWith(".jsonl")&&!f.endsWith(".migrated"))}async function runSeed(sql,repoPath){let result2={agents:0,templates:0,teams:0,mailboxMessages:0,chatMessages:0},workers=await seedWorkers(sql);result2.agents=workers.agents,result2.templates=workers.templates;let teams=await seedTeams(sql);if(result2.teams=teams.count,repoPath)result2.mailboxMessages=await seedMailbox(sql,repoPath),result2.chatMessages=await seedTeamChat(sql,repoPath);if(await markMigrated(repoPath),!teams.hadFailures)await writeTeamsSeedMarker(teams.teamNames);return result2}var init_pg_seed=__esm(()=>{init_claude_native_teams()});import{execSync as execSync2}from"child_process";import{readFileSync as readFileSync8}from"fs";function getProcessStartTime(pid){if(!Number.isInteger(pid)||pid<=0)return null;try{if(process.platform==="darwin"){let raw=execSync2(`ps -o lstart= -p ${pid}`,{encoding:"utf8",timeout:1000,stdio:["ignore","pipe","ignore"]}).trim();return raw===""?null:raw}if(process.platform==="linux"){let raw=readFileSync8(`/proc/${pid}/stat`,"utf-8"),closeParen=raw.lastIndexOf(")");if(closeParen<0)return null;let starttime=raw.slice(closeParen+1).trim().split(/\s+/)[19];return starttime&&starttime.length>0?starttime:null}}catch{return null}return null}var init_process_identity=()=>{};function cachedError(xs){if(originCache.has(xs))return originCache.get(xs);let x=Error.stackTraceLimit;return Error.stackTraceLimit=4,originCache.set(xs,Error()),Error.stackTraceLimit=x,originCache.get(xs)}var originCache,originStackCache,originError,CLOSE,Query;var init_query=__esm(()=>{originCache=new Map,originStackCache=new Map,originError=Symbol("OriginError"),CLOSE={};Query=class Query extends Promise{constructor(strings,args,handler,canceller,options={}){let resolve3,reject;super((a,b)=>{resolve3=a,reject=b});this.tagged=Array.isArray(strings.raw),this.strings=strings,this.args=args,this.handler=handler,this.canceller=canceller,this.options=options,this.state=null,this.statement=null,this.resolve=(x)=>(this.active=!1,resolve3(x)),this.reject=(x)=>(this.active=!1,reject(x)),this.active=!1,this.cancelled=null,this.executed=!1,this.signature="",this[originError]=this.handler.debug?Error():this.tagged&&cachedError(this.strings)}get origin(){return(this.handler.debug?this[originError].stack:this.tagged&&originStackCache.has(this.strings)?originStackCache.get(this.strings):originStackCache.set(this.strings,this[originError].stack).get(this.strings))||""}static get[Symbol.species](){return Promise}cancel(){return this.canceller&&(this.canceller(this),this.canceller=null)}simple(){return this.options.simple=!0,this.options.prepare=!1,this}async readable(){return this.simple(),this.streaming=!0,this}async writable(){return this.simple(),this.streaming=!0,this}cursor(rows=1,fn){if(this.options.simple=!1,typeof rows==="function")fn=rows,rows=1;if(this.cursorRows=rows,typeof fn==="function")return this.cursorFn=fn,this;let prev;return{[Symbol.asyncIterator]:()=>({next:()=>{if(this.executed&&!this.active)return{done:!0};prev&&prev();let promise=new Promise((resolve3,reject)=>{this.cursorFn=(value)=>{return resolve3({value,done:!1}),new Promise((r)=>prev=r)},this.resolve=()=>(this.active=!1,resolve3({done:!0})),this.reject=(x)=>(this.active=!1,reject(x))});return this.execute(),promise},return(){return prev&&prev(CLOSE),{done:!0}}})}}describe(){return this.options.simple=!1,this.onlyDescribe=this.options.prepare=!0,this}stream(){throw Error(".stream has been renamed to .forEach")}forEach(fn){return this.forEachFn=fn,this.handle(),this}raw(){return this.isRaw=!0,this}values(){return this.isRaw="values",this}async handle(){!this.executed&&(this.executed=!0)&&await 1&&this.handler(this)}execute(){return this.handle(),this}then(){return this.handle(),super.then.apply(this,arguments)}catch(){return this.handle(),super.catch.apply(this,arguments)}finally(){return this.handle(),super.finally.apply(this,arguments)}}});function connection(x,options,socket){let{host,port}=socket||options,error=Object.assign(Error("write "+x+" "+(options.path||host+":"+port)),{code:x,errno:x,address:options.path||host},options.path?{}:{port});return Error.captureStackTrace(error,connection),error}function postgres(x){let error=new PostgresError(x);return Error.captureStackTrace(error,postgres),error}function generic(code,message){let error=Object.assign(Error(code+": "+message),{code});return Error.captureStackTrace(error,generic),error}function notSupported(x){let error=Object.assign(Error(x+" (B) is not supported"),{code:"MESSAGE_NOT_SUPPORTED",name:x});return Error.captureStackTrace(error,notSupported),error}var PostgresError,Errors;var init_errors2=__esm(()=>{PostgresError=class PostgresError extends Error{constructor(x){super(x.message);this.name=this.constructor.name,Object.assign(this,x)}};Errors={connection,postgres,generic,notSupported}});class NotTagged{then(){notTagged()}catch(){notTagged()}finally(){notTagged()}}function handleValue(x,parameters,types4,options){let value=x instanceof Parameter?x.value:x;if(value===void 0){if(x instanceof Parameter?x.value=options.transform.undefined:value=x=options.transform.undefined,value===void 0)throw Errors.generic("UNDEFINED_VALUE","Undefined values are not allowed")}return"$"+types4.push(x instanceof Parameter?(parameters.push(x.value),x.array?x.array[x.type||inferType(x.value)]||x.type||firstIsString(x.value):x.type):(parameters.push(x),inferType(x)))}function stringify(q,string,value,parameters,types4,options){for(let i2=1;i2<q.strings.length;i2++)string+=stringifyValue(string,value,parameters,types4,options)+q.strings[i2],value=q.args[i2];return string}function stringifyValue(string,value,parameters,types4,o){return value instanceof Builder?value.build(string,parameters,types4,o):value instanceof Query?fragment(value,parameters,types4,o):value instanceof Identifier?value.value:value&&value[0]instanceof Query?value.reduce((acc,x)=>acc+" "+fragment(x,parameters,types4,o),""):handleValue(value,parameters,types4,o)}function fragment(q,parameters,types4,options){return q.fragment=!0,stringify(q,q.strings[0],q.args[0],parameters,types4,options)}function valuesBuilder(first,parameters,types4,columns,options){return first.map((row)=>"("+columns.map((column)=>stringifyValue("values",row[column],parameters,types4,options)).join(",")+")").join(",")}function values(first,rest,parameters,types4,options){let multi=Array.isArray(first[0]),columns=rest.length?rest.flat():Object.keys(multi?first[0]:first);return valuesBuilder(multi?first:[first],parameters,types4,columns,options)}function select(first,rest,parameters,types4,options){if(typeof first==="string"&&(first=[first].concat(rest)),Array.isArray(first))return escapeIdentifiers(first,options);let value;return(rest.length?rest.flat():Object.keys(first)).map((x)=>{return value=first[x],(value instanceof Query?fragment(value,parameters,types4,options):value instanceof Identifier?value.value:handleValue(value,parameters,types4,options))+" as "+escapeIdentifier(options.transform.column.to?options.transform.column.to(x):x)}).join(",")}function notTagged(){throw Errors.generic("NOT_TAGGED_CALL","Query not called as a tagged template literal")}function firstIsString(x){if(Array.isArray(x))return firstIsString(x[0]);return typeof x==="string"?1009:0}function typeHandlers(types4){return Object.keys(types4).reduce((acc,k)=>{if(types4[k].from&&[].concat(types4[k].from).forEach((x)=>acc.parsers[x]=types4[k].parse),types4[k].serialize)acc.serializers[types4[k].to]=types4[k].serialize,types4[k].from&&[].concat(types4[k].from).forEach((x)=>acc.serializers[x]=types4[k].serialize);return acc},{parsers:{},serializers:{}})}function escapeIdentifiers(xs,{transform:{column}}){return xs.map((x)=>escapeIdentifier(column.to?column.to(x):x)).join(",")}function arrayEscape(x){return x.replace(escapeBackslash,"\\\\").replace(escapeQuote,"\\\"")}function arrayParserLoop(s,x,parser,typarray){let xs=[],delimiter=typarray===1020?";":",";for(;s.i<x.length;s.i++){if(s.char=x[s.i],s.quoted)if(s.char==="\\")s.str+=x[++s.i];else if(s.char==='"')xs.push(parser?parser(s.str):s.str),s.str="",s.quoted=x[s.i+1]==='"',s.last=s.i+2;else s.str+=s.char;else if(s.char==='"')s.quoted=!0;else if(s.char==="{")s.last=++s.i,xs.push(arrayParserLoop(s,x,parser,typarray));else if(s.char==="}"){s.quoted=!1,s.last<s.i&&xs.push(parser?parser(x.slice(s.last,s.i)):x.slice(s.last,s.i)),s.last=s.i+1;break}else if(s.char===delimiter&&s.p!=="}"&&s.p!=='"')xs.push(parser?parser(x.slice(s.last,s.i)):x.slice(s.last,s.i)),s.last=s.i+1;s.p=s.char}return s.last<s.i&&xs.push(parser?parser(x.slice(s.last,s.i+1)):x.slice(s.last,s.i+1)),xs}function createJsonTransform(fn){return function jsonTransform(x,column){return typeof x==="object"&&x!==null&&(column.type===114||column.type===3802)?Array.isArray(x)?x.map((x2)=>jsonTransform(x2,column)):Object.entries(x).reduce((acc,[k,v])=>Object.assign(acc,{[fn(k)]:jsonTransform(v,column)}),{}):x}}var types3,Identifier,Parameter,Builder,defaultHandlers,builders,serializers,parsers,mergeUserTypes=function(types4){let user=typeHandlers(types4||{});return{serializers:Object.assign({},serializers,user.serializers),parsers:Object.assign({},parsers,user.parsers)}},escapeIdentifier=function(str2){return'"'+str2.replace(/"/g,'""').replace(/\./g,'"."')+'"'},inferType=function inferType2(x){return x instanceof Parameter?x.type:x instanceof Date?1184:x instanceof Uint8Array?17:x===!0||x===!1?16:typeof x==="bigint"?20:Array.isArray(x)?inferType2(x[0]):0},escapeBackslash,escapeQuote,arraySerializer=function arraySerializer2(xs,serializer,options,typarray){if(Array.isArray(xs)===!1)return xs;if(!xs.length)return"{}";let first=xs[0],delimiter=typarray===1020?";":",";if(Array.isArray(first)&&!first.type)return"{"+xs.map((x)=>arraySerializer2(x,serializer,options,typarray)).join(delimiter)+"}";return"{"+xs.map((x)=>{if(x===void 0){if(x=options.transform.undefined,x===void 0)throw Errors.generic("UNDEFINED_VALUE","Undefined values are not allowed")}return x===null?"null":'"'+arrayEscape(serializer?serializer(x.type?x.value:x):""+x)+'"'}).join(delimiter)+"}"},arrayParserState,arrayParser=function(x,parser,typarray){return arrayParserState.i=arrayParserState.last=0,arrayParserLoop(arrayParserState,x,parser,typarray)},toCamel=(x)=>{let str2=x[0];for(let i2=1;i2<x.length;i2++)str2+=x[i2]==="_"?x[++i2].toUpperCase():x[i2];return str2},toPascal=(x)=>{let str2=x[0].toUpperCase();for(let i2=1;i2<x.length;i2++)str2+=x[i2]==="_"?x[++i2].toUpperCase():x[i2];return str2},toKebab=(x)=>x.replace(/_/g,"-"),fromCamel=(x)=>x.replace(/([A-Z])/g,"_$1").toLowerCase(),fromPascal=(x)=>(x.slice(0,1)+x.slice(1).replace(/([A-Z])/g,"_$1")).toLowerCase(),fromKebab=(x)=>x.replace(/-/g,"_"),camel,pascal,kebab;var init_types3=__esm(()=>{init_query();init_errors2();types3={string:{to:25,from:null,serialize:(x)=>""+x},number:{to:0,from:[21,23,26,700,701],serialize:(x)=>""+x,parse:(x)=>+x},json:{to:114,from:[114,3802],serialize:(x)=>JSON.stringify(x),parse:(x)=>JSON.parse(x)},boolean:{to:16,from:16,serialize:(x)=>x===!0?"t":"f",parse:(x)=>x==="t"},date:{to:1184,from:[1082,1114,1184],serialize:(x)=>(x instanceof Date?x:new Date(x)).toISOString(),parse:(x)=>new Date(x)},bytea:{to:17,from:17,serialize:(x)=>"\\x"+Buffer.from(x).toString("hex"),parse:(x)=>Buffer.from(x.slice(2),"hex")}};Identifier=class Identifier extends NotTagged{constructor(value){super();this.value=escapeIdentifier(value)}};Parameter=class Parameter extends NotTagged{constructor(value,type2,array){super();this.value=value,this.type=type2,this.array=array}};Builder=class Builder extends NotTagged{constructor(first,rest){super();this.first=first,this.rest=rest}build(before,parameters,types4,options){let keyword=builders.map(([x,fn])=>({fn,i:before.search(x)})).sort((a,b)=>a.i-b.i).pop();return keyword.i===-1?escapeIdentifiers(this.first,options):keyword.fn(this.first,this.rest,parameters,types4,options)}};defaultHandlers=typeHandlers(types3);builders=Object.entries({values,in:(...xs)=>{let x=values(...xs);return x==="()"?"(null)":x},select,as:select,returning:select,"\\(":select,update(first,rest,parameters,types4,options){return(rest.length?rest.flat():Object.keys(first)).map((x)=>escapeIdentifier(options.transform.column.to?options.transform.column.to(x):x)+"="+stringifyValue("values",first[x],parameters,types4,options))},insert(first,rest,parameters,types4,options){let columns=rest.length?rest.flat():Object.keys(Array.isArray(first)?first[0]:first);return"("+escapeIdentifiers(columns,options)+")values"+valuesBuilder(Array.isArray(first)?first:[first],parameters,types4,columns,options)}}).map(([x,fn])=>[new RegExp("((?:^|[\\s(])"+x+"(?:$|[\\s(]))(?![\\s\\S]*\\1)","i"),fn]);serializers=defaultHandlers.serializers,parsers=defaultHandlers.parsers;escapeBackslash=/\\/g,escapeQuote=/"/g;arrayParserState={i:0,char:null,str:"",quoted:!1,last:0};toCamel.column={from:toCamel};toCamel.value={from:createJsonTransform(toCamel)};fromCamel.column={to:fromCamel};camel={...toCamel};camel.column.to=fromCamel;toPascal.column={from:toPascal};toPascal.value={from:createJsonTransform(toPascal)};fromPascal.column={to:fromPascal};pascal={...toPascal};pascal.column.to=fromPascal;toKebab.column={from:toKebab};toKebab.value={from:createJsonTransform(toKebab)};fromKebab.column={to:fromKebab};kebab={...toKebab};kebab.column.to=fromKebab});var Result;var init_result=__esm(()=>{Result=class Result extends Array{constructor(){super();Object.defineProperties(this,{count:{value:null,writable:!0},state:{value:null,writable:!0},command:{value:null,writable:!0},columns:{value:null,writable:!0},statement:{value:null,writable:!0}})}static get[Symbol.species](){return Array}}});function Queue(initial=[]){let xs=initial.slice(),index=0;return{get length(){return xs.length-index},remove:(x)=>{let index2=xs.indexOf(x);return index2===-1?null:(xs.splice(index2,1),x)},push:(x)=>(xs.push(x),x),shift:()=>{let out=xs[index++];if(index===xs.length)index=0,xs=[];else xs[index-1]=void 0;return out}}}var queue_default;var init_queue=__esm(()=>{queue_default=Queue});function fit(x){if(buffer.length-b.i<x){let prev=buffer,length=prev.length;buffer=Buffer.allocUnsafe(length+(length>>1)+x),prev.copy(buffer)}}function reset(){return b.i=0,b}var buffer,messages,b,bytes_default;var init_bytes=__esm(()=>{buffer=Buffer.allocUnsafe(256),messages="BCcDdEFfHPpQSX".split("").reduce((acc,x)=>{let v=x.charCodeAt(0);return acc[x]=()=>{return buffer[0]=v,b.i=5,b},acc},{}),b=Object.assign(reset,messages,{N:String.fromCharCode(0),i:0,inc(x){return b.i+=x,b},str(x){let length=Buffer.byteLength(x);return fit(length),b.i+=buffer.write(x,b.i,length,"utf8"),b},i16(x){return fit(2),buffer.writeUInt16BE(x,b.i),b.i+=2,b},i32(x,i2){if(i2||i2===0)return buffer.writeUInt32BE(x,i2),b;return fit(4),buffer.writeUInt32BE(x,b.i),b.i+=4,b},z(x){return fit(x),buffer.fill(0,b.i,b.i+x),b.i+=x,b},raw(x){return buffer=Buffer.concat([buffer.subarray(0,b.i),x]),b.i=buffer.length,b},end(at=1){buffer.writeUInt32BE(b.i-at,at);let out=buffer.subarray(0,b.i);return b.i=0,buffer=Buffer.allocUnsafe(256),out}}),bytes_default=b});import net from"net";import tls from"tls";import crypto2 from"crypto";import Stream from"stream";import{performance as performance2}from"perf_hooks";function Connection(options,queues={},{onopen=noop,onend=noop,onclose=noop}={}){let{sslnegotiation,ssl,max,user,host,port,database,parsers:parsers2,transform,onnotice,onnotify,onparameter,max_pipeline,keep_alive,backoff,target_session_attrs}=options,sent=queue_default(),id=uid++,backend={pid:null,secret:null},idleTimer=timer(end,options.idle_timeout),lifeTimer=timer(end,options.max_lifetime),connectTimer=timer(connectTimedOut,options.connect_timeout),socket=null,cancelMessage,errorResponse=null,result2=new Result,incoming=Buffer.alloc(0),needsTypes=options.fetch_types,backendParameters={},statements={},statementId=Math.random().toString(36).slice(2),statementCount=1,closedTime=0,remaining=0,hostIndex=0,retries=0,length=0,delay=0,rows=0,serverSignature=null,nextWriteTimer=null,terminated=!1,incomings=null,results=null,initial=null,ending=null,stream=null,chunk=null,ended=null,nonce=null,query=null,final=null,connection2={queue:queues.closed,idleTimer,connect(query2){initial=query2,reconnect()},terminate,execute,cancel,end,count:0,id};return queues.closed&&queues.closed.push(connection2),connection2;async function createSocket(){let x;try{x=options.socket?await Promise.resolve(options.socket(options)):new net.Socket}catch(e){error(e);return}return x.on("error",error),x.on("close",closed),x.on("drain",drain),x}async function cancel({pid,secret},resolve3,reject){try{cancelMessage=bytes_default().i32(16).i32(80877102).i32(pid).i32(secret).end(16),await connect(),socket.once("error",reject),socket.once("close",resolve3)}catch(error2){reject(error2)}}function execute(q){if(terminated)return queryError(q,Errors.connection("CONNECTION_DESTROYED",options));if(stream)return queryError(q,Errors.generic("COPY_IN_PROGRESS","You cannot execute queries during copy"));if(q.cancelled)return;try{return q.state=backend,query?sent.push(q):(query=q,query.active=!0),build(q),write(toBuffer(q))&&!q.describeFirst&&!q.cursorFn&&sent.length<max_pipeline&&(!q.options.onexecute||q.options.onexecute(connection2))}catch(error2){return sent.length===0&&write(Sync),errored(error2),!0}}function toBuffer(q){if(q.parameters.length>=65534)throw Errors.generic("MAX_PARAMETERS_EXCEEDED","Max number of parameters (65534) exceeded");return q.options.simple?bytes_default().Q().str(q.statement.string+bytes_default.N).end():q.describeFirst?Buffer.concat([describe(q),Flush]):q.prepare?q.prepared?prepared(q):Buffer.concat([describe(q),prepared(q)]):unnamed(q)}function describe(q){return Buffer.concat([Parse(q.statement.string,q.parameters,q.statement.types,q.statement.name),Describe("S",q.statement.name)])}function prepared(q){return Buffer.concat([Bind(q.parameters,q.statement.types,q.statement.name,q.cursorName),q.cursorFn?Execute("",q.cursorRows):ExecuteUnnamed])}function unnamed(q){return Buffer.concat([Parse(q.statement.string,q.parameters,q.statement.types),DescribeUnnamed,prepared(q)])}function build(q){let parameters=[],types4=[],string=stringify(q,q.strings[0],q.args[0],parameters,types4,options);!q.tagged&&q.args.forEach((x)=>handleValue(x,parameters,types4,options)),q.prepare=options.prepare&&("prepare"in q.options?q.options.prepare:!0),q.string=string,q.signature=q.prepare&&types4+string,q.onlyDescribe&&delete statements[q.signature],q.parameters=q.parameters||parameters,q.prepared=q.prepare&&q.signature in statements,q.describeFirst=q.onlyDescribe||parameters.length&&!q.prepared,q.statement=q.prepared?statements[q.signature]:{string,types:types4,name:q.prepare?statementId+statementCount++:""},typeof options.debug==="function"&&options.debug(id,string,parameters,types4)}function write(x,fn){if(chunk=chunk?Buffer.concat([chunk,x]):Buffer.from(x),fn||chunk.length>=1024)return nextWrite(fn);return nextWriteTimer===null&&(nextWriteTimer=setImmediate(nextWrite)),!0}function nextWrite(fn){let x=socket.write(chunk,fn);return nextWriteTimer!==null&&clearImmediate(nextWriteTimer),chunk=nextWriteTimer=null,x}function connectTimedOut(){errored(Errors.connection("CONNECT_TIMEOUT",options,socket)),socket.destroy()}async function secure(){if(sslnegotiation!=="direct"){if(write(SSLRequest),!await new Promise((r)=>socket.once("data",(x)=>r(x[0]===83)))&&ssl==="prefer")return connected()}let options2={socket,servername:net.isIP(socket.host)?void 0:socket.host};if(sslnegotiation==="direct")options2.ALPNProtocols=["postgresql"];if(ssl==="require"||ssl==="allow"||ssl==="prefer")options2.rejectUnauthorized=!1;else if(typeof ssl==="object")Object.assign(options2,ssl);socket.removeAllListeners(),socket=tls.connect(options2),socket.on("secureConnect",connected),socket.on("error",error),socket.on("close",closed),socket.on("drain",drain)}function drain(){!query&&onopen(connection2)}function data(x){if(incomings){if(incomings.push(x),remaining-=x.length,remaining>0)return}incoming=incomings?Buffer.concat(incomings,length-remaining):incoming.length===0?x:Buffer.concat([incoming,x],incoming.length+x.length);while(incoming.length>4){if(length=incoming.readUInt32BE(1),length>=incoming.length){remaining=length-incoming.length,incomings=[incoming];break}try{handle(incoming.subarray(0,length+1))}catch(e){query&&(query.cursorFn||query.describeFirst)&&write(Sync),errored(e)}incoming=incoming.subarray(length+1),remaining=0,incomings=null}}async function connect(){if(terminated=!1,backendParameters={},socket||(socket=await createSocket()),!socket)return;if(connectTimer.start(),options.socket)return ssl?secure():connected();if(socket.on("connect",ssl?secure:connected),options.path)return socket.connect(options.path);socket.ssl=ssl,socket.connect(port[hostIndex],host[hostIndex]),socket.host=host[hostIndex],socket.port=port[hostIndex],hostIndex=(hostIndex+1)%port.length}function reconnect(){setTimeout(connect,closedTime?Math.max(0,closedTime+delay-performance2.now()):0)}function connected(){try{statements={},needsTypes=options.fetch_types,statementId=Math.random().toString(36).slice(2),statementCount=1,lifeTimer.start(),socket.on("data",data),keep_alive&&socket.setKeepAlive&&socket.setKeepAlive(!0,1000*keep_alive);let s=StartupMessage();write(s)}catch(err){error(err)}}function error(err){if(connection2.queue===queues.connecting&&options.host[retries+1])return;errored(err);while(sent.length)queryError(sent.shift(),err)}function errored(err){stream&&(stream.destroy(err),stream=null),query&&queryError(query,err),initial&&(queryError(initial,err),initial=null)}function queryError(query2,err){if(query2.reserve)return query2.reject(err);if(!err||typeof err!=="object")err=Error(err);"query"in err||"parameters"in err||Object.defineProperties(err,{stack:{value:err.stack+query2.origin.replace(/.*\n/,`
|
|
659
|
+
`).filter(Boolean))try{let msg=JSON.parse(line);if(msg.id)records.push(msg)}catch{}return records}async function seedTeamChat(sql,repoPath){let dir=join16(repoPath,".genie","chat");if(!existsSync12(dir))return 0;let files;try{files=await readdir3(dir)}catch{return 0}let count=0;for(let file of files){if(!file.endsWith(".jsonl")||file.endsWith(".migrated"))continue;if(!needsMigration(join16(dir,file)))continue;let teamName=file.replace(".jsonl","").replace(/--/g,"/"),content;try{content=await readFile4(join16(dir,file),"utf-8")}catch{continue}for(let msg of parseJsonlRecords(content))await upsertChatMessage(sql,msg,teamName,repoPath),count++}return count}async function markMigrated(repoPath){let workersPath=workersJsonPath();if(needsMigration(workersPath))await rename(workersPath,`${workersPath}.migrated`);if(!repoPath)return;await renameMatchingFiles(join16(repoPath,".genie","mailbox"),isMailboxFile),await renameMatchingFiles(join16(repoPath,".genie","chat"),(f)=>f.endsWith(".jsonl")&&!f.endsWith(".migrated"))}async function runSeed(sql,repoPath){let result2={agents:0,templates:0,teams:0,mailboxMessages:0,chatMessages:0},workers=await seedWorkers(sql);result2.agents=workers.agents,result2.templates=workers.templates;let teams=await seedTeams(sql);if(result2.teams=teams.count,repoPath)result2.mailboxMessages=await seedMailbox(sql,repoPath),result2.chatMessages=await seedTeamChat(sql,repoPath);if(await markMigrated(repoPath),!teams.hadFailures)await writeTeamsSeedMarker(teams.teamNames);return result2}var MEMBER_UUID_RE;var init_pg_seed=__esm(()=>{init_claude_native_teams();MEMBER_UUID_RE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/});import{execSync as execSync2}from"child_process";import{readFileSync as readFileSync8}from"fs";function getProcessStartTime(pid){if(!Number.isInteger(pid)||pid<=0)return null;try{if(process.platform==="darwin"){let raw=execSync2(`ps -o lstart= -p ${pid}`,{encoding:"utf8",timeout:1000,stdio:["ignore","pipe","ignore"]}).trim();return raw===""?null:raw}if(process.platform==="linux"){let raw=readFileSync8(`/proc/${pid}/stat`,"utf-8"),closeParen=raw.lastIndexOf(")");if(closeParen<0)return null;let starttime=raw.slice(closeParen+1).trim().split(/\s+/)[19];return starttime&&starttime.length>0?starttime:null}}catch{return null}return null}var init_process_identity=()=>{};function cachedError(xs){if(originCache.has(xs))return originCache.get(xs);let x=Error.stackTraceLimit;return Error.stackTraceLimit=4,originCache.set(xs,Error()),Error.stackTraceLimit=x,originCache.get(xs)}var originCache,originStackCache,originError,CLOSE,Query;var init_query=__esm(()=>{originCache=new Map,originStackCache=new Map,originError=Symbol("OriginError"),CLOSE={};Query=class Query extends Promise{constructor(strings,args,handler,canceller,options={}){let resolve3,reject;super((a,b)=>{resolve3=a,reject=b});this.tagged=Array.isArray(strings.raw),this.strings=strings,this.args=args,this.handler=handler,this.canceller=canceller,this.options=options,this.state=null,this.statement=null,this.resolve=(x)=>(this.active=!1,resolve3(x)),this.reject=(x)=>(this.active=!1,reject(x)),this.active=!1,this.cancelled=null,this.executed=!1,this.signature="",this[originError]=this.handler.debug?Error():this.tagged&&cachedError(this.strings)}get origin(){return(this.handler.debug?this[originError].stack:this.tagged&&originStackCache.has(this.strings)?originStackCache.get(this.strings):originStackCache.set(this.strings,this[originError].stack).get(this.strings))||""}static get[Symbol.species](){return Promise}cancel(){return this.canceller&&(this.canceller(this),this.canceller=null)}simple(){return this.options.simple=!0,this.options.prepare=!1,this}async readable(){return this.simple(),this.streaming=!0,this}async writable(){return this.simple(),this.streaming=!0,this}cursor(rows=1,fn){if(this.options.simple=!1,typeof rows==="function")fn=rows,rows=1;if(this.cursorRows=rows,typeof fn==="function")return this.cursorFn=fn,this;let prev;return{[Symbol.asyncIterator]:()=>({next:()=>{if(this.executed&&!this.active)return{done:!0};prev&&prev();let promise=new Promise((resolve3,reject)=>{this.cursorFn=(value)=>{return resolve3({value,done:!1}),new Promise((r)=>prev=r)},this.resolve=()=>(this.active=!1,resolve3({done:!0})),this.reject=(x)=>(this.active=!1,reject(x))});return this.execute(),promise},return(){return prev&&prev(CLOSE),{done:!0}}})}}describe(){return this.options.simple=!1,this.onlyDescribe=this.options.prepare=!0,this}stream(){throw Error(".stream has been renamed to .forEach")}forEach(fn){return this.forEachFn=fn,this.handle(),this}raw(){return this.isRaw=!0,this}values(){return this.isRaw="values",this}async handle(){!this.executed&&(this.executed=!0)&&await 1&&this.handler(this)}execute(){return this.handle(),this}then(){return this.handle(),super.then.apply(this,arguments)}catch(){return this.handle(),super.catch.apply(this,arguments)}finally(){return this.handle(),super.finally.apply(this,arguments)}}});function connection(x,options,socket){let{host,port}=socket||options,error=Object.assign(Error("write "+x+" "+(options.path||host+":"+port)),{code:x,errno:x,address:options.path||host},options.path?{}:{port});return Error.captureStackTrace(error,connection),error}function postgres(x){let error=new PostgresError(x);return Error.captureStackTrace(error,postgres),error}function generic(code,message){let error=Object.assign(Error(code+": "+message),{code});return Error.captureStackTrace(error,generic),error}function notSupported(x){let error=Object.assign(Error(x+" (B) is not supported"),{code:"MESSAGE_NOT_SUPPORTED",name:x});return Error.captureStackTrace(error,notSupported),error}var PostgresError,Errors;var init_errors2=__esm(()=>{PostgresError=class PostgresError extends Error{constructor(x){super(x.message);this.name=this.constructor.name,Object.assign(this,x)}};Errors={connection,postgres,generic,notSupported}});class NotTagged{then(){notTagged()}catch(){notTagged()}finally(){notTagged()}}function handleValue(x,parameters,types4,options){let value=x instanceof Parameter?x.value:x;if(value===void 0){if(x instanceof Parameter?x.value=options.transform.undefined:value=x=options.transform.undefined,value===void 0)throw Errors.generic("UNDEFINED_VALUE","Undefined values are not allowed")}return"$"+types4.push(x instanceof Parameter?(parameters.push(x.value),x.array?x.array[x.type||inferType(x.value)]||x.type||firstIsString(x.value):x.type):(parameters.push(x),inferType(x)))}function stringify(q,string,value,parameters,types4,options){for(let i2=1;i2<q.strings.length;i2++)string+=stringifyValue(string,value,parameters,types4,options)+q.strings[i2],value=q.args[i2];return string}function stringifyValue(string,value,parameters,types4,o){return value instanceof Builder?value.build(string,parameters,types4,o):value instanceof Query?fragment(value,parameters,types4,o):value instanceof Identifier?value.value:value&&value[0]instanceof Query?value.reduce((acc,x)=>acc+" "+fragment(x,parameters,types4,o),""):handleValue(value,parameters,types4,o)}function fragment(q,parameters,types4,options){return q.fragment=!0,stringify(q,q.strings[0],q.args[0],parameters,types4,options)}function valuesBuilder(first,parameters,types4,columns,options){return first.map((row)=>"("+columns.map((column)=>stringifyValue("values",row[column],parameters,types4,options)).join(",")+")").join(",")}function values(first,rest,parameters,types4,options){let multi=Array.isArray(first[0]),columns=rest.length?rest.flat():Object.keys(multi?first[0]:first);return valuesBuilder(multi?first:[first],parameters,types4,columns,options)}function select(first,rest,parameters,types4,options){if(typeof first==="string"&&(first=[first].concat(rest)),Array.isArray(first))return escapeIdentifiers(first,options);let value;return(rest.length?rest.flat():Object.keys(first)).map((x)=>{return value=first[x],(value instanceof Query?fragment(value,parameters,types4,options):value instanceof Identifier?value.value:handleValue(value,parameters,types4,options))+" as "+escapeIdentifier(options.transform.column.to?options.transform.column.to(x):x)}).join(",")}function notTagged(){throw Errors.generic("NOT_TAGGED_CALL","Query not called as a tagged template literal")}function firstIsString(x){if(Array.isArray(x))return firstIsString(x[0]);return typeof x==="string"?1009:0}function typeHandlers(types4){return Object.keys(types4).reduce((acc,k)=>{if(types4[k].from&&[].concat(types4[k].from).forEach((x)=>acc.parsers[x]=types4[k].parse),types4[k].serialize)acc.serializers[types4[k].to]=types4[k].serialize,types4[k].from&&[].concat(types4[k].from).forEach((x)=>acc.serializers[x]=types4[k].serialize);return acc},{parsers:{},serializers:{}})}function escapeIdentifiers(xs,{transform:{column}}){return xs.map((x)=>escapeIdentifier(column.to?column.to(x):x)).join(",")}function arrayEscape(x){return x.replace(escapeBackslash,"\\\\").replace(escapeQuote,"\\\"")}function arrayParserLoop(s,x,parser,typarray){let xs=[],delimiter=typarray===1020?";":",";for(;s.i<x.length;s.i++){if(s.char=x[s.i],s.quoted)if(s.char==="\\")s.str+=x[++s.i];else if(s.char==='"')xs.push(parser?parser(s.str):s.str),s.str="",s.quoted=x[s.i+1]==='"',s.last=s.i+2;else s.str+=s.char;else if(s.char==='"')s.quoted=!0;else if(s.char==="{")s.last=++s.i,xs.push(arrayParserLoop(s,x,parser,typarray));else if(s.char==="}"){s.quoted=!1,s.last<s.i&&xs.push(parser?parser(x.slice(s.last,s.i)):x.slice(s.last,s.i)),s.last=s.i+1;break}else if(s.char===delimiter&&s.p!=="}"&&s.p!=='"')xs.push(parser?parser(x.slice(s.last,s.i)):x.slice(s.last,s.i)),s.last=s.i+1;s.p=s.char}return s.last<s.i&&xs.push(parser?parser(x.slice(s.last,s.i+1)):x.slice(s.last,s.i+1)),xs}function createJsonTransform(fn){return function jsonTransform(x,column){return typeof x==="object"&&x!==null&&(column.type===114||column.type===3802)?Array.isArray(x)?x.map((x2)=>jsonTransform(x2,column)):Object.entries(x).reduce((acc,[k,v])=>Object.assign(acc,{[fn(k)]:jsonTransform(v,column)}),{}):x}}var types3,Identifier,Parameter,Builder,defaultHandlers,builders,serializers,parsers,mergeUserTypes=function(types4){let user=typeHandlers(types4||{});return{serializers:Object.assign({},serializers,user.serializers),parsers:Object.assign({},parsers,user.parsers)}},escapeIdentifier=function(str2){return'"'+str2.replace(/"/g,'""').replace(/\./g,'"."')+'"'},inferType=function inferType2(x){return x instanceof Parameter?x.type:x instanceof Date?1184:x instanceof Uint8Array?17:x===!0||x===!1?16:typeof x==="bigint"?20:Array.isArray(x)?inferType2(x[0]):0},escapeBackslash,escapeQuote,arraySerializer=function arraySerializer2(xs,serializer,options,typarray){if(Array.isArray(xs)===!1)return xs;if(!xs.length)return"{}";let first=xs[0],delimiter=typarray===1020?";":",";if(Array.isArray(first)&&!first.type)return"{"+xs.map((x)=>arraySerializer2(x,serializer,options,typarray)).join(delimiter)+"}";return"{"+xs.map((x)=>{if(x===void 0){if(x=options.transform.undefined,x===void 0)throw Errors.generic("UNDEFINED_VALUE","Undefined values are not allowed")}return x===null?"null":'"'+arrayEscape(serializer?serializer(x.type?x.value:x):""+x)+'"'}).join(delimiter)+"}"},arrayParserState,arrayParser=function(x,parser,typarray){return arrayParserState.i=arrayParserState.last=0,arrayParserLoop(arrayParserState,x,parser,typarray)},toCamel=(x)=>{let str2=x[0];for(let i2=1;i2<x.length;i2++)str2+=x[i2]==="_"?x[++i2].toUpperCase():x[i2];return str2},toPascal=(x)=>{let str2=x[0].toUpperCase();for(let i2=1;i2<x.length;i2++)str2+=x[i2]==="_"?x[++i2].toUpperCase():x[i2];return str2},toKebab=(x)=>x.replace(/_/g,"-"),fromCamel=(x)=>x.replace(/([A-Z])/g,"_$1").toLowerCase(),fromPascal=(x)=>(x.slice(0,1)+x.slice(1).replace(/([A-Z])/g,"_$1")).toLowerCase(),fromKebab=(x)=>x.replace(/-/g,"_"),camel,pascal,kebab;var init_types3=__esm(()=>{init_query();init_errors2();types3={string:{to:25,from:null,serialize:(x)=>""+x},number:{to:0,from:[21,23,26,700,701],serialize:(x)=>""+x,parse:(x)=>+x},json:{to:114,from:[114,3802],serialize:(x)=>JSON.stringify(x),parse:(x)=>JSON.parse(x)},boolean:{to:16,from:16,serialize:(x)=>x===!0?"t":"f",parse:(x)=>x==="t"},date:{to:1184,from:[1082,1114,1184],serialize:(x)=>(x instanceof Date?x:new Date(x)).toISOString(),parse:(x)=>new Date(x)},bytea:{to:17,from:17,serialize:(x)=>"\\x"+Buffer.from(x).toString("hex"),parse:(x)=>Buffer.from(x.slice(2),"hex")}};Identifier=class Identifier extends NotTagged{constructor(value){super();this.value=escapeIdentifier(value)}};Parameter=class Parameter extends NotTagged{constructor(value,type2,array){super();this.value=value,this.type=type2,this.array=array}};Builder=class Builder extends NotTagged{constructor(first,rest){super();this.first=first,this.rest=rest}build(before,parameters,types4,options){let keyword=builders.map(([x,fn])=>({fn,i:before.search(x)})).sort((a,b)=>a.i-b.i).pop();return keyword.i===-1?escapeIdentifiers(this.first,options):keyword.fn(this.first,this.rest,parameters,types4,options)}};defaultHandlers=typeHandlers(types3);builders=Object.entries({values,in:(...xs)=>{let x=values(...xs);return x==="()"?"(null)":x},select,as:select,returning:select,"\\(":select,update(first,rest,parameters,types4,options){return(rest.length?rest.flat():Object.keys(first)).map((x)=>escapeIdentifier(options.transform.column.to?options.transform.column.to(x):x)+"="+stringifyValue("values",first[x],parameters,types4,options))},insert(first,rest,parameters,types4,options){let columns=rest.length?rest.flat():Object.keys(Array.isArray(first)?first[0]:first);return"("+escapeIdentifiers(columns,options)+")values"+valuesBuilder(Array.isArray(first)?first:[first],parameters,types4,columns,options)}}).map(([x,fn])=>[new RegExp("((?:^|[\\s(])"+x+"(?:$|[\\s(]))(?![\\s\\S]*\\1)","i"),fn]);serializers=defaultHandlers.serializers,parsers=defaultHandlers.parsers;escapeBackslash=/\\/g,escapeQuote=/"/g;arrayParserState={i:0,char:null,str:"",quoted:!1,last:0};toCamel.column={from:toCamel};toCamel.value={from:createJsonTransform(toCamel)};fromCamel.column={to:fromCamel};camel={...toCamel};camel.column.to=fromCamel;toPascal.column={from:toPascal};toPascal.value={from:createJsonTransform(toPascal)};fromPascal.column={to:fromPascal};pascal={...toPascal};pascal.column.to=fromPascal;toKebab.column={from:toKebab};toKebab.value={from:createJsonTransform(toKebab)};fromKebab.column={to:fromKebab};kebab={...toKebab};kebab.column.to=fromKebab});var Result;var init_result=__esm(()=>{Result=class Result extends Array{constructor(){super();Object.defineProperties(this,{count:{value:null,writable:!0},state:{value:null,writable:!0},command:{value:null,writable:!0},columns:{value:null,writable:!0},statement:{value:null,writable:!0}})}static get[Symbol.species](){return Array}}});function Queue(initial=[]){let xs=initial.slice(),index=0;return{get length(){return xs.length-index},remove:(x)=>{let index2=xs.indexOf(x);return index2===-1?null:(xs.splice(index2,1),x)},push:(x)=>(xs.push(x),x),shift:()=>{let out=xs[index++];if(index===xs.length)index=0,xs=[];else xs[index-1]=void 0;return out}}}var queue_default;var init_queue=__esm(()=>{queue_default=Queue});function fit(x){if(buffer.length-b.i<x){let prev=buffer,length=prev.length;buffer=Buffer.allocUnsafe(length+(length>>1)+x),prev.copy(buffer)}}function reset(){return b.i=0,b}var buffer,messages,b,bytes_default;var init_bytes=__esm(()=>{buffer=Buffer.allocUnsafe(256),messages="BCcDdEFfHPpQSX".split("").reduce((acc,x)=>{let v=x.charCodeAt(0);return acc[x]=()=>{return buffer[0]=v,b.i=5,b},acc},{}),b=Object.assign(reset,messages,{N:String.fromCharCode(0),i:0,inc(x){return b.i+=x,b},str(x){let length=Buffer.byteLength(x);return fit(length),b.i+=buffer.write(x,b.i,length,"utf8"),b},i16(x){return fit(2),buffer.writeUInt16BE(x,b.i),b.i+=2,b},i32(x,i2){if(i2||i2===0)return buffer.writeUInt32BE(x,i2),b;return fit(4),buffer.writeUInt32BE(x,b.i),b.i+=4,b},z(x){return fit(x),buffer.fill(0,b.i,b.i+x),b.i+=x,b},raw(x){return buffer=Buffer.concat([buffer.subarray(0,b.i),x]),b.i=buffer.length,b},end(at=1){buffer.writeUInt32BE(b.i-at,at);let out=buffer.subarray(0,b.i);return b.i=0,buffer=Buffer.allocUnsafe(256),out}}),bytes_default=b});import net from"net";import tls from"tls";import crypto2 from"crypto";import Stream from"stream";import{performance as performance2}from"perf_hooks";function Connection(options,queues={},{onopen=noop,onend=noop,onclose=noop}={}){let{sslnegotiation,ssl,max,user,host,port,database,parsers:parsers2,transform,onnotice,onnotify,onparameter,max_pipeline,keep_alive,backoff,target_session_attrs}=options,sent=queue_default(),id=uid++,backend={pid:null,secret:null},idleTimer=timer(end,options.idle_timeout),lifeTimer=timer(end,options.max_lifetime),connectTimer=timer(connectTimedOut,options.connect_timeout),socket=null,cancelMessage,errorResponse=null,result2=new Result,incoming=Buffer.alloc(0),needsTypes=options.fetch_types,backendParameters={},statements={},statementId=Math.random().toString(36).slice(2),statementCount=1,closedTime=0,remaining=0,hostIndex=0,retries=0,length=0,delay=0,rows=0,serverSignature=null,nextWriteTimer=null,terminated=!1,incomings=null,results=null,initial=null,ending=null,stream=null,chunk=null,ended=null,nonce=null,query=null,final=null,connection2={queue:queues.closed,idleTimer,connect(query2){initial=query2,reconnect()},terminate,execute,cancel,end,count:0,id};return queues.closed&&queues.closed.push(connection2),connection2;async function createSocket(){let x;try{x=options.socket?await Promise.resolve(options.socket(options)):new net.Socket}catch(e){error(e);return}return x.on("error",error),x.on("close",closed),x.on("drain",drain),x}async function cancel({pid,secret},resolve3,reject){try{cancelMessage=bytes_default().i32(16).i32(80877102).i32(pid).i32(secret).end(16),await connect(),socket.once("error",reject),socket.once("close",resolve3)}catch(error2){reject(error2)}}function execute(q){if(terminated)return queryError(q,Errors.connection("CONNECTION_DESTROYED",options));if(stream)return queryError(q,Errors.generic("COPY_IN_PROGRESS","You cannot execute queries during copy"));if(q.cancelled)return;try{return q.state=backend,query?sent.push(q):(query=q,query.active=!0),build(q),write(toBuffer(q))&&!q.describeFirst&&!q.cursorFn&&sent.length<max_pipeline&&(!q.options.onexecute||q.options.onexecute(connection2))}catch(error2){return sent.length===0&&write(Sync),errored(error2),!0}}function toBuffer(q){if(q.parameters.length>=65534)throw Errors.generic("MAX_PARAMETERS_EXCEEDED","Max number of parameters (65534) exceeded");return q.options.simple?bytes_default().Q().str(q.statement.string+bytes_default.N).end():q.describeFirst?Buffer.concat([describe(q),Flush]):q.prepare?q.prepared?prepared(q):Buffer.concat([describe(q),prepared(q)]):unnamed(q)}function describe(q){return Buffer.concat([Parse(q.statement.string,q.parameters,q.statement.types,q.statement.name),Describe("S",q.statement.name)])}function prepared(q){return Buffer.concat([Bind(q.parameters,q.statement.types,q.statement.name,q.cursorName),q.cursorFn?Execute("",q.cursorRows):ExecuteUnnamed])}function unnamed(q){return Buffer.concat([Parse(q.statement.string,q.parameters,q.statement.types),DescribeUnnamed,prepared(q)])}function build(q){let parameters=[],types4=[],string=stringify(q,q.strings[0],q.args[0],parameters,types4,options);!q.tagged&&q.args.forEach((x)=>handleValue(x,parameters,types4,options)),q.prepare=options.prepare&&("prepare"in q.options?q.options.prepare:!0),q.string=string,q.signature=q.prepare&&types4+string,q.onlyDescribe&&delete statements[q.signature],q.parameters=q.parameters||parameters,q.prepared=q.prepare&&q.signature in statements,q.describeFirst=q.onlyDescribe||parameters.length&&!q.prepared,q.statement=q.prepared?statements[q.signature]:{string,types:types4,name:q.prepare?statementId+statementCount++:""},typeof options.debug==="function"&&options.debug(id,string,parameters,types4)}function write(x,fn){if(chunk=chunk?Buffer.concat([chunk,x]):Buffer.from(x),fn||chunk.length>=1024)return nextWrite(fn);return nextWriteTimer===null&&(nextWriteTimer=setImmediate(nextWrite)),!0}function nextWrite(fn){let x=socket.write(chunk,fn);return nextWriteTimer!==null&&clearImmediate(nextWriteTimer),chunk=nextWriteTimer=null,x}function connectTimedOut(){errored(Errors.connection("CONNECT_TIMEOUT",options,socket)),socket.destroy()}async function secure(){if(sslnegotiation!=="direct"){if(write(SSLRequest),!await new Promise((r)=>socket.once("data",(x)=>r(x[0]===83)))&&ssl==="prefer")return connected()}let options2={socket,servername:net.isIP(socket.host)?void 0:socket.host};if(sslnegotiation==="direct")options2.ALPNProtocols=["postgresql"];if(ssl==="require"||ssl==="allow"||ssl==="prefer")options2.rejectUnauthorized=!1;else if(typeof ssl==="object")Object.assign(options2,ssl);socket.removeAllListeners(),socket=tls.connect(options2),socket.on("secureConnect",connected),socket.on("error",error),socket.on("close",closed),socket.on("drain",drain)}function drain(){!query&&onopen(connection2)}function data(x){if(incomings){if(incomings.push(x),remaining-=x.length,remaining>0)return}incoming=incomings?Buffer.concat(incomings,length-remaining):incoming.length===0?x:Buffer.concat([incoming,x],incoming.length+x.length);while(incoming.length>4){if(length=incoming.readUInt32BE(1),length>=incoming.length){remaining=length-incoming.length,incomings=[incoming];break}try{handle(incoming.subarray(0,length+1))}catch(e){query&&(query.cursorFn||query.describeFirst)&&write(Sync),errored(e)}incoming=incoming.subarray(length+1),remaining=0,incomings=null}}async function connect(){if(terminated=!1,backendParameters={},socket||(socket=await createSocket()),!socket)return;if(connectTimer.start(),options.socket)return ssl?secure():connected();if(socket.on("connect",ssl?secure:connected),options.path)return socket.connect(options.path);socket.ssl=ssl,socket.connect(port[hostIndex],host[hostIndex]),socket.host=host[hostIndex],socket.port=port[hostIndex],hostIndex=(hostIndex+1)%port.length}function reconnect(){setTimeout(connect,closedTime?Math.max(0,closedTime+delay-performance2.now()):0)}function connected(){try{statements={},needsTypes=options.fetch_types,statementId=Math.random().toString(36).slice(2),statementCount=1,lifeTimer.start(),socket.on("data",data),keep_alive&&socket.setKeepAlive&&socket.setKeepAlive(!0,1000*keep_alive);let s=StartupMessage();write(s)}catch(err){error(err)}}function error(err){if(connection2.queue===queues.connecting&&options.host[retries+1])return;errored(err);while(sent.length)queryError(sent.shift(),err)}function errored(err){stream&&(stream.destroy(err),stream=null),query&&queryError(query,err),initial&&(queryError(initial,err),initial=null)}function queryError(query2,err){if(query2.reserve)return query2.reject(err);if(!err||typeof err!=="object")err=Error(err);"query"in err||"parameters"in err||Object.defineProperties(err,{stack:{value:err.stack+query2.origin.replace(/.*\n/,`
|
|
660
660
|
`),enumerable:options.debug},query:{value:query2.string,enumerable:options.debug},parameters:{value:query2.parameters,enumerable:options.debug},args:{value:query2.args,enumerable:options.debug},types:{value:query2.statement&&query2.statement.types,enumerable:options.debug}}),query2.reject(err)}function end(){return ending||(!connection2.reserved&&onend(connection2),!connection2.reserved&&!initial&&!query&&sent.length===0?(terminate(),new Promise((r)=>socket&&socket.readyState!=="closed"?socket.once("close",r):r())):ending=new Promise((r)=>ended=r))}function terminate(){if(terminated=!0,stream||query||initial||sent.length)error(Errors.connection("CONNECTION_DESTROYED",options));if(clearImmediate(nextWriteTimer),socket)socket.removeListener("data",data),socket.removeListener("connect",connected),socket.readyState==="open"&&socket.end(bytes_default().X().end());ended&&(ended(),ending=ended=null)}async function closed(hadError){if(incoming=Buffer.alloc(0),remaining=0,incomings=null,clearImmediate(nextWriteTimer),socket.removeListener("data",data),socket.removeListener("connect",connected),idleTimer.cancel(),lifeTimer.cancel(),connectTimer.cancel(),socket.removeAllListeners(),socket=null,initial)return reconnect();!hadError&&(query||sent.length)&&error(Errors.connection("CONNECTION_CLOSED",options,socket)),closedTime=performance2.now(),hadError&&options.shared.retries++,delay=(typeof backoff==="function"?backoff(options.shared.retries):backoff)*1000,onclose(connection2,Errors.connection("CONNECTION_CLOSED",options,socket))}function handle(xs,x=xs[0]){(x===68?DataRow:x===100?CopyData:x===65?NotificationResponse:x===83?ParameterStatus:x===90?ReadyForQuery:x===67?CommandComplete:x===50?BindComplete:x===49?ParseComplete:x===116?ParameterDescription:x===84?RowDescription:x===82?Authentication:x===110?NoData:x===75?BackendKeyData:x===69?ErrorResponse:x===115?PortalSuspended:x===51?CloseComplete:x===71?CopyInResponse:x===78?NoticeResponse:x===72?CopyOutResponse:x===99?CopyDone:x===73?EmptyQueryResponse:x===86?FunctionCallResponse:x===118?NegotiateProtocolVersion:x===87?CopyBothResponse:UnknownMessage)(xs)}function DataRow(x){let index=7,length2,column,value,row=query.isRaw?Array(query.statement.columns.length):{};for(let i2=0;i2<query.statement.columns.length;i2++)column=query.statement.columns[i2],length2=x.readInt32BE(index),index+=4,value=length2===-1?null:query.isRaw===!0?x.subarray(index,index+=length2):column.parser===void 0?x.toString("utf8",index,index+=length2):column.parser.array===!0?column.parser(x.toString("utf8",index+1,index+=length2)):column.parser(x.toString("utf8",index,index+=length2)),query.isRaw?row[i2]=query.isRaw===!0?value:transform.value.from?transform.value.from(value,column):value:row[column.name]=transform.value.from?transform.value.from(value,column):value;query.forEachFn?query.forEachFn(transform.row.from?transform.row.from(row):row,result2):result2[rows++]=transform.row.from?transform.row.from(row):row}function ParameterStatus(x){let[k,v]=x.toString("utf8",5,x.length-1).split(bytes_default.N);if(backendParameters[k]=v,options.parameters[k]!==v)options.parameters[k]=v,onparameter&&onparameter(k,v)}function ReadyForQuery(x){if(query)if(errorResponse)query.retried?errored(query.retried):query.prepared&&retryRoutines.has(errorResponse.routine)?retry(query,errorResponse):errored(errorResponse);else query.resolve(results||result2);else if(errorResponse)errored(errorResponse);if(query=results=errorResponse=null,result2=new Result,connectTimer.cancel(),initial){if(target_session_attrs){if(!backendParameters.in_hot_standby||!backendParameters.default_transaction_read_only)return fetchState();else if(tryNext(target_session_attrs,backendParameters))return terminate()}if(needsTypes)return initial.reserve&&(initial=null),fetchArrayTypes();initial&&!initial.reserve&&execute(initial),options.shared.retries=retries=0,initial=null;return}while(sent.length&&(query=sent.shift())&&(query.active=!0,query.cancelled))Connection(options).cancel(query.state,query.cancelled.resolve,query.cancelled.reject);if(query)return;connection2.reserved?!connection2.reserved.release&&x[5]===73?ending?terminate():(connection2.reserved=null,onopen(connection2)):connection2.reserved():ending?terminate():onopen(connection2)}function CommandComplete(x){rows=0;for(let i2=x.length-1;i2>0;i2--){if(x[i2]===32&&x[i2+1]<58&&result2.count===null)result2.count=+x.toString("utf8",i2+1,x.length-1);if(x[i2-1]>=65){result2.command=x.toString("utf8",5,i2),result2.state=backend;break}}if(final&&(final(),final=null),result2.command==="BEGIN"&&max!==1&&!connection2.reserved)return errored(Errors.generic("UNSAFE_TRANSACTION","Only use sql.begin, sql.reserved or max: 1"));if(query.options.simple)return BindComplete();if(query.cursorFn)result2.count&&query.cursorFn(result2),write(Sync)}function ParseComplete(){query.parsing=!1}function BindComplete(){!result2.statement&&(result2.statement=query.statement),result2.columns=query.statement.columns}function ParameterDescription(x){let length2=x.readUInt16BE(5);for(let i2=0;i2<length2;++i2)!query.statement.types[i2]&&(query.statement.types[i2]=x.readUInt32BE(7+i2*4));query.prepare&&(statements[query.signature]=query.statement),query.describeFirst&&!query.onlyDescribe&&(write(prepared(query)),query.describeFirst=!1)}function RowDescription(x){if(result2.command)results=results||[result2],results.push(result2=new Result),result2.count=null,query.statement.columns=null;let length2=x.readUInt16BE(5),index=7,start;query.statement.columns=Array(length2);for(let i2=0;i2<length2;++i2){start=index;while(x[index++]!==0);let table=x.readUInt32BE(index),number=x.readUInt16BE(index+4),type2=x.readUInt32BE(index+6);query.statement.columns[i2]={name:transform.column.from?transform.column.from(x.toString("utf8",start,index-1)):x.toString("utf8",start,index-1),parser:parsers2[type2],table,number,type:type2},index+=18}if(result2.statement=query.statement,query.onlyDescribe)return query.resolve(query.statement),write(Sync)}async function Authentication(x,type2=x.readUInt32BE(5)){(type2===3?AuthenticationCleartextPassword:type2===5?AuthenticationMD5Password:type2===10?SASL:type2===11?SASLContinue:type2===12?SASLFinal:type2!==0?UnknownAuth:noop)(x,type2)}async function AuthenticationCleartextPassword(){let payload=await Pass();write(bytes_default().p().str(payload).z(1).end())}async function AuthenticationMD5Password(x){let payload="md5"+await md5(Buffer.concat([Buffer.from(await md5(await Pass()+user)),x.subarray(9)]));write(bytes_default().p().str(payload).z(1).end())}async function SASL(){nonce=(await crypto2.randomBytes(18)).toString("base64"),bytes_default().p().str("SCRAM-SHA-256"+bytes_default.N);let i2=bytes_default.i;write(bytes_default.inc(4).str("n,,n=*,r="+nonce).i32(bytes_default.i-i2-4,i2).end())}async function SASLContinue(x){let res=x.toString("utf8",9).split(",").reduce((acc,x2)=>(acc[x2[0]]=x2.slice(2),acc),{}),saltedPassword=await crypto2.pbkdf2Sync(await Pass(),Buffer.from(res.s,"base64"),parseInt(res.i),32,"sha256"),clientKey=await hmac(saltedPassword,"Client Key"),auth="n=*,r="+nonce+",r="+res.r+",s="+res.s+",i="+res.i+",c=biws,r="+res.r;serverSignature=(await hmac(await hmac(saltedPassword,"Server Key"),auth)).toString("base64");let payload="c=biws,r="+res.r+",p="+xor(clientKey,Buffer.from(await hmac(await sha256(clientKey),auth))).toString("base64");write(bytes_default().p().str(payload).end())}function SASLFinal(x){if(x.toString("utf8",9).split(bytes_default.N,1)[0].slice(2)===serverSignature)return;errored(Errors.generic("SASL_SIGNATURE_MISMATCH","The server did not return the correct signature")),socket.destroy()}function Pass(){return Promise.resolve(typeof options.pass==="function"?options.pass():options.pass)}function NoData(){if(result2.statement=query.statement,result2.statement.columns=[],query.onlyDescribe)return query.resolve(query.statement),write(Sync)}function BackendKeyData(x){backend.pid=x.readUInt32BE(5),backend.secret=x.readUInt32BE(9)}async function fetchArrayTypes(){needsTypes=!1,(await new Query([`
|
|
661
661
|
select b.oid, b.typarray
|
|
662
662
|
from pg_catalog.pg_type a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automagik/genie",
|
|
3
|
-
"version": "4.260503.
|
|
3
|
+
"version": "4.260503.7",
|
|
4
4
|
"description": "Collaborative terminal toolkit for human + AI workflows. NOTE: the npm distribution is being soft-deprecated — the canonical install is `curl -fsSL https://get.automagik.dev/genie | bash` (cosign + SLSA verified). See https://automagik.dev/genie/security/distribution-sovereignty",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genie",
|
|
3
|
-
"version": "4.260503.
|
|
3
|
+
"version": "4.260503.7",
|
|
4
4
|
"description": "Human-AI partnership for Claude Code. Share a terminal, orchestrate workers, evolve together. Brainstorm ideas, turn them into wishes, execute with /work, validate with /review, and ship as one team.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Namastex Labs"
|