aegisai-harness 0.80.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to AegisAi Harness are documented here.
4
4
 
5
- ## [0.80.0] - 2026-11-25
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.80.0 (see [ROADMAP.md](./ROADMAP.md)).
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/ROADMAP.md CHANGED
@@ -550,28 +550,29 @@ Feasibility: **H** = fits current JS architecture, **M** = needs external servic
550
550
  | Conversation templates | prior backlog | H |
551
551
  | Multi-model A/B across runs | prior backlog | H |
552
552
 
553
- ### Batch 4 — after
554
- | Item | Source | Feasibility |
555
- |---|---|---|
556
- | HTTP probe tool (httpx-style) | projectdiscovery/httpx | H |
557
- | Pentest eval harness | usestrix/benchmarks | H |
558
- | Tiny-model boolean router | qybaihe/mu | H |
559
- | Slide/deck skill (PDF) | qybaihe/codex-ppt | H |
560
- | Canonical Agent Skills schema | anthropics/skills | H |
561
- | Interactive architecture map page | haydenschmitty/floorplan | H |
562
- | Guardrail routing API surface | sandbox-quantum/switch-trust | H |
563
- | IoC feed import | cisco-talos/IOCs | H |
564
- | Synthetic security log corpus | cisco-talos/EvidenceForge | H |
565
- | Teams + Mattermost channels | sandbox-quantum/switch | M |
566
- | External agent CLI adapters | openai/codex-plugin-cc | M |
567
- | Official MCP registry alignment | modelcontextprotocol/registry | M |
568
- | Codex skills catalog import | openai/skills | M |
569
- | Attachment malware scan (`clamscan`) | cisco-talos/clamav | M |
570
- | Project-wide symbol rename (LSP) | sandbox-quantum/bartleby | M |
571
- | Binary function similarity | cisco-talos/binary_function_similarity | M |
572
- | RAGFlow-style private retrieval | bytedance/deer-flow | M |
573
- | Codex-style MCP config presets | openai/codex | H |
574
- | Package-install guard | usestrix/firewall | M |
553
+ ### Batch 4 — shipped in v0.81.0
554
+ | Item | Source | Feasibility | Status |
555
+ |---|---|---|---|
556
+ | HTTP probe tool (httpx-style) | projectdiscovery/httpx | H | ✅ `src/http_probe.js` |
557
+ | Pentest eval harness | usestrix/benchmarks | H | ✅ `src/pentest_eval.js` |
558
+ | Tiny-model boolean router | qybaihe/mu | H | ✅ `src/tiny_router.js` |
559
+ | Slide/deck skill (PDF) | qybaihe/codex-ppt | H | ✅ `src/deck.js` |
560
+ | Canonical Agent Skills schema | anthropics/skills | H | ✅ `src/skill_schema.js` |
561
+ | Interactive architecture map page | haydenschmitty/floorplan | H | ✅ `public/map.html` + `/api/code-map` |
562
+ | Guardrail routing API surface | sandbox-quantum/switch-trust | H | ✅ `src/guardrail_api.js` |
563
+ | IoC feed import | cisco-talos/IOCs | H | ✅ `src/ioc_import.js` + KB store |
564
+ | Synthetic security log corpus | cisco-talos/EvidenceForge | H | ✅ `src/security_logs.js` |
565
+ | Teams + Mattermost channels | sandbox-quantum/switch | M | ✅ `src/channels_extra.js` |
566
+ | External agent CLI adapters | openai/codex-plugin-cc | M | ✅ `src/agent_cli.js` |
567
+ | Project-wide symbol rename (LSP) | sandbox-quantum/bartleby | M | ✅ `lsp.rename` + `applyWorkspaceEdit` |
568
+ | Package-install guard | usestrix/firewall | M | ✅ `src/package_guard.js` |
569
+ | Official MCP registry alignment | modelcontextprotocol/registry | M | ⬜ deferred |
570
+ | Codex skills catalog import | openai/skills | M | ⬜ deferred |
571
+ | Attachment malware scan (`clamscan`) | cisco-talos/clamav | M | ⬜ deferred (needs binary) |
572
+ | Binary function similarity | cisco-talos/binary_function_similarity | M | ⬜ deferred (needs RE pipeline work) |
573
+ | RAGFlow-style private retrieval | bytedance/deer-flow | M | ⬜ deferred (needs external service) |
574
+ | Codex-style MCP config presets | openai/codex | H | ⬜ deferred (existing `mcp_presets` covers most) |
575
+
575
576
  | OOB interaction channel | projectdiscovery/interactsh | M |
