archscribe 0.2.1 → 0.2.2-rc.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.
Files changed (153) hide show
  1. package/README.md +1 -8
  2. package/dist/cli/archscribe.js +29 -74
  3. package/dist/cli/archscribe.js.map +1 -1
  4. package/dist/cli/doctor.js +1 -0
  5. package/dist/cli/doctor.js.map +1 -1
  6. package/dist/cli/login.js +5 -2
  7. package/dist/cli/login.js.map +1 -1
  8. package/dist/cli/rag.d.ts +4 -1
  9. package/dist/cli/rag.js +29 -7
  10. package/dist/cli/rag.js.map +1 -1
  11. package/dist/cli/run.js +7 -1
  12. package/dist/cli/run.js.map +1 -1
  13. package/dist/cli/shell.d.ts +1 -1
  14. package/dist/cli/shell.js +29 -3
  15. package/dist/cli/shell.js.map +1 -1
  16. package/dist/core/docx-package.d.ts +9 -0
  17. package/dist/core/docx-package.js +99 -0
  18. package/dist/core/docx-package.js.map +1 -0
  19. package/dist/core/docx-styles.d.ts +12 -11
  20. package/dist/core/docx-styles.js +12 -11
  21. package/dist/core/docx-styles.js.map +1 -1
  22. package/dist/core/docx-update.d.ts +6 -0
  23. package/dist/core/docx-update.js +437 -0
  24. package/dist/core/docx-update.js.map +1 -0
  25. package/dist/core/docx.d.ts +8 -2
  26. package/dist/core/docx.js +263 -74
  27. package/dist/core/docx.js.map +1 -1
  28. package/dist/core/flow.js +8 -2
  29. package/dist/core/flow.js.map +1 -1
  30. package/dist/core/iuh-logo.d.ts +1 -0
  31. package/dist/core/iuh-logo.js +3 -0
  32. package/dist/core/iuh-logo.js.map +1 -0
  33. package/dist/core/manifest.js +1 -1
  34. package/dist/core/manifest.js.map +1 -1
  35. package/dist/core/markdown.js +24 -11
  36. package/dist/core/markdown.js.map +1 -1
  37. package/dist/core/parser.js +3 -0
  38. package/dist/core/parser.js.map +1 -1
  39. package/dist/core/project-config.d.ts +4 -0
  40. package/dist/core/project-config.js +39 -0
  41. package/dist/core/project-config.js.map +1 -1
  42. package/dist/diagrams/layout/radial.js +69 -0
  43. package/dist/diagrams/layout/radial.js.map +1 -1
  44. package/dist/evaluation/dashboard-review.js +66 -0
  45. package/dist/evaluation/dashboard-review.js.map +1 -1
  46. package/dist/knowledge/embedding.d.ts +11 -0
  47. package/dist/knowledge/embedding.js +31 -0
  48. package/dist/knowledge/embedding.js.map +1 -0
  49. package/dist/knowledge/hub-grouping.d.ts +3 -3
  50. package/dist/knowledge/hub-grouping.js +52 -54
  51. package/dist/knowledge/hub-grouping.js.map +1 -1
  52. package/dist/knowledge/qdrant-client.d.ts +20 -0
  53. package/dist/knowledge/qdrant-client.js +95 -0
  54. package/dist/knowledge/qdrant-client.js.map +1 -0
  55. package/dist/knowledge/rag-augment.d.ts +1 -1
  56. package/dist/knowledge/rag-augment.js +7 -6
  57. package/dist/knowledge/rag-augment.js.map +1 -1
  58. package/dist/knowledge/retriever.d.ts +2 -6
  59. package/dist/knowledge/retriever.js +14 -27
  60. package/dist/knowledge/retriever.js.map +1 -1
  61. package/dist/knowledge/seed-data-extended.d.ts +7 -0
  62. package/dist/knowledge/seed-data-extended.js +183 -0
  63. package/dist/knowledge/seed-data-extended.js.map +1 -0
  64. package/dist/knowledge/seed-data-extra.d.ts +6 -0
  65. package/dist/knowledge/seed-data-extra.js +178 -0
  66. package/dist/knowledge/seed-data-extra.js.map +1 -0
  67. package/dist/knowledge/seed-data.d.ts +3 -0
  68. package/dist/knowledge/seed-data.js +333 -0
  69. package/dist/knowledge/seed-data.js.map +1 -0
  70. package/dist/knowledge/seed.d.ts +22 -0
  71. package/dist/knowledge/seed.js +44 -0
  72. package/dist/knowledge/seed.js.map +1 -0
  73. package/dist/knowledge/types.d.ts +1 -4
  74. package/dist/license/banner.d.ts +3 -1
  75. package/dist/license/banner.js +6 -2
  76. package/dist/license/banner.js.map +1 -1
  77. package/dist/license/client.d.ts +7 -3
  78. package/dist/license/client.js +15 -2
  79. package/dist/license/client.js.map +1 -1
  80. package/dist/license/gate.d.ts +3 -1
  81. package/dist/license/gate.js +1 -1
  82. package/dist/license/gate.js.map +1 -1
  83. package/dist/parser.jar +0 -0
  84. package/dist/server.js +10 -28
  85. package/dist/server.js.map +1 -1
  86. package/dist/theory/fill.d.ts +3 -1
  87. package/dist/theory/fill.js +28 -47
  88. package/dist/theory/fill.js.map +1 -1
  89. package/dist/theory/references.d.ts +32 -5
  90. package/dist/theory/references.js +126 -2
  91. package/dist/theory/references.js.map +1 -1
  92. package/dist/theory/scaffold.js +7 -6
  93. package/dist/theory/scaffold.js.map +1 -1
  94. package/dist/tools/analyze_project.js +3 -0
  95. package/dist/tools/analyze_project.js.map +1 -1
  96. package/dist/tools/environment.js +1 -0
  97. package/dist/tools/environment.js.map +1 -1
  98. package/dist/tools/generate_report.d.ts +5 -5
  99. package/dist/tools/generate_report.js +83 -232
  100. package/dist/tools/generate_report.js.map +1 -1
  101. package/dist/tools/learn_usecase.d.ts +6 -2
  102. package/dist/tools/learn_usecase.js +34 -50
  103. package/dist/tools/learn_usecase.js.map +1 -1
  104. package/dist/tools/scaffold.js +24 -23
  105. package/dist/tools/scaffold.js.map +1 -1
  106. package/dist/types/license.d.ts +3 -1
  107. package/dist/types/report.d.ts +3 -3
  108. package/dist/types/theory.d.ts +4 -1
  109. package/dist/types/uc-grouping.d.ts +8 -0
  110. package/dist/utils/approval.d.ts +32 -4
  111. package/dist/utils/approval.js +160 -9
  112. package/dist/utils/approval.js.map +1 -1
  113. package/dist/utils/dashboard-launcher.js +1 -0
  114. package/dist/utils/dashboard-launcher.js.map +1 -1
  115. package/dist/utils/keep-regions.d.ts +44 -0
  116. package/dist/utils/keep-regions.js +153 -0
  117. package/dist/utils/keep-regions.js.map +1 -0
  118. package/package.json +11 -16
  119. package/LICENSE +0 -33
  120. package/dashboard-server/client-dist/assets/index-CswIFyKN.js +0 -9
  121. package/dashboard-server/client-dist/assets/index-DWB_-3yk.css +0 -1
  122. package/dashboard-server/client-dist/brand/favicon.png +0 -0
  123. package/dashboard-server/client-dist/brand/logo-full.png +0 -0
  124. package/dashboard-server/client-dist/icons.svg +0 -24
  125. package/dashboard-server/client-dist/index.html +0 -14
  126. package/dashboard-server/dist/core-bridge.js +0 -19
  127. package/dashboard-server/dist/files-route.js +0 -28
  128. package/dashboard-server/dist/index.js +0 -294
  129. package/dashboard-server/dist/license-routes.js +0 -39
  130. package/dashboard-server/dist/review-route.js +0 -150
  131. package/dashboard-server/dist/run-route.js +0 -74
  132. package/dashboard-server/dist/security.js +0 -115
  133. package/dist/core/review-ledger.d.ts +0 -36
  134. package/dist/core/review-ledger.js +0 -104
  135. package/dist/core/review-ledger.js.map +0 -1
  136. package/dist/core/review-rerun.d.ts +0 -16
  137. package/dist/core/review-rerun.js +0 -31
  138. package/dist/core/review-rerun.js.map +0 -1
  139. package/dist/knowledge/local-kb.d.ts +0 -4
  140. package/dist/knowledge/local-kb.js +0 -82
  141. package/dist/knowledge/local-kb.js.map +0 -1
  142. package/dist/knowledge/rag-client.d.ts +0 -11
  143. package/dist/knowledge/rag-client.js +0 -60
  144. package/dist/knowledge/rag-client.js.map +0 -1
  145. package/dist/knowledge/rules.d.ts +0 -2
  146. package/dist/knowledge/rules.js +0 -10
  147. package/dist/knowledge/rules.js.map +0 -1
  148. package/dist/tools/review-tasks.d.ts +0 -28
  149. package/dist/tools/review-tasks.js +0 -168
  150. package/dist/tools/review-tasks.js.map +0 -1
  151. package/dist/utils/mcp-launch.d.ts +0 -24
  152. package/dist/utils/mcp-launch.js +0 -37
  153. package/dist/utils/mcp-launch.js.map +0 -1
