aegisone 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -1
- package/scripts/predist.mjs +1 -1
- package/src/permissions.js +1 -1
- package/vendor/cli/bin/aegiscode.js +915 -2
- package/vendor/cli/package.json +1 -1
- package/vendor/cli/src/app.js +1 -1
- package/vendor/cli/src/autonomous.js +515 -1
- package/vendor/cli/src/caps.js +879 -1
- package/vendor/cli/src/chatflow.js +1 -1
- package/vendor/cli/src/commands.js +1 -1
- package/vendor/cli/src/engine.js +1 -1
- package/vendor/cli/src/gate.js +55 -1
- package/vendor/cli/src/history.js +1 -1
- package/vendor/cli/src/limits.js +190 -1
- package/vendor/cli/src/mcp.js +694 -1
- package/vendor/cli/src/models.js +1 -1
- package/vendor/cli/src/overlays.js +1 -1
- package/vendor/cli/src/permissions.js +290 -1
- package/vendor/cli/src/provenance.js +182 -2
- package/vendor/cli/src/provenance.lock.json +2 -2
- package/vendor/cli/vendor/client/aegis.js +1 -1
- package/vendor/cli/vendor/client/attest.js +1 -1
- package/vendor/cli/vendor/client/byok-catalog.js +1 -1
- package/vendor/cli/vendor/client/catalog-client.js +3 -0
- package/vendor/cli/vendor/client/conversation-export.js +3 -0
- package/vendor/cli/vendor/client/drive-upload.js +1 -1
- package/vendor/cli/vendor/client/session-store.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/attachments.js +3 -0
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/context.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/exec-plan.js +3 -0
- package/vendor/cli/vendor/desktop/lib/local/local.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/spill.js +3 -0
- package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1
- package/vendor/cli/vendor/one/src/permissions.js +1 -1
- package/vendor/desktop/lib/auto.js +1 -1
- package/vendor/desktop/lib/google-connect.js +1 -1
- package/vendor/desktop/lib/local/attachments.js +3 -0
- package/vendor/desktop/lib/local/claude-pro.js +1 -1
- package/vendor/desktop/lib/local/context.js +1 -1
- package/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/desktop/lib/local/exec-plan.js +3 -0
- package/vendor/desktop/lib/local/local.js +1 -1
- package/vendor/desktop/lib/local/prompt.js +1 -1
- package/vendor/desktop/lib/local/session-rounds.js +1 -1
- package/vendor/desktop/lib/local/shell.js +1 -1
- package/vendor/desktop/lib/local/spill.js +3 -0
- package/vendor/desktop/lib/local/tools.js +1 -1
- package/vendor/desktop/main.js +1 -1
- package/vendor/desktop/package.json +3 -2
- package/vendor/desktop/preload.js +1 -1
- package/vendor/desktop/renderer/app.js +1 -1
- package/vendor/desktop/renderer/budget.js +1 -1
- package/vendor/desktop/renderer/fingerprint.js +2 -2
- package/vendor/desktop/renderer/index.html +44 -4
- package/vendor/desktop/renderer/quick.html +4 -1
- package/vendor/desktop/renderer/quick.js +1 -1
- package/vendor/desktop/renderer/stream-policy.js +1 -1
- package/vendor/desktop/renderer/style.css +124 -0
- package/vendor/desktop/vendor/aegis.js +1 -1
- package/vendor/desktop/vendor/attest.js +1 -1
- package/vendor/desktop/vendor/byok-catalog.js +1 -1
- package/vendor/desktop/vendor/catalog-client.js +3 -0
- package/vendor/desktop/vendor/conversation-export.js +3 -0
- package/vendor/desktop/vendor/drive-upload.js +1 -1
- package/vendor/desktop/vendor/session-store.js +1 -1
package/vendor/cli/src/models.js
CHANGED
|
@@ -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"),{resolveShared:resolveShared}=require("./sharedpaths.js"),{offerableCatalog:offerableCatalog}=require(resolveShared(path.join("client","brain-catalog.js"))),envFile=require(resolveShared(path.join("client","env-file.js"))),claudePro=require(resolveShared(path.join("desktop","lib","local","claude-pro.js")));function claudeProLoggedIn(){try{return!!claudePro.claudeProStatus({env:process.env}).loggedIn}catch{return!1}}const NO_PIN=null,ID_NOTES=Object.freeze({"openai-gpt4o-mini":"OpenAI gpt-4o-mini, pooled","anthropic-haiku":"Anthropic Haiku, pooled","nexus-brain":"pooled brain · multi-call fan-out, sized by /effort"});function normalizeModel(e){const o="string"==typeof e?{id:e}:e;if(!o||"object"!=typeof o)return null;const r="string"==typeof o.id?o.id.trim():"";if(!r)return null;const n="string"==typeof o.alias_of&&o.alias_of.trim()?o.alias_of.trim():null,i=Array.isArray(o.capabilities)?o.capabilities.filter((e=>"string"==typeof e&&e)):[],t={id:r,label:"string"==typeof o.label&&o.label.trim()||"string"==typeof o.name&&o.name.trim()||r,note:("string"==typeof o.note&&o.note.trim()?o.note.trim():"")||(n?`alias of ${n}`:ID_NOTES[r]||i.join(", ")),hidden:!0===o.hidden,aliasOf:n,capabilities:i};return"string"==typeof o.provider&&o.provider.trim()&&(t.provider=o.provider.trim()),!0===o.configured&&(t.configured=!0),"string"==typeof o.cls&&o.cls.trim()&&(t.cls=o.cls.trim()),t}function normalizeModelCatalog(e){const o=Array.isArray(e)?e:Array.isArray(e&&e.models)?e.models:[],r=[],n=new Set;for(const e of o){const o=normalizeModel(e);o&&!n.has(o.id)&&(n.add(o.id),r.push(o))}return r}function pickerEntries(e){const o=Array.isArray(e)?e.filter(Boolean):[],r=offerableCatalog(o).map(normalizeModel).filter(Boolean);if(r.length)return r;const n=o.filter((e=>!e.aliasOf));return n.length?n:o}function findModel(e,o){const r="string"==typeof o?o.trim():"";return r&&(Array.isArray(e)?e:[]).find((e=>e&&e.id===r))||null}function catalogIds(e){return new Set((Array.isArray(e)?e:[]).map((e=>String(e&&e.id||"").toLowerCase())).filter(Boolean))}function modelKeyPlan(e,o={}){const r=e&&e.id||"",n=envFile.keyForModelId(r,e&&e.cls);if(!n.env)return{needed:!1,env:"",provider:"",pooled:n.pooled,status:null,why:"this id has no key variable"};if(n.foreign){const e=!!envFile.resolveForeignSecret(n.env)||claudeProLoggedIn();return{needed:!e,env:n.env,provider:"",pooled:!1,status:{present:e,inFile:e,source:e?"file":"none"},why:e?`${n.env} is already set aside for Claude Code Pro`:`no ${n.env} is set aside for Claude Code Pro`}}const i=envFile.keyStatus(n.env);if(n.pooled){const e=!i.present&&!o.accountConfigured;return{needed:e,env:n.env,provider:"",pooled:!0,status:i,why:e?`no ${n.env} is set on this machine`:`account key present (${o.accountConfigured&&!i.present?"credentials.json":i.source})`}}const t=!i.inFile&&!o.hasStored;return{needed:t,env:n.env,provider:n.provider,pooled:!1,status:i,why:t?`no ${n.env} is stored for provider "${n.provider}"`:`${n.env} is already stored (${i.inFile?i.source:"provider store"})`}}function modelKeyQueue(e,o={}){const r=e&&e.id||"";if(!String(r).trim())return[];const n=envFile.keyForModelId(r,e&&e.cls);if(!n.env)return[];if(n.foreign)return envFile.resolveForeignSecret(n.env)||claudeProLoggedIn()?[]:[{env:n.env,provider:"",vendor:"",role:"claude-pro",needed:!0,status:{present:!1},why:`no ${n.env} is set aside for Claude Code Pro`}];const i=[],t=envFile.keyStatus(envFile.ACCOUNT_ENV_VAR);t.present||o.accountConfigured||i.push({env:envFile.ACCOUNT_ENV_VAR,provider:"",vendor:"",role:"account",needed:!0,status:t,why:`no ${envFile.ACCOUNT_ENV_VAR} is set on this machine`});const l=n.vendor||"",d=l?envFile.envVarFor(l):"",s=!(!l||"function"!=typeof o.hasStoredFor||!o.hasStoredFor(l));if(d){const e=envFile.keyStatus(d);e.inFile||s||i.push({env:d,provider:l,vendor:l,role:"provider",needed:!0,status:e,why:e.present?`${d} is exported in this shell only — the desktop cannot see it`:`no ${d} is stored for provider "${l}"`})}return i}function storeModelKey(e,o,r={}){const n=envFile.keyForModelId(e&&e.id,e&&e.cls),i=String(r.env||"").trim()||n.env;if(!i)return{ok:!1,file:"",changed:!1,error:`cannot name a key variable for "${e&&e.id||""}"`,env:"",provider:"",pooled:n.pooled};const t={...r};delete t.env;const l=n.foreign?envFile.setForeignSecret(i,o,t):envFile.setEnvValue(i,o,t),d=!n.foreign&&i===envFile.ACCOUNT_ENV_VAR;return{...l,env:i,provider:i===n.env?n.provider:"",pooled:d,foreign:!!n.foreign}}function keyVarForModel(e){return envFile.keyForModelId(e&&e.id,e&&e.cls).env}module.exports={NO_PIN:null,ID_NOTES:ID_NOTES,normalizeModel:normalizeModel,normalizeModelCatalog:normalizeModelCatalog,pickerEntries:pickerEntries,findModel:findModel,catalogIds:catalogIds,modelKeyPlan:modelKeyPlan,modelKeyQueue:modelKeyQueue,storeModelKey:storeModelKey,keyVarForModel:keyVarForModel,claudeProLoggedIn:claudeProLoggedIn};
|
|
3
|
+
"use strict";const path=require("node:path"),{resolveShared:resolveShared}=require("./sharedpaths.js"),{offerableCatalog:offerableCatalog}=require(resolveShared(path.join("client","brain-catalog.js"))),envFile=require(resolveShared(path.join("client","env-file.js"))),claudePro=require(resolveShared(path.join("desktop","lib","local","claude-pro.js")));function claudeProLoggedIn(){try{return!!claudePro.claudeProStatus({env:process.env}).loggedIn}catch{return!1}}const NO_PIN=null,ID_NOTES=Object.freeze({"openai-gpt4o-mini":"OpenAI gpt-4o-mini, pooled","anthropic-haiku":"Anthropic Haiku, pooled","nexus-brain":"pooled brain · multi-call fan-out, sized by /effort"});function normalizeModel(e){const o="string"==typeof e?{id:e}:e;if(!o||"object"!=typeof o)return null;const r="string"==typeof o.id?o.id.trim():"";if(!r)return null;const n="string"==typeof o.alias_of&&o.alias_of.trim()?o.alias_of.trim():null,i=Array.isArray(o.capabilities)?o.capabilities.filter((e=>"string"==typeof e&&e)):[],t={id:r,label:"string"==typeof o.label&&o.label.trim()||"string"==typeof o.name&&o.name.trim()||r,note:("string"==typeof o.note&&o.note.trim()?o.note.trim():"")||(n?`alias of ${n}`:ID_NOTES[r]||i.join(", ")),hidden:!0===o.hidden,aliasOf:n,capabilities:i};return"string"==typeof o.provider&&o.provider.trim()&&(t.provider=o.provider.trim()),!0===o.configured&&(t.configured=!0),"string"==typeof o.cls&&o.cls.trim()&&(t.cls=o.cls.trim()),t}function normalizeModelCatalog(e){const o=Array.isArray(e)?e:Array.isArray(e&&e.models)?e.models:[],r=[],n=new Set;for(const e of o){const o=normalizeModel(e);o&&!n.has(o.id)&&(n.add(o.id),r.push(o))}return r}function pickerEntries(e){const o=Array.isArray(e)?e.filter(Boolean):[],r=offerableCatalog(o).map(normalizeModel).filter(Boolean);if(r.length)return r;const n=o.filter((e=>!e.aliasOf));return n.length?n:o}function findModel(e,o){const r="string"==typeof o?o.trim():"";return r&&(Array.isArray(e)?e:[]).find((e=>e&&e.id===r))||null}function catalogIds(e){return new Set((Array.isArray(e)?e:[]).map((e=>String(e&&e.id||"").toLowerCase())).filter(Boolean))}function modelKeyPlan(e,o={}){const r=e&&e.id||"",n=envFile.keyForModelId(r,e&&e.cls);if(!n.env)return{needed:!1,env:"",provider:"",pooled:n.pooled,status:null,why:"this id has no key variable"};if(n.foreign){const e=!!envFile.resolveForeignSecret(n.env)||claudeProLoggedIn();return{needed:!e,env:n.env,provider:"",pooled:!1,status:{present:e,inFile:e,source:e?"file":"none"},why:e?`${n.env} is already set aside for Claude Code Pro`:`no ${n.env} is set aside for Claude Code Pro`}}const i=envFile.keyStatus(n.env);if(n.pooled){const e=!i.present&&!o.accountConfigured;return{needed:e,env:n.env,provider:"",pooled:!0,status:i,why:e?`no ${n.env} is set on this machine`:`account key present (${o.accountConfigured&&!i.present?"credentials.json":i.source})`}}const t=!i.inFile&&!o.hasStored;return{needed:t,env:n.env,provider:n.provider,pooled:!1,status:i,why:t?`no ${n.env} is stored for provider "${n.provider}"`:`${n.env} is already stored (${i.inFile?i.source:"provider store"})`}}function modelKeyQueue(e,o={}){const r=e&&e.id||"";if(!String(r).trim())return[];const n=envFile.keyForModelId(r,e&&e.cls);if(!n.env)return[];if(n.foreign)return envFile.resolveForeignSecret(n.env)||claudeProLoggedIn()?[]:[{env:n.env,provider:"",vendor:"",role:"claude-pro",needed:!0,status:{present:!1},why:`no ${n.env} is set aside for Claude Code Pro`}];const i=[],t=envFile.keyStatus(envFile.ACCOUNT_ENV_VAR);t.present||o.accountConfigured||i.push({env:envFile.ACCOUNT_ENV_VAR,provider:"",vendor:"",role:"account",needed:!0,status:t,why:`no ${envFile.ACCOUNT_ENV_VAR} is set on this machine`});const l=n.vendor||"",d=l?envFile.envVarFor(l):"",s=!(!l||"function"!=typeof o.hasStoredFor||!o.hasStoredFor(l));if(d){const e=envFile.keyStatus(d);e.inFile||s||i.push({env:d,provider:l,vendor:l,role:"provider",needed:!0,status:e,why:e.present?`${d} is exported in this shell only — the desktop cannot see it`:`no ${d} is stored for provider "${l}"`})}return i}function storeModelKey(e,o,r={}){const n=envFile.keyForModelId(e&&e.id,e&&e.cls),i=String(r.env||"").trim()||n.env;if(!i)return{ok:!1,file:"",changed:!1,error:`cannot name a key variable for "${e&&e.id||""}"`,env:"",provider:"",pooled:n.pooled};const t={...r};delete t.env;const l=n.foreign?envFile.setForeignSecret(i,o,t):envFile.setEnvValue(i,o,t),d=!n.foreign&&i===envFile.ACCOUNT_ENV_VAR;return{...l,env:i,provider:i===n.env?n.provider:"",pooled:d,foreign:!!n.foreign}}function keyVarForModel(e){return envFile.keyForModelId(e&&e.id,e&&e.cls).env}function providerForModel(e){const o=String(e&&e.id||"").trim();return o&&(envFile.keyForModelId(o,e&&e.cls).provider||envFile.providerForModelId(o,e&&e.cls))||""}module.exports={NO_PIN:null,ID_NOTES:ID_NOTES,normalizeModel:normalizeModel,normalizeModelCatalog:normalizeModelCatalog,pickerEntries:pickerEntries,findModel:findModel,catalogIds:catalogIds,modelKeyPlan:modelKeyPlan,modelKeyQueue:modelKeyQueue,storeModelKey:storeModelKey,keyVarForModel:keyVarForModel,providerForModel:providerForModel,claudeProLoggedIn:claudeProLoggedIn};
|
|
@@ -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{span:span,padLine:padLine}=require("./screen.js"),{C:C,BOLD:BOLD,BOLD_OFF:BOLD_OFF,GLYPH:GLYPH}=require("./theme.js");let fuzzy=null;try{fuzzy=require("./fuzzy.js")}catch{fuzzy=null}function rankCommands(e,a){if(fuzzy&&"function"==typeof fuzzy.fuzzyRankWithAliases)return fuzzy.fuzzyRankWithAliases(e,a,(e=>e.name),(e=>e.aliases||[]));const n=String(e||"").toLowerCase();return n?a.filter((e=>`${e.name} ${(e.aliases||[]).join(" ")}`.toLowerCase().includes(n))):a}const descOf=e=>null!=e.help?e.help:null!=e.desc?e.desc:"",hintOf=e=>null!=e.hint?e.hint:null!=e.args?e.args:"";function fit(e,a){return e.map((e=>padLine(e,a)))}const blank=e=>[span(""," ".repeat(Math.max(0,e)))];function boldMatched(e,a,n){const s=fuzzy&&"function"==typeof fuzzy.fuzzyMatchPositions?fuzzy.fuzzyMatchPositions(e,a):[];if(!s||!s.length)return[span(n,a)];const t=[];let r=0;for(const e of s)e>r&&t.push(span(n,a.slice(r,e))),t.push(span(n+BOLD,a[e])),r=e+1;return r<a.length&&t.push(span(n,a.slice(r))),t}function renderPalette(e,a={},n=80,s=24){!Array.isArray(e)&&e&&"object"==typeof e&&(a=e,e=Array.isArray(e.commands)?e.commands:[]);const t=rankCommands(a.query||"",e||[]),r=Number.isInteger(a.sel)?a.sel:0,p=t.length,l=Math.max(1,Math.min(12,s-8)),o=Math.max(0,Math.min(r-Math.floor(l/2),Math.max(0,p-l))),u=t.slice(o,o+l),h=[];h.push(blank(n)),h.push([span(C.gray," "+"─".repeat(Math.max(10,n-4)))]);for(let e=0;e<u.length;e++){const n=u[e],s=o+e===r,t=s?span(C.lavender,GLYPH.cursor):span(""," "),p=s?C.blue:C.white,l=[span(p,"/"),...boldMatched(a.query||"",n.name,p)],i=" ".repeat(Math.max(1,22-[...n.name].length));h.push([span(""," "),t,span(""," "),...l,span(n.unavailable?C.dim:C.gray,i+descOf(n))]),s&&hintOf(n)&&h.push([span(""," "),span(C.gray,`${GLYPH.hook} Usage: /${n.name} ${hintOf(n)}`)])}for(;h.length<4+2*l;)h.push(blank(n));return h.push([span(C.gray," "+"─".repeat(Math.max(10,n-4)))]),h.push([span(C.gray,` type to filter ${GLYPH.bullet} shift+enter runs the top row ${GLYPH.bullet} enter runs ${GLYPH.bullet} esc closes`)]),fit(h,n)}const PICKER_HINT=`↑↓ or tab move ${GLYPH.bullet} enter pins ${GLYPH.bullet} shift+↑↓ pins at once ${GLYPH.bullet} esc cancels`;function renderModelPicker(e,a=0,n=80,s=24,t=null,r=null,p=null){const l=[],o="function"==typeof p&&r?p(r):null;l.push(blank(n)),l.push([span(""," "),span(C.white+BOLD,"Select model"),span(BOLD_OFF,""),...o?[span(C.gray,` — running on ${o}`)]:[]]),l.push([span(""," "),span(C.gray,"Switch between models. Your pick becomes the default for new sessions.")]),l.push([span(""," "),span(C.gray,"Nexus is pooled; any other row prompts for its provider key on pick.")]),l.push(blank(n));const u=Math.max(1,(s||24)-8),h=e.length,i=h>u?Math.min(Math.max(0,a-Math.floor(u/2)),h-u):0,c=Math.min(h,i+u);i>0&&l.push([span(""," "),span(C.gray,`↑ ${i} more above`)]);for(let n=i;n<c;n++){const s=e[n]||{},r=s.label||s.name||s.id||"",p=n===a,o=null!=t&&s.id===t,u=p?span(C.lavender,GLYPH.cursor):span(""," "),h=span(C.gray,`${n+1}.`),i=span(p?C.lavender:C.white,r),c=o?span(C.green," "+GLYPH.check):span("",""),d=" ".repeat(Math.max(1,22-[...r].length)),g="byok"!==s.cls||s.configured?"":"[key needed] ";l.push([span(""," "),u,span(""," "),h,span(""," "),i,c,span(C.gray,d+g+(s.note||s.model||""))])}return c<h&&l.push([span(""," "),span(C.gray,`↓ ${h-c} more below`)]),l.push(blank(n)),l.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(l,n)}const EFFORT_LEVELS=[{label:"Low",note:"Fastest, cheapest budget"},{label:"Medium",note:"Balanced"},{label:"High",note:"Highest budget, slowest (default)"}],EFFORT_VALUES=EFFORT_LEVELS.map((e=>void 0===e.value?e.label.toLowerCase():e.value));function renderEffortPicker(e=0,a=80,n=null,s=EFFORT_LEVELS){const t=[];t.push(blank(a)),t.push([span(""," "),span(C.white+BOLD,"Select effort"),span(BOLD_OFF,"")]),t.push([span(""," "),span(C.gray,"Sets the token budget the pool sizes each turn from.")]),t.push(blank(a));for(let a=0;a<s.length;a++){const r=s[a],p=a===e,l=String(n||"high").toLowerCase()===String(r.label).toLowerCase(),o=p?span(C.lavender,GLYPH.cursor):span(""," "),u=span(p?C.lavender:C.white,r.label),h=l?span(C.green," "+GLYPH.check):span("",""),i=" ".repeat(Math.max(1,12-[...r.label].length));t.push([span(""," "),o,span(""," "),u,h,span(C.gray,i+r.note)])}return t.push(blank(a)),t.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(t,a)}function renderClassPicker(e,a=0,n=80,s=null,t=null){const r=Array.isArray(e)?e:[],p=e=>("function"==typeof t?t(e):e)||e,l=[];l.push(blank(n)),l.push([span(""," "),span(C.white+BOLD,"Select class"),span(BOLD_OFF,"")]),l.push([span(""," "),span(C.gray,"Which route the next turn takes — who pays, and with which credential.")]),l.push(blank(n));for(let e=0;e<r.length;e++){const n=r[e]||{},t=n.class,o=e===a,u=null!=s&&t===s,h=o?span(C.lavender,GLYPH.cursor):span(""," "),i=p(t),c=span(o?C.lavender:C.white,i),d=u?span(C.green," "+GLYPH.check):span("",""),g=" ".repeat(Math.max(1,14-[...i].length)),
|
|
3
|
+
"use strict";const{span:span,padLine:padLine}=require("./screen.js"),{C:C,BOLD:BOLD,BOLD_OFF:BOLD_OFF,GLYPH:GLYPH}=require("./theme.js");let fuzzy=null;try{fuzzy=require("./fuzzy.js")}catch{fuzzy=null}function rankCommands(e,a){if(fuzzy&&"function"==typeof fuzzy.fuzzyRankWithAliases)return fuzzy.fuzzyRankWithAliases(e,a,(e=>e.name),(e=>e.aliases||[]));const n=String(e||"").toLowerCase();return n?a.filter((e=>`${e.name} ${(e.aliases||[]).join(" ")}`.toLowerCase().includes(n))):a}const descOf=e=>null!=e.help?e.help:null!=e.desc?e.desc:"",hintOf=e=>null!=e.hint?e.hint:null!=e.args?e.args:"";function fit(e,a){return e.map((e=>padLine(e,a)))}const blank=e=>[span(""," ".repeat(Math.max(0,e)))];function boldMatched(e,a,n){const s=fuzzy&&"function"==typeof fuzzy.fuzzyMatchPositions?fuzzy.fuzzyMatchPositions(e,a):[];if(!s||!s.length)return[span(n,a)];const t=[];let r=0;for(const e of s)e>r&&t.push(span(n,a.slice(r,e))),t.push(span(n+BOLD,a[e])),r=e+1;return r<a.length&&t.push(span(n,a.slice(r))),t}function renderPalette(e,a={},n=80,s=24){!Array.isArray(e)&&e&&"object"==typeof e&&(a=e,e=Array.isArray(e.commands)?e.commands:[]);const t=rankCommands(a.query||"",e||[]),r=Number.isInteger(a.sel)?a.sel:0,p=t.length,l=Math.max(1,Math.min(12,s-8)),o=Math.max(0,Math.min(r-Math.floor(l/2),Math.max(0,p-l))),u=t.slice(o,o+l),h=[];h.push(blank(n)),h.push([span(C.gray," "+"─".repeat(Math.max(10,n-4)))]);for(let e=0;e<u.length;e++){const n=u[e],s=o+e===r,t=s?span(C.lavender,GLYPH.cursor):span(""," "),p=s?C.blue:C.white,l=[span(p,"/"),...boldMatched(a.query||"",n.name,p)],i=" ".repeat(Math.max(1,22-[...n.name].length));h.push([span(""," "),t,span(""," "),...l,span(n.unavailable?C.dim:C.gray,i+descOf(n))]),s&&hintOf(n)&&h.push([span(""," "),span(C.gray,`${GLYPH.hook} Usage: /${n.name} ${hintOf(n)}`)])}for(;h.length<4+2*l;)h.push(blank(n));return h.push([span(C.gray," "+"─".repeat(Math.max(10,n-4)))]),h.push([span(C.gray,` type to filter ${GLYPH.bullet} shift+enter runs the top row ${GLYPH.bullet} enter runs ${GLYPH.bullet} esc closes`)]),fit(h,n)}const PICKER_HINT=`↑↓ or tab move ${GLYPH.bullet} enter pins ${GLYPH.bullet} shift+↑↓ pins at once ${GLYPH.bullet} esc cancels`;function renderModelPicker(e,a=0,n=80,s=24,t=null,r=null,p=null){const l=[],o="function"==typeof p&&r?p(r):null;l.push(blank(n)),l.push([span(""," "),span(C.white+BOLD,"Select model"),span(BOLD_OFF,""),...o?[span(C.gray,` — running on ${o}`)]:[]]),l.push([span(""," "),span(C.gray,"Switch between models. Your pick becomes the default for new sessions.")]),l.push([span(""," "),span(C.gray,"Nexus is pooled; any other row prompts for its provider key on pick.")]),l.push(blank(n));const u=Math.max(1,(s||24)-8),h=e.length,i=h>u?Math.min(Math.max(0,a-Math.floor(u/2)),h-u):0,c=Math.min(h,i+u);i>0&&l.push([span(""," "),span(C.gray,`↑ ${i} more above`)]);for(let n=i;n<c;n++){const s=e[n]||{},r=s.label||s.name||s.id||"",p=n===a,o=null!=t&&s.id===t,u=p?span(C.lavender,GLYPH.cursor):span(""," "),h=span(C.gray,`${n+1}.`),i=span(p?C.lavender:C.white,r),c=o?span(C.green," "+GLYPH.check):span("",""),d=" ".repeat(Math.max(1,22-[...r].length)),g="byok"!==s.cls||s.configured?"":"[key needed] ";l.push([span(""," "),u,span(""," "),h,span(""," "),i,c,span(C.gray,d+g+(s.note||s.model||""))])}return c<h&&l.push([span(""," "),span(C.gray,`↓ ${h-c} more below`)]),l.push(blank(n)),l.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(l,n)}const EFFORT_LEVELS=[{label:"Low",note:"Fastest, cheapest budget"},{label:"Medium",note:"Balanced"},{label:"High",note:"Highest budget, slowest (default)"},{label:"Max",note:"Deepest reasoning where the model defines it; same budget as high"}],EFFORT_VALUES=EFFORT_LEVELS.map((e=>void 0===e.value?e.label.toLowerCase():e.value));function renderEffortPicker(e=0,a=80,n=null,s=EFFORT_LEVELS){const t=[];t.push(blank(a)),t.push([span(""," "),span(C.white+BOLD,"Select effort"),span(BOLD_OFF,"")]),t.push([span(""," "),span(C.gray,"Sets the token budget the pool sizes each turn from.")]),t.push(blank(a));for(let a=0;a<s.length;a++){const r=s[a],p=a===e,l=String(n||"high").toLowerCase()===String(r.label).toLowerCase(),o=p?span(C.lavender,GLYPH.cursor):span(""," "),u=span(p?C.lavender:C.white,r.label),h=l?span(C.green," "+GLYPH.check):span("",""),i=" ".repeat(Math.max(1,12-[...r.label].length));t.push([span(""," "),o,span(""," "),u,h,span(C.gray,i+r.note)])}return t.push(blank(a)),t.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(t,a)}function renderClassPicker(e,a=0,n=80,s=null,t=null){const r=Array.isArray(e)?e:[],p=e=>("function"==typeof t?t(e):e)||e,l=[];l.push(blank(n)),l.push([span(""," "),span(C.white+BOLD,"Select class"),span(BOLD_OFF,"")]),l.push([span(""," "),span(C.gray,"Which route the next turn takes — who pays, and with which credential.")]),l.push(blank(n));for(let e=0;e<r.length;e++){const n=r[e]||{},t=n.class,o=e===a,u=null!=s&&t===s,h=o?span(C.lavender,GLYPH.cursor):span(""," "),i=p(t),c=span(o?C.lavender:C.white,i),d=u?span(C.green," "+GLYPH.check):span("",""),g=" ".repeat(Math.max(1,14-[...i].length)),f="byok"===t?n.configured?"your key, relayed by AEGIS — billed a handling fee":"needs a provider key: /byok-key <provider>":"the pool — your AEGIS account key pays for it";l.push([span(""," "),h,span(""," "),c,d,span(C.gray,g+f)])}return l.push(blank(n)),l.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(l,n)}function renderResumeList(e,a=0,n=80,s=24){const t=Array.isArray(e)?e:[],r=[];r.push(blank(n)),r.push([span(""," "),span(C.gray,"─".repeat(Math.max(10,n-4)))]),r.push([span(""," "),span(C.white+BOLD,"Resume session"),span(C.gray,` (${a+1} of ${Math.max(1,t.length)})`),span(BOLD_OFF,"")]);const p=Math.max(10,n-4);r.push([span(""," "),span(C.gray,"╭"+"─".repeat(Math.max(0,p-2))+"╮")]),r.push([span(""," "),span(C.gray,"│"),span(C.white,"⌕ Search…"),span(""," ".repeat(Math.max(0,p-9))),span(C.gray,"│")]),r.push([span(""," "),span(C.gray,"╰"+"─".repeat(Math.max(0,p-2))+"╯")]),r.push(blank(n));const l=Math.max(2,Math.min(6,s-16)),o=Math.max(0,Math.min(a-Math.floor(l/2),Math.max(0,t.length-l))),u=t.slice(o,o+l);for(let e=0;e<u.length;e++){const n=u[e]||{},s=o+e===a,t=s?span(C.lavender,GLYPH.cursor):span(""," "),p=n.own?span(C.green,GLYPH.star+" "):span(C.gray,GLYPH.bullet+" "),l=span(s?C.white+BOLD:C.white,n.summary||"(untitled)");r.push([span(""," "),t,span(""," "),p,l]),r.push([span(""," "),span(C.gray,`${n.cwd||"~"} ${GLYPH.bullet} ${ago(n.time)}`)])}for(;r.length<6+2*l;)r.push(blank(n));return r.push([span(""," "),span(C.gray,"─".repeat(Math.max(10,n-4)))]),r.push([span(""," "),span(C.gray,`Ctrl+A all projects ${GLYPH.bullet} Space to preview ${GLYPH.bullet} Type to search ${GLYPH.bullet} Esc to cancel`)]),fit(r,n)}function ago(e){if(!e)return"";const a=Date.now()-new Date(String(e)).getTime();return a>=0&&!Number.isNaN(a)?a<6e4?`${Math.max(1,Math.round(a/1e3))}s ago`:a<36e5?`${Math.round(a/6e4)}m ago`:a<864e5?`${Math.round(a/36e5)}h ago`:`${Math.round(a/864e5)}d ago`:""}function renderProviderPicker(e,a=0,n=80,s=null,t=null){const r=Array.isArray(e)?e:[],p=[];p.push(blank(n)),p.push([span(""," "),span(C.white+BOLD,"Select provider"),span(BOLD_OFF,"")]),p.push([span(""," "),span(C.gray,"Which vendor the key you are about to paste belongs to.")]),p.push(blank(n));for(let e=0;e<r.length;e++){const n=r[e]||{},t=String(n.id||"");if(!t)continue;const l=e===a,o=null!=s&&t===s,u=l?span(C.lavender,GLYPH.cursor):span(""," "),h=span(l?C.lavender:C.white,t),i=o?span(C.green," "+GLYPH.check):span("",""),c=String(n.label||""),d=" ".repeat(Math.max(1,16-[...t].length)),g=n.configured?span(C.green,"set"+(n.masked?` (${n.masked})`:"")):span(C.gray,"not set");p.push([span(""," "),u,span(""," "),h,i,span(C.gray,d+(c?`${c} · `:"")),g])}return p.push(blank(n)),p.push([span(""," "),span(C.gray,t||`↑↓ or tab move ${GLYPH.bullet} enter picks ${GLYPH.bullet} esc cancels`)]),fit(p,n)}module.exports={boldMatched:boldMatched,renderPalette:renderPalette,renderModelPicker:renderModelPicker,renderEffortPicker:renderEffortPicker,renderClassPicker:renderClassPicker,renderProviderPicker:renderProviderPicker,renderResumeList:renderResumeList,EFFORT_LEVELS:EFFORT_LEVELS,EFFORT_VALUES:EFFORT_VALUES,PICKER_HINT:PICKER_HINT};
|
|
@@ -1,3 +1,292 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
3
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
4
|
+
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
+
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
// The silent gate, loaded directly rather than trusted to have been asked by
|
|
9
|
+
// somebody up the call stack. FAIL CLOSED if it cannot be loaded at all: a tree
|
|
10
|
+
// with no `src/limits.js` is a tree someone edited to remove the question, and
|
|
11
|
+
// "the checker is missing" must read as "not the published build" for the same
|
|
12
|
+
// reason `src/provenance.js` treats a missing manifest as a failure and not a
|
|
13
|
+
// pass. Note what this deliberately does NOT do: it never throws, and it never
|
|
14
|
+
// stops `resolveSkip` from returning a decision — it only ever takes the skip
|
|
15
|
+
// away, so the worst a broken gate can cause is a confirmation prompt.
|
|
16
|
+
const limits = (() => {
|
|
17
|
+
try {
|
|
18
|
+
return require('./limits.js');
|
|
19
|
+
} catch {
|
|
20
|
+
return { armed: () => true, refuse: () => 1, check: () => ({ tripped: true, code: 'p2', units: 0 }) };
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Real enforcement for the /permissions rules (src/config.js) in the
|
|
26
|
+
* direct-provider tool loop. The `claude` CLI path already has its own real
|
|
27
|
+
* approval UX from the real binary, so this only applies to
|
|
28
|
+
* Bash/Read/Write/Edit/Glob/Grep run by a provider model.
|
|
29
|
+
*
|
|
30
|
+
* Scope decision: the multi-directory-change Bash heuristic,
|
|
31
|
+
* explicit /permissions allow|deny|ask rules, and `defaultMode: 'ask'` when
|
|
32
|
+
* the permissions file *explicitly* writes it (rules.explicitAsk) are
|
|
33
|
+
* enforced here. The file-free default ('ask' in DEFAULT_PERMISSIONS) is
|
|
34
|
+
* NOT consulted — honoring the implicit default would prompt on every tool
|
|
35
|
+
* call out of the box and make the agentic loop unusable by default.
|
|
36
|
+
* /confirm and /yolo still toggle defaultMode for the explicit case.
|
|
37
|
+
*
|
|
38
|
+
* Not tools.js's Glob-tool globToRegex: that one is filesystem-glob (`*`
|
|
39
|
+
* stops at `/`, matching one path segment) because it walks a directory
|
|
40
|
+
* tree. Rule subjects here are just as often a Bash command string, where
|
|
41
|
+
* `/` is ordinary text ("rm -rf /tmp/x") — a `Bash(npm run *)` rule (see
|
|
42
|
+
* DEFAULT_PERMISSIONS's own example) needs `*` to match the rest of the
|
|
43
|
+
* line, slashes included. So `*` and `?` here are plain "match anything"
|
|
44
|
+
* wildcards, not path-segment-bounded ones; reimplemented rather than
|
|
45
|
+
* imported so this module has no import-cycle with tools.js (executeTool's
|
|
46
|
+
* home, which calls into this one).
|
|
47
|
+
*
|
|
48
|
+
* Ported from the upstream engine reference (ESM → CommonJS).
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
const RULE_RE = /^(\w+)(?:\((.*)\))?$/;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Tool-name aliases. The shipped engine (desktop/lib/local/tools.js) names its
|
|
55
|
+
* tools readFile/writeFile/editFile/listDir/glob/grep/exec/task, while this
|
|
56
|
+
* module was ported from the reference and keyed on that CLI's names —
|
|
57
|
+
* Read/Write/Edit/Glob/Grep/Bash/Task. Those reference names are also what
|
|
58
|
+
* users write into /permissions, so both spellings must fold onto one
|
|
59
|
+
* capability. Keying on the reference's spelling alone meant subjectFor()
|
|
60
|
+
* returned '' for every tool the engine actually calls: `exec(git *)` never
|
|
61
|
+
* matched its subject, `Read(*.env)` never matched a readFile, and the
|
|
62
|
+
* multi-directory rail never fired — a permission system blind to the very
|
|
63
|
+
* tools it was meant to govern.
|
|
64
|
+
*/
|
|
65
|
+
const TOOL_ALIAS = {
|
|
66
|
+
exec: 'shell', Bash: 'shell',
|
|
67
|
+
readFile: 'read', Read: 'read',
|
|
68
|
+
writeFile: 'write', Write: 'write',
|
|
69
|
+
editFile: 'edit', Edit: 'edit',
|
|
70
|
+
listDir: 'list', LS: 'list',
|
|
71
|
+
glob: 'glob', Glob: 'glob',
|
|
72
|
+
grep: 'grep', Grep: 'grep',
|
|
73
|
+
task: 'task', Task: 'task',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Fold either registry's name for a tool onto the capability it names. */
|
|
77
|
+
function canonTool(name) {
|
|
78
|
+
const key = String(name == null ? '' : name);
|
|
79
|
+
return TOOL_ALIAS[key] || key;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** True for the engine's `exec` and the reference's `Bash` alike. */
|
|
83
|
+
function isShellTool(toolName) {
|
|
84
|
+
return canonTool(toolName) === 'shell';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function globToRegex(pattern) {
|
|
88
|
+
let re = '^';
|
|
89
|
+
for (const c of pattern) {
|
|
90
|
+
if (c === '*') re += '.*';
|
|
91
|
+
else if (c === '?') re += '.';
|
|
92
|
+
else if (/[.+^${}()|[\]\\]/.test(c)) re += `\\${c}`;
|
|
93
|
+
else re += c;
|
|
94
|
+
}
|
|
95
|
+
return new RegExp(re + "$");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The subject a rule's pattern matches against, per tool. */
|
|
99
|
+
function subjectFor(toolName, args = {}) {
|
|
100
|
+
switch (canonTool(toolName)) {
|
|
101
|
+
case 'shell': return String(args.command || '');
|
|
102
|
+
case 'read': case 'write': case 'edit': return String(args.file_path || '');
|
|
103
|
+
case 'glob': case 'grep': return String(args.pattern || '');
|
|
104
|
+
case 'list': return String(args.path || '');
|
|
105
|
+
default: return '';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function matchRule(rule, toolName, subject) {
|
|
110
|
+
const m = RULE_RE.exec(String(rule || '').trim());
|
|
111
|
+
if (!m) return false;
|
|
112
|
+
const [, tool, pattern] = m;
|
|
113
|
+
// A rule spelled with the reference's name governs the engine's tool and
|
|
114
|
+
// vice versa: `Bash(git *)` and `exec(git *)` are one rule, not two.
|
|
115
|
+
if (canonTool(tool) !== canonTool(toolName)) return false;
|
|
116
|
+
if (pattern === undefined) return true; // bare "Bash"/"exec" matches every call
|
|
117
|
+
try { return globToRegex(pattern).test(subject); } catch { return false; }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const matchesAny = (list, toolName, subject) =>
|
|
121
|
+
Array.isArray(list) && list.some((r) => matchRule(r, toolName, subject));
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A Bash command that changes directory more than once needs a second look:
|
|
125
|
+
* each `&&`/`;`/`|`/newline-separated segment starting with `cd` counts.
|
|
126
|
+
* Mirrors the captured Claude Code 2.1.228 heuristic ("Multiple directory
|
|
127
|
+
* changes in one command require approval for clarity") — a hardcoded UX
|
|
128
|
+
* safety rail, not a configurable rule.
|
|
129
|
+
*/
|
|
130
|
+
function isMultiDirCommand(command) {
|
|
131
|
+
const segments = String(command || '').split(/&&|\|\||;|\n/).map((s) => s.trim());
|
|
132
|
+
const cdCount = segments.filter((s) => /^cd(\s|$)/.test(s)).length;
|
|
133
|
+
return cdCount > 1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Evaluate a tool call against the persisted /permissions rules.
|
|
138
|
+
* Returns 'allow' | 'deny' | 'ask'. Precedence: an explicit deny rule always
|
|
139
|
+
* wins (a security floor). An explicit allow rule is the real "always
|
|
140
|
+
* allow" escape hatch, so it's checked next and suppresses the multi-cd
|
|
141
|
+
* heuristic below it — same as upstream, where an always-allow rule for
|
|
142
|
+
* Bash stops it asking again. With no allow rule, the multi-cd heuristic
|
|
143
|
+
* forces 'ask' on its own; then explicit ask rules. Anything left
|
|
144
|
+
* unmatched falls through to rules.explicitAsk (an explicitly written
|
|
145
|
+
* `defaultMode: 'ask'` prompts on the residual); otherwise 'allow' — see
|
|
146
|
+
* the scope note above, the implicit defaultMode is intentionally not
|
|
147
|
+
* consulted.
|
|
148
|
+
*/
|
|
149
|
+
function evalPermission(toolName, args, rules = {}) {
|
|
150
|
+
const subject = subjectFor(toolName, args);
|
|
151
|
+
if (matchesAny(rules.deny, toolName, subject)) return 'deny';
|
|
152
|
+
if (matchesAny(rules.allow, toolName, subject)) return 'allow';
|
|
153
|
+
if (isShellTool(toolName) && isMultiDirCommand(args && args.command)) return 'ask';
|
|
154
|
+
if (matchesAny(rules.ask, toolName, subject)) return 'ask';
|
|
155
|
+
if (rules.explicitAsk && rules.defaultMode === 'ask') return 'ask';
|
|
156
|
+
return 'allow';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ── "Skip permissions", resolved ONCE (AEGISONE, D8 rules 3 and 5) ──────────
|
|
160
|
+
//
|
|
161
|
+
// One resolver, two callers: `one/src/permissions.js` (the product's posture,
|
|
162
|
+
// which feeds a spawned Claude child's argv) and `cli/src/app.js` (this face's
|
|
163
|
+
// own confirmation gate). It lives HERE, beside `evalPermission`, so the rule
|
|
164
|
+
// engine and the skip resolver are one module rather than two spellings that
|
|
165
|
+
// can drift — the same reason D8 keeps one rule language.
|
|
166
|
+
//
|
|
167
|
+
// The three sources, and why they are three:
|
|
168
|
+
//
|
|
169
|
+
// flag `--dangerously-skip-permissions`, typed by a human. Always
|
|
170
|
+
// honored: it is the whole point of the flag, and rule 3 requires
|
|
171
|
+
// a one-line report of what it skipped (the caller prints it).
|
|
172
|
+
// productEnv `AEGISONE_SKIP_PERMISSIONS`, set by the `aegis` bin ONLY after
|
|
173
|
+
// it resolved the posture for the child it is about to spawn —
|
|
174
|
+
// i.e. the flag, already checked against rule 5. That indirection
|
|
175
|
+
// is what lets the terminal face honor `aegis … --dangerously-
|
|
176
|
+
// skip-permissions` without the face ever reading the *user's*
|
|
177
|
+
// environment for a skip it was not asked for.
|
|
178
|
+
// env `AEGIS_SKIP_PERMISSIONS`, the CI/queue spelling. It equals the
|
|
179
|
+
// flag only when the process is NON-interactive: a stray `export`
|
|
180
|
+
// in a shell profile must not be able to disarm a human's own
|
|
181
|
+
// gate (rule 5). Interactive + unasked ⇒ warn and ignore.
|
|
182
|
+
//
|
|
183
|
+
// It never returns why something was skipped beyond naming its source: what a
|
|
184
|
+
// skip DOES cover is rule 2's business, and rule 2's floors (the covenant
|
|
185
|
+
// assert and the four level-independent approvals) are not reachable from here
|
|
186
|
+
// at all.
|
|
187
|
+
const SKIP = Object.freeze({
|
|
188
|
+
flag: '--dangerously-skip-permissions',
|
|
189
|
+
env: 'AEGIS_SKIP_PERMISSIONS',
|
|
190
|
+
productEnv: 'AEGISONE_SKIP_PERMISSIONS',
|
|
191
|
+
truthy: Object.freeze(['1', 'true', 'yes', 'on']),
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const isTruthyEnv = (v) => v !== undefined && SKIP.truthy.includes(String(v).trim().toLowerCase());
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The mark an interlock-failed build carries (`AEGIS_REDUCED_MODE`, set in
|
|
198
|
+
* bin/aegiscode.js from src/limits.js). A build that is not the published one
|
|
199
|
+
* does not get to disarm the confirmation gate — from the flag, from the
|
|
200
|
+
* product env or from the CI env. That is the whole payoff of editing this
|
|
201
|
+
* file, so it is the one thing this file will not do when it is not itself.
|
|
202
|
+
*
|
|
203
|
+
* Read from the caller's env AND from process.env, because the two callers
|
|
204
|
+
* differ: `one/src/permissions.js` passes an env it assembled, and the mark is
|
|
205
|
+
* set on the process. Deliberately not documented anywhere a manipulator would
|
|
206
|
+
* read before deciding what to edit next.
|
|
207
|
+
*
|
|
208
|
+
* …and asked for directly, through `limits.armed()`, rather than only read off
|
|
209
|
+
* the environment. Reading the mark alone made this file's refusal depend on
|
|
210
|
+
* somebody else's call: delete the one line in `bin/aegiscode.js` that sets it
|
|
211
|
+
* and `--dangerously-skip-permissions` starts working again on a build that is
|
|
212
|
+
* not the published one. The question is now asked HERE, by the module that owns
|
|
213
|
+
* the privilege, and the answer is memoised in src/limits.js — so the same edit
|
|
214
|
+
* buys nothing, and a scrubbed `input.env` cannot spoof the answer either.
|
|
215
|
+
*/
|
|
216
|
+
function reducedMode(input = {}) {
|
|
217
|
+
const env = input.env || {};
|
|
218
|
+
if (isTruthyEnv(env.AEGIS_REDUCED_MODE) || isTruthyEnv(process.env.AEGIS_REDUCED_MODE)) return true;
|
|
219
|
+
return limits.armed();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Rule 5's warning, spelled once so both callers print the same sentence. */
|
|
223
|
+
const SKIP_ENV_WARNING =
|
|
224
|
+
`AEGIS_SKIP_PERMISSIONS is set but this session is interactive — ignoring it. ` +
|
|
225
|
+
`Pass --dangerously-skip-permissions to skip the configurable gates on purpose; ` +
|
|
226
|
+
`the ÆGIS covenant and the write|shell|network|offDevice approvals are never skipped.`;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @param {object} [input]
|
|
230
|
+
* @param {boolean} [input.flag] the flag was explicitly passed
|
|
231
|
+
* @param {object} [input.env] environment to read (never mutated)
|
|
232
|
+
* @param {boolean} [input.interactive] both stdio ends are a terminal
|
|
233
|
+
* @returns {{skip: boolean, source: 'flag'|'product'|'env'|'env-ignored'|'reduced'|'none',
|
|
234
|
+
* flag: boolean, envSet: boolean, interactive: boolean,
|
|
235
|
+
* warned: boolean, warning: string|null}}
|
|
236
|
+
*/
|
|
237
|
+
function resolveSkip(input = {}) {
|
|
238
|
+
const flag = input.flag === true;
|
|
239
|
+
const env = input.env || {};
|
|
240
|
+
const interactive = input.interactive === true;
|
|
241
|
+
const envSet = isTruthyEnv(env[SKIP.env]);
|
|
242
|
+
const productSet = isTruthyEnv(env[SKIP.productEnv]);
|
|
243
|
+
|
|
244
|
+
// A build that failed the interlock never skips, whatever it was asked: the
|
|
245
|
+
// flag and both env spellings are refused at the source, so the confirm gate
|
|
246
|
+
// is the one thing a modified build cannot switch off. Reported as its own
|
|
247
|
+
// source so a caller does not print "the user asked for this".
|
|
248
|
+
if (reducedMode(input)) {
|
|
249
|
+
return { skip: false, source: 'reduced', flag, envSet, interactive, warned: false, warning: null };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src: flag → product → env(non-interactive). No `catch`-all default that
|
|
253
|
+
// could skip: every other path returns skip: false.
|
|
254
|
+
if (flag || productSet) {
|
|
255
|
+
return {
|
|
256
|
+
skip: true,
|
|
257
|
+
source: flag ? 'flag' : 'product',
|
|
258
|
+
flag,
|
|
259
|
+
envSet,
|
|
260
|
+
interactive,
|
|
261
|
+
warned: false,
|
|
262
|
+
warning: null,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
if (envSet && !interactive) {
|
|
266
|
+
return { skip: true, source: 'env', flag, envSet, interactive, warned: false, warning: null };
|
|
267
|
+
}
|
|
268
|
+
if (envSet && interactive) {
|
|
269
|
+
return {
|
|
270
|
+
skip: false,
|
|
271
|
+
source: 'env-ignored',
|
|
272
|
+
flag,
|
|
273
|
+
envSet,
|
|
274
|
+
interactive,
|
|
275
|
+
warned: true,
|
|
276
|
+
warning: SKIP_ENV_WARNING,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
return { skip: false, source: 'none', flag, envSet: false, interactive, warned: false, warning: null };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
module.exports = {
|
|
283
|
+
canonTool,
|
|
284
|
+
isShellTool,
|
|
285
|
+
subjectFor,
|
|
286
|
+
matchRule,
|
|
287
|
+
isMultiDirCommand,
|
|
288
|
+
evalPermission,
|
|
289
|
+
SKIP,
|
|
290
|
+
SKIP_ENV_WARNING,
|
|
291
|
+
resolveSkip,
|
|
292
|
+
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
3
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
4
|
+
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
+
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
4
8
|
/**
|
|
5
9
|
* provenance — who this program is, and whether it is still the program that
|
|
6
10
|
* was published.
|
|
@@ -55,4 +59,180 @@
|
|
|
55
59
|
* so absence is reported (`unverifiable`) instead of being read as "nothing
|
|
56
60
|
* configured". `AEGIS_NO_PROVENANCE_CHECK=1` silences it for a development tree
|
|
57
61
|
* that is mid-edit — loudly, and by name, so it is never the quiet path.
|
|
58
|
-
*/
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
const { createHash } = require('node:crypto');
|
|
65
|
+
const { existsSync, readFileSync } = require('node:fs');
|
|
66
|
+
const path = require('node:path');
|
|
67
|
+
const limits = require('./limits.js');
|
|
68
|
+
|
|
69
|
+
/** Everything a copy would have to change to look like its own product. */
|
|
70
|
+
const IDENTITY = Object.freeze({
|
|
71
|
+
product: 'AEGIS Code',
|
|
72
|
+
bin: 'aegiscode',
|
|
73
|
+
license: 'AGPL-3.0-or-later',
|
|
74
|
+
copyright: 'Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.',
|
|
75
|
+
source: 'https://github.com/aegisinfo/aegiscode-plugin',
|
|
76
|
+
homepage: 'https://aegiscloud.org',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The sealed set: id → path. This table is the mapping the manifest refuses to
|
|
81
|
+
* carry, and the only reason a report can say `p3` at all. Keep it in step with
|
|
82
|
+
* `tools/provenance.mjs`, which writes both halves from it.
|
|
83
|
+
*/
|
|
84
|
+
const UNITS = Object.freeze([
|
|
85
|
+
Object.freeze({ id: 'p1', rel: 'bin/aegiscode.js' }),
|
|
86
|
+
Object.freeze({ id: 'p2', rel: 'src/provenance.js' }),
|
|
87
|
+
Object.freeze({ id: 'p3', rel: 'src/gate.js' }),
|
|
88
|
+
Object.freeze({ id: 'p4', rel: 'src/permissions.js' }),
|
|
89
|
+
Object.freeze({ id: 'p5', rel: 'src/caps.js' }),
|
|
90
|
+
Object.freeze({ id: 'p6', rel: 'src/autonomous.js' }),
|
|
91
|
+
Object.freeze({ id: 'p7', rel: 'src/limits.js' }),
|
|
92
|
+
Object.freeze({ id: 'p8', rel: 'src/mcp.js' }),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
const PACKAGE_ROOT = path.join(__dirname, '..');
|
|
96
|
+
const MANIFEST_FILE = path.join(__dirname, 'provenance.lock.json');
|
|
97
|
+
|
|
98
|
+
const sha256 = (data) => createHash('sha256').update(data).digest('hex');
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Read the shipped manifest. Two shapes are accepted:
|
|
102
|
+
*
|
|
103
|
+
* - current: `{ v: 1, alg: 'sha256', units: { p1: '<hex>', … } }` — ids only,
|
|
104
|
+
* no paths, nothing to read off the file except which digests moved;
|
|
105
|
+
* - legacy: `{ files: { '<rel path>': '<hex>' } }` — still honoured so a
|
|
106
|
+
* package built from an older tree can still be checked, and still reported
|
|
107
|
+
* by id rather than by path.
|
|
108
|
+
*/
|
|
109
|
+
function readManifest() {
|
|
110
|
+
try {
|
|
111
|
+
const parsed = JSON.parse(readFileSync(MANIFEST_FILE, 'utf8'));
|
|
112
|
+
if (!parsed) return null;
|
|
113
|
+
if (parsed.units && typeof parsed.units === 'object') {
|
|
114
|
+
return { units: parsed.units, legacyPaths: null };
|
|
115
|
+
}
|
|
116
|
+
if (parsed.files && typeof parsed.files === 'object') {
|
|
117
|
+
return { units: parsed.files, legacyPaths: parsed.files };
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Resolve a unit's expected digest, in either manifest shape. */
|
|
126
|
+
function expectedFor(manifest, unit) {
|
|
127
|
+
if (!manifest) return undefined;
|
|
128
|
+
if (manifest.legacyPaths) return manifest.legacyPaths[unit.rel];
|
|
129
|
+
return manifest.units[unit.id];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Compare this install's safety files to the shipped manifest.
|
|
134
|
+
*
|
|
135
|
+
* Never throws: this is a diagnostic, and a diagnostic that can break the
|
|
136
|
+
* program it is reporting on is worse than no diagnostic.
|
|
137
|
+
*
|
|
138
|
+
* Reports unit ids, never paths. See the header for why the difference matters.
|
|
139
|
+
*
|
|
140
|
+
* @returns {{ ok: boolean, checked: number, problems: string[], unverifiable: boolean }}
|
|
141
|
+
*/
|
|
142
|
+
function selfCheck() {
|
|
143
|
+
const manifest = readManifest();
|
|
144
|
+
if (!manifest) {
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
checked: 0,
|
|
148
|
+
problems: [`${path.basename(MANIFEST_FILE)} is missing or unreadable`],
|
|
149
|
+
unverifiable: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const problems = [];
|
|
153
|
+
let checked = 0;
|
|
154
|
+
for (const unit of UNITS) {
|
|
155
|
+
const abs = path.join(PACKAGE_ROOT, unit.rel);
|
|
156
|
+
if (!existsSync(abs)) {
|
|
157
|
+
problems.push(`${unit.id}: sealed unit missing from this install`);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const actual = sha256(readFileSync(abs));
|
|
162
|
+
checked++;
|
|
163
|
+
const expected = expectedFor(manifest, unit);
|
|
164
|
+
if (expected && actual !== expected) problems.push(`${unit.id}: digest moved`);
|
|
165
|
+
} catch {
|
|
166
|
+
problems.push(`${unit.id}: unreadable`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return { ok: problems.length === 0, checked, problems, unverifiable: false };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The one stderr line worth writing, or null when everything is as published.
|
|
174
|
+
*
|
|
175
|
+
* It names ids and counts. It does not name files, does not describe what those
|
|
176
|
+
* files do, and does not say how to re-seal: those three sentences are exactly
|
|
177
|
+
* what a tampered build would otherwise hand its author for free.
|
|
178
|
+
*
|
|
179
|
+
* A development tree can silence it with AEGIS_NO_PROVENANCE_CHECK=1; the
|
|
180
|
+
* silence is printed too, because a control that can be switched off quietly is
|
|
181
|
+
* not a control.
|
|
182
|
+
*/
|
|
183
|
+
function warning(report) {
|
|
184
|
+
if (!report || report.ok) return null;
|
|
185
|
+
if (process.env.AEGIS_NO_PROVENANCE_CHECK) {
|
|
186
|
+
return `aegiscode: provenance check SKIPPED (AEGIS_NO_PROVENANCE_CHECK is set): ${report.problems[0]}\n`;
|
|
187
|
+
}
|
|
188
|
+
return (
|
|
189
|
+
`aegiscode: provenance — ${report.problems.length} sealed unit${
|
|
190
|
+
report.problems.length === 1 ? '' : 's'
|
|
191
|
+
} do not match the published manifest (${IDENTITY.license}):\n` +
|
|
192
|
+
report.problems.map((p) => `aegiscode: ${p}\n`).join('') +
|
|
193
|
+
'aegiscode: this build is not the published one; do not trust what it reports about itself.\n'
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The human-readable answer for `aegiscode provenance`. */
|
|
198
|
+
function describe({ version } = {}) {
|
|
199
|
+
const report = selfCheck();
|
|
200
|
+
const lines = [
|
|
201
|
+
`${IDENTITY.product} (${IDENTITY.bin})${version ? ` ${version}` : ''} — ${IDENTITY.license}`,
|
|
202
|
+
`source: ${IDENTITY.source}`,
|
|
203
|
+
`homepage: ${IDENTITY.homepage}`,
|
|
204
|
+
IDENTITY.copyright,
|
|
205
|
+
];
|
|
206
|
+
// The identity half is MEANT to be read — it is the notice that has to travel
|
|
207
|
+
// with a copy, and withholding it would defeat the licence half of this file.
|
|
208
|
+
// The integrity half is not. A build that failed the silent gate does not get
|
|
209
|
+
// to report on itself: it is told exactly as much as any other module is
|
|
210
|
+
// (src/limits.js, "reduced mode"), and the ids it would otherwise print stay
|
|
211
|
+
// here. Asked through limits.armed() rather than trusting the caller, so that
|
|
212
|
+
// deleting the entry point's own refusal does not hand this back — the guard
|
|
213
|
+
// lives in a file the sealed set covers.
|
|
214
|
+
if (limits.armed()) {
|
|
215
|
+
lines.push('safety: reduced mode — this build is not the one that was published.');
|
|
216
|
+
return {
|
|
217
|
+
text: lines.join('\n') + '\n',
|
|
218
|
+
ok: false,
|
|
219
|
+
report: { ok: false, checked: report.checked, problems: [], unverifiable: report.unverifiable, withheld: true },
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (report.ok) {
|
|
223
|
+
lines.push(`safety: ${report.checked} sealed units verified`);
|
|
224
|
+
} else if (report.unverifiable) {
|
|
225
|
+
lines.push(`safety: UNVERIFIABLE — ${report.problems[0]}`);
|
|
226
|
+
} else {
|
|
227
|
+
lines.push(`safety: ${report.problems.length} sealed unit(s) do not match the published manifest:`);
|
|
228
|
+
for (const p of report.problems) lines.push(` ${p}`);
|
|
229
|
+
}
|
|
230
|
+
return { text: lines.join('\n') + '\n', ok: report.ok, report };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** The id→path mapping, for the development tool only. Never called at runtime. */
|
|
234
|
+
function sealMap() {
|
|
235
|
+
return UNITS.map((u) => ({ id: u.id, rel: u.rel }));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = { IDENTITY, UNITS, MANIFEST_FILE, selfCheck, warning, describe, sealMap };
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"license": "AGPL-3.0-or-later",
|
|
25
25
|
"source": "https://github.com/aegisinfo/aegiscode-plugin",
|
|
26
26
|
"units": {
|
|
27
|
-
"p1": "
|
|
27
|
+
"p1": "909ac3005c25322fe6eeb99c817788c78699cac339482ebbfd2ebc16b3db5ad9",
|
|
28
28
|
"p2": "d63d147de5455eea111d000b748d7eef9572a11a08d31f2471d5ff146701342c",
|
|
29
29
|
"p3": "ff962ac8dbf42cecb2477e2f77bf5ec61f88aa1751b0d4e506bf030fbc5fc6c6",
|
|
30
30
|
"p4": "2e8385c3a653a2af324050b4b92aeb9d142fc6765c91a13ccc928c5d4a2dbedb",
|
|
31
31
|
"p5": "408d67f78f31f6d637a26d2852e0c809a260544e613afdc64b731401c0ba3801",
|
|
32
32
|
"p6": "22bcd0b5dc1afad8d870652fbf1fd25bd0a547be9d8700161449cafa35bab6eb",
|
|
33
|
-
"p7": "
|
|
33
|
+
"p7": "e1f4a85e7e7b38a043111aaf98d0d2703340fd5bc6919923beb1a3539355aa46",
|
|
34
34
|
"p8": "3cc054d06715e065fe635b37b7d1bb98bf7989d64453a572ddbb77cec5b830e7"
|
|
35
35
|
}
|
|
36
36
|
}
|