@latysh-development/monolith 0.0.0-stage → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +179 -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 +342 -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 +12 -0
- package/dist/brief/constants.d.ts.map +1 -0
- package/dist/brief/constants.js +11 -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 +67 -0
- package/dist/brief/render.d.ts.map +1 -0
- package/dist/brief/render.js +458 -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 +126 -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 +199 -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/discovery/compose.d.ts +28 -0
- package/dist/discovery/compose.d.ts.map +1 -0
- package/dist/discovery/compose.js +159 -0
- package/dist/discovery/contracts.d.ts +211 -0
- package/dist/discovery/contracts.d.ts.map +1 -0
- package/dist/discovery/contracts.js +555 -0
- package/dist/discovery/docs.d.ts +278 -0
- package/dist/discovery/docs.d.ts.map +1 -0
- package/dist/discovery/docs.js +1182 -0
- package/dist/discovery/facts.d.ts +49 -0
- package/dist/discovery/facts.d.ts.map +1 -0
- package/dist/discovery/facts.js +541 -0
- package/dist/discovery/index.d.ts +8 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +9 -0
- package/dist/discovery/orchestrate.d.ts +35 -0
- package/dist/discovery/orchestrate.d.ts.map +1 -0
- package/dist/discovery/orchestrate.js +32 -0
- package/dist/discovery/render.d.ts +36 -0
- package/dist/discovery/render.d.ts.map +1 -0
- package/dist/discovery/render.js +278 -0
- package/dist/discovery/traverse.d.ts +197 -0
- package/dist/discovery/traverse.d.ts.map +1 -0
- package/dist/discovery/traverse.js +510 -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 +192 -0
- package/dist/durable/errors.d.ts.map +1 -0
- package/dist/durable/errors.js +323 -0
- package/dist/durable/fs-store.d.ts +254 -0
- package/dist/durable/fs-store.d.ts.map +1 -0
- package/dist/durable/fs-store.js +1493 -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 +34 -0
- package/dist/durable/prune-check.d.ts.map +1 -0
- package/dist/durable/prune-check.js +72 -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 +499 -0
- package/dist/durable/runtime.d.ts.map +1 -0
- package/dist/durable/runtime.js +1288 -0
- package/dist/durable/seams.d.ts +44 -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/ideas/cli.d.ts +33 -0
- package/dist/ideas/cli.d.ts.map +1 -0
- package/dist/ideas/cli.js +158 -0
- package/dist/ideas/format.d.ts +38 -0
- package/dist/ideas/format.d.ts.map +1 -0
- package/dist/ideas/format.js +194 -0
- package/dist/ideas/index.d.ts +6 -0
- package/dist/ideas/index.d.ts.map +1 -0
- package/dist/ideas/index.js +3 -0
- package/dist/ideas/store.d.ts +55 -0
- package/dist/ideas/store.d.ts.map +1 -0
- package/dist/ideas/store.js +262 -0
- package/dist/ideas/types.d.ts +54 -0
- package/dist/ideas/types.d.ts.map +1 -0
- package/dist/ideas/types.js +26 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -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 +29 -0
- package/dist/init/scaffold.d.ts.map +1 -0
- package/dist/init/scaffold.js +208 -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/managed/index.d.ts +73 -0
- package/dist/managed/index.d.ts.map +1 -0
- package/dist/managed/index.js +222 -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 +186 -0
- package/dist/root/index.d.ts.map +1 -0
- package/dist/root/index.js +430 -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/update/cli.d.ts +8 -0
- package/dist/update/cli.d.ts.map +1 -0
- package/dist/update/cli.js +115 -0
- package/dist/update/index.d.ts +78 -0
- package/dist/update/index.d.ts.map +1 -0
- package/dist/update/index.js +285 -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 +59 -0
- package/templates/default-instance/instruction/.windsurfrules +59 -0
- package/templates/default-instance/instruction/CLAUDE.md +57 -0
- package/templates/default-instance/managed/agent.md +20 -0
- package/templates/default-instance/managed/bootstrap.md +7 -0
- package/templates/default-instance/managed/index-idea.md +5 -0
- package/templates/default-instance/managed/routing-idea.md +14 -0
- package/templates/default-instance/monolith/AGENT.md +1 -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 +151 -0
- package/templates/default-instance/monolith/context/maps/semantic-map.md +75 -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 +32 -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/idea-capture/SKILL.md +157 -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 +111 -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,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem `EventStore`.
|
|
3
|
+
*
|
|
4
|
+
* Layout under the store directory:
|
|
5
|
+
*
|
|
6
|
+
* tasks/<taskId>/events/<seq,9 digits>.json one canonical event, immutable
|
|
7
|
+
* tasks/<taskId>/segments/S<from>-<to>.jsonl packed, verified events (compaction)
|
|
8
|
+
* tasks/<taskId>/prune-<n>.prepare.json prune decision register (ADR-019): one attempt per file pair,
|
|
9
|
+
* tasks/<taskId>/prune-<n>.decision.json create-only, never deleted, never rewritten
|
|
10
|
+
* tasks/<taskId>/tombstone.json published from the `commit` record of the register
|
|
11
|
+
* durable-protocol.json version marker; created only by `initializeProtocol()`
|
|
12
|
+
*
|
|
13
|
+
* Concurrency needs no lock file. The one linearizable primitive is "create
|
|
14
|
+
* `<seq>.json` if it does not exist" — `createFile` of the safe-write
|
|
15
|
+
* primitive (temp file, fsync, `link()`, ADR-012). Of N writers racing for the
|
|
16
|
+
* same slot exactly one wins; the others see `conflict`, re-read and retry.
|
|
17
|
+
* There is no owner to declare dead, so none of the stale-lock failure modes
|
|
18
|
+
* (PID reuse across namespaces, wedged lock after a crash; ADR-015) exist.
|
|
19
|
+
*
|
|
20
|
+
* Crash behaviour:
|
|
21
|
+
* - before `link()` : nothing is visible; the temp file is a stranger.
|
|
22
|
+
* - between `link()`/`unlink` : the event is complete and visible, but the file
|
|
23
|
+
* has two names (`nlink == 2`). The strict reader of ADR-014 refuses such a
|
|
24
|
+
* file, which would wedge the task for good. Here that state is *provable
|
|
25
|
+
* residue* — the second name is `<file>.tmp.<pid>.<rand>` with the same
|
|
26
|
+
* dev/ino — and the reader removes exactly that name and re-reads. Any
|
|
27
|
+
* other second link stays a hard `StoreSecurityError`.
|
|
28
|
+
* - compaction / prune : ordered so that every prefix of the steps is a
|
|
29
|
+
* consistent state (segment before unlink, tombstone before removal).
|
|
30
|
+
*
|
|
31
|
+
* Out of scope (same as the rest of MONOLITH, ADR-013): a local adversary that
|
|
32
|
+
* swaps directories concurrently (TM-C), NFS/SMB, Windows.
|
|
33
|
+
*/
|
|
34
|
+
import { StoreIoError } from './errors.js';
|
|
35
|
+
import { type DecisionBy, type PruneOutcome, type PruneState } from './types.js';
|
|
36
|
+
import { type WriteWarning } from '../root/index.js';
|
|
37
|
+
import type { AppendOutcome, CompactionResult, EventStore, LogRead, TaskEvent, Tombstone } from './types.js';
|
|
38
|
+
export type FsStoreTarget = {
|
|
39
|
+
scope: 'project';
|
|
40
|
+
projectRoot: string;
|
|
41
|
+
dir: string;
|
|
42
|
+
} | {
|
|
43
|
+
scope: 'trusted-directory';
|
|
44
|
+
dir: string;
|
|
45
|
+
};
|
|
46
|
+
export interface FsStoreOptions {
|
|
47
|
+
target: FsStoreTarget;
|
|
48
|
+
/** Receives non-fatal findings of the write primitive (e.g. directory fsync unsupported). */
|
|
49
|
+
onWarning?: (w: WriteWarning) => void;
|
|
50
|
+
/** `'full'` (default) fsyncs file and directory; `'file'` only the file. */
|
|
51
|
+
durability?: 'full' | 'file';
|
|
52
|
+
}
|
|
53
|
+
/** Packed segments stay well below this; it is the reader's ceiling. */
|
|
54
|
+
export declare const MAX_SEGMENT_BYTES: number;
|
|
55
|
+
export declare class AppendOutcomeUnknownError extends StoreIoError {
|
|
56
|
+
readonly taskId: string;
|
|
57
|
+
readonly seq: number;
|
|
58
|
+
constructor(taskId: string, seq: number, cause?: unknown);
|
|
59
|
+
}
|
|
60
|
+
/** What the version marker says about the store (Design A, sections 13 and 46.5). */
|
|
61
|
+
export type ProtocolStatus =
|
|
62
|
+
/** `durable-protocol.json` is present and understood: the store may be written. */
|
|
63
|
+
{
|
|
64
|
+
mode: 'ready';
|
|
65
|
+
version: 2;
|
|
66
|
+
}
|
|
67
|
+
/** No marker: read-only diagnostics. Nothing is created, nothing is migrated. */
|
|
68
|
+
| {
|
|
69
|
+
mode: 'diagnostic';
|
|
70
|
+
reason: 'uninitialized';
|
|
71
|
+
tasksPresent: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** A marker this build does not understand (a newer version, or damaged): the store is not opened as compatible. */
|
|
74
|
+
| {
|
|
75
|
+
mode: 'incompatible';
|
|
76
|
+
reason: 'unsupported-version' | 'invalid-marker';
|
|
77
|
+
};
|
|
78
|
+
export declare class FsEventStore implements EventStore {
|
|
79
|
+
private readonly root;
|
|
80
|
+
private readonly boundaryDir;
|
|
81
|
+
private boundaryCache;
|
|
82
|
+
private readonly opts;
|
|
83
|
+
/** True once a valid marker was seen. Only then may a read repair anything (it is a mutation). Never reset: the marker is never removed. */
|
|
84
|
+
private ready;
|
|
85
|
+
private readonly maxAttempts;
|
|
86
|
+
private readonly seams;
|
|
87
|
+
constructor(opts: FsStoreOptions);
|
|
88
|
+
/**
|
|
89
|
+
* The trust boundary. In `trusted-directory` scope the directory is the boundary and is created on the
|
|
90
|
+
* first write if missing (same contract as the state keeper); a read of a store that does not exist yet
|
|
91
|
+
* simply finds nothing. In `project` scope the project root must already exist.
|
|
92
|
+
*/
|
|
93
|
+
private boundaryFor;
|
|
94
|
+
private taskDir;
|
|
95
|
+
private eventsDir;
|
|
96
|
+
private segmentsDir;
|
|
97
|
+
private refsDir;
|
|
98
|
+
private wrapSafe;
|
|
99
|
+
private mapWriteError;
|
|
100
|
+
private markerRead;
|
|
101
|
+
private hasTasks;
|
|
102
|
+
/**
|
|
103
|
+
* What this store may be used for. Pure observation: it creates nothing and repairs nothing. A store with no marker is
|
|
104
|
+
* `diagnostic` (empty or not): reads work, every mutation is refused until the operator calls `initializeProtocol()`.
|
|
105
|
+
*/
|
|
106
|
+
protocolStatus(): Promise<ProtocolStatus>;
|
|
107
|
+
/**
|
|
108
|
+
* Explicit operator action (Design A section 46.5, ADR-018 D3): publish `durable-protocol.json` (`{"v":2}`, create-only)
|
|
109
|
+
* in an EMPTY store, with every runtime of an older version stopped. It refuses a store that holds tasks (that needs the
|
|
110
|
+
* migration decision of the operator, not a bootstrap), refuses a marker of another version, and is a no-op when a valid
|
|
111
|
+
* marker is already there. Opening a store never does this.
|
|
112
|
+
*/
|
|
113
|
+
initializeProtocol(): Promise<'initialized' | 'already-initialized'>;
|
|
114
|
+
/** The same operator action as `initializeProtocol`, for scripts and tests that are not async. */
|
|
115
|
+
initializeProtocolSync(): 'initialized' | 'already-initialized';
|
|
116
|
+
/** Called first by every public method. A write needs a valid marker; a read needs the marker to be absent or valid. */
|
|
117
|
+
private gate;
|
|
118
|
+
/** Verified directory (no symlink below the boundary) or `null` if it does not exist. */
|
|
119
|
+
private existingDir;
|
|
120
|
+
private listDir;
|
|
121
|
+
/**
|
|
122
|
+
* The second name of a freshly published file, if (and only if) it is
|
|
123
|
+
* provably this file's staging name: `<name>.tmp.<pid>.<rand>` in the same
|
|
124
|
+
* directory with the same dev/ino. Returns the removed name or `null`.
|
|
125
|
+
* Removing it is a mutation: a store without a valid marker (diagnostics only) never does it.
|
|
126
|
+
*/
|
|
127
|
+
private repairResidue;
|
|
128
|
+
/** `null` when the file is missing. Throws on anything unsafe or unreadable. */
|
|
129
|
+
private readManaged;
|
|
130
|
+
/**
|
|
131
|
+
* The same safe read, reported as an observation instead of an exception, for the places that must tell
|
|
132
|
+
* "not there" (`absent`) from "there and wrong" (`bad`: evidence) from "could not find out" (`ioerr`: never evidence).
|
|
133
|
+
*/
|
|
134
|
+
private readFileObs;
|
|
135
|
+
private registerIO;
|
|
136
|
+
/** Files of the task still on disk (events, segments, references, staging). `> 0` after a commit means "deleting". */
|
|
137
|
+
private residueCount;
|
|
138
|
+
/** `derivePruneState` over the real directory. Reads only. */
|
|
139
|
+
private derive;
|
|
140
|
+
/** The error a state that grants nothing turns into. */
|
|
141
|
+
private refusal;
|
|
142
|
+
pruneState(taskId: string): Promise<PruneState>;
|
|
143
|
+
private publishRecord;
|
|
144
|
+
/**
|
|
145
|
+
* The precondition of an irreversible prune (F-1): the log, read now, is that of a finished task whose head is the one
|
|
146
|
+
* the tombstone names. Meaningful only for an attempt that is already visible in the register (or, as a refusal that
|
|
147
|
+
* leaves no residue, just before one is published): from the moment the prepare is visible, an append that lands after
|
|
148
|
+
* this read settles through G2, finds the open attempt and closes it with `abort`, so a commit can never follow it.
|
|
149
|
+
*/
|
|
150
|
+
private assertPrunable;
|
|
151
|
+
preparePrune(tombstone: Tombstone): Promise<{
|
|
152
|
+
attempt: number;
|
|
153
|
+
created: boolean;
|
|
154
|
+
}>;
|
|
155
|
+
decidePrune(taskId: string, attempt: number, outcome: PruneOutcome, tombstone?: Tombstone, by?: DecisionBy): Promise<PruneOutcome>;
|
|
156
|
+
markPruned(tombstone: Tombstone): Promise<void>;
|
|
157
|
+
withdrawTombstone(tombstone: Tombstone): Promise<void>;
|
|
158
|
+
prune(tombstone: Tombstone, opts?: {
|
|
159
|
+
requireCommit?: boolean;
|
|
160
|
+
}): Promise<{
|
|
161
|
+
removedFiles: number;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* The events (and covered segment lines) still on disk with `seq <= upTo`, each verified on its own; no gap is an error,
|
|
165
|
+
* because a roll-forward that was interrupted leaves gaps. A segment wins over a loose copy of the same slot (the reader's
|
|
166
|
+
* rule). Anything that cannot be read safely or does not verify throws: the audit then refuses instead of guessing.
|
|
167
|
+
*/
|
|
168
|
+
private survivingEvents;
|
|
169
|
+
/**
|
|
170
|
+
* O-1: a committed register is not self-proving (its checksum is unkeyed), so the data still on disk must not contradict
|
|
171
|
+
* it before anything is unlinked. See `committedProblem` for what a partly removed log can and cannot prove. Reads only.
|
|
172
|
+
*
|
|
173
|
+
* I-1: the data is read FIRST and `tombstone.json` AFTER it. The roll-forward publishes the tombstone before its first
|
|
174
|
+
* unlink and nothing ever removes it, so a tombstone that is still absent after the data was read proves that no unlink
|
|
175
|
+
* had begun when the data was read (it was absent at every earlier moment too): a gap in the data is then not a removal
|
|
176
|
+
* but a torn observation or real damage. The loose files are read before the segments are listed (see `survivingEvents`), so a
|
|
177
|
+
* compaction that moves events into a segment meanwhile does not tear the observation. Read the
|
|
178
|
+
* other way round, a concurrent pruner that publishes the tombstone and removes events between the two reads is taken
|
|
179
|
+
* for damage. A gap seen without a tombstone is still looked at again a few times before it is refused (a defence in depth,
|
|
180
|
+
* not what F-1 relies on). No lock: a pruner that races this audit only ever turns the verdict
|
|
181
|
+
* from "the whole log must be there" into "a part may be gone", and the roll-forward still checks the tombstone it finds.
|
|
182
|
+
*/
|
|
183
|
+
private auditCommitted;
|
|
184
|
+
/**
|
|
185
|
+
* Prune cleanup (class C, section 30.3): only for a verified, consistent `COMMITTED`. Publishes `tombstone.json` from the
|
|
186
|
+
* commit, then removes the data of the task. It never touches the register, `tombstone.json` or the task directory,
|
|
187
|
+
* decides nothing, and finishing a half-done run is the same call again.
|
|
188
|
+
*/
|
|
189
|
+
private rollForward;
|
|
190
|
+
/**
|
|
191
|
+
* G1 (section 24.6): an optional early refusal, so that a write to a pruned or damaged task does not leave a file
|
|
192
|
+
* behind. Safety never depends on it (G2 decides); turning it off changes only how much is left over.
|
|
193
|
+
*/
|
|
194
|
+
private earlyCheck;
|
|
195
|
+
/**
|
|
196
|
+
* G2 (section 24.2): after a file was published, ask the register. It never unlinks anything: a published file is
|
|
197
|
+
* shared state (F-1, class A is forbidden). `PREPARING` is closed with an `abort` (always safe), at most
|
|
198
|
+
* `MAX_WRITE_RESOLVE` times; a pruner that keeps opening attempts leaves the outcome UNKNOWN, never a deletion.
|
|
199
|
+
*/
|
|
200
|
+
private settle;
|
|
201
|
+
listTaskIds(): Promise<string[]>;
|
|
202
|
+
readLog(taskId: string, opts?: {
|
|
203
|
+
afterSeq?: number;
|
|
204
|
+
rawEvents?: boolean;
|
|
205
|
+
}): Promise<LogRead>;
|
|
206
|
+
private readLogImpl;
|
|
207
|
+
private fileExists;
|
|
208
|
+
private slotName;
|
|
209
|
+
/** The loose file of a slot as an observation (trimmed line), never an exception. */
|
|
210
|
+
private readSlot;
|
|
211
|
+
private listSegments;
|
|
212
|
+
/** A segment as its lines, validated the way `readLog` validates it. */
|
|
213
|
+
private readSegmentLines;
|
|
214
|
+
/**
|
|
215
|
+
* `CanonRead` for the slots `from..to` (section 40.2). Every loose file is read BEFORE the single listing of
|
|
216
|
+
* `segments/` (the order is what makes a slot that was compacted in between visible, section 35.3), and a slot
|
|
217
|
+
* covered by a segment takes the segment's row: a loose file next to it is a copy or an orphan and is not consulted
|
|
218
|
+
* (CEI-2), so an I/O error on it does not matter. Writes nothing.
|
|
219
|
+
*/
|
|
220
|
+
private canonRead;
|
|
221
|
+
/**
|
|
222
|
+
* Canonical Event Identity (section 35.2), run right after the `link` of a loose file (or its `EEXIST`): the slot was
|
|
223
|
+
* read first (`slot`), the listing of `segments/` comes strictly after. Confirmation needs the slot to equal the event
|
|
224
|
+
* of the caller, canonically: the row of a covering segment, or — if nothing covers it — the loose file.
|
|
225
|
+
*/
|
|
226
|
+
private cei;
|
|
227
|
+
/** AV-4: the error for a write that is not valid, chosen from the register only AFTER the refusal (section 31.1). */
|
|
228
|
+
private refuseWrite;
|
|
229
|
+
append(event: TaskEvent): Promise<AppendOutcome>;
|
|
230
|
+
/** The file is already visible: say so on the corruption error. */
|
|
231
|
+
private published;
|
|
232
|
+
/** Removes `name` only if its bytes are exactly `line` (a copy the caller published itself, class B). */
|
|
233
|
+
private removeOwnLooseFile;
|
|
234
|
+
compact(taskId: string, throughSeq: number, events: TaskEvent[]): Promise<CompactionResult>;
|
|
235
|
+
/** Removes the loose event file `name` iff its content is exactly `line`. `true` if it was removed. */
|
|
236
|
+
private removeLooseIfIdentical;
|
|
237
|
+
sweepCompacted(taskId: string): Promise<{
|
|
238
|
+
removedFiles: number;
|
|
239
|
+
keptFiles: number;
|
|
240
|
+
}>;
|
|
241
|
+
pinReference(parentId: string, childId: string, at: string): Promise<'pinned' | 'parent-pruned' | 'parent-missing'>;
|
|
242
|
+
listReferences(parentId: string): Promise<Array<{
|
|
243
|
+
childId: string;
|
|
244
|
+
at: string;
|
|
245
|
+
}>>;
|
|
246
|
+
/** fsync `dir` and every ancestor down to the store root: directory entries created by mkdir are not durable until their parent is synced. */
|
|
247
|
+
private fsyncChain;
|
|
248
|
+
/**
|
|
249
|
+
* Mode A (the only mode claimed): a failed directory fsync is a warning of the write primitive, never a reason to refuse or
|
|
250
|
+
* to continue differently — durability verification (`DV`) is Mode B and is not called here (Design A section 18.2).
|
|
251
|
+
*/
|
|
252
|
+
private fsyncDir;
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=fs-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-store.d.ts","sourceRoot":"","sources":["../../src/durable/fs-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAKH,OAAO,EAKL,YAAY,EAMb,MAAM,aAAa,CAAC;AAuBrB,OAAO,EAAoC,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACnH,OAAO,EASL,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,UAA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