@amalgm/live 0.2.8 → 0.2.10

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/PURPOSE.md CHANGED
@@ -96,11 +96,10 @@ its cutover.
96
96
  registered root with valid `.git` evidence is `repo.git`, as is any nested
97
97
  directory with that evidence; the UUID does not change when the type does.
98
98
  `.git` itself is repository transport metadata and never receives an
99
- entity row. Worktree children retain local UUID rows, but a proper
100
- `repo.git` ancestor carries their identities and bytes in one immutable
101
- Card + Checkpoint parcel rather than one cloud record per child. A shallow
102
- repository carries its declared Git history boundary in that parcel, so a
103
- new machine never depends on an object outside the transport.
99
+ entity row. Worktree children retain local UUID rows, while their
100
+ identities ride in the repository state manifest rather than becoming
101
+ individual cloud records. A shallow repository carries its declared Git
102
+ history boundary, so a new machine never invents history beyond it.
104
103
  22. **Transfer moves content; it never discovers state.** `upload` moves one
105
104
  already-registered immutable artifact toward cloud storage and `download`
106
105
  moves that same artifact toward a machine cache. Neither operation scans,
@@ -108,15 +107,31 @@ its cutover.
108
107
  publishes a registry snapshot.
109
108
  23. **Entity type selects the artifact, not a second lifecycle.** Text and
110
109
  binary files travel as file bytes, links travel as their literal target,
111
- and repositories travel as their immutable Git Card + Checkpoint parcel.
110
+ and repositories travel as a small state manifest plus Git-native packs.
112
111
  Workspace and folder membership travels in the entity graph; references
113
112
  carry a UUID and therefore have no separate content artifact.
114
- 24. **Transfer is verified, missing-only, and commit-last.** Every chunk is
115
- content-addressed and verified at each boundary; an uploader sends only
116
- chunks the authority reports missing, a downloader fetches only chunks its
117
- machine cache lacks, and the manifest becomes visible only after all of its
118
- chunks are durable. Repeating either operation is safe and moves no bytes
119
- that the destination already has.
113
+ 24. **Transfer is verified, missing-only, and commit-last.** File chunks and
114
+ Git packs are content-addressed and verified at each boundary; an uploader
115
+ sends only content the authority reports missing, a downloader fetches
116
+ only content its machine cache lacks, and the new state becomes visible
117
+ only after every dependency is durable. Repeating either operation is safe
118
+ and moves no bytes that the destination already has.
119
+ 25. **Cold repository transfer is native Git work.** An empty destination
120
+ receives one binary pack containing exactly the objects reachable from the
121
+ repository's declared refs, plus bounded Amalgm state metadata. A Git pack
122
+ is never embedded in JSON or base64 and is never unpacked into per-file
123
+ upload requests.
124
+ 26. **Incremental repository transfer is negotiated Git work.** The
125
+ destination's existing object frontier is the exclusion set for Git's
126
+ packer. A new repository state links to its prior transport and carries
127
+ only objects the prior state cannot supply; download follows and imports
128
+ only the missing links, oldest first. A one-file commit can never cause the
129
+ previously uploaded repository history to travel again.
130
+ 27. **Registered type selects transfer.** Upload and download dispatch only
131
+ from the registered entity type according to `docs/transfer.md`. They
132
+ never re-detect type from a path or contents. Graph-only types perform no
133
+ content effects; text and binary files use the same block law; Git alone
134
+ uses Git object negotiation.
120
135
 
121
136
  ## Five surfaces, one behavior
122
137
 
@@ -11,9 +11,12 @@
11
11
  * host effects; this file owns the shape and its laws.
12
12
  */
13
13
  import { type Checked } from './validate.js';
14
- export declare const CONTENT_CONTRACT = "amalgm-entity-content@1";
15
- /** One chunk is one WAN round trip; the gateway accepts parts up to this same bound. */
14
+ export declare const CONTENT_CONTRACT = "amalgm-entity-content@2";
15
+ export declare const MIN_CONTENT_BLOCK_BYTES: number;
16
+ export declare const MAX_CONTENT_BLOCK_BYTES: number;
17
+ /** Maximum accepted block size. Kept as the public manifest-bound name. */
16
18
  export declare const CHUNK_BYTES: number;
