archscribe 0.2.2-rc.1 → 0.2.2
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 +96 -30
- package/dashboard-server/client-dist/assets/index-BK3iMzXX.css +1 -0
- package/dashboard-server/client-dist/assets/index-Bs2O2H8s.js +23 -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 +26 -0
- package/dashboard-server/dist/files-route.js +34 -0
- package/dashboard-server/dist/index.js +292 -0
- package/dashboard-server/dist/license-routes.js +39 -0
- package/dashboard-server/dist/outputs-route.js +208 -0
- package/dashboard-server/dist/run-route.js +89 -0
- package/dashboard-server/dist/security.js +115 -0
- package/dist/cli/archscribe.js +111 -30
- package/dist/cli/archscribe.js.map +1 -1
- package/dist/cli/commands.js +6 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/context.d.ts +1 -0
- package/dist/cli/context.js +34 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/doctor.js +2 -2
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/history.js +58 -0
- package/dist/cli/history.js.map +1 -1
- package/dist/cli/login.js +4 -6
- package/dist/cli/login.js.map +1 -1
- package/dist/cli/logout.js +1 -1
- package/dist/cli/logout.js.map +1 -1
- package/dist/cli/rag.d.ts +1 -4
- package/dist/cli/rag.js +7 -29
- package/dist/cli/rag.js.map +1 -1
- package/dist/cli/review.d.ts +1 -0
- package/dist/cli/review.js +144 -0
- package/dist/cli/review.js.map +1 -0
- package/dist/cli/run.d.ts +4 -1
- package/dist/cli/run.js +10 -20
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/shell.js +8 -19
- package/dist/cli/shell.js.map +1 -1
- package/dist/cli/ui/animations.js +1 -1
- package/dist/cli/ui/document-frame.d.ts +17 -0
- package/dist/cli/ui/document-frame.js +65 -0
- package/dist/cli/ui/document-frame.js.map +1 -0
- package/dist/cli/ui/document-tui.d.ts +5 -0
- package/dist/cli/ui/document-tui.js +224 -0
- package/dist/cli/ui/document-tui.js.map +1 -0
- package/dist/cli/ui/keys.d.ts +1 -0
- package/dist/cli/ui/keys.js +30 -6
- package/dist/cli/ui/keys.js.map +1 -1
- package/dist/cli/ui/little-scribe.d.ts +3 -0
- package/dist/cli/ui/little-scribe.js +67 -0
- package/dist/cli/ui/little-scribe.js.map +1 -0
- package/dist/cli/ui/mascot.d.ts +4 -2
- package/dist/cli/ui/mascot.js +19 -46
- package/dist/cli/ui/mascot.js.map +1 -1
- package/dist/cli/ui/menu.d.ts +1 -1
- package/dist/cli/ui/menu.js +1 -1
- package/dist/cli/ui/menu.js.map +1 -1
- package/dist/cli/ui/stage.js +12 -7
- package/dist/cli/ui/stage.js.map +1 -1
- package/dist/cli/ui/term.js +3 -1
- package/dist/cli/ui/term.js.map +1 -1
- package/dist/core/actor-inference.d.ts +1 -0
- package/dist/core/actor-inference.js +2 -1
- package/dist/core/actor-inference.js.map +1 -1
- package/dist/core/approval-ledger.d.ts +57 -0
- package/dist/core/approval-ledger.js +95 -0
- package/dist/core/approval-ledger.js.map +1 -0
- package/dist/core/component-groups.d.ts +2 -0
- package/dist/core/component-groups.js +4 -0
- package/dist/core/component-groups.js.map +1 -1
- package/dist/core/docx-update.js +36 -4
- package/dist/core/docx-update.js.map +1 -1
- package/dist/core/docx.js +2 -2
- package/dist/core/docx.js.map +1 -1
- package/dist/core/flow-steps.d.ts +1 -4
- package/dist/core/flow-steps.js +46 -108
- package/dist/core/flow-steps.js.map +1 -1
- package/dist/core/flow-trace.d.ts +9 -2
- package/dist/core/flow-trace.js +57 -58
- package/dist/core/flow-trace.js.map +1 -1
- package/dist/core/flow.js +10 -14
- package/dist/core/flow.js.map +1 -1
- package/dist/core/grouping-messages.generated.d.ts +21 -0
- package/dist/core/grouping-messages.generated.js +22 -0
- package/dist/core/grouping-messages.generated.js.map +1 -0
- package/dist/core/ledger-reconcile.d.ts +40 -0
- package/dist/core/ledger-reconcile.js +296 -0
- package/dist/core/ledger-reconcile.js.map +1 -0
- package/dist/core/markdown.d.ts +14 -1
- package/dist/core/markdown.js +80 -24
- package/dist/core/markdown.js.map +1 -1
- package/dist/core/materialize-report.d.ts +10 -0
- package/dist/core/materialize-report.js +72 -0
- package/dist/core/materialize-report.js.map +1 -0
- package/dist/core/output-history.d.ts +29 -0
- package/dist/core/output-history.js +204 -0
- package/dist/core/output-history.js.map +1 -0
- package/dist/core/output-mutation.d.ts +1 -0
- package/dist/core/output-mutation.js +15 -0
- package/dist/core/output-mutation.js.map +1 -0
- package/dist/core/parser.js +1 -3
- package/dist/core/parser.js.map +1 -1
- package/dist/core/review-feedback.d.ts +7 -0
- package/dist/core/review-feedback.js +46 -0
- package/dist/core/review-feedback.js.map +1 -0
- package/dist/core/uc-context-builder.d.ts +1 -0
- package/dist/core/uc-context-builder.js +11 -0
- package/dist/core/uc-context-builder.js.map +1 -1
- package/dist/core/uc-grouping-candidates.d.ts +9 -0
- package/dist/core/uc-grouping-candidates.js +35 -0
- package/dist/core/uc-grouping-candidates.js.map +1 -0
- package/dist/core/uc-grouping-evidence.d.ts +5 -0
- package/dist/core/uc-grouping-evidence.js +95 -0
- package/dist/core/uc-grouping-evidence.js.map +1 -0
- package/dist/core/uc-proposal.d.ts +19 -2
- package/dist/core/uc-proposal.js +127 -0
- package/dist/core/uc-proposal.js.map +1 -1
- package/dist/diagrams/activity.js +16 -5
- package/dist/diagrams/activity.js.map +1 -1
- package/dist/diagrams/arch/classify.d.ts +35 -0
- package/dist/diagrams/arch/classify.js +132 -0
- package/dist/diagrams/arch/classify.js.map +1 -0
- package/dist/diagrams/arch/layout-clean.d.ts +10 -0
- package/dist/diagrams/arch/layout-clean.js +74 -0
- package/dist/diagrams/arch/layout-clean.js.map +1 -0
- package/dist/diagrams/arch/layout-component.d.ts +13 -0
- package/dist/diagrams/arch/layout-component.js +136 -0
- package/dist/diagrams/arch/layout-component.js.map +1 -0
- package/dist/diagrams/arch/layout-hexagonal.d.ts +11 -0
- package/dist/diagrams/arch/layout-hexagonal.js +142 -0
- package/dist/diagrams/arch/layout-hexagonal.js.map +1 -0
- package/dist/diagrams/arch/layout-layered.d.ts +17 -0
- package/dist/diagrams/arch/layout-layered.js +89 -0
- package/dist/diagrams/arch/layout-layered.js.map +1 -0
- package/dist/diagrams/arch/model.d.ts +66 -0
- package/dist/diagrams/arch/model.js +216 -0
- package/dist/diagrams/arch/model.js.map +1 -0
- package/dist/diagrams/arch/xml.d.ts +20 -0
- package/dist/diagrams/arch/xml.js +39 -0
- package/dist/diagrams/arch/xml.js.map +1 -0
- package/dist/diagrams/architecture.d.ts +26 -36
- package/dist/diagrams/architecture.js +48 -155
- package/dist/diagrams/architecture.js.map +1 -1
- package/dist/diagrams/layout/radial.d.ts +1 -1
- package/dist/diagrams/layout/radial.js +318 -2
- package/dist/diagrams/layout/radial.js.map +1 -1
- package/dist/diagrams/sequence-model.js +6 -8
- package/dist/diagrams/sequence-model.js.map +1 -1
- package/dist/diagrams/usecase.d.ts +2 -1
- package/dist/diagrams/usecase.js +44 -20
- package/dist/diagrams/usecase.js.map +1 -1
- package/dist/diagrams/usecase_layout.d.ts +7 -12
- package/dist/diagrams/usecase_layout.js +25 -84
- package/dist/diagrams/usecase_layout.js.map +1 -1
- package/dist/evaluation/dashboard-review.js +0 -66
- package/dist/evaluation/dashboard-review.js.map +1 -1
- package/dist/knowledge/evidence.d.ts +48 -0
- package/dist/knowledge/evidence.js +253 -0
- package/dist/knowledge/evidence.js.map +1 -0
- package/dist/knowledge/hub-grouping.d.ts +7 -3
- package/dist/knowledge/hub-grouping.js +74 -55
- package/dist/knowledge/hub-grouping.js.map +1 -1
- package/dist/knowledge/local-kb.d.ts +4 -0
- package/dist/knowledge/local-kb.js +84 -0
- package/dist/knowledge/local-kb.js.map +1 -0
- package/dist/knowledge/rag-augment.d.ts +31 -6
- package/dist/knowledge/rag-augment.js +77 -37
- package/dist/knowledge/rag-augment.js.map +1 -1
- package/dist/knowledge/rag-client.d.ts +11 -0
- package/dist/knowledge/rag-client.js +60 -0
- package/dist/knowledge/rag-client.js.map +1 -0
- package/dist/knowledge/retriever.d.ts +7 -2
- package/dist/knowledge/retriever.js +29 -14
- package/dist/knowledge/retriever.js.map +1 -1
- package/dist/knowledge/rules.d.ts +2 -0
- package/dist/knowledge/rules.js +10 -0
- package/dist/knowledge/rules.js.map +1 -0
- package/dist/knowledge/store-lock.d.ts +2 -0
- package/dist/knowledge/store-lock.js +35 -0
- package/dist/knowledge/store-lock.js.map +1 -0
- package/dist/knowledge/types.d.ts +6 -1
- package/dist/license/banner.d.ts +1 -3
- package/dist/license/banner.js +2 -6
- package/dist/license/banner.js.map +1 -1
- package/dist/license/client.d.ts +4 -7
- package/dist/license/client.js +6 -16
- package/dist/license/client.js.map +1 -1
- package/dist/license/gate.d.ts +1 -3
- package/dist/license/gate.js +3 -3
- package/dist/license/gate.js.map +1 -1
- package/dist/license/verify.js +19 -14
- package/dist/license/verify.js.map +1 -1
- package/dist/parser.jar +0 -0
- package/dist/server.js +120 -11
- package/dist/server.js.map +1 -1
- package/dist/theory/context.d.ts +52 -0
- package/dist/theory/context.js +144 -0
- package/dist/theory/context.js.map +1 -0
- package/dist/theory/fill.d.ts +13 -1
- package/dist/theory/fill.js +122 -71
- package/dist/theory/fill.js.map +1 -1
- package/dist/theory/references.d.ts +9 -34
- package/dist/theory/references.js +9 -135
- package/dist/theory/references.js.map +1 -1
- package/dist/theory/scaffold.js +41 -26
- package/dist/theory/scaffold.js.map +1 -1
- package/dist/tools/environment.js +1 -1
- package/dist/tools/environment.js.map +1 -1
- package/dist/tools/generate_report.d.ts +5 -1
- package/dist/tools/generate_report.js +153 -88
- package/dist/tools/generate_report.js.map +1 -1
- package/dist/tools/learn_usecase.d.ts +2 -6
- package/dist/tools/learn_usecase.js +50 -34
- package/dist/tools/learn_usecase.js.map +1 -1
- package/dist/tools/propose_uc_groupings.d.ts +1 -10
- package/dist/tools/propose_uc_groupings.js +23 -79
- package/dist/tools/propose_uc_groupings.js.map +1 -1
- package/dist/tools/review_tools.d.ts +26 -0
- package/dist/tools/review_tools.js +55 -0
- package/dist/tools/review_tools.js.map +1 -0
- package/dist/tools/scaffold.d.ts +3 -1
- package/dist/tools/scaffold.js +99 -58
- package/dist/tools/scaffold.js.map +1 -1
- package/dist/tools/scan_repo.js +1 -1
- package/dist/tools/scan_repo.js.map +1 -1
- package/dist/types/ir.d.ts +4 -0
- package/dist/types/license.d.ts +4 -3
- package/dist/types/report.d.ts +10 -1
- package/dist/types/theory.d.ts +3 -2
- package/dist/types/uc-grouping.d.ts +57 -7
- package/dist/utils/dashboard-launcher.js +1 -1
- package/dist/utils/dashboard-launcher.js.map +1 -1
- package/dist/utils/mcp-launch.d.ts +26 -0
- package/dist/utils/mcp-launch.js +48 -0
- package/dist/utils/mcp-launch.js.map +1 -0
- package/dist/utils/run-history.d.ts +1 -2
- package/dist/utils/run-history.js +2 -11
- package/dist/utils/run-history.js.map +1 -1
- package/package.json +35 -10
- package/dist/knowledge/embedding.d.ts +0 -11
- package/dist/knowledge/embedding.js +0 -31
- package/dist/knowledge/embedding.js.map +0 -1
- package/dist/knowledge/qdrant-client.d.ts +0 -20
- package/dist/knowledge/qdrant-client.js +0 -95
- package/dist/knowledge/qdrant-client.js.map +0 -1
- package/dist/knowledge/seed-data-extended.d.ts +0 -7
- package/dist/knowledge/seed-data-extended.js +0 -183
- package/dist/knowledge/seed-data-extended.js.map +0 -1
- package/dist/knowledge/seed-data-extra.d.ts +0 -6
- package/dist/knowledge/seed-data-extra.js +0 -178
- package/dist/knowledge/seed-data-extra.js.map +0 -1
- package/dist/knowledge/seed-data.d.ts +0 -3
- package/dist/knowledge/seed-data.js +0 -333
- package/dist/knowledge/seed-data.js.map +0 -1
- package/dist/knowledge/seed.d.ts +0 -22
- package/dist/knowledge/seed.js +0 -44
- package/dist/knowledge/seed.js.map +0 -1
- package/dist/utils/approval.d.ts +0 -65
- package/dist/utils/approval.js +0 -324
- package/dist/utils/approval.js.map +0 -1
- package/dist/utils/keep-regions.d.ts +0 -44
- package/dist/utils/keep-regions.js +0 -153
- package/dist/utils/keep-regions.js.map +0 -1
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
|
3
|
+
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
|
4
|
+
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
|
5
|
+
</symbol>
|
|
6
|
+
<symbol id="discord-icon" viewBox="0 0 20 19">
|
|
7
|
+
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
|
8
|
+
</symbol>
|
|
9
|
+
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
|
10
|
+
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
|
11
|
+
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
|
12
|
+
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
|
13
|
+
</symbol>
|
|
14
|
+
<symbol id="github-icon" viewBox="0 0 19 19">
|
|
15
|
+
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
|
16
|
+
</symbol>
|
|
17
|
+
<symbol id="social-icon" viewBox="0 0 20 20">
|
|
18
|
+
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
|
19
|
+
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
|
20
|
+
</symbol>
|
|
21
|
+
<symbol id="x-icon" viewBox="0 0 19 19">
|
|
22
|
+
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
|
23
|
+
</symbol>
|
|
24
|
+
</svg>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/png" href="/brand/favicon.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>archscribe dashboard</title>
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-Bs2O2H8s.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BK3iMzXX.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every archscribe-core function the dashboard needs, re-exported from one
|
|
3
|
+
* place. The dashboard calls these DIRECTLY — never spawns `archscribe`
|
|
4
|
+
* and parses its terminal output — so this file is the one spot that knows
|
|
5
|
+
* the relative path from dashboard-server/dist back to the root dist/
|
|
6
|
+
* (requires `npm run build:ts` in the repo root before building this
|
|
7
|
+
* package; see dashboard-server/README or build-test.yml for the order).
|
|
8
|
+
*/
|
|
9
|
+
export { scanRepo, extractClasses, extractDependencies } from "../../dist/tools/scan_repo.js";
|
|
10
|
+
export { generateReport } from "../../dist/tools/generate_report.js";
|
|
11
|
+
export { loadLicense } from "../../dist/license/verify.js";
|
|
12
|
+
export { performLogin } from "../../dist/license/login-flow.js";
|
|
13
|
+
export { formatLicenseStatusLine } from "../../dist/license/status-line.js";
|
|
14
|
+
export { formatReportResultLine } from "../../dist/core/run-result.js";
|
|
15
|
+
export { renderComponentGroups } from "../../dist/core/component-groups.js";
|
|
16
|
+
export { buildRunSummary } from "../../dist/core/run-summary.js";
|
|
17
|
+
export { trackedFiles, listVersions, diffVersions, restoreVersion } from "../../dist/core/output-history.js";
|
|
18
|
+
export { readFeedback, saveFeedback, reviewKey } from "../../dist/core/review-feedback.js";
|
|
19
|
+
export { withOutputMutation } from "../../dist/core/output-mutation.js";
|
|
20
|
+
export { docxAvailable } from "../../dist/core/materialize-report.js";
|
|
21
|
+
export { readLedger } from "../../dist/core/approval-ledger.js";
|
|
22
|
+
export { browserOpenCommand } from "../../dist/utils/open.js";
|
|
23
|
+
export { getPackageVersion } from "../../dist/utils/version.js";
|
|
24
|
+
export { readConfig, resolveOutputDir, resolveReportSource } from "../../dist/core/project-config.js";
|
|
25
|
+
export { validateManagedSource } from "../../dist/core/docx-update.js";
|
|
26
|
+
export { checkFreshness } from "../../dist/core/freshness.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/files — serves one output file by path, scoped to a run's own
|
|
3
|
+
* output directory. `path` is normally one of the absolute paths the SAME
|
|
4
|
+
* run already returned (e.g. RunSummary.report.docx_path) — the client
|
|
5
|
+
* echoes it back, the server re-validates it stays inside `dir` before
|
|
6
|
+
* ever reading it. Never serves a file that doesn't exist: a missing
|
|
7
|
+
* report.docx (Free tier skipped it) is a 404, not a fabricated "ready".
|
|
8
|
+
*/
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { docxAvailable } from "./core-bridge.js";
|
|
12
|
+
import { resolveWithinDir } from "./security.js";
|
|
13
|
+
export function handleFileDownload(req, res) {
|
|
14
|
+
const dir = req.query["dir"];
|
|
15
|
+
const filePath = req.query["path"];
|
|
16
|
+
if (typeof dir !== "string" || typeof filePath !== "string" || !dir || !filePath) {
|
|
17
|
+
res.status(400).json({ error: "dir and path query params are required" });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const resolved = resolveWithinDir(dir, filePath);
|
|
21
|
+
if (!resolved) {
|
|
22
|
+
res.status(403).json({ error: "path escapes the given output directory" });
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) {
|
|
26
|
+
res.status(404).json({ error: "file not found" });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (path.extname(resolved).toLowerCase() === ".docx" && !docxAvailable(path.dirname(resolved), path.basename(resolved))) {
|
|
30
|
+
res.status(409).json({ error: "DOCX is stale or unavailable; re-export the report first" });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
res.download(resolved);
|
|
34
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// Suppress the spurious Node.js 22+ localStorage warning emitted by the docx
|
|
2
|
+
// library (loaded transitively via core-bridge.js -> generateReport). Same
|
|
3
|
+
// suppression as archscribe.ts/server.ts in the root package — docx touches
|
|
4
|
+
// window.localStorage at module load; this process never passes
|
|
5
|
+
// --localstorage-file either.
|
|
6
|
+
{
|
|
7
|
+
const _origEmit = process.emit.bind(process);
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
process.emit = function (name, ...args) {
|
|
10
|
+
if (name === "warning") {
|
|
11
|
+
const w = args[0];
|
|
12
|
+
if (w && String(w.message).includes("localstorage-file"))
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
return _origEmit(name, ...args);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
import express from "express";
|
|
20
|
+
import fs from "node:fs";
|
|
21
|
+
import os from "node:os";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
import { hostGuard, authGuard, generateToken, persistToken, readPersistedToken } from "./security.js";
|
|
25
|
+
import { handleRunRequest } from "./run-route.js";
|
|
26
|
+
import { registerOutputRoutes, listOutputs } from "./outputs-route.js";
|
|
27
|
+
import { handleLicenseStatus, handleLogin } from "./license-routes.js";
|
|
28
|
+
import { handleFileDownload } from "./files-route.js";
|
|
29
|
+
import { getPackageVersion, checkFreshness } from "./core-bridge.js";
|
|
30
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
31
|
+
const PORT = parseInt(process.env.DASHBOARD_PORT ?? "4173", 10);
|
|
32
|
+
// DASHBOARD_PROJECTS_FILE: tests point this at a temp file, never the
|
|
33
|
+
// developer's real projects.local.json.
|
|
34
|
+
const PROJECTS_FILE = process.env.DASHBOARD_PROJECTS_FILE
|
|
35
|
+
? path.resolve(process.env.DASHBOARD_PROJECTS_FILE)
|
|
36
|
+
: path.resolve(__dirname, "../../projects.local.json");
|
|
37
|
+
// Serve React build when available (built via `npm run build` in client/)
|
|
38
|
+
const CLIENT_DIST = path.resolve(__dirname, "../client-dist");
|
|
39
|
+
// A pre-chosen token (DASHBOARD_TOKEN env var) wins when present so the process
|
|
40
|
+
// that spawned this server can pin one without reading the token file back.
|
|
41
|
+
// Otherwise reuse the token a previous run persisted: minting a fresh one on
|
|
42
|
+
// every start turned every /api/* call in an already-open dashboard tab into a
|
|
43
|
+
// 401 (the tab still had the old token in sessionStorage and no way to get the
|
|
44
|
+
// new one). Only when there is no usable persisted token do we generate one.
|
|
45
|
+
// Either way it's persisted to TOKEN_FILE so any other local process can
|
|
46
|
+
// discover whichever token THIS running server actually checks.
|
|
47
|
+
const TOKEN = process.env.DASHBOARD_TOKEN && process.env.DASHBOARD_TOKEN.length >= 32
|
|
48
|
+
? process.env.DASHBOARD_TOKEN
|
|
49
|
+
: readPersistedToken() ?? generateToken();
|
|
50
|
+
persistToken(TOKEN);
|
|
51
|
+
const app = express();
|
|
52
|
+
app.use(express.json({ limit: "10mb" }));
|
|
53
|
+
// Serve React SPA static assets if built
|
|
54
|
+
if (fs.existsSync(CLIENT_DIST)) {
|
|
55
|
+
app.use(express.static(CLIENT_DIST));
|
|
56
|
+
}
|
|
57
|
+
const sseClients = [];
|
|
58
|
+
let sseClientId = 0;
|
|
59
|
+
function broadcast(event, data) {
|
|
60
|
+
const payload = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
61
|
+
for (const client of sseClients) {
|
|
62
|
+
client.res.write(payload);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
66
|
+
function readProjects() {
|
|
67
|
+
if (!fs.existsSync(PROJECTS_FILE))
|
|
68
|
+
return process.env.DASHBOARD_PROJECTS_FILE ? {} : readRecentProjects();
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(fs.readFileSync(PROJECTS_FILE, "utf-8"));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** npm installs have no projects.local.json; reuse projects recorded by the CLI. */
|
|
77
|
+
function readRecentProjects() {
|
|
78
|
+
try {
|
|
79
|
+
const state = JSON.parse(fs.readFileSync(path.join(os.homedir(), ".archscribe", "state.json"), "utf-8"));
|
|
80
|
+
if (!state || typeof state !== "object" || !("recent" in state) || !Array.isArray(state.recent))
|
|
81
|
+
return {};
|
|
82
|
+
const out = Object.create(null);
|
|
83
|
+
for (const entry of state.recent) {
|
|
84
|
+
if (!entry || typeof entry.path !== "string" || !path.isAbsolute(entry.path))
|
|
85
|
+
continue;
|
|
86
|
+
const base = path.basename(entry.path);
|
|
87
|
+
if (!base || Object.values(out).includes(entry.path))
|
|
88
|
+
continue;
|
|
89
|
+
let name = base;
|
|
90
|
+
for (let i = 2; Object.hasOwn(out, name); i++)
|
|
91
|
+
name = `${base}-${i}`;
|
|
92
|
+
out[name] = entry.path;
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function reportPath(projectPath) {
|
|
101
|
+
return path.join(projectPath, "archscribe-output", "evaluation-report.json");
|
|
102
|
+
}
|
|
103
|
+
function diagramDir(projectPath) {
|
|
104
|
+
return path.join(projectPath, "archscribe-output", "diagrams");
|
|
105
|
+
}
|
|
106
|
+
// ── Public routes (no auth — must reveal nothing sensitive) ────────────────
|
|
107
|
+
/** Health check — used by launcher to detect if server is already running. */
|
|
108
|
+
app.get("/health", (_req, res) => {
|
|
109
|
+
res.json({ status: "ok", port: PORT });
|
|
110
|
+
});
|
|
111
|
+
// ── Everything under /api/* requires same-host + the startup token ─────────
|
|
112
|
+
app.use("/api", hostGuard, authGuard(() => TOKEN));
|
|
113
|
+
app.get("/api/version", (_req, res) => {
|
|
114
|
+
res.json({ version: getPackageVersion() });
|
|
115
|
+
});
|
|
116
|
+
app.get("/api/license/status", (_req, res) => {
|
|
117
|
+
handleLicenseStatus(_req, res).catch((e) => res.status(500).json({ error: String(e) }));
|
|
118
|
+
});
|
|
119
|
+
app.post("/api/login", (req, res) => {
|
|
120
|
+
handleLogin(req, res).catch((e) => res.status(500).json({ error: String(e) }));
|
|
121
|
+
});
|
|
122
|
+
app.post("/api/run", (req, res) => {
|
|
123
|
+
handleRunRequest(req, res, broadcast).catch((e) => res.status(500).json({ error: String(e) }));
|
|
124
|
+
});
|
|
125
|
+
app.get("/api/files", handleFileDownload);
|
|
126
|
+
/** List all configured projects with metadata. */
|
|
127
|
+
app.get("/api/projects", (_req, res) => {
|
|
128
|
+
const projects = readProjects();
|
|
129
|
+
const list = Object.entries(projects).map(([name, projectPath]) => {
|
|
130
|
+
const rp = reportPath(projectPath);
|
|
131
|
+
let lastRun = null;
|
|
132
|
+
let hasReport = false;
|
|
133
|
+
if (fs.existsSync(rp)) {
|
|
134
|
+
hasReport = true;
|
|
135
|
+
try {
|
|
136
|
+
const stat = fs.statSync(rp);
|
|
137
|
+
lastRun = stat.mtime.toISOString();
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// ignore
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { name, path: projectPath, hasReport, lastRun };
|
|
144
|
+
});
|
|
145
|
+
res.json(list);
|
|
146
|
+
});
|
|
147
|
+
/** Read a project's evaluation-report.json live (no caching). */
|
|
148
|
+
app.get("/api/projects/:name/report", (req, res) => {
|
|
149
|
+
const projects = readProjects();
|
|
150
|
+
const projectPath = projects[req.params.name];
|
|
151
|
+
if (!projectPath) {
|
|
152
|
+
res.status(404).json({ error: "Project not found" });
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const rp = reportPath(projectPath);
|
|
156
|
+
if (!fs.existsSync(rp)) {
|
|
157
|
+
res.status(404).json({ error: "No report yet — run archscribe first" });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const data = JSON.parse(fs.readFileSync(rp, "utf-8"));
|
|
162
|
+
res.json(data);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
res.status(500).json({ error: "Failed to parse report" });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
/** List .drawio files in a project's archscribe-output dir. */
|
|
169
|
+
app.get("/api/projects/:name/diagrams", (req, res) => {
|
|
170
|
+
const projects = readProjects();
|
|
171
|
+
const projectPath = projects[req.params.name];
|
|
172
|
+
if (!projectPath) {
|
|
173
|
+
res.status(404).json({ error: "Project not found" });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const dir = diagramDir(projectPath);
|
|
177
|
+
if (!fs.existsSync(dir)) {
|
|
178
|
+
res.json([]);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const files = listOutputs(projectPath)
|
|
182
|
+
.filter((f) => f.path.startsWith("archscribe-output/diagrams/") && f.path.endsWith(".drawio"))
|
|
183
|
+
.map((f) => ({ name: f.path.slice("archscribe-output/diagrams/".length), path: path.join(projectPath, f.path) }));
|
|
184
|
+
res.json(files);
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* Receive new report data from the archscribe pipeline (via dashboard-launcher).
|
|
188
|
+
* Saves to disk and notifies SSE clients.
|
|
189
|
+
*/
|
|
190
|
+
app.post("/api/projects/:name/report", (req, res) => {
|
|
191
|
+
const projects = readProjects();
|
|
192
|
+
const projectPath = projects[req.params.name];
|
|
193
|
+
if (!projectPath) {
|
|
194
|
+
res.status(404).json({ error: "Project not found" });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const rp = reportPath(projectPath);
|
|
198
|
+
try {
|
|
199
|
+
// Persist the incoming report (pipeline already wrote it; this is a
|
|
200
|
+
// push notification so the React client can update without polling)
|
|
201
|
+
const data = req.body;
|
|
202
|
+
fs.mkdirSync(path.dirname(rp), { recursive: true });
|
|
203
|
+
fs.writeFileSync(rp, JSON.stringify(data, null, 2), "utf-8");
|
|
204
|
+
broadcast("report-updated", { project: req.params.name });
|
|
205
|
+
res.json({ ok: true });
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
res.status(500).json({ error: String(e) });
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
/** SSE endpoint — clients subscribe to live report updates. EventSource can't set headers, so the client passes the token via ?token= (see authGuard). */
|
|
212
|
+
app.get("/api/events", (req, res) => {
|
|
213
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
214
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
215
|
+
res.setHeader("Connection", "keep-alive");
|
|
216
|
+
res.flushHeaders();
|
|
217
|
+
const id = ++sseClientId;
|
|
218
|
+
sseClients.push({ res, id });
|
|
219
|
+
// Heartbeat every 25s to keep connection alive through proxies
|
|
220
|
+
const heartbeat = setInterval(() => {
|
|
221
|
+
res.write(": heartbeat\n\n");
|
|
222
|
+
}, 25_000);
|
|
223
|
+
req.on("close", () => {
|
|
224
|
+
clearInterval(heartbeat);
|
|
225
|
+
const idx = sseClients.findIndex((c) => c.id === id);
|
|
226
|
+
if (idx >= 0)
|
|
227
|
+
sseClients.splice(idx, 1);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
/** B3 — are the generated docs stale? Compares the sources with archscribe-output/manifest.json. */
|
|
231
|
+
app.get("/api/projects/:name/freshness", (req, res) => {
|
|
232
|
+
const projectPath = readProjects()[req.params.name];
|
|
233
|
+
if (!projectPath) {
|
|
234
|
+
res.status(404).json({ error: "Project not found" });
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
res.json(checkFreshness(projectPath, path.join(projectPath, "archscribe-output")));
|
|
238
|
+
});
|
|
239
|
+
/** Read run history for a project from runs/<slug>/run-meta.json files. */
|
|
240
|
+
app.get("/api/projects/:name/runs", (req, res) => {
|
|
241
|
+
const projects = readProjects();
|
|
242
|
+
const projectPath = projects[req.params.name];
|
|
243
|
+
if (!projectPath) {
|
|
244
|
+
res.status(404).json({ error: "Project not found" });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const runsDir = path.join(projectPath, "archscribe-output", "runs");
|
|
248
|
+
if (!fs.existsSync(runsDir)) {
|
|
249
|
+
res.json([]);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
const entries = fs.readdirSync(runsDir, { withFileTypes: true })
|
|
254
|
+
.filter((e) => e.isDirectory()).map((e) => e.name).sort().reverse();
|
|
255
|
+
const runs = entries.flatMap((dir) => {
|
|
256
|
+
try {
|
|
257
|
+
return [JSON.parse(fs.readFileSync(path.join(runsDir, dir, "run-meta.json"), "utf8"))];
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return [];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
res.json(runs);
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
res.json([]);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
registerOutputRoutes(app, readProjects, broadcast);
|
|
270
|
+
// A request under /api/* that doesn't match any route above is a client
|
|
271
|
+
// bug (wrong endpoint), not a page navigation — it must 404 as JSON, not
|
|
272
|
+
// fall through to the SPA catch-all below. Without this, a mistyped API
|
|
273
|
+
// call gets back index.html's HTML with a 200, which surfaces client-side
|
|
274
|
+
// as "Unexpected token '<'" from JSON.parse() — a confusing failure mode
|
|
275
|
+
// for what's actually a 404. Registered AFTER every real /api/* route
|
|
276
|
+
// above (Express matches routes in registration order) and BEFORE the
|
|
277
|
+
// catch-all below, so it only catches what nothing else did.
|
|
278
|
+
app.use("/api", (_req, res) => {
|
|
279
|
+
res.status(404).json({ error: "Not found" });
|
|
280
|
+
});
|
|
281
|
+
// SPA fallback — serve index.html for any unmatched route (React Router)
|
|
282
|
+
if (fs.existsSync(CLIENT_DIST)) {
|
|
283
|
+
app.get("*", (_req, res) => {
|
|
284
|
+
res.sendFile(path.join(CLIENT_DIST, "index.html"));
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// Bind 127.0.0.1 ONLY — this server runs real core functions (scanRepo,
|
|
288
|
+
// generateReport, activateOnline) with filesystem and license-server access;
|
|
289
|
+
// it must never be reachable from the local network, only this machine.
|
|
290
|
+
app.listen(PORT, "127.0.0.1", () => {
|
|
291
|
+
console.log(`archscribe dashboard running on http://localhost:${PORT}/?token=${TOKEN}`);
|
|
292
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { loadLicense, performLogin, formatLicenseStatusLine } from "./core-bridge.js";
|
|
2
|
+
export async function handleLicenseStatus(_req, res) {
|
|
3
|
+
const check = await loadLicense([]);
|
|
4
|
+
res.json({ ...check, line: formatLicenseStatusLine(check) });
|
|
5
|
+
}
|
|
6
|
+
export async function handleLogin(req, res) {
|
|
7
|
+
const body = req.body;
|
|
8
|
+
const licenseKey = body.licenseKey;
|
|
9
|
+
if (!licenseKey || typeof licenseKey !== "string" || !licenseKey.trim()) {
|
|
10
|
+
res.status(400).json({ error: "licenseKey is required" });
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const outcome = await performLogin(licenseKey);
|
|
14
|
+
if (outcome.kind === "ok") {
|
|
15
|
+
const { session } = outcome;
|
|
16
|
+
res.json({
|
|
17
|
+
kind: "ok",
|
|
18
|
+
tier: session.tier,
|
|
19
|
+
licensee: session.licensee,
|
|
20
|
+
expiresAt: session.expiresAt,
|
|
21
|
+
line: formatLicenseStatusLine({ tier: session.tier, code: session.tier === "pro" ? "pro" : "free_plan", licensee: session.licensee, expiresAt: session.expiresAt, reason: "login" }),
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (outcome.kind === "already_logged_in") {
|
|
26
|
+
// D1: the dashboard never silently replaces another key — use the CLI.
|
|
27
|
+
res.status(409).json({
|
|
28
|
+
kind: "already_logged_in",
|
|
29
|
+
message: `This machine already uses another license (key ending ${outcome.currentKeyHint}). Run \`archscribe logout\` or \`archscribe login --switch\` in a terminal.`,
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (outcome.kind === "denied") {
|
|
34
|
+
res.status(401).json({ kind: "denied", code: outcome.code, message: outcome.message });
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
res.status(503).json({ kind: "unavailable", message: outcome.message });
|
|
38
|
+
// Never echo `licenseKey` back in any branch above.
|
|
39
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { trackedFiles, browserOpenCommand, listVersions, diffVersions, restoreVersion, readLedger, readFeedback, saveFeedback, reviewKey, withOutputMutation } from "./core-bridge.js";
|
|
5
|
+
import { recordVersion } from "../../dist/core/output-history.js";
|
|
6
|
+
import { docxAvailable } from "./core-bridge.js";
|
|
7
|
+
import { resolveWithinDir } from "./security.js";
|
|
8
|
+
const output = (project) => path.join(project, "archscribe-output");
|
|
9
|
+
const slash = (p) => p.split(path.sep).join("/");
|
|
10
|
+
export function listOutputs(project) {
|
|
11
|
+
const out = output(project);
|
|
12
|
+
const files = trackedFiles(project, out);
|
|
13
|
+
for (const name of ["report.docx", "dashboard.html"]) {
|
|
14
|
+
const rel = `archscribe-output/${name}`;
|
|
15
|
+
if (fs.existsSync(path.join(out, name)))
|
|
16
|
+
files.push(rel);
|
|
17
|
+
}
|
|
18
|
+
return [...new Set(files)].sort().flatMap((rel) => {
|
|
19
|
+
if (rel.endsWith('.docx') && !docxAvailable(out, path.basename(rel)))
|
|
20
|
+
return [];
|
|
21
|
+
const file = resolveManagedPath(project, rel);
|
|
22
|
+
if (!file)
|
|
23
|
+
return [];
|
|
24
|
+
const stat = fs.statSync(file);
|
|
25
|
+
return [{ path: rel, size: stat.size, mtime: stat.mtime.toISOString() }];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function resolveManagedPath(project, rel) {
|
|
29
|
+
if (path.isAbsolute(rel) || rel.includes("\\") || rel.split("/").includes(".."))
|
|
30
|
+
return null;
|
|
31
|
+
const file = resolveWithinDir(project, rel);
|
|
32
|
+
if (!file || !fs.existsSync(file) || !fs.statSync(file).isFile())
|
|
33
|
+
return null;
|
|
34
|
+
const root = fs.realpathSync(project);
|
|
35
|
+
const actual = fs.realpathSync(file);
|
|
36
|
+
if (!actual.startsWith(root + path.sep))
|
|
37
|
+
return null;
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
export function resolveManaged(project, rel) {
|
|
41
|
+
if (!resolveManagedPath(project, rel))
|
|
42
|
+
return null;
|
|
43
|
+
if (!listOutputs(project).some((f) => f.path === slash(rel)))
|
|
44
|
+
return null;
|
|
45
|
+
return resolveManagedPath(project, rel);
|
|
46
|
+
}
|
|
47
|
+
export function registerOutputRoutes(app, projects, broadcast) {
|
|
48
|
+
const projectFor = (name) => projects()[name];
|
|
49
|
+
app.get("/api/projects/:name/review", (req, res) => {
|
|
50
|
+
const project = projectFor(req.params.name);
|
|
51
|
+
if (!project) {
|
|
52
|
+
res.status(404).json({ error: "Project not found" });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const ledger = readLedger(project);
|
|
57
|
+
res.json({ feedback: readFeedback(project), specs: Object.fromEntries(Object.entries(ledger.entries).map(([key, e]) => [key, e.content])) });
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
res.status(500).json({ error: String(e) });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
app.post("/api/projects/:name/review", async (req, res) => {
|
|
64
|
+
const project = projectFor(req.params.name);
|
|
65
|
+
if (!project) {
|
|
66
|
+
res.status(404).json({ error: "Project not found" });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
await withOutputMutation(project, async () => {
|
|
71
|
+
const keys = new Set();
|
|
72
|
+
const evaluationPath = path.join(output(project), "evaluation-report.json");
|
|
73
|
+
const evaluation = fs.existsSync(evaluationPath) ? JSON.parse(fs.readFileSync(evaluationPath, "utf8")) : {};
|
|
74
|
+
const exists = (file) => typeof file === "string" && file.endsWith(".drawio") &&
|
|
75
|
+
resolveManagedPath(project, slash(path.relative(project, path.resolve(output(project), file)))) !== null;
|
|
76
|
+
for (const [kind, file] of Object.entries(evaluation.diagramPaths ?? {})) {
|
|
77
|
+
if (exists(file))
|
|
78
|
+
keys.add(`diagram:${kind}`);
|
|
79
|
+
}
|
|
80
|
+
for (const [key, entry] of Object.entries(readLedger(project).entries)) {
|
|
81
|
+
if (entry.status === "orphaned")
|
|
82
|
+
continue;
|
|
83
|
+
keys.add(reviewKey("uc", key));
|
|
84
|
+
const flow = evaluation.usecases?.find((f) => `uc:${f.endpoint}#${f.controllerName}.${f.methodName}` === key);
|
|
85
|
+
if (exists(flow?.activityDiagramPath))
|
|
86
|
+
keys.add(reviewKey("activity", key));
|
|
87
|
+
if (exists(flow?.sequenceDiagramPath))
|
|
88
|
+
keys.add(reviewKey("sequence", key));
|
|
89
|
+
}
|
|
90
|
+
// Allow clearing obsolete feedback, but never approving an absent artifact.
|
|
91
|
+
if (req.body?.status === null && typeof req.body?.key === "string" && req.body.key in readFeedback(project))
|
|
92
|
+
keys.add(req.body.key);
|
|
93
|
+
saveFeedback(project, req.body?.key, { status: req.body?.status, notes: req.body?.notes }, keys);
|
|
94
|
+
await recordVersion(project, output(project), `feedback: ${req.body.key}`);
|
|
95
|
+
res.json(readFeedback(project));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
res.status(String(e).includes("busy") ? 409 : 400).json({ error: String(e) });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
app.get("/api/projects/:name/outputs", (req, res) => {
|
|
103
|
+
const project = projectFor(req.params.name);
|
|
104
|
+
if (!project) {
|
|
105
|
+
res.status(404).json({ error: "Project not found" });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
res.json(listOutputs(project));
|
|
109
|
+
});
|
|
110
|
+
app.get("/api/projects/:name/outputs/file", (req, res) => {
|
|
111
|
+
const project = projectFor(req.params.name);
|
|
112
|
+
if (!project) {
|
|
113
|
+
res.status(404).json({ error: "Project not found" });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const file = typeof req.query.path === "string" ? resolveManaged(project, req.query.path) : null;
|
|
117
|
+
if (!file) {
|
|
118
|
+
res.status(403).json({ error: "File not managed" });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (/\.(md|json|drawio)$/.test(file))
|
|
122
|
+
res.type("text/plain; charset=utf-8").send(fs.readFileSync(file, "utf8"));
|
|
123
|
+
else
|
|
124
|
+
res.download(file);
|
|
125
|
+
});
|
|
126
|
+
app.post("/api/projects/:name/outputs/open", (req, res) => {
|
|
127
|
+
const project = projectFor(req.params.name);
|
|
128
|
+
if (!project) {
|
|
129
|
+
res.status(404).json({ error: "Project not found" });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const rel = req.body?.path;
|
|
133
|
+
if (typeof rel !== "string" || !rel.endsWith(".drawio")) {
|
|
134
|
+
res.status(400).json({ error: "Only .drawio files can be opened" });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const file = resolveManaged(project, rel);
|
|
138
|
+
if (!file) {
|
|
139
|
+
res.status(403).json({ error: "File not managed" });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const { command, args } = browserOpenCommand(process.platform, file);
|
|
143
|
+
spawn(command, args, { detached: true, stdio: "ignore" }).unref();
|
|
144
|
+
res.json({ ok: true });
|
|
145
|
+
});
|
|
146
|
+
app.get("/api/projects/:name/versions", async (req, res) => {
|
|
147
|
+
const project = projectFor(req.params.name);
|
|
148
|
+
if (!project) {
|
|
149
|
+
res.status(404).json({ error: "Project not found" });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
res.json(await listVersions(project));
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
res.status(500).json({ error: String(e) });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
app.get("/api/projects/:name/versions/diff", async (req, res) => {
|
|
160
|
+
const project = projectFor(req.params.name);
|
|
161
|
+
if (!project) {
|
|
162
|
+
res.status(404).json({ error: "Project not found" });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (typeof req.query.a !== "string" || typeof req.query.b !== "string") {
|
|
166
|
+
res.status(400).json({ error: "a and b required" });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
res.json(await diffVersions(project, req.query.a, req.query.b));
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
res.status(400).json({ error: String(e) });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
app.post("/api/projects/:name/versions/restore", async (req, res) => {
|
|
177
|
+
const project = projectFor(req.params.name);
|
|
178
|
+
if (!project) {
|
|
179
|
+
res.status(404).json({ error: "Project not found" });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (typeof req.body?.ref !== "string") {
|
|
183
|
+
res.status(400).json({ error: "ref required" });
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const restored = await restoreVersion(project, output(project), req.body.ref);
|
|
188
|
+
broadcast("report-updated", { project: req.params.name });
|
|
189
|
+
res.json(restored);
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
res.status(String(e).includes("busy") ? 409 : 400).json({ error: String(e) });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
app.get("/api/projects/:name/approvals", (req, res) => {
|
|
196
|
+
const project = projectFor(req.params.name);
|
|
197
|
+
if (!project) {
|
|
198
|
+
res.status(404).json({ error: "Project not found" });
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
res.json(readLedger(project));
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
res.status(500).json({ error: String(e) });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|