aegisai-harness 0.81.0 → 0.82.0
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/packaging/windows/installer.iss +2 -2
- package/src/ab_testing.js +177 -0
- package/src/i18n.js +138 -0
- package/src/index.js +63 -0
- package/src/malware_scan.js +54 -0
- package/src/skills_catalog.js +74 -0
- package/src/version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to AegisAi Harness are documented here.
|
|
4
4
|
|
|
5
|
-
## [0.
|
|
5
|
+
## [0.82.0] - 2026-11-25
|
|
6
6
|
|
|
7
7
|
### Fixed
|
|
8
8
|
- Installation: Windows installer now preflights Node.js 22.13+ with actionable messages; launcher no longer hides npm failures, uses `--omit=dev`, and records a dependency marker. Inno uninstall removes stale `node_modules`/lockfiles; `install.ps1` preserves `data/` and handles GitHub source zips.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A **feature-rich, local-only AI agent harness** — OpenCode-class runtime, but
|
|
|
10
10
|
offline-first: no cloud dependencies, no telemetry. 66 milestones, ~200 modules,
|
|
11
11
|
257 tests, CI green.
|
|
12
12
|
|
|
13
|
-
> Status: v0.
|
|
13
|
+
> Status: v0.82.0 (see [ROADMAP.md](./ROADMAP.md)).
|
|
14
14
|
> **Successor to [aegisai-next](https://github.com/user6811992/aegisai-next)** — that project is deprecated; all features have been ported here.
|
|
15
15
|
> **Live docs:** https://user6811992.github.io/aegisai-harness/
|
|
16
16
|
|
package/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AegisAi Harness — agent-readable catalog
|
|
2
2
|
|
|
3
|
-
A feature-rich, local-only AI agent harness. CLI-first, offline-first. v0.
|
|
3
|
+
A feature-rich, local-only AI agent harness. CLI-first, offline-first. v0.82.0.
|
|
4
4
|
|
|
5
5
|
## Capabilities
|
|
6
6
|
- Multi-backend LLM adapter (Ollama + OpenAI-compatible + 18 providers)
|
package/package.json
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
[Setup]
|
|
5
5
|
AppId={{8F3D1B2A-6C4E-4B9A-9D21-AE615A010001}}
|
|
6
6
|
AppName=AegisAi Harness
|
|
7
|
-
AppVersion=0.
|
|
7
|
+
AppVersion=0.82.0
|
|
8
8
|
AppPublisher=AegisAi
|
|
9
9
|
AppPublisherURL=https://github.com/user6811992/aegisai-harness
|
|
10
10
|
DefaultDirName={autopf}\AegisAiHarness
|
|
11
11
|
DefaultGroupName=AegisAi Harness
|
|
12
12
|
OutputDir=..\..\dist
|
|
13
|
-
OutputBaseFilename=AegisAi-Harness-0.
|
|
13
|
+
OutputBaseFilename=AegisAi-Harness-0.82.0-Setup
|
|
14
14
|
Compression=lzma2
|
|
15
15
|
SolidCompression=yes
|
|
16
16
|
PrivilegesRequired=lowest
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/ab_testing.js
|
|
2
|
+
// Multi-model A/B testing across repeated runs.
|
|
3
|
+
// Runs each (model, prompt) pair N times, computes pass rate, median latency,
|
|
4
|
+
// and a pairwise significance (sign test) between the top two models.
|
|
5
|
+
const { compare } = require('./model_compare');
|
|
6
|
+
|
|
7
|
+
function median(arr) {
|
|
8
|
+
if (!arr.length) return 0;
|
|
9
|
+
const s = arr.slice().sort((a, b) => a - b);
|
|
10
|
+
const m = Math.floor(s.length / 2);
|
|
11
|
+
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function percentile(arr, p) {
|
|
15
|
+
if (!arr.length) return 0;
|
|
16
|
+
const s = arr.slice().sort((a, b) => a - b);
|
|
17
|
+
const idx = Math.min(s.length - 1, Math.max(0, Math.ceil((p / 100) * s.length) - 1));
|
|
18
|
+
return s[idx];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// passFn: (result) -> boolean. Default: reply non-empty and no error.
|
|
22
|
+
function defaultPass(r) { return Boolean(r.ok && r.reply && r.reply.trim().length > 0); }
|
|
23
|
+
|
|
24
|
+
async function run(opts) {
|
|
25
|
+
opts = opts || {};
|
|
26
|
+
const prompts = opts.prompts || [opts.prompt || ''];
|
|
27
|
+
const models = opts.models || [];
|
|
28
|
+
const trials = Math.max(1, opts.trials || 3);
|
|
29
|
+
const passFn = opts.passFn || defaultPass;
|
|
30
|
+
const projectRoot = opts.projectRoot || process.cwd();
|
|
31
|
+
|
|
32
|
+
const runs = []; // { model, prompt, trial, ok, pass, duration, reply, error }
|
|
33
|
+
for (const model of models) {
|
|
34
|
+
for (const prompt of prompts) {
|
|
35
|
+
for (let t = 0; t < trials; t++) {
|
|
36
|
+
const started = Date.now();
|
|
37
|
+
try {
|
|
38
|
+
const r = await require('./model_compare').compare(prompt, [model], { projectRoot, tokenBudget: opts.tokenBudget || 0 });
|
|
39
|
+
const res = (r.results || [])[0] || {};
|
|
40
|
+
runs.push({
|
|
41
|
+
model, prompt, trial: t,
|
|
42
|
+
ok: Boolean(res.ok),
|
|
43
|
+
pass: passFn(res),
|
|
44
|
+
duration: res.duration || (Date.now() - started),
|
|
45
|
+
reply: res.reply || '',
|
|
46
|
+
error: res.error || null,
|
|
47
|
+
tokenStats: res.tokenStats || null,
|
|
48
|
+
});
|
|
49
|
+
} catch (e) {
|
|
50
|
+
runs.push({ model, prompt, trial: t, ok: false, pass: false, duration: Date.now() - started, reply: '', error: String(e.message || e) });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Aggregate per (model, prompt).
|
|
57
|
+
const groups = {};
|
|
58
|
+
for (const r of runs) {
|
|
59
|
+
const key = r.model + '\u0000' + r.prompt;
|
|
60
|
+
if (!groups[key]) groups[key] = { model: r.model, prompt: r.prompt, runs: [] };
|
|
61
|
+
groups[key].runs.push(r);
|
|
62
|
+
}
|
|
63
|
+
const aggregates = Object.values(groups).map((g) => {
|
|
64
|
+
const passes = g.runs.filter((r) => r.pass).length;
|
|
65
|
+
const lats = g.runs.map((r) => r.duration);
|
|
66
|
+
return {
|
|
67
|
+
model: g.model,
|
|
68
|
+
prompt: g.prompt,
|
|
69
|
+
trials: g.runs.length,
|
|
70
|
+
passes,
|
|
71
|
+
passRate: +(passes / g.runs.length).toFixed(3),
|
|
72
|
+
medianLatency: median(lats),
|
|
73
|
+
p95Latency: percentile(lats, 95),
|
|
74
|
+
meanLatency: Math.round(lats.reduce((a, b) => a + b, 0) / (lats.length || 1)),
|
|
75
|
+
failures: g.runs.filter((r) => !r.ok).length,
|
|
76
|
+
errors: g.runs.map((r) => r.error).filter(Boolean),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Overall per model (across prompts).
|
|
81
|
+
const perModel = {};
|
|
82
|
+
for (const m of models) {
|
|
83
|
+
const rs = runs.filter((r) => r.model === m);
|
|
84
|
+
const passes = rs.filter((r) => r.pass).length;
|
|
85
|
+
perModel[m] = {
|
|
86
|
+
trials: rs.length,
|
|
87
|
+
passes,
|
|
88
|
+
passRate: rs.length ? +(passes / rs.length).toFixed(3) : 0,
|
|
89
|
+
medianLatency: median(rs.map((r) => r.duration)),
|
|
90
|
+
p95Latency: percentile(rs.map((r) => r.duration), 95),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Significance: pairwise sign test between the top two models on shared prompts.
|
|
95
|
+
const significance = [];
|
|
96
|
+
if (models.length >= 2) {
|
|
97
|
+
const [a, b] = models.slice(0, 2);
|
|
98
|
+
const sharedPrompts = prompts;
|
|
99
|
+
let aWins = 0, bWins = 0, ties = 0;
|
|
100
|
+
for (const prompt of sharedPrompts) {
|
|
101
|
+
for (let t = 0; t < trials; t++) {
|
|
102
|
+
const ra = runs.find((r) => r.model === a && r.prompt === prompt && r.trial === t);
|
|
103
|
+
const rb = runs.find((r) => r.model === b && r.prompt === prompt && r.trial === t);
|
|
104
|
+
if (!ra || !rb) continue;
|
|
105
|
+
if (ra.pass && !rb.pass) aWins++;
|
|
106
|
+
else if (!ra.pass && rb.pass) bWins++;
|
|
107
|
+
else if (ra.duration < rb.duration && ra.pass === rb.pass) aWins++;
|
|
108
|
+
else if (rb.duration < ra.duration && ra.pass === rb.pass) bWins++;
|
|
109
|
+
else ties++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const n = aWins + bWins;
|
|
113
|
+
// Two-sided binomial sign test (p = 0.5).
|
|
114
|
+
let p = 1;
|
|
115
|
+
if (n > 0) {
|
|
116
|
+
let cum = 0;
|
|
117
|
+
const k = Math.min(aWins, bWins);
|
|
118
|
+
for (let i = 0; i <= k; i++) {
|
|
119
|
+
cum += comb(n, i) * Math.pow(0.5, n);
|
|
120
|
+
}
|
|
121
|
+
p = Math.min(1, 2 * cum);
|
|
122
|
+
}
|
|
123
|
+
significance.push({ a, b, aWins, bWins, ties, pValue: +p.toFixed(4), significant: p < 0.05 });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Winner = highest pass rate, then lowest median latency.
|
|
127
|
+
const winner = Object.keys(perModel).sort((x, y) => {
|
|
128
|
+
if (perModel[y].passRate !== perModel[x].passRate) return perModel[y].passRate - perModel[x].passRate;
|
|
129
|
+
return perModel[x].medianLatency - perModel[y].medianLatency;
|
|
130
|
+
})[0] || null;
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
prompts, models, trials, winner,
|
|
134
|
+
perModel, aggregates, significance, runs: opts.includeRuns ? runs : undefined,
|
|
135
|
+
summary: {
|
|
136
|
+
trials: runs.length,
|
|
137
|
+
winner,
|
|
138
|
+
winnerPassRate: winner ? perModel[winner].passRate : null,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function comb(n, k) {
|
|
144
|
+
if (k < 0 || k > n) return 0;
|
|
145
|
+
let r = 1;
|
|
146
|
+
for (let i = 1; i <= k; i++) r = (r * (n - i + 1)) / i;
|
|
147
|
+
return r;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function format(result) {
|
|
151
|
+
const lines = [];
|
|
152
|
+
lines.push('# A/B Test Results');
|
|
153
|
+
lines.push('');
|
|
154
|
+
lines.push('**Prompts:** ' + result.prompts.length + ' | **Models:** ' + result.models.join(', ') + ' | **Trials:** ' + result.trials);
|
|
155
|
+
lines.push('**Winner:** ' + (result.winner || 'n/a') + (result.summary.winnerPassRate != null ? ' (pass rate ' + (result.summary.winnerPassRate * 100).toFixed(0) + '%)' : ''));
|
|
156
|
+
lines.push('');
|
|
157
|
+
lines.push('## Per model');
|
|
158
|
+
for (const m of result.models) {
|
|
159
|
+
const a = result.perModel[m];
|
|
160
|
+
lines.push('- **' + m + '**: pass ' + (a.passRate * 100).toFixed(0) + '% (' + a.passes + '/' + a.trials + '), median ' + a.medianLatency + ' ms, p95 ' + a.p95Latency + ' ms');
|
|
161
|
+
}
|
|
162
|
+
if (result.significance.length) {
|
|
163
|
+
lines.push('');
|
|
164
|
+
lines.push('## Significance');
|
|
165
|
+
for (const s of result.significance) {
|
|
166
|
+
lines.push('- ' + s.a + ' vs ' + s.b + ': ' + s.aWins + '–' + s.bWins + ' (ties ' + s.ties + '), p=' + s.pValue + (s.significant ? ' (significant)' : ' (not significant)'));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
lines.push('');
|
|
170
|
+
lines.push('## Per (model, prompt)');
|
|
171
|
+
for (const a of result.aggregates) {
|
|
172
|
+
lines.push('- **' + a.model + '** on `' + a.prompt.slice(0, 60) + '` → ' + (a.passRate * 100).toFixed(0) + '% pass, median ' + a.medianLatency + ' ms');
|
|
173
|
+
}
|
|
174
|
+
return lines.join('\n');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
module.exports = { run, format, median, percentile, defaultPass };
|
package/src/i18n.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// src/i18n.js
|
|
2
|
+
// Tiny i18n: locale dictionaries + t(key, params) with interpolation.
|
|
3
|
+
const DICTS = {};
|
|
4
|
+
const FALLBACK = 'en';
|
|
5
|
+
|
|
6
|
+
const BUILTIN = {
|
|
7
|
+
en: {
|
|
8
|
+
'app.title': 'AegisAi Harness',
|
|
9
|
+
'chat.send': 'Send',
|
|
10
|
+
'chat.placeholder': 'Type a message... (Shift+Enter for new line)',
|
|
11
|
+
'chat.newChat': 'New Chat',
|
|
12
|
+
'chat.clear': 'Clear Chat',
|
|
13
|
+
'config.save': 'Save',
|
|
14
|
+
'config.close': 'Close',
|
|
15
|
+
'files.open': 'File Browser',
|
|
16
|
+
'search.title': 'Search Conversations',
|
|
17
|
+
'theme.cycle': 'Cycle theme',
|
|
18
|
+
'compare.title': 'Compare Models',
|
|
19
|
+
'export.title': 'Export Chat',
|
|
20
|
+
'help.title': 'Help & Shortcuts',
|
|
21
|
+
'onboarding.welcome': 'Welcome to AegisAi Harness',
|
|
22
|
+
'onboarding.done': 'Setup complete! You\'re ready to start chatting.',
|
|
23
|
+
'toast.updateAvailable': 'Update available: v{version}',
|
|
24
|
+
'toast.exported': 'Exported to {path}',
|
|
25
|
+
'toast.configSaved': 'Configuration saved',
|
|
26
|
+
'toast.scanFound': 'Found {n} models',
|
|
27
|
+
'error.unauthorized': 'Authentication Required',
|
|
28
|
+
},
|
|
29
|
+
es: {
|
|
30
|
+
'app.title': 'AegisAi Harness',
|
|
31
|
+
'chat.send': 'Enviar',
|
|
32
|
+
'chat.placeholder': 'Escribe un mensaje... (Shift+Enter para nueva línea)',
|
|
33
|
+
'chat.newChat': 'Nuevo chat',
|
|
34
|
+
'chat.clear': 'Limpiar chat',
|
|
35
|
+
'config.save': 'Guardar',
|
|
36
|
+
'config.close': 'Cerrar',
|
|
37
|
+
'files.open': 'Explorador de archivos',
|
|
38
|
+
'search.title': 'Buscar conversaciones',
|
|
39
|
+
'theme.cycle': 'Cambiar tema',
|
|
40
|
+
'compare.title': 'Comparar modelos',
|
|
41
|
+
'export.title': 'Exportar chat',
|
|
42
|
+
'help.title': 'Ayuda y atajos',
|
|
43
|
+
'onboarding.welcome': 'Bienvenido a AegisAi Harness',
|
|
44
|
+
'onboarding.done': '¡Configuración completa! Ya puedes chatear.',
|
|
45
|
+
'toast.updateAvailable': 'Actualización disponible: v{version}',
|
|
46
|
+
'toast.exported': 'Exportado a {path}',
|
|
47
|
+
'toast.configSaved': 'Configuración guardada',
|
|
48
|
+
'toast.scanFound': 'Se encontraron {n} modelos',
|
|
49
|
+
'error.unauthorized': 'Autenticación requerida',
|
|
50
|
+
},
|
|
51
|
+
fr: {
|
|
52
|
+
'app.title': 'AegisAi Harness',
|
|
53
|
+
'chat.send': 'Envoyer',
|
|
54
|
+
'chat.placeholder': 'Tapez un message... (Shift+Enter pour une nouvelle ligne)',
|
|
55
|
+
'chat.newChat': 'Nouveau chat',
|
|
56
|
+
'chat.clear': 'Effacer le chat',
|
|
57
|
+
'config.save': 'Enregistrer',
|
|
58
|
+
'config.close': 'Fermer',
|
|
59
|
+
'files.open': 'Explorateur de fichiers',
|
|
60
|
+
'search.title': 'Rechercher des conversations',
|
|
61
|
+
'theme.cycle': 'Changer de thème',
|
|
62
|
+
'compare.title': 'Comparer les modèles',
|
|
63
|
+
'export.title': 'Exporter le chat',
|
|
64
|
+
'help.title': 'Aide et raccourcis',
|
|
65
|
+
'onboarding.welcome': 'Bienvenue dans AegisAi Harness',
|
|
66
|
+
'onboarding.done': 'Configuration terminée ! Vous pouvez commencer à discuter.',
|
|
67
|
+
'toast.updateAvailable': 'Mise à jour disponible : v{version}',
|
|
68
|
+
'toast.exported': 'Exporté vers {path}',
|
|
69
|
+
'toast.configSaved': 'Configuration enregistrée',
|
|
70
|
+
'toast.scanFound': '{n} modèles trouvés',
|
|
71
|
+
'error.unauthorized': 'Authentification requise',
|
|
72
|
+
},
|
|
73
|
+
de: {
|
|
74
|
+
'app.title': 'AegisAi Harness',
|
|
75
|
+
'chat.send': 'Senden',
|
|
76
|
+
'chat.placeholder': 'Nachricht eingeben... (Shift+Enter für neue Zeile)',
|
|
77
|
+
'chat.newChat': 'Neuer Chat',
|
|
78
|
+
'chat.clear': 'Chat leeren',
|
|
79
|
+
'config.save': 'Speichern',
|
|
80
|
+
'config.close': 'Schließen',
|
|
81
|
+
'files.open': 'Dateibrowser',
|
|
82
|
+
'search.title': 'Konversationen durchsuchen',
|
|
83
|
+
'theme.cycle': 'Thema wechseln',
|
|
84
|
+
'compare.title': 'Modelle vergleichen',
|
|
85
|
+
'export.title': 'Chat exportieren',
|
|
86
|
+
'help.title': 'Hilfe und Tastenkürzel',
|
|
87
|
+
'onboarding.welcome': 'Willkommen bei AegisAi Harness',
|
|
88
|
+
'onboarding.done': 'Einrichtung abgeschlossen! Sie können jetzt chatten.',
|
|
89
|
+
'toast.updateAvailable': 'Update verfügbar: v{version}',
|
|
90
|
+
'toast.exported': 'Exportiert nach {path}',
|
|
91
|
+
'toast.configSaved': 'Konfiguration gespeichert',
|
|
92
|
+
'toast.scanFound': '{n} Modelle gefunden',
|
|
93
|
+
'error.unauthorized': 'Authentifizierung erforderlich',
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
let currentLocale = (typeof process !== 'undefined' && process.env && process.env.AEGISAI_LOCALE) || 'en';
|
|
98
|
+
|
|
99
|
+
function register(locale, dict) {
|
|
100
|
+
DICTS[locale] = Object.assign({}, DICTS[locale] || {}, dict || {});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function setLocale(locale) {
|
|
104
|
+
if (locale) currentLocale = locale;
|
|
105
|
+
return currentLocale;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getLocale() { return currentLocale; }
|
|
109
|
+
|
|
110
|
+
function t(key, params) {
|
|
111
|
+
const dict = DICTS[currentLocale] || BUILTIN[currentLocale] || BUILTIN[FALLBACK] || {};
|
|
112
|
+
let s = dict[key];
|
|
113
|
+
if (s == null) {
|
|
114
|
+
const fb = BUILTIN[FALLBACK] || {};
|
|
115
|
+
s = fb[key];
|
|
116
|
+
}
|
|
117
|
+
if (s == null) s = key;
|
|
118
|
+
if (params) {
|
|
119
|
+
s = s.replace(/\{(\w+)\}/g, (_, k) => (params[k] != null ? String(params[k]) : '{' + k + '}'));
|
|
120
|
+
}
|
|
121
|
+
return s;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function available() { return Object.keys(BUILTIN).concat(Object.keys(DICTS)).filter((v, i, a) => a.indexOf(v) === i); }
|
|
125
|
+
|
|
126
|
+
// Auto-register builtins.
|
|
127
|
+
for (const [loc, dict] of Object.entries(BUILTIN)) register(loc, dict);
|
|
128
|
+
|
|
129
|
+
function loadFromFile(filePath) {
|
|
130
|
+
try {
|
|
131
|
+
const fs = require('fs');
|
|
132
|
+
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
133
|
+
if (data && data.locale && data.strings) register(data.locale, data.strings);
|
|
134
|
+
return true;
|
|
135
|
+
} catch (e) { return false; }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = { register, setLocale, getLocale, t, available, loadFromFile, BUILTIN };
|
package/src/index.js
CHANGED
|
@@ -501,6 +501,44 @@ async function main() {
|
|
|
501
501
|
sendJson(res, 200, require('./channels_extra').status());
|
|
502
502
|
return;
|
|
503
503
|
}
|
|
504
|
+
if (req.method === 'GET' && req.url.split('?')[0] === '/api/ab-test') {
|
|
505
|
+
const u = new URL(req.url, 'http://x');
|
|
506
|
+
const models = (u.searchParams.get('models') || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
507
|
+
const prompts = (u.searchParams.get('prompts') || u.searchParams.get('prompt') || '').split('||').map((s) => s.trim()).filter(Boolean);
|
|
508
|
+
const trials = parseInt(u.searchParams.get('trials') || '3', 10);
|
|
509
|
+
const r = await require('./ab_testing').run({ models, prompts: prompts.length ? prompts : [''], trials, projectRoot: process.cwd() });
|
|
510
|
+
sendJson(res, 200, r);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (req.method === 'POST' && req.url.split('?')[0] === '/api/ab-test') {
|
|
514
|
+
const parsed = await readJson(req);
|
|
515
|
+
const r = await require('./ab_testing').run({ models: parsed.models, prompts: parsed.prompts || [parsed.prompt || ''], trials: parsed.trials, projectRoot: process.cwd() });
|
|
516
|
+
sendJson(res, 200, r);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (req.method === 'POST' && req.url.split('?')[0] === '/api/malware-scan') {
|
|
520
|
+
const parsed = await readJson(req);
|
|
521
|
+
const targets = parsed.targets || (parsed.path ? [parsed.path] : []);
|
|
522
|
+
sendJson(res, 200, require('./malware_scan').scan(targets, { recursive: parsed.recursive }));
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (req.method === 'GET' && req.url.split('?')[0] === '/api/skills-catalog') {
|
|
526
|
+
const r = require('./skills_catalog').loadCatalog();
|
|
527
|
+
sendJson(res, 200, r);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (req.method === 'POST' && req.url.split('?')[0] === '/api/skills-catalog/fetch') {
|
|
531
|
+
const parsed = await readJson(req);
|
|
532
|
+
const r = await require('./skills_catalog').fetchCatalog(parsed.url);
|
|
533
|
+
sendJson(res, 200, { count: r.count, fetched: r.skills.length });
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
if (req.method === 'GET' && req.url.split('?')[0] === '/api/i18n') {
|
|
537
|
+
const loc = new URL(req.url, 'http://x').searchParams.get('locale') || require('./i18n').getLocale();
|
|
538
|
+
require('./i18n').setLocale(loc);
|
|
539
|
+
sendJson(res, 200, { locale: require('./i18n').getLocale(), available: require('./i18n').available(), strings: {} });
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
504
542
|
if (req.method === 'POST' && req.url.split('?')[0] === '/api/diff') {
|
|
505
543
|
const parsed = await readJson(req);
|
|
506
544
|
const d = require('./text_diff');
|
|
@@ -1183,6 +1221,31 @@ async function main() {
|
|
|
1183
1221
|
if (t === '/channels-extra') { console.log(JSON.stringify(require('./channels_extra').status(), null, 2)); rl.prompt(); return; }
|
|
1184
1222
|
if (t === '/map') { const files = require('./code_map').build(root, 60) || []; console.log('Architecture map: open /map.html in the web UI (--web). Indexed ' + files.length + ' files.'); rl.prompt(); return; }
|
|
1185
1223
|
if (t.startsWith('/rename ')) { const p = t.slice(8).trim().split('|').map((x) => x.trim()); const edit = await require('./lsp').rename(p[0], p[1], Number(p[2]), Number(p[3]), p[4]); const applied = require('./lsp').applyWorkspaceEdit(edit, { dryRun: p[5] !== 'apply' }); console.log(JSON.stringify(applied, null, 2).slice(0, 2000)); rl.prompt(); return; }
|
|
1224
|
+
if (t.startsWith('/ab-test ')) { const p = t.slice(9).trim().split('|').map((x) => x.trim()); const r = await require('./ab_testing').run({ prompts: [p[0] || ''], models: p.slice(1).filter(Boolean), trials: Number(p[p.length-1]) || 3, projectRoot: root }); console.log(require('./ab_testing').format(r)); rl.prompt(); return; }
|
|
1225
|
+
if (t.startsWith('/malware-scan ')) { const p = t.slice(14).trim().split('|').map((x) => x.trim()); const r = require('./malware_scan').scan(p[0].split(','), { recursive: p.includes('recursive') }); console.log(JSON.stringify(r, null, 2).slice(0, 3000)); rl.prompt(); return; }
|
|
1226
|
+
if (t.startsWith('/ioc-match ')) { const p = t.slice(11).trim().split('|'); console.log(JSON.stringify(require('./ioc_import').match(p[1] || '', require('./ioc_import').parseFeed(p[0] || '', 'inline')))); rl.prompt(); return; }
|
|
1227
|
+
if (t.startsWith('/skill-schema ')) { const p = t.slice(14).trim(); const r = require('fs').statSync(p).isDirectory() ? require('./skill_schema').validateDir(p) : [require('./skill_schema').validateFile(p)]; console.log(JSON.stringify({ summary: require('./skill_schema').summarize(r), results: r.map((x) => ({ file: x.file, ok: x.ok, errors: x.errors, warnings: x.warnings })) }, null, 2).slice(0, 3000)); rl.prompt(); return; }
|
|
1228
|
+
if (t.startsWith('/guardrail ')) { const p = t.slice(11).trim().split('|'); const r = require('./guardrail_api').evaluate({ tool: p[0], args: p[1] ? JSON.parse(p[1]) : {}, context: { projectRoot: root, readOnly: process.env.AEGISAI_READ_ONLY === 'true' } }); console.log(JSON.stringify({ decision: r.decision, reasons: r.reasons }, null, 2)); rl.prompt(); return; }
|
|
1229
|
+
if (t.startsWith('/sec-logs')) { const p = t.slice(9).trim().split('|'); const doc = require('./security_logs').generate({ seed: Number(p[0] || 42), perScenario: Number(p[1] || 12) }); if (p[2]) { require('fs').writeFileSync(p[2], p[2].endsWith('.csv') ? require('./security_logs').toCsv(doc) : require('./security_logs').toJsonl(doc)); console.log('wrote', p[2], doc.events.length, 'events'); } else { console.log(JSON.stringify({ summary: doc.summary, expectations: require('./security_logs').expectations(doc) }, null, 2)); } rl.prompt(); return; }
|
|
1230
|
+
if (t === '/agent-cli') { console.log(JSON.stringify(require('./agent_cli').detect(), null, 2)); rl.prompt(); return; }
|
|
1231
|
+
if (t.startsWith('/package-guard ')) { console.log(JSON.stringify(require('./package_guard').checkCommand(t.slice(15).trim()), null, 2)); rl.prompt(); return; }
|
|
1232
|
+
if (t === '/channels-extra') { console.log(JSON.stringify(require('./channels_extra').status(), null, 2)); rl.prompt(); return; }
|
|
1233
|
+
if (t === '/map') { const files = require('./code_map').build(root, 60) || []; console.log('Architecture map: open /map.html in the web UI (--web). Indexed ' + files.length + ' files.'); rl.prompt(); return; }
|
|
1234
|
+
if (t.startsWith('/skills-catalog')) { const r = await require('./skills_catalog').fetchCatalog(); console.log(JSON.stringify({ count: r.count }, null, 2)); rl.prompt(); return; }
|
|
1235
|
+
if (t.startsWith('/skills-import ')) { const u = t.slice(15).trim(); const name = u.split('/').pop().replace(/\.md$/i, '') || 'imported'; const r = await require('./skills_catalog').importSkill(u, name); console.log(JSON.stringify(r)); rl.prompt(); return; }
|
|
1236
|
+
if (t.startsWith('/ab-test ')) { const p = t.slice(9).trim().split('|').map((x) => x.trim()); const r = await require('./ab_testing').run({ prompts: [p[0] || ''], models: p.slice(1, -1).filter(Boolean), trials: Number(p[p.length-1]) || 3, projectRoot: root }); console.log(require('./ab_testing').format(r)); rl.prompt(); return; }
|
|
1237
|
+
if (t.startsWith('/malware-scan ')) { const p = t.slice(14).trim().split('|').map((x) => x.trim()); const r = require('./malware_scan').scan(p[0].split(','), { recursive: p.includes('recursive') }); console.log(JSON.stringify(r, null, 2).slice(0, 3000)); rl.prompt(); return; }
|
|
1238
|
+
if (t.startsWith('/probe-http ')) { const u = t.slice(12).trim(); const r = await require('./http_probe').probe(u, { headers: true }); console.log(JSON.stringify(r.results[0], null, 2)); rl.prompt(); return; }
|
|
1239
|
+
if (t.startsWith('/pentest-eval')) { const r = await require('./pentest_eval').run({}); console.log(JSON.stringify(r.summary, null, 2)); console.log(JSON.stringify(r.fixtures.map((f) => ({ id: f.id, s: f.score })), null, 2)); rl.prompt(); return; }
|
|
1240
|
+
if (t.startsWith('/decide ')) { const q = t.slice(8).trim(); const r = await require('./tiny_router').decide(q); console.log(JSON.stringify(r)); rl.prompt(); return; }
|
|
1241
|
+
if (t.startsWith('/deck ')) { const p = t.slice(6).trim().split('|'); const outline = require('fs').existsSync(p[0]) ? require('fs').readFileSync(p[0], 'utf8') : p[0]; const out = p[1] || require('path').join(root, 'deck-' + Date.now() + '.pdf'); const r = require('./deck').generate(outline, out); console.log(JSON.stringify({ slides: r.slides, bytes: r.bytes, path: r.path })); rl.prompt(); return; }
|
|
1242
|
+
if (t.startsWith('/skill-schema ')) { const p = t.slice(14).trim(); const r = require('fs').statSync(p).isDirectory() ? require('./skill_schema').validateDir(p) : [require('./skill_schema').validateFile(p)]; console.log(JSON.stringify({ summary: require('./skill_schema').summarize(r), results: r.map((x) => ({ file: x.file, ok: x.ok, errors: x.errors, warnings: x.warnings })) }, null, 2).slice(0, 3000)); rl.prompt(); return; }
|
|
1243
|
+
if (t.startsWith('/guardrail ')) { const p = t.slice(11).trim().split('|'); const r = require('./guardrail_api').evaluate({ tool: p[0], args: p[1] ? JSON.parse(p[1]) : {}, context: { projectRoot: root, readOnly: process.env.AEGISAI_READ_ONLY === 'true' } }); console.log(JSON.stringify({ decision: r.decision, reasons: r.reasons }, null, 2)); rl.prompt(); return; }
|
|
1244
|
+
if (t.startsWith('/ioc ')) { const p = t.slice(5).trim().split('|'); const r = require('fs').existsSync(p[0]) ? require('./ioc_import').importFile(p[0], { persist: p[1] === 'persist' }) : { parsed: require('./ioc_import').parseFeed(p[0] || '', 'inline'), summary: require('./ioc_import').summarize(require('./ioc_import').parseFeed(p[0] || '', 'inline')) }; console.log(JSON.stringify(r.summary, null, 2)); rl.prompt(); return; }
|
|
1245
|
+
if (t.startsWith('/sec-logs')) { const p = t.slice(9).trim().split('|'); const doc = require('./security_logs').generate({ seed: Number(p[0] || 42), perScenario: Number(p[1] || 12) }); if (p[2]) { require('fs').writeFileSync(p[2], p[2].endsWith('.csv') ? require('./security_logs').toCsv(doc) : require('./security_logs').toJsonl(doc)); console.log('wrote', p[2], doc.events.length, 'events'); } else { console.log(JSON.stringify({ summary: doc.summary, expectations: require('./security_logs').expectations(doc) }, null, 2)); } rl.prompt(); return; }
|
|
1246
|
+
if (t === '/agent-cli') { console.log(JSON.stringify(require('./agent_cli').detect(), null, 2)); rl.prompt(); return; }
|
|
1247
|
+
if (t.startsWith('/package-guard ')) { console.log(JSON.stringify(require('./package_guard').checkCommand(t.slice(15).trim()), null, 2)); rl.prompt(); return; }
|
|
1248
|
+
if (t === '/channels-extra') { console.log(JSON.stringify(require('./channels_extra').status(), null, 2)); rl.prompt(); return; }
|
|
1186
1249
|
if (t.startsWith('/time ')) { console.log(JSON.stringify(require('./time_tool').now(t.slice(6).trim()))); rl.prompt(); return; }
|
|
1187
1250
|
if (t.startsWith('/mcp-registry ')) { const r = await require('./mcp_registry_browser').browse(t.slice(14).trim()); console.log(JSON.stringify(r, null, 2).slice(0, 2000)); rl.prompt(); return; }
|
|
1188
1251
|
if (t === '/everything-manifest') { console.log(JSON.stringify(require('./mcp_everything').manifest(), null, 2).slice(0, 1500)); rl.prompt(); return; }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/malware_scan.js
|
|
2
|
+
// Optional malware scan via clamscan. Never required; degrades gracefully.
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
function which(bin) {
|
|
8
|
+
const cmd = process.platform === 'win32' ? 'where' : 'which';
|
|
9
|
+
try {
|
|
10
|
+
const r = spawnSync(cmd, [bin], { encoding: 'utf8', timeout: 5000 });
|
|
11
|
+
if (r.status === 0) return String(r.stdout || '').split(/\r?\n/).filter(Boolean)[0] || bin;
|
|
12
|
+
} catch (e) {}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function available() { return Boolean(which('clamscan') || which('clamdscan')); }
|
|
17
|
+
|
|
18
|
+
function scan(targets, opts) {
|
|
19
|
+
opts = opts || {};
|
|
20
|
+
const bin = which('clamscan') || which('clamdscan');
|
|
21
|
+
if (!bin) return { ok: false, available: false, note: 'clamscan not found on PATH; install ClamAV to enable malware scanning' };
|
|
22
|
+
const list = Array.isArray(targets) ? targets : [targets];
|
|
23
|
+
const args = ['--infected', '--no-summary', '--stdout'].concat(opts.recursive ? ['-r'] : []).concat(list);
|
|
24
|
+
const started = Date.now();
|
|
25
|
+
const r = spawnSync(bin, args, { encoding: 'utf8', timeout: opts.timeoutMs || 300000, maxBuffer: 20 * 1024 * 1024 });
|
|
26
|
+
const lines = String(r.stdout || '').split(/\r?\n/).filter(Boolean);
|
|
27
|
+
const infected = lines.filter((l) => /FOUND$/i.test(l.trim()));
|
|
28
|
+
const errors = lines.filter((l) => /ERROR|SCAN ERROR/i.test(l));
|
|
29
|
+
return {
|
|
30
|
+
ok: r.status === 0 || r.status === 1,
|
|
31
|
+
available: true,
|
|
32
|
+
exitCode: r.status,
|
|
33
|
+
duration: Date.now() - started,
|
|
34
|
+
scanned: list.length,
|
|
35
|
+
infected: infected.map((l) => {
|
|
36
|
+
const m = l.match(/^(.*?):\s*(.+?)\s*FOUND$/i);
|
|
37
|
+
return m ? { file: m[1], signature: m[2] } : { raw: l };
|
|
38
|
+
}),
|
|
39
|
+
infectedCount: infected.length,
|
|
40
|
+
errors: errors.slice(0, 20),
|
|
41
|
+
clean: infected.length === 0 && r.status === 0,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Scan a single buffer (write to a temp file first).
|
|
46
|
+
function scanBuffer(buf, filename, opts) {
|
|
47
|
+
const tmp = path.join(require('os').tmpdir(), 'aegisai-scan-' + Date.now() + '-' + (filename || 'blob'));
|
|
48
|
+
try { require('fs').writeFileSync(tmp, buf); } catch (e) { return { ok: false, error: String(e.message || e) }; }
|
|
49
|
+
const r = scan([tmp], opts);
|
|
50
|
+
try { require('fs').unlinkSync(tmp); } catch (e) {}
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = { available, scan, scanBuffer, which };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/skills_catalog.js
|
|
2
|
+
// Import skills from a remote catalog (openai/skills-style).
|
|
3
|
+
// The catalog is expected to be a JSON array or { skills: [...] } with
|
|
4
|
+
// { name, description, url?, license?, tags? }.
|
|
5
|
+
const https = require('https');
|
|
6
|
+
const http = require('http');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { DATA_DIR } = require('./core/config');
|
|
10
|
+
|
|
11
|
+
const DEFAULT_CATALOG_URL = 'https://raw.githubusercontent.com/openai/skills/main/catalog.json';
|
|
12
|
+
|
|
13
|
+
function fetchJson(url, timeoutMs) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const lib = /^https:/.test(url) ? https : http;
|
|
16
|
+
const req = lib.get(url, { headers: { 'User-Agent': 'aegisai-skills-catalog' } }, (res) => {
|
|
17
|
+
let d = '';
|
|
18
|
+
res.on('data', (c) => { d += c; });
|
|
19
|
+
res.on('end', () => {
|
|
20
|
+
if (res.statusCode >= 400) return reject(new Error('HTTP ' + res.statusCode));
|
|
21
|
+
try { resolve(JSON.parse(d)); } catch (e) { reject(e); }
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
req.on('error', reject);
|
|
25
|
+
req.setTimeout(timeoutMs || 20000, () => { req.destroy(); reject(new Error('timeout')); });
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeCatalog(data) {
|
|
30
|
+
const list = Array.isArray(data) ? data : (data && (data.skills || data.items || data.catalog)) || [];
|
|
31
|
+
return list.map((s) => ({
|
|
32
|
+
name: String(s.name || s.id || '').trim(),
|
|
33
|
+
description: String(s.description || s.summary || '').trim(),
|
|
34
|
+
url: s.url || s.source || s.link || null,
|
|
35
|
+
license: s.license || null,
|
|
36
|
+
tags: Array.isArray(s.tags) ? s.tags : [],
|
|
37
|
+
version: s.version || null,
|
|
38
|
+
})).filter((s) => s.name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function catalogPath() { return path.join(DATA_DIR, 'skills-catalog.json'); }
|
|
42
|
+
|
|
43
|
+
function saveCatalog(items) {
|
|
44
|
+
try { fs.mkdirSync(DATA_DIR, { recursive: true }); fs.writeFileSync(catalogPath(), JSON.stringify({ fetched: new Date().toISOString(), skills: items }, null, 2)); return true; } catch (e) { return false; }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function loadCatalog() {
|
|
48
|
+
try { const d = JSON.parse(fs.readFileSync(catalogPath(), 'utf8')); return { fetched: d.fetched, skills: d.skills || [] }; } catch (e) { return { fetched: null, skills: [] }; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function fetchCatalog(url) {
|
|
52
|
+
const data = await fetchJson(url || DEFAULT_CATALOG_URL);
|
|
53
|
+
const items = normalizeCatalog(data);
|
|
54
|
+
saveCatalog(items);
|
|
55
|
+
return { url: url || DEFAULT_CATALOG_URL, count: items.length, skills: items };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Import a single skill from a URL into the default skills pack.
|
|
59
|
+
async function importSkill(url, name) {
|
|
60
|
+
const text = await new Promise((resolve, reject) => {
|
|
61
|
+
const lib = /^https:/.test(url) ? https : http;
|
|
62
|
+
const req = lib.get(url, { headers: { 'User-Agent': 'aegisai-skills-catalog' } }, (res) => {
|
|
63
|
+
let d = ''; res.on('data', (c) => { d += c; }); res.on('end', () => resolve(d));
|
|
64
|
+
});
|
|
65
|
+
req.on('error', reject);
|
|
66
|
+
req.setTimeout(20000, () => { req.destroy(); reject(new Error('timeout')); });
|
|
67
|
+
});
|
|
68
|
+
const dir = path.join(DATA_DIR, 'imported-skills', name || ('skill-' + Date.now()));
|
|
69
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
70
|
+
fs.writeFileSync(path.join(dir, 'SKILL.md'), text);
|
|
71
|
+
return { ok: true, dir, bytes: text.length };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { DEFAULT_CATALOG_URL, fetchJson, normalizeCatalog, fetchCatalog, loadCatalog, saveCatalog, importSkill, catalogPath };
|
package/src/version.js
CHANGED