19
+ export declare const MAX_CONTENT_BLOCKS = 2000;
17
20
  export interface ContentChunk {
18
21
  readonly sha256: string;
19
22
  readonly bytes: number;
@@ -37,6 +40,9 @@ export declare function checkContentManifest(input: unknown, expectedHash?: stri
37
40
  * hand-built manifest cannot drift from the derivation rule.
38
41
  */
39
42
  export declare function manifestFromChunks(contentHash: string, chunks: readonly ContentChunk[]): Checked<ContentManifest>;
40
- /** Split a byte count into the chunk sizes capture will produce: full chunks, then the remainder. Zero bytes zero chunks. */
43
+ /** Syncthing's adaptive fixed-block rule: the smallest power of two that
44
+ * keeps the manifest at no more than 2,000 blocks, capped at 16 MiB. */
45
+ export declare function contentBlockSize(totalBytes: number): number;
46
+ /** Split a byte count into adaptive full blocks, then the remainder. */
41
47
  export declare function chunkSizes(totalBytes: number): number[];
42
48
  //# sourceMappingURL=content.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/contracts/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAwB,MAAM,eAAe,CAAC;AAEnE,eAAO,MAAM,gBAAgB,4BAA4B,CAAC;AAE1D,wFAAwF;AACxF,eAAO,MAAM,WAAW,QAAkB,CAAC;AAI3C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,gBAAgB,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAkCjH;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,YAAY,EAAE,GAC9B,OAAO,CAAC,eAAe,CAAC,CAK1B;AAED,+HAA+H;AAC/H,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAOvD"}
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/contracts/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAwB,MAAM,eAAe,CAAC;AAEnE,eAAO,MAAM,gBAAgB,4BAA4B,CAAC;AAE1D,eAAO,MAAM,uBAAuB,QAAa,CAAC;AAClD,eAAO,MAAM,uBAAuB,QAAmB,CAAC;AACxD,2EAA2E;AAC3E,eAAO,MAAM,WAAW,QAA0B,CAAC;AACnD,eAAO,MAAM,kBAAkB,OAAQ,CAAC;AAIxC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,gBAAgB,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAkCjH;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,SAAS,YAAY,EAAE,GAC9B,OAAO,CAAC,eAAe,CAAC,CAK1B;AAED;wEACwE;AACxE,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAQvD"}
@@ -11,9 +11,12 @@
11
11
  * host effects; this file owns the shape and its laws.
12
12
  */
13
13
  import { pass, fail, isRecord } from './validate.js';
14
- export const CONTENT_CONTRACT = 'amalgm-entity-content@1';
15
- /** One chunk is one WAN round trip; the gateway accepts parts up to this same bound. */
16
- export const CHUNK_BYTES = 4 * 1024 * 1024;
14
+ export const CONTENT_CONTRACT = 'amalgm-entity-content@2';
15
+ export const MIN_CONTENT_BLOCK_BYTES = 128 * 1024;
16
+ export const MAX_CONTENT_BLOCK_BYTES = 16 * 1024 * 1024;
17
+ /** Maximum accepted block size. Kept as the public manifest-bound name. */
18
+ export const CHUNK_BYTES = MAX_CONTENT_BLOCK_BYTES;
19
+ export const MAX_CONTENT_BLOCKS = 2_000;
17
20
  const HASH = /^[0-9a-f]{64}$/;
18
21
  /**
19
22
  * Validate and normalize a manifest. The laws, in conviction order:
@@ -59,13 +62,25 @@ export function checkContentManifest(input, expectedHash = null) {
59
62
  export function manifestFromChunks(contentHash, chunks) {
60
63
  return checkContentManifest({ contract: CONTENT_CONTRACT, contentHash, bytes: chunks.reduce((t, c) => t + c.bytes, 0), chunks }, contentHash);
61
64
  }
62
- /** Split a byte count into the chunk sizes capture will produce: full chunks, then the remainder. Zero bytes zero chunks. */
65
+ /** Syncthing's adaptive fixed-block rule: the smallest power of two that
66
+ * keeps the manifest at no more than 2,000 blocks, capped at 16 MiB. */
67
+ export function contentBlockSize(totalBytes) {
68
+ if (!Number.isSafeInteger(totalBytes) || totalBytes < 0)
69
+ return MIN_CONTENT_BLOCK_BYTES;
70
+ let bytes = MIN_CONTENT_BLOCK_BYTES;
71
+ while (Math.ceil(totalBytes / bytes) > MAX_CONTENT_BLOCKS && bytes < MAX_CONTENT_BLOCK_BYTES) {
72
+ bytes *= 2;
73
+ }
74
+ return bytes;
75
+ }
76
+ /** Split a byte count into adaptive full blocks, then the remainder. */
63
77
  export function chunkSizes(totalBytes) {
64
78
  if (!Number.isSafeInteger(totalBytes) || totalBytes < 0)
65
79
  return [];
80
+ const blockBytes = contentBlockSize(totalBytes);
66
81
  const sizes = [];
67
- for (let remaining = totalBytes; remaining > 0; remaining -= CHUNK_BYTES) {
68
- sizes.push(Math.min(remaining, CHUNK_BYTES));
82
+ for (let remaining = totalBytes; remaining > 0; remaining -= blockBytes) {
83
+ sizes.push(Math.min(remaining, blockBytes));
69
84
  }
70
85
  return sizes;
71
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/contracts/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAgB,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D,wFAAwF;AACxF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAc9B;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc,EAAE,eAA8B,IAAI;IACrF,IACE,CAAC,QAAQ,CAAC,KAAK,CAAC;QAChB,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;QACrC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;QAC7B,CAAC,YAAY,KAAK,IAAI,IAAI,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC;QAC7D,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;QACjC,KAAK,CAAC,KAAgB,GAAG,CAAC;QAC3B,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;QAC5B,KAAK,CAAC,MAAM,CAAC,IAAI,CACf,CAAC,KAAK,EAAE,EAAE,CACR,CAAC,QAAQ,CAAC,KAAK,CAAC;YAChB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YACtC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;YACjC,KAAK,CAAC,KAAgB,GAAG,CAAC;YAC1B,KAAK,CAAC,KAAgB,GAAG,WAAW,CACxC,EACD,CAAC;QACD,OAAO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A+B;IAE/B,OAAO,oBAAoB,CACzB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EACnG,WAAW,CACZ,CAAC;AACJ,CAAC;AAED;wEACwE;AACxE,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IACjD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC;QAAE,OAAO,uBAAuB,CAAC;IACxF,IAAI,KAAK,GAAG,uBAAuB,CAAC;IACpC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,GAAG,kBAAkB,IAAI,KAAK,GAAG,uBAAuB,EAAE,CAAC;QAC7F,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,UAAkB;IAC3C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IACnE,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,SAAS,GAAG,UAAU,EAAE,SAAS,GAAG,CAAC,EAAE,SAAS,IAAI,UAAU,EAAE,CAAC;QACxE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,33 +1,14 @@
1
1
  /**
2
- * The Card + Checkpoint state codec and its id derivations (engine
3
- * registration/repo-states.js + repocard/capture.js). A `repo.git`
4
- * entity's semantic head is `stateId = sha256(cardId + checkpointId)`;
5
- * this module owns those derivations and the exact JSON the state travels
6
- * and persists as, byte for byte.
2
+ * Portable repository state and binary transport.
7
3
  *
8
- * Axioms carried over from the engine:
9
- * - the durable local state deliberately omits the Git bundle bundles
10
- * are transport cargo, named by a content head, never identity-store
11
- * bytes;
12
- * - a transport document contains its bundle and checkpoint bytes but
13
- * never names itself: its SHA-256 IS the immutable cloud content head,
14
- * so bundle packing can vary without changing repository identity;
15
- * - the identity map (worktree path → { uuid, type }) is transport cargo
16
- * too: repo children never travel as individual cloud records, so
17
- * their permanent UUIDs ride inside the one state parcel;
18
- * - ids derive deterministically — remotes are seed metadata, not
19
- * identity, and bundle bytes are excluded because packing is not
20
- * deterministic. Equal ids are silence.
21
- *
22
- * `unpack` trusts its input to be `pack`'s output (the host's own durable
23
- * row or transport parcel); it is a codec, not a wire validator.
24
- *
25
- * JSON parity note: derivations and `pack` serialize host-built objects,
26
- * so nested key order follows the host's object insertion order. Build
27
- * cards and checkpoints in the field order these interfaces declare (the
28
- * engine capture order) and the bytes match the engine's exactly.
4
+ * Git object bytes remain a native PACK stream. Amalgm metadata is a short
5
+ * UTF-8 JSON header followed by raw checkpoint cargo; no byte field is ever
6
+ * base64 encoded. Successive transports name their parent and carry an
7
+ * identity-map delta, so one new commit never embeds old repository history
8
+ * or the unchanged per-path identity map again.
29
9
  */
30
10
  import type { Sha256Hex } from './types.js';
11
+ export declare const REPOSITORY_TRANSPORT_CONTRACT = "amalgm.repo-transport.v2";
31
12
  export interface RepoHead {
32
13
  readonly branch: string | null;
33
14
  readonly commit: string | null;
@@ -41,7 +22,8 @@ export interface RepoRemote {
41
22
  readonly name: string;
42
23
  readonly url: string;
43
24
  }
44
- export interface RepoBundle {
25
+ /** A native Git pack. It may be thin when a parent transport supplies bases. */
26
+ export interface RepoPack {
45
27
  readonly bytes: Uint8Array;
46
28
  readonly sha256: string;
47
29
  }
@@ -51,15 +33,9 @@ export interface RepoCard {
51
33
  readonly branches: readonly RepoRef[];
52
34
  readonly tags: readonly RepoRef[];
53
35
  readonly remotes: readonly RepoRemote[];
54
- /** Git's declared history horizon. These commits are present, but their
55
- * parents intentionally are not; an empty receiver must install this
56
- * boundary before importing the bundle. Transport metadata, not identity. */
36
+ /** Git's declared history horizon. */
57
37
  readonly shallow?: readonly string[];
58
- readonly bundle: RepoBundle | null;
59
38
  }
60
- /** `content: null` marks a reused (unopened) entry; ids derive from
61
- * (path, mode, sha256) alone, so a scoped capture's ids are byte-identical
62
- * to a from-scratch one over the same ground. */
63
39
  export interface RepoUntrackedFile {
64
40
  readonly path: string;
65
41
  readonly mode: string;
@@ -74,52 +50,59 @@ export interface RepoCheckpoint {
74
50
  readonly unstagedPatch: Uint8Array;
75
51
  readonly untracked: readonly RepoUntrackedFile[];
76
52
  }
77
- /** One enrolled worktree entity inside the transport identity map. */
53
+ /** One enrolled worktree entity inside the repository identity map. */
78
54
  export interface RepoIdentityEntry {
79
55
  readonly path: string;
80
56
  readonly uuid: string;
81
57
  readonly type: string;
82
58
  }
59
+ export interface RepoIdentityDelta {
60
+ /** True only for a chain root. Its upserts are the complete identity map. */
61
+ readonly reset: boolean;
62
+ readonly upsert: readonly RepoIdentityEntry[];
63
+ readonly remove: readonly string[];
64
+ }
83
65
  export interface RepoState {
84
66
  readonly stateId: string;
85
67
  readonly cardId: string;
86
68
  readonly checkpointId: string;
87
- readonly transportVersion?: string | null;
88
- readonly identity?: readonly RepoIdentityEntry[] | null;
89
69
  readonly card: RepoCard;
90
70
  readonly checkpoint: RepoCheckpoint;
71
+ readonly pack: RepoPack | null;
91
72
  }
92
- /** A state whose transport head and identity map are settled (what
93
- * `unpack` and `localState` return). */
94
- export interface LocalRepoState extends RepoState {
95
- readonly transportVersion: string | null;
96
- readonly identity: readonly RepoIdentityEntry[] | null;
73
+ /** One immutable node in a repository transport chain. */
74
+ export interface RepositoryTransport extends RepoState {
75
+ readonly parentTransportVersion: string | null;
76
+ readonly identityHash: string;
77
+ readonly identityDelta: RepoIdentityDelta;
97
78
  }
98
- export interface PackOptions {
99
- readonly includeBundle?: boolean;
100
- readonly transportVersion?: string | null;
101
- readonly identity?: readonly RepoIdentityEntry[] | null;
79
+ export interface RepositoryTransportInput {
80
+ readonly parentTransportVersion: string | null;
81
+ readonly identityHash: string;
82
+ readonly identityDelta: RepoIdentityDelta;
102
83
  }
103
- /** Serialize a state to its durable/transport JSON. The durable local form
104
- * omits the bundle (`includeBundle: false`); the transport form carries it
105
- * plus the identity map. */
106
- export declare function pack(state: RepoState, { includeBundle, transportVersion, identity }?: PackOptions): string;
107
- /** Decode `pack`'s JSON back into a state with real bytes. */
108
- export declare function unpack(text: string): LocalRepoState;
109
- /** The transport parcel: bundle included, no self-naming transport head,
110
- * the identity map riding inside. Its SHA-256 is the cloud content head. */
111
- export declare function transportBytes(state: RepoState, identity?: readonly RepoIdentityEntry[] | null): Uint8Array;
112
- /** The durable local form of a captured state: bundle and identity map
113
- * shed, the settled transport head recorded. */
114
- export declare function localState(state: RepoState, transportVersion: string | null): LocalRepoState;
115
- /** Card identity from the ledger only.
116
- * Remotes deliberately absent: seed metadata, not identity.
117
- * Bundle bytes deliberately absent: packing is not deterministic. */
84
+ export declare function repositoryIdentityHash(identity: readonly RepoIdentityEntry[], sha256Hex: Sha256Hex): string;
85
+ /** Derive the smallest path-keyed change from one identity map to the next. */
86
+ export declare function planRepositoryIdentity(current: readonly RepoIdentityEntry[], previous: readonly RepoIdentityEntry[] | null, sha256Hex: Sha256Hex): {
87
+ readonly identityHash: string;
88
+ readonly identityDelta: RepoIdentityDelta;
89
+ };
90
+ /** Apply and verify one identity-map chain node. */
91
+ export declare function applyRepositoryIdentity(previous: readonly RepoIdentityEntry[] | null, transport: Pick<RepositoryTransport, 'identityHash' | 'identityDelta'>, sha256Hex: Sha256Hex): readonly RepoIdentityEntry[];
92
+ /** Encode metadata followed by raw Git/checkpoint bytes. */
93
+ export declare function encodeRepositoryTransport(state: RepoState, input: RepositoryTransportInput): Uint8Array;
94
+ /** Decode the binary envelope without interpreting Git's native pack bytes. */
95
+ export declare function decodeRepositoryTransport(bytes: Uint8Array): RepositoryTransport;
96
+ /** Separate Git work from Amalgm metadata/checkpoint overhead in benchmarks. */
97
+ export declare function repositoryTransportSizes(bytes: Uint8Array): {
98
+ readonly totalBytes: number;
99
+ readonly metadataBytes: number;
100
+ readonly gitPackBytes: number;
101
+ readonly checkpointBytes: number;
102
+ };
103
+ /** Card identity from the ledger only. Remotes and transport data are absent. */
118
104
  export declare function deriveCardId(card: Pick<RepoCard, 'version' | 'head' | 'branches' | 'tags'>, sha256Hex: Sha256Hex): string;
119
- /** Checkpoint identity from the diff base, the patch hashes, and each
120
- * untracked (path, mode, sha256) — never the untracked contents, so reused
121
- * entries derive identically. */
105
+ /** Checkpoint identity from its hashes, never duplicated byte encodings. */
122
106
  export declare function deriveCheckpointId(checkpoint: Pick<RepoCheckpoint, 'baseCommit' | 'stagedPatch' | 'unstagedPatch' | 'untracked'>, sha256Hex: Sha256Hex): string;
123
- /** The repository's semantic head: sha256(cardId + checkpointId). */
124
107
  export declare const deriveStateId: (cardId: string, checkpointId: string, sha256Hex: Sha256Hex) => string;
125
108
  //# sourceMappingURL=repo-states.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repo-states.d.ts","sourceRoot":"","sources":["../../src/entities/repo-states.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,E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checkpoint state codec and its id derivations (engine
3
- * registration/repo-states.js + repocard/capture.js). A `repo.git`
4
- * entity's semantic head is `stateId = sha256(cardId + checkpointId)`;
5
- * this module owns those derivations and the exact JSON the state travels
6
- * and persists as, byte for byte.
2
+ * Portable repository state and binary transport.
7
3
  *
8
- * Axioms carried over from the engine:
9
- * - the durable local state deliberately omits the Git bundle bundles
10
- * are transport cargo, named by a content head, never identity-store
11
- * bytes;
12
- * - a transport document contains its bundle and checkpoint bytes but
13
- * never names itself: its SHA-256 IS the immutable cloud content head,
14
- * so bundle packing can vary without changing repository identity;
15
- * - the identity map (worktree path → { uuid, type }) is transport cargo
16
- * too: repo children never travel as individual cloud records, so
17
- * their permanent UUIDs ride inside the one state parcel;
18
- * - ids derive deterministically — remotes are seed metadata, not
19
- * identity, and bundle bytes are excluded because packing is not
20
- * deterministic. Equal ids are silence.
21
- *
22
- * `unpack` trusts its input to be `pack`'s output (the host's own durable
23
- * row or transport parcel); it is a codec, not a wire validator.
24
- *
25
- * JSON parity note: derivations and `pack` serialize host-built objects,
26
- * so nested key order follows the host's object insertion order. Build
27
- * cards and checkpoints in the field order these interfaces declare (the
28
- * engine capture order) and the bytes match the engine's exactly.
4
+ * Git object bytes remain a native PACK stream. Amalgm metadata is a short
5
+ * UTF-8 JSON header followed by raw checkpoint cargo; no byte field is ever
6
+ * base64 encoded. Successive transports name their parent and carry an
7
+ * identity-map delta, so one new commit never embeds old repository history
8
+ * or the unchanged per-path identity map again.
29
9
  */
30
- import { base64ToBytes, bytesToBase64, utf8Encode } from './bytes.js';
31
- const encodeBytes = (bytes) => bytesToBase64(bytes ?? new Uint8Array());
32
- const decodeBytes = (encoded) => base64ToBytes(encoded ?? '');
33
- /** Serialize a state to its durable/transport JSON. The durable local form
34
- * omits the bundle (`includeBundle: false`); the transport form carries it
35
- * plus the identity map. */
36
- export function pack(state, { includeBundle = true, transportVersion = state.transportVersion ?? null, identity = null } = {}) {
37
- return JSON.stringify({
10
+ import { utf8Decode, utf8Encode } from './bytes.js';
11
+ export const REPOSITORY_TRANSPORT_CONTRACT = 'amalgm.repo-transport.v2';
12
+ const MAGIC = utf8Encode('AMGREPO2');
13
+ const HEADER_BYTES = MAGIC.byteLength + 4;
14
+ const sortedIdentity = (identity) => [...identity].sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
15
+ export function repositoryIdentityHash(identity, sha256Hex) {
16
+ return sha256Hex(JSON.stringify(sortedIdentity(identity)));
17
+ }
18
+ /** Derive the smallest path-keyed change from one identity map to the next. */
19
+ export function planRepositoryIdentity(current, previous, sha256Hex) {
20
+ const next = sortedIdentity(current);
21
+ if (new Set(next.map((entry) => entry.path)).size !== next.length) {
22
+ throw new Error('repository identity map has duplicate paths');
23
+ }
24
+ if (previous === null) {
25
+ return {
26
+ identityHash: repositoryIdentityHash(next, sha256Hex),
27
+ identityDelta: { reset: true, upsert: next, remove: [] },
28
+ };
29
+ }
30
+ const prior = new Map(previous.map((entry) => [entry.path, entry]));
31
+ const currentPaths = new Set(next.map((entry) => entry.path));
32
+ const upsert = next.filter((entry) => {
33
+ const old = prior.get(entry.path);
34
+ return old === undefined || old.uuid !== entry.uuid || old.type !== entry.type;
35
+ });
36
+ const remove = [...prior.keys()].filter((path) => !currentPaths.has(path)).sort();
37
+ return {
38
+ identityHash: repositoryIdentityHash(next, sha256Hex),
39
+ identityDelta: { reset: false, upsert, remove },
40
+ };
41
+ }
42
+ /** Apply and verify one identity-map chain node. */
43
+ export function applyRepositoryIdentity(previous, transport, sha256Hex) {
44
+ if (transport.identityDelta.reset !== (previous === null)) {
45
+ throw new Error('repository identity delta has the wrong chain boundary');
46
+ }
47
+ const entries = new Map((previous ?? []).map((entry) => [entry.path, entry]));
48
+ for (const path of transport.identityDelta.remove)
49
+ entries.delete(path);
50
+ for (const entry of transport.identityDelta.upsert)
51
+ entries.set(entry.path, entry);
52
+ const result = sortedIdentity([...entries.values()]);
53
+ if (repositoryIdentityHash(result, sha256Hex) !== transport.identityHash) {
54
+ throw new Error('repository identity delta does not produce its declared map');
55
+ }
56
+ return result;
57
+ }
58
+ const descriptor = (bytes) => ({ bytes: bytes.byteLength });
59
+ /** Encode metadata followed by raw Git/checkpoint bytes. */
60
+ export function encodeRepositoryTransport(state, input) {
61
+ const header = {
62
+ contract: REPOSITORY_TRANSPORT_CONTRACT,
38
63
  stateId: state.stateId,
39
64
  cardId: state.cardId,
40
65
  checkpointId: state.checkpointId,
41
- transportVersion,
42
- ...(identity ? { identity } : {}),
43
- card: {
44
- ...state.card,
45
- bundle: includeBundle && state.card.bundle ? {
46
- ...state.card.bundle,
47
- bytes: encodeBytes(state.card.bundle.bytes),
48
- } : null,
49
- },
66
+ parentTransportVersion: input.parentTransportVersion,
67
+ identityHash: input.identityHash,
68
+ identityDelta: input.identityDelta,
69
+ card: state.card,
70
+ pack: state.pack ? { sha256: state.pack.sha256, bytes: state.pack.bytes.byteLength } : null,
50
71
  checkpoint: {
51
- ...state.checkpoint,
52
- stagedPatch: encodeBytes(state.checkpoint.stagedPatch),
53
- unstagedPatch: encodeBytes(state.checkpoint.unstagedPatch),
72
+ baseCommit: state.checkpoint.baseCommit,
73
+ branch: state.checkpoint.branch,
74
+ stagedPatch: descriptor(state.checkpoint.stagedPatch),
75
+ unstagedPatch: descriptor(state.checkpoint.unstagedPatch),
54
76
  untracked: state.checkpoint.untracked.map((file) => ({
55
- ...file,
56
- content: encodeBytes(file.content),
77
+ path: file.path,
78
+ mode: file.mode,
79
+ sha256: file.sha256,
80
+ ...(file.reused === undefined ? {} : { reused: file.reused }),
81
+ content: file.content === null ? null : descriptor(file.content),
57
82
  })),
58
83
  },
59
- });
84
+ };
85
+ const metadata = utf8Encode(JSON.stringify(header));
86
+ if (metadata.byteLength > 0xffff_ffff)
87
+ throw new Error('repository transport metadata is too large');
88
+ const cargo = [
89
+ ...(state.pack ? [state.pack.bytes] : []),
90
+ state.checkpoint.stagedPatch,
91
+ state.checkpoint.unstagedPatch,
92
+ ...state.checkpoint.untracked.flatMap((file) => file.content === null ? [] : [file.content]),
93
+ ];
94
+ const cargoBytes = cargo.reduce((total, bytes) => total + bytes.byteLength, 0);
95
+ const output = new Uint8Array(HEADER_BYTES + metadata.byteLength + cargoBytes);
96
+ output.set(MAGIC, 0);
97
+ new DataView(output.buffer).setUint32(MAGIC.byteLength, metadata.byteLength, false);
98
+ output.set(metadata, HEADER_BYTES);
99
+ let cursor = HEADER_BYTES + metadata.byteLength;
100
+ for (const bytes of cargo) {
101
+ output.set(bytes, cursor);
102
+ cursor += bytes.byteLength;
103
+ }
104
+ return output;
60
105
  }
61
- /** Decode `pack`'s JSON back into a state with real bytes. */
62
- export function unpack(text) {
63
- const state = JSON.parse(text);
106
+ const byteCount = (value, label) => {
107
+ if (!Number.isSafeInteger(value) || value < 0) {
108
+ throw new Error(`repository transport has invalid ${label} byte count`);
109
+ }
110
+ return value;
111
+ };
112
+ /** Decode the binary envelope without interpreting Git's native pack bytes. */
113
+ export function decodeRepositoryTransport(bytes) {
114
+ if (bytes.byteLength < HEADER_BYTES
115
+ || MAGIC.some((value, index) => bytes[index] !== value)) {
116
+ throw new Error('repository transport has an invalid binary header');
117
+ }
118
+ const metadataBytes = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
119
+ .getUint32(MAGIC.byteLength, false);
120
+ const cargoStart = HEADER_BYTES + metadataBytes;
121
+ if (cargoStart > bytes.byteLength)
122
+ throw new Error('repository transport metadata is truncated');
123
+ const header = JSON.parse(utf8Decode(bytes.subarray(HEADER_BYTES, cargoStart)));
124
+ if (header.contract !== REPOSITORY_TRANSPORT_CONTRACT) {
125
+ throw new Error('repository transport contract is unsupported');
126
+ }
127
+ let cursor = cargoStart;
128
+ const take = (count, label) => {
129
+ const length = byteCount(count, label);
130
+ const end = cursor + length;
131
+ if (!Number.isSafeInteger(end) || end > bytes.byteLength) {
132
+ throw new Error(`repository transport ${label} is truncated`);
133
+ }
134
+ const value = bytes.slice(cursor, end);
135
+ cursor = end;
136
+ return value;
137
+ };
138
+ const pack = header.pack === null ? null : {
139
+ sha256: header.pack.sha256,
140
+ bytes: take(header.pack.bytes, 'Git pack'),
141
+ };
142
+ const stagedPatch = take(header.checkpoint.stagedPatch.bytes, 'staged patch');
143
+ const unstagedPatch = take(header.checkpoint.unstagedPatch.bytes, 'unstaged patch');
144
+ const untracked = header.checkpoint.untracked.map((file) => ({
145
+ ...file,
146
+ content: file.content === null ? null : take(file.content.bytes, `untracked file ${file.path}`),
147
+ }));
148
+ if (cursor !== bytes.byteLength)
149
+ throw new Error('repository transport has trailing cargo');
64
150
  return {
65
- ...state,
66
- transportVersion: typeof state.transportVersion === 'string' ? state.transportVersion : null,
67
- identity: Array.isArray(state.identity) ? state.identity : null,
68
- card: {
69
- ...state.card,
70
- bundle: state.card.bundle && {
71
- ...state.card.bundle,
72
- bytes: decodeBytes(state.card.bundle.bytes),
73
- },
74
- },
151
+ stateId: header.stateId,
152
+ cardId: header.cardId,
153
+ checkpointId: header.checkpointId,
154
+ parentTransportVersion: header.parentTransportVersion,
155
+ identityHash: header.identityHash,
156
+ identityDelta: header.identityDelta,
157
+ card: header.card,
158
+ pack,
75
159
  checkpoint: {
76
- ...state.checkpoint,
77
- stagedPatch: decodeBytes(state.checkpoint.stagedPatch),
78
- unstagedPatch: decodeBytes(state.checkpoint.unstagedPatch),
79
- untracked: state.checkpoint.untracked.map((file) => ({
80
- ...file,
81
- content: decodeBytes(file.content),
82
- })),
160
+ baseCommit: header.checkpoint.baseCommit,
161
+ branch: header.checkpoint.branch,
162
+ stagedPatch,
163
+ unstagedPatch,
164
+ untracked,
83
165
  },
84
166
  };
85
167
  }
86
- /** The transport parcel: bundle included, no self-naming transport head,
87
- * the identity map riding inside. Its SHA-256 is the cloud content head. */
88
- export function transportBytes(state, identity = null) {
89
- return utf8Encode(pack(state, { includeBundle: true, transportVersion: null, identity }));
90
- }
91
- /** The durable local form of a captured state: bundle and identity map
92
- * shed, the settled transport head recorded. */
93
- export function localState(state, transportVersion) {
168
+ /** Separate Git work from Amalgm metadata/checkpoint overhead in benchmarks. */
169
+ export function repositoryTransportSizes(bytes) {
170
+ const transport = decodeRepositoryTransport(bytes);
171
+ const metadataBytes = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
172
+ .getUint32(MAGIC.byteLength, false) + HEADER_BYTES;
173
+ const gitPackBytes = transport.pack?.bytes.byteLength ?? 0;
94
174
  return {
95
- ...state,
96
- transportVersion,
97
- identity: null,
98
- card: { ...state.card, bundle: null },
175
+ totalBytes: bytes.byteLength,
176
+ metadataBytes,
177
+ gitPackBytes,
178
+ checkpointBytes: bytes.byteLength - metadataBytes - gitPackBytes,
99
179
  };
100
180
  }
101
- /** Card identity from the ledger only.
102
- * Remotes deliberately absent: seed metadata, not identity.
103
- * Bundle bytes deliberately absent: packing is not deterministic. */
181
+ /** Card identity from the ledger only. Remotes and transport data are absent. */
104
182
  export function deriveCardId(card, sha256Hex) {
105
183
  return sha256Hex(JSON.stringify({
106
184
  version: card.version,
@@ -109,9 +187,7 @@ export function deriveCardId(card, sha256Hex) {
109
187
  tags: card.tags,
110
188
  }));
111
189
  }
112
- /** Checkpoint identity from the diff base, the patch hashes, and each
113
- * untracked (path, mode, sha256) — never the untracked contents, so reused
114
- * entries derive identically. */
190
+ /** Checkpoint identity from its hashes, never duplicated byte encodings. */
115
191
  export function deriveCheckpointId(checkpoint, sha256Hex) {
116
192
  return sha256Hex(JSON.stringify({
117
193
  baseCommit: checkpoint.baseCommit,
@@ -122,6 +198,5 @@ export function deriveCheckpointId(checkpoint, sha256Hex) {
122
198
  })),
123
199
  }));
124
200
  }
125
- /** The repository's semantic head: sha256(cardId + checkpointId). */
126
201
  export const deriveStateId = (cardId, checkpointId, sha256Hex) => sha256Hex(cardId + checkpointId);
127
202
  //# sourceMappingURL=repo-states.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"repo-states.js","sourceRoot":"","sources":["../../src/entities/repo-states.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;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CAC1B,IAA8D,EAC9D,SAAoB;IAEpB,OAAO,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;QAC9B,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC,CAAC;AACN,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,kBAAkB,CAChC,UAA8F,EAC9F,SAAoB;IAEpB,OAAO,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;QAC9B,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,WAAW,EAAE,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC;QAC9C,aAAa,EAAE,SAAS,CAAC,UAAU,CAAC,aAAa,CAAC;QAClD,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC7C,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM;SACtD,CAAC,CAAC;KACJ,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,YAAoB,EAAE,SAAoB,EAAU,EAAE,CAClG,SAAS,CAAC,MAAM,GAAG,YAAY,CAAC,CAAC"}
@@ -14,6 +14,9 @@ export interface TransferArtifact {
14
14
  readonly kind: ArtifactKind;
15
15
  readonly contentHash: string;
16
16
  }
17
+ /** Registration's type is the only transfer selector. */
18
+ export declare function artifactKindForType(type: EntityType): ArtifactKind | null;
19
+ export declare function assertTransferArtifact(artifact: TransferArtifact): void;
17
20
  /**
18
21
  * Select the one immutable artifact carried by a cloud entity record.
19
22
  * Deleted records are tombstones. A not-yet-captured leaf has no artifact yet.
@@ -1 +1 @@
1
- {"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../../src/transfer/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB,GAAG,IAAI,CAmCpF"}
1
+ {"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../../src/transfer/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,yDAAyD;AACzD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI,CAczE;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAKvE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB,GAAG,IAAI,CAiCpF"}
@@ -6,6 +6,28 @@
6
6
  * no independent byte artifact: their portable state is already in the graph.
7
7
  */
8
8
  const CONTENT_HEAD = /^[0-9a-f]{64}$/;
9
+ /** Registration's type is the only transfer selector. */
10
+ export function artifactKindForType(type) {
11
+ switch (type) {
12
+ case 'file.text':
13
+ case 'file.binary':
14
+ return 'file';
15
+ case 'link':
16
+ return 'link';
17
+ case 'repo.git':
18
+ return 'git';
19
+ case 'workspace':
20
+ case 'folder':
21
+ case 'reference':
22
+ return null;
23
+ }
24
+ }
25
+ export function assertTransferArtifact(artifact) {
26
+ const expected = artifactKindForType(artifact.entityType);
27
+ if (expected === null || artifact.kind !== expected) {
28
+ throw new Error(`entity type ${artifact.entityType} cannot use ${artifact.kind} transfer`);
29
+ }
30
+ }
9
31
  /**
10
32
  * Select the one immutable artifact carried by a cloud entity record.
11
33
  * Deleted records are tombstones. A not-yet-captured leaf has no artifact yet.
@@ -13,20 +35,19 @@ const CONTENT_HEAD = /^[0-9a-f]{64}$/;
13
35
  export function artifactForRecord(record) {
14
36
  if (record.status === 'deleted')
15
37
  return null;
16
- let kind;
38
+ const kind = artifactKindForType(record.type);
39
+ if (kind === null)
40
+ return null;
17
41
  let contentHash;
18
42
  switch (record.type) {
19
43
  case 'file.text':
20
44
  case 'file.binary':
21
- kind = 'file';
22
45
  contentHash = record.payloadVersion;
23
46
  break;
24
47
  case 'link':
25
- kind = 'link';
26
48
  contentHash = record.payloadVersion;
27
49
  break;
28
50
  case 'repo.git':
29
- kind = 'git';
30
51
  contentHash = record.transportVersion;
31
52
  break;
32
53
  case 'workspace':
@@ -1 +1 @@
1
- {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../src/transfer/artifacts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAWtC;;;GAGG;AACH,MAA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,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,CAAC,IAAI,+BAA+B,CAAC,CAAC;IACxE,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,IAAI;QACrB,UAAU,EAAE,MAAM,CAAC,IAAI;QACvB,IAAI;QACJ,WAAW;KACZ,CAAC;AACJ,CAAC"}
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { type ContentChunk, type ContentManifest } from '../contracts/content.js';
10
10
  import type { Sha256Hex } from '../entities/types.js';
11
- import type { TransferArtifact } from './artifacts.js';
11
+ import { type TransferArtifact } from './artifacts.js';
12
12
  export interface DownloadPorts<LocalArtifact> {
13
13
  readonly sha256Hex: Sha256Hex;
14
14
  getManifest(artifact: TransferArtifact): Promise<unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/transfer/download.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAwB,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACxG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,MAAM,WAAW,aAAa,CAAC,aAAa;IAC1C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1D,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,QAAQ,CACN,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,QAAQ,CAAC,KAAK,E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AAC,aAAa,CAAC,EACnC,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAqCzC"}
@@ -7,9 +7,11 @@
7
7
  * hash before returning a local handle.
8
8
  */
9
9
  import { checkContentManifest } from '../contracts/content.js';
10
+ import { assertTransferArtifact } from './artifacts.js';
10
11
  import { parallelForEach } from './parallel.js';
11
12
  /** Download one immutable artifact, fetching only machine-cache gaps. */
12
13
  export async function download(artifact, ports, options = {}) {
14
+ assertTransferArtifact(artifact);
13
15
  const checked = checkContentManifest(await ports.getManifest(artifact), artifact.contentHash);
14
16
  if (!checked.ok)
15
17
  throw new Error(checked.error);
@@ -1 +1 @@
1
- {"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/transfer/download.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAA2C,MAAM,yBAAyB,CAAC;AAGxG,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAsChD,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,QAA0B,EAC1B,KAAmC,EACnC,UAA2B,EAAE;IAE7B,MAAM,OAAO,GAAG,oBAAoB,CAClC,MAAM,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,EACjC,QAAQ,CAAC,WAAW,CACrB,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAE/B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC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,EAAE,KAAK,CAAC,CAAC;QAC9D,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;eAC7B,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC,KAAK;eACnC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,sBAAsB,CAAC,CAAC;QAC3E,CAAC;QACD,MAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,IAAI,MAAM,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,WAAW,sBAAsB,CAAC,CAAC;IACrF,CAAC;IACD,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,gBAAgB,EAAE,OAAO,CAAC,MAAM;QAChC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM;KACtD,CAAC;AACJ,CAAC"}
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { type ContentManifest } from '../contracts/content.js';
9
9
  import type { Sha256Hex } from '../entities/types.js';
10
- import type { TransferArtifact } from './artifacts.js';
10
+ import { type TransferArtifact } from './artifacts.js';
11
11
  export interface UploadSource {
12
12
  /** Exact byte count of the captured artifact named by `contentHash`. */
13
13
  readonly bytes: number;
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/transfer/upload.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAIL,KAAK,e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AAgB,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnF;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAyBD,2EAA2E;AAC3E,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAoDxB"}
@@ -6,6 +6,7 @@
6
6
  * committed last; until then a partial upload is invisible.
7
7
  */
8
8
  import { checkContentManifest, chunkSizes, manifestFromChunks, } from '../contracts/content.js';
9
+ import { assertTransferArtifact } from './artifacts.js';
9
10
  import { parallelForEach } from './parallel.js';
10
11
  const planChunks = (sizes) => {
11
12
  let offset = 0;
@@ -24,6 +25,7 @@ const readExact = async (source, chunk) => {
24
25
  };
25
26
  /** Upload one immutable artifact, sending only authority-declared gaps. */
26
27
  export async function upload(artifact, source, ports, options = {}) {
28
+ assertTransferArtifact(artifact);
27
29
  if (!Number.isSafeInteger(source.bytes) || source.bytes < 0) {
28
30
  throw new Error('upload source byte count is invalid');
29
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/transfer/upload.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,kBAAkB,GAEnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA+ChD,MAAM,UAAU,GAAG,CAA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;QACD,MAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5C,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,cAAc,EAAE,OAAO,CAAC,MAAM;QAC9B,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM;KACtD,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amalgm/live",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Portable realtime SDK for Amalgm — wire contracts, mutation discipline, and delivery state machines behind host-injected adapters.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",