@oaksecurity/aitm 0.0.0-stage → 2.3.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.
Files changed (63) hide show
  1. package/.env.example +11 -0
  2. package/CHANGELOG.md +100 -0
  3. package/LICENSE +21 -0
  4. package/README.md +229 -2
  5. package/SECURITY.md +49 -0
  6. package/SPEC.md +304 -0
  7. package/docs/api.md +332 -0
  8. package/docs/inputs-and-limits.md +78 -0
  9. package/docs/usage.md +351 -0
  10. package/examples/custody-architecture.md +27 -0
  11. package/package.json +67 -4
  12. package/src/api/server.js +591 -0
  13. package/src/api/web.js +38 -0
  14. package/src/application.js +32 -0
  15. package/src/assessments.js +37 -0
  16. package/src/assets/BDOGrotesk-Bold.ttf +0 -0
  17. package/src/assets/BDOGrotesk-Regular.ttf +0 -0
  18. package/src/assets/OFL.txt +93 -0
  19. package/src/assets/README.md +10 -0
  20. package/src/cli.js +224 -0
  21. package/src/client.js +88 -0
  22. package/src/config.js +105 -0
  23. package/src/doctor.js +128 -0
  24. package/src/engine/credentials.js +31 -0
  25. package/src/engine/download.js +135 -0
  26. package/src/engine/engine.js +783 -0
  27. package/src/engine/errors.js +23 -0
  28. package/src/engine/generation.js +121 -0
  29. package/src/engine/ingest.js +444 -0
  30. package/src/engine/pdf-layout.js +204 -0
  31. package/src/engine/pdf-report.js +573 -0
  32. package/src/engine/prompts.js +82 -0
  33. package/src/engine/providers.js +476 -0
  34. package/src/engine/references.js +112 -0
  35. package/src/engine/report.js +200 -0
  36. package/src/engine/schema.js +267 -0
  37. package/src/engine/store.js +115 -0
  38. package/src/engine/validate.js +397 -0
  39. package/src/engine/zip.js +70 -0
  40. package/src/index.js +5 -0
  41. package/src/source-input.js +32 -0
  42. package/src/token.js +59 -0
  43. package/src/tui/app.js +694 -0
  44. package/src/tui/editor.js +34 -0
  45. package/src/tui/file-picker.js +111 -0
  46. package/src/tui/logo.js +8 -0
  47. package/src/tui/progress.js +90 -0
  48. package/src/tui/report-reader.js +105 -0
  49. package/src/tui/select.js +63 -0
  50. package/src/tui/workbench.js +377 -0
  51. package/src/version.js +5 -0
  52. package/src/web/app.js +729 -0
  53. package/src/web/assets/BDOGrotesk-Bold.woff2 +0 -0
  54. package/src/web/assets/BDOGrotesk-Medium.woff2 +0 -0
  55. package/src/web/assets/BDOGrotesk-Regular.woff2 +0 -0
  56. package/src/web/assets/README.md +5 -0
  57. package/src/web/assets/aitm-mark.svg +12 -0
  58. package/src/web/assets/oak-white.svg +166 -0
  59. package/src/web/html.js +32 -0
  60. package/src/web/index.html +26 -0
  61. package/src/web/markdown.js +48 -0
  62. package/src/web/styles.css +1450 -0
  63. package/src/web/views.js +254 -0
