@radicaltools/cli 0.3.3 → 0.4.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/README.md CHANGED
@@ -556,6 +556,104 @@ of its tool's real output; `src/sensors/contract.test.ts` runs every adapter on
556
556
  its fixture and checks that it writes valid radical-metrics/1 and takes no
557
557
  threshold. Pull requests welcome.
558
558
 
559
+ ## radical assay
560
+
561
+ Radical Assay finds the model in existing code (experimental). `extract` is
562
+ its deterministic part: it reads the facts of each code repository in the
563
+ directories given, each with its file and line, and writes no model; an agent
564
+ turns the facts into one over MCP (`assay_start`, see the MCP server's
565
+ README).
566
+
567
+ ```bash
568
+ radical assay extract ../shop # every repository in ../shop
569
+ radical assay extract orders storefront --report storefront=reports/unit.json
570
+ radical assay extract . --json # the facts and links as JSON
571
+ radical assay extract ~/handover/billing.zip # code handed over as an archive
572
+ ```
573
+
574
+ A directory is a repository when it has a `.git`; one that is not stands for
575
+ the repositories directly inside it, or is a folder of code itself when it
576
+ holds none. A directory of nothing but folders is searched three levels down. A
577
+ `.zip` file is unpacked into `.radical/assay/unpacked/` first, without any
578
+ `.git` folder it holds (and refused whole when an entry would land outside
579
+ it). A folder of code is left as it was: its facts go to
580
+ `.radical/assay/facts/` of the current directory. Nothing is fetched or
581
+ cloned. For each repository it reads, from the files git lists:
582
+
583
+ - units, wherever they are: npm packages, Nx projects (`project.json`),
584
+ Composer projects (PHP, Laravel), Maven and Gradle projects, Go modules (or
585
+ main packages before modules), .NET projects and SQL Server database
586
+ projects (`.sqlproj`), Python projects, VB6 projects, and a folder with a
587
+ Dockerfile no manifest claims (not a `.devcontainer`, nor one that copies
588
+ other units' projects: it builds them, nor a runner image whose compose
589
+ service mounts a unit's folder: that service runs the unit); not a
590
+ workspace's root (a `pyproject.toml` without `[project]`, a `go.mod` with
591
+ no Go code of its own) nor a library vendored in `wwwroot/lib`; each an app, a library or tests,
592
+ with its stack and the frameworks it names;
593
+ - each unit's dependencies, and its references to other units by path (a
594
+ .NET `ProjectReference`, also those `Directory.Build.props` and
595
+ `.targets` add by conditions on the project's name and path, a VB6
596
+ `Reference=*\A…vbp`, a Gradle `project(':x')`, a Go `replace` to a
597
+ folder);
598
+ a VB6 reference to a COM binary another unit builds counts as one;
599
+ - solutions and VB6 groups (`.sln`, `.vbg`);
600
+ - what runs: the services of docker-compose files, Kubernetes manifests and
601
+ .NET Aspire AppHosts, each built from a unit or running a database, queue,
602
+ cache or observability image, with what it depends on or references;
603
+ - calls: OpenAPI operations, gRPC services (`.proto`) with the units that
604
+ register and call them, and addresses in code and configuration (a URL or
605
+ `host:port` naming another unit or service, `lb://name`, a host given as a
606
+ default or named in a variable such as `${CART_HOST}`, a local port only
607
+ one unit listens on or publishes from compose, a gateway's `serviceId`, a
608
+ Feign client's name); a Spring Cloud Config server's files are read as the
609
+ configuration of the applications they are named for, its
610
+ `application.yml` as every client's (a client library's settings only for
611
+ units depending on that library); a gRPC client a library's function makes
612
+ is a client of each unit calling that function; a migrator or seeder
613
+ another service depends on is no call of it; a VB6 socket's host and port and a
614
+ connection string's server and database are followed through the
615
+ constants, variables, record fields and INI settings that hold them;
616
+ - data: the databases connection strings name (ADO and OLE DB, ODBC, JDBC,
617
+ .NET, PDO, Go's MySQL driver, database URLs, a `.env` file's
618
+ `DB_CONNECTION` (or Laravel's default connection) and `DB_DATABASE`, a
619
+ compose service's environment, a Prisma datasource, an SQLite URL; not a
620
+ commented line, nor a placeholder name, which a dump's database stands in
621
+ for) and the tables SQL names; a table SQL creates or alters, Laravel's
622
+ migrations create, or an ORM class maps (JPA, Entity Framework Core, Django
623
+ with Wagtail's models, SQLAlchemy, TypeORM, Prisma, Doctrine), with its
624
+ columns and the table each foreign key references, and many-to-many join
625
+ tables;
626
+ migrations count in order, so a table a later one drops is gone; a table
627
+ in a schema is named by schema and name only where two schemas hold its
628
+ name. An Access file's own tables are read by the
629
+ MCP server only: the CLI notes each Access file a unit uses;
630
+ - statuses: the values an enum named for a status, a `CHECK … IN` list, an
631
+ SQL `ENUM`, a table's flags (boolean columns, nullable dates of an event)
632
+ or a field set to quoted values (`!Paid = "Y"`) give, and the lines that
633
+ set each value;
634
+ - screens: each VB6 form and ActiveX document, with its caption, size, controls at their
635
+ positions and the forms its code opens;
636
+ - entry points: HTTP routes in code (Express, NestJS, Spring, ASP.NET Core,
637
+ Flask, FastAPI, Go), a VB6 form's caption, menu items and any control with
638
+ a Click handler, VB6 Timers that do more than change the screen and `Handle…` procedures, scheduled jobs and
639
+ message handlers; and each unit's test framework;
640
+ - the tests its reports name (Vitest, Jest or Playwright JSON, JUnit XML; by
641
+ default its `reports/`), as `<file> › <title>` from its root;
642
+ - its documents: READMEs, the documents of `docs/` and decisions folders and
643
+ its ADR records, each with its title and headings.
644
+
645
+ Documentation from outside the code (folders, `.zip` files, public links) is
646
+ taken over MCP (`assay_start`'s `sources`, `assay_add_sources`).
647
+
648
+ They go to the repository's `.radical/assay/facts.json`. Then the units are
649
+ linked across the repositories: references, dependencies, `depends_on` and
650
+ connection strings as observed; OpenAPI paths, gRPC clients and addresses as
651
+ inferred. Each link cites the facts of both sides.
652
+
653
+ `packages/assay/bench` measures it on pinned public repositories of several
654
+ stacks and ages: `npx tsx packages/assay/bench/bench.ts` (and `--held-out`
655
+ for the ones no rule was tuned on).
656
+
559
657
  ## radical fuzz
560
658
 
561
659
  Runs a project's fuzz files (Radical Crucible): tests that do random sequences
@@ -0,0 +1,28 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require2() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+
15
+ // <define:__RADICAL_BUILD__>
16
+ var define_RADICAL_BUILD_default;
17
+ var init_define_RADICAL_BUILD = __esm({
18
+ "<define:__RADICAL_BUILD__>"() {
19
+ define_RADICAL_BUILD_default = { version: "0.4.0", commit: "8f1e2cd", date: "2026-11-10", release: true };
20
+ }
21
+ });
22
+
23
+ export {
24
+ __require,
25
+ __commonJS,
26
+ init_define_RADICAL_BUILD,
27
+ define_RADICAL_BUILD_default
28
+ };
@@ -0,0 +1,219 @@
1
+ import {
2
+ init_define_RADICAL_BUILD
3
+ } from "./chunk-3H4ISGOV.js";
4
+
5
+ // ../../packages/assay/node_modules/unpdf/dist/index.mjs
6
+ init_define_RADICAL_BUILD();
7
+ var resolvedModule;
8
+ var isNode = globalThis.process?.release?.name === "node";
9
+ var isBrowser = typeof window !== "undefined";
10
+ async function getDocumentProxy(data, options = {}) {
11
+ const { getDocument } = await getResolvedPDFJS();
12
+ const pdf = await getDocument({
13
+ data,
14
+ isEvalSupported: false,
15
+ // See: https://github.com/mozilla/pdf.js/issues/4244#issuecomment-1479534301
16
+ useSystemFonts: true,
17
+ ...options
18
+ }).promise;
19
+ return pdf;
20
+ }
21
+ async function getResolvedPDFJS() {
22
+ if (!resolvedModule) {
23
+ await resolvePDFJSImports();
24
+ }
25
+ return resolvedModule;
26
+ }
27
+ async function resolvePDFJSImports(pdfjsResolver, { force = false } = {}) {
28
+ if (resolvedModule && !force) {
29
+ return;
30
+ }
31
+ if (pdfjsResolver) {
32
+ try {
33
+ resolvedModule = await interopDefault(pdfjsResolver());
34
+ if (resolvedModule && "resolvePDFJS" in resolvedModule) {
35
+ resolvedModule = await resolvedModule.resolvePDFJS();
36
+ }
37
+ return;
38
+ } catch (error) {
39
+ console.error(error);
40
+ throw new Error("Resolving failed. Please check the provided configuration.");
41
+ }
42
+ }
43
+ try {
44
+ const { resolvePDFJS } = await import("./pdfjs-I4NKVZXV.js");
45
+ resolvedModule = await resolvePDFJS();
46
+ } catch (error) {
47
+ console.error(error);
48
+ throw new Error("PDF.js is not available. Please add the package as a dependency.");
49
+ }
50
+ }
51
+ function isPDFDocumentProxy(data) {
52
+ return typeof data === "object" && data !== null && "_pdfInfo" in data;
53
+ }
54
+ async function interopDefault(m) {
55
+ const resolved = await m;
56
+ return resolved.default || resolved;
57
+ }
58
+ async function extractImages$1(data, pageNumber) {
59
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
60
+ if (pageNumber < 1 || pageNumber > pdf.numPages) {
61
+ throw new Error(`Invalid page number. Must be between 1 and ${pdf.numPages}.`);
62
+ }
63
+ const page = await pdf.getPage(pageNumber);
64
+ const operatorList = await page.getOperatorList();
65
+ const { OPS } = await getResolvedPDFJS();
66
+ const images = [];
67
+ for (let i = 0; i < operatorList.fnArray.length; i++) {
68
+ const op = operatorList.fnArray[i];
69
+ if (op !== OPS.paintImageXObject) {
70
+ continue;
71
+ }
72
+ const imageKey = operatorList.argsArray[i][0];
73
+ const image = await page.objs.get(imageKey);
74
+ if (!image || !image.data || !image.width || !image.height) {
75
+ continue;
76
+ }
77
+ const { width, height, data: data2 } = image;
78
+ const calculatedChannels = data2.length / (width * height);
79
+ if (![1, 3, 4].includes(calculatedChannels)) {
80
+ continue;
81
+ }
82
+ const channels = calculatedChannels;
83
+ images.push({
84
+ data: data2,
85
+ width,
86
+ height,
87
+ channels,
88
+ key: imageKey
89
+ });
90
+ }
91
+ return images;
92
+ }
93
+ async function renderPageAsImage$1(data, pageNumber, options = {}) {
94
+ const canvasFactory = await createIsomorphicCanvasFactory(options.canvas);
95
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data, { canvasFactory });
96
+ const page = await pdf.getPage(pageNumber);
97
+ if (pageNumber < 1 || pageNumber > pdf.numPages) {
98
+ throw new Error(`Invalid page number. Must be between 1 and ${pdf.numPages}.`);
99
+ }
100
+ let outputScale = options.scale || 1;
101
+ let viewport = page.getViewport({ scale: outputScale });
102
+ if (options.width) {
103
+ outputScale = options.width / viewport.width;
104
+ } else if (options.height) {
105
+ outputScale = options.height / viewport.height;
106
+ }
107
+ if (outputScale !== 1 && outputScale > 0) {
108
+ viewport = page.getViewport({ scale: outputScale });
109
+ }
110
+ const ctx = canvasFactory.create(viewport.width, viewport.height);
111
+ await page.render({
112
+ canvasContext: ctx.context,
113
+ viewport
114
+ }).promise;
115
+ const dataUrl = isBrowser ? ctx.canvas.toDataURL() : ctx.canvas.toDataURL();
116
+ const response = await fetch(dataUrl);
117
+ return await response.arrayBuffer();
118
+ }
119
+ async function createIsomorphicCanvasFactory(canvas) {
120
+ const _canvas = canvas ? await interopDefault(canvas()) : void 0;
121
+ return {
122
+ _createCanvas(width, height) {
123
+ if (isBrowser) {
124
+ const canvas2 = document.createElement("canvas");
125
+ canvas2.width = width;
126
+ canvas2.height = height;
127
+ return canvas2;
128
+ }
129
+ if (isNode) {
130
+ if (!_canvas) {
131
+ throw new Error('Failed to resolve "canvas" package.');
132
+ }
133
+ return _canvas.createCanvas(width, height);
134
+ }
135
+ throw new Error("Unsupported environment for canvas creation.");
136
+ },
137
+ create(width, height) {
138
+ const _canvas2 = this._createCanvas(width, height);
139
+ const context = _canvas2.getContext(
140
+ "2d"
141
+ );
142
+ return {
143
+ canvas: _canvas2,
144
+ context
145
+ };
146
+ },
147
+ reset(ctx, width, height) {
148
+ if (ctx.canvas) {
149
+ ctx.canvas.width = width;
150
+ ctx.canvas.height = height;
151
+ }
152
+ },
153
+ destroy(ctx) {
154
+ if (ctx.canvas) {
155
+ ctx.canvas.width = 0;
156
+ ctx.canvas.height = 0;
157
+ }
158
+ ctx.canvas = void 0;
159
+ ctx.context = void 0;
160
+ }
161
+ };
162
+ }
163
+ async function getMeta$1(data) {
164
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
165
+ const meta = await pdf.getMetadata();
166
+ return {
167
+ info: meta?.info ?? {},
168
+ metadata: meta?.metadata?.getAll() ?? {}
169
+ };
170
+ }
171
+ async function extractText$1(data, options = {}) {
172
+ const { mergePages = false } = { ...options };
173
+ const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
174
+ const texts = await Promise.all(
175
+ Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
176
+ );
177
+ return {
178
+ totalPages: pdf.numPages,
179
+ text: mergePages ? texts.join("\n").replace(/\s+/g, " ") : texts
180
+ };
181
+ }
182
+ async function getPageText(document2, pageNumber) {
183
+ const page = await document2.getPage(pageNumber);
184
+ const content = await page.getTextContent();
185
+ return content.items.filter((item) => item.str != null).map((item) => item.str + (item.hasEOL ? "\n" : "")).join("");
186
+ }
187
+ async function configureUnPDF(options) {
188
+ const { pdfjs } = { ...options };
189
+ if (pdfjs) {
190
+ await resolvePDFJSImports(pdfjs, { force: true });
191
+ }
192
+ }
193
+ var getMeta = async (...args) => {
194
+ await resolvePDFJSImports();
195
+ return await getMeta$1(...args);
196
+ };
197
+ var extractText = async (...args) => {
198
+ await resolvePDFJSImports();
199
+ return await extractText$1(...args);
200
+ };
201
+ var extractImages = async (...args) => {
202
+ await resolvePDFJSImports();
203
+ return await extractImages$1(...args);
204
+ };
205
+ var renderPageAsImage = async (...args) => {
206
+ await resolvePDFJSImports();
207
+ return await renderPageAsImage$1(...args);
208
+ };
209
+ export {
210
+ configureUnPDF,
211
+ createIsomorphicCanvasFactory,
212
+ extractImages,
213
+ extractText,
214
+ getDocumentProxy,
215
+ getMeta,
216
+ getResolvedPDFJS,
217
+ renderPageAsImage,
218
+ resolvePDFJSImports
219
+ };