@needmoretruth/nmts-cli 0.43.0 → 0.45.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.
Files changed (86) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +35 -0
  3. package/README.ko.md +8 -2
  4. package/README.md +8 -2
  5. package/dist/account.d.ts +7 -3
  6. package/dist/account.js +46 -19
  7. package/dist/arg-options.d.ts +22 -0
  8. package/dist/args.js +9 -3
  9. package/dist/artifact-about.d.ts +1 -1
  10. package/dist/commands/ai-account.d.ts +34 -0
  11. package/dist/commands/ai-account.js +260 -0
  12. package/dist/commands/balance.d.ts +68 -0
  13. package/dist/commands/balance.js +11 -1
  14. package/dist/commands/extend.d.ts +3 -0
  15. package/dist/commands/extend.js +1 -0
  16. package/dist/commands/get.d.ts +2 -0
  17. package/dist/commands/get.js +13 -1
  18. package/dist/commands/login.js +2 -2
  19. package/dist/commands/ls.d.ts +2 -0
  20. package/dist/commands/ls.js +18 -5
  21. package/dist/commands/push-wallet.js +4 -1
  22. package/dist/commands/push.d.ts +3 -0
  23. package/dist/commands/put-payer.d.ts +3 -1
  24. package/dist/commands/put-payer.js +13 -1
  25. package/dist/commands/put-thumbnail.d.ts +4 -0
  26. package/dist/commands/put-thumbnail.js +119 -0
  27. package/dist/commands/put-wallet.d.ts +33 -0
  28. package/dist/commands/put-wallet.js +86 -11
  29. package/dist/commands/put.d.ts +13 -0
  30. package/dist/commands/put.js +5 -0
  31. package/dist/commands/whoami.d.ts +4 -0
  32. package/dist/commands/whoami.js +14 -1
  33. package/dist/crypto-surface.d.ts +11 -0
  34. package/dist/crypto-surface.js +6 -0
  35. package/dist/drive-edit/trash.js +5 -3
  36. package/dist/drive-edit/tree.d.ts +18 -0
  37. package/dist/drive-edit/tree.js +35 -4
  38. package/dist/drive-erase.d.ts +5 -3
  39. package/dist/drive-erase.js +8 -3
  40. package/dist/drive-paths.d.ts +2 -2
  41. package/dist/drive-paths.js +2 -2
  42. package/dist/help-options.d.ts +2 -0
  43. package/dist/help-options.js +146 -0
  44. package/dist/help.js +10 -123
  45. package/dist/main.js +17 -19
  46. package/dist/mcp-tools/files.js +21 -2
  47. package/dist/mcp-tools/reads.js +13 -4
  48. package/dist/portable.d.ts +3 -2
  49. package/dist/portable.js +3 -2
  50. package/dist/product.d.ts +1 -1
  51. package/dist/product.js +1 -1
  52. package/dist/refill-source.d.ts +69 -0
  53. package/dist/refill-source.js +143 -0
  54. package/dist/risk.d.ts +12 -0
  55. package/dist/risk.js +16 -0
  56. package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
  57. package/dist/shared/lib/drive/manifest-codec.js +15 -23
  58. package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
  59. package/dist/shared/lib/drive/manifest-index.js +30 -8
  60. package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
  61. package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
  62. package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
  63. package/dist/shared/lib/drive/preview-classify.js +96 -0
  64. package/dist/shared/lib/wallet/activity.js +23 -1
  65. package/dist/standing-tip.d.ts +26 -0
  66. package/dist/standing-tip.js +31 -0
  67. package/dist/upload-wallet-plan.d.ts +8 -0
  68. package/dist/upload-wallet-plan.js +12 -3
  69. package/dist/upload-wallet-put.d.ts +2 -0
  70. package/dist/upload-wallet-put.js +1 -0
  71. package/dist/walrus.d.ts +9 -1
  72. package/dist/walrus.js +17 -3
  73. package/docs/commands/ai-account.md +25 -0
  74. package/docs/commands/get.md +3 -0
  75. package/docs/commands/login.md +4 -3
  76. package/docs/commands/ls.md +5 -0
  77. package/docs/commands/put.md +8 -0
  78. package/docs/commands/verify.md +1 -1
  79. package/docs/commands/whoami.md +4 -0
  80. package/examples/podman.sh +48 -0
  81. package/package.json +2 -1
  82. package/server.json +2 -2
  83. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +42 -6
  84. package/vendor/nmts-crypto/nmts_crypto_wasm.js +105 -2
  85. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  86. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +9 -4