@@ -0,0 +1,204 @@
1
+ import PDFDocument from 'pdfkit';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ export const COLORS = {
5
+ ink: '#202126',
6
+ muted: '#61636C',
7
+ line: '#DEDDE2',
8
+ paper: '#F5F4F6',
9
+ gold: '#FFC965',
10
+ magenta: '#9C0069',
11
+ pale: '#F9EDF5',
12
+ };
13
+ const clean = (value) =>
14
+ String(value ?? '')
15
+ .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '')
16
+ .replace(/\t/g, ' ');
17
+ export const plain = (value) =>
18
+ clean(value)
19
+ .replace(/\*\*/g, '')
20
+ .replace(/`([^`]+)`/g, '$1');
21
+
22
+ // Owns page geometry and flowing text. Large fields flow onto new pages; diagrams
23
+ // and short records reserve space before drawing. No content uses clipping boxes.
24
+ export class ReportLayout {
25
+ constructor(project) {
26
+ this.doc = new PDFDocument({
27
+ size: 'A4',
28
+ margins: { top: 76, bottom: 62, left: 48, right: 48 },
29
+ autoFirstPage: false,
30
+ bufferPages: true,
31
+ info: { Title: `${project.name} — TRACE threat model`, Author: 'AiTM — AI-generated report' },
32
+ });
33
+ this.doc.registerFont(
34
+ 'Oak',
35
+ fileURLToPath(new URL('../assets/BDOGrotesk-Regular.ttf', import.meta.url)),
36
+ );
37
+ this.doc.registerFont(
38
+ 'Oak-Bold',
39
+ fileURLToPath(new URL('../assets/BDOGrotesk-Bold.ttf', import.meta.url)),
40
+ );
41
+ const chunks = [];
42
+ this.completed = new Promise((resolve, reject) => {
43
+ this.doc.on('data', (chunk) => chunks.push(chunk));
44
+ this.doc.on('end', () => resolve(Buffer.concat(chunks)));
45
+ this.doc.on('error', reject);
46
+ });
47
+ this.width = 499.28;
48
+ this.left = 48;
49
+ this.top = 76;
50
+ this.bottom = 779.89;
51
+ this.pages = [];
52
+ this.contents = [];
53
+ this.label = '';
54
+ this.doc.on('pageAdded', () => {
55
+ this.pages.push(this.label);
56
+ this.doc.x = this.left;
57
+ this.doc.y = this.top;
58
+ });
59
+ }
60
+ page(label = this.label) {
61
+ this.label = label;
62
+ this.doc.addPage();
63
+ }
64
+ ensure(height) {
65
+ if (this.doc.y + height > this.bottom) this.page();
66
+ }
67
+ gap(height = 12) {
68
+ this.doc.y += height;
69
+ }
70
+ style(size = 11, bold = false, color = COLORS.ink) {
71
+ return this.doc
72
+ .font(bold ? 'Oak-Bold' : 'Oak')
73
+ .fontSize(size)
74
+ .fillColor(color);
75
+ }
76
+ height(text, width = this.width, size = 11, bold = false) {
77
+ return this.style(size, bold).heightOfString(plain(text), { width, lineGap: 4 });
78
+ }
79
+ text(
80
+ value,
81
+ {
82
+ size = 11,
83
+ bold = false,
84
+ color = COLORS.ink,
85
+ indent = 0,
86
+ gap = 9,
87
+ literal = false,
88
+ ...options
89
+ } = {},
90
+ ) {
91
+ const text = literal ? clean(value) : plain(value);
92
+ if (!text) return;
93
+ this.ensure(size + 9);
94
+ this.style(size, bold, color).text(text, this.left + indent, this.doc.y, {
95
+ width: this.width - indent,
96
+ lineGap: 4,
97
+ ...options,
98
+ });
99
+ this.doc.y += gap;
100
+ }
101
+ anchor(id) {
102
+ this.doc.addNamedDestination(id, 'XYZ', this.left, this.doc.page.height - this.doc.y, null);
103
+ }
104
+ section(title) {
105
+ this.page(title);
106
+ const number = String(this.contents.length + 1).padStart(2, '0');
107
+ const id = `section-${number}`;
108
+ this.anchor(id);
109
+ this.contents.push({ title, number, id, page: this.pages.length });
110
+ this.doc.outline.addItem(title);
111
+ this.text(`SECTION ${number}`, { size: 9, bold: true, color: COLORS.magenta, gap: 12 });
112
+ this.text(title, { size: 28, bold: true, gap: 18 });
113
+ this.rule();
114
+ this.gap(18);
115
+ }
116
+ heading(title, { size = 17, id, keep = 52 } = {}) {
117
+ const height = this.height(title, this.width, size, true);
118
+ this.ensure(height + keep + 15);
119
+ if (id) this.anchor(id);
120
+ this.text(title, { size, bold: true, gap: 12 });
121
+ }
122
+ field(label, value, options = {}) {
123
+ if (!plain(value)) return;
124
+ this.ensure(55);
125
+ this.text(label, { size: 9, bold: true, color: COLORS.muted, gap: 3 });
126
+ this.text(value, options);
127
+ }
128
+ bullets(items) {
129
+ if (!items.length) return this.text('None recorded.', { color: COLORS.muted });
130
+ for (const item of items) {
131
+ this.ensure(30);
132
+ const y = this.doc.y;
133
+ this.doc.circle(this.left + 3, y + 7, 2).fill(COLORS.magenta);
134
+ this.text(item, { indent: 15, gap: 9 });
135
+ }
136
+ }
137
+ rule() {
138
+ const y = this.doc.y;
139
+ this.doc
140
+ .moveTo(this.left, y)
141
+ .lineTo(this.left + this.width, y)
142
+ .lineWidth(0.7)
143
+ .stroke(COLORS.line);
144
+ }
145
+ // A row for compact directories: wrapped labels and values, with a repeated
146
+ // section header supplied by the page furniture on automatic continuation pages.
147
+ row(label, value, { labelWidth = 112, size = 10, destination } = {}) {
148
+ const width = this.width - labelWidth - 16;
149
+ const height =
150
+ Math.max(this.height(label, labelWidth, size, true), this.height(value, width, size)) + 20;
151
+ if (height > this.bottom - this.top) {
152
+ this.heading(label, { size: 12 });
153
+ this.text(value, { size });
154
+ return;
155
+ }
156
+ this.ensure(height);
157
+ const y = this.doc.y;
158
+ this.style(size, true, destination ? COLORS.magenta : COLORS.ink).text(
159
+ plain(label),
160
+ this.left,
161
+ y + 7,
162
+ {
163
+ width: labelWidth,
164
+ lineGap: 4,
165
+ ...(destination ? { goTo: destination } : {}),
166
+ },
167
+ );
168
+ this.style(size).text(plain(value), this.left + labelWidth + 16, y + 7, { width, lineGap: 4 });
169
+ this.doc.y = y + height;
170
+ this.rule();
171
+ if (destination) this.doc.goTo(this.left, y, this.width, height, destination);
172
+ }
173
+ finish() {
174
+ const doc = this.doc;
175
+ const total = this.pages.length;
176
+ // Draw page furniture last so automatic text pagination cannot inherit its style.
177
+ for (let i = 0; i < total; i++) {
178
+ doc.switchToPage(i);
179
+ const bottomMargin = doc.page.margins.bottom;
180
+ doc.page.margins.bottom = 0;
181
+ if (i > 0) {
182
+ this.style(9, true, COLORS.magenta).text('AiTM / TRACE', 48, 31, { lineBreak: false });
183
+ this.style(9, false, COLORS.muted).text(this.pages[i], 180, 31, {
184
+ width: 367,
185
+ align: 'right',
186
+ lineBreak: false,
187
+ });
188
+ doc.moveTo(48, 54).lineTo(547.28, 54).lineWidth(0.6).stroke(COLORS.line);
189
+ }
190
+ doc.moveTo(48, 799).lineTo(547.28, 799).lineWidth(1).stroke(COLORS.gold);
191
+ this.style(8, false, COLORS.muted).text('AI-generated / TRACE threat model', 48, 811, {
192
+ lineBreak: false,
193
+ });
194
+ this.style(8, true, COLORS.muted).text(`${i + 1} / ${total}`, 487, 811, {
195
+ width: 60,
196
+ align: 'right',
197
+ lineBreak: false,
198
+ });
199
+ doc.page.margins.bottom = bottomMargin;
200
+ }
201
+ doc.end();
202
+ return this.completed;
203
+ }
204
+ }