aegisone 1.0.39 → 1.0.41

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.
Files changed (122) hide show
  1. package/LICENSING.md +186 -0
  2. package/README.md +2 -2
  3. package/bin/aegis.js +1 -1
  4. package/package.json +3 -2
  5. package/scripts/predist.mjs +1 -1
  6. package/src/child.js +1 -1
  7. package/src/permissions.js +1 -1
  8. package/vendor/cli/package.json +4 -2
  9. package/vendor/cli/src/app.js +1 -1
  10. package/vendor/cli/src/chatflow.js +1 -1
  11. package/vendor/cli/src/commands.js +3 -1
  12. package/vendor/cli/src/config.js +1 -1
  13. package/vendor/cli/src/diff.js +1 -1
  14. package/vendor/cli/src/diffview.js +1 -1
  15. package/vendor/cli/src/engine.js +1 -1
  16. package/vendor/cli/src/history.js +1 -1
  17. package/vendor/cli/src/models.js +1 -1
  18. package/vendor/cli/src/overlays.js +1 -1
  19. package/vendor/cli/src/panels.js +1 -1
  20. package/vendor/cli/vendor/client/brain-catalog.js +1 -1
  21. package/vendor/cli/vendor/client/byok-catalog.js +1 -1
  22. package/vendor/cli/vendor/client/credits.js +45 -0
  23. package/vendor/cli/vendor/client/foreign-sessions.js +3 -0
  24. package/vendor/cli/vendor/client/naming.js +1 -1
  25. package/vendor/cli/vendor/client/prefs.js +1 -1
  26. package/vendor/cli/vendor/client/session-search.js +3 -0
  27. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1
  28. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -1
  29. package/vendor/cli/vendor/desktop/lib/local/integrity.js +42 -2
  30. package/vendor/cli/vendor/desktop/lib/local/perm-rules.js +206 -0
  31. package/vendor/cli/vendor/desktop/lib/local/perm-store.js +298 -0
  32. package/vendor/cli/vendor/desktop/lib/local/perm-write.js +199 -0
  33. package/vendor/cli/vendor/desktop/lib/local/pro-sessions.js +3 -0
  34. package/vendor/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +242 -0
  35. package/vendor/cli/vendor/desktop/lib/local/sandbox-bwrap.js +316 -0
  36. package/vendor/cli/vendor/desktop/lib/local/sandbox-seatbelt.js +380 -0
  37. package/vendor/cli/vendor/desktop/lib/local/sandbox.js +493 -0
  38. package/vendor/cli/vendor/desktop/lib/local/shell.js +155 -20
  39. package/vendor/cli/vendor/desktop/lib/local/tools.js +29 -4
  40. package/vendor/cli/vendor/desktop/lib/settings.js +1 -1
  41. package/vendor/cli/vendor/desktop/main.js +774 -37
  42. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1
  43. package/vendor/cli/vendor/mcp/admission.js +3 -0
  44. package/vendor/cli/vendor/mcp/server.js +1 -1
  45. package/vendor/cli/vendor/one/src/child.js +1 -1
  46. package/vendor/cli/vendor/one/src/permissions.js +1 -1
  47. package/vendor/desktop/bin/aegis.js +1 -1
  48. package/vendor/desktop/lib/local/claude-pro.js +1 -1
  49. package/vendor/desktop/lib/local/engine.js +1 -1
  50. package/vendor/desktop/lib/local/integrity.js +42 -2
  51. package/vendor/desktop/lib/local/perm-rules.js +206 -0
  52. package/vendor/desktop/lib/local/perm-store.js +298 -0
  53. package/vendor/desktop/lib/local/perm-write.js +199 -0
  54. package/vendor/desktop/lib/local/pro-sessions.js +3 -0
  55. package/vendor/desktop/lib/local/sandbox-appcontainer.js +242 -0
  56. package/vendor/desktop/lib/local/sandbox-bwrap.js +316 -0
  57. package/vendor/desktop/lib/local/sandbox-seatbelt.js +380 -0
  58. package/vendor/desktop/lib/local/sandbox.js +493 -0
  59. package/vendor/desktop/lib/local/shell.js +155 -20
  60. package/vendor/desktop/lib/local/tools.js +29 -4
  61. package/vendor/desktop/lib/settings.js +1 -1
  62. package/vendor/desktop/lib/sync/memory-store.js +3 -0
  63. package/vendor/desktop/main.js +774 -37
  64. package/vendor/desktop/package.json +19 -7
  65. package/vendor/desktop/preload.js +1 -1
  66. package/vendor/desktop/renderer/app.js +5 -1
  67. package/vendor/desktop/renderer/diff.js +1 -1
  68. package/vendor/desktop/renderer/diffview.js +1 -1
  69. package/vendor/desktop/renderer/index.html +221 -5
  70. package/vendor/desktop/renderer/provider-mark.js +1 -1
  71. package/vendor/desktop/renderer/provider-toolbar.js +1 -1
  72. package/vendor/desktop/renderer/providers.js +1 -1
  73. package/vendor/desktop/renderer/style.css +223 -6
  74. package/vendor/desktop/renderer/usage.js +1 -1
  75. package/vendor/desktop/vendor/brain-catalog.js +1 -1
  76. package/vendor/desktop/vendor/byok-catalog.js +1 -1
  77. package/vendor/desktop/vendor/credits.js +45 -0
  78. package/vendor/desktop/vendor/faces/cli/package.json +3 -2
  79. package/vendor/desktop/vendor/faces/cli/src/app.js +1 -1
  80. package/vendor/desktop/vendor/faces/cli/src/chatflow.js +1 -1
  81. package/vendor/desktop/vendor/faces/cli/src/commands.js +3 -1
  82. package/vendor/desktop/vendor/faces/cli/src/config.js +1 -1
  83. package/vendor/desktop/vendor/faces/cli/src/diff.js +1 -1
  84. package/vendor/desktop/vendor/faces/cli/src/diffview.js +1 -1
  85. package/vendor/desktop/vendor/faces/cli/src/engine.js +1 -1
  86. package/vendor/desktop/vendor/faces/cli/src/history.js +1 -1
  87. package/vendor/desktop/vendor/faces/cli/src/models.js +1 -1
  88. package/vendor/desktop/vendor/faces/cli/src/overlays.js +1 -1
  89. package/vendor/desktop/vendor/faces/cli/src/panels.js +1 -1
  90. package/vendor/desktop/vendor/faces/cli/vendor/client/brain-catalog.js +1 -1
  91. package/vendor/desktop/vendor/faces/cli/vendor/client/byok-catalog.js +1 -1
  92. package/vendor/desktop/vendor/faces/cli/vendor/client/credits.js +45 -0
  93. package/vendor/desktop/vendor/faces/cli/vendor/client/foreign-sessions.js +3 -0
  94. package/vendor/desktop/vendor/faces/cli/vendor/client/naming.js +1 -1
  95. package/vendor/desktop/vendor/faces/cli/vendor/client/prefs.js +1 -1
  96. package/vendor/desktop/vendor/faces/cli/vendor/client/session-search.js +3 -0
  97. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/claude-pro.js +1 -1
  98. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/engine.js +1 -1
  99. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/integrity.js +1 -1
  100. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/perm-rules.js +3 -0
  101. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/perm-store.js +3 -0
  102. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/perm-write.js +3 -0
  103. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/pro-sessions.js +3 -0
  104. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +3 -0
  105. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-bwrap.js +3 -0
  106. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-seatbelt.js +3 -0
  107. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox.js +3 -0
  108. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/shell.js +1 -1
  109. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/tools.js +1 -1
  110. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/settings.js +1 -1
  111. package/vendor/desktop/vendor/faces/cli/vendor/desktop/main.js +4 -2
  112. package/vendor/desktop/vendor/faces/cli/vendor/desktop/renderer/usage.js +1 -1
  113. package/vendor/desktop/vendor/faces/cli/vendor/mcp/admission.js +3 -0
  114. package/vendor/desktop/vendor/faces/cli/vendor/mcp/server.js +1 -1
  115. package/vendor/desktop/vendor/faces/cli/vendor/one/src/child.js +1 -1
  116. package/vendor/desktop/vendor/faces/cli/vendor/one/src/permissions.js +1 -1
  117. package/vendor/desktop/vendor/foreign-sessions.js +3 -0
  118. package/vendor/desktop/vendor/naming.js +1 -1
  119. package/vendor/desktop/vendor/prefs.js +1 -1
  120. package/vendor/desktop/vendor/sandbox/provenance.json +20 -0
  121. package/vendor/desktop/vendor/sandbox/x64-linux/bwrap +0 -0
  122. package/vendor/desktop/vendor/session-search.js +3 -0
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  // SPDX-License-Identifier: AGPL-3.0-or-later
3
3
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
4
- "use strict";const{createClient:createClient}=require("../client/aegis.js"),credentials=require("../client/credentials.js"),{autoProvisionApiKey:autoProvisionApiKey}=require("../client/auto-provision.js"),{createTools:createTools}=require("./tools.js");try{const e=require("../client/env-file.js").loadEnvFile();e.loose&&process.stderr.write(`aegis: ${e.file} is readable by other accounts (mode ${e.mode.toString(8)}) — consider \`chmod 600\` on it.\n`)}catch{}const aegis=createClient(credentials.clientOptions()),{TOOLS:TOOLS,toolList:toolList}=createTools(aegis),API_BASE=aegis.apiBase,SERVER_NAME="aegis",SERVER_VERSION="0.4.0";function missingKeyText(){const{path:e}=credentials.keyStatus();return["No AEGIS API key is configured for this session.","","Set one with any of:"," • `aegiscode login` in a terminal (saves it to "+e+", mode 0600)"," • export AEGIS_API_KEY=… in the environment Claude Code was launched from"," • put `AEGIS_API_KEY=…` in ~/.aegiscode/.env (read at startup, every host)","","Then restart Claude Code. Get a key at https://aegiscloud.org."].join("\n")}let provisionAttempted=!1;async function ensureApiKey(){if(aegis.apiKey||provisionAttempted)return;provisionAttempted=!0;const e=await autoProvisionApiKey(aegis,credentials,{app:"mcp"});e.error?process.stderr.write(`aegis: device auto-registration failed (${e.error.message}) — falling back to manual setup.\n`):e.key?process.stderr.write("aegis: no API key was configured — auto-provisioned a free AEGIS account"+(e.ok?` (key saved to ${credentials.keyStatus().path}).\n`:" (could not save it — see above).\n")+`Fund it at ${aegis.promptUrl("topup","device_autoprovision")} or set your own BYOK key with aegis_byok_set.\n`):process.stderr.write("aegis: device auto-registration returned no usable key — falling back to manual setup.\n")}function send(e){process.stdout.write(JSON.stringify(e)+"\n")}function reply(e,t){send({jsonrpc:"2.0",id:e,result:t})}function replyError(e,t,i){send({jsonrpc:"2.0",id:e,error:{code:t,message:i}})}let pending=0,stdinClosed=!1;function maybeExit(){stdinClosed&&0===pending&&process.exit(0)}async function handleMessage(e){const{id:t,method:i,params:o}=e,r=null==t;try{switch(i){case"initialize":return void reply(t,{protocolVersion:o&&o.protocolVersion||"2024-11-05",capabilities:{tools:{}},serverInfo:{name:"aegis",version:"0.4.0"}});case"notifications/initialized":case"notifications/cancelled":return;case"ping":return void(r||reply(t,{}));case"tools/list":return void reply(t,{tools:toolList()});case"tools/call":{const i=o&&o.name,r=TOOLS[i];if(!r)return void reply(t,{content:[{type:"text",text:`Unknown tool: ${i}`}],isError:!0});if(aegis.apiKey||await ensureApiKey(),!aegis.apiKey)return void reply(t,{content:[{type:"text",text:missingKeyText()}],isError:!0});try{reply(t,{content:[{type:"text",text:await r.run(o&&o.arguments||{})}],isError:!1})}catch(e){reply(t,{content:[{type:"text",text:`AEGIS error: ${e.message}`}],isError:!0})}return}default:return void(r||replyError(t,-32601,`Method not found: ${i}`))}}catch(e){r||replyError(t,-32603,e.message)}}let buffer="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(e=>{let t;for(buffer+=e;-1!==(t=buffer.indexOf("\n"));){const e=buffer.slice(0,t).trim();if(buffer=buffer.slice(t+1),!e)continue;let i;try{i=JSON.parse(e)}catch{continue}pending++,Promise.resolve(handleMessage(i)).finally((()=>{pending--,maybeExit()}))}})),process.stdin.on("end",(()=>{stdinClosed=!0,maybeExit()}));
4
+ "use strict";const{createClient:createClient}=require("../client/aegis.js"),credentials=require("../client/credentials.js"),{autoProvisionApiKey:autoProvisionApiKey}=require("../client/auto-provision.js"),{createTools:createTools}=require("./tools.js"),admission=require("./admission.js");try{const e=require("../client/env-file.js").loadEnvFile();e.loose&&process.stderr.write(`aegis: ${e.file} is readable by other accounts (mode ${e.mode.toString(8)}) — consider \`chmod 600\` on it.\n`)}catch{}const aegis=createClient(credentials.clientOptions()),{TOOLS:TOOLS,toolList:toolList}=createTools(aegis),API_BASE=aegis.apiBase,SERVER_NAME="aegis",SERVER_VERSION="0.4.0";function missingKeyText(){const{path:e}=credentials.keyStatus();return["No AEGIS API key is configured for this session.","","Set one with any of:"," • `aegiscode login` in a terminal (saves it to "+e+", mode 0600)"," • export AEGIS_API_KEY=… in the environment Claude Code was launched from"," • put `AEGIS_API_KEY=…` in ~/.aegiscode/.env (read at startup, every host)","","Then restart Claude Code. Get a key at https://aegiscloud.org."].join("\n")}let provisionAttempted=!1;async function ensureApiKey(){if(aegis.apiKey||provisionAttempted)return;provisionAttempted=!0;const e=await autoProvisionApiKey(aegis,credentials,{app:"mcp"});e.error?process.stderr.write(`aegis: device auto-registration failed (${e.error.message}) — falling back to manual setup.\n`):e.key?process.stderr.write("aegis: no API key was configured — auto-provisioned a free AEGIS account"+(e.ok?` (key saved to ${credentials.keyStatus().path}).\n`:" (could not save it — see above).\n")+`Fund it at ${aegis.promptUrl("topup","device_autoprovision")} or set your own BYOK key with aegis_byok_set.\n`):process.stderr.write("aegis: device auto-registration returned no usable key — falling back to manual setup.\n")}function send(e){process.stdout.write(JSON.stringify(e)+"\n")}function reply(e,t){send({jsonrpc:"2.0",id:e,result:t})}function replyError(e,t,i){send({jsonrpc:"2.0",id:e,error:{code:t,message:i}})}let caller={ok:!0,name:"unknown",reason:""},pending=0,stdinClosed=!1;function maybeExit(){stdinClosed&&0===pending&&process.exit(0)}async function handleMessage(e){const{id:t,method:i,params:r}=e,o=null==t;try{switch(i){case"initialize":{const e=r&&r.clientInfo||null;return caller=admission.admit(e),caller.ok?admission.record(e):process.stderr.write(`${caller.reason}\n`),void reply(t,{protocolVersion:r&&r.protocolVersion||"2024-11-05",capabilities:{tools:{}},serverInfo:{name:"aegis",version:"0.4.0"}})}case"notifications/initialized":case"notifications/cancelled":return;case"ping":return void(o||reply(t,{}));case"tools/list":return void reply(t,{tools:toolList()});case"tools/call":{if(!caller.ok)return void reply(t,{content:[{type:"text",text:caller.reason}],isError:!0});const i=r&&r.name,o=TOOLS[i];if(!o)return void reply(t,{content:[{type:"text",text:`Unknown tool: ${i}`}],isError:!0});if(aegis.apiKey||await ensureApiKey(),!aegis.apiKey)return void reply(t,{content:[{type:"text",text:missingKeyText()}],isError:!0});try{reply(t,{content:[{type:"text",text:await o.run(r&&r.arguments||{})}],isError:!1})}catch(e){reply(t,{content:[{type:"text",text:`AEGIS error: ${e.message}`}],isError:!0})}return}default:return void(o||replyError(t,-32601,`Method not found: ${i}`))}}catch(e){o||replyError(t,-32603,e.message)}}let buffer="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(e=>{let t;for(buffer+=e;-1!==(t=buffer.indexOf("\n"));){const e=buffer.slice(0,t).trim();if(buffer=buffer.slice(t+1),!e)continue;let i;try{i=JSON.parse(e)}catch{continue}pending++,Promise.resolve(handleMessage(i)).finally((()=>{pending--,maybeExit()}))}})),process.stdin.on("end",(()=>{stdinClosed=!0,maybeExit()}));
@@ -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 FLAGS=Object.freeze({headlessSkip:"--dangerously-skip-permissions",interactiveSkip:"--allow-dangerously-skip-permissions",permissionMode:"--permission-mode",allowedTools:"--allowedTools",disallowedTools:"--disallowedTools",print:"-p",outputFormat:"--output-format",model:"--model",sessionId:"--session-id",resume:"--resume",addDir:"--add-dir"});function addDirArgs(e){const s=[];for(const o of unique(e))s.push(`${FLAGS.addDir}=${o}`);return s}const UUID_RE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,DEFAULT_OUTPUT_FORMAT="stream-json";function unique(e){const s=new Set,o=[];for(const i of Array.isArray(e)?e:[]){const e=String(i).trim();e&&!s.has(e)&&(s.add(e),o.push(e))}return o}function claudeArgv(e={}){const s=e.posture;if(!s||"object"!=typeof s)throw new Error("claudeArgv requires a resolved posture record (one/src/permissions.js resolvePosture)");const o=s.childKind,i="interactive"!==o,{PERMISSION_MODES:r}=require("./permissions.js"),n=void 0!==e.permissionMode&&null!==e.permissionMode,d=n?String(e.permissionMode):null;if(n&&!r.includes(d))throw new Error(`--permission-mode ${JSON.stringify(d)} is not one of ${r.join("|")} — refusing to pass (or to silently drop) a mode the child does not accept.`);const t=s.rules||{},l=unique(t.allow),a=unique(t.deny),u=unique(t.ask),p=e.resumeSessionId?String(e.resumeSessionId).trim():"",c=e.sessionId?String(e.sessionId).trim():"",m=p||null,h=!m&&c?c:null;for(const[e,s]of[["resumeSessionId",m],["sessionId",h]])if(s&&!UUID_RE.test(s))throw new Error(`${e} ${JSON.stringify(s)} is not a UUID — refusing to pass it to --resume/--session-id, which the child rejects after the spawn (turning a continuity bug into an opaque failed turn).`);const f=[];i&&f.push(FLAGS.print,FLAGS.outputFormat,String(e.outputFormat||"stream-json")),e.model&&f.push(FLAGS.model,String(e.model));const g=addDirArgs(e.addDir);f.push(...g),l.length&&f.push(FLAGS.allowedTools,l.join(",")),a.length&&f.push(FLAGS.disallowedTools,a.join(",")),n&&f.push(FLAGS.permissionMode,d),s.child&&s.child.flag&&f.push(s.child.flag),m?f.push(FLAGS.resume,m):h&&f.push(FLAGS.sessionId,h),Array.isArray(e.extra)&&f.push(...e.extra.map(String)),void 0!==e.prompt&&null!==e.prompt&&f.push(String(e.prompt));const S=Object.freeze({kind:o,permissionMode:d,permissionModePassed:n,skip:Boolean(s.child&&s.child.skip),skipFlag:s.child&&s.child.flag||null,allowedTools:Object.freeze(l),disallowedTools:Object.freeze(a),unmappedAsk:Object.freeze(u),addDir:Object.freeze(g.map((e=>e.slice(FLAGS.addDir.length+1)))),resumeSessionId:m,sessionId:h,argv:Object.freeze(f.slice())});return{argv:S.argv,record:S}}function childRecordLine(e){if(!e||"object"!=typeof e)return null;const s=e.permissionModePassed?`${FLAGS.permissionMode}=${e.permissionMode}`:"no --permission-mode (none was set)";return`aegis: claude child [${e.kind}] ${e.skipFlag||"no permission flag"} · ${s} · allowedTools=[${e.allowedTools.join(", ")}] disallowedTools=[${e.disallowedTools.join(", ")}]`+(e.unmappedAsk.length?` (ask rules recorded, unmapped: ${e.unmappedAsk.join(", ")})`:"")+(e.addDir&&e.addDir.length?` · addDir=[${e.addDir.join(", ")}]`:"")+(e.resumeSessionId?` · resumed session ${e.resumeSessionId}`:e.sessionId?` · new session ${e.sessionId}`:" · no session id (each turn is a new conversation)")}module.exports={FLAGS:FLAGS,DEFAULT_OUTPUT_FORMAT:"stream-json",claudeArgv:claudeArgv,addDirArgs:addDirArgs,childRecordLine:childRecordLine};
3
+ "use strict";const FLAGS=Object.freeze({headlessSkip:"--dangerously-skip-permissions",interactiveSkip:"--allow-dangerously-skip-permissions",permissionMode:"--permission-mode",allowedTools:"--allowedTools",disallowedTools:"--disallowedTools",print:"-p",outputFormat:"--output-format",model:"--model",sessionId:"--session-id",resume:"--resume",inputFormat:"--input-format",permissionPromptTool:"--permission-prompt-tool",addDir:"--add-dir"});function addDirArgs(e){const s=[];for(const o of unique(e))s.push(`${FLAGS.addDir}=${o}`);return s}const UUID_RE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,DEFAULT_OUTPUT_FORMAT="stream-json";function unique(e){const s=new Set,o=[];for(const i of Array.isArray(e)?e:[]){const e=String(i).trim();e&&!s.has(e)&&(s.add(e),o.push(e))}return o}function claudeArgv(e={}){const s=e.posture;if(!s||"object"!=typeof s)throw new Error("claudeArgv requires a resolved posture record (one/src/permissions.js resolvePosture)");const o=s.childKind,i="interactive"!==o,{PERMISSION_MODES:r}=require("./permissions.js"),n=s.child&&"string"==typeof s.child.permissionMode?s.child.permissionMode:null,d=void 0!==e.permissionMode&&null!==e.permissionMode?String(e.permissionMode):null,t=null!==d||null!==n,l=null!==d?d:n;if(t&&!r.includes(l))throw new Error(`--permission-mode ${JSON.stringify(l)} is not one of ${r.join("|")} — refusing to pass (or to silently drop) a mode the child does not accept.`);const a=s.rules||{},p=unique(a.allow),u=unique(a.deny),c=unique(a.ask),m=e.resumeSessionId?String(e.resumeSessionId).trim():"",h=e.sessionId?String(e.sessionId).trim():"",g=m||null,f=!g&&h?h:null;for(const[e,s]of[["resumeSessionId",g],["sessionId",f]])if(s&&!UUID_RE.test(s))throw new Error(`${e} ${JSON.stringify(s)} is not a UUID — refusing to pass it to --resume/--session-id, which the child rejects after the spawn (turning a continuity bug into an opaque failed turn).`);const S=!0===e.askBridge&&!(s.child&&s.child.skip),A=[];i&&A.push(FLAGS.print,FLAGS.outputFormat,String(e.outputFormat||"stream-json")),e.model&&A.push(FLAGS.model,String(e.model));const F=addDirArgs(e.addDir);A.push(...F),p.length&&A.push(FLAGS.allowedTools,p.join(",")),u.length&&A.push(FLAGS.disallowedTools,u.join(",")),t&&A.push(FLAGS.permissionMode,l),s.child&&s.child.flag&&A.push(s.child.flag),S&&A.push(FLAGS.inputFormat,"stream-json",FLAGS.permissionPromptTool,"stdio"),g?A.push(FLAGS.resume,g):f&&A.push(FLAGS.sessionId,f),Array.isArray(e.extra)&&A.push(...e.extra.map(String)),S||void 0===e.prompt||null===e.prompt||A.push(String(e.prompt));const w=Object.freeze({kind:o,permissionMode:l,permissionModePassed:t,permissionModeSource:t?null!==d?"descriptor":"posture":null,permissionModeDropped:s&&s.permissionModeDropped||null,skip:Boolean(s.child&&s.child.skip),skipFlag:s.child&&s.child.flag||null,allowedTools:Object.freeze(p),disallowedTools:Object.freeze(u),unmappedAsk:Object.freeze(c),addDir:Object.freeze(F.map((e=>e.slice(FLAGS.addDir.length+1)))),resumeSessionId:g,sessionId:f,askBridge:S,argv:Object.freeze(A.slice())});return{argv:w.argv,record:w}}function childRecordLine(e){if(!e||"object"!=typeof e)return null;const s=e.permissionModePassed?`${FLAGS.permissionMode}=${e.permissionMode}`:e.permissionModeDropped?`no --permission-mode (asked for one, dropped: ${e.permissionModeDropped})`:"no --permission-mode (none was set)";return`aegis: claude child [${e.kind}] ${e.skipFlag||"no permission flag"} · ${s} · allowedTools=[${e.allowedTools.join(", ")}] disallowedTools=[${e.disallowedTools.join(", ")}]`+(e.unmappedAsk.length?` (ask rules recorded, unmapped: ${e.unmappedAsk.join(", ")})`:"")+(e.addDir&&e.addDir.length?` · addDir=[${e.addDir.join(", ")}]`:"")+(e.resumeSessionId?` · resumed session ${e.resumeSessionId}`:e.sessionId?` · new session ${e.sessionId}`:" · no session id (each turn is a new conversation)")+(e.askBridge?" · ask bridge (the child can raise approval cards)":" · no ask bridge (headless: unapproved tools auto-deny)")}module.exports={FLAGS:FLAGS,DEFAULT_OUTPUT_FORMAT:"stream-json",claudeArgv:claudeArgv,addDirArgs:addDirArgs,childRecordLine:childRecordLine};
@@ -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"),CHILD_KINDS=Object.freeze({HEADLESS:"headless",INTERACTIVE:"interactive"}),CONFIGURABLE_CLASSES=Object.freeze(["exec","writeFile","editFile"]),SKIP_FLAG="--dangerously-skip-permissions",FROZEN_CLASSES=Object.freeze(["write","shell","network","offDevice"]),PERMISSION_MODES=Object.freeze(["acceptEdits","auto","bypassPermissions","manual","dontAsk","plan"]);let cachedEvaluator=null,cachedConfig=null;function loadEvaluator(e){if(e)return e;if(cachedEvaluator)return cachedEvaluator;const o=[path.join(__dirname,"..","..","cli","src","permissions.js"),path.join(__dirname,"..","vendor","cli","src","permissions.js"),path.join(__dirname,"..","..","..","src","permissions.js")];for(const e of o)try{const o=require(e);if(o&&"function"==typeof o.evalPermission&&"function"==typeof o.resolveSkip)return cachedEvaluator=o,o}catch{}throw new Error("aegis: the one rule evaluator (cli/src/permissions.js) is missing from this install — refusing to resolve a permission posture from a second, unshared rule engine.")}function loadConfigStore(e){if(e)return e;if(cachedConfig)return cachedConfig;const o=[path.join(__dirname,"..","..","cli","src","config.js"),path.join(__dirname,"..","vendor","cli","src","config.js"),path.join(__dirname,"..","..","..","src","config.js")];for(const e of o)try{const o=require(e);if(o&&"function"==typeof o.confirmPosture)return cachedConfig=o,o}catch{}return null}function storedPermissionFacts(e={}){const o=loadConfigStore(e.config);if(!o)return{confirmationsOn:void 0,rules:void 0,source:"unavailable"};try{const e=o.confirmPosture();let r;try{r=o.loadPermissions()}catch{r=void 0}return{confirmationsOn:e&&"boolean"==typeof e.enabled?e.enabled:void 0,rules:r,source:e&&e.source||"unavailable"}}catch{return{confirmationsOn:void 0,rules:void 0,source:"unavailable"}}}function normalizeRules(e){const o=e&&"object"==typeof e?e:{},r=e=>Array.isArray(e)?e.map(String):[];return Object.freeze({defaultMode:"allow"===o.defaultMode||"deny"===o.defaultMode?o.defaultMode:"ask",allow:Object.freeze(r(o.allow)),deny:Object.freeze(r(o.deny)),ask:Object.freeze(r(o.ask)),explicitAsk:!0===o.explicitAsk||"ask"===o.defaultMode})}function resolvePosture(e={},o={}){const r=loadEvaluator(o.evaluator),s=normalizeRules(e.rules),i=!0===e.interactive,n=e.childKind===CHILD_KINDS.INTERACTIVE?CHILD_KINDS.INTERACTIVE:CHILD_KINDS.HEADLESS,a=r.resolveSkip({flag:!0===e.flag,env:e.env,interactive:i}),t=!1===e.gate,l=a.skip||t,c=a.skip?a.source:t?"posture":a.source,u=n===CHILD_KINDS.INTERACTIVE;return Object.freeze({version:1,rules:s,interactive:i,childKind:n,skip:l,skipSource:c,skipFromFlag:a.skip,envVarSet:a.envSet,storedGate:void 0===e.gate||null===e.gate?null:Boolean(e.gate),warned:a.warned,warning:a.warning||null,skipped:Object.freeze(l?CONFIGURABLE_CLASSES:[]),frozen:FROZEN_CLASSES,child:Object.freeze({kind:n,skip:l,flag:l?u?"--allow-dangerously-skip-permissions":"--dangerously-skip-permissions":null,why:l?u?"the interactive variant offers the bypass as an option (the child still asks; a human is there)":"the headless variant takes the bypass as a default, because no one can answer the child's prompt":"no skip was asked for, so no permission flag is passed to the child"})})}function gateFor(e,o,r,s={}){const i=loadEvaluator(s.evaluator),n=e&&e.rules?e.rules:normalizeRules({}),a=i.evalPermission(o,r,n);return"deny"===a?"deny":"allow"===a||e&&e.skip?"allow":"ask"}function skipReport(e){if(!e||!e.skip)return null;const o=e.child.flag?`; the ${e.child.kind} Claude child is passed ${e.child.flag}`:"";return`aegis: ${"posture"===e.skipSource?"automode (the stored confirmation posture both faces share)":"--dangerously-skip-permissions"} (via ${e.skipSource}) — skipping the configurable confirmation gates (${CONFIGURABLE_CLASSES.join(", ")})${o}. NOT skipped, and not reachable by any setting, flag or env var: the ÆGIS covenant pre-action assert and the ${FROZEN_CLASSES.join("|")} approvals (always 'ask'), plus any explicit deny rule.`}module.exports={CHILD_KINDS:CHILD_KINDS,CONFIGURABLE_CLASSES:CONFIGURABLE_CLASSES,FROZEN_CLASSES:FROZEN_CLASSES,PERMISSION_MODES:PERMISSION_MODES,SKIP_FLAG:SKIP_FLAG,loadEvaluator:loadEvaluator,loadConfigStore:loadConfigStore,storedPermissionFacts:storedPermissionFacts,normalizeRules:normalizeRules,resolvePosture:resolvePosture,gateFor:gateFor,skipReport:skipReport};
3
+ "use strict";const path=require("node:path"),CHILD_KINDS=Object.freeze({HEADLESS:"headless",INTERACTIVE:"interactive"}),CONFIGURABLE_CLASSES=Object.freeze(["exec","writeFile","editFile"]),SKIP_FLAG="--dangerously-skip-permissions",FROZEN_CLASSES=Object.freeze(["write","shell","network","offDevice"]),PERMISSION_MODES=Object.freeze(["acceptEdits","auto","bypassPermissions","manual","dontAsk","plan"]);let cachedEvaluator=null,cachedConfig=null;function loadEvaluator(e){if(e)return e;if(cachedEvaluator)return cachedEvaluator;const o=[path.join(__dirname,"..","..","cli","src","permissions.js"),path.join(__dirname,"..","vendor","cli","src","permissions.js"),path.join(__dirname,"..","..","..","src","permissions.js")];for(const e of o)try{const o=require(e);if(o&&"function"==typeof o.evalPermission&&"function"==typeof o.resolveSkip)return cachedEvaluator=o,o}catch{}throw new Error("aegis: the one rule evaluator (cli/src/permissions.js) is missing from this install — refusing to resolve a permission posture from a second, unshared rule engine.")}function loadConfigStore(e){if(e)return e;if(cachedConfig)return cachedConfig;const o=[path.join(__dirname,"..","..","cli","src","config.js"),path.join(__dirname,"..","vendor","cli","src","config.js"),path.join(__dirname,"..","..","..","src","config.js")];for(const e of o)try{const o=require(e);if(o&&"function"==typeof o.confirmPosture)return cachedConfig=o,o}catch{}return null}function storedPermissionFacts(e={}){const o=loadConfigStore(e.config);if(!o)return{confirmationsOn:void 0,rules:void 0,permissionMode:null,source:"unavailable"};try{const e=o.confirmPosture();let s;try{s=o.loadPermissions()}catch{s=void 0}let i=null;try{if("function"==typeof o.permissionMode){const e=o.permissionMode();"string"==typeof e&&PERMISSION_MODES.includes(e)&&(i=e)}}catch{i=null}return{confirmationsOn:e&&"boolean"==typeof e.enabled?e.enabled:void 0,rules:s,permissionMode:i,source:e&&e.source||"unavailable"}}catch{return{confirmationsOn:void 0,rules:void 0,permissionMode:null,source:"unavailable"}}}function normalizeRules(e){const o=e&&"object"==typeof e?e:{},s=e=>Array.isArray(e)?e.map(String):[];return Object.freeze({defaultMode:"allow"===o.defaultMode||"deny"===o.defaultMode?o.defaultMode:"ask",allow:Object.freeze(s(o.allow)),deny:Object.freeze(s(o.deny)),ask:Object.freeze(s(o.ask)),explicitAsk:!0===o.explicitAsk||"ask"===o.defaultMode})}function resolvePosture(e={},o={}){const s=loadEvaluator(o.evaluator),i=normalizeRules(e.rules),n=!0===e.interactive,r=e.childKind===CHILD_KINDS.INTERACTIVE?CHILD_KINDS.INTERACTIVE:CHILD_KINDS.HEADLESS,t=s.resolveSkip({flag:!0===e.flag,env:e.env,interactive:n}),a=!1===e.gate,l=t.skip||a,c=t.skip?t.source:a?"posture":t.source,u="string"==typeof e.permissionMode?e.permissionMode:null,d=null!==u&&PERMISSION_MODES.includes(u),p=d&&!l?u:null,f=null!==u&&!p,S=r===CHILD_KINDS.INTERACTIVE;return Object.freeze({version:1,rules:i,interactive:n,childKind:r,skip:l,skipSource:c,skipFromFlag:t.skip,envVarSet:t.envSet,storedGate:void 0===e.gate||null===e.gate?null:Boolean(e.gate),permissionMode:p,permissionModeAsked:d?u:null,permissionModeDropped:f?l?"a skip is in effect (--dangerously-skip-permissions or the stored posture), and the child may not be given two permission policies":"not one of "+PERMISSION_MODES.join("|"):null,warned:t.warned,warning:t.warning||null,skipped:Object.freeze(l?CONFIGURABLE_CLASSES:[]),frozen:FROZEN_CLASSES,child:Object.freeze({kind:r,skip:l,permissionMode:p,flag:l?S?"--allow-dangerously-skip-permissions":"--dangerously-skip-permissions":null,why:l?S?"the interactive variant offers the bypass as an option (the child still asks; a human is there)":"the headless variant takes the bypass as a default, because no one can answer the child's prompt":"no skip was asked for, so no permission flag is passed to the child"})})}function gateFor(e,o,s,i={}){const n=loadEvaluator(i.evaluator),r=e&&e.rules?e.rules:normalizeRules({}),t=n.evalPermission(o,s,r);return"deny"===t?"deny":"allow"===t||e&&e.skip?"allow":"ask"}function skipReport(e){if(!e||!e.skip)return null;const o=e.child.flag?`; the ${e.child.kind} Claude child is passed ${e.child.flag}`:"";return`aegis: ${"posture"===e.skipSource?"automode (the stored confirmation posture both faces share)":"--dangerously-skip-permissions"} (via ${e.skipSource}) — skipping the configurable confirmation gates (${CONFIGURABLE_CLASSES.join(", ")})${o}. NOT skipped, and not reachable by any setting, flag or env var: the ÆGIS covenant pre-action assert and the ${FROZEN_CLASSES.join("|")} approvals (always 'ask'), plus any explicit deny rule.`}module.exports={CHILD_KINDS:CHILD_KINDS,CONFIGURABLE_CLASSES:CONFIGURABLE_CLASSES,FROZEN_CLASSES:FROZEN_CLASSES,PERMISSION_MODES:PERMISSION_MODES,SKIP_FLAG:SKIP_FLAG,loadEvaluator:loadEvaluator,loadConfigStore:loadConfigStore,storedPermissionFacts:storedPermissionFacts,normalizeRules:normalizeRules,resolvePosture:resolvePosture,gateFor:gateFor,skipReport:skipReport};
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),os=require("node:os"),crypto=require("node:crypto");let DatabaseSync=null;try{DatabaseSync=require("node:sqlite").DatabaseSync}catch{DatabaseSync=null}const DEFAULTS={minMessages:2,minChars:2,maxCharsPerMessage:8e3,maxMessagesPerSession:400,maxSessionsPerSource:200,maxFilesPerSource:600,maxFileBytes:33554432,maxTotalMessages:2e4},NOISE=[/^<command-name>/i,/^<local-command-stdout>/i,/^<local-command-caveat>/i,/^<environment_context>/i,/^<user_instructions>/i,/^\[Request interrupted by user/i,/^Caveat: The messages below were generated by the user while running local commands/i,/^(ok|okay|yes|no|yep|nope|sure|thanks|thank you|continue|proceed|go on|done)[.!]?$/i],layout=require("./foreign-memory.js")._internal,platformOf=layout.platformOf,appRoots=layout.appRoots;function homeDir(e){return e||os.homedir()}function isDir(e){try{return fs.statSync(e).isDirectory()}catch{return!1}}function isFile(e){try{return fs.statSync(e).isFile()}catch{return!1}}function fileSize(e){try{return fs.statSync(e).size}catch{return 0}}function fileMtime(e){try{return fs.statSync(e).mtimeMs}catch{return Date.now()}}function stableId(...e){return`imp-${crypto.createHash("sha1").update(e.join("|")).digest("hex").slice(0,16)}`}function cleanText(e){return"string"!=typeof e?"":e.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g," ").replace(/\s+/g," ").trim()}function isNoise(e){return!e||NOISE.some((t=>t.test(e)))}function readJsonl(e){const t=[];let s;try{s=fs.readFileSync(e,"utf8")}catch{return t}for(const e of s.split("\n")){const s=e.trim();if(s)try{t.push(JSON.parse(s))}catch{}}return t}function walkFiles(e,{ext:t,limit:s}){const n=[],o=[e];for(;o.length&&n.length<s;){const e=o.pop();let i;try{i=fs.readdirSync(e,{withFileTypes:!0})}catch{continue}for(const r of i){if(n.length>=s)break;if(r.isSymbolicLink())continue;const i=path.join(e,r.name);if(r.isDirectory()){if("node_modules"===r.name||".git"===r.name)continue;o.push(i)}else if(r.isFile()){if(t&&!t.some((e=>r.name.endsWith(e))))continue;n.push(i)}}}return n}function textFromClaudeMessage(e){if(!e)return"";const t=null!=e.content?e.content:e;return"string"==typeof t?cleanText(t):Array.isArray(t)?cleanText(t.filter((e=>e&&"text"===e.type&&"string"==typeof e.text)).map((e=>e.text)).join("\n")):""}function extractClaudeSession(e,t){const s=readJsonl(e),n=[];let o="",i="",r="",a="",c="";for(const e of s){if(!e||"object"!=typeof e)continue;if(e.sessionId&&!c&&(c=e.sessionId),e.cwd&&!i&&(i=e.cwd),"summary"===e.type&&"string"==typeof e.summary&&!o){o=cleanText(e.summary);continue}const s="user"===e.type?"user":"assistant"===e.type?"assistant":null;if(!s)continue;if(!0===e.isSidechain)continue;const l=textFromClaudeMessage(e.message);isNoise(l)||(n.push({role:s,content:l.slice(0,t.maxCharsPerMessage)}),!r&&e.timestamp&&(r=e.timestamp),e.timestamp&&(a=e.timestamp))}return finishSession({file:e,messages:n,title:o,cwd:i,foreignId:c,first:r,last:a,opts:t})}function extractCodexSession(e,t){const s=readJsonl(e),n=[];let o="",i="",r="",a="";const c=(e,s)=>{isNoise(s)||n.push({role:e,content:s.slice(0,t.maxCharsPerMessage)})};for(const e of s){if(!e||"object"!=typeof e)continue;const t=e.payload&&"object"==typeof e.payload?e.payload:null,s=e.timestamp||t&&t.timestamp||"";if("session_meta"===e.type&&t)t.id&&!a&&(a=String(t.id)),t.cwd&&!o&&(o=String(t.cwd)),s&&!i&&(i=s);else if("response_item"===e.type&&t&&"message"===t.type){const e=t.role;if("user"!==e&&"assistant"!==e)continue;c(e,cleanText((Array.isArray(t.content)?t.content:[]).filter((e=>e&&("input_text"===e.type||"output_text"===e.type||"text"===e.type))).map((e=>e.text)).filter((e=>"string"==typeof e)).join("\n"))),s&&(r=s)}else"event_msg"===e.type&&t&&("user_message"===t.type?c("user",cleanText(t.message)):"agent_message"===t.type&&c("assistant",cleanText(t.message)),s&&(r=s))}return finishSession({file:e,messages:n,title:"",cwd:o,foreignId:a,first:i,last:r,opts:t})}function extractGenericSession(e,t){const s=readJsonl(e),n=[];let o="",i="",r="",a="";for(const e of s){if(!e||"object"!=typeof e)continue;const s=e.role||e.message&&e.message.role;if("user"!==s&&"assistant"!==s)continue;const c=null!=e.content?e.content:e.message&&e.message.content,l=cleanText("string"==typeof c?c:textFromClaudeMessage({content:c}));if(isNoise(l))continue;n.push({role:s,content:l.slice(0,t.maxCharsPerMessage)});const u=e.timestamp||e.created_at||e.createdAt||"";u&&!o&&(o=u),u&&(i=u),a||"string"!=typeof e.cwd||(a=e.cwd),r||"string"!=typeof e.title||(r=cleanText(e.title))}return finishSession({file:e,messages:n,title:r,cwd:a,foreignId:"",first:o,last:i,opts:t})}function extractJsonSessions(e,t){if(fileSize(e)>t.maxFileBytes)return[];let s;try{s=JSON.parse(fs.readFileSync(e,"utf8"))}catch{return[]}if(!s||"object"!=typeof s)return[];const n=Array.isArray(s)?s:Array.isArray(s.sessions)?s.sessions:Array.isArray(s.conversations)?s.conversations:Array.isArray(s.chats)?s.chats:Array.isArray(s.threads)?s.threads:null;if(!n)return[];const o=[];for(const[s,i]of n.entries()){if(!i||"object"!=typeof i)continue;const n=Array.isArray(i.messages)?i.messages:Array.isArray(i.conversation)?i.conversation:Array.isArray(i.turns)?i.turns:[],r=[];for(const e of n){if(!e||"object"!=typeof e)continue;const s="assistant"===e.role?"assistant":"user"===e.role?"user":null;if(!s)continue;const n=null!=e.content?e.content:e.text,o=cleanText("string"==typeof n?n:textFromClaudeMessage({content:n}));isNoise(o)||r.push({role:s,content:o.slice(0,t.maxCharsPerMessage)})}const a=finishSession({file:`${e}#${s}`,messages:r,title:cleanText(i.title||i.name||""),cwd:"string"==typeof i.cwd?i.cwd:"",foreignId:i.id||i.sessionId||i.uuid||"",first:i.createdAt||i.created_at||"",last:i.updatedAt||i.updated_at||"",opts:t});a&&o.push(a)}return o}function finishSession({file:e,messages:t,title:s,cwd:n,foreignId:o,first:i,last:r,opts:a}){const c=t.slice(0,a.maxMessagesPerSession);if(c.length<a.minMessages)return null;const l=c.find((e=>"user"===e.role));if(!l)return null;const u=(e,t)=>{const s=Date.parse(e);return Number.isFinite(s)?s:t},d=fileMtime(e.split("#")[0]);return{file:e,foreignId:o?String(o):path.basename(e).replace(/\.(jsonl|json)$/i,""),title:s||cleanText(l.content).slice(0,60)||path.basename(path.dirname(e))||"imported session",cwd:n||"",messages:c,createdAt:u(i,d),updatedAt:u(r,d)}}function extractJsonSessionDoc(e,t){if(fileSize(e)>t.maxFileBytes)return[];let s;try{s=JSON.parse(fs.readFileSync(e,"utf8"))}catch{return[]}if(!s||"object"!=typeof s)return[];const n=Array.isArray(s.messages)?s.messages:Array.isArray(s.conversation)?s.conversation:Array.isArray(s.turns)?s.turns:null;if(!n)return[];const o=[];for(const e of n){if(!e||"object"!=typeof e)continue;const s=e.role||e.type||e.author,n="assistant"===s||"model"===s||"gemini"===s||"ai"===s?"assistant":"user"===s||"human"===s?"user":null;if(!n)continue;const i=null!=e.content?e.content:e.text,r=cleanText("string"==typeof i?i:textFromClaudeMessage({content:i}));isNoise(r)||o.push({role:n,content:r.slice(0,t.maxCharsPerMessage)})}const i=finishSession({file:e,messages:o,title:cleanText(s.title||s.name||""),cwd:"string"==typeof s.cwd?s.cwd:"",foreignId:s.id||s.sessionId||path.basename(e).replace(/\.json$/i,""),first:s.createdAt||s.created_at||s.startTime||"",last:s.updatedAt||s.updated_at||s.endTime||"",opts:t});return i?[i]:[]}function openReadOnlyDb(e){if(!DatabaseSync)return null;try{return new DatabaseSync(e,{readOnly:!0})}catch{return null}}function extractOpencodeDb(e,t){const s=openReadOnlyDb(e);if(!s)return[];try{const n=s.prepare("SELECT id, title, directory, time_created, time_updated FROM session").all(),o=[];for(const i of n){const n=s.prepare("SELECT id, data FROM message WHERE session_id = ? ORDER BY time_created, id").all(i.id),r=[];for(const e of n){let n;try{n=JSON.parse(e.data)}catch{continue}const o=n&&"assistant"===n.role?"assistant":n&&"user"===n.role?"user":null;if(!o)continue;const i=cleanText(s.prepare("SELECT data FROM part WHERE message_id = ? ORDER BY time_created, id").all(e.id).map((e=>{try{const t=JSON.parse(e.data);return t&&"text"===t.type&&"string"==typeof t.text?t.text:""}catch{return""}})).filter(Boolean).join("\n"));isNoise(i)||r.push({role:o,content:i.slice(0,t.maxCharsPerMessage)})}const a=finishSession({file:`${e}#${i.id}`,messages:r,title:cleanText(i.title||""),cwd:"string"==typeof i.directory?i.directory:"",foreignId:i.id,first:i.time_created?new Date(i.time_created).toISOString():"",last:i.time_updated?new Date(i.time_updated).toISOString():"",opts:t});a&&o.push(a)}return o}finally{s.close()}}function extractCodexThreadHistoryDb(e,t){const s=openReadOnlyDb(e);if(!s)return[];try{const n=s.prepare("SELECT thread_id, item_type, item_json, created_at_ms FROM thread_items WHERE item_type IN ('userMessage','agentMessage','assistantMessage') ORDER BY thread_id, rollout_ordinal").all(),o=new Map;for(const e of n)o.has(e.thread_id)||o.set(e.thread_id,[]),o.get(e.thread_id).push(e);const i=[];for(const[s,n]of o){const o=[];let r="",a="";for(const e of n){let s;try{s=JSON.parse(e.item_json)}catch{continue}const n="userMessage"===e.item_type?"user":"assistant",i=cleanText((Array.isArray(s&&s.content)?s.content:[]).filter((e=>e&&"text"===e.type&&"string"==typeof e.text)).map((e=>e.text)).join("\n"));if(isNoise(i))continue;o.push({role:n,content:i.slice(0,t.maxCharsPerMessage)});const c=e.created_at_ms?new Date(e.created_at_ms).toISOString():"";c&&!r&&(r=c),c&&(a=c)}const c=finishSession({file:`${e}#${s}`,messages:o,title:"",cwd:"",foreignId:s,first:r,last:a,opts:t});c&&i.push(c)}return i}finally{s.close()}}const SQLITE_EXTRACTORS={opencode:extractOpencodeDb,codex:extractCodexThreadHistoryDb},SOURCES=[{id:"claude-code",label:"Claude Code",verified:!0,roots:e=>[path.join(e,".claude","projects")],extract:{".jsonl":extractClaudeSession}},{id:"claude-desktop",label:"Claude Desktop",verified:!1,roots:(e,t)=>appRoots(e,t,"Claude",{macSupport:!0}),extract:{".jsonl":extractClaudeSession,".json":extractJsonSessions}},{id:"codex",label:"OpenAI Codex CLI",verified:!0,roots:e=>[path.join(e,".codex","sessions")],sqlite:e=>[path.join(e,".codex","thread_history_1.sqlite"),path.join(e,".codex","history_1.sqlite")],extract:{".jsonl":extractCodexSession}},{id:"gemini-cli",label:"Gemini CLI",verified:!1,roots:e=>[path.join(e,".gemini","tmp")],extract:{".json":extractJsonSessionDoc,".jsonl":extractGenericSession}},{id:"opencode",label:"opencode",verified:!1,roots:(e,t)=>[...appRoots(e,t,"opencode",{data:!0}),path.join(e,".local","share","opencode")],sqlite:e=>[path.join(e,".local","share","opencode","opencode.db")],extract:{".json":extractJsonSessions,".jsonl":extractGenericSession}},{id:"cursor",label:"Cursor",verified:!1,roots:(e,t)=>[path.join(e,".cursor"),...appRoots(e,t,"Cursor",{macSupport:!0})],sqlite:(e,t)=>{const s="darwin"===t?path.join(e,"Library","Application Support","Cursor"):null,n=appRoots(e,t,"Cursor",{macSupport:!0})[0]||path.join(e,".cursor");return[s?path.join(s,"User","globalStorage","state.vscdb"):path.join(n,"User","globalStorage","state.vscdb")]},extract:{}},{id:"windsurf",label:"Windsurf / Codeium",verified:!1,roots:(e,t)=>[path.join(e,".windsurf"),path.join(e,".codeium"),...appRoots(e,t,"Windsurf",{config:!1,macSupport:!0})],extract:{".json":extractJsonSessions,".jsonl":extractGenericSession}},{id:"continue",label:"Continue",verified:!1,roots:e=>[path.join(e,".continue")],extract:{".json":extractJsonSessions,".jsonl":extractGenericSession}},{id:"goose",label:"Goose",verified:!1,roots:(e,t)=>appRoots(e,t,"goose",{data:!0}),sqlite:(e,t)=>appRoots(e,t,"goose",{data:!0}).map((e=>path.join(e,"sessions.db"))),extract:{".json":extractJsonSessions,".jsonl":extractGenericSession}},{id:"zed",label:"Zed",verified:!1,roots:(e,t)=>appRoots(e,t,"zed"),sqlite:(e,t)=>appRoots(e,t,"zed").flatMap((e=>[path.join(e,"threads","threads.db"),path.join(e,"conversations","conversations.db")])),extract:{}},{id:"kimi-code",label:"Kimi Code",verified:!1,roots:e=>[path.join(e,".kimi-code","sessions"),path.join(e,".kimi-code","history")],extract:{".jsonl":extractGenericSession,".json":extractJsonSessionDoc}},{id:"aegiscodex",label:"AEGIS Codex engine",verified:!0,roots:e=>[path.join(e,".aegiscodex","sessions"),path.join(e,".aegiscodex","history")],extract:{".jsonl":extractGenericSession,".json":extractJsonSessionDoc}}];function sourceById(e){return SOURCES.find((t=>t.id===e))||null}function listSources(e,t){const s=homeDir(e),n=platformOf(t);return SOURCES.map((e=>{const t=e.roots(s,n).filter(isDir),o=(e.sqlite?e.sqlite(s,n):[]).filter(isFile),i=o.length>0&&"function"==typeof SQLITE_EXTRACTORS[e.id];return{id:e.id,label:e.label,verified:e.verified,roots:t,databases:o,present:t.length>0||o.length>0,readable:t.length>0||i}}))}function suffixOf(e){const t=e.lastIndexOf("*");return-1===t?e:e.slice(t+1)}function extractorFor(e,t){for(const[s,n]of Object.entries(e))if(t.endsWith(suffixOf(s)))return n;return null}function scan(e={}){const t=homeDir(e.home),s=platformOf(e.platform),n=null!=e.maxSessionsPerSource?e.maxSessionsPerSource:DEFAULTS.maxSessionsPerSource,o=null!=e.limit?e.limit:1/0,i=e.sources&&e.sources.length?new Set(e.sources):null,r={minMessages:null!=e.minMessages?e.minMessages:DEFAULTS.minMessages,minChars:null!=e.minChars?e.minChars:DEFAULTS.minChars,maxCharsPerMessage:null!=e.maxCharsPerMessage?e.maxCharsPerMessage:DEFAULTS.maxCharsPerMessage,maxMessagesPerSession:null!=e.maxMessagesPerSession?e.maxMessagesPerSession:DEFAULTS.maxMessagesPerSession,maxFileBytes:null!=e.maxFileBytes?e.maxFileBytes:DEFAULTS.maxFileBytes},a=[],c=[],l=new Set;let u=0;for(const e of SOURCES){if(i&&!i.has(e.id))continue;const d=e.roots(t,s).filter(isDir),f=(e.sqlite?e.sqlite(t,s):[]).filter(isFile),p=d.length>0||f.length>0,m=Object.keys(e.extract).map(suffixOf),h=SQLITE_EXTRACTORS[e.id],g={id:e.id,label:e.label,verified:e.verified,present:p,roots:d,databases:f,files:0,scanned:0,count:0,skipped:0,unreadable:p&&!m.length&&!(f.length&&h),messages:0};if(!p){a.push(g);continue}const y=t=>{if(t.messages.length<r.minMessages)return void(g.skipped+=1);if(u+t.messages.length>DEFAULTS.maxTotalMessages)return!1;const s=stableId(e.id,t.foreignId||t.file,t.title);if(!l.has(s))return l.add(s),u+=t.messages.length,g.scanned+=1,g.count+=1,g.messages+=t.messages.length,c.push({id:s,source:e.id,sourceLabel:e.label,title:t.title,cwd:t.cwd,createdAt:t.createdAt,updatedAt:t.updatedAt,messages:t.messages,file:t.file}),!0;g.skipped+=1};if(m.length){const t=[];for(const e of d)t.push(...walkFiles(e,{ext:m,limit:DEFAULTS.maxFilesPerSource}));for(const s of t){if(g.count>=n||c.length>=o)break;if(fileSize(s)>r.maxFileBytes){g.skipped+=1;continue}const t=extractorFor(e.extract,s);if(!t)continue;let i;g.files+=1;try{i=t(s,r)}catch{g.skipped+=1;continue}const a=Array.isArray(i)?i:i?[i]:[];if(a.length)for(const e of a){if(g.count>=n||c.length>=o)break;if(!1===y(e))break}else g.skipped+=1}}if(f.length&&h)for(const e of f){if(g.count>=n||c.length>=o)break;let t;try{t=h(e,r)}catch{g.skipped+=1;continue}const s=Array.isArray(t)?t:t?[t]:[];if(g.files+=1,s.length)for(const e of s){if(g.count>=n||c.length>=o)break;if(!1===y(e))break}else g.skipped+=1}a.push(g)}return{sessions:c,sources:a,totals:{sessions:c.length,sourcesPresent:a.filter((e=>e.present)).length,sourcesWithSessions:a.filter((e=>e.count>0)).length,sourcesUnreadable:a.filter((e=>e.unreadable)).length,files:a.reduce(((e,t)=>e+t.files),0),messages:u,skipped:a.reduce(((e,t)=>e+t.skipped),0)},scannedAt:(new Date).toISOString()}}function toRecord(e,{pending:t=!1}={}){const s=(Array.isArray(e.messages)?e.messages:[]).map(((t,s)=>({role:"assistant"===t.role?"assistant":"user",content:String(null==t.content?"":t.content),at:0===s?e.createdAt||e.updatedAt||Date.now():void 0})));for(const e of s)null==e.at&&delete e.at;return{id:e.id,title:e.title||"imported session",messages:s,createdAt:e.createdAt||e.updatedAt||Date.now(),updatedAt:e.updatedAt||e.createdAt||Date.now(),origin:`import:${e.source}`,importedFrom:{source:e.source,label:e.sourceLabel,file:e.file,at:(new Date).toISOString()},pending:!0===t}}function chunk(e,t=50){const s=[];for(let n=0;n<e.length;n+=t)s.push(e.slice(n,n+t));return s}function describe(e){const t=(e.sources||[]).filter((e=>e.present));if(!t.length)return"No other AI tool sessions found on this machine.";const s=t.map((e=>{if(e.unreadable)return` ${e.label}: found, but its store is a database this version cannot read`;const t=e.verified?"":" (best-effort layout)";return` ${e.label}${t}: ${e.count} session(s) from ${e.files} file(s), ${e.skipped} skipped`}));return[`Found ${e.totals.sessions} importable session(s) across ${e.totals.sourcesWithSessions} source(s):`,...s].join("\n")}module.exports={DEFAULTS:DEFAULTS,SOURCES:SOURCES,scan:scan,listSources:listSources,describe:describe,chunk:chunk,toRecord:toRecord,stableId:stableId,sourceById:sourceById,_internal:{walkFiles:walkFiles,readJsonl:readJsonl,cleanText:cleanText,isNoise:isNoise,finishSession:finishSession,extractClaudeSession:extractClaudeSession,extractCodexSession:extractCodexSession,extractGenericSession:extractGenericSession,extractJsonSessions:extractJsonSessions,extractJsonSessionDoc:extractJsonSessionDoc,extractorFor:extractorFor,suffixOf:suffixOf,platformOf:platformOf,appRoots:appRoots}};
@@ -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 GENERIC_TITLE="New conversation",TITLE_SYSTEM='You name conversations. Write a short descriptive title (2 to 6 words) that captures the topic of the conversation. Never repeat the user\'s words verbatim — if the message is just a greeting or has no clear topic, name it something like "New conversation". Sentence case, no quotes, no markdown, no trailing punctuation, no explanation.',isGenericTitle=e=>!e||String(e).trim().toLowerCase()===GENERIC_TITLE.toLowerCase(),GREETINGS=new Set(["hey","heey","heyy","heyyy","hi","hii","hello","hej","hejj","yo","sup","hola","howdy","hai","heyo","hiya","wassup","greetings","namaste","ahoy","hallo"]);function isTopicless(e){const t=String(e).trim().toLowerCase().replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim();if(!t)return!0;const i=t.split(" ");return!!/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(t)||i.length<=2&&t.length<=12&&GREETINGS.has(i[0])}function looksLikeEcho(e,t){const i=e=>String(e).toLowerCase().replace(/[^a-z0-9\s]/g,"").replace(/\s+/g," ").trim(),n=i(e),o=i(t);if(!n||!o)return!1;if(n===o)return!0;if(o.length<=14&&(n.startsWith(o)||o.startsWith(n)))return!0;if(o.length<=24){const i=e=>new Set((String(e).toLowerCase().match(/[a-z0-9]+/g)||[]).filter((e=>!ECHO_STOP.has(e)))),n=i(e),o=i(t);if(n.size&&n.size===o.size&&[...n].every((e=>o.has(e))))return!0}return!1}const ECHO_STOP=new Set(["the","a","an","to","of","in","on","at","for","and","or","is","are","be","it","its","my","our","please","can","you","just","do","that","this"]);function cleanTitle(e){return String(null==e?"":e).replace(/\s+/g," ").trim().replace(/["'`“”‘’]/g,"").replace(/[*_#]/g,"").replace(/^\s*(?:title|name)\s*[:\-–]\s*/i,"").replace(/[.\s]+$/g,"").slice(0,60).trim()}const titlePromptOf=e=>`Write a short title for a conversation that begins with: "${String(e).slice(0,500)}"`,FILLER=/^(?:please|pls|plz|hey|hi|hello|ok(?:ay)?|so|now|just|also|and|then|maybe|well|um|uh|can you|could you|would you|will you|i want you to|i want to|i need you to|i need to|i'?d like you to|i would like you to|i'?d like to|help me|help|let'?s|lets|go ahead and)\b[\s,:;-]*/i,TRAILING_STOP=new Set(["the","a","an","in","on","at","to","for","of","and","or","with","is","are","my","our","this","that","please","can","you","could","would","i","we","just","do","it"]);function deriveTitle(e){let t=String(null==e?"":e).trim().replace(/\s+/g," ");if(!t)return GENERIC_TITLE;for(let e=0;e<6;e++){const e=t.replace(FILLER,"").trim();if(e===t)break;t=e}const i=t.split(" ").filter(Boolean);if(!i.length)return GENERIC_TITLE;const n=i.slice(0,6);for(;n.length>2&&TRAILING_STOP.has(n[n.length-1].toLowerCase().replace(/[^a-z0-9]/g,""));)n.pop();let o=n.join(" ").replace(/[.,!?;:]+$/,"").trim();return o?(o=o[0].toUpperCase()+o.slice(1),o.slice(0,60).trim()||GENERIC_TITLE):GENERIC_TITLE}async function nameConversation(e,{callModel:t,signal:i}={}){const n=null==e?"":String(e);if(!n.trim())return"";if(isTopicless(n))return GENERIC_TITLE;if(!("function"!=typeof t||i&&i.aborted)){let e=null;try{e=await t(titlePromptOf(n),{system:TITLE_SYSTEM,signal:i,naming:!0})}catch{e=null}const o=cleanTitle(e);if(o)return looksLikeEcho(o,n)?GENERIC_TITLE:o}return deriveTitle(n)}async function refineTitle(e,t,i={}){const n=i&&!0===i.named,o=i&&!0===i.seeded;if(n)return null;if(!o&&!isGenericTitle(e))return null;if(!String(t||"").trim()||isTopicless(t))return null;const r=cleanTitle(await nameConversation(t,i));return!r||isGenericTitle(r)?null:r}async function nameSession(e,t,i,n,o={}){if(!e||"function"!=typeof e.setTitle)return null;if(!i)return null;const r="function"==typeof e.getSession?e.getSession(t,i):null,s=r&&r.title,l={...o,seeded:!(!r||r.named)},a=await refineTitle(s,n,l);if(a){try{e.setTitle(t,i,a,{named:!0})}catch{return null}return a}if(isTopicless(n)&&r&&!r.named&&!isGenericTitle(s)){try{e.setTitle(t,i,GENERIC_TITLE)}catch{return null}return GENERIC_TITLE}return null}module.exports={GENERIC_TITLE:GENERIC_TITLE,TITLE_SYSTEM:TITLE_SYSTEM,isGenericTitle:isGenericTitle,isTopicless:isTopicless,looksLikeEcho:looksLikeEcho,cleanTitle:cleanTitle,titlePromptOf:titlePromptOf,deriveTitle:deriveTitle,nameConversation:nameConversation,refineTitle:refineTitle,nameSession:nameSession};
3
+ "use strict";const GENERIC_TITLE="New conversation",TITLE_SYSTEM='You name conversations. Write a short descriptive title (2 to 6 words) that captures the topic of the conversation. Never repeat the user\'s words verbatim — if the message is just a greeting or has no clear topic, name it something like "New conversation". Sentence case, no quotes, no markdown, no trailing punctuation, no explanation.',isGenericTitle=e=>!e||String(e).trim().toLowerCase()===GENERIC_TITLE.toLowerCase(),GREETINGS=new Set(["hey","heey","heyy","heyyy","hi","hii","hello","hej","hejj","yo","sup","hola","howdy","hai","heyo","hiya","wassup","greetings","namaste","ahoy","hallo"]);function isTopicless(e){const t=String(e).trim().toLowerCase().replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim();if(!t)return!0;const i=t.split(" ");return!!/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(t)||i.length<=2&&t.length<=12&&GREETINGS.has(i[0])}function looksLikeEcho(e,t){const i=e=>String(e).toLowerCase().replace(/[^a-z0-9\s]/g,"").replace(/\s+/g," ").trim(),n=i(e),o=i(t);if(!n||!o)return!1;if(n===o)return!0;if(o.length<=14&&(n.startsWith(o)||o.startsWith(n)))return!0;if(o.length<=24){const i=e=>new Set((String(e).toLowerCase().match(/[a-z0-9]+/g)||[]).filter((e=>!ECHO_STOP.has(e)))),n=i(e),o=i(t);if(n.size&&n.size===o.size&&[...n].every((e=>o.has(e))))return!0}return!1}const ECHO_STOP=new Set(["the","a","an","to","of","in","on","at","for","and","or","is","are","be","it","its","my","our","please","can","you","just","do","that","this"]);function cleanTitle(e){return String(null==e?"":e).replace(/\s+/g," ").trim().replace(/["'`“”‘’]/g,"").replace(/[*_#]/g,"").replace(/^\s*(?:title|name)\s*[:\-–]\s*/i,"").replace(/[.\s]+$/g,"").slice(0,60).trim()}const titlePromptOf=e=>`Write a short title for a conversation that begins with: "${String(e).slice(0,500)}"`,FILLER=/^(?:please|pls|plz|hey|hi|hello|ok(?:ay)?|so|now|just|also|and|then|maybe|well|um|uh|can you|could you|would you|will you|i want you to|i want to|i need you to|i need to|i'?d like you to|i would like you to|i'?d like to|help me|help|let'?s|lets|go ahead and)\b[\s,:;-]*/i,TRAILING_STOP=new Set(["the","a","an","in","on","at","to","for","of","and","or","with","is","are","my","our","this","that","please","can","you","could","would","i","we","just","do","it"]);function deriveTitle(e){let t=String(null==e?"":e).trim().replace(/\s+/g," ");if(!t)return GENERIC_TITLE;for(let e=0;e<6;e++){const e=t.replace(FILLER,"").trim();if(e===t)break;t=e}const i=t.split(" ").filter(Boolean);if(!i.length)return GENERIC_TITLE;const n=i.slice(0,6);for(;n.length>2&&TRAILING_STOP.has(n[n.length-1].toLowerCase().replace(/[^a-z0-9]/g,""));)n.pop();let o=n.join(" ").replace(/[.,!?;:]+$/,"").trim();return o?(o=o[0].toUpperCase()+o.slice(1),o.slice(0,60).trim()||GENERIC_TITLE):GENERIC_TITLE}async function nameConversation(e,{callModel:t,signal:i}={}){const n=null==e?"":String(e);if(!n.trim())return"";if(isTopicless(n))return GENERIC_TITLE;if(!("function"!=typeof t||i&&i.aborted)){let e=null;try{e=await t(titlePromptOf(n),{system:TITLE_SYSTEM,signal:i,naming:!0})}catch{e=null}const o=cleanTitle(e);if(o)return looksLikeEcho(o,n)?GENERIC_TITLE:o}return deriveTitle(n)}async function refineTitle(e,t,i={}){const n=i&&!0===i.named,o=i&&!0===i.seeded;if(n)return null;if(!o&&!isGenericTitle(e))return null;if(!String(t||"").trim()||isTopicless(t))return null;const r=cleanTitle(await nameConversation(t,i));return!r||isGenericTitle(r)?null:r}async function nameSession(e,t,i,n,o={}){if(!e||"function"!=typeof e.setTitle)return null;if(!i)return null;const r="function"==typeof e.getSession?e.getSession(t,i):null,s=r&&r.title,l=!(!r||r.named);if(l&&s&&!isGenericTitle(s)&&!looksLikeEcho(s,n)){try{e.setTitle(t,i,s,{named:!0})}catch{return null}return null}const a={...o,seeded:l},c=await refineTitle(s,n,a);if(c){try{e.setTitle(t,i,c,{named:!0})}catch{return null}return c}if(isTopicless(n)&&r&&!r.named&&!isGenericTitle(s)){try{e.setTitle(t,i,GENERIC_TITLE)}catch{return null}return GENERIC_TITLE}return null}module.exports={GENERIC_TITLE:GENERIC_TITLE,TITLE_SYSTEM:TITLE_SYSTEM,isGenericTitle:isGenericTitle,isTopicless:isTopicless,looksLikeEcho:looksLikeEcho,cleanTitle:cleanTitle,titlePromptOf:titlePromptOf,deriveTitle:deriveTitle,nameConversation:nameConversation,refineTitle:refineTitle,nameSession:nameSession};
@@ -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"),PREFS_FILE="preferences.json",PREFS_VERSION=1,SHARED_PREF_KEYS=Object.freeze(["themeIndex","model","modelClass","currentModelId","models","effort","vim","memoryPersist","confirmMode"]),LEGACY_MEMORY_PERSIST_NAMESPACE="__memoryPersist",LEGACY_CONFIRM_MODE_NAMESPACE="__confirmMode",SECRET_KEY_RE=/(^|[^a-z0-9])(api[_-]?key|apikey|key|keys|token|secret|password|passwd|credential|credentials|authorization|bearer|private[_-]?key|access[_-]?key|session[_-]?key)([^a-z0-9]|$)/i,SECRET_VALUE_RES=[/\baegis_[A-Za-z0-9_\-]{12,}/,/\bsk-[A-Za-z0-9_\-]{12,}/,/\bghp_[A-Za-z0-9_\-]{20,}/,/\bxox[baprs]-[A-Za-z0-9\-]{10,}/,/\beyJ[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{8,}/,/^[A-Za-z0-9+/]{48,}={0,2}$/];function prefsDir(e){const r=e||{};return r.dir&&String(r.dir).trim()?path.resolve(String(r.dir).trim()):aegisHome(r.env)}function prefsFile(e){const r=e||{};return r.file&&String(r.file).trim()?path.resolve(String(r.file).trim()):path.join(prefsDir(r),PREFS_FILE)}function scanForSecrets(e,r="",t=[]){if(null==e)return t;if("string"==typeof e)return SECRET_VALUE_RES.some((r=>r.test(e)))&&t.push(r||"(root)"),t;if("object"!=typeof e)return t;if(Array.isArray(e))return e.forEach(((e,o)=>scanForSecrets(e,`${r}[${o}]`,t))),t;for(const[o,s]of Object.entries(e)){const e=r?`${r}.${o}`:o;SECRET_KEY_RE.test(o)&&null!=s&&""!==s&&!1!==s?t.push(e):scanForSecrets(s,e,t)}return t}function assertNoSecrets(e,r="shared preference store"){const t=scanForSecrets(e);if(t.length)throw new Error(`${r} must not carry key material — refusing to write (found: ${t.join(", ")}). Secrets belong in the host-local credential store, where the OS can protect them.`);return e}function readJson(e,r){try{const t=JSON.parse(fs.readFileSync(e,"utf8"));return t&&"object"==typeof t&&!Array.isArray(t)?t:r}catch{return r}}function load(e){return readJson(prefsFile(e),{})}function write(e,r){assertNoSecrets(e);const t=prefsFile(r);fs.mkdirSync(path.dirname(t),{recursive:!0});const o=`${t}.tmp-${process.pid}`;fs.writeFileSync(o,JSON.stringify(e,null,2)+"\n",{mode:384}),fs.renameSync(o,t);try{fs.chmodSync(t,384)}catch{}return e}function set(e,r){const t={...load(r),...e||{}};for(const e of Object.keys(t))void 0===t[e]&&delete t[e];return void 0===t.version&&(t.version=1),write(t,r)}function get(e,r,t){const o=load(r)[e];return void 0===o?t:o}function has(e,r){return void 0!==load(r)[e]}function remove(e,r){const t=load(r);return delete t[e],write(t,r)}function extractNonSecretHalf(e){const r={},t=(e||{})[LEGACY_MEMORY_PERSIST_NAMESPACE];t&&"object"==typeof t&&"boolean"==typeof t.enabled&&(r.memoryPersist=t.enabled);const o=(e||{})[LEGACY_CONFIRM_MODE_NAMESPACE];return o&&"object"==typeof o&&"boolean"==typeof o.enabled&&(r.confirmMode=o.enabled),r}function adopt(e){const r=e||{},t=prefsFile(r),o=r.legacyDir,s=o?path.join(String(o),"settings.json"):null;if(s&&path.resolve(s)===t)return{adopted:!1,keys:[],from:s,reason:"shared store is the legacy file"};if(!s||!fs.existsSync(s))return{adopted:!1,keys:[],from:s,reason:"no legacy settings file"};const n=load(r),a=extractNonSecretHalf(readJson(s,{})),i=Object.keys(a).filter((e=>void 0===n[e]));if(!i.length)return{adopted:!1,keys:[],from:s,reason:Object.keys(a).length?"shared store already carries these preferences":"legacy store has no shared preferences"};const c={};for(const e of i)c[e]=a[e];return c.adopted={from:s,at:(new Date).toISOString(),names:i.slice().sort()},write({...n,...c},r),{adopted:!0,keys:i.slice().sort(),from:s}}module.exports={PREFS_FILE:PREFS_FILE,PREFS_VERSION:1,SHARED_PREF_KEYS:SHARED_PREF_KEYS,LEGACY_MEMORY_PERSIST_NAMESPACE:LEGACY_MEMORY_PERSIST_NAMESPACE,prefsDir:prefsDir,prefsFile:prefsFile,load:load,set:set,get:get,has:has,remove:remove,scanForSecrets:scanForSecrets,assertNoSecrets:assertNoSecrets,extractNonSecretHalf:extractNonSecretHalf,adopt:adopt};
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{aegisHome:aegisHome}=require("./credentials.js"),PREFS_FILE="preferences.json",PREFS_VERSION=1,SHARED_PREF_KEYS=Object.freeze(["themeIndex","model","modelClass","currentModelId","models","effort","vim","memoryPersist","confirmMode","permissionMode","sandboxPolicy"]),LEGACY_MEMORY_PERSIST_NAMESPACE="__memoryPersist",LEGACY_CONFIRM_MODE_NAMESPACE="__confirmMode",SECRET_KEY_RE=/(^|[^a-z0-9])(api[_-]?key|apikey|key|keys|token|secret|password|passwd|credential|credentials|authorization|bearer|private[_-]?key|access[_-]?key|session[_-]?key)([^a-z0-9]|$)/i,SECRET_VALUE_RES=[/\baegis_[A-Za-z0-9_\-]{12,}/,/\bsk-[A-Za-z0-9_\-]{12,}/,/\bghp_[A-Za-z0-9_\-]{20,}/,/\bxox[baprs]-[A-Za-z0-9\-]{10,}/,/\beyJ[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{8,}/,/^[A-Za-z0-9+/]{48,}={0,2}$/];function prefsDir(e){const r=e||{};return r.dir&&String(r.dir).trim()?path.resolve(String(r.dir).trim()):aegisHome(r.env)}function prefsFile(e){const r=e||{};return r.file&&String(r.file).trim()?path.resolve(String(r.file).trim()):path.join(prefsDir(r),PREFS_FILE)}function scanForSecrets(e,r="",t=[]){if(null==e)return t;if("string"==typeof e)return SECRET_VALUE_RES.some((r=>r.test(e)))&&t.push(r||"(root)"),t;if("object"!=typeof e)return t;if(Array.isArray(e))return e.forEach(((e,o)=>scanForSecrets(e,`${r}[${o}]`,t))),t;for(const[o,s]of Object.entries(e)){const e=r?`${r}.${o}`:o;SECRET_KEY_RE.test(o)&&null!=s&&""!==s&&!1!==s?t.push(e):scanForSecrets(s,e,t)}return t}function assertNoSecrets(e,r="shared preference store"){const t=scanForSecrets(e);if(t.length)throw new Error(`${r} must not carry key material — refusing to write (found: ${t.join(", ")}). Secrets belong in the host-local credential store, where the OS can protect them.`);return e}function readJson(e,r){try{const t=JSON.parse(fs.readFileSync(e,"utf8"));return t&&"object"==typeof t&&!Array.isArray(t)?t:r}catch{return r}}function load(e){return readJson(prefsFile(e),{})}function write(e,r){assertNoSecrets(e);const t=prefsFile(r);fs.mkdirSync(path.dirname(t),{recursive:!0});const o=`${t}.tmp-${process.pid}`;fs.writeFileSync(o,JSON.stringify(e,null,2)+"\n",{mode:384}),fs.renameSync(o,t);try{fs.chmodSync(t,384)}catch{}return e}function set(e,r){const t={...load(r),...e||{}};for(const e of Object.keys(t))void 0===t[e]&&delete t[e];return void 0===t.version&&(t.version=1),write(t,r)}function get(e,r,t){const o=load(r)[e];return void 0===o?t:o}function has(e,r){return void 0!==load(r)[e]}function remove(e,r){const t=load(r);return delete t[e],write(t,r)}function extractNonSecretHalf(e){const r={},t=(e||{})[LEGACY_MEMORY_PERSIST_NAMESPACE];t&&"object"==typeof t&&"boolean"==typeof t.enabled&&(r.memoryPersist=t.enabled);const o=(e||{})[LEGACY_CONFIRM_MODE_NAMESPACE];return o&&"object"==typeof o&&"boolean"==typeof o.enabled&&(r.confirmMode=o.enabled),r}function adopt(e){const r=e||{},t=prefsFile(r),o=r.legacyDir,s=o?path.join(String(o),"settings.json"):null;if(s&&path.resolve(s)===t)return{adopted:!1,keys:[],from:s,reason:"shared store is the legacy file"};if(!s||!fs.existsSync(s))return{adopted:!1,keys:[],from:s,reason:"no legacy settings file"};const n=load(r),i=extractNonSecretHalf(readJson(s,{})),a=Object.keys(i).filter((e=>void 0===n[e]));if(!a.length)return{adopted:!1,keys:[],from:s,reason:Object.keys(i).length?"shared store already carries these preferences":"legacy store has no shared preferences"};const c={};for(const e of a)c[e]=i[e];return c.adopted={from:s,at:(new Date).toISOString(),names:a.slice().sort()},write({...n,...c},r),{adopted:!0,keys:a.slice().sort(),from:s}}module.exports={PREFS_FILE:PREFS_FILE,PREFS_VERSION:1,SHARED_PREF_KEYS:SHARED_PREF_KEYS,LEGACY_MEMORY_PERSIST_NAMESPACE:LEGACY_MEMORY_PERSIST_NAMESPACE,prefsDir:prefsDir,prefsFile:prefsFile,load:load,set:set,get:get,has:has,remove:remove,scanForSecrets:scanForSecrets,assertNoSecrets:assertNoSecrets,extractNonSecretHalf:extractNonSecretHalf,adopt:adopt};
@@ -0,0 +1,20 @@
1
+ {
2
+ "note": "written by tools/vendor-sandbox.mjs — records what was actually verified",
3
+ "binary": "x64-linux/bwrap",
4
+ "arch": "x64-linux",
5
+ "version": "bubblewrap 0.9.0",
6
+ "digest": "e318903862396f96de3df57264e0158682b952fd3fb53ac23d876413e7b30f71",
7
+ "bytes": 72160,
8
+ "source": "/usr/bin/bwrap",
9
+ "sourceDigest": "e318903862396f96de3df57264e0158682b952fd3fb53ac23d876413e7b30f71",
10
+ "linkage": [
11
+ "linux-vdso.so.1 (0x00007602120c7000)",
12
+ "libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x0000760212069000)",
13
+ "libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x000076021205c000)",
14
+ "libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000760211e00000)",
15
+ "libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x0000760211d66000)",
16
+ "/lib64/ld-linux-x86-64.so.2 (0x00007602120c9000)"
17
+ ],
18
+ "usernsProbe": "ok",
19
+ "stagedAt": "2026-11-06T14:18:34.860Z"
20
+ }
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ "use strict";function haystack(e){if(!e||"object"!=typeof e)return"";const t=[e.title,e.summary,e.cwd,e.id].filter((e=>"string"==typeof e&&e)),s=Array.isArray(e.messages)?e.messages:[];for(const e of s)if(e&&"user"===e.role&&"string"==typeof e.content&&e.content){t.push(e.content.slice(0,400));break}return t.join("\n")}function scoreSession(e,t){const s=String(e||"").trim().toLowerCase();if(!s)return{matched:!0,score:0,field:"all"};const r="string"==typeof(t&&t.title)?t.title.toLowerCase():"",n=haystack(t).toLowerCase();if(r&&r===s)return{matched:!0,score:1e3,field:"title"};if(r&&r.startsWith(s))return{matched:!0,score:900,field:"title"};const o=r?r.indexOf(s):-1;if(-1!==o)return{matched:!0,score:700-o,field:"title"};const i=n.indexOf(s);if(-1!==i)return{matched:!0,score:Math.max(1,400-i),field:"body"};if(r){let e=100,t=-2,n=-1,o=!0;for(const i of s){const s=r.indexOf(i,n+1);if(-1===s){o=!1;break}e+=s===t+1?15:5,0===s&&(e+=20),t=s,n=s}if(o)return{matched:!0,score:e,field:"title"}}return{matched:!1,score:0,field:null}}function rankSessions(e,t){const s=Array.isArray(t)?t:[],r=String(e||"").trim();if(!r)return s.slice();const n=[];for(let e=0;e<s.length;e+=1){const t=s[e],o=scoreSession(r,t);o.matched&&n.push({s:t,i:e,score:o.score})}return n.sort(((e,t)=>t.score-e.score||e.i-t.i)),n.map((e=>e.s))}function matchReason(e,t){const s=String(e||"").trim();if(!s)return null;const r=scoreSession(s,t);return r.matched?"title"===r.field?"title":"body"===r.field?"content":null:null}module.exports={haystack:haystack,scoreSession:scoreSession,rankSessions:rankSessions,matchReason:matchReason};