@941design/marmot-engine 0.0.0-stage → 0.2.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/CHANGELOG.md +434 -0
- package/LICENSE +49 -0
- package/README.md +33 -2
- package/dist/audit/emitter.d.ts +17 -0
- package/dist/audit/emitter.js +30 -0
- package/dist/audit/helpers.d.ts +16 -0
- package/dist/audit/helpers.js +103 -0
- package/dist/audit/index.d.ts +6 -0
- package/dist/audit/index.js +6 -0
- package/dist/audit/recorder.d.ts +13 -0
- package/dist/audit/recorder.js +24 -0
- package/dist/audit/sink.d.ts +16 -0
- package/dist/audit/sink.js +27 -0
- package/dist/audit/types-internal.d.ts +7 -0
- package/dist/audit/types-internal.js +1 -0
- package/dist/audit/types.d.ts +289 -0
- package/dist/audit/types.js +2 -0
- package/dist/core/account-identity-proof.d.ts +165 -0
- package/dist/core/account-identity-proof.js +277 -0
- package/dist/core/application-rumor.d.ts +45 -0
- package/dist/core/application-rumor.js +120 -0
- package/dist/core/auth-service.d.ts +2 -0
- package/dist/core/auth-service.js +52 -0
- package/dist/core/binary.d.ts +142 -0
- package/dist/core/binary.js +363 -0
- package/dist/core/capabilities.d.ts +51 -0
- package/dist/core/capabilities.js +102 -0
- package/dist/core/client-state.d.ts +119 -0
- package/dist/core/client-state.js +226 -0
- package/dist/core/commit-authorization.d.ts +26 -0
- package/dist/core/commit-authorization.js +26 -0
- package/dist/core/components/admin-policy.d.ts +4 -0
- package/dist/core/components/admin-policy.js +69 -0
- package/dist/core/components/agent-text-stream.d.ts +51 -0
- package/dist/core/components/agent-text-stream.js +112 -0
- package/dist/core/components/app-components-list.d.ts +17 -0
- package/dist/core/components/app-components-list.js +35 -0
- package/dist/core/components/avatar-url.d.ts +12 -0
- package/dist/core/components/avatar-url.js +85 -0
- package/dist/core/components/bytes.d.ts +5 -0
- package/dist/core/components/bytes.js +18 -0
- package/dist/core/components/dictionary.d.ts +80 -0
- package/dist/core/components/dictionary.js +175 -0
- package/dist/core/components/disband-validation.d.ts +21 -0
- package/dist/core/components/disband-validation.js +173 -0
- package/dist/core/components/encrypted-media.d.ts +44 -0
- package/dist/core/components/encrypted-media.js +210 -0
- package/dist/core/components/group-lifecycle.d.ts +10 -0
- package/dist/core/components/group-lifecycle.js +32 -0
- package/dist/core/components/group-profile.d.ts +24 -0
- package/dist/core/components/group-profile.js +35 -0
- package/dist/core/components/host-safety.d.ts +9 -0
- package/dist/core/components/host-safety.js +148 -0
- package/dist/core/components/ids.d.ts +74 -0
- package/dist/core/components/ids.js +73 -0
- package/dist/core/components/index.d.ts +14 -0
- package/dist/core/components/index.js +14 -0
- package/dist/core/components/integrity.d.ts +141 -0
- package/dist/core/components/integrity.js +293 -0
- package/dist/core/components/message-retention.d.ts +17 -0
- package/dist/core/components/message-retention.js +26 -0
- package/dist/core/components/nostr-routing.d.ts +8 -0
- package/dist/core/components/nostr-routing.js +92 -0
- package/dist/core/components/url.d.ts +26 -0
- package/dist/core/components/url.js +44 -0
- package/dist/core/convergence-status.d.ts +84 -0
- package/dist/core/convergence-status.js +82 -0
- package/dist/core/convergence.d.ts +567 -0
- package/dist/core/convergence.js +1150 -0
- package/dist/core/credential.d.ts +16 -0
- package/dist/core/credential.js +64 -0
- package/dist/core/default-capabilities.d.ts +9 -0
- package/dist/core/default-capabilities.js +34 -0
- package/dist/core/extensions.d.ts +9 -0
- package/dist/core/extensions.js +5 -0
- package/dist/core/grease.d.ts +2 -0
- package/dist/core/grease.js +6 -0
- package/dist/core/group-event.d.ts +18 -0
- package/dist/core/group-event.js +30 -0
- package/dist/core/group-lifecycle.d.ts +42 -0
- package/dist/core/group-lifecycle.js +66 -0
- package/dist/core/group-members.d.ts +37 -0
- package/dist/core/group-members.js +99 -0
- package/dist/core/group-message-classify.d.ts +42 -0
- package/dist/core/group-message-classify.js +57 -0
- package/dist/core/group-message-crypto.d.ts +53 -0
- package/dist/core/group-message-crypto.js +140 -0
- package/dist/core/group-message.d.ts +5 -0
- package/dist/core/group-message.js +11 -0
- package/dist/core/group.d.ts +45 -0
- package/dist/core/group.js +78 -0
- package/dist/core/inbound.d.ts +102 -0
- package/dist/core/inbound.js +79 -0
- package/dist/core/index.d.ts +28 -0
- package/dist/core/index.js +26 -0
- package/dist/core/key-package-eligibility.d.ts +31 -0
- package/dist/core/key-package-eligibility.js +116 -0
- package/dist/core/key-package-event-decode.d.ts +43 -0
- package/dist/core/key-package-event-decode.js +118 -0
- package/dist/core/key-package-event-delete.d.ts +16 -0
- package/dist/core/key-package-event-delete.js +46 -0
- package/dist/core/key-package-event-encode.d.ts +28 -0
- package/dist/core/key-package-event-encode.js +102 -0
- package/dist/core/key-package-event.d.ts +4 -0
- package/dist/core/key-package-event.js +8 -0
- package/dist/core/key-package.d.ts +55 -0
- package/dist/core/key-package.js +115 -0
- package/dist/core/leaf-succession.d.ts +83 -0
- package/dist/core/leaf-succession.js +97 -0
- package/dist/core/media/canonical.d.ts +34 -0
- package/dist/core/media/canonical.js +57 -0
- package/dist/core/media/crypto.d.ts +79 -0
- package/dist/core/media/crypto.js +215 -0
- package/dist/core/media/imeta.d.ts +33 -0
- package/dist/core/media/imeta.js +188 -0
- package/dist/core/media/locator.d.ts +44 -0
- package/dist/core/media/locator.js +69 -0
- package/dist/core/media/types.d.ts +83 -0
- package/dist/core/media/types.js +12 -0
- package/dist/core/media.d.ts +6 -0
- package/dist/core/media.js +12 -0
- package/dist/core/protocol.d.ts +51 -0
- package/dist/core/protocol.js +41 -0
- package/dist/core/relay-lists.d.ts +52 -0
- package/dist/core/relay-lists.js +86 -0
- package/dist/core/retained-history.d.ts +78 -0
- package/dist/core/retained-history.js +59 -0
- package/dist/core/transport.d.ts +43 -0
- package/dist/core/transport.js +21 -0
- package/dist/core/welcome-event.d.ts +61 -0
- package/dist/core/welcome-event.js +116 -0
- package/dist/core/welcome-join.d.ts +155 -0
- package/dist/core/welcome-join.js +243 -0
- package/dist/core/welcome.d.ts +3 -0
- package/dist/core/welcome.js +6 -0
- package/dist/engine/admin-policy.d.ts +58 -0
- package/dist/engine/admin-policy.js +137 -0
- package/dist/engine/auto-committer.d.ts +39 -0
- package/dist/engine/auto-committer.js +42 -0
- package/dist/engine/delivered-payloads.d.ts +61 -0
- package/dist/engine/delivered-payloads.js +84 -0
- package/dist/engine/disband-request.d.ts +41 -0
- package/dist/engine/disband-request.js +86 -0
- package/dist/engine/disband-tombstone.d.ts +14 -0
- package/dist/engine/disband-tombstone.js +66 -0
- package/dist/engine/fork-recovery.d.ts +672 -0
- package/dist/engine/fork-recovery.js +1615 -0
- package/dist/engine/group-engine.d.ts +571 -0
- package/dist/engine/group-engine.js +5112 -0
- package/dist/engine/history-tree.d.ts +232 -0
- package/dist/engine/history-tree.js +651 -0
- package/dist/engine/index.d.ts +16 -0
- package/dist/engine/index.js +15 -0
- package/dist/engine/ingest-disposition.d.ts +5 -0
- package/dist/engine/ingest-disposition.js +63 -0
- package/dist/engine/ingest.d.ts +390 -0
- package/dist/engine/ingest.js +1258 -0
- package/dist/engine/ingestion-pool.d.ts +74 -0
- package/dist/engine/ingestion-pool.js +95 -0
- package/dist/engine/message-dedup.d.ts +16 -0
- package/dist/engine/message-dedup.js +20 -0
- package/dist/engine/own-commit-stamp.d.ts +30 -0
- package/dist/engine/own-commit-stamp.js +71 -0
- package/dist/engine/retained-store.d.ts +79 -0
- package/dist/engine/retained-store.js +133 -0
- package/dist/engine/sender-ratchet.d.ts +50 -0
- package/dist/engine/sender-ratchet.js +196 -0
- package/dist/engine/state-notifications.d.ts +122 -0
- package/dist/engine/state-notifications.js +173 -0
- package/dist/engine/tree-convergence.d.ts +41 -0
- package/dist/engine/tree-convergence.js +90 -0
- package/dist/engine/types.d.ts +366 -0
- package/dist/engine/types.js +14 -0
- package/dist/engine/wire-format.d.ts +77 -0
- package/dist/engine/wire-format.js +120 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -0
- package/dist/mls.d.ts +11 -0
- package/dist/mls.js +11 -0
- package/dist/utils/debug.d.ts +3 -0
- package/dist/utils/debug.js +3 -0
- package/dist/utils/encoding.d.ts +38 -0
- package/dist/utils/encoding.js +91 -0
- package/dist/utils/key-value.d.ts +18 -0
- package/dist/utils/key-value.js +2 -0
- package/dist/utils/nostr.d.ts +35 -0
- package/dist/utils/nostr.js +26 -0
- package/dist/utils/relay-url.d.ts +10 -0
- package/dist/utils/relay-url.js +23 -0
- package/dist/utils/tag-cardinality.d.ts +50 -0
- package/dist/utils/tag-cardinality.js +91 -0
- package/dist/utils/timestamp.d.ts +50 -0
- package/dist/utils/timestamp.js +95 -0
- package/dist/version.d.ts +112 -0
- package/dist/version.js +112 -0
- package/package.json +68 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** @module @category Core - Convergence */
|
|
2
|
+
import { type GroupLifecycleState } from "./group-lifecycle.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convergence status (Marmot v2 `protocol-core/group-state.md` §Convergence
|
|
5
|
+
* status) — a *derived* view of how convergence is progressing within the
|
|
6
|
+
* authoritative lifecycle state. It is computed from stored input and policy; it
|
|
7
|
+
* is never stored state and never a claim made by the transport.
|
|
8
|
+
*
|
|
9
|
+
* Ported from darkmatter `cgka-engine/src/canonicalization.rs`
|
|
10
|
+
* (`ConvergenceStatus`, `convergence_status_for_result`). The lifecycle state
|
|
11
|
+
* ({@link GroupLifecycleState}) stays authoritative; this is the settle-window
|
|
12
|
+
* spine layered on top that gates when queued outbound work may be released.
|
|
13
|
+
*/
|
|
14
|
+
export declare const convergenceStatuses: {
|
|
15
|
+
/** Convergence-relevant input is still arriving, or the quiescence window has not elapsed. */
|
|
16
|
+
readonly syncing: "Syncing";
|
|
17
|
+
/**
|
|
18
|
+
* The quiescence window elapsed, but unresolved convergence work remains —
|
|
19
|
+
* e.g. a child commit whose parent has not been retained or fetched yet.
|
|
20
|
+
*/
|
|
21
|
+
readonly resolving: "Resolving";
|
|
22
|
+
/** Candidate processing reached a fixed point and the selected branch, if any, was applied. */
|
|
23
|
+
readonly settled: "Settled";
|
|
24
|
+
/** Candidate processing cannot safely continue without a repair path or missing retained material. */
|
|
25
|
+
readonly blocked: "Blocked";
|
|
26
|
+
};
|
|
27
|
+
/** A convergence status value. */
|
|
28
|
+
export type ConvergenceStatus = (typeof convergenceStatuses)[keyof typeof convergenceStatuses];
|
|
29
|
+
/** The inputs from which {@link deriveConvergenceStatus} computes the status. */
|
|
30
|
+
export interface ConvergenceStatusInput {
|
|
31
|
+
/** Current wall-clock time (ms). */
|
|
32
|
+
nowMs: number;
|
|
33
|
+
/**
|
|
34
|
+
* Timestamp (ms) of the most recent convergence-relevant input (a commit, or
|
|
35
|
+
* fork material entering recovery). Non-convergence traffic (application
|
|
36
|
+
* messages, lone proposals) MUST NOT advance this.
|
|
37
|
+
*/
|
|
38
|
+
lastConvergenceRelevantInputMs: number;
|
|
39
|
+
/** The quiescence window (`settlementQuiescenceMs` from the convergence policy). */
|
|
40
|
+
settlementQuiescenceMs: number;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the last convergence pass left a non-proposal input message without
|
|
43
|
+
* a disposition (e.g. a child commit whose parent has not been materialized).
|
|
44
|
+
* A lone uncommitted proposal does NOT count — commits are the consensus log
|
|
45
|
+
* and a proposal only takes effect once a commit consumes it
|
|
46
|
+
* (`convergence.md`), so an un-dispositioned proposal must not pin the pass in
|
|
47
|
+
* `Resolving` (darkmatter#154).
|
|
48
|
+
*/
|
|
49
|
+
hasUnresolvedInput: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether convergence hit a blocking error that retained material cannot clear
|
|
52
|
+
* — the `MissingRetainedAnchor` condition (`has_blocking_convergence_error`).
|
|
53
|
+
*/
|
|
54
|
+
hasBlockingError: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Derives the {@link ConvergenceStatus} for a convergence pass, mirroring
|
|
58
|
+
* darkmatter `convergence_status_for_result`. The order is load-bearing: the
|
|
59
|
+
* quiescence window gates first (`Syncing`), then unresolved input
|
|
60
|
+
* (`Resolving`) takes precedence over a blocking error (`Blocked`), and a clean
|
|
61
|
+
* fixed point is `Settled`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function deriveConvergenceStatus(input: ConvergenceStatusInput): ConvergenceStatus;
|
|
64
|
+
/**
|
|
65
|
+
* Whether `status` may legally appear in `lifecycle` (`group-state.md` table).
|
|
66
|
+
* `PendingPublish` and `Merging` are local-publish states, not convergence
|
|
67
|
+
* passes, so no convergence status is meaningful in them — this returns `false`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isConvergenceStatusLegal(status: ConvergenceStatus, lifecycle: GroupLifecycleState): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a client SHOULD queue a local outbound intent rather than preparing it
|
|
72
|
+
* now (`group-state.md` §Local actions during convergence). Outbound work is
|
|
73
|
+
* released only once convergence is `Settled`; `Syncing`, `Resolving`, and
|
|
74
|
+
* `Blocked` all queue, because a state that MAY lose branch selection or require
|
|
75
|
+
* repair must not have payloads encrypted or commits staged against it.
|
|
76
|
+
*/
|
|
77
|
+
export declare function shouldQueueOutbound(status: ConvergenceStatus): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Whether queued outbound work may be released and prepared now: convergence is
|
|
80
|
+
* `Settled` AND the lifecycle allows outbound work. Per the legal-combination
|
|
81
|
+
* table `Settled` only appears in `Stable`, so this is `Settled` + `Stable`;
|
|
82
|
+
* both are checked so a caller passing an inconsistent pair fails closed.
|
|
83
|
+
*/
|
|
84
|
+
export declare function mayReleaseOutbound(status: ConvergenceStatus, lifecycle: GroupLifecycleState): boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** @module @category Core - Convergence */
|
|
2
|
+
import { groupLifecycleStates, } from "./group-lifecycle.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convergence status (Marmot v2 `protocol-core/group-state.md` §Convergence
|
|
5
|
+
* status) — a *derived* view of how convergence is progressing within the
|
|
6
|
+
* authoritative lifecycle state. It is computed from stored input and policy; it
|
|
7
|
+
* is never stored state and never a claim made by the transport.
|
|
8
|
+
*
|
|
9
|
+
* Ported from darkmatter `cgka-engine/src/canonicalization.rs`
|
|
10
|
+
* (`ConvergenceStatus`, `convergence_status_for_result`). The lifecycle state
|
|
11
|
+
* ({@link GroupLifecycleState}) stays authoritative; this is the settle-window
|
|
12
|
+
* spine layered on top that gates when queued outbound work may be released.
|
|
13
|
+
*/
|
|
14
|
+
export const convergenceStatuses = {
|
|
15
|
+
/** Convergence-relevant input is still arriving, or the quiescence window has not elapsed. */
|
|
16
|
+
syncing: "Syncing",
|
|
17
|
+
/**
|
|
18
|
+
* The quiescence window elapsed, but unresolved convergence work remains —
|
|
19
|
+
* e.g. a child commit whose parent has not been retained or fetched yet.
|
|
20
|
+
*/
|
|
21
|
+
resolving: "Resolving",
|
|
22
|
+
/** Candidate processing reached a fixed point and the selected branch, if any, was applied. */
|
|
23
|
+
settled: "Settled",
|
|
24
|
+
/** Candidate processing cannot safely continue without a repair path or missing retained material. */
|
|
25
|
+
blocked: "Blocked",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Derives the {@link ConvergenceStatus} for a convergence pass, mirroring
|
|
29
|
+
* darkmatter `convergence_status_for_result`. The order is load-bearing: the
|
|
30
|
+
* quiescence window gates first (`Syncing`), then unresolved input
|
|
31
|
+
* (`Resolving`) takes precedence over a blocking error (`Blocked`), and a clean
|
|
32
|
+
* fixed point is `Settled`.
|
|
33
|
+
*/
|
|
34
|
+
export function deriveConvergenceStatus(input) {
|
|
35
|
+
const elapsed = Math.max(0, input.nowMs - input.lastConvergenceRelevantInputMs);
|
|
36
|
+
if (elapsed < input.settlementQuiescenceMs)
|
|
37
|
+
return convergenceStatuses.syncing;
|
|
38
|
+
if (input.hasUnresolvedInput)
|
|
39
|
+
return convergenceStatuses.resolving;
|
|
40
|
+
if (input.hasBlockingError)
|
|
41
|
+
return convergenceStatuses.blocked;
|
|
42
|
+
return convergenceStatuses.settled;
|
|
43
|
+
}
|
|
44
|
+
const S = groupLifecycleStates;
|
|
45
|
+
/**
|
|
46
|
+
* The legal (convergence status → lifecycle state) combinations from
|
|
47
|
+
* `group-state.md`. The lifecycle state is authoritative; a status that does
|
|
48
|
+
* not pair with the current lifecycle indicates a coordination bug.
|
|
49
|
+
*/
|
|
50
|
+
const LEGAL_COMBINATIONS = {
|
|
51
|
+
[convergenceStatuses.syncing]: [S.stable, S.recovering],
|
|
52
|
+
[convergenceStatuses.resolving]: [S.stable, S.recovering],
|
|
53
|
+
[convergenceStatuses.settled]: [S.stable],
|
|
54
|
+
[convergenceStatuses.blocked]: [S.recovering, S.unrecoverable],
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Whether `status` may legally appear in `lifecycle` (`group-state.md` table).
|
|
58
|
+
* `PendingPublish` and `Merging` are local-publish states, not convergence
|
|
59
|
+
* passes, so no convergence status is meaningful in them — this returns `false`.
|
|
60
|
+
*/
|
|
61
|
+
export function isConvergenceStatusLegal(status, lifecycle) {
|
|
62
|
+
return LEGAL_COMBINATIONS[status].includes(lifecycle);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether a client SHOULD queue a local outbound intent rather than preparing it
|
|
66
|
+
* now (`group-state.md` §Local actions during convergence). Outbound work is
|
|
67
|
+
* released only once convergence is `Settled`; `Syncing`, `Resolving`, and
|
|
68
|
+
* `Blocked` all queue, because a state that MAY lose branch selection or require
|
|
69
|
+
* repair must not have payloads encrypted or commits staged against it.
|
|
70
|
+
*/
|
|
71
|
+
export function shouldQueueOutbound(status) {
|
|
72
|
+
return status !== convergenceStatuses.settled;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Whether queued outbound work may be released and prepared now: convergence is
|
|
76
|
+
* `Settled` AND the lifecycle allows outbound work. Per the legal-combination
|
|
77
|
+
* table `Settled` only appears in `Stable`, so this is `Settled` + `Stable`;
|
|
78
|
+
* both are checked so a caller passing an inconsistent pair fails closed.
|
|
79
|
+
*/
|
|
80
|
+
export function mayReleaseOutbound(status, lifecycle) {
|
|
81
|
+
return status === convergenceStatuses.settled && lifecycle === S.stable;
|
|
82
|
+
}
|