aegisone 1.0.57 → 1.0.59
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 +4 -2
- package/package.json +3 -2
- package/scripts/predist.mjs +1 -1
- package/src/doctor.js +1 -1
- package/vendor/cli/README.md +2 -2
- package/vendor/cli/package.json +1 -1
- package/vendor/cli/src/app.js +1 -1
- package/vendor/cli/src/commands.js +2 -2
- package/vendor/cli/src/config.js +1 -1
- package/vendor/cli/src/panels.js +1 -1
- package/vendor/cli/vendor/client/model-autosync.js +3 -0
- package/vendor/cli/vendor/client/model-sync.js +3 -0
- package/vendor/cli/vendor/client/prefs.js +1 -1
- package/vendor/cli/vendor/client/skills.js +3 -0
- package/vendor/cli/vendor/client/speech.js +3 -0
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/integrity.js +1 -1
- package/vendor/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +6 -6
- package/vendor/cli/vendor/desktop/lib/local/sandbox-bwrap.js +7 -7
- package/vendor/cli/vendor/desktop/lib/local/sandbox.js +17 -11
- package/vendor/cli/vendor/desktop/main.js +406 -2
- package/vendor/cli/vendor/one/src/iface/pty.js +3 -0
- package/vendor/cli/vendor/one/src/protocol.js +3 -0
- package/vendor/desktop/lib/local/cli-face.js +1 -1
- package/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/desktop/lib/local/integrity.js +1 -1
- package/vendor/desktop/lib/local/pty-host.js +3 -0
- package/vendor/desktop/lib/local/sandbox-appcontainer.js +6 -6
- package/vendor/desktop/lib/local/sandbox-bwrap.js +7 -7
- package/vendor/desktop/lib/local/sandbox.js +17 -11
- package/vendor/desktop/lib/skills-host.js +3 -0
- package/vendor/desktop/lib/speech-host.js +3 -0
- package/vendor/desktop/lib/speech-resolve.js +3 -0
- package/vendor/desktop/main.js +406 -2
- package/vendor/desktop/package.json +4 -3
- package/vendor/desktop/preload.js +1 -1
- package/vendor/desktop/renderer/app.js +3 -3
- package/vendor/desktop/renderer/avatar/avatar.css +29 -1
- package/vendor/desktop/renderer/avatar/pane.js +1 -1
- package/vendor/desktop/renderer/dictation.js +3 -0
- package/vendor/desktop/renderer/index.html +200 -2
- package/vendor/desktop/renderer/pty-panel.js +3 -0
- package/vendor/desktop/renderer/settings-skills.js +3 -0
- package/vendor/desktop/renderer/style.css +230 -0
- package/vendor/desktop/renderer/vendor/NOTICE.md +10 -2
- package/vendor/desktop/renderer/vendor/xterm.css +285 -0
- package/vendor/desktop/renderer/vendor/xterm.js +1 -0
- package/vendor/desktop/vendor/faces/cli/README.md +2 -2
- package/vendor/desktop/vendor/faces/cli/package.json +1 -1
- package/vendor/desktop/vendor/faces/cli/src/app.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/commands.js +2 -2
- package/vendor/desktop/vendor/faces/cli/src/config.js +1 -1
- package/vendor/desktop/vendor/faces/cli/src/panels.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/model-autosync.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/client/model-sync.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/client/prefs.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/client/skills.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/client/speech.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/engine.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/integrity.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-appcontainer.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox-bwrap.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/sandbox.js +1 -1
- package/vendor/desktop/vendor/faces/cli/vendor/desktop/main.js +3 -3
- package/vendor/desktop/vendor/faces/cli/vendor/one/src/iface/pty.js +3 -0
- package/vendor/desktop/vendor/faces/cli/vendor/one/src/protocol.js +3 -0
- package/vendor/desktop/vendor/model-autosync.js +3 -0
- package/vendor/desktop/vendor/model-sync.js +3 -0
- package/vendor/desktop/vendor/prefs.js +1 -1
- package/vendor/desktop/vendor/protocol.js +3 -0
- package/vendor/desktop/vendor/pty.js +3 -0
- package/vendor/desktop/vendor/skills.js +3 -0
- package/vendor/desktop/vendor/speech.js +3 -0
|
@@ -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","permissionMode","sandboxPolicy","devMode","accountUsername"]),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","modelAutoSync","effort","vim","memoryPersist","confirmMode","permissionMode","sandboxPolicy","devMode","speech","accountUsername"]),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};
|
|
@@ -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 PROTO=1,METHODS=Object.freeze(["hello","exec","event","cancel"]),CAPS=Object.freeze({EXEC:"exec",EVENT:"event",CANCEL:"cancel",PTY:"pty"}),CODE=Object.freeze({BAD_JSON:"bad_json",BAD_FRAME:"bad_frame",UNKNOWN_METHOD:"unknown_method",PROTO_MISMATCH:"proto_mismatch",HELLO_REQUIRED:"hello_required",CAPABILITY_MISSING:"capability_missing",UNSUPPORTED:"unsupported"});function request(e,o,t){return{id:e,m:String(o),p:t&&"object"==typeof t?t:{}}}function ok(e,o){return{id:e,ok:!0,r:o&&"object"==typeof o?o:{}}}function err(e,o,t){return{id:e,ok:!1,e:{code:String(o||CODE.UNSUPPORTED),msg:String(t||"")}}}function isObject(e){return Boolean(e)&&"object"==typeof e&&!Array.isArray(e)}function validate(e){return isObject(e)?void 0===e.id||null===e.id?{ok:!1,code:CODE.BAD_FRAME,msg:"frame has no id"}:void 0!==e.ok?!0===e.ok?void 0!==e.e?{ok:!1,code:CODE.BAD_FRAME,msg:"reply carries both r and e"}:{ok:!0}:!1===e.ok?isObject(e.e)&&e.e.code?{ok:!0}:{ok:!1,code:CODE.BAD_FRAME,msg:"a failed reply must name a code"}:{ok:!1,code:CODE.BAD_FRAME,msg:"ok must be true or false"}:"string"==typeof e.m&&METHODS.includes(e.m)?void 0===e.p||isObject(e.p)?{ok:!0}:{ok:!1,code:CODE.BAD_FRAME,msg:"params must be an object"}:{ok:!1,code:CODE.UNKNOWN_METHOD,msg:`unknown method: ${String(e.m)}`}:{ok:!1,code:CODE.BAD_FRAME,msg:"frame must be an object"}}function negotiate(e,o){const t=o||{},r=validate(e);if(!r.ok)return{ok:!1,code:r.code,msg:r.msg};if("hello"!==e.m)return{ok:!1,code:CODE.HELLO_REQUIRED,msg:`the first frame must be hello, got ${String(e.m)}`};const n=e.p||{};if(1!==n.proto)return{ok:!1,code:CODE.PROTO_MISMATCH,msg:`peer speaks protocol ${String(n.proto)}, this build speaks 1`};const i=Array.isArray(n.caps)?n.caps.map(String):[],s=(Array.isArray(t.requireCaps)?t.requireCaps.map(String):[]).filter((e=>!i.includes(e)));return s.length?{ok:!1,code:CODE.CAPABILITY_MISSING,msg:`peer does not offer: ${s.join(", ")}`}:{ok:!0,proto:1,caps:i}}function hello(e){return request(void 0===e?0:e,"hello",{proto:1,caps:[CAPS.EXEC,CAPS.EVENT,CAPS.CANCEL]})}function encode(e){return`${JSON.stringify(e)}\n`}function decodeLine(e){const o=String(null==e?"":e).trim();if(!o)return{ok:!1,id:null,code:CODE.BAD_JSON,msg:"empty line"};let t;try{t=JSON.parse(o)}catch(e){return{ok:!1,id:null,code:CODE.BAD_JSON,msg:`not JSON: ${e.message}`}}const r=validate(t);return r.ok?{ok:!0,frame:t}:{ok:!1,id:isObject(t)&&void 0!==t.id?t.id:null,code:r.code,msg:r.msg}}function splitLines(e){const o=String(null==e?"":e).split("\n"),t=o.pop();return{lines:o.filter((e=>""!==e.trim())),rest:void 0===t?"":t}}module.exports={PROTO:1,METHODS:METHODS,CAPS:CAPS,CODE:CODE,request:request,ok:ok,err:err,hello:hello,validate:validate,negotiate:negotiate,encode:encode,decodeLine:decodeLine,splitLines:splitLines};
|
|
@@ -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 path=require("node:path"),KIND=Object.freeze({PTY:"pty",PIPE:"pipe"}),CAP="pty",CODE=Object.freeze({UNSUPPORTED:"unsupported",NO_SPAWN:"no_spawn",BAD_DESC:"bad_desc"});function plan(n){const e=n||{};return"wasm"===e.target?{ok:!1,code:CODE.UNSUPPORTED,msg:"this target has no child processes: a WASM core cannot run exec"}:e.nativePty?{ok:!0,kind:KIND.PTY,cap:CAP,reason:"a PTY backend is available, so the child gets a real terminal"}:{ok:!0,kind:KIND.PIPE,cap:null,reason:"no PTY backend: stdio works, but resize, signals and line discipline do not"}}function caps(n){return n&&n.ok&&n.cap?[n.cap]:[]}function spawn(n,e,a){const s=a||{};if(!n||!n.ok)return{ok:!1,code:n&&n.code||CODE.UNSUPPORTED,msg:n&&n.msg||"no usable process plan"};const o=e||{},t=Array.isArray(o.argv)?o.argv.map(String):[];if(!t.length)return{ok:!1,code:CODE.BAD_DESC,msg:"exec needs a non-empty argv"};const c={cwd:o.cwd,env:o.env,cols:o.cols,rows:o.rows};return n.kind===KIND.PTY?"function"!=typeof s.spawnPty?{ok:!1,code:CODE.NO_SPAWN,msg:"pty was negotiated but no PTY spawner was injected"}:{ok:!0,kind:KIND.PTY,handle:s.spawnPty(t,c)}:"function"!=typeof s.spawnChild?{ok:!1,code:CODE.NO_SPAWN,msg:"no child-process spawner was injected"}:{ok:!0,kind:KIND.PIPE,handle:s.spawnChild(t,c)}}function sameCommand(n,e){return path.basename(String(n||""))===path.basename(String(e||""))}module.exports={KIND:KIND,CAP:CAP,CODE:CODE,plan:plan,caps:caps,spawn:spawn,sameCommand:sameCommand};
|
|
@@ -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 fsDefault=require("node:fs"),os=require("node:os"),path=require("node:path"),SKILL_FILE="SKILL.md",DEFAULT_ROOTS=Object.freeze([Object.freeze({rel:[".aegis","skills"],scope:"user"}),Object.freeze({rel:[".aegiscode","skills"],scope:"user"}),Object.freeze({rel:[".claude","skills"],scope:"user"})]),PROJECT_ROOTS=Object.freeze([Object.freeze({rel:[".aegis","skills"],scope:"project"}),Object.freeze({rel:[".aegiscode","skills"],scope:"project"})]),NAME_RE=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,MAX_NAME=64,MAX_DESCRIPTION=300;function isPlainObject(e){return Boolean(e)&&"object"==typeof e&&!Array.isArray(e)}function validateName(e){const t="string"==typeof e?e.trim():"";return t?t.length>MAX_NAME?{ok:!1,reason:`name is longer than ${MAX_NAME} characters`}:NAME_RE.test(t)?{ok:!0,name:t}:{ok:!1,reason:"name must be lowercase letters, digits and single hyphens (for example: release-notes)"}:{ok:!1,reason:"a skill needs a name"}}function parseFrontmatter(e){const t="string"==typeof e?e:"",r=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(t);if(!r)return{front:{},body:t,hasFrontmatter:!1};const n={};for(const e of r[1].split(/\r?\n/)){const t=/^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(e);if(!t)continue;const r=t[2].trim().replace(/^['"]|['"]$/g,"");r&&(n[t[1]]=r)}return{front:n,body:t.slice(r[0].length),hasFrontmatter:!0}}function describeOf(e,t){const r=e.front.description||"";if(r)return r.slice(0,MAX_DESCRIPTION);const n=String(e.body||"").split(/\r?\n/).map((e=>e.trim())).find((e=>e&&!e.startsWith("#")));return n?n.slice(0,MAX_DESCRIPTION):`skill ${t}`}function rootsFor(e={}){const t=e.home||os.homedir(),r=e.cwd||process.cwd(),n="win32"===e.platform?path.win32.join:path.join,o=[];for(const e of PROJECT_ROOTS)o.push({dir:n(r,...e.rel),scope:e.scope});for(const e of DEFAULT_ROOTS)o.push({dir:n(t,...e.rel),scope:e.scope});return o}function defaultCreateDir(e={}){const t=e.home||os.homedir();return("win32"===e.platform?path.win32.join:path.join)(t,".aegiscode","skills")}function scan(e={}){const t=e.fs||fsDefault,r=rootsFor(e),n=new Set,o=[];for(const e of r)n.has(e.dir)||(n.add(e.dir),o.push(e));const s=[],i=[];for(const e of o){let r;try{r=t.readdirSync(e.dir,{withFileTypes:!0})}catch{i.push(e.dir);continue}for(const n of r){if(!n.isDirectory())continue;const r=n.name,o=path.join(e.dir,r,SKILL_FILE);let i;try{i=t.readFileSync(o,"utf8")}catch{continue}const a=parseFrontmatter(i),c=a.front.name;s.push({name:r,declaredName:c||null,description:describeOf(a,r),scope:e.scope,path:o,dir:path.join(e.dir,r),hasFrontmatter:a.hasFrontmatter,warning:a.hasFrontmatter?null:"no --- frontmatter block; add name: and description:",bodyPreview:a.body.trim().split(/\r?\n/).slice(0,6).join("\n"),lines:i.split(/\r?\n/).length})}}return s.sort(((e,t)=>e.scope!==t.scope?"user"===e.scope?-1:1:e.name.localeCompare(t.name))),{entries:s,roots:o.map((e=>e.dir)),missing:i}}function find(e,t={}){const r=String(e||"").trim();if(!r)return null;const{entries:n}=scan(t);return n.find((e=>e.name===r))||null}function renderSkill(e={}){const t=String(e.name||"").trim(),r=String(e.description||"").trim()||`Use when the user asks for ${t}.`,n=String(e.body||"").trim()||[`# ${t}`,"","\x3c!-- What this skill does. Be concrete: the steps, the commands, and what",' "done" looks like. The model reads this file when the description above'," matches the task. --\x3e"].join("\n");return["---",`name: ${t}`,`description: ${r.replace(/\r?\n/g," ")}`,"---","",n,""].join("\n")}function create(e={},t={}){const r=t.fs||fsDefault,n=validateName(e.name);if(!n.ok)return{ok:!1,reason:n.reason};const o=n.name,s=String(null==e.description?"":e.description).trim();if(s.length>MAX_DESCRIPTION)return{ok:!1,reason:`description is longer than ${MAX_DESCRIPTION} characters`};const i=String(e.targetDir||"").trim()||defaultCreateDir(t),a=path.join(i,o),c=path.join(a,SKILL_FILE);try{r.mkdirSync(a,{recursive:!0})}catch(e){return{ok:!1,reason:`could not create ${a}: ${e&&e.message?e.message:e}`}}try{r.writeFileSync(c,renderSkill({name:o,description:s,body:e.body}),{encoding:"utf8",flag:"wx"})}catch(e){return e&&"EEXIST"===e.code?{ok:!1,reason:`a skill named "${o}" already exists at ${c}`,exists:!0,path:c}:{ok:!1,reason:`could not write ${c}: ${e&&e.message?e.message:e}`}}return{ok:!0,name:o,dir:a,path:c}}function remove(e,t={}){const r=t.fs||fsDefault,n=find(e,t);if(!n)return{ok:!1,reason:`no skill named "${e}" was found`};try{r.rmSync(n.dir,{recursive:!0,force:!0})}catch(e){return{ok:!1,reason:`could not remove ${n.dir}: ${e&&e.message?e.message:e}`}}return{ok:!0,name:n.name,dir:n.dir}}const DEFAULT_IMPORT_TIMEOUT_MS=1e4,MAX_IMPORT_BYTES=262144;async function fetchSkillText(e,t={}){const r=t.fetch||("function"==typeof fetch?fetch:null);if(!r)throw new Error("network fetch is not available in this runtime");const n=Number.isFinite(t.importTimeoutMs)?t.importTimeoutMs:DEFAULT_IMPORT_TIMEOUT_MS,o="function"==typeof AbortController?new AbortController:null,s=o?setTimeout((()=>o.abort()),n):null;let i;s&&"function"==typeof s.unref&&s.unref();try{i=await r(e,o?{signal:o.signal}:void 0)}catch(t){if(o&&o.signal.aborted)throw new Error(`timed out after ${n/1e3}s fetching ${e}`);throw new Error(t&&t.message||`could not fetch ${e}`)}finally{s&&clearTimeout(s)}if(!i||!1===i.ok){const t=i&&i.status;throw new Error(`fetch failed${t?` (${t})`:""} for ${e}`)}const a=i.headers&&"function"==typeof i.headers.get?Number(i.headers.get("content-length")):NaN;if(Number.isFinite(a)&&a>MAX_IMPORT_BYTES)throw new Error(`refused: ${e} declares ${a} bytes, over the ${MAX_IMPORT_BYTES}-byte limit for a skill`);const c=await i.text();if(Buffer.byteLength(c,"utf8")>MAX_IMPORT_BYTES)throw new Error(`refused: the response is over the ${MAX_IMPORT_BYTES}-byte limit for a skill`);return c}async function importFromUrl(e={},t={}){const r=t.fs||fsDefault,n=String(e.url||"").trim();let o,s;try{o=new URL(n)}catch{return{ok:!1,reason:"not a valid URL"}}if("http:"!==o.protocol&&"https:"!==o.protocol)return{ok:!1,reason:"only http:// and https:// URLs are supported"};try{s=await fetchSkillText(o.toString(),t)}catch(e){return{ok:!1,reason:e&&e.message||`could not fetch ${n}`}}const i=parseFrontmatter(s),a=String(e.name||i.front.name||"").trim(),c=validateName(a);if(!c.ok)return{ok:!1,reason:a?c.reason:"could not determine a name — the fetched file has no name: frontmatter; pass one explicitly"};const l=c.name,f=String(e.targetDir||"").trim()||defaultCreateDir(t),d=path.join(f,l),u=path.join(d,SKILL_FILE);try{r.mkdirSync(d,{recursive:!0})}catch(e){return{ok:!1,reason:`could not create ${d}: ${e&&e.message?e.message:e}`}}try{r.writeFileSync(u,s,{encoding:"utf8",flag:"wx"})}catch(e){return e&&"EEXIST"===e.code?{ok:!1,reason:`a skill named "${l}" already exists at ${u}`,exists:!0,path:u}:{ok:!1,reason:`could not write ${u}: ${e&&e.message?e.message:e}`}}return{ok:!0,name:l,dir:d,path:u,source:o.toString()}}module.exports={SKILL_FILE:SKILL_FILE,DEFAULT_ROOTS:DEFAULT_ROOTS,PROJECT_ROOTS:PROJECT_ROOTS,NAME_RE:NAME_RE,MAX_NAME:MAX_NAME,MAX_DESCRIPTION:MAX_DESCRIPTION,MAX_IMPORT_BYTES:MAX_IMPORT_BYTES,validateName:validateName,parseFrontmatter:parseFrontmatter,describeOf:describeOf,rootsFor:rootsFor,defaultCreateDir:defaultCreateDir,scan:scan,find:find,renderSkill:renderSkill,create:create,remove:remove,importFromUrl:importFromUrl,isPlainObject:isPlainObject};
|
|
@@ -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 ENGINES=Object.freeze(["none","local"]),LOCAL_ENGINES=Object.freeze({"whisper-cli":Object.freeze({bin:"whisper-cli",args:e=>["-m",String(e.model||""),"-f",String(e.audio||""),"-nt","-l",String(e.language||"auto")],stdout:!0}),main:Object.freeze({bin:"main",args:e=>["-m",String(e.model||""),"-f",String(e.audio||""),"-nt","-l",String(e.language||"auto")],stdout:!0})}),AUDIO_FORMATS=Object.freeze(["wav","webm","ogg","mp3","flac","m4a"]),MAX_SECONDS=120,MAX_BYTES=26214400,DEFAULT_SETTINGS=Object.freeze({enabled:!1,engine:"none",model:"",language:"auto",maxSeconds:120});function isPlainObject(e){return Boolean(e)&&"object"==typeof e&&!Array.isArray(e)}function detectEngine(e={}){const n="function"==typeof e.probe?e.probe:()=>!1;for(const[e,t]of Object.entries(LOCAL_ENGINES))if(n(t.bin))return{engine:e,bin:t.bin};return null}function resolve(e,n={}){const t=isPlainObject(e)?e:{},i=Number.isFinite(t.maxSeconds)&&t.maxSeconds>0?Math.min(120,Math.max(5,Math.round(t.maxSeconds))):120,o="string"==typeof t.language&&t.language.trim()?t.language.trim():"auto",a="string"==typeof t.model?t.model.trim():"",r=(e,n)=>({enabled:!1,engine:"none",bin:null,model:a,language:o,maxSeconds:i,reason:e,install:n||null});if(!0!==t.enabled)return r("dictation is off (opt-in, default off)");if("none"===n.envEngine)return r("AEGIS_SPEECH=none forces dictation off");const l=n.detected||detectEngine(n);return l?a?{enabled:!0,engine:"local",bin:l.bin,engineName:l.engine,model:a,language:o,maxSeconds:i,reason:`local engine ${l.engine}`,install:null}:r(`found ${l.engine}, but no model file is configured — set one in Settings → Dictation`,installHint()):r("no local transcription engine installed — dictation stays off rather than uploading audio",installHint())}function installHint(){const e=process.platform;return"win32"===e?"Install whisper.cpp (winget install ggml.llamacpp) or build it from https://github.com/ggerganov/whisper.cpp, then put whisper-cli on PATH.":"darwin"===e?"brew install whisper-cpp — then set the model path in Settings → Dictation.":"Install whisper.cpp (package: whisper.cpp) and put whisper-cli on PATH — then set the model path in Settings → Dictation."}function normalizeTranscript(e){return"string"!=typeof e?"":e.replace(/\[\d{2}:\d{2}:\d{2}\.\d{3}\s*-->\s*\d{2}:\d{2}:\d{2}\.\d{3}\]/g," ").replace(/\[BLANK_AUDIO\]|\[_(?:BLANK_AUDIO|MUSIC|NOISE|SOUND)\]_?/gi," ").replace(/\u0000/g,"").replace(/[ \t]+/g," ").replace(/\s*\n\s*/g," ").trim()}function plan(e,n,t={}){const i="string"==typeof e?e:"";if(!i.trim())return{ok:!1,reason:"no audio file to transcribe",shell:!1};if(!isPlainObject(n)||!0!==n.enabled)return{ok:!1,reason:n&&n.reason||"dictation is not available",shell:!1};const o=n.engineName&&LOCAL_ENGINES[n.engineName]?n.engineName:"whisper-cli",a=LOCAL_ENGINES[o];return{ok:!0,cmd:n.bin||a.bin,args:a.args({model:n.model,audio:i,language:n.language||t.language}),shell:!1,engine:o}}function checkRecording(e={}){const n=isPlainObject(e)?e:{},t=Number(n.seconds),i=Number(n.bytes);if(Number.isFinite(t)&&t>120)return{ok:!1,reason:"recording is longer than 120s — try a shorter sentence"};if(Number.isFinite(i)&&i>26214400)return{ok:!1,reason:`recording is larger than ${Math.round(25)} MB`};const o=String(n.ext||"").replace(/^\./,"").toLowerCase();return o&&!AUDIO_FORMATS.includes(o)?{ok:!1,reason:`unsupported audio format "${o}" (expected one of ${AUDIO_FORMATS.join(", ")})`}:{ok:!0}}function offPatch(){return{enabled:!1,engine:"none"}}module.exports={ENGINES:ENGINES,LOCAL_ENGINES:LOCAL_ENGINES,AUDIO_FORMATS:AUDIO_FORMATS,MAX_SECONDS:120,MAX_BYTES:26214400,DEFAULT_SETTINGS:DEFAULT_SETTINGS,detectEngine:detectEngine,resolve:resolve,installHint:installHint,normalizeTranscript:normalizeTranscript,plan:plan,checkRecording:checkRecording,offPatch:offPatch};
|