@@ -1,74 +0,0 @@
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
- }
@@ -1,115 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
1
- export type ReviewStatus = 'pending' | 'needs-fix' | 'draft' | 'approved' | 'unresolved';
2
- export interface ReviewEntry {
3
- key: string;
4
- status: ReviewStatus;
5
- note: string;
6
- title?: string;
7
- endpoint?: string;
8
- baseFingerprint?: string;
9
- sourceFingerprint?: string;
10
- snapshots?: {
11
- spec: string;
12
- activity?: string;
13
- sequence?: string;
14
- };
15
- draft?: {
16
- spec?: string;
17
- activity?: string;
18
- sequence?: string;
19
- };
20
- }
21
- export interface ReviewLedger {
22
- version: 1;
23
- entries: Record<string, ReviewEntry>;
24
- }
25
- export declare function loadReviewLedger(projectPath: string): ReviewLedger;
26
- export declare function saveReviewLedger(projectPath: string, ledger: ReviewLedger): void;
27
- export declare function setReviewNote(projectPath: string, sourceKey: string, note: string): ReviewEntry;
28
- export declare function approveReview(projectPath: string, sourceKey: string, artifacts: {
29
- spec: string;
30
- activity?: string;
31
- sequence?: string;
32
- }, context?: {
33
- title: string;
34
- endpoint: string;
35
- sourceFingerprint?: string;
36
- }): ReviewEntry;
@@ -1,104 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { createHash, randomUUID } from 'node:crypto';
4
- const root = (project) => path.join(project, '.archscribe');
5
- const ledgerFile = (project) => path.join(root(project), 'review.json');
6
- function safeSnapshot(project, relative) {
7
- const base = path.resolve(root(project), 'review');
8
- const target = path.resolve(root(project), relative);
9
- if (!target.startsWith(base + path.sep))
10
- throw new Error('Invalid review snapshot path');
11
- return target;
12
- }
13
- export function loadReviewLedger(projectPath) {
14
- const file = ledgerFile(projectPath);
15
- if (!fs.existsSync(file))
16
- return { version: 1, entries: {} };
17
- let value;
18
- try {
19
- value = JSON.parse(fs.readFileSync(file, 'utf8'));
20
- }
21
- catch (error) {
22
- throw new Error(`Invalid review ledger: ${String(error)}`);
23
- }
24
- if (!value || typeof value !== 'object' || value.version !== 1 ||
25
- !(value.entries instanceof Object) || Array.isArray(value.entries)) {
26
- throw new Error('Invalid review ledger format');
27
- }
28
- const ledger = value;
29
- for (const [key, entry] of Object.entries(ledger.entries)) {
30
- if (!entry || entry.key !== key || !['pending', 'needs-fix', 'draft', 'approved', 'unresolved'].includes(entry.status) || typeof entry.note !== 'string' ||
31
- (entry.status === 'approved' && !entry.snapshots?.spec)) {
32
- throw new Error('Invalid review entry');
33
- }
34
- for (const relative of [...Object.values(entry.snapshots ?? {}), ...Object.values(entry.draft ?? {})]) {
35
- const file = safeSnapshot(projectPath, relative);
36
- if (!fs.existsSync(file))
37
- throw new Error(`Missing review snapshot: ${relative}`);
38
- }
39
- }
40
- return ledger;
41
- }
42
- export function saveReviewLedger(projectPath, ledger) {
43
- if (ledger.version !== 1)
44
- throw new Error('Invalid review ledger version');
45
- for (const [key, entry] of Object.entries(ledger.entries)) {
46
- if (entry.key !== key)
47
- throw new Error('Invalid review entry key');
48
- if (entry.status === 'approved' && !entry.snapshots?.spec)
49
- throw new Error('Missing approved spec snapshot');
50
- for (const relative of [...Object.values(entry.snapshots ?? {}), ...Object.values(entry.draft ?? {})]) {
51
- const file = safeSnapshot(projectPath, relative);
52
- if (!fs.existsSync(file))
53
- throw new Error(`Missing review snapshot: ${relative}`);
54
- }
55
- }
56
- fs.mkdirSync(root(projectPath), { recursive: true });
57
- const file = ledgerFile(projectPath), temp = `${file}.${randomUUID()}.tmp`;
58
- try {
59
- fs.writeFileSync(temp, JSON.stringify(ledger, null, 2), { encoding: 'utf8', flag: 'wx' });
60
- fs.renameSync(temp, file);
61
- }
62
- finally {
63
- if (fs.existsSync(temp))
64
- fs.unlinkSync(temp);
65
- }
66
- }
67
- export function setReviewNote(projectPath, sourceKey, note) {
68
- if (!sourceKey.trim() || typeof note !== 'string')
69
- throw new Error('Invalid review note');
70
- const ledger = loadReviewLedger(projectPath);
71
- const previous = ledger.entries[sourceKey];
72
- const entry = { ...previous, key: sourceKey, status: note.trim() ? 'needs-fix' : (previous?.status ?? 'pending'), note };
73
- ledger.entries[sourceKey] = entry;
74
- saveReviewLedger(projectPath, ledger);
75
- return entry;
76
- }
77
- export function approveReview(projectPath, sourceKey, artifacts, context) {
78
- if (!sourceKey.trim())
79
- throw new Error('Invalid review key');
80
- const ledger = loadReviewLedger(projectPath);
81
- const bytes = Object.entries(artifacts).map(([kind, file]) => {
82
- if (!['spec', 'activity', 'sequence'].includes(kind) || typeof file !== 'string' || !fs.existsSync(file))
83
- throw new Error(`Missing review artifact: ${kind}`);
84
- return [kind, fs.readFileSync(file)];
85
- });
86
- const version = randomUUID();
87
- const snapshots = { spec: '' };
88
- for (const [kind, data] of bytes) {
89
- const relative = path.join('review', version, `${kind}${kind === 'spec' ? '.md' : '.drawio'}`);
90
- const dest = safeSnapshot(projectPath, relative);
91
- fs.mkdirSync(path.dirname(dest), { recursive: true });
92
- fs.writeFileSync(dest, data, { flag: 'wx' });
93
- snapshots[kind] = relative;
94
- }
95
- const entry = {
96
- ...ledger.entries[sourceKey], key: sourceKey, status: 'approved', note: '', snapshots, draft: undefined,
97
- ...context,
98
- baseFingerprint: createHash('sha256').update(bytes.map(([, b]) => b).reduce((a, b) => Buffer.concat([a, b]), Buffer.alloc(0))).digest('hex'),
99
- };
100
- ledger.entries[sourceKey] = entry;
101
- saveReviewLedger(projectPath, ledger);
102
- return entry;
103
- }
104
- //# sourceMappingURL=review-ledger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"review-ledger.js","sourceRoot":"","sources":["../../src/core/review-ledger.ts"],"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M,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS;QACvG,GAAG,OAAO;QACV,eAAe,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;KAC7I,CAAC;IACF,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;IAClC,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACtC,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,16 +0,0 @@
1
- import type { UseCaseFlow } from '../types/report.js';
2
- type Source = Pick<UseCaseFlow, 'endpoint' | 'controllerName' | 'methodName'> & {
3
- sourceFile?: string;
4
- sourceTrace?: string[];
5
- };
6
- /** A display UC number is deliberately not part of this identity. */
7
- export declare function sourceKey(flow: Source): string;
8
- export declare function selectRerunWork(candidates: Array<{
9
- key: string;
10
- id: string;
11
- }>, approvedKeys: Set<string>, requestedLimit: number, explicitKeys?: Set<string>): {
12
- workKeys: string[];
13
- retainedKeys: string[];
14
- unresolvedKeys: string[];
15
- };
16
- export {};
@@ -1,31 +0,0 @@
1
- /** A display UC number is deliberately not part of this identity. */
2
- export function sourceKey(flow) {
3
- const file = flow.sourceFile ?? flow.sourceTrace?.[0]?.split(' -> ')[0];
4
- if (!file || !flow.endpoint || !flow.controllerName || !flow.methodName) {
5
- throw new Error('Cannot identify use case without source file, endpoint and method');
6
- }
7
- return JSON.stringify([
8
- flow.endpoint.trim().replace(/\s+/g, ' ').toUpperCase(),
9
- file.replace(/\\/g, '/').replace(/^\.\//, ''),
10
- flow.controllerName.trim(),
11
- flow.methodName.trim(),
12
- ]);
13
- }
14
- export function selectRerunWork(candidates, approvedKeys, requestedLimit, explicitKeys) {
15
- if (!Number.isInteger(requestedLimit) || requestedLimit < 0)
16
- throw new Error('Invalid work limit');
17
- const keys = new Set();
18
- for (const candidate of candidates) {
19
- if (keys.has(candidate.key))
20
- throw new Error(`Ambiguous duplicate use case: ${candidate.id}`);
21
- keys.add(candidate.key);
22
- }
23
- const retainedKeys = [...approvedKeys];
24
- return {
25
- retainedKeys,
26
- unresolvedKeys: retainedKeys.filter((key) => !keys.has(key)),
27
- workKeys: candidates.filter((c) => !approvedKeys.has(c.key) && (!explicitKeys || explicitKeys.has(c.key)))
28
- .slice(0, requestedLimit).map((c) => c.key),
29
- };
30
- }
31
- //# sourceMappingURL=review-rerun.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"review-rerun.js","sourceRoot":"","sources":["../../src/core/review-rerun.ts"],"names":[],"mappings":"AAOA,qEAAqE;AACrE,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE;QACvD,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CAAC,GAAG,CAAC;KAC9C,CAAC;AACJ,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { KBResult, LocalUC } from "./types.js";
2
- export declare function loadLocalKB(): Promise<LocalUC[]>;
3
- export declare function appendLocalUC(payload: LocalUC): Promise<void>;
4
- export declare function searchLocalUC(query: string, limit: number): Promise<KBResult[]>;
@@ -1,82 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import os from "node:os";
3
- import { randomUUID } from "node:crypto";
4
- import { dirname, join } from "node:path";
5
- import { scrub } from "./rules.js";
6
- const kbFile = () => join(os.homedir(), ".archscribe", "kb.json");
7
- const tokens = (text) => new Set(text.toLocaleLowerCase("vi").match(/[\p{L}\p{N}]+/gu) ?? []);
8
- function valid(entry) {
9
- if (!entry || typeof entry !== "object")
10
- return false;
11
- const e = entry;
12
- return typeof e.ucName === "string" && typeof e.actor === "string" &&
13
- typeof e.description === "string" && typeof e.domain === "string" &&
14
- Array.isArray(e.mainFlow) && e.mainFlow.every((s) => typeof s === "string") &&
15
- Array.isArray(e.preconditions) && e.preconditions.every((s) => typeof s === "string") &&
16
- Array.isArray(e.postconditions) && e.postconditions.every((s) => typeof s === "string") &&
17
- (e.source === "learned" || e.source === "seed") && typeof e.verified === "boolean" &&
18
- Array.isArray(e.vector) && e.vector.length === 768 && e.vector.every((n) => typeof n === "number" && Number.isFinite(n));
19
- }
20
- function parse(text) {
21
- const data = JSON.parse(text);
22
- if (!data || typeof data !== "object")
23
- throw new Error("Invalid local KB");
24
- const store = data;
25
- if (store.version !== 1 || !Array.isArray(store.entries) || !store.entries.every(valid))
26
- throw new Error("Invalid local KB");
27
- return store.entries.map(sanitized);
28
- }
29
- function sanitized(payload) {
30
- return {
31
- ucName: scrub(payload.ucName), actor: scrub(payload.actor), description: scrub(payload.description),
32
- preconditions: payload.preconditions.map(scrub), mainFlow: payload.mainFlow.map(scrub),
33
- postconditions: payload.postconditions.map(scrub), domain: scrub(payload.domain),
34
- source: payload.source, verified: payload.verified, vector: payload.vector,
35
- };
36
- }
37
- export async function loadLocalKB() {
38
- try {
39
- return parse(await fs.readFile(kbFile(), "utf8"));
40
- }
41
- catch {
42
- return [];
43
- }
44
- }
45
- export async function appendLocalUC(payload) {
46
- if (!valid(payload))
47
- throw new Error("Invalid local UC");
48
- const file = kbFile();
49
- let entries;
50
- try {
51
- entries = parse(await fs.readFile(file, "utf8"));
52
- }
53
- catch (error) {
54
- if (error.code !== "ENOENT")
55
- throw error;
56
- entries = [];
57
- }
58
- const clean = sanitized(payload);
59
- await fs.mkdir(dirname(file), { recursive: true });
60
- const temp = `${file}.${randomUUID()}.tmp`;
61
- try {
62
- await fs.writeFile(temp, JSON.stringify({ version: 1, entries: [...entries, clean] }), { flag: "wx" });
63
- await fs.rename(temp, file);
64
- }
65
- finally {
66
- await fs.rm(temp, { force: true });
67
- }
68
- }
69
- export async function searchLocalUC(query, limit) {
70
- const wanted = tokens(query);
71
- if (!wanted.size || limit <= 0)
72
- return [];
73
- const entries = await loadLocalKB();
74
- return entries.flatMap((entry, index) => {
75
- if (!entry.verified)
76
- return [];
77
- const found = tokens(`${entry.ucName} ${entry.actor} ${entry.domain} ${entry.description} ${entry.mainFlow.join(" ")}`);
78
- const overlap = [...wanted].filter((token) => found.has(token)).length;
79
- return overlap ? [{ id: `local:${index}`, score: overlap / wanted.size, payload: entry }] : [];
80
- }).sort((a, b) => b.score - a.score).slice(0, limit);
81
- }
82
- //# sourceMappingURL=local-kb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local-kb.js","sourceRoot":"","sources":["../../src/knowledge/local-kb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,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,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { KBResult } from "./types.js";
2
- export declare function search(text: string, topK?: number): Promise<KBResult[]>;
3
- export declare function embed(mode: "query" | "document", texts: string[]): Promise<number[][]>;
4
- export declare function review(input: {
5
- title: string;
6
- actor: string;
7
- description: string;
8
- }): Promise<{
9
- pass: boolean;
10
- reason: string;
11
- }>;
@@ -1,60 +0,0 @@
1
- import { loadSession, isSessionValid } from "../license/session.js";
2
- import { scrub } from "./rules.js";
3
- /** Send only scrubbed UC text to the configured Worker; never use the license key. */
4
- async function post(path, body) {
5
- const url = new URL(process.env.ARCHSCRIBE_RAG_URL ?? "");
6
- if ((url.protocol !== "https:" && !(url.protocol === "http:" && url.hostname === "localhost")) ||
7
- url.username || url.password || url.search || url.hash)
8
- throw new Error("Unsafe RAG URL");
9
- const session = loadSession();
10
- if (!session || !isSessionValid(session) || !session.sessionToken)
11
- throw new Error("No valid RAG session");
12
- const response = await fetch(new URL(path, url.href.replace(/\/?$/, "/")), {
13
- method: "POST",
14
- headers: { "content-type": "application/json", authorization: `Bearer ${session.sessionToken}` },
15
- body: JSON.stringify(body),
16
- signal: AbortSignal.timeout(10_000),
17
- redirect: "error",
18
- });
19
- if (!response.ok)
20
- throw new Error(`RAG HTTP ${response.status}`);
21
- try {
22
- return await response.json();
23
- }
24
- catch {
25
- throw new Error("Invalid RAG response");
26
- }
27
- }
28
- export async function search(text, topK) {
29
- const result = await post("search", { text: scrub(text), ...(topK === undefined ? {} : { topK }) });
30
- if (!result || !Array.isArray(result.results) || !result.results.every((item) => {
31
- if (!item || typeof item !== "object")
32
- return false;
33
- const entry = item;
34
- const payload = entry.payload;
35
- return (typeof entry.id === "string" || typeof entry.id === "number") &&
36
- typeof entry.score === "number" && Number.isFinite(entry.score) &&
37
- payload && typeof payload.ucName === "string" && typeof payload.description === "string" &&
38
- typeof payload.actor === "string" && Array.isArray(payload.mainFlow) &&
39
- payload.mainFlow.every((step) => typeof step === "string");
40
- }))
41
- throw new Error("Invalid RAG search response");
42
- return result.results;
43
- }
44
- export async function embed(mode, texts) {
45
- const result = await post("embed", { mode, texts: texts.map(scrub) });
46
- if (!result || !Array.isArray(result.vectors) || result.vectors.length !== texts.length ||
47
- !result.vectors.every((v) => Array.isArray(v) && v.length > 0 &&
48
- v.every((n) => typeof n === "number" && Number.isFinite(n))))
49
- throw new Error("Invalid RAG embed response");
50
- return result.vectors;
51
- }
52
- export async function review(input) {
53
- const result = await post("review", {
54
- title: scrub(input.title), actor: scrub(input.actor), description: scrub(input.description),
55
- });
56
- if (!result || typeof result.pass !== "boolean" || typeof result.reason !== "string")
57
- throw new Error("Invalid RAG review response");
58
- return { pass: result.pass, reason: result.reason };
59
- }
60
- //# sourceMappingURL=rag-client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rag-client.js","sourceRoot":"","sources":["../../src/knowledge/rag-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,sFAAsF;AACtF,KAAK,UAAU,IAAI,CAAC,IAAY,EAAE,IAAY;IAC5C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;IAC1D,IAAI,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC;QAC1F,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,IA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AI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QACnF,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;YACpE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC,OAAqB,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAA4D;IACvF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE;QAClC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC;KAC5F,CAAyC,CAAC;IAC3C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QAClF,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;AACtD,CAAC"}
@@ -1,2 +0,0 @@
1
- /** Remove obvious project identifiers and secrets before remote RAG requests. */
2
- export declare function scrub(text: string): string;
@@ -1,10 +0,0 @@
1
- /** Remove obvious project identifiers and secrets before remote RAG requests. */
2
- export function scrub(text) {
3
- return text
4
- .replace(/\b(?:bearer\s+\S+|(?:password|api[_-]?key|secret|token)\s*[:=]\s*\S+)/gi, "")
5
- .replace(/https?:\/\/\S+|\b[\w.+-]+@[\w.-]+\.[a-z]{2,}\b/gi, "")
6
- .replace(/\b[a-z]+(?:\.[a-z]+){2,}\b|\b[A-Z][a-zA-Z]+(?:Impl|Service|Controller|Repository)\b|\b\d{6,}\b/g, "")
7
- .replace(/\s+/g, " ")
8
- .trim();
9
- }
10
- //# sourceMappingURL=rules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/knowledge/rules.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO,IAAI;SACR,OAAO,CAAC,yEAAyE,EAAE,EAAE,CAAC;SACtF,OAAO,CAAC,kDAAkD,EAAE,EAAE,CAAC;SAC/D,OAAO,CAAC,iGAAiG,EAAE,EAAE,CAAC;SAC9G,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC"}
@@ -1,28 +0,0 @@
1
- import { type ReviewEntry } from '../core/review-ledger.js';
2
- type Kind = 'spec' | 'activity' | 'sequence';
3
- export interface ReviewTask {
4
- sourceKey: string;
5
- id: string;
6
- title: string;
7
- endpoint: string;
8
- note: string;
9
- sourceTrace: string[];
10
- spec: string;
11
- activity?: string;
12
- sequence?: string;
13
- allowedKinds: Kind[];
14
- baseFingerprint: string;
15
- }
16
- export declare function getReviewTasks({ projectPath }: {
17
- projectPath: string;
18
- }): ReviewTask[];
19
- export declare function currentReviewBaseFingerprint(projectPath: string, key: string, note: string): string;
20
- export declare function submitReviewRevision(input: {
21
- projectPath: string;
22
- sourceKey: string;
23
- baseFingerprint: string;
24
- spec?: string;
25
- activity?: string;
26
- sequence?: string;
27
- }): ReviewEntry;
28
- export {};