@latysh-development/monolith 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +132 -2
- package/dist/brief/cli.d.ts +30 -0
- package/dist/brief/cli.d.ts.map +1 -0
- package/dist/brief/cli.js +85 -0
- package/dist/brief/collect.d.ts +17 -0
- package/dist/brief/collect.d.ts.map +1 -0
- package/dist/brief/collect.js +302 -0
- package/dist/brief/config.d.ts +40 -0
- package/dist/brief/config.d.ts.map +1 -0
- package/dist/brief/config.js +85 -0
- package/dist/brief/constants.d.ts +10 -0
- package/dist/brief/constants.d.ts.map +1 -0
- package/dist/brief/constants.js +9 -0
- package/dist/brief/docs.d.ts +53 -0
- package/dist/brief/docs.d.ts.map +1 -0
- package/dist/brief/docs.js +229 -0
- package/dist/brief/freshness.d.ts +104 -0
- package/dist/brief/freshness.d.ts.map +1 -0
- package/dist/brief/freshness.js +263 -0
- package/dist/brief/git-signals.d.ts +17 -0
- package/dist/brief/git-signals.d.ts.map +1 -0
- package/dist/brief/git-signals.js +101 -0
- package/dist/brief/index.d.ts +11 -0
- package/dist/brief/index.d.ts.map +1 -0
- package/dist/brief/index.js +5 -0
- package/dist/brief/reconcile.d.ts +75 -0
- package/dist/brief/reconcile.d.ts.map +1 -0
- package/dist/brief/reconcile.js +259 -0
- package/dist/brief/render.d.ts +60 -0
- package/dist/brief/render.d.ts.map +1 -0
- package/dist/brief/render.js +407 -0
- package/dist/brief/sanitize.d.ts +38 -0
- package/dist/brief/sanitize.d.ts.map +1 -0
- package/dist/brief/sanitize.js +48 -0
- package/dist/brief/selectors.d.ts +36 -0
- package/dist/brief/selectors.d.ts.map +1 -0
- package/dist/brief/selectors.js +75 -0
- package/dist/brief/story.d.ts +18 -0
- package/dist/brief/story.d.ts.map +1 -0
- package/dist/brief/story.js +59 -0
- package/dist/brief/types.d.ts +110 -0
- package/dist/brief/types.d.ts.map +1 -0
- package/dist/brief/types.js +11 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +166 -0
- package/dist/cli/init-args.d.ts +16 -0
- package/dist/cli/init-args.d.ts.map +1 -0
- package/dist/cli/init-args.js +24 -0
- package/dist/cli/ui-args.d.ts +23 -0
- package/dist/cli/ui-args.d.ts.map +1 -0
- package/dist/cli/ui-args.js +66 -0
- package/dist/cli/ui.d.ts +40 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +180 -0
- package/dist/coordinatorium/checkpoint.d.ts +44 -0
- package/dist/coordinatorium/checkpoint.d.ts.map +1 -0
- package/dist/coordinatorium/checkpoint.js +124 -0
- package/dist/coordinatorium/cli.d.ts +39 -0
- package/dist/coordinatorium/cli.d.ts.map +1 -0
- package/dist/coordinatorium/cli.js +203 -0
- package/dist/coordinatorium/errors.d.ts +112 -0
- package/dist/coordinatorium/errors.d.ts.map +1 -0
- package/dist/coordinatorium/errors.js +145 -0
- package/dist/coordinatorium/index.d.ts +11 -0
- package/dist/coordinatorium/index.d.ts.map +1 -0
- package/dist/coordinatorium/index.js +5 -0
- package/dist/coordinatorium/lock.d.ts +187 -0
- package/dist/coordinatorium/lock.d.ts.map +1 -0
- package/dist/coordinatorium/lock.js +659 -0
- package/dist/coordinatorium/mission.d.ts +32 -0
- package/dist/coordinatorium/mission.d.ts.map +1 -0
- package/dist/coordinatorium/mission.js +87 -0
- package/dist/coordinatorium/state-keeper.d.ts +115 -0
- package/dist/coordinatorium/state-keeper.d.ts.map +1 -0
- package/dist/coordinatorium/state-keeper.js +396 -0
- package/dist/coordinatorium/types.d.ts +69 -0
- package/dist/coordinatorium/types.d.ts.map +1 -0
- package/dist/coordinatorium/types.js +27 -0
- package/dist/durable/assess.d.ts +105 -0
- package/dist/durable/assess.d.ts.map +1 -0
- package/dist/durable/assess.js +239 -0
- package/dist/durable/canonical.d.ts +25 -0
- package/dist/durable/canonical.d.ts.map +1 -0
- package/dist/durable/canonical.js +78 -0
- package/dist/durable/cli.d.ts +37 -0
- package/dist/durable/cli.d.ts.map +1 -0
- package/dist/durable/cli.js +141 -0
- package/dist/durable/errors.d.ts +188 -0
- package/dist/durable/errors.d.ts.map +1 -0
- package/dist/durable/errors.js +317 -0
- package/dist/durable/fs-store.d.ts +233 -0
- package/dist/durable/fs-store.d.ts.map +1 -0
- package/dist/durable/fs-store.js +1393 -0
- package/dist/durable/index.d.ts +20 -0
- package/dist/durable/index.d.ts.map +1 -0
- package/dist/durable/index.js +13 -0
- package/dist/durable/log.d.ts +33 -0
- package/dist/durable/log.d.ts.map +1 -0
- package/dist/durable/log.js +157 -0
- package/dist/durable/memory-store.d.ts +51 -0
- package/dist/durable/memory-store.d.ts.map +1 -0
- package/dist/durable/memory-store.js +302 -0
- package/dist/durable/projection.d.ts +35 -0
- package/dist/durable/projection.d.ts.map +1 -0
- package/dist/durable/projection.js +328 -0
- package/dist/durable/prune-check.d.ts +17 -0
- package/dist/durable/prune-check.d.ts.map +1 -0
- package/dist/durable/prune-check.js +45 -0
- package/dist/durable/register.d.ts +100 -0
- package/dist/durable/register.d.ts.map +1 -0
- package/dist/durable/register.js +532 -0
- package/dist/durable/retention.d.ts +49 -0
- package/dist/durable/retention.d.ts.map +1 -0
- package/dist/durable/retention.js +59 -0
- package/dist/durable/runtime.d.ts +497 -0
- package/dist/durable/runtime.d.ts.map +1 -0
- package/dist/durable/runtime.js +1271 -0
- package/dist/durable/seams.d.ts +40 -0
- package/dist/durable/seams.d.ts.map +1 -0
- package/dist/durable/seams.js +21 -0
- package/dist/durable/testing.d.ts +11 -0
- package/dist/durable/testing.d.ts.map +1 -0
- package/dist/durable/testing.js +25 -0
- package/dist/durable/types.d.ts +442 -0
- package/dist/durable/types.d.ts.map +1 -0
- package/dist/durable/types.js +75 -0
- package/dist/graph/builder.d.ts +11 -0
- package/dist/graph/builder.d.ts.map +1 -0
- package/dist/graph/builder.js +153 -0
- package/dist/graph/identity.d.ts +37 -0
- package/dist/graph/identity.d.ts.map +1 -0
- package/dist/graph/identity.js +46 -0
- package/dist/graph/index.d.ts +7 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +3 -0
- package/dist/graph/resolver.d.ts +41 -0
- package/dist/graph/resolver.d.ts.map +1 -0
- package/dist/graph/resolver.js +36 -0
- package/dist/graph/types.d.ts +42 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +1 -0
- package/dist/http/index.d.ts +5 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +2 -0
- package/dist/http/server.d.ts +76 -0
- package/dist/http/server.d.ts.map +1 -0
- package/dist/http/server.js +195 -0
- package/dist/http/ui-assets.d.ts +22 -0
- package/dist/http/ui-assets.d.ts.map +1 -0
- package/dist/http/ui-assets.js +100 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/init/index.d.ts +12 -0
- package/dist/init/index.d.ts.map +1 -0
- package/dist/init/index.js +90 -0
- package/dist/init/prompts.d.ts +3 -0
- package/dist/init/prompts.d.ts.map +1 -0
- package/dist/init/prompts.js +47 -0
- package/dist/init/scaffold.d.ts +25 -0
- package/dist/init/scaffold.d.ts.map +1 -0
- package/dist/init/scaffold.js +204 -0
- package/dist/init/types.d.ts +14 -0
- package/dist/init/types.d.ts.map +1 -0
- package/dist/init/types.js +1 -0
- package/dist/readmodel/dashboard.d.ts +40 -0
- package/dist/readmodel/dashboard.d.ts.map +1 -0
- package/dist/readmodel/dashboard.js +236 -0
- package/dist/readmodel/index.d.ts +3 -0
- package/dist/readmodel/index.d.ts.map +1 -0
- package/dist/readmodel/index.js +1 -0
- package/dist/readmodel/types.d.ts +104 -0
- package/dist/readmodel/types.d.ts.map +1 -0
- package/dist/readmodel/types.js +15 -0
- package/dist/root/index.d.ts +179 -0
- package/dist/root/index.d.ts.map +1 -0
- package/dist/root/index.js +418 -0
- package/dist/root/safe-write.d.ts +268 -0
- package/dist/root/safe-write.d.ts.map +1 -0
- package/dist/root/safe-write.js +966 -0
- package/dist/root/write-artifacts.d.ts +20 -0
- package/dist/root/write-artifacts.d.ts.map +1 -0
- package/dist/root/write-artifacts.js +42 -0
- package/dist/scriptorium/compile.d.ts +4 -0
- package/dist/scriptorium/compile.d.ts.map +1 -0
- package/dist/scriptorium/compile.js +185 -0
- package/dist/scriptorium/frontmatter.d.ts +13 -0
- package/dist/scriptorium/frontmatter.d.ts.map +1 -0
- package/dist/scriptorium/frontmatter.js +90 -0
- package/dist/scriptorium/index.d.ts +3 -0
- package/dist/scriptorium/index.d.ts.map +1 -0
- package/dist/scriptorium/index.js +1 -0
- package/dist/scriptorium/markdown.d.ts +31 -0
- package/dist/scriptorium/markdown.d.ts.map +1 -0
- package/dist/scriptorium/markdown.js +88 -0
- package/dist/scriptorium/types.d.ts +78 -0
- package/dist/scriptorium/types.d.ts.map +1 -0
- package/dist/scriptorium/types.js +1 -0
- package/dist/types/enforcement.d.ts +11 -0
- package/dist/types/enforcement.d.ts.map +1 -0
- package/dist/types/enforcement.js +1 -0
- package/dist/types/integrity.d.ts +33 -0
- package/dist/types/integrity.d.ts.map +1 -0
- package/dist/types/integrity.js +1 -0
- package/dist/types/project-definition.d.ts +30 -0
- package/dist/types/project-definition.d.ts.map +1 -0
- package/dist/types/project-definition.js +1 -0
- package/dist/ui/assets/cosmic-glass-bg-Dwx47zPu.webp +0 -0
- package/dist/ui/assets/index-C4NhMaq7.js +28 -0
- package/dist/ui/assets/index-DMZ7ZvZY.css +1 -0
- package/dist/ui/index.html +13 -0
- package/dist/validate/index.d.ts +6 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +214 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/package.json +67 -4
- package/templates/.gitkeep +0 -0
- package/templates/default-instance/instruction/.cursorrules +53 -0
- package/templates/default-instance/instruction/.windsurfrules +53 -0
- package/templates/default-instance/instruction/CLAUDE.md +53 -0
- package/templates/default-instance/monolith/context/boot/HANDOFF.md +49 -0
- package/templates/default-instance/monolith/context/boot/WORK_SESSION.md +30 -0
- package/templates/default-instance/monolith/context/execution/current-state.md +30 -0
- package/templates/default-instance/monolith/context/maps/dependency-map.md +38 -0
- package/templates/default-instance/monolith/context/maps/project-map.md +85 -0
- package/templates/default-instance/monolith/context/maps/roadmap-index.md +41 -0
- package/templates/default-instance/monolith/context/maps/routing-map.md +147 -0
- package/templates/default-instance/monolith/context/maps/semantic-map.md +73 -0
- package/templates/default-instance/monolith/context/models/model-registry.md +37 -0
- package/templates/default-instance/monolith/context/models/privacy-classification.md +35 -0
- package/templates/default-instance/monolith/context/templates/plan-template.md +56 -0
- package/templates/default-instance/monolith/governance/README.md +29 -0
- package/templates/default-instance/monolith/governance/RULE_SCHEMA.md +58 -0
- package/templates/default-instance/monolith/learning/INDEX.md +48 -0
- package/templates/default-instance/monolith/learning/injection-map.md +49 -0
- package/templates/default-instance/monolith/learning/taxonomy.md +30 -0
- package/templates/default-instance/monolith/memory/errors/README.md +26 -0
- package/templates/default-instance/monolith/memory/errors/SCHEMA.md +47 -0
- package/templates/default-instance/monolith/memory/errors/TAXONOMY.md +27 -0
- package/templates/default-instance/monolith/memory/long-term/architecture-principles.md +31 -0
- package/templates/default-instance/monolith/memory/long-term/decisions.md +36 -0
- package/templates/default-instance/monolith/memory/long-term/execution-history.md +20 -0
- package/templates/default-instance/monolith/memory/long-term/tech-debt.md +25 -0
- package/templates/default-instance/monolith/memory/working/active.md +41 -0
- package/templates/default-instance/monolith/memory/working/governance-result.md +0 -0
- package/templates/default-instance/monolith/memory/working/integrity-result.md +0 -0
- package/templates/default-instance/monolith/memory/working/story-index.md +28 -0
- package/templates/default-instance/monolith/protocols/boot/boot-sequence.md +59 -0
- package/templates/default-instance/monolith/protocols/cognition/cognitive-modes.md +90 -0
- package/templates/default-instance/monolith/protocols/cognition/dry-run.md +56 -0
- package/templates/default-instance/monolith/protocols/cognition/execution-trace-format.md +52 -0
- package/templates/default-instance/monolith/protocols/cognition/semantic-planning.md +51 -0
- package/templates/default-instance/monolith/protocols/execution/hybrid-execution.md +37 -0
- package/templates/default-instance/monolith/protocols/execution/local-llm-governance.md +42 -0
- package/templates/default-instance/monolith/protocols/governance/command-policy.md +51 -0
- package/templates/default-instance/monolith/protocols/governance/core-invariants.md +40 -0
- package/templates/default-instance/monolith/protocols/governance/memory-governance.md +54 -0
- package/templates/default-instance/monolith/protocols/governance/metadata-schema.md +62 -0
- package/templates/default-instance/monolith/protocols/governance/skills.md +53 -0
- package/templates/default-instance/monolith/protocols/governance/work-session.md +46 -0
- package/templates/default-instance/monolith/skills/INDEX.md +28 -0
- package/templates/default-instance/monolith/skills/current-status/SKILL.md +47 -0
- package/templates/default-instance/monolith/skills/finalize-story/SKILL.md +86 -0
- package/templates/default-instance/monolith/skills/global-status/SKILL.md +56 -0
- package/templates/default-instance/monolith/skills/self-improvement/SKILL.md +77 -0
- package/templates/default-instance/monolith/state.json +11 -0
- package/templates/default-instance/monolith/tests/INDEX.md +57 -0
- package/templates/default-instance/monolith/tests/scenarios/architecture-review.md +32 -0
- package/templates/default-instance/monolith/tests/scenarios/debug-failure.md +32 -0
- package/templates/default-instance/monolith/tests/scenarios/dry-run-activation.md +33 -0
- package/templates/default-instance/monolith/tests/scenarios/execution-trace-verification.md +31 -0
- package/templates/default-instance/monolith/tests/scenarios/finalize-story.md +35 -0
- package/templates/default-instance/monolith/tests/scenarios/implement-feature.md +36 -0
- package/templates/default-instance/monolith/tests/scenarios/local-llm-delegation.md +31 -0
- package/templates/default-instance/monolith/tests/scenarios/planning-request.md +32 -0
- package/templates/default-instance/monolith/tests/scenarios/sensitive-context-task.md +30 -0
- package/templates/default-instance/monolith/tests/scenarios/validator-verification.md +33 -0
- package/templates/default-instance/monolith/tests/validation/expected-behavior.md +70 -0
- package/templates/default-instance/monolith/tests/validators/INDEX.md +17 -0
- package/templates/default-instance/monolith/tests/validators/delegation-semantics.md +22 -0
- package/templates/default-instance/monolith/tests/validators/mode-consistency.md +25 -0
- package/templates/default-instance/monolith/tests/validators/privacy-routing.md +23 -0
- package/templates/default-instance/monolith/tests/validators/protocol-references.md +27 -0
- package/templates/default-instance/monolith/tests/validators/routing-integrity.md +30 -0
- package/templates/default-instance/projectroot/AGENTS.md +107 -0
- package/templates/default-instance/projectroot/monolith.config.json +32 -0
- package/templates/default-instance/projectroot/project.definition.mjs.template +41 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secure read-only HTTP transport for Mission Control (UI-001B.2, ADR-010 G2).
|
|
3
|
+
*
|
|
4
|
+
* One endpoint, `GET /api/dashboard`, serves the existing `DashboardReadModel`
|
|
5
|
+
* exactly as `readDashboardModel(projectRoot)` returns it. This module is a
|
|
6
|
+
* transport only:
|
|
7
|
+
* - it reads no file and imports no filesystem module; every byte of project
|
|
8
|
+
* data arrives through `readDashboardModel` (ADR-014 safe read);
|
|
9
|
+
* - it knows nothing about `state.json`, its schema or its physical layout, so
|
|
10
|
+
* the Core storage can change (STATE-003) without touching this layer;
|
|
11
|
+
* - the project root is fixed when the server starts and is never taken from a
|
|
12
|
+
* request (query, body, header or cookie are not read for that purpose).
|
|
13
|
+
*
|
|
14
|
+
* With `options.assets` it also serves the built UI from memory (`monolith ui`);
|
|
15
|
+
* the API route, the Host/Origin checks and the loopback bind are unchanged.
|
|
16
|
+
*
|
|
17
|
+
* Security boundary (G2): bound to 127.0.0.1 only; `Host` allowlist (loopback
|
|
18
|
+
* name + the real port, against DNS rebinding); `Origin` checked when present
|
|
19
|
+
* and never reflected; no CORS headers at all; GET only; fixed response
|
|
20
|
+
* headers; bounded response size with no partial JSON; errors are fixed codes,
|
|
21
|
+
* never exception text or paths. Loopback is NOT treated as authentication.
|
|
22
|
+
*
|
|
23
|
+
* Source failures (absent / forbidden / corrupt / unreadable) are part of the
|
|
24
|
+
* DTO (`SourceReport`) and keep their Typed Read Model semantics: they are a
|
|
25
|
+
* valid 200 response carrying `data: null` and a typed code, never project
|
|
26
|
+
* content. Threat model (ADR-013): TM-A supported with limitations, TM-B
|
|
27
|
+
* partially supported, TM-C (concurrent adversarial mutation) NOT supported;
|
|
28
|
+
* dynamic TOCTOU is not closed here, nor by Core.
|
|
29
|
+
*/
|
|
30
|
+
import { createServer } from 'http';
|
|
31
|
+
import { isAbsolute } from 'path';
|
|
32
|
+
import { readDashboardModel } from '../readmodel/index.js';
|
|
33
|
+
export const DASHBOARD_PATH = '/api/dashboard';
|
|
34
|
+
/** The only bind address; there is deliberately no option to change it. */
|
|
35
|
+
export const LOOPBACK_HOST = '127.0.0.1';
|
|
36
|
+
/**
|
|
37
|
+
* Hard ceiling for one serialized response. The Core read limits (state 16 MiB,
|
|
38
|
+
* active.md/roadmap 256 KiB) are protective ceilings of their own and can exceed
|
|
39
|
+
* it; an over-limit DTO is refused whole, never truncated.
|
|
40
|
+
*/
|
|
41
|
+
export const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
42
|
+
const ERROR_STATUS = {
|
|
43
|
+
HOST_NOT_ALLOWED: 403,
|
|
44
|
+
ORIGIN_NOT_ALLOWED: 403,
|
|
45
|
+
NOT_FOUND: 404,
|
|
46
|
+
METHOD_NOT_ALLOWED: 405,
|
|
47
|
+
RESPONSE_TOO_LARGE: 500,
|
|
48
|
+
INTERNAL_ERROR: 500,
|
|
49
|
+
};
|
|
50
|
+
const ERROR_KIND = {
|
|
51
|
+
HOST_NOT_ALLOWED: 'security',
|
|
52
|
+
ORIGIN_NOT_ALLOWED: 'security',
|
|
53
|
+
NOT_FOUND: 'request',
|
|
54
|
+
METHOD_NOT_ALLOWED: 'request',
|
|
55
|
+
RESPONSE_TOO_LARGE: 'dashboard',
|
|
56
|
+
INTERNAL_ERROR: 'internal',
|
|
57
|
+
};
|
|
58
|
+
function send(res, status, body, extra = {}) {
|
|
59
|
+
const buf = Buffer.from(body, 'utf8');
|
|
60
|
+
res.writeHead(status, {
|
|
61
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
62
|
+
'Content-Length': String(buf.length),
|
|
63
|
+
'X-Content-Type-Options': 'nosniff',
|
|
64
|
+
'Cache-Control': 'no-store',
|
|
65
|
+
'Content-Security-Policy': "default-src 'none'",
|
|
66
|
+
...extra,
|
|
67
|
+
});
|
|
68
|
+
res.end(buf);
|
|
69
|
+
}
|
|
70
|
+
/** CSP of the UI document and its assets: self-hosted code only, no framing, no form posts. */
|
|
71
|
+
const UI_CSP = "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; " +
|
|
72
|
+
"font-src 'self' data:; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'";
|
|
73
|
+
function sendAsset(res, body, contentType) {
|
|
74
|
+
res.writeHead(200, {
|
|
75
|
+
'Content-Type': contentType,
|
|
76
|
+
'Content-Length': String(body.length),
|
|
77
|
+
'X-Content-Type-Options': 'nosniff',
|
|
78
|
+
'Cache-Control': 'no-store',
|
|
79
|
+
'Content-Security-Policy': UI_CSP,
|
|
80
|
+
'Referrer-Policy': 'no-referrer',
|
|
81
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
82
|
+
});
|
|
83
|
+
res.end(body);
|
|
84
|
+
}
|
|
85
|
+
function sendError(res, code) {
|
|
86
|
+
const body = { error: { kind: ERROR_KIND[code], code } };
|
|
87
|
+
// An unread request body must not keep the connection busy.
|
|
88
|
+
const extra = { Connection: 'close' };
|
|
89
|
+
if (code === 'METHOD_NOT_ALLOWED')
|
|
90
|
+
extra.Allow = 'GET';
|
|
91
|
+
send(res, ERROR_STATUS[code], JSON.stringify(body), extra);
|
|
92
|
+
}
|
|
93
|
+
function single(h) {
|
|
94
|
+
return typeof h === 'string' ? h : undefined;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Node exposes only the first `Host` in `req.headers`, so duplicates must be
|
|
98
|
+
* counted on the raw header list (names are case-insensitive; values are
|
|
99
|
+
* ignored here and never echoed).
|
|
100
|
+
*/
|
|
101
|
+
function hostHeaderCount(rawHeaders) {
|
|
102
|
+
let count = 0;
|
|
103
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
104
|
+
if (rawHeaders[i].toLowerCase() === 'host')
|
|
105
|
+
count++;
|
|
106
|
+
}
|
|
107
|
+
return count;
|
|
108
|
+
}
|
|
109
|
+
/** Path of the request target without its query; the query is never interpreted. */
|
|
110
|
+
function pathOf(target) {
|
|
111
|
+
if (target === undefined)
|
|
112
|
+
return '';
|
|
113
|
+
const q = target.indexOf('?');
|
|
114
|
+
return q === -1 ? target : target.slice(0, q);
|
|
115
|
+
}
|
|
116
|
+
export async function startDashboardServer(options) {
|
|
117
|
+
const { projectRoot } = options;
|
|
118
|
+
if (typeof projectRoot !== 'string' || !isAbsolute(projectRoot)) {
|
|
119
|
+
throw new TypeError('projectRoot must be an absolute path');
|
|
120
|
+
}
|
|
121
|
+
const maxBytes = options.maxResponseBytes ?? MAX_RESPONSE_BYTES;
|
|
122
|
+
let allowedHosts = new Set();
|
|
123
|
+
let allowedOrigins = new Set();
|
|
124
|
+
function handle(req, res) {
|
|
125
|
+
// 1. Security preconditions, before anything about the route is revealed.
|
|
126
|
+
// Exactly one Host: a duplicate is ambiguous (proxies may pick another one).
|
|
127
|
+
const host = single(req.headers.host)?.toLowerCase();
|
|
128
|
+
if (hostHeaderCount(req.rawHeaders) !== 1 || host === undefined || !allowedHosts.has(host))
|
|
129
|
+
return sendError(res, 'HOST_NOT_ALLOWED');
|
|
130
|
+
if (req.headers.origin !== undefined && !allowedOrigins.has(single(req.headers.origin)?.toLowerCase() ?? '')) {
|
|
131
|
+
return sendError(res, 'ORIGIN_NOT_ALLOWED');
|
|
132
|
+
}
|
|
133
|
+
// 2. Route and method. Exact match only: no trailing slash, no decoding.
|
|
134
|
+
const path = pathOf(req.url);
|
|
135
|
+
if (path !== DASHBOARD_PATH) {
|
|
136
|
+
const asset = options.assets?.get(path === '/' ? '/index.html' : path);
|
|
137
|
+
if (asset === undefined)
|
|
138
|
+
return sendError(res, 'NOT_FOUND');
|
|
139
|
+
if (req.method !== 'GET')
|
|
140
|
+
return sendError(res, 'METHOD_NOT_ALLOWED');
|
|
141
|
+
return sendAsset(res, asset.body, asset.contentType);
|
|
142
|
+
}
|
|
143
|
+
if (req.method !== 'GET')
|
|
144
|
+
return sendError(res, 'METHOD_NOT_ALLOWED');
|
|
145
|
+
// 3. The DTO, whole or not at all.
|
|
146
|
+
let body;
|
|
147
|
+
try {
|
|
148
|
+
body = JSON.stringify(readDashboardModel(projectRoot));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return sendError(res, 'INTERNAL_ERROR');
|
|
152
|
+
}
|
|
153
|
+
if (Buffer.byteLength(body, 'utf8') > maxBytes)
|
|
154
|
+
return sendError(res, 'RESPONSE_TOO_LARGE');
|
|
155
|
+
send(res, 200, body);
|
|
156
|
+
}
|
|
157
|
+
const server = createServer((req, res) => {
|
|
158
|
+
try {
|
|
159
|
+
handle(req, res);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
if (!res.headersSent)
|
|
163
|
+
sendError(res, 'INTERNAL_ERROR');
|
|
164
|
+
else
|
|
165
|
+
res.destroy();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
server.requestTimeout = 10_000;
|
|
169
|
+
server.headersTimeout = 5_000;
|
|
170
|
+
const port = await new Promise((resolve, reject) => {
|
|
171
|
+
server.once('error', reject);
|
|
172
|
+
server.listen(options.port ?? 0, LOOPBACK_HOST, () => {
|
|
173
|
+
server.off('error', reject);
|
|
174
|
+
const addr = server.address();
|
|
175
|
+
if (addr === null || typeof addr === 'string')
|
|
176
|
+
reject(new Error('unexpected listen address'));
|
|
177
|
+
else
|
|
178
|
+
resolve(addr.port);
|
|
179
|
+
});
|
|
180
|
+
}).catch((err) => {
|
|
181
|
+
server.close();
|
|
182
|
+
throw err;
|
|
183
|
+
});
|
|
184
|
+
allowedHosts = new Set([`${LOOPBACK_HOST}:${port}`, `localhost:${port}`]);
|
|
185
|
+
allowedOrigins = new Set([`http://${LOOPBACK_HOST}:${port}`, `http://localhost:${port}`]);
|
|
186
|
+
return {
|
|
187
|
+
host: LOOPBACK_HOST,
|
|
188
|
+
port,
|
|
189
|
+
url: `http://${LOOPBACK_HOST}:${port}`,
|
|
190
|
+
close: () => new Promise((resolve, reject) => {
|
|
191
|
+
server.close((err) => (err ? reject(err) : resolve()));
|
|
192
|
+
server.closeAllConnections();
|
|
193
|
+
}),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for the built Mission Control UI (`dist/ui`), used by `monolith ui`.
|
|
3
|
+
*
|
|
4
|
+
* The HTTP transport (`server.ts`) imports no filesystem module on purpose, so
|
|
5
|
+
* the static files are read here, once, at startup, into memory. The server
|
|
6
|
+
* then serves them by exact key: a request path is never joined to a directory,
|
|
7
|
+
* so path traversal has nothing to traverse.
|
|
8
|
+
*
|
|
9
|
+
* What is accepted: regular files only (no symlink, no special file, one link),
|
|
10
|
+
* a fixed extension allowlist, a bounded directory depth, file count and size.
|
|
11
|
+
* Anything else is skipped, except that a missing or unsafe `index.html` is an
|
|
12
|
+
* error. Assets are read once; later changes on disk are not picked up.
|
|
13
|
+
*/
|
|
14
|
+
import type { UiAssets } from './server.js';
|
|
15
|
+
export type UiAssetsErrorCode = 'UI_BUILD_MISSING' | 'UI_BUILD_UNSAFE' | 'UI_BUILD_TOO_LARGE';
|
|
16
|
+
export declare class UiAssetsError extends Error {
|
|
17
|
+
readonly code: UiAssetsErrorCode;
|
|
18
|
+
constructor(code: UiAssetsErrorCode, message: string);
|
|
19
|
+
}
|
|
20
|
+
/** Reads `dir` (the built UI) into memory. Throws `UiAssetsError` if there is no usable `index.html`. */
|
|
21
|
+
export declare function loadUiAssets(dir: string): UiAssets;
|
|
22
|
+
//# sourceMappingURL=ui-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-assets.d.ts","sourceRoot":"","sources":["../../src/http/ui-assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAE9F,qBAAa,aAAc,SAAQ,KAAK;IAC1B,QAAQ,CAAC,IAAI,EAAE,iBAAiB;gBAAvB,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM;CAI9D;AAiCD,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAwClD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for the built Mission Control UI (`dist/ui`), used by `monolith ui`.
|
|
3
|
+
*
|
|
4
|
+
* The HTTP transport (`server.ts`) imports no filesystem module on purpose, so
|
|
5
|
+
* the static files are read here, once, at startup, into memory. The server
|
|
6
|
+
* then serves them by exact key: a request path is never joined to a directory,
|
|
7
|
+
* so path traversal has nothing to traverse.
|
|
8
|
+
*
|
|
9
|
+
* What is accepted: regular files only (no symlink, no special file, one link),
|
|
10
|
+
* a fixed extension allowlist, a bounded directory depth, file count and size.
|
|
11
|
+
* Anything else is skipped, except that a missing or unsafe `index.html` is an
|
|
12
|
+
* error. Assets are read once; later changes on disk are not picked up.
|
|
13
|
+
*/
|
|
14
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, readdirSync } from 'fs';
|
|
15
|
+
import { join, extname } from 'path';
|
|
16
|
+
export class UiAssetsError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.name = 'UiAssetsError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const CONTENT_TYPES = {
|
|
25
|
+
'.html': 'text/html; charset=utf-8',
|
|
26
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
27
|
+
'.css': 'text/css; charset=utf-8',
|
|
28
|
+
'.webp': 'image/webp',
|
|
29
|
+
'.png': 'image/png',
|
|
30
|
+
'.svg': 'image/svg+xml',
|
|
31
|
+
'.ico': 'image/x-icon',
|
|
32
|
+
'.woff2': 'font/woff2',
|
|
33
|
+
};
|
|
34
|
+
const MAX_DEPTH = 3;
|
|
35
|
+
const MAX_FILES = 200;
|
|
36
|
+
const MAX_FILE_BYTES = 8 * 1024 * 1024;
|
|
37
|
+
const MAX_TOTAL_BYTES = 32 * 1024 * 1024;
|
|
38
|
+
function readRegular(abs) {
|
|
39
|
+
// lstat first so a symlink is refused rather than followed.
|
|
40
|
+
const st = lstatSync(abs);
|
|
41
|
+
if (!st.isFile() || st.nlink !== 1)
|
|
42
|
+
return null;
|
|
43
|
+
if (st.size > MAX_FILE_BYTES)
|
|
44
|
+
throw new UiAssetsError('UI_BUILD_TOO_LARGE', `UI build file is larger than ${MAX_FILE_BYTES} bytes.`);
|
|
45
|
+
const fd = openSync(abs, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
46
|
+
try {
|
|
47
|
+
const fst = fstatSync(fd);
|
|
48
|
+
if (!fst.isFile() || fst.dev !== st.dev || fst.ino !== st.ino)
|
|
49
|
+
return null;
|
|
50
|
+
return readFileSync(fd);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
closeSync(fd);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Reads `dir` (the built UI) into memory. Throws `UiAssetsError` if there is no usable `index.html`. */
|
|
57
|
+
export function loadUiAssets(dir) {
|
|
58
|
+
const assets = new Map();
|
|
59
|
+
let total = 0;
|
|
60
|
+
const walk = (abs, rel, depth) => {
|
|
61
|
+
for (const name of readdirSync(abs).sort()) {
|
|
62
|
+
const childAbs = join(abs, name);
|
|
63
|
+
const childRel = `${rel}/${name}`;
|
|
64
|
+
const st = lstatSync(childAbs);
|
|
65
|
+
if (st.isDirectory()) {
|
|
66
|
+
if (depth < MAX_DEPTH)
|
|
67
|
+
walk(childAbs, childRel, depth + 1);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const contentType = CONTENT_TYPES[extname(name).toLowerCase()];
|
|
71
|
+
if (contentType === undefined)
|
|
72
|
+
continue;
|
|
73
|
+
const body = readRegular(childAbs);
|
|
74
|
+
if (body === null)
|
|
75
|
+
continue;
|
|
76
|
+
total += body.length;
|
|
77
|
+
if (assets.size >= MAX_FILES || total > MAX_TOTAL_BYTES) {
|
|
78
|
+
throw new UiAssetsError('UI_BUILD_TOO_LARGE', 'UI build has too many or too large files.');
|
|
79
|
+
}
|
|
80
|
+
assets.set(childRel, { body, contentType });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
if (!lstatSync(dir).isDirectory())
|
|
85
|
+
throw new UiAssetsError('UI_BUILD_MISSING', 'UI build directory is not a directory.');
|
|
86
|
+
walk(dir, '', 0);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (err instanceof UiAssetsError)
|
|
90
|
+
throw err;
|
|
91
|
+
if (err.code === 'ENOENT') {
|
|
92
|
+
throw new UiAssetsError('UI_BUILD_MISSING', 'UI build directory does not exist.');
|
|
93
|
+
}
|
|
94
|
+
throw new UiAssetsError('UI_BUILD_UNSAFE', 'UI build directory could not be read safely.');
|
|
95
|
+
}
|
|
96
|
+
if (!assets.has('/index.html')) {
|
|
97
|
+
throw new UiAssetsError('UI_BUILD_MISSING', 'UI build has no index.html.');
|
|
98
|
+
}
|
|
99
|
+
return assets;
|
|
100
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latysh-development/monolith — Public API surface
|
|
3
|
+
*
|
|
4
|
+
* This file is the package entrypoint. Exports grow here as Kernel modules
|
|
5
|
+
* are extracted from project instances into this package.
|
|
6
|
+
*
|
|
7
|
+
* Current state: Phase 6 — validate implemented; Scriptorium (Story 1.2) and
|
|
8
|
+
* Explicit Relationship Graph (Story 1.3) integrated.
|
|
9
|
+
* See Phase 7+ roadmap for Kernel extraction.
|
|
10
|
+
*
|
|
11
|
+
* Webway (the frequency-based "meaning linker" prototype from Story 1.1) was
|
|
12
|
+
* extracted into its own repository: https://github.com/Demion-L/webway —
|
|
13
|
+
* it was an independent research track with zero runtime coupling to
|
|
14
|
+
* Scriptorium/Graph, see docs/webway-v0.md for the historical record.
|
|
15
|
+
*/
|
|
16
|
+
export type { ProjectDefinition } from './types/project-definition.js';
|
|
17
|
+
export type { GateCheckResult } from './types/enforcement.js';
|
|
18
|
+
export type { VerificationContext, VerificationReport } from './types/integrity.js';
|
|
19
|
+
export type { ProjectConfig, InitOptions } from './init/types.js';
|
|
20
|
+
export { MONOLITH_VERSION } from './version.js';
|
|
21
|
+
export { runInit } from './init/index.js';
|
|
22
|
+
export type { ScriptoriumInput, ScriptoriumResult, ConceptCandidate, RelationshipCandidate, Evidence, SourceReference, ScriptoriumDiagnostic, ConceptSource, EvidenceSource, HeadingLevel, ObjectDeclaration, DeclaredObjectKind, } from './scriptorium/index.js';
|
|
23
|
+
export { compileMarkdownArtifact, isStructuralHeadingNoise } from './scriptorium/index.js';
|
|
24
|
+
export type { GraphNode, GraphEdge, GraphDiagnostic, ExplicitRelationshipGraph, UnresolvedReference, IdentityConflict, KnowledgeObject, KnowledgeObjectKind, Resolution, UnresolvedResolution, ObjectIndex, } from './graph/index.js';
|
|
25
|
+
export { buildGraph, buildObjectIndex, resolveRef, makeRef, parseRef, isValidIdentifier } from './graph/index.js';
|
|
26
|
+
export type { CoordinatoriumState, Mission, MissionStatus, MissionResult, CoordinatoriumErrorCode, StartMissionInput, FinishMissionInput, StateWriteTarget, StateReadTarget, } from './coordinatorium/index.js';
|
|
27
|
+
export { createInitialState, CoordinatoriumError, StateCorruptedError, StateSchemaError, LockTimeoutError, MissionNotFoundError, InvalidTransitionError, ValidationError, readState, mutateState, projectTarget, trustedDirectoryTarget, startMission, listMissions, getMission, finishMission, } from './coordinatorium/index.js';
|
|
28
|
+
export { SafeWriteError } from './root/index.js';
|
|
29
|
+
export type { WriteErrorCode, WriteWarning, WriteWarningCode, PublicationState } from './root/index.js';
|
|
30
|
+
export * as durable from './durable/index.js';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACpF,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAG3F,YAAY,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,oBAAoB,EACpB,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIlH,YAAY,EACV,mBAAmB,EACnB,OAAO,EACP,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,SAAS,EACT,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,aAAa,GACd,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKxG,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @latysh-development/monolith — Public API surface
|
|
3
|
+
*
|
|
4
|
+
* This file is the package entrypoint. Exports grow here as Kernel modules
|
|
5
|
+
* are extracted from project instances into this package.
|
|
6
|
+
*
|
|
7
|
+
* Current state: Phase 6 — validate implemented; Scriptorium (Story 1.2) and
|
|
8
|
+
* Explicit Relationship Graph (Story 1.3) integrated.
|
|
9
|
+
* See Phase 7+ roadmap for Kernel extraction.
|
|
10
|
+
*
|
|
11
|
+
* Webway (the frequency-based "meaning linker" prototype from Story 1.1) was
|
|
12
|
+
* extracted into its own repository: https://github.com/Demion-L/webway —
|
|
13
|
+
* it was an independent research track with zero runtime coupling to
|
|
14
|
+
* Scriptorium/Graph, see docs/webway-v0.md for the historical record.
|
|
15
|
+
*/
|
|
16
|
+
export { MONOLITH_VERSION } from './version.js';
|
|
17
|
+
export { runInit } from './init/index.js';
|
|
18
|
+
export { compileMarkdownArtifact, isStructuralHeadingNoise } from './scriptorium/index.js';
|
|
19
|
+
export { buildGraph, buildObjectIndex, resolveRef, makeRef, parseRef, isValidIdentifier } from './graph/index.js';
|
|
20
|
+
export { createInitialState, CoordinatoriumError, StateCorruptedError, StateSchemaError, LockTimeoutError, MissionNotFoundError, InvalidTransitionError, ValidationError, readState, mutateState, projectTarget, trustedDirectoryTarget, startMission, listMissions, getMission, finishMission, } from './coordinatorium/index.js';
|
|
21
|
+
// Safe writes — explicit write scope and publication states (SEC-001B.2, ADR-012)
|
|
22
|
+
export { SafeWriteError } from './root/index.js';
|
|
23
|
+
// Durable State — domain-neutral, crash-safe execution record for long-running agentic tasks (ADR-017).
|
|
24
|
+
// Namespaced: its error taxonomy deliberately shares names (e.g. ValidationError) with Coordinatorium's.
|
|
25
|
+
// EXPERIMENTAL. Security acceptance pending (see AGENTS.md → Durable State); the API may change in any alpha.
|
|
26
|
+
export * as durable from './durable/index.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InitOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when `monolith init` would overwrite existing tracked files.
|
|
4
|
+
* Raised strictly before any write — see planScaffoldConflicts. Carries a
|
|
5
|
+
* non-zero exit via the CLI's top-level main().catch handler.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InitConflictError extends Error {
|
|
8
|
+
readonly conflicts: string[];
|
|
9
|
+
constructor(conflicts: string[]);
|
|
10
|
+
}
|
|
11
|
+
export declare function runInit(options?: InitOptions): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/init/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;gBAEjB,SAAS,EAAE,MAAM,EAAE;CAmBhC;AAED,wBAAsB,OAAO,CAAC,OAAO,GAAE,WAA0C,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DhG"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { promptProjectConfig } from './prompts.js';
|
|
4
|
+
import { scaffoldInstance, planScaffoldConflicts } from './scaffold.js';
|
|
5
|
+
import { reportWriteWarning } from '../root/index.js';
|
|
6
|
+
const CONFLICT_LIST_LIMIT = 20;
|
|
7
|
+
/**
|
|
8
|
+
* Thrown when `monolith init` would overwrite existing tracked files.
|
|
9
|
+
* Raised strictly before any write — see planScaffoldConflicts. Carries a
|
|
10
|
+
* non-zero exit via the CLI's top-level main().catch handler.
|
|
11
|
+
*/
|
|
12
|
+
export class InitConflictError extends Error {
|
|
13
|
+
conflicts;
|
|
14
|
+
constructor(conflicts) {
|
|
15
|
+
const shown = conflicts.slice(0, CONFLICT_LIST_LIMIT);
|
|
16
|
+
const more = conflicts.length - shown.length;
|
|
17
|
+
const list = shown.map((c) => ` - ${c}`).join('\n');
|
|
18
|
+
super(`Refusing to initialize: ${conflicts.length} existing or unsafe path(s) (already present, or a symlink / special file that must not be written through):\n` +
|
|
19
|
+
`${list}\n` +
|
|
20
|
+
(more > 0 ? ` ...and ${more} more\n` : '') +
|
|
21
|
+
'\n' +
|
|
22
|
+
' monolith init always scaffolds the current working directory and never\n' +
|
|
23
|
+
' overwrites existing tracked files (re-running it is not an upgrade/force\n' +
|
|
24
|
+
' mechanism). --yes only skips interactive prompts for a clean directory;\n' +
|
|
25
|
+
' it does not authorize overwriting existing data.\n' +
|
|
26
|
+
' Remove, rename, or back up the conflicting file(s) yourself, or run init\n' +
|
|
27
|
+
' in an empty directory, then re-run.');
|
|
28
|
+
this.name = 'InitConflictError';
|
|
29
|
+
this.conflicts = conflicts;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function runInit(options = { targetDir: process.cwd() }) {
|
|
33
|
+
const targetDir = resolve(options.targetDir);
|
|
34
|
+
console.log(' Initializing MONOLITH instance...');
|
|
35
|
+
console.log('');
|
|
36
|
+
let config;
|
|
37
|
+
if (options.yes) {
|
|
38
|
+
// Non-interactive: use all defaults
|
|
39
|
+
const { basename } = await import('path');
|
|
40
|
+
config = {
|
|
41
|
+
projectName: basename(targetDir),
|
|
42
|
+
language: 'typescript',
|
|
43
|
+
packageManager: 'pnpm',
|
|
44
|
+
aiTool: 'claude',
|
|
45
|
+
finalizationProtocol: 'finalize-story',
|
|
46
|
+
protocols: ['finalize-story', 'failure-memory-logging', 'governance-evaluation', 'integrity-verification'],
|
|
47
|
+
monolithRoot: '.monolith',
|
|
48
|
+
};
|
|
49
|
+
console.log(` Project: ${config.projectName} (defaults applied)`);
|
|
50
|
+
console.log('');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
config = await promptProjectConfig();
|
|
54
|
+
}
|
|
55
|
+
// Preflight: must run — and find zero conflicts — before any write, so a
|
|
56
|
+
// conflict is never discovered after half the instance has already been
|
|
57
|
+
// scaffolded (see LESSON-2026-0006 / TD-007).
|
|
58
|
+
const conflicts = planScaffoldConflicts(targetDir, config);
|
|
59
|
+
if (conflicts.length > 0) {
|
|
60
|
+
throw new InitConflictError(conflicts);
|
|
61
|
+
}
|
|
62
|
+
console.log(' Scaffolding instance...');
|
|
63
|
+
console.log('');
|
|
64
|
+
const result = await scaffoldInstance(targetDir, config);
|
|
65
|
+
for (const w of result.warnings)
|
|
66
|
+
reportWriteWarning(w);
|
|
67
|
+
console.log('');
|
|
68
|
+
console.log(' ✅ MONOLITH instance initialized!');
|
|
69
|
+
console.log('');
|
|
70
|
+
console.log(` Project: ${config.projectName}`);
|
|
71
|
+
console.log(` Root: ${config.monolithRoot}/`);
|
|
72
|
+
console.log(` Files created: ${result.filesCreated}`);
|
|
73
|
+
console.log('');
|
|
74
|
+
const instructionFileMap = {
|
|
75
|
+
claude: 'CLAUDE.md',
|
|
76
|
+
cursor: '.cursorrules',
|
|
77
|
+
windsurf: '.windsurfrules',
|
|
78
|
+
};
|
|
79
|
+
const instructionFile = instructionFileMap[config.aiTool] ?? 'AGENTS.md';
|
|
80
|
+
console.log(` AI tool: ${config.aiTool} → ${instructionFile}`);
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log(' Next steps:');
|
|
83
|
+
console.log(` 1. Edit ${instructionFile} — verify skill triggers and paths`);
|
|
84
|
+
console.log(' 2. Edit AGENTS.md — add project description');
|
|
85
|
+
console.log(` 3. Edit ${config.monolithRoot}/context/maps/project-map.md — describe your structure`);
|
|
86
|
+
console.log(` 4. Edit ${config.monolithRoot}/context/maps/roadmap-index.md — add your phases`);
|
|
87
|
+
console.log(` 5. Edit ${config.monolithRoot}/protocols/governance/core-invariants.md — set Current Focus`);
|
|
88
|
+
console.log(` 6. Start first story: edit ${config.monolithRoot}/memory/working/active.md`);
|
|
89
|
+
console.log('');
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/init/prompts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+BhD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CAuClE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { createInterface } from 'readline';
|
|
3
|
+
import { basename } from 'path';
|
|
4
|
+
function createPrompter() {
|
|
5
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
6
|
+
const ask = (question, defaultValue) => new Promise((resolve) => {
|
|
7
|
+
const hint = defaultValue ? ` (${defaultValue})` : '';
|
|
8
|
+
rl.question(` ${question}${hint}: `, (answer) => {
|
|
9
|
+
resolve(answer.trim() || defaultValue || '');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
const askChoice = (question, choices, defaultChoice) => new Promise((resolve) => {
|
|
13
|
+
const choiceStr = choices.map((c) => (c === defaultChoice ? `[${c}]` : c)).join(' | ');
|
|
14
|
+
rl.question(` ${question} (${choiceStr}): `, (answer) => {
|
|
15
|
+
const trimmed = answer.trim().toLowerCase();
|
|
16
|
+
if (!trimmed)
|
|
17
|
+
return resolve(defaultChoice);
|
|
18
|
+
const match = choices.find((c) => c.toLowerCase() === trimmed);
|
|
19
|
+
resolve(match ?? defaultChoice);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
return { ask, askChoice, close: () => rl.close() };
|
|
23
|
+
}
|
|
24
|
+
export async function promptProjectConfig() {
|
|
25
|
+
const p = createPrompter();
|
|
26
|
+
console.log('');
|
|
27
|
+
const projectName = await p.ask('Project name', basename(process.cwd()));
|
|
28
|
+
const language = await p.askChoice('Primary language', ['typescript', 'javascript', 'python', 'other'], 'typescript');
|
|
29
|
+
const packageManager = await p.askChoice('Package manager', ['pnpm', 'npm', 'yarn', 'other'], 'pnpm');
|
|
30
|
+
const aiTool = await p.askChoice('AI assistant tool', ['claude', 'cursor', 'windsurf', 'other'], 'claude');
|
|
31
|
+
p.close();
|
|
32
|
+
console.log('');
|
|
33
|
+
return {
|
|
34
|
+
projectName,
|
|
35
|
+
language,
|
|
36
|
+
packageManager,
|
|
37
|
+
aiTool,
|
|
38
|
+
finalizationProtocol: 'finalize-story',
|
|
39
|
+
protocols: [
|
|
40
|
+
'finalize-story',
|
|
41
|
+
'failure-memory-logging',
|
|
42
|
+
'governance-evaluation',
|
|
43
|
+
'integrity-verification',
|
|
44
|
+
],
|
|
45
|
+
monolithRoot: '.monolith',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProjectConfig } from './types.js';
|
|
2
|
+
import { type WriteWarning } from '../root/index.js';
|
|
3
|
+
export interface ScaffoldResult {
|
|
4
|
+
filesCreated: number;
|
|
5
|
+
dirsCreated: string[];
|
|
6
|
+
/** Non-fatal write findings (e.g. best-effort platform). */
|
|
7
|
+
warnings: WriteWarning[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Preflight: compute every tracked template target path scaffoldInstance
|
|
11
|
+
* would write, and return the ones that already exist on disk — or that cannot
|
|
12
|
+
* be written safely (a symlink, including a dangling one, at the target or in
|
|
13
|
+
* a parent component; a FIFO or other special file). Must be called — and
|
|
14
|
+
* found empty — before scaffoldInstance runs, so a conflict is caught before
|
|
15
|
+
* any file is written (no half-scaffolded instance). This is advice for a
|
|
16
|
+
* clean error message; the exclusive creation in scaffoldInstance is the
|
|
17
|
+
* authoritative check.
|
|
18
|
+
*
|
|
19
|
+
* `state.json` is intentionally excluded when it is a regular file:
|
|
20
|
+
* scaffoldInstance never overwrites it (mutable Coordinatorium runtime data,
|
|
21
|
+
* ADR-008), so its presence is not a conflict. A symlink there still is.
|
|
22
|
+
*/
|
|
23
|
+
export declare function planScaffoldConflicts(targetDir: string, config: ProjectConfig): string[];
|
|
24
|
+
export declare function scaffoldInstance(targetDir: string, config: ProjectConfig): Promise<ScaffoldResult>;
|
|
25
|
+
//# sourceMappingURL=scaffold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/init/scaffold.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAQL,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AA+H1B,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAqCxF;AAED,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,cAAc,CAAC,CA4EzB"}
|