aegisone 1.0.70 → 1.0.75

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
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const fs=require("node:fs"),path=require("node:path"),{aegisHome:aegisHome}=require("./credentials.js"),STORE_FILE="sessions.json",STORE_VERSION=2,MAX_MESSAGES_PER_SESSION=2e3;function storeDir(e){return e||aegisHome()}function storeFile(e){return path.join(storeDir(e),STORE_FILE)}function nextSeq(e){const t=("number"==typeof e.__seq?e.__seq:0)+1;return e.__seq=t,t}function toEpochMs(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"==typeof e&&e.trim()){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function load(e){try{const t=JSON.parse(fs.readFileSync(storeFile(e),"utf8"));if(t&&"object"==typeof t&&!Array.isArray(t))return t}catch{}return{}}function atomicWrite(e,t){fs.mkdirSync(path.dirname(e),{recursive:!0});const n=`${e}.tmp-${process.pid}`;fs.writeFileSync(n,JSON.stringify(t,null,2),{mode:384}),fs.renameSync(n,e);try{fs.chmodSync(e,384)}catch{}}const LOCK_STALE_MS=3e4,LOCK_WAIT_MS=(()=>{const e=Number(process.env.AEGIS_STORE_LOCK_WAIT_MS);return Number.isFinite(e)&&e>0?e:15e3})(),SLEEP_CELL=new Int32Array(new SharedArrayBuffer(4));function lockFile(e){return`${storeFile(e)}.lock`}function acquireLock(e){const t=lockFile(e);try{fs.mkdirSync(path.dirname(t),{recursive:!0})}catch{return!1}const n=Date.now()+LOCK_WAIT_MS,s=Math.max(200,Math.ceil(LOCK_WAIT_MS/5)+200);for(let e=0;e<s;e++)try{const e=fs.openSync(t,"wx");return fs.writeSync(e,String(process.pid)),fs.closeSync(e),!0}catch{let e=null;try{e=Date.now()-fs.statSync(t).mtimeMs}catch{continue}if(lockAbandoned(t,e)){try{fs.unlinkSync(t)}catch{}continue}if(Date.now()>=n)return!1;Atomics.wait(SLEEP_CELL,0,0,5)}return!1}function pidAlive(e){try{return process.kill(e,0),!0}catch(e){return e&&"EPERM"===e.code}}function lockAbandoned(e,t){let n=0;try{n=Number(String(fs.readFileSync(e,"utf8")).trim())}catch{n=0}return Number.isInteger(n)&&n>0?!pidAlive(n):t>3e4}function releaseLock(e){try{fs.unlinkSync(lockFile(e))}catch{}}function mutate(e,t){if(!acquireLock(e))throw new Error(`session store is locked by another writer: ${lockFile(e)} (waited ${LOCK_WAIT_MS}ms — refusing to write unlocked and overwrite it)`);try{const n=load(e),s=t(n);return save(e,n),s}finally{releaseLock(e)}}function save(e,t){atomicWrite(storeFile(e),t)}function trimMessages(e){return Array.isArray(e)?e.length<=2e3?e:e.slice(e.length-2e3):[]}function upsertSession(e,t){const n=t&&t.id;if(!n)throw new Error("session.id is required");return mutate(e,e=>{const s=e[n]||{messages:[]};e[n]={...s,...t,id:n,version:2};const r=t&&!0===t.seed,i="string"==typeof s.title&&s.title;return!0===s.named&&i?(e[n].title=s.title,e[n].named=!0):r&&i&&s.title&&(e[n].title=s.title),delete e[n].seed,!1!==t.pending&&(e[n].pending=!0),e[n].updatedAt||(e[n].updatedAt=Date.now()),e[n].seq=nextSeq(e),e[n]})}function appendMessage(e,t,n){if(!t)throw new Error("sessionId is required");return mutate(e,e=>{const s=e[t]||{id:t,messages:[]},r=Array.isArray(s.messages)?s.messages:[];return s.messages=trimMessages(r.concat(n)),s.updatedAt=Date.now(),s.pending=!0,s.seq=nextSeq(e),e[t]=s,s})}function recordExchange(e,t){const n=t||{};if(!n.sessionId)return null;const s=n.sessionId;return mutate(e,e=>{const t=e[s]||{id:s,messages:[]},r=Array.isArray(t.messages)?t.messages:[],i=n.ts||(new Date).toISOString(),o={role:"user",content:null==n.prompt?"":String(n.prompt),ts:i},a={role:"assistant",content:null==n.reply?"":String(n.reply),ts:i};return n.tokens&&(a.tokens=n.tokens),"number"==typeof n.costUsd&&(a.costUsd=n.costUsd),n.status&&(a.status=n.status),n.model&&(a.model=n.model),n.provider&&(a.provider=n.provider),n.origin&&(o.origin=n.origin,a.origin=n.origin),t.messages=trimMessages(r.concat([o,a])),t.title=t.title||String(n.prompt||"").slice(0,60),n.cwd&&(t.cwd=n.cwd),t.origin=n.origin||t.origin||"unknown",t.updatedAt=Date.now(),t.pending=!0===n.pending,t.seq=nextSeq(e),e[s]=t,t})}function setTitle(e,t,n,s){const r=String(null==n?"":n).trim().slice(0,200);if(!t||!r)return null;const i=s&&!0===s.named;return mutate(e,e=>{const n=e[t];return n?(n.title=r,i&&(n.named=!0),n.updatedAt=Date.now(),n.seq=nextSeq(e),n):null})}function listSessions(e){const t=load(e);return Object.values(t).filter(e=>e&&e.id).sort((e,t)=>(t.updatedAt||0)-(e.updatedAt||0)||(t.seq||0)-(e.seq||0))}function getSession(e,t){return load(e)[t]||null}function deleteSession(e,t){return mutate(e,e=>(delete e[t],{ok:!0}))}function markSynced(e,t,n){return mutate(e,e=>{const s=e[t];return s?(s.pending=!1,s.lastSyncedAt=Date.now(),n&&n.remoteId&&(s.remoteId=n.remoteId),s.seq=nextSeq(e),s):null})}function markPending(e,t){return mutate(e,e=>{const n=e[t];return n?(n.pending=!0,n.seq=nextSeq(e),n):null})}function listPending(e){return listSessions(e).filter(e=>!1!==e.pending)}function mergeRemoteSessions(e,t){const n=Array.isArray(t)?t:[];return n.length?mutate(e,e=>{let t=0;for(const s of n){const n=s&&(s.session_id||s.id);if(!n)continue;const r=e[n],i=toEpochMs(s.updated_at??s.updatedAt);r&&(r.pending||(r.updatedAt||0)>=i)||(e[n]={id:n,title:s.title||r&&r.title||"",messages:Array.isArray(s.messages)?s.messages:[],updatedAt:i||Date.now(),pending:!1,lastSyncedAt:Date.now(),remoteId:s.session_id||s.id,origin:s.source||r&&r.origin||"cloud",version:2},e[n].seq=nextSeq(e),t+=1)}return t}):0}function listSummaries(e,t=8){return listSessions(e).slice(0,t).map(e=>{const t=Array.isArray(e.messages)?e.messages:[],n=t.find(e=>e&&"user"===e.role);return{id:e.id,cwd:(e.cwd||"").split(/[\\/]/).filter(Boolean).pop()||"~",summary:String(e.title||n&&n.content||"").slice(0,60),time:new Date(e.updatedAt||Date.now()).toISOString(),own:!0,origin:e.origin||"unknown",messages:t.length,pending:!0===e.pending,dir:String(e.cwd||"")}})}function readTranscript(e,t){const n=getSession(e,t);return n?(Array.isArray(n.messages)?n.messages:[]).filter(e=>e&&("user"===e.role||"assistant"===e.role)).map(e=>({role:e.role,text:null==e.content?"":String(e.content)})):[]}function adopt(e,t){const n=storeFile(t);if(!(()=>{try{return fs.existsSync(n)}catch{return!1}})())return{adopted:!1,sessions:0,from:n,reason:"no legacy store"};const s=(()=>{try{const e=JSON.parse(fs.readFileSync(n,"utf8"));return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}catch{return{}}})(),r=Object.values(s).filter(e=>e&&e.id);if(!r.length)return{adopted:!1,sessions:0,from:n,reason:"legacy store empty"};let i=0;return mutate(e,e=>{for(const t of r)e[t.id]||(e[t.id]={...t,adoptedFrom:n,version:2},e[t.id].seq=nextSeq(e),i+=1);return e.__seq=Math.max(e.__seq||0,s.__seq||0),e.version=2,null}),i?{adopted:!0,sessions:i,from:n}:{adopted:!1,sessions:0,from:n,reason:"already adopted"}}function toMarkdown(e){const t=e&&(e.title||e.id)||"session",n=e&&Array.isArray(e.messages)?e.messages:[],s=[`# ${t}`,""];for(const e of n){const t=e&&e.role||"unknown",n=t.charAt(0).toUpperCase()+t.slice(1),r=e&&(e.content||e.text)||"";s.push(`## ${n}`,"",r,"")}return s.join("\n")}function toJson(e){return JSON.stringify(e,null,2)}module.exports={STORE_FILE:STORE_FILE,STORE_VERSION:2,MAX_MESSAGES_PER_SESSION:2e3,storeDir:storeDir,storeFile:storeFile,lockFile:lockFile,LOCK_STALE_MS:3e4,LOCK_WAIT_MS:LOCK_WAIT_MS,toEpochMs:toEpochMs,load:load,save:save,upsertSession:upsertSession,appendMessage:appendMessage,recordExchange:recordExchange,setTitle:setTitle,listSessions:listSessions,getSession:getSession,deleteSession:deleteSession,markSynced:markSynced,markPending:markPending,listPending:listPending,mergeRemoteSessions:mergeRemoteSessions,listSummaries:listSummaries,readTranscript:readTranscript,adopt:adopt,toMarkdown:toMarkdown,toJson:toJson};
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{aegisHome:aegisHome}=require("./credentials.js"),STORE_FILE="sessions.json",STORE_VERSION=2,MAX_MESSAGES_PER_SESSION=2e3;function storeDir(e){return e||aegisHome()}function storeFile(e){return path.join(storeDir(e),STORE_FILE)}function nextSeq(e){const t=("number"==typeof e.__seq?e.__seq:0)+1;return e.__seq=t,t}function toEpochMs(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"==typeof e&&e.trim()){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function load(e){try{const t=JSON.parse(fs.readFileSync(storeFile(e),"utf8"));if(t&&"object"==typeof t&&!Array.isArray(t))return t}catch{}return{}}function atomicWrite(e,t){fs.mkdirSync(path.dirname(e),{recursive:!0});const n=`${e}.tmp-${process.pid}`;fs.writeFileSync(n,JSON.stringify(t,null,2),{mode:384}),fs.renameSync(n,e);try{fs.chmodSync(e,384)}catch{}}const LOCK_STALE_MS=3e4,LOCK_WAIT_MS=(()=>{const e=Number(process.env.AEGIS_STORE_LOCK_WAIT_MS);return Number.isFinite(e)&&e>0?e:15e3})(),SLEEP_CELL=new Int32Array(new SharedArrayBuffer(4));function lockFile(e){return`${storeFile(e)}.lock`}function acquireLock(e){const t=lockFile(e);try{fs.mkdirSync(path.dirname(t),{recursive:!0})}catch{return!1}const n=Date.now()+LOCK_WAIT_MS,s=Math.max(200,Math.ceil(LOCK_WAIT_MS/5)+200);for(let e=0;e<s;e++)try{const e=fs.openSync(t,"wx");return fs.writeSync(e,String(process.pid)),fs.closeSync(e),!0}catch{let e=null;try{e=Date.now()-fs.statSync(t).mtimeMs}catch{continue}if(lockAbandoned(t,e)){try{fs.unlinkSync(t)}catch{}continue}if(Date.now()>=n)return!1;Atomics.wait(SLEEP_CELL,0,0,5)}return!1}function pidAlive(e){try{return process.kill(e,0),!0}catch(e){return e&&"EPERM"===e.code}}function lockAbandoned(e,t){let n=0;try{n=Number(String(fs.readFileSync(e,"utf8")).trim())}catch{n=0}return Number.isInteger(n)&&n>0?!pidAlive(n):t>3e4}function releaseLock(e){try{fs.unlinkSync(lockFile(e))}catch{}}function mutate(e,t){if(!acquireLock(e))throw new Error(`session store is locked by another writer: ${lockFile(e)} (waited ${LOCK_WAIT_MS}ms — refusing to write unlocked and overwrite it)`);try{const n=load(e),s=t(n);return save(e,n),s}finally{releaseLock(e)}}function save(e,t){atomicWrite(storeFile(e),t)}function trimMessages(e){return Array.isArray(e)?e.length<=2e3?e:e.slice(e.length-2e3):[]}function upsertSession(e,t){const n=t&&t.id;if(!n)throw new Error("session.id is required");return mutate(e,e=>{const s=e[n]||{messages:[]};e[n]={...s,...t,id:n,version:2};const r=t&&!0===t.seed,i="string"==typeof s.title&&s.title;return!0===s.named&&i?(e[n].title=s.title,e[n].named=!0):r&&i&&s.title&&(e[n].title=s.title),delete e[n].seed,!1!==t.pending&&(e[n].pending=!0),e[n].updatedAt||(e[n].updatedAt=Date.now()),e[n].seq=nextSeq(e),e[n]})}function appendMessage(e,t,n){if(!t)throw new Error("sessionId is required");return mutate(e,e=>{const s=e[t]||{id:t,messages:[]},r=Array.isArray(s.messages)?s.messages:[];return s.messages=trimMessages(r.concat(n)),s.updatedAt=Date.now(),s.pending=!0,s.seq=nextSeq(e),e[t]=s,s})}function recordExchange(e,t){const n=t||{};if(!n.sessionId)return null;const s=n.sessionId,r=null==n.reply?"":String(n.reply),i=""!==r.trim()&&"(no response)"!==r.trim();return mutate(e,e=>{if(!i&&!e[s])return null;const t=e[s]||{id:s,messages:[]},r=Array.isArray(t.messages)?t.messages:[],o=n.ts||(new Date).toISOString(),a={role:"user",content:null==n.prompt?"":String(n.prompt),ts:o},c={role:"assistant",content:null==n.reply?"":String(n.reply),ts:o};return n.tokens&&(c.tokens=n.tokens),"number"==typeof n.costUsd&&(c.costUsd=n.costUsd),n.status&&(c.status=n.status),n.model&&(c.model=n.model),n.provider&&(c.provider=n.provider),n.origin&&(a.origin=n.origin,c.origin=n.origin),t.messages=trimMessages(r.concat([a,c])),t.title=t.title||String(n.prompt||"").slice(0,60),n.cwd&&(t.cwd=n.cwd),t.origin=n.origin||t.origin||"unknown",t.updatedAt=Date.now(),t.pending=!0===n.pending,t.seq=nextSeq(e),e[s]=t,t})}function setTitle(e,t,n,s){const r=String(null==n?"":n).trim().slice(0,200);if(!t||!r)return null;const i=s&&!0===s.named;return mutate(e,e=>{const n=e[t];return n?(n.title=r,i&&(n.named=!0),n.updatedAt=Date.now(),n.seq=nextSeq(e),n):null})}function listSessions(e){const t=load(e);return Object.values(t).filter(e=>e&&e.id&&"string"==typeof e.id).sort((e,t)=>(t.updatedAt||0)-(e.updatedAt||0)||(t.seq||0)-(e.seq||0))}function getSession(e,t){return t&&t!==DELETED_KEY&&load(e)[t]||null}function deleteSession(e,t){return t?mutate(e,e=>{const n=e[t];if(!n)return{ok:!1};const s=deletedMap(e);return s[t]={at:Date.now(),remoteId:n.remoteId||null},e[DELETED_KEY]=s,nextSeq(e),delete e[t],{ok:!0}}):{ok:!1}}function markSynced(e,t,n){return mutate(e,e=>{const s=e[t];return s?(s.pending=!1,s.lastSyncedAt=Date.now(),n&&n.remoteId&&(s.remoteId=n.remoteId),s.seq=nextSeq(e),s):null})}function markPending(e,t){return mutate(e,e=>{const n=e[t];return n?(n.pending=!0,n.seq=nextSeq(e),n):null})}function listPending(e){return listSessions(e).filter(e=>!1!==e.pending)}const DELETED_KEY="__deleted";function deletedMap(e){const t=e&&e[DELETED_KEY];return t&&"object"==typeof t&&!Array.isArray(t)?t:{}}function isDeleted(e,t){return!!t&&Boolean(deletedMap(load(e))[t])}function mergeRemoteSessions(e,t){const n=Array.isArray(t)?t:[];return n.length?mutate(e,e=>{let t=0;const s=deletedMap(e);for(const r of n){const n=r&&(r.session_id||r.id);if(!n)continue;if(s[n]&&!e[n])continue;const i=e[n],o=toEpochMs(r.updated_at??r.updatedAt);i&&(i.pending||(i.updatedAt||0)>=o)||(e[n]={id:n,title:r.title||i&&i.title||"",messages:Array.isArray(r.messages)?r.messages:[],updatedAt:o||Date.now(),pending:!1,lastSyncedAt:Date.now(),remoteId:r.session_id||r.id,origin:r.source||i&&i.origin||"cloud",version:2},e[n].seq=nextSeq(e),t+=1)}return t}):0}function listSummaries(e,t=8){return listSessions(e).slice(0,t).map(e=>{const t=Array.isArray(e.messages)?e.messages:[],n=t.find(e=>e&&"user"===e.role);return{id:e.id,cwd:(e.cwd||"").split(/[\\/]/).filter(Boolean).pop()||"~",summary:String(e.title||n&&n.content||"").slice(0,60),time:new Date(e.updatedAt||Date.now()).toISOString(),own:!0,origin:e.origin||"unknown",messages:t.length,pending:!0===e.pending,dir:String(e.cwd||"")}})}function readTranscript(e,t){const n=getSession(e,t);return n?(Array.isArray(n.messages)?n.messages:[]).filter(e=>e&&("user"===e.role||"assistant"===e.role)).map(e=>({role:e.role,text:null==e.content?"":String(e.content)})):[]}function adopt(e,t){const n=storeFile(t);if(!(()=>{try{return fs.existsSync(n)}catch{return!1}})())return{adopted:!1,sessions:0,from:n,reason:"no legacy store"};const s=(()=>{try{const e=JSON.parse(fs.readFileSync(n,"utf8"));return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}catch{return{}}})(),r=Object.values(s).filter(e=>e&&e.id);if(!r.length)return{adopted:!1,sessions:0,from:n,reason:"legacy store empty"};let i=0;return mutate(e,e=>{const t=deletedMap(e);for(const s of r)e[s.id]||t[s.id]||(e[s.id]={...s,adoptedFrom:n,version:2},e[s.id].seq=nextSeq(e),i+=1);return e.__seq=Math.max(e.__seq||0,s.__seq||0),e.version=2,null}),i?{adopted:!0,sessions:i,from:n}:{adopted:!1,sessions:0,from:n,reason:"already adopted"}}function toMarkdown(e){const t=e&&(e.title||e.id)||"session",n=e&&Array.isArray(e.messages)?e.messages:[],s=[`# ${t}`,""];for(const e of n){const t=e&&e.role||"unknown",n=t.charAt(0).toUpperCase()+t.slice(1),r=e&&(e.content||e.text)||"";s.push(`## ${n}`,"",r,"")}return s.join("\n")}function toJson(e){return JSON.stringify(e,null,2)}module.exports={STORE_FILE:STORE_FILE,STORE_VERSION:2,MAX_MESSAGES_PER_SESSION:2e3,storeDir:storeDir,storeFile:storeFile,lockFile:lockFile,LOCK_STALE_MS:3e4,LOCK_WAIT_MS:LOCK_WAIT_MS,toEpochMs:toEpochMs,load:load,save:save,upsertSession:upsertSession,appendMessage:appendMessage,recordExchange:recordExchange,setTitle:setTitle,listSessions:listSessions,getSession:getSession,deleteSession:deleteSession,DELETED_KEY:DELETED_KEY,isDeleted:isDeleted,markSynced:markSynced,markPending:markPending,listPending:listPending,mergeRemoteSessions:mergeRemoteSessions,listSummaries:listSummaries,readTranscript:readTranscript,adopt:adopt,toMarkdown:toMarkdown,toJson:toJson};
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const path=require("node:path"),fs=require("node:fs"),os=require("node:os");function resolveOneModule(e,o,t){const n=t||{},r=n.exists||fs.existsSync,s=n.load||require,i=[path.join(__dirname,"..","..","..",e),path.join(__dirname,"..","..","vendor",o)];for(const e of i)if(r(e))return s(e);throw new Error(`pty-host: cannot find ${e}. Expected it beside desktop/ (repo checkout) or flattened at desktop/vendor/${o} (published package) — run \`node one/scripts/predist.mjs --flat-only\` if this is a source checkout.`)}function loadSeam(e){const o=e||{};return{protocol:o.protocol||resolveOneModule("one/src/protocol.js","protocol.js",o),pty:o.pty||resolveOneModule("one/src/iface/pty.js","pty.js",o)}}function isDirectory(e){try{return fs.statSync(e).isDirectory()}catch{return!1}}function resolveCwd(e){const o=e||{},t=o.env||process.env,n="function"==typeof o.homedir?o.homedir():o.homedir||os.homedir(),r="function"==typeof o.isDirectory?o.isDirectory:isDirectory,s="string"==typeof o.cwd?o.cwd:process.cwd(),i=String(null==t.AEGIS_WORKSPACE?"":t.AEGIS_WORKSPACE).trim();if(i){const e=path.resolve(n,i);if(r(e))return e}return s&&path.resolve(s)!==path.resolve(path.parse(s).root)&&r(s)?s:n}function probeNodePty(e){const o=e||require;try{return o("node-pty")}catch{return null}}function createPtyHost(e){const o=e||{},{protocol:t,pty:n}=loadSeam(o),r=o.cliFace||require("./cli-face.js"),s=Boolean(o.nativePty),i=n.plan({nativePty:s}),c=new Map;function u(e){return c.get(e)||null}return{hello:function(e){const o=[t.CAPS.EXEC,t.CAPS.EVENT,t.CAPS.CANCEL,...n.caps(i)];return t.ok(e,{proto:t.PROTO,caps:o})},exec:function(e,s,u){const d=s||{},l="function"==typeof u?u:()=>{},a=r.innerCommand(o.appInfo||{});if(!a.ok)return t.err(e,"no_spawn",a.reason);const p=n.spawn(i,{argv:[a.exec,...a.args],env:a.env,cwd:resolveCwd({env:o.env,homedir:o.homedir,cwd:o.cwd,isDirectory:o.isDirectory}),cols:d.cols,rows:d.rows},{spawnPty:o.spawnPty});if(!p.ok)return t.err(e,p.code,p.msg);const f=p.handle;return c.set(e,f),"function"==typeof f.onData&&f.onData(o=>l(t.request(e,"event",{kind:"data",chunk:o}))),"function"==typeof f.onExit&&f.onExit(o=>{c.delete(e),l(t.request(e,"event",{kind:"exit",exitCode:o&&"number"==typeof o.exitCode?o.exitCode:null,signal:o&&o.signal||null}))}),t.ok(e,{kind:p.kind})},write:function(e,o){const r=u(e);return r&&"function"==typeof r.write?(r.write(String(null==o?"":o)),t.ok(e,{})):t.err(e,n.CODE.NO_SPAWN,"no session for this id")},resize:function(e,o,r){const s=u(e);return s&&"function"==typeof s.resize?(s.resize(o,r),t.ok(e,{})):t.err(e,n.CODE.NO_SPAWN,"no session for this id")},cancel:function(e){const o=u(e);return o?("function"==typeof o.kill&&o.kill(),c.delete(e),t.ok(e,{})):t.err(e,t.CODE.UNSUPPORTED,"no session for this id")},sessionCount:function(){return c.size}}}module.exports={createPtyHost:createPtyHost,probeNodePty:probeNodePty,resolveOneModule:resolveOneModule,resolveCwd:resolveCwd};
3
+ "use strict";const path=require("node:path"),fs=require("node:fs"),os=require("node:os");function resolveOneModule(e,o,t){const n=t||{},r=n.exists||fs.existsSync,s=n.load||require,i=[path.join(__dirname,"..","..","..",e),path.join(__dirname,"..","..","vendor",o)];for(const e of i)if(r(e))return s(e);throw new Error(`pty-host: cannot find ${e}. Expected it beside desktop/ (repo checkout) or flattened at desktop/vendor/${o} (published package) — run \`node one/scripts/predist.mjs --flat-only\` if this is a source checkout.`)}function loadSeam(e){const o=e||{};return{protocol:o.protocol||resolveOneModule("one/src/protocol.js","protocol.js",o),pty:o.pty||resolveOneModule("one/src/iface/pty.js","pty.js",o)}}function isDirectory(e){try{return fs.statSync(e).isDirectory()}catch{return!1}}function resolveCwd(e){const o=e||{},t=o.env||process.env,n="function"==typeof o.homedir?o.homedir():o.homedir||os.homedir(),r="function"==typeof o.isDirectory?o.isDirectory:isDirectory,s="string"==typeof o.cwd?o.cwd:process.cwd(),i=String(null==t.AEGIS_WORKSPACE?"":t.AEGIS_WORKSPACE).trim();if(i){const e=path.resolve(n,i);if(r(e))return e}return s&&path.resolve(s)!==path.resolve(path.parse(s).root)&&r(s)?s:n}function probeNodePty(e){const o=e||require;try{return o("node-pty")}catch{return null}}function createPtyHost(e){const o=e||{},{protocol:t,pty:n}=loadSeam(o),r=o.cliFace||require("./cli-face.js"),s=Boolean(o.nativePty),i=n.plan({nativePty:s}),c=new Map;function a(e){return c.get(e)||null}return{hello:function(e){const o=[t.CAPS.EXEC,t.CAPS.EVENT,t.CAPS.CANCEL,...n.caps(i)];return t.ok(e,{proto:t.PROTO,caps:o})},exec:function(e,s,a){const u=s||{},d="function"==typeof a?a:()=>{},l="string"==typeof u.cliSessionId&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(u.cliSessionId)?u.cliSessionId:"",f=o.appInfo||{},p=r.innerCommand(l?{...f,args:[...Array.isArray(f.args)?f.args:[],"--session-id",l]}:f);if(!p.ok)return t.err(e,"no_spawn",p.reason);const y=n.spawn(i,{argv:[p.exec,...p.args],env:p.env,cwd:resolveCwd({env:o.env,homedir:o.homedir,cwd:o.cwd,isDirectory:o.isDirectory}),cols:u.cols,rows:u.rows},{spawnPty:o.spawnPty});if(!y.ok)return t.err(e,y.code,y.msg);const h=y.handle;return c.set(e,h),"function"==typeof h.onData&&h.onData(o=>d(t.request(e,"event",{kind:"data",chunk:o}))),"function"==typeof h.onExit&&h.onExit(o=>{c.delete(e),d(t.request(e,"event",{kind:"exit",exitCode:o&&"number"==typeof o.exitCode?o.exitCode:null,signal:o&&o.signal||null}))}),t.ok(e,{kind:y.kind})},write:function(e,o){const r=a(e);return r&&"function"==typeof r.write?(r.write(String(null==o?"":o)),t.ok(e,{})):t.err(e,n.CODE.NO_SPAWN,"no session for this id")},resize:function(e,o,r){const s=a(e);return s&&"function"==typeof s.resize?(s.resize(o,r),t.ok(e,{})):t.err(e,n.CODE.NO_SPAWN,"no session for this id")},cancel:function(e){const o=a(e);return o?("function"==typeof o.kill&&o.kill(),c.delete(e),t.ok(e,{})):t.err(e,t.CODE.UNSUPPORTED,"no session for this id")},sessionCount:function(){return c.size}}}module.exports={createPtyHost:createPtyHost,probeNodePty:probeNodePty,resolveOneModule:resolveOneModule,resolveCwd:resolveCwd};
@@ -2,7 +2,7 @@
2
2
  "name": "aegis-desktop",
3
3
  "productName": "aegis one",
4
4
  "desktopName": "aegis-desktop",
5
- "version": "1.0.62",
5
+ "version": "1.0.67",
6
6
  "description": "Thin Electron host for AEGIS — a local chat UI over the shared client/aegis.js transport. Ships transport + UI only; engine logic stays server-side.",
7
7
  "author": {
8
8
  "name": "AEGIS Code",