576
577
  | DNS/port enumeration | projectdiscovery/subfinder+dnsx+naabu | M |
577
578
  | Playwright browser driver | microsoft/playwright | M |
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.80.0.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aegisai-harness",
3
- "version": "0.80.0",
3
+ "version": "0.82.0",
4
4
  "description": "AegisAi Harness — feature-rich, local-only AI agent harness",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
@@ -4,13 +4,13 @@
4
4
  [Setup]
5
5
  AppId={{8F3D1B2A-6C4E-4B9A-9D21-AE615A010001}}
6
6
  AppName=AegisAi Harness
7
- AppVersion=0.80.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.80.0-Setup
13
+ OutputBaseFilename=AegisAi-Harness-0.82.0-Setup
14
14
  Compression=lzma2
15
15
  SolidCompression=yes
16
16
  PrivilegesRequired=lowest
@@ -0,0 +1,136 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en"><head><meta charset="utf-8" />
3
+ <title>Architecture Map — AegisAi Harness</title>
4
+ <link rel="stylesheet" href="/style.css" />
5
+ <style>
6
+ body { margin: 0; padding: 16px; }
7
+ .map-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 12px; }
8
+ #graph { position: relative; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); height: 72vh; overflow: hidden; }
9
+ .node { position: absolute; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); font-size: 11px; font-family: ui-monospace, monospace; cursor: pointer; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
10
+ .node.hub { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
11
+ .node.sel { background: var(--accent); color: #fff; }
12
+ svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
13
+ line { stroke: var(--border); stroke-width: 1; }
14
+ aside { border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow: auto; height: 72vh; }
15
+ aside h3 { margin: 0 0 8px; font-size: 13px; }
16
+ aside pre { font-size: 11px; white-space: pre-wrap; word-break: break-word; }
17
+ .stat { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; border-bottom: 1px solid var(--border); }
18
+ .legend { font-size: 11px; color: var(--muted, #8b949e); margin-top: 8px; }
19
+ </style></head>
20
+ <body>
21
+ <header style="display:flex;gap:8px;align-items:center;margin-bottom:12px">
22
+ <h2 style="margin:0">Architecture Map</h2>
23
+ <button onclick="location.href='/'">Back</button>
24
+ <button onclick="load(true)">Refresh</button>
25
+ <label style="font-size:12px;margin-left:auto">max files <input id="limit" type="number" value="60" min="5" max="400" style="width:64px" /></label>
26
+ </header>
27
+ <div class="map-wrap">
28
+ <div id="graph"><svg id="edges"></svg></div>
29
+ <aside>
30
+ <h3>Summary</h3>
31
+ <div id="stats"></div>
32
+ <h3 style="margin-top:12px">Module</h3>
33
+ <pre id="detail">Click a module.</pre>
34
+ <div class="legend">Nodes are files, edges are `require`/`import` relationships inside the project root. Hover a node to highlight its edges.</div>
35
+ <div class="legend" id="error" style="color:var(--danger)"></div>
36
+ </aside>
37
+ </div>
38
+ <script src="/authtoken.js"></script>
39
+ <script>
40
+ let data = null;
41
+ let selected = null;
42
+
43
+ function shortName(p) {
44
+ return String(p).split(/[\\/]/).pop();
45
+ }
46
+
47
+ function layout(nodes) {
48
+ const cols = Math.max(3, Math.ceil(Math.sqrt(nodes.length * 1.6)));
49
+ const graph = document.getElementById('graph');
50
+ const W = graph.clientWidth || 800;
51
+ const H = graph.clientHeight || 500;
52
+ const padX = 90, padY = 50;
53
+ const colW = (W - padX * 2) / Math.max(1, cols - 1 || 1);
54
+ const rows = Math.max(1, Math.ceil(nodes.length / cols));
55
+ const rowH = (H - padY * 2) / Math.max(1, rows - 1 || 1);
56
+ return nodes.map((n, i) => {
57
+ const c = i % cols;
58
+ const r = Math.floor(i / cols);
59
+ return { ...n, x: padX + c * colW, y: padY + r * rowH };
60
+ });
61
+ }
62
+
63
+ function render() {
64
+ const graph = document.getElementById('graph');
65
+ graph.querySelectorAll('.node').forEach((el) => el.remove());
66
+ const svg = document.getElementById('edges');
67
+ svg.innerHTML = '';
68
+ const nodes = layout(data.nodes || []);
69
+ const byPath = new Map(nodes.map((n) => [n.path, n]));
70
+ const degree = new Map();
71
+ for (const e of data.edges || []) {
72
+ degree.set(e.from, (degree.get(e.from) || 0) + 1);
73
+ degree.set(e.to, (degree.get(e.to) || 0) + 1);
74
+ }
75
+ for (const e of data.edges || []) {
76
+ const a = byPath.get(e.from); const b = byPath.get(e.to);
77
+ if (!a || !b) continue;
78
+ const line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
79
+ line.setAttribute('x1', a.x); line.setAttribute('y1', a.y);
80
+ line.setAttribute('x2', b.x); line.setAttribute('y2', b.y);
81
+ line.dataset.from = e.from; line.dataset.to = e.to;
82
+ svg.appendChild(line);
83
+ }
84
+ for (const n of nodes) {
85
+ const d = document.createElement('div');
86
+ d.className = 'node' + ((degree.get(n.path) || 0) >= 4 ? ' hub' : '') + (selected === n.path ? ' sel' : '');
87
+ d.style.left = n.x + 'px'; d.style.top = n.y + 'px';
88
+ d.style.transform = 'translate(-50%,-50%)';
89
+ d.textContent = shortName(n.path);
90
+ d.title = n.path;
91
+ d.onmouseenter = () => highlight(n.path);
92
+ d.onmouseleave = () => highlight(null);
93
+ d.onclick = () => { selected = n.path; render(); showDetail(n); };
94
+ graph.appendChild(d);
95
+ }
96
+ const stat = document.getElementById('stats');
97
+ stat.innerHTML = '';
98
+ for (const [k, v] of [['files', (data.nodes || []).length], ['edges', (data.edges || []).length], ['languages', (data.languages || []).join(', ') || '-']]) {
99
+ const row = document.createElement('div'); row.className = 'stat';
100
+ row.innerHTML = '<span>' + k + '</span><span>' + v + '</span>';
101
+ stat.appendChild(row);
102
+ }
103
+ }
104
+
105
+ function highlight(path) {
106
+ const svg = document.getElementById('edges');
107
+ for (const line of svg.querySelectorAll('line')) {
108
+ const on = !path || line.dataset.from === path || line.dataset.to === path;
109
+ line.style.opacity = on ? '1' : '0.08';
110
+ line.style.stroke = on && path ? 'var(--accent)' : 'var(--border)';
111
+ }
112
+ }
113
+
114
+ function showDetail(n) {
115
+ const out = (data.edges || []).filter((e) => e.from === n.path).map((e) => '→ ' + e.to);
116
+ const inc = (data.edges || []).filter((e) => e.to === n.path).map((e) => '← ' + e.from);
117
+ document.getElementById('detail').textContent = n.path + '\n\n' + (out.concat(inc).join('\n') || '(no internal edges)');
118
+ }
119
+
120
+ async function load(refresh) {
121
+ document.getElementById('error').textContent = '';
122
+ try {
123
+ const limit = document.getElementById('limit').value || 60;
124
+ const r = await fetch('/api/code-map?limit=' + encodeURIComponent(limit) + (refresh ? '&refresh=1' : ''));
125
+ if (!r.ok) throw new Error('HTTP ' + r.status);
126
+ data = await r.json();
127
+ if (!data.nodes) throw new Error(data.error || 'no data');
128
+ render();
129
+ } catch (e) {
130
+ document.getElementById('error').textContent = 'Failed to load: ' + e.message;
131
+ }
132
+ }
133
+ load();
134
+ window.addEventListener('resize', () => { if (data) render(); });
135
+ </script>
136
+ </body></html>
@@ -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 };
@@ -0,0 +1,89 @@
1
+ // src/agent_cli.js
2
+ // Adapters that delegate a task to an external coding-agent CLI and capture the
3
+ // result as structured evidence. Nothing runs unless the binary is present and
4
+ // the caller explicitly invokes it.
5
+ const { spawnSync } = require('child_process');
6
+
7
+ const ADAPTERS = [
8
+ {
9
+ id: 'codex',
10
+ bin: 'codex',
11
+ buildArgs: (task, opts) => (opts && opts.fullAuto ? ['exec', '--full-auto', task] : ['exec', task]),
12
+ notes: 'OpenAI Codex CLI',
13
+ },
14
+ {
15
+ id: 'claude',
16
+ bin: 'claude',
17
+ buildArgs: (task) => ['-p', task],
18
+ notes: 'Claude Code CLI (print mode)',
19
+ },
20
+ {
21
+ id: 'aider',
22
+ bin: 'aider',
23
+ buildArgs: (task, opts) => ['--yes', '--message', task].concat((opts && opts.files) || []),
24
+ notes: 'Aider',
25
+ },
26
+ {
27
+ id: 'gemini',
28
+ bin: 'gemini',
29
+ buildArgs: (task) => ['-p', task],
30
+ notes: 'Gemini CLI',
31
+ },
32
+ ];
33
+
34
+ function which(bin) {
35
+ const cmd = process.platform === 'win32' ? 'where' : 'which';
36
+ try {
37
+ const r = spawnSync(cmd, [bin], { encoding: 'utf8', timeout: 5000 });
38
+ if (r.status === 0) return String(r.stdout || '').split(/\r?\n/).filter(Boolean)[0] || bin;
39
+ } catch (e) {}
40
+ return null;
41
+ }
42
+
43
+ function detect() {
44
+ return ADAPTERS.map((a) => ({ id: a.id, bin: a.bin, notes: a.notes, available: Boolean(which(a.bin)) }));
45
+ }
46
+
47
+ function get(id) { return ADAPTERS.find((a) => a.id === id) || null; }
48
+
49
+ /**
50
+ * run(id, task, opts) -> { ok, agent, exitCode, stdout, stderr, duration }
51
+ * opts: { cwd, timeoutMs, files, fullAuto, dryRun }
52
+ */
53
+ function run(id, task, opts) {
54
+ opts = opts || {};
55
+ const adapter = get(id);
56
+ if (!adapter) return { ok: false, error: 'unknown agent: ' + id };
57
+ const binPath = which(adapter.bin);
58
+ if (!binPath) return { ok: false, agent: id, error: 'binary not found on PATH: ' + adapter.bin };
59
+ const args = adapter.buildArgs(task, opts);
60
+ if (opts.dryRun) return { ok: true, agent: id, dryRun: true, bin: binPath, args };
61
+ const started = Date.now();
62
+ const r = spawnSync(binPath, args, {
63
+ cwd: opts.cwd || process.cwd(),
64
+ encoding: 'utf8',
65
+ timeout: opts.timeoutMs || 300000,
66
+ maxBuffer: 20 * 1024 * 1024,
67
+ shell: false,
68
+ });
69
+ return {
70
+ ok: r.status === 0,
71
+ agent: id,
72
+ exitCode: r.status,
73
+ stdout: String(r.stdout || '').slice(0, 200000),
74
+ stderr: String(r.stderr || '').slice(0, 20000),
75
+ duration: Date.now() - started,
76
+ args,
77
+ };
78
+ }
79
+
80
+ // Capture a delegation as an evidence record in the ledger.
81
+ function record(id, task, result) {
82
+ try {
83
+ const ledger = require('./ledger');
84
+ ledger.append('agent_cli_delegation', { agent: id, task: String(task || '').slice(0, 500), ok: result.ok, exitCode: result.exitCode, duration: result.duration });
85
+ } catch (e) {}
86
+ return result;
87
+ }
88
+
89
+ module.exports = { ADAPTERS, detect, get, run, record, which };
@@ -0,0 +1,67 @@
1
+ // src/channels_extra.js
2
+ // Microsoft Teams and Mattermost channel adapters.
3
+ // Same contract as src/channels.js: handle(text, opts) -> { ok, reply, channel }.
4
+ // No network calls unless a webhook/client is configured.
5
+
6
+ function teamsPayload(text, opts) {
7
+ opts = opts || {};
8
+ return {
9
+ '@type': 'MessageCard',
10
+ '@context': 'https://schema.org/extensions',
11
+ themeColor: opts.color || '0A66C2',
12
+ summary: opts.title || 'AegisAi Harness',
13
+ sections: [{ activityTitle: opts.title || 'AegisAi Harness', text: String(text || '') }],
14
+ };
15
+ }
16
+
17
+ function mattermostPayload(text, opts) {
18
+ opts = opts || {};
19
+ return { channel: opts.channel || '', username: opts.username || 'aegisai-harness', text: String(text || '') };
20
+ }
21
+
22
+ function handleTeams(input, client) {
23
+ return handle('teams', input, client, teamsPayload);
24
+ }
25
+ function handleMattermost(input, client) {
26
+ return handle('mattermost', input, client, mattermostPayload);
27
+ }
28
+
29
+ function handle(kind, input, client, payloadFor) {
30
+ const text = typeof input === 'string' ? input : (input && input.text) || '';
31
+ const mention = /@?aegis(ai)?(?:-harness)?\b/i.exec(text);
32
+ const body = mention ? text.slice(mention.index + mention[0].length).trim() : text.trim();
33
+ const payload = payloadFor(body || text, input && input.opts);
34
+ if (!client || typeof client.send !== 'function') {
35
+ return { ok: false, channel: kind, note: 'no ' + kind + ' client configured (mock mode)', payload };
36
+ }
37
+ try {
38
+ const r = client.send(payload);
39
+ return { ok: true, channel: kind, sent: true, result: r };
40
+ } catch (e) {
41
+ return { ok: false, channel: kind, error: String(e.message || e) };
42
+ }
43
+ }
44
+
45
+ function status() {
46
+ return {
47
+ teams: { configured: Boolean(process.env.AEGISAI_TEAMS_WEBHOOK), transport: 'incoming-webhook' },
48
+ mattermost: { configured: Boolean(process.env.AEGISAI_MATTERMOST_URL), transport: 'incoming-webhook' },
49
+ existing: ['slack', 'telegram', 'discord', 'dingtalk', 'feishu'],
50
+ };
51
+ }
52
+
53
+ // Post to a configured incoming webhook (opt-in, network call).
54
+ async function post(kind, text, opts) {
55
+ opts = opts || {};
56
+ const url = kind === 'teams' ? process.env.AEGISAI_TEAMS_WEBHOOK : process.env.AEGISAI_MATTERMOST_URL;
57
+ if (!url) return { ok: false, channel: kind, error: 'webhook not configured' };
58
+ const payload = kind === 'teams' ? teamsPayload(text, opts) : mattermostPayload(text, opts);
59
+ try {
60
+ const r = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), signal: AbortSignal.timeout(10000) });
61
+ return { ok: r.ok, channel: kind, status: r.status };
62
+ } catch (e) {
63
+ return { ok: false, channel: kind, error: String(e.message || e) };
64
+ }
65
+ }
66
+
67
+ module.exports = { teamsPayload, mattermostPayload, handleTeams, handleMattermost, status, post };