create-astram-app 0.14.5 → 0.14.7
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astram-app",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Scaffolder for a new Astram app — emits a running, framework-enforced NestJS server (deny-by-default, built-in auth/identity to switch on) and, with --with-frontend, a React admin/auth UI, over the immutable @astram/* framework packages.",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// agentPlainText.test.mjs — personal-data-masking deviation (1e), QA iteration 5: the agent
|
|
2
|
+
// answer, claims, gaps, clarification questions (and option labels) and evidence render as
|
|
3
|
+
// PLAIN-TEXT nodes only: never through markdown, HTML injection or a linkifier.
|
|
4
|
+
//
|
|
5
|
+
// node --test src/platform/agentPlainText.test.mjs
|
|
6
|
+
//
|
|
7
|
+
// Why: `@astram/agent` swaps pseudonym tokens back to real values for the task's owner only when
|
|
8
|
+
// the server opts in with `AgentModule.forRoot({ masking: { ownerDisplay: 'plain-text' } })`, and
|
|
9
|
+
// that opt-in is the app's attestation of exactly this rendering. Model-written text could
|
|
10
|
+
// otherwise compose a link, image or URL around a real value. This template's server does not
|
|
11
|
+
// register AgentModule (so the swap is off); the guard still holds the agent UI to plain text, so
|
|
12
|
+
// an app that adds the agent and the opt-in keeps the attestation true.
|
|
13
|
+
//
|
|
14
|
+
// A static check (no React/DOM: this template has no DOM test harness and no agent answer
|
|
15
|
+
// component yet, so there is nothing to render): every source file under src/ that is agent UI
|
|
16
|
+
// (a file or folder named *agent*, or a file that mentions `agent` at all, which over-includes on
|
|
17
|
+
// purpose) must not use an HTML-injection API or import a markdown / HTML / linkify package, and
|
|
18
|
+
// the frontend's dependencies must hold none of those packages. A self-test proves each rule
|
|
19
|
+
// catches its violation.
|
|
20
|
+
import { test, describe } from 'node:test';
|
|
21
|
+
import assert from 'node:assert/strict';
|
|
22
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
23
|
+
import { basename, join, relative } from 'node:path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
|
|
26
|
+
const root = fileURLToPath(new URL('../..', import.meta.url));
|
|
27
|
+
const src = join(root, 'src');
|
|
28
|
+
|
|
29
|
+
/** HTML-injection APIs (React and DOM). */
|
|
30
|
+
const HTML_APIS = [
|
|
31
|
+
['dangerouslySetInnerHTML', /dangerouslySetInnerHTML/],
|
|
32
|
+
['innerHTML', /\binnerHTML\b/],
|
|
33
|
+
['outerHTML', /\bouterHTML\b/],
|
|
34
|
+
['insertAdjacentHTML', /\binsertAdjacentHTML\b/],
|
|
35
|
+
['document.write', /\bdocument\s*\.\s*write(?:ln)?\s*\(/],
|
|
36
|
+
['createContextualFragment', /\bcreateContextualFragment\b/],
|
|
37
|
+
['DOMParser', /\bDOMParser\b/],
|
|
38
|
+
['srcdoc', /\bsrcdoc\b/i],
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
/** Markdown, HTML-to-React and linkifier packages (and sanitizers, which imply rendered HTML). */
|
|
42
|
+
const RENDER_PACKAGE =
|
|
43
|
+
/^(?:react-markdown|marked|markdown-it(?:-.*)?|remark(?:-.*)?|rehype(?:-.*)?|micromark(?:-.*)?|mdast-.*|hast-.*|unified|showdown|commonmark|snarkdown|markdown-to-jsx|@mdx-js\/.*|@uiw\/react-md.*|linkifyjs|linkify-.*|react-linkify|autolinker|anchorme|html-react-parser|react-html-parser|htmr|dompurify|isomorphic-dompurify|sanitize-html|xss)(?:\/.*)?$/;
|
|
44
|
+
|
|
45
|
+
/** Every module specifier a source imports (static, dynamic, require, re-export). */
|
|
46
|
+
function specifiers(source) {
|
|
47
|
+
const out = [];
|
|
48
|
+
const patterns = [
|
|
49
|
+
/\bimport\s+(?:[^'"`;]*?\s+from\s+)?['"]([^'"]+)['"]/g,
|
|
50
|
+
/\bexport\s+[^'"`;]*?\s+from\s+['"]([^'"]+)['"]/g,
|
|
51
|
+
/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
52
|
+
/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
53
|
+
];
|
|
54
|
+
for (const p of patterns) for (const m of source.matchAll(p)) out.push(m[1]);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The rule violations of one source text (empty when it renders plain text only). */
|
|
59
|
+
export function violations(source) {
|
|
60
|
+
const found = [];
|
|
61
|
+
for (const [name, re] of HTML_APIS) if (re.test(source)) found.push(`uses ${name}`);
|
|
62
|
+
for (const spec of specifiers(source)) {
|
|
63
|
+
if (RENDER_PACKAGE.test(spec)) found.push(`imports ${spec}`);
|
|
64
|
+
}
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function sourceFiles(dir) {
|
|
69
|
+
const found = [];
|
|
70
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
71
|
+
const path = join(dir, entry.name);
|
|
72
|
+
if (entry.isDirectory()) found.push(...sourceFiles(path));
|
|
73
|
+
else if (/\.(?:jsx?|tsx?|mjs|cjs)$/.test(entry.name) && !entry.name.endsWith('.test.mjs')) {
|
|
74
|
+
found.push(path);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Agent UI: a file or folder named *agent*, or any file that mentions `agent` (over-includes). */
|
|
81
|
+
function agentUiFiles() {
|
|
82
|
+
return sourceFiles(src).filter((path) => {
|
|
83
|
+
const rel = relative(src, path);
|
|
84
|
+
return /agent/i.test(rel) || /\bagent\b/i.test(readFileSync(path, 'utf8'));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe('agent UI renders plain text only (personal-data-masking (1e))', () => {
|
|
89
|
+
test('the agent UI files are found (the guard is not vacuous)', () => {
|
|
90
|
+
const names = agentUiFiles().map((p) => basename(p));
|
|
91
|
+
assert.ok(names.includes('agentStreamTransport.js'), names.join(', '));
|
|
92
|
+
assert.ok(names.includes('AuthContext.jsx'), names.join(', '));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('no agent UI file uses an HTML-injection API or imports a markdown / HTML / linkify package', () => {
|
|
96
|
+
const bad = agentUiFiles()
|
|
97
|
+
.map((path) => [relative(root, path), violations(readFileSync(path, 'utf8'))])
|
|
98
|
+
.filter(([, v]) => v.length > 0)
|
|
99
|
+
.map(([path, v]) => `${path}: ${v.join(', ')}`);
|
|
100
|
+
assert.deepEqual(bad, []);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('the frontend depends on no markdown / HTML / linkify package', () => {
|
|
104
|
+
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
105
|
+
const deps = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies });
|
|
106
|
+
assert.deepEqual(
|
|
107
|
+
deps.filter((d) => RENDER_PACKAGE.test(d)),
|
|
108
|
+
[],
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('VIOLATION CAUGHT: each rule flags its pattern', () => {
|
|
113
|
+
const cases = [
|
|
114
|
+
['<p dangerouslySetInnerHTML={{ __html: frame.answer }} />', 'uses dangerouslySetInnerHTML'],
|
|
115
|
+
['node.innerHTML = claim.text;', 'uses innerHTML'],
|
|
116
|
+
["el.insertAdjacentHTML('beforeend', gap);", 'uses insertAdjacentHTML'],
|
|
117
|
+
['document.write(answer)', 'uses document.write'],
|
|
118
|
+
["import ReactMarkdown from 'react-markdown';", 'imports react-markdown'],
|
|
119
|
+
["import { marked } from 'marked';", 'imports marked'],
|
|
120
|
+
["import MarkdownIt from 'markdown-it';", 'imports markdown-it'],
|
|
121
|
+
["import remarkGfm from 'remark-gfm';", 'imports remark-gfm'],
|
|
122
|
+
["import Linkify from 'linkify-react';", 'imports linkify-react'],
|
|
123
|
+
["const linkify = require('linkifyjs');", 'imports linkifyjs'],
|
|
124
|
+
["const md = await import('micromark');", 'imports micromark'],
|
|
125
|
+
["import parse from 'html-react-parser';", 'imports html-react-parser'],
|
|
126
|
+
["export { default } from 'dompurify';", 'imports dompurify'],
|
|
127
|
+
];
|
|
128
|
+
for (const [source, expected] of cases) {
|
|
129
|
+
assert.ok(violations(source).includes(expected), `${source} ⇒ ${violations(source)}`);
|
|
130
|
+
}
|
|
131
|
+
// Plain-text rendering passes.
|
|
132
|
+
assert.deepEqual(violations('<p className="whitespace-pre-wrap">{frame.answer}</p>'), []);
|
|
133
|
+
assert.deepEqual(violations("import { Button } from '@/components/ui/button';"), []);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"postinstall": "node scripts/sync-astram-guide.mjs"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@astram/core": "1.
|
|
25
|
-
"@astram/engine": "0.
|
|
26
|
-
"@astram/guard": "0.
|
|
24
|
+
"@astram/core": "1.18.0",
|
|
25
|
+
"@astram/engine": "0.18.0",
|
|
26
|
+
"@astram/guard": "0.31.0",
|
|
27
27
|
"@astram/guide": "^0.2.8",
|
|
28
|
-
"@astram/identity": "0.
|
|
29
|
-
"@astram/messaging": "0.1.
|
|
30
|
-
"@astram/migrate": "0.7.
|
|
28
|
+
"@astram/identity": "0.30.0",
|
|
29
|
+
"@astram/messaging": "0.1.19",
|
|
30
|
+
"@astram/migrate": "0.7.8",
|
|
31
31
|
"@astram/sdk": "^0.2.0",
|
|
32
32
|
"@nestjs/common": "^11.2.7",
|
|
33
33
|
"@nestjs/core": "^11.2.7",
|