aegisai-harness 0.80.0 → 0.81.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.81.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.81.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.81.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.81.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.81.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.81.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,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 };
package/src/deck.js ADDED
@@ -0,0 +1,92 @@
1
+ // src/deck.js
2
+ // Slide-deck generator: 16:9 landscape PDF decks from a simple outline.
3
+ // Uses the zero-dependency PDF writer; no external tooling.
4
+ const path = require('path');
5
+ const { buildPdf } = require('./pdf_writer');
6
+
7
+ // 16:9 landscape at 1280x720 points ⇒ readable on projectors and in PDF viewers.
8
+ const SLIDE_W = 960;
9
+ const SLIDE_H = 540;
10
+
11
+ function makeWriter() {
12
+ // A tiny variant of buildPdf that lays out one slide per page at 960x540.
13
+ const pdf = require('./pdf_writer');
14
+ // Reuse buildPdf by rendering each slide as its own short page; buildPdf uses
15
+ // Letter portrait, so we implement a slide-specific writer here instead.
16
+ return pdf;
17
+ }
18
+
19
+ function escape(s) {
20
+ return String(s == null ? '' : s).replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/[^\x20-\x7e]/g, '');
21
+ }
22
+
23
+ function buildSlidePdf(slides, meta) {
24
+ meta = meta || {};
25
+ const objs = [];
26
+ const add = (s) => { objs.push(s); return objs.length; };
27
+ add('<< /Type /Catalog /Pages 2 0 R >>');
28
+ objs.push('PLACEHOLDER');
29
+ const pageIds = [];
30
+ const fontIds = {};
31
+ const fallbackFont = () => { if (!fontIds.regular) { fontIds.regular = add('<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>'); fontIds.bold = add('<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold >>'); } return fontIds; };
32
+ for (const slide of slides) {
33
+ fallbackFont();
34
+ const ops = [];
35
+ // Background
36
+ ops.push('1 1 1 rg 0 0 ' + SLIDE_W + ' ' + SLIDE_H + ' re f');
37
+ // Title bar
38
+ ops.push('0.086 0.106 0.145 rg 0 ' + (SLIDE_H - 96) + ' ' + SLIDE_W + ' 96 re f');
39
+ ops.push('BT /F2 30 Tf 1 1 1 rg 48 ' + (SLIDE_H - 62) + ' Td (' + escape(slide.title || '') + ') Tj ET');
40
+ let y = SLIDE_H - 150;
41
+ for (const line of slide.bullets || []) {
42
+ ops.push('BT /F1 20 Tf 0.13 0.16 0.19 rg 64 ' + y + ' Td (' + escape('• ' + line) + ') Tj ET');
43
+ y -= 40;
44
+ }
45
+ if (slide.notes) {
46
+ ops.push('BT /F1 12 Tf 0.45 0.48 0.5 rg 64 40 Td (' + escape(slide.notes) + ') Tj ET');
47
+ }
48
+ const content = ops.join('\n');
49
+ const cId = add('<< /Length ' + Buffer.byteLength(content, 'latin1') + ' >>\nstream\n' + content + 'endstream');
50
+ const pId = add('<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ' + SLIDE_W + ' ' + SLIDE_H + '] /Resources << /Font << /F1 ' + fontIds.regular + ' 0 R /F2 ' + fontIds.bold + ' 0 R >> >> /Contents ' + cId + ' 0 R >>');
51
+ pageIds.push(pId);
52
+ }
53
+ objs[1] = '<< /Type /Pages /Kids [' + pageIds.map((i) => i + ' 0 R').join(' ') + '] /Count ' + pageIds.length + ' >>';
54
+ let out = '%PDF-1.4\n%\xE2\xE3\xCF\xD3\n';
55
+ const offsets = [0];
56
+ for (let i = 0; i < objs.length; i++) {
57
+ offsets[i + 1] = Buffer.byteLength(out, 'latin1');
58
+ out += (i + 1) + ' 0 obj\n' + objs[i] + '\nendobj\n';
59
+ }
60
+ const xref = Buffer.byteLength(out, 'latin1');
61
+ out += 'xref\n0 ' + (objs.length + 1) + '\n0000000000 65535 f \n';
62
+ for (let i = 1; i <= objs.length; i++) out += String(offsets[i]).padStart(10, '0') + ' 00000 n \n';
63
+ out += 'trailer\n<< /Size ' + (objs.length + 1) + ' /Root 1 0 R >>\nstartxref\n' + xref + '\n%%EOF\n';
64
+ return Buffer.from(out, 'latin1');
65
+ }
66
+
67
+ // Turn an outline (markdown-ish or object list) into slides.
68
+ function fromOutline(input) {
69
+ if (Array.isArray(input)) return input.map((s) => ({ title: s.title || '', bullets: s.bullets || [], notes: s.notes || '' }));
70
+ const slides = [];
71
+ let current = null;
72
+ for (const raw of String(input || '').split(/\r?\n/)) {
73
+ const line = raw.trim();
74
+ if (!line) continue;
75
+ if (/^#\s+/.test(line)) { current = { title: line.replace(/^#\s+/, ''), bullets: [], notes: '' }; slides.push(current); continue; }
76
+ if (/^##\s+/.test(line)) { current = { title: line.replace(/^##\s+/, ''), bullets: [], notes: '' }; slides.push(current); continue; }
77
+ if (/^[-*]\s+/.test(line)) { if (current) current.bullets.push(line.replace(/^[-*]\s+/, '')); continue; }
78
+ if (/^>\s+/.test(line)) { if (current) current.notes = line.replace(/^>\s+/, ''); continue; }
79
+ if (current) current.bullets.push(line);
80
+ }
81
+ return slides;
82
+ }
83
+
84
+ function generate(input, outputPath, meta) {
85
+ const slides = fromOutline(input);
86
+ if (!slides.length) throw Object.assign(new Error('no slides in outline'), { status: 400 });
87
+ const buf = buildSlidePdf(slides, meta);
88
+ if (outputPath) require('fs').writeFileSync(outputPath, buf);
89
+ return { slides: slides.length, bytes: buf.length, path: outputPath || null, buffer: outputPath ? undefined : buf };
90
+ }
91
+
92
+ module.exports = { generate, fromOutline, buildSlidePdf, SLIDE_W, SLIDE_H };
@@ -0,0 +1,98 @@
1
+ // src/guardrail_api.js
2
+ // Stable, documented surface for evaluating a tool call against every guardrail
3
+ // the harness already has: read-only boundary, policy rules, charter, sandbox
4
+ // rings, and the AHP supervisor. External tools can depend on this instead of
5
+ // reaching into internals.
6
+ const readOnly = require('./read_only');
7
+ const policy = require('./policy');
8
+ const charter = require('./charter');
9
+ const rings = require('./sandbox_rings');
10
+ const ahp = require('./ahp');
11
+
12
+ const DESTRUCTIVE = new Set(['write_file', 'edit_file', 'run_command', 'delete_file', 'move_file', 'apply_patch', 'run_python']);
13
+
14
+ /**
15
+ * evaluate({ tool, args, context })
16
+ * context: {
17
+ * readOnly: boolean,
18
+ * projectRoot: string|false, // false disables charter lookup
19
+ * policy: object, // parsed policy document
20
+ * charterObj: object, // pre-loaded charter
21
+ * sandboxRing: number, // current privilege ring (default TRUSTED)
22
+ * toolLog: array, // for action guard through AHP
23
+ * agent: string, // gateway identity
24
+ * }
25
+ * returns { decision: 'allow'|'ask'|'deny', reasons, layers }
26
+ */
27
+ function evaluate(input) {
28
+ input = input || {};
29
+ const tool = String(input.tool || '');
30
+ const args = input.args || {};
31
+ const ctx = input.context || {};
32
+ const reasons = [];
33
+ const layers = {};
34
+
35
+ if (!tool) return { decision: 'deny', reasons: ['no tool specified'], layers: {} };
36
+
37
+ // 1. Read-only boundary
38
+ {
39
+ const r = readOnly.enforce(tool, Boolean(ctx.readOnly));
40
+ layers.readOnly = r.allowed;
41
+ if (!r.allowed) reasons.push(r.reason || ('read-only mode blocks ' + tool));
42
+ }
43
+
44
+ // 2. Policy rules (only when a policy document is supplied)
45
+ if (ctx.policy) {
46
+ const p = policy.evaluate(ctx.policy, { tool_name: tool, args });
47
+ layers.policy = p;
48
+ if (!p.allowed) reasons.push('policy blocked: ' + (p.rule || 'rule'));
49
+ }
50
+
51
+ // 3. Charter (project-local rules)
52
+ let charterObj = ctx.charterObj || null;
53
+ if (!charterObj && ctx.projectRoot !== false) {
54
+ try { charterObj = charter.load ? charter.load(ctx.projectRoot || process.cwd()) : null; } catch (e) { charterObj = null; }
55
+ }
56
+ if (charterObj) {
57
+ const c = charter.enforce(charterObj, tool, args);
58
+ layers.charter = c;
59
+ if (!c.allowed) reasons.push('charter blocked: ' + (c.reason || 'rule'));
60
+ }
61
+
62
+ // 4. Sandbox ring
63
+ {
64
+ const toolRing = rings.ringOf(tool);
65
+ const currentRing = typeof ctx.sandboxRing === 'number' ? ctx.sandboxRing : rings.RINGS.TRUSTED;
66
+ const ok = rings.allowed(currentRing, toolRing);
67
+ layers.sandbox = { current: rings.describe(currentRing), tool: rings.describe(toolRing), allowed: ok };
68
+ if (!ok) reasons.push('sandbox ring ' + rings.describe(currentRing) + ' cannot run ' + tool);
69
+ }
70
+
71
+ // 5. AHP unified supervisor (runs the gates again with full context; its
72
+ // verdict is authoritative when supplied).
73
+ if (ctx.policy || ctx.charterObj || ctx.agent || ctx.actionGuard || ctx.readOnly) {
74
+ try {
75
+ const s = ahp.supervise(tool, args, {
76
+ policy: ctx.policy,
77
+ charterObj,
78
+ agent: ctx.agent,
79
+ actionGuard: ctx.actionGuard,
80
+ readOnly: ctx.readOnly,
81
+ toolLog: ctx.toolLog,
82
+ });
83
+ layers.ahp = s;
84
+ if (!s.allowed && s.blockedBy) reasons.push('AHP blocked at ' + s.blockedBy.gate + ': ' + (s.blockedBy.reason || 'denied'));
85
+ } catch (e) { layers.ahp = { error: String(e.message || e) }; }
86
+ }
87
+
88
+ const deny = reasons.some((r) => /block|denied|cannot|forbid/i.test(r));
89
+ let decision = 'allow';
90
+ if (deny) decision = 'deny';
91
+ else if (reasons.length) decision = 'ask';
92
+
93
+ return { decision, reasons, layers };
94
+ }
95
+
96
+ function isAllowed(input) { return evaluate(input).decision === 'allow'; }
97
+
98
+ module.exports = { evaluate, isAllowed, DESTRUCTIVE };