archscribe 0.2.0 → 0.2.1
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/LICENSE +33 -0
- package/dashboard-server/client-dist/assets/index-CswIFyKN.js +9 -0
- package/dashboard-server/client-dist/assets/index-DWB_-3yk.css +1 -0
- package/dashboard-server/client-dist/brand/favicon.png +0 -0
- package/dashboard-server/client-dist/brand/logo-full.png +0 -0
- package/dashboard-server/client-dist/icons.svg +24 -0
- package/dashboard-server/client-dist/index.html +14 -0
- package/dashboard-server/dist/core-bridge.js +19 -0
- package/dashboard-server/dist/files-route.js +28 -0
- package/dashboard-server/dist/index.js +294 -0
- package/dashboard-server/dist/license-routes.js +39 -0
- package/dashboard-server/dist/review-route.js +150 -0
- package/dashboard-server/dist/run-route.js +74 -0
- package/dashboard-server/dist/security.js +115 -0
- package/dist/parser.jar +0 -0
- package/package.json +9 -3
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { scanRepo, extractClasses, extractDependencies, generateReport, buildRunSummary, readConfig, resolveOutputDir, } from "./core-bridge.js";
|
|
3
|
+
export async function handleRunRequest(req, res, broadcast) {
|
|
4
|
+
const body = req.body;
|
|
5
|
+
const projectPath = body.projectPath;
|
|
6
|
+
if (!projectPath || typeof projectPath !== "string") {
|
|
7
|
+
res.status(400).json({ error: "projectPath is required" });
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let stat;
|
|
11
|
+
try {
|
|
12
|
+
stat = fs.statSync(projectPath);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
res.status(400).json({ error: `Path does not exist: ${projectPath}` });
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!stat.isDirectory()) {
|
|
19
|
+
res.status(400).json({ error: `Not a directory: ${projectPath}` });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const cfg = readConfig(projectPath);
|
|
23
|
+
const resolvedOutput = resolveOutputDir(projectPath, cfg, body.outputDir);
|
|
24
|
+
const selectN = body.select ?? (typeof cfg.maxUseCases === "number" ? cfg.maxUseCases : undefined);
|
|
25
|
+
const selectedIds = cfg.selectedUseCases?.length ? cfg.selectedUseCases : undefined;
|
|
26
|
+
try {
|
|
27
|
+
broadcast("run-progress", { step: "scan", status: "start" });
|
|
28
|
+
const scanT0 = performance.now();
|
|
29
|
+
const ir = await scanRepo({ project_path: projectPath });
|
|
30
|
+
const parseTimeMs = Math.round(performance.now() - scanT0);
|
|
31
|
+
const classes = extractClasses(ir);
|
|
32
|
+
const { dependencies } = extractDependencies(ir);
|
|
33
|
+
const classCount = ir.classes?.length ?? 0;
|
|
34
|
+
const byType = classes.summary?.by_type ?? {};
|
|
35
|
+
const projectName = cfg.projectName || ir.project.name;
|
|
36
|
+
broadcast("run-progress", { step: "scan", status: "done", detail: `${classCount} classes` });
|
|
37
|
+
broadcast("run-progress", { step: "diagram", status: "start" });
|
|
38
|
+
// Component grouping is derived straight from the scan — no extra work,
|
|
39
|
+
// but still its own step for parity with the CLI's 3-step display.
|
|
40
|
+
broadcast("run-progress", { step: "diagram", status: "done" });
|
|
41
|
+
broadcast("run-progress", { step: "report", status: "start" });
|
|
42
|
+
const report = await generateReport({
|
|
43
|
+
ir,
|
|
44
|
+
classes,
|
|
45
|
+
dependencies,
|
|
46
|
+
output_dir: resolvedOutput,
|
|
47
|
+
parse_time_ms: parseTimeMs,
|
|
48
|
+
usecase_selection: (selectN != null || selectedIds) ? { limit: selectN, selected_ids: selectedIds } : undefined,
|
|
49
|
+
project_info: {
|
|
50
|
+
title: `${projectName} — Báo cáo phân tích và thiết kế`,
|
|
51
|
+
subject: "Công nghệ mới trong phát triển ứng dụng CNTT",
|
|
52
|
+
group: "Nhóm XX",
|
|
53
|
+
},
|
|
54
|
+
actor_overrides: cfg.actorOverrides,
|
|
55
|
+
});
|
|
56
|
+
broadcast("run-progress", { step: "report", status: "done" });
|
|
57
|
+
const summary = buildRunSummary({
|
|
58
|
+
projectName,
|
|
59
|
+
outputDir: resolvedOutput,
|
|
60
|
+
classCount,
|
|
61
|
+
byType,
|
|
62
|
+
parseTimeMs,
|
|
63
|
+
classes,
|
|
64
|
+
report,
|
|
65
|
+
});
|
|
66
|
+
broadcast("run-complete", { projectName, outputDir: resolvedOutput });
|
|
67
|
+
res.json(summary);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
71
|
+
broadcast("run-error", { message });
|
|
72
|
+
res.status(500).json({ error: message });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local-server hardening for the dashboard: this process runs real core
|
|
3
|
+
* functions (scanRepo/generateReport/activateOnline) with filesystem and
|
|
4
|
+
* network access on whatever the browser tells it to, so every request must
|
|
5
|
+
* be provably from the person who started this process, not from any page
|
|
6
|
+
* a browser tab happens to have open.
|
|
7
|
+
*/
|
|
8
|
+
import crypto from "node:crypto";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
export const TOKEN_FILE = path.join(os.homedir(), ".archscribe", "dashboard-token");
|
|
13
|
+
/**
|
|
14
|
+
* Persist this server instance's token to TOKEN_FILE (mode 0600 where the
|
|
15
|
+
* platform supports it) so other local processes with filesystem access to
|
|
16
|
+
* ~/.archscribe — the CLI pipeline's notifyNewReport(), or a second
|
|
17
|
+
* `archscribe run` checking whether a dashboard is already up — can
|
|
18
|
+
* discover the CURRENT token the same way they already trust that
|
|
19
|
+
* directory for the license key. Never logged, never put in a response body.
|
|
20
|
+
* Called both when this process generates its own token and when it was
|
|
21
|
+
* handed one via DASHBOARD_TOKEN, so the file always reflects whichever
|
|
22
|
+
* token the currently-running server actually checks.
|
|
23
|
+
*/
|
|
24
|
+
export function persistToken(token) {
|
|
25
|
+
fs.mkdirSync(path.dirname(TOKEN_FILE), { recursive: true });
|
|
26
|
+
fs.writeFileSync(TOKEN_FILE, token, { encoding: "utf8", mode: 0o600 });
|
|
27
|
+
try {
|
|
28
|
+
fs.chmodSync(TOKEN_FILE, 0o600);
|
|
29
|
+
}
|
|
30
|
+
catch { /* best-effort on platforms without POSIX modes */ }
|
|
31
|
+
}
|
|
32
|
+
/** Generate a fresh random token - does NOT persist it, call persistToken() too. */
|
|
33
|
+
export function generateToken() {
|
|
34
|
+
return crypto.randomBytes(24).toString("hex");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The token a previous run persisted, so the next start reuses it instead of
|
|
38
|
+
* minting a new one.
|
|
39
|
+
*
|
|
40
|
+
* Regenerating on every start silently broke any dashboard tab already open:
|
|
41
|
+
* its sessionStorage still holds the old token, so every /api/* call becomes a
|
|
42
|
+
* 401 the tab has no way to recover from. Reusing the persisted token keeps
|
|
43
|
+
* open tabs working across a restart. Returns null for a missing, empty, or
|
|
44
|
+
* implausibly short file (never a usable token), so a corrupt file just falls
|
|
45
|
+
* back to a fresh token.
|
|
46
|
+
*/
|
|
47
|
+
export function readPersistedToken() {
|
|
48
|
+
try {
|
|
49
|
+
const t = fs.readFileSync(TOKEN_FILE, "utf8").trim();
|
|
50
|
+
return t.length >= 32 ? t : null;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Rejects any request whose Host header isn't localhost/127.0.0.1/::1 —
|
|
58
|
+
* binding to 127.0.0.1 alone does not stop DNS rebinding: an attacker-owned
|
|
59
|
+
* hostname can resolve to 127.0.0.1, and the browser then considers a
|
|
60
|
+
* fetch() from a page on that hostname same-origin-with-itself, landing a
|
|
61
|
+
* real TCP connection on this server whose Host header names the attacker's
|
|
62
|
+
* domain, not localhost. The attacker controls DNS, never the Host header
|
|
63
|
+
* a legitimate localhost tab sends, so checking it here is what actually
|
|
64
|
+
* stops the attack that IP-binding alone does not.
|
|
65
|
+
*/
|
|
66
|
+
export const hostGuard = (req, res, next) => {
|
|
67
|
+
const host = req.headers.host ?? "";
|
|
68
|
+
const hostname = host.split(":")[0]?.toLowerCase();
|
|
69
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") {
|
|
70
|
+
next();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
res.status(403).json({ error: "forbidden_host" });
|
|
74
|
+
};
|
|
75
|
+
/** Constant-time compare so a wrong-length guess can't be distinguished by timing from a wrong-value one of the right length. */
|
|
76
|
+
function timingSafeEqualStrings(a, b) {
|
|
77
|
+
const bufA = Buffer.from(a);
|
|
78
|
+
const bufB = Buffer.from(b);
|
|
79
|
+
if (bufA.length !== bufB.length)
|
|
80
|
+
return false;
|
|
81
|
+
return crypto.timingSafeEqual(bufA, bufB);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Requires the startup token, via `Authorization: Bearer <token>` (every
|
|
85
|
+
* fetch() call) or a `?token=` query param (the one exception: browser
|
|
86
|
+
* EventSource cannot set custom headers, so the SSE connection has no other
|
|
87
|
+
* way to authenticate). Accepting the query-param form everywhere is a
|
|
88
|
+
* deliberate, narrow trade-off for a local single-user tool, not a general
|
|
89
|
+
* API — the token is still never accepted from anywhere but these two.
|
|
90
|
+
*/
|
|
91
|
+
export function authGuard(getCurrentToken) {
|
|
92
|
+
return (req, res, next) => {
|
|
93
|
+
const header = req.headers.authorization ?? "";
|
|
94
|
+
const fromHeader = header.startsWith("Bearer ") ? header.slice(7) : "";
|
|
95
|
+
const fromQuery = typeof req.query["token"] === "string" ? req.query["token"] : "";
|
|
96
|
+
const provided = fromHeader || fromQuery;
|
|
97
|
+
if (provided && timingSafeEqualStrings(provided, getCurrentToken())) {
|
|
98
|
+
next();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
res.status(401).json({ error: "unauthorized" });
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Resolves `relPath` against `baseDir` and refuses anything that escapes it
|
|
106
|
+
* (via `..`, an absolute path, a symlink-free lexical check) — returns null
|
|
107
|
+
* rather than throwing, so every caller is forced to handle the rejection.
|
|
108
|
+
*/
|
|
109
|
+
export function resolveWithinDir(baseDir, relPath) {
|
|
110
|
+
const base = path.resolve(baseDir);
|
|
111
|
+
const resolved = path.resolve(base, relPath);
|
|
112
|
+
if (resolved !== base && !resolved.startsWith(base + path.sep))
|
|
113
|
+
return null;
|
|
114
|
+
return resolved;
|
|
115
|
+
}
|
package/dist/parser.jar
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "archscribe",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
4
5
|
"description": "MCP Server for Java Spring Boot documentation generation",
|
|
5
6
|
"keywords": ["mcp", "spring-boot", "java", "documentation", "uml", "drawio", "claude-code", "codex", "ai-agent"],
|
|
6
7
|
"homepage": "https://archscribe.dev",
|
|
@@ -8,7 +9,10 @@
|
|
|
8
9
|
"type": "module",
|
|
9
10
|
"main": "dist/server.js",
|
|
10
11
|
"files": [
|
|
11
|
-
"dist/",
|
|
12
|
+
"dist/",
|
|
13
|
+
"dashboard-server/dist/",
|
|
14
|
+
"dashboard-server/client-dist/",
|
|
15
|
+
"LICENSE",
|
|
12
16
|
"!dist/knowledge/seed*",
|
|
13
17
|
"!dist/knowledge/qdrant-client.*",
|
|
14
18
|
"!dist/knowledge/embedding.*"
|
|
@@ -39,13 +43,15 @@
|
|
|
39
43
|
"gen-keypair": "npx tsx tools/gen-keypair.ts",
|
|
40
44
|
"issue-license": "npx tsx tools/issue-license.ts",
|
|
41
45
|
"dashboard:build": "cd dashboard-server && npm run build:server && cd client && npm run build",
|
|
42
|
-
"dashboard:serve": "cd dashboard-server && node dist/index.js"
|
|
46
|
+
"dashboard:serve": "cd dashboard-server && node dist/index.js",
|
|
47
|
+
"prepublishOnly": "npm run build && npm run dashboard:build"
|
|
43
48
|
},
|
|
44
49
|
"dependencies": {
|
|
45
50
|
"@clack/prompts": "^1.8.1",
|
|
46
51
|
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
47
52
|
"docx": "^8.5.0",
|
|
48
53
|
"elkjs": "^0.12.0",
|
|
54
|
+
"express": "^4.19.2",
|
|
49
55
|
"zod": "^3.23.8"
|
|
50
56
|
},
|
|
51
57
|
"devDependencies": {
|