@@ -0,0 +1,69 @@
1
+ import { type ListEditInput } from "./manifest-write.ts";
2
+ import type { Network } from "./network.ts";
3
+ import type { ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
4
+ /** The file a re-upload is built from, and exactly where the new one goes. */
5
+ export interface DriveOriginal {
6
+ /** The entry as the list holds it — the id that goes to the trash, and the key that opens it. */
7
+ entry: ManifestEntry;
8
+ /** The name the new file takes: the old one's, because this replaces it in place. */
9
+ name: string;
10
+ parentId: string | null;
11
+ /**
12
+ * The folder the new file goes in, spelled as a path.
13
+ *
14
+ * ⚠ IT IS PART OF THE RESERVATION KEY, so it has to be the same string on a second attempt at
15
+ * the same re-upload. Built from the list rather than from what somebody typed, which is what
16
+ * makes it stable: `--from ./docs/a.txt` and `--from docs/a.txt` are one file and one key.
17
+ */
18
+ destination: string;
19
+ }
20
+ /**
21
+ * The live file a drive path names, with the place the replacement goes.
22
+ *
23
+ * ⛔ A FOLDER, A TRASHED FILE AND A FILE WITH NO KEY ARE ALL REFUSED HERE, before anything is
24
+ * priced. Each one would fail later, after a price had been quoted and possibly after money had
25
+ * moved, and the third would fail in the worst place of all: the download.
26
+ */
27
+ export declare function findOriginal(entries: readonly ManifestEntry[], path: string): DriveOriginal;
28
+ /** Where a downloaded plaintext waits while it is being sealed again. */
29
+ export interface Scratch {
30
+ localPath: string;
31
+ /** Remove it. Safe to call twice, and called on every path out. */
32
+ remove: () => void;
33
+ }
34
+ /**
35
+ * Read one file out of the account and leave it on this machine, checked.
36
+ *
37
+ * ⛔ THE SAME READ `nmts get` MAKES, including the whole-file hash. A re-upload that sealed bytes
38
+ * the download had not proved would replace a good file with a corrupt one and put the good one
39
+ * in the trash — the one outcome this command must never produce.
40
+ */
41
+ export declare function downloadForRefill(input: {
42
+ server: string;
43
+ apiKey: string;
44
+ code: string;
45
+ network: Network;
46
+ original: DriveOriginal;
47
+ }): Promise<Scratch>;
48
+ /**
49
+ * Give the new file the old one's name and put the old one in the trash — after the upload, in one
50
+ * write.
51
+ *
52
+ * ⛔ WHY IT IS A SECOND WRITE AND NOT AN OVERWRITE ON THE COMMIT. `collision.ts` refuses to let a
53
+ * per-run answer of "overwrite" take effect while this machine is in the default mode, on
54
+ * purpose: a program passing a flag must not be able to destroy a file. That rule is not worked
55
+ * around here. The upload lands as an ordinary addition — numbered beside the original if the
56
+ * machine renames — and only then, with the paid-for bytes safely in the list, is the name moved
57
+ * across and the original trashed. A person named the file they were replacing; nothing here
58
+ * decides that for anybody.
59
+ *
60
+ * ⛔ AND THE ORDER IS THE ONE THE WHOLE TOOL KEEPS: the new file is committed first, so a failure
61
+ * anywhere in this step leaves both files in the drive rather than neither. Running the same
62
+ * command again is not the repair for that — the file is already there under a numbered name —
63
+ * so what a failure here costs is a rename somebody does by hand, never bytes.
64
+ *
65
+ * ⚠ IT IS DECIDED AGAIN ON EVERY ATTEMPT of the compare-and-swap, which is what makes it safe to
66
+ * replay: a list where another device already trashed the original, or where this run's own
67
+ * earlier attempt already renamed the new file, produces no intent for that half.
68
+ */
69
+ export declare function settleRefill(input: ListEditInput, original: DriveOriginal, newItemId: string): Promise<number>;
@@ -0,0 +1,143 @@
1
+ // Taking a file that credits paid for and handing it back as something a wallet can pay for:
2
+ // finding it in the sealed list, and getting its plaintext onto this machine once.
3
+ //
4
+ // ⛔ WHY IT IS A DOWNLOAD AND A RE-SEAL RATHER THAN A MOVE. Storage on the network is bought for
5
+ // particular bytes under a particular blob id, and the treasury owns the storage under a
6
+ // credit-paid part. Nothing on the chain can transfer that object to somebody's own wallet, and
7
+ // nothing in NMTS can re-point an existing part at storage bought elsewhere. So the only honest
8
+ // shape is: read the file out, seal it again, buy storage for the new sealing, and let the old
9
+ // file go to the trash — which is what `put --pay wallet --from <path>` does.
10
+ //
11
+ // ⛔ THE PLAINTEXT LANDS IN THIS TOOL'S OWN DIRECTORY, NOT IN THE SYSTEM TEMPORARY ONE. It is
12
+ // somebody's decrypted file; `/tmp` is world-listable on every machine this runs on, and a name
13
+ // other accounts can see is a name they can watch for. The config directory is 0700 where the
14
+ // platform honours it, the file itself is 0600 (`fileSink`), and it is removed on every path out
15
+ // including the failing ones.
16
+ //
17
+ // ⚠ IT IS A COPY ON DISK FOR AS LONG AS THE UPLOAD TAKES, and that is the price of not holding a
18
+ // whole file in memory. A caller who cannot pay it should download and upload by hand, which is
19
+ // the same two acts with the copy in a place they chose.
20
+ import { mkdirSync, rmSync } from "node:fs";
21
+ import { randomBytes } from "node:crypto";
22
+ import { join } from "node:path";
23
+ import { configDir } from "./credentials.js";
24
+ import { setTrashed } from "./item-trash.js";
25
+ import { applyManyToList } from "./manifest-write.js";
26
+ import { fetchFile } from "./download.js";
27
+ import { fileSink } from "./download-sink-node.js";
28
+ import { buildIndex, entryAt, fullPathOf, isLive, KIND_FILE, normalisePath } from "./drive-paths.js";
29
+ import { NmtsError } from "./errors.js";
30
+ import { BINARY_NAME } from "./product.js";
31
+ /**
32
+ * The live file a drive path names, with the place the replacement goes.
33
+ *
34
+ * ⛔ A FOLDER, A TRASHED FILE AND A FILE WITH NO KEY ARE ALL REFUSED HERE, before anything is
35
+ * priced. Each one would fail later, after a price had been quoted and possibly after money had
36
+ * moved, and the third would fail in the worst place of all: the download.
37
+ */
38
+ export function findOriginal(entries, path) {
39
+ const wanted = normalisePath(path);
40
+ const index = buildIndex(entries);
41
+ const entry = entryAt(entries, wanted, { nothingHappened: "Nothing was signed and nothing was sent." });
42
+ if (entry.kind !== KIND_FILE) {
43
+ throw new NmtsError(`"${wanted}" is a folder.`, {
44
+ exitCode: 4,
45
+ nextStep: `Nothing was signed. --from takes one file at a time.`,
46
+ });
47
+ }
48
+ if (!isLive(index, entry)) {
49
+ throw new NmtsError(`"${wanted}" is in the trash.`, {
50
+ exitCode: 4,
51
+ nextStep: `Nothing was signed. \`${BINARY_NAME} restore\` brings it back, and then this can re-upload it.`,
52
+ });
53
+ }
54
+ if (entry.dekWrapped === undefined) {
55
+ throw new NmtsError(`The file list holds no key for "${wanted}".`, {
56
+ exitCode: 4,
57
+ nextStep: `Nothing was signed. Without it nothing can open the stored bytes, so there is nothing to re-seal.`,
58
+ });
59
+ }
60
+ const full = fullPathOf(index, entry);
61
+ return {
62
+ entry,
63
+ name: entry.name,
64
+ parentId: entry.parentId,
65
+ destination: full.slice(0, Math.max(0, full.length - entry.name.length)).replace(/\/$/, ""),
66
+ };
67
+ }
68
+ /**
69
+ * Read one file out of the account and leave it on this machine, checked.
70
+ *
71
+ * ⛔ THE SAME READ `nmts get` MAKES, including the whole-file hash. A re-upload that sealed bytes
72
+ * the download had not proved would replace a good file with a corrupt one and put the good one
73
+ * in the trash — the one outcome this command must never produce.
74
+ */
75
+ export async function downloadForRefill(input) {
76
+ const { entry } = input.original;
77
+ const dekWrapped = entry.dekWrapped;
78
+ if (dekWrapped === undefined)
79
+ throw new NmtsError("unreachable: an original with no key");
80
+ const area = join(configDir(), "refill");
81
+ mkdirSync(area, { recursive: true, mode: 0o700 });
82
+ const localPath = join(area, `${randomBytes(9).toString("hex")}.part`);
83
+ const remove = () => rmSync(localPath, { force: true });
84
+ try {
85
+ await fetchFile({
86
+ base: input.server,
87
+ apiKey: input.apiKey,
88
+ accountCode: input.code,
89
+ itemId: entry.id,
90
+ size: entry.size,
91
+ dekWrapped,
92
+ ...(entry.contentHashCt === undefined ? {} : { contentHashCt: entry.contentHashCt }),
93
+ chain: input.network,
94
+ sink: fileSink(localPath, { force: true }),
95
+ });
96
+ }
97
+ catch (error) {
98
+ remove();
99
+ throw error;
100
+ }
101
+ return { localPath, remove };
102
+ }
103
+ /**
104
+ * Give the new file the old one's name and put the old one in the trash — after the upload, in one
105
+ * write.
106
+ *
107
+ * ⛔ WHY IT IS A SECOND WRITE AND NOT AN OVERWRITE ON THE COMMIT. `collision.ts` refuses to let a
108
+ * per-run answer of "overwrite" take effect while this machine is in the default mode, on
109
+ * purpose: a program passing a flag must not be able to destroy a file. That rule is not worked
110
+ * around here. The upload lands as an ordinary addition — numbered beside the original if the
111
+ * machine renames — and only then, with the paid-for bytes safely in the list, is the name moved
112
+ * across and the original trashed. A person named the file they were replacing; nothing here
113
+ * decides that for anybody.
114
+ *
115
+ * ⛔ AND THE ORDER IS THE ONE THE WHOLE TOOL KEEPS: the new file is committed first, so a failure
116
+ * anywhere in this step leaves both files in the drive rather than neither. Running the same
117
+ * command again is not the repair for that — the file is already there under a numbered name —
118
+ * so what a failure here costs is a rename somebody does by hand, never bytes.
119
+ *
120
+ * ⚠ IT IS DECIDED AGAIN ON EVERY ATTEMPT of the compare-and-swap, which is what makes it safe to
121
+ * replay: a list where another device already trashed the original, or where this run's own
122
+ * earlier attempt already renamed the new file, produces no intent for that half.
123
+ */
124
+ export async function settleRefill(input, original, newItemId) {
125
+ const at = Date.now();
126
+ const result = await applyManyToList(input, (entries) => {
127
+ const intents = [];
128
+ const old = entries.find((e) => e.id === original.entry.id);
129
+ if (old !== undefined && old.deletedAt === undefined) {
130
+ intents.push({ op: "trash", ids: [original.entry.id], at });
131
+ }
132
+ const fresh = entries.find((e) => e.id === newItemId);
133
+ if (fresh !== undefined && fresh.name !== original.name) {
134
+ intents.push({ op: "rename", id: newItemId, name: original.name, at });
135
+ }
136
+ return intents;
137
+ });
138
+ // ⛔ THE SERVER IS TOLD LAST, and a 404 there is "already in that state" (`item-trash.ts`). Until
139
+ // this line the original is a live row the account still holds — which is the harmless
140
+ // direction: it is restorable, it still expires on its own, and `nmts rm` finishes the job.
141
+ await setTrashed(input.server, input.apiKey, original.entry.id, true);
142
+ return result.seq;
143
+ }
package/dist/risk.d.ts CHANGED
@@ -50,6 +50,9 @@ export declare const ACTS: {
50
50
  readonly losses: {
51
51
  readonly tier: "none";
52
52
  };
53
+ readonly "ai-account": {
54
+ readonly tier: "none";
55
+ };
53
56
  readonly "public-code": {
54
57
  readonly tier: "none";
55
58
  };
@@ -335,6 +338,10 @@ export declare const ACTS: {
335
338
  readonly what: "Create a new account under the Terms in force.";
336
339
  readonly asksItself: true;
337
340
  };
341
+ readonly "ai-account.create": {
342
+ readonly tier: "high";
343
+ readonly what: "Make a new account for an AI to work in, under the Terms in force.";
344
+ };
338
345
  readonly "accept-terms.accept": {
339
346
  readonly tier: "high";
340
347
  readonly what: "Accept a new version of the Terms for this account.";
@@ -345,6 +352,11 @@ export declare const ACTS: {
345
352
  readonly what: "Erase this account's server record, permanently.";
346
353
  readonly asksItself: true;
347
354
  };
355
+ readonly "ai-account.delete": {
356
+ readonly tier: "ultra-high";
357
+ readonly what: "Erase an AI account this one made, and everything in it, permanently.";
358
+ readonly asksItself: true;
359
+ };
348
360
  readonly erase: {
349
361
  readonly tier: "ultra-high";
350
362
  readonly what: "Erase files for good: the server's record and this account's key to them.";
package/dist/risk.js CHANGED
@@ -35,6 +35,9 @@ export const ACTS = {
35
35
  trial: { tier: "none" },
36
36
  expiring: { tier: "none" },
37
37
  losses: { tier: "none" },
38
+ // Reading which accounts this one has made for an AI. The two acts that change something are
39
+ // below, under the tiers they belong to.
40
+ "ai-account": { tier: "none" },
38
41
  "public-code": { tier: "none" },
39
42
  wallet: { tier: "none" },
40
43
  get: { tier: "none" },
@@ -132,9 +135,20 @@ export const ACTS = {
132
135
  "whoami.reveal": { tier: "high", lock: "reveal", what: "Print the NMTS key on this screen." },
133
136
  kit: { tier: "high", lock: "kit", what: "Write the NMTS key into a recovery kit file on this disk." },
134
137
  create: { tier: "high", what: "Create a new account under the Terms in force.", asksItself: true },
138
+ // ⛔ BESIDE `create`, BECAUSE IT IS THE SAME ACT aimed at a new account: it makes an account under
139
+ // the Terms in force, and the acceptance recorded for it is this caller's own. It does not ask
140
+ // itself — there is no version for anybody to type, so the gate takes the yes.
141
+ "ai-account.create": { tier: "high", what: "Make a new account for an AI to work in, under the Terms in force." },
135
142
  "accept-terms.accept": { tier: "high", what: "Accept a new version of the Terms for this account.", asksItself: true },
136
143
  // ── ultra-high: permanent destruction ──
137
144
  "delete-account": { tier: "ultra-high", what: "Erase this account's server record, permanently.", asksItself: true },
145
+ // ⛔ THE SAME ERASURE, AIMED AT AN ACCOUNT THIS ONE MADE — the row, the files, the keys and the
146
+ // shares in both directions. It types the same sentence `delete-account` does.
147
+ "ai-account.delete": {
148
+ tier: "ultra-high",
149
+ what: "Erase an AI account this one made, and everything in it, permanently.",
150
+ asksItself: true,
151
+ },
138
152
  erase: { tier: "ultra-high", what: "Erase files for good: the server's record and this account's key to them.", asksItself: true },
139
153
  "erase.release": {
140
154
  tier: "ultra-high",
@@ -190,6 +204,8 @@ export function actOf(args) {
190
204
  return args.pay === "wallet" ? "push.wallet" : "push";
191
205
  case "key":
192
206
  return sub === "new" ? "key.new" : sub === "revoke" ? "key.revoke" : "key";
207
+ case "ai-account":
208
+ return sub === "create" ? "ai-account.create" : sub === "delete" ? "ai-account.delete" : "ai-account";
193
209
  case "openers":
194
210
  return sub === "add" ? "openers.add" : sub === "remove" ? "openers.remove" : "openers";
195
211
  case "trial":
@@ -1,27 +1,7 @@
1
1
  import { TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT, type AccountSettings } from "./manifest-settings.ts";
2
+ import { type ShareReceipt, type WireShareReceipt } from "./manifest-wire-extras.ts";
2
3
  export { TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT };
3
- export type { AccountSettings };
4
- /**
5
- * One share this device made, kept where the server cannot reach it (`ManifestEntry.shares`).
6
- *
7
- * A receipt is written only AFTER the server's created row was checked to carry the very address
8
- * the sender typed — so what is stored is the address she asked for, never one the server chose.
9
- */
10
- export interface ShareReceipt {
11
- /** Recipient address in WIRE form: exactly what the create call was checked against. */
12
- address: string;
13
- /** When this device wrote the receipt, ms since the Unix epoch. This browser's clock. */
14
- at: number;
15
- /**
16
- * A revoke was sent for this receipt and the listing has not yet come back without the row.
17
- *
18
- * The receipt outlives the revoke ON PURPOSE: a revoke this side cannot verify is exactly the
19
- * case worth keeping, and a listing that still carries the address is the only evidence the
20
- * removal did not happen. Dropped once a listing no longer names it (`sharePrune`), which is
21
- * what keeps this array from growing forever.
22
- */
23
- revoked?: true;
24
- }
4
+ export type { AccountSettings, ShareReceipt };
25
5
  /** One entry — a file or a folder — as the rest of the app sees it. */
26
6
  export interface ManifestEntry {
27
7
  /** Item id. Files: the id the server assigned at commit. Folders: client-generated. */
@@ -100,6 +80,14 @@ export interface ManifestEntry {
100
80
  * log in the clear — the server is never handed a per-account value it could use as a handle.
101
81
  */
102
82
  labels?: string[];
83
+ /**
84
+ * This file is the preview picture of the video with this id: an
85
+ * ordinary file in every other way. Hidden wherever that video is in the list; shown once it is
86
+ * not, so a picture someone paid for never becomes an invisible orphan.
87
+ */
88
+ thumbOf?: string;
89
+ /** Wire keys this build does not know, written back verbatim (`manifest-wire-extras.ts`). */
90
+ carried?: Readonly<Record<string, unknown>>;
103
91
  }
104
92
  /**
105
93
  * Account-level settings that live INSIDE the sealed list.
@@ -174,15 +162,7 @@ export interface WireEntry {
174
162
  l?: string[];
175
163
  sn?: number;
176
164
  sh?: WireShareReceipt[];
177
- }
178
- /** One share receipt on the wire. Same short-key reason as the entry above it. */
179
- interface WireShareReceipt {
180
- /** address. */
181
- a: string;
182
- /** at. */
183
- t: number;
184
- /** revoked. */
185
- r?: 1;
165
+ to?: string;
186
166
  }
187
167
  export declare function toWire(e: ManifestEntry): WireEntry;
188
168
  export declare function fromWire(w: WireEntry): ManifestEntry;
@@ -17,6 +17,7 @@
17
17
  // codec round-trip suite and resolves no path aliases.
18
18
  import { NETWORK_WHEN_UNRECORDED } from "../storage-network.js";
19
19
  import { settingsFromWire, settingsToWire, TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT, } from "./manifest-settings.js";
20
+ import { carriedFromWire, sharesFromWire, sharesToWire, withCarried, } from "./manifest-wire-extras.js";
20
21
  export { TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT };
21
22
  /**
22
23
  * Current format version this build writes.
@@ -70,10 +71,11 @@ export function toWire(e) {
70
71
  // spelling it out would cost bytes on every file of every save to say nothing new.
71
72
  if (e.network !== undefined && e.network !== NETWORK_WHEN_UNRECORDED)
72
73
  w.sn = e.network;
73
- if (e.shares && e.shares.length > 0) {
74
- w.sh = e.shares.map((r) => (r.revoked ? { a: r.address, t: r.at, r: 1 } : { a: r.address, t: r.at }));
75
- }
76
- return w;
74
+ if (e.shares && e.shares.length > 0)
75
+ w.sh = sharesToWire(e.shares);
76
+ if (e.thumbOf !== undefined)
77
+ w.to = e.thumbOf;
78
+ return withCarried(w, e.carried);
77
79
  }
78
80
  export function fromWire(w) {
79
81
  const e = {
@@ -108,25 +110,15 @@ export function fromWire(w) {
108
110
  // "stored on Walrus" — a claim about someone else's bytes that nothing would ever correct.
109
111
  if (typeof w.sn === "number")
110
112
  e.network = w.sn;
111
- // Defensive in the same way labels are, and for a sharper reason: a receipt with a blank address
112
- // or a broken instant would be compared against the server's rows and could produce a warning
113
- // about a share nobody ever made. Anything unusable is dropped — a receipt that cannot be
114
- // checked says nothing, and saying nothing is the honest outcome.
115
- if (Array.isArray(w.sh)) {
116
- const clean = [];
117
- for (const raw of w.sh) {
118
- if (!raw || typeof raw !== "object")
119
- continue;
120
- const { a, t, r } = raw;
121
- if (typeof a !== "string" || a === "")
122
- continue;
123
- if (typeof t !== "number" || !Number.isFinite(t))
124
- continue;
125
- clean.push(r === 1 ? { address: a, at: t, revoked: true } : { address: a, at: t });
126
- }
127
- if (clean.length > 0)
128
- e.shares = clean;
129
- }
113
+ // Checked receipt by receipt — see `sharesFromWire` for why a broken one says nothing.
114
+ const shares = sharesFromWire(w.sh);
115
+ if (shares)
116
+ e.shares = shares;
117
+ if (typeof w.to === "string" && w.to !== "")
118
+ e.thumbOf = w.to;
119
+ const carried = carriedFromWire(w);
120
+ if (carried)
121
+ e.carried = carried;
130
122
  return e;
131
123
  }
132
124
  /** Thrown when the plaintext is not a manifest this build can read. */
@@ -8,9 +8,15 @@ export interface ManifestIndex {
8
8
  readonly byId: ReadonlyMap<string, ManifestEntry>;
9
9
  /** Direct children by parent id (root under its own key). Values keep list order. */
10
10
  readonly childrenByParent: ReadonlyMap<string, readonly ManifestEntry[]>;
11
+ /** Preview pictures whose video is in the list — no view below shows these. */
12
+ readonly hidden: ReadonlySet<string>;
13
+ /** Video id → its hidden preview pictures, so every act on a video can take them along. */
14
+ readonly previews: ReadonlyMap<string, readonly string[]>;
11
15
  }
12
16
  /** Build the lookup structures for one version of the list. Cost is linear; do it once. */
13
17
  export declare function buildIndex(entries: readonly ManifestEntry[]): ManifestIndex;
18
+ /** Would a view show this entry at all? False only for a preview picture whose video is listed. */
19
+ export declare function shown(index: ManifestIndex, entry: ManifestEntry): boolean;
14
20
  /**
15
21
  * The instant this item became trash — its own, or the nearest trashed ancestor's.
16
22
  * `null` means live. A parent chain that is broken or looping counts as live at the point it
@@ -94,5 +100,8 @@ export interface DriveTotals {
94
100
  /** Bytes held by trashed files — the figure that explains "deleting did not free space yet". */
95
101
  trashedBytes: number;
96
102
  }
97
- /** Whole-drive counts. Exact, because the list is complete by construction. */
103
+ /**
104
+ * Whole-drive counts. Exact, because the list is complete by construction.
105
+ * ⚠ A hidden preview picture is not counted: the totals describe what the lists show.
106
+ */
98
107
  export declare function totalsOf(index: ManifestIndex): DriveTotals;
@@ -16,7 +16,23 @@ export function buildIndex(entries) {
16
16
  else
17
17
  childrenByParent.set(key, [e]);
18
18
  }
19
- return { all: entries, byId, childrenByParent };
19
+ const hidden = new Set();
20
+ const previews = new Map();
21
+ for (const e of entries) {
22
+ if (e.thumbOf === undefined || e.thumbOf === e.id || byId.get(e.thumbOf)?.kind !== KIND_FILE)
23
+ continue;
24
+ hidden.add(e.id);
25
+ const bucket = previews.get(e.thumbOf);
26
+ if (bucket)
27
+ bucket.push(e.id);
28
+ else
29
+ previews.set(e.thumbOf, [e.id]);
30
+ }
31
+ return { all: entries, byId, childrenByParent, hidden, previews };
32
+ }
33
+ /** Would a view show this entry at all? False only for a preview picture whose video is listed. */
34
+ export function shown(index, entry) {
35
+ return !index.hidden.has(entry.id);
20
36
  }
21
37
  /**
22
38
  * The instant this item became trash — its own, or the nearest trashed ancestor's.
@@ -54,7 +70,7 @@ export function isLive(index, entry) {
54
70
  * writes the live drive, so a drive whose every file is in the trash has nothing to export.
55
71
  */
56
72
  export function hasLiveFile(index) {
57
- return index.all.some((e) => e.kind === KIND_FILE && isLive(index, e));
73
+ return index.all.some((e) => e.kind === KIND_FILE && shown(index, e) && isLive(index, e));
58
74
  }
59
75
  /**
60
76
  * Live children of a folder (`null` = drive root), in list order.
@@ -64,7 +80,7 @@ export function childrenOf(index, parentId) {
64
80
  const bucket = index.childrenByParent.get(parentId ?? ROOT);
65
81
  if (!bucket)
66
82
  return [];
67
- return bucket.filter((e) => isLive(index, e));
83
+ return bucket.filter((e) => shown(index, e) && isLive(index, e));
68
84
  }
69
85
  /**
70
86
  * What the trash view shows: items the person deleted directly, newest first.
@@ -72,7 +88,7 @@ export function childrenOf(index, parentId) {
72
88
  */
73
89
  export function trashRoots(index) {
74
90
  const roots = index.all.filter((e) => {
75
- if (e.deletedAt === undefined)
91
+ if (e.deletedAt === undefined || !shown(index, e))
76
92
  return false;
77
93
  if (e.parentId === null)
78
94
  return true;
@@ -159,7 +175,7 @@ export function searchByName(index, query, limit = 500) {
159
175
  break;
160
176
  if (!e.name.toLocaleLowerCase().includes(needle))
161
177
  continue;
162
- if (!isLive(index, e))
178
+ if (!shown(index, e) || !isLive(index, e))
163
179
  continue;
164
180
  out.push(e);
165
181
  }
@@ -173,7 +189,7 @@ export function searchByName(index, query, limit = 500) {
173
189
  */
174
190
  export function favoriteFiles(index) {
175
191
  return index.all
176
- .filter((e) => e.kind === KIND_FILE && e.favorite === true && isLive(index, e))
192
+ .filter((e) => e.kind === KIND_FILE && e.favorite === true && shown(index, e) && isLive(index, e))
177
193
  .slice()
178
194
  .sort((a, b) => b.updatedAt - a.updatedAt);
179
195
  }
@@ -188,7 +204,7 @@ export function labelCounts(index) {
188
204
  for (const e of index.all) {
189
205
  if (e.kind !== KIND_FILE || !e.labels || e.labels.length === 0)
190
206
  continue;
191
- if (!isLive(index, e))
207
+ if (!shown(index, e) || !isLive(index, e))
192
208
  continue;
193
209
  for (const label of e.labels)
194
210
  counts.set(label, (counts.get(label) ?? 0) + 1);
@@ -202,11 +218,15 @@ export function filesWithLabel(index, label) {
202
218
  return index.all
203
219
  .filter((e) => e.kind === KIND_FILE &&
204
220
  (e.labels ?? []).includes(label) &&
221
+ shown(index, e) &&
205
222
  isLive(index, e))
206
223
  .slice()
207
224
  .sort((a, b) => b.updatedAt - a.updatedAt);
208
225
  }
209
- /** Whole-drive counts. Exact, because the list is complete by construction. */
226
+ /**
227
+ * Whole-drive counts. Exact, because the list is complete by construction.
228
+ * ⚠ A hidden preview picture is not counted: the totals describe what the lists show.
229
+ */
210
230
  export function totalsOf(index) {
211
231
  const totals = {
212
232
  files: 0,
@@ -216,6 +236,8 @@ export function totalsOf(index) {
216
236
  trashedBytes: 0,
217
237
  };
218
238
  for (const e of index.all) {
239
+ if (!shown(index, e))
240
+ continue;
219
241
  const live = isLive(index, e);
220
242
  if (e.kind === KIND_FOLDER) {
221
243
  if (live)
@@ -0,0 +1,50 @@
1
+ /**
2
+ * One share this device made, kept where the server cannot reach it (`ManifestEntry.shares`).
3
+ *
4
+ * A receipt is written only AFTER the server's created row was checked to carry the very address
5
+ * the sender typed — so what is stored is the address she asked for, never one the server chose.
6
+ */
7
+ export interface ShareReceipt {
8
+ /** Recipient address in WIRE form: exactly what the create call was checked against. */
9
+ address: string;
10
+ /** When this device wrote the receipt, ms since the Unix epoch. This browser's clock. */
11
+ at: number;
12
+ /**
13
+ * A revoke was sent for this receipt and the listing has not yet come back without the row.
14
+ *
15
+ * The receipt outlives the revoke ON PURPOSE: a revoke this side cannot verify is exactly the
16
+ * case worth keeping, and a listing that still carries the address is the only evidence the
17
+ * removal did not happen. Dropped once a listing no longer names it (`sharePrune`), which is
18
+ * what keeps this array from growing forever.
19
+ */
20
+ revoked?: true;
21
+ }
22
+ /** One share receipt on the wire. Same short-key reason as the entry it sits on. */
23
+ export interface WireShareReceipt {
24
+ /** address. */
25
+ a: string;
26
+ /** at. */
27
+ t: number;
28
+ /** revoked. */
29
+ r?: 1;
30
+ }
31
+ export declare function sharesToWire(shares: readonly ShareReceipt[]): WireShareReceipt[];
32
+ /**
33
+ * Receipts that can be checked, or `undefined` when none can.
34
+ *
35
+ * Defensive for a sharp reason: a receipt with a blank address or a broken instant would be
36
+ * compared against the server's rows and could produce a warning about a share nobody ever made.
37
+ * Anything unusable is dropped — a receipt that cannot be checked says nothing, and saying nothing
38
+ * is the honest outcome.
39
+ */
40
+ export declare function sharesFromWire(raw: unknown): ShareReceipt[] | undefined;
41
+ /**
42
+ * Every entry key this build reads. ⛔ A key added to `WireEntry` and not here would ALSO be
43
+ * carried, and a mark this build clears would come back from the carried copy on the next save —
44
+ * the codec test pins the two lists together.
45
+ */
46
+ export declare const KNOWN_ENTRY_KEYS: ReadonlySet<string>;
47
+ /** The keys of a wire entry this build does not know, or `undefined` when there are none. */
48
+ export declare function carriedFromWire(w: object): Readonly<Record<string, unknown>> | undefined;
49
+ /** `w` with the carried keys laid UNDER it — a key this build writes always wins over one it carries. */
50
+ export declare function withCarried<T extends object>(w: T, carried: Readonly<Record<string, unknown>> | undefined): T;
@@ -0,0 +1,65 @@
1
+ // NMF-1 — the parts of an entry's wire form that are not its core facts. ⚠ PUBLISHED — copied
2
+ // byte-for-byte into the `nmts` command-line package with the codec that imports it; keep comments
3
+ // self-contained English.
4
+ //
5
+ // Two things live here, apart from `manifest-codec.ts` only because that file is at its length
6
+ // ceiling: the share receipts (their own small wire shape) and the CARRY rule for keys this build
7
+ // does not know.
8
+ //
9
+ // THE CARRY RULE. An entry key this build has never heard of is kept verbatim on the entry and
10
+ // written back on the next save. Before it, a key was dropped when read, so an older build that
11
+ // SAVED rewrote every entry without the newer build's fields — a stale tab could clear stars,
12
+ // labels and anything added later. ⚠ It protects only from THIS build onward: a build without
13
+ // this rule still drops what it does not know. That is why every optional field must still be
14
+ // safe to lose (see `MANIFEST_FORMAT_VERSION`).
15
+ export function sharesToWire(shares) {
16
+ return shares.map((r) => (r.revoked ? { a: r.address, t: r.at, r: 1 } : { a: r.address, t: r.at }));
17
+ }
18
+ /**
19
+ * Receipts that can be checked, or `undefined` when none can.
20
+ *
21
+ * Defensive for a sharp reason: a receipt with a blank address or a broken instant would be
22
+ * compared against the server's rows and could produce a warning about a share nobody ever made.
23
+ * Anything unusable is dropped — a receipt that cannot be checked says nothing, and saying nothing
24
+ * is the honest outcome.
25
+ */
26
+ export function sharesFromWire(raw) {
27
+ if (!Array.isArray(raw))
28
+ return undefined;
29
+ const clean = [];
30
+ for (const item of raw) {
31
+ if (!item || typeof item !== "object")
32
+ continue;
33
+ const a = "a" in item ? item.a : undefined;
34
+ const t = "t" in item ? item.t : undefined;
35
+ const r = "r" in item ? item.r : undefined;
36
+ if (typeof a !== "string" || a === "")
37
+ continue;
38
+ if (typeof t !== "number" || !Number.isFinite(t))
39
+ continue;
40
+ clean.push(r === 1 ? { address: a, at: t, revoked: true } : { address: a, at: t });
41
+ }
42
+ return clean.length > 0 ? clean : undefined;
43
+ }
44
+ /**
45
+ * Every entry key this build reads. ⛔ A key added to `WireEntry` and not here would ALSO be
46
+ * carried, and a mark this build clears would come back from the carried copy on the next save —
47
+ * the codec test pins the two lists together.
48
+ */
49
+ export const KNOWN_ENTRY_KEYS = new Set([
50
+ "i", "p", "k", "n", "s", "c", "u", "d", "w", "h", "f", "pn", "l", "sn", "sh", "to",
51
+ ]);
52
+ /** The keys of a wire entry this build does not know, or `undefined` when there are none. */
53
+ export function carriedFromWire(w) {
54
+ let carried;
55
+ for (const [key, value] of Object.entries(w)) {
56
+ if (KNOWN_ENTRY_KEYS.has(key))
57
+ continue;
58
+ (carried ??= {})[key] = value;
59
+ }
60
+ return carried;
61
+ }
62
+ /** `w` with the carried keys laid UNDER it — a key this build writes always wins over one it carries. */
63
+ export function withCarried(w, carried) {
64
+ return carried ? { ...carried, ...w } : w;
65
+ }