@needmoretruth/nmts-cli 0.44.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 (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/arg-options.d.ts +6 -0
  5. package/dist/args.js +4 -1
  6. package/dist/artifact-about.d.ts +1 -1
  7. package/dist/commands/get.d.ts +2 -0
  8. package/dist/commands/get.js +13 -1
  9. package/dist/commands/ls.d.ts +2 -0
  10. package/dist/commands/ls.js +18 -5
  11. package/dist/commands/put-thumbnail.d.ts +4 -0
  12. package/dist/commands/put-thumbnail.js +119 -0
  13. package/dist/commands/put-wallet.d.ts +2 -0
  14. package/dist/commands/put-wallet.js +3 -2
  15. package/dist/commands/put.d.ts +8 -0
  16. package/dist/commands/put.js +5 -0
  17. package/dist/drive-edit/trash.js +5 -3
  18. package/dist/drive-edit/tree.d.ts +6 -0
  19. package/dist/drive-edit/tree.js +10 -0
  20. package/dist/drive-erase.js +2 -2
  21. package/dist/drive-paths.d.ts +2 -2
  22. package/dist/drive-paths.js +2 -2
  23. package/dist/help-options.js +4 -0
  24. package/dist/main.js +3 -0
  25. package/dist/mcp-tools/files.js +21 -2
  26. package/dist/mcp-tools/reads.js +9 -1
  27. package/dist/portable.d.ts +2 -1
  28. package/dist/portable.js +2 -1
  29. package/dist/product.d.ts +1 -1
  30. package/dist/product.js +1 -1
  31. package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
  32. package/dist/shared/lib/drive/manifest-codec.js +15 -23
  33. package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
  34. package/dist/shared/lib/drive/manifest-index.js +30 -8
  35. package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
  36. package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
  37. package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
  38. package/dist/shared/lib/drive/preview-classify.js +96 -0
  39. package/dist/upload-wallet-put.d.ts +2 -0
  40. package/dist/upload-wallet-put.js +1 -0
  41. package/docs/commands/get.md +3 -0
  42. package/docs/commands/ls.md +5 -0
  43. package/docs/commands/put.md +8 -0
  44. package/package.json +1 -1
  45. package/server.json +2 -2
package/dist/portable.js CHANGED
@@ -43,7 +43,7 @@ export { isCryptoGlue, missingExports } from "./crypto-surface.js";
43
43
  // The sealed file list: reading it, editing it, and walking it by path.
44
44
  export { readFileList } from "./manifest.js";
45
45
  export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.js";
46
- export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, trashedAt, } from "./drive-paths.js";
46
+ export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.js";
47
47
  export { setTrashed } from "./item-trash.js";
48
48
  // The Platform's two credentials: a business's signature over one request, and the delegation
49
49
  // token it mints for one of its users. Making either needs no host and no server — a business
@@ -84,6 +84,7 @@ export { signerAddress, signExtension, signTransfer } from "./wallet-sign.js";
84
84
  // numbers as `nmts wallet list` — a second walk, or a second reading of the setting, would be a
85
85
  // second answer to a question that has to have exactly one.
86
86
  export { activeWalletOf, walletCountOf, WALLET_INDEX_LIMIT } from "./shared/lib/drive/manifest-settings.js";
87
+ export { classify } from "./shared/lib/drive/preview-classify.js";
87
88
  export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.js";
88
89
  export { hasHistory } from "./wallet-list-chain.js";
89
90
  // What this package is.
package/dist/product.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare const BINARY_NAME = "nmts";
9
9
  * beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
10
10
  * command importing the entry point is a cycle waiting to bite.
11
11
  */
12
- export declare const VERSION = "0.44.0";
12
+ export declare const VERSION = "0.45.0";
13
13
  /** Where the product lives, for messages that need to send somebody somewhere real. */
14
14
  export declare const HOME_URL = "https://nmts.me";
15
15
  /** The source, so a person holding only the built program can find what it was built from. */
package/dist/product.js CHANGED
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
18
18
  * beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
19
19
  * command importing the entry point is a cycle waiting to bite.
20
20
  */
21
- export const VERSION = "0.44.0";
21
+ export const VERSION = "0.45.0";
22
22
  /** Where the product lives, for messages that need to send somebody somewhere real. */
23
23
  export const HOME_URL = "https://nmts.me";
24
24
  /** The source, so a person holding only the built program can find what it was built from. */
@@ -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
+ }
@@ -0,0 +1,17 @@
1
+ /** How a file may be shown. `none` means "not previewed", which is a valid and often correct answer. */
2
+ export type PreviewKind = "image" | "video" | "audio" | "text" | "pdf" | "none";
3
+ /**
4
+ * Decide how a file named `name` may be shown, from its extension alone.
5
+ *
6
+ * Extension-only is deliberate: the alternative is sniffing the decrypted bytes, which means
7
+ * deciding "is this really a PNG?" on content an attacker chose. An extension the person can see
8
+ * in their own file list is a worse signal about the format and a much better one about intent —
9
+ * and every branch below is safe even when the extension lies, because none of them hands the
10
+ * bytes to a renderer that would execute them.
11
+ *
12
+ * Unknown ⇒ `none`. The default must be refusal, never a guess about whether a format can execute.
13
+ */
14
+ export declare function classify(name: string): {
15
+ kind: PreviewKind;
16
+ mime: string;
17
+ };
@@ -0,0 +1,96 @@
1
+ // The one decision that decides whether a previewed file can run code. Split out of
2
+ // FilePreview.tsx during the E-stage audit (2026-07-28) so it can be tested on every commit —
3
+ // `node --test` cannot load a `.tsx`, which is the whole reason this rule went untested for as
4
+ // long as it did.
5
+ //
6
+ // WHY IT MATTERS MORE HERE THAN IN AN ORDINARY VIEWER. A file in this drive can come from ANOTHER
7
+ // PERSON (private shares). Rendering one as a live document would run it in OUR origin, and this
8
+ // origin's IndexedDB is where "remember this device" keeps the account code. Stored XSS on an E2EE
9
+ // drive is not defacement — it is key theft, and the account code has no reset (GUIDE invariant
10
+ // #10).
11
+ //
12
+ // The rendering side of the contract, in FilePreview.tsx:
13
+ // · image → `<img src=blob:>` — an <img> never executes its contents, whatever the bytes are
14
+ // · text → textContent in `<pre>` — React escapes; NEVER innerHTML
15
+ // · pdf → `<iframe sandbox="">` — no scripts, opaque origin, download fallback beside it
16
+ // · video → `<video src=blob:>` — a media element plays its bytes, it never executes them
17
+ // · audio → `<audio src=blob:>` — the same, for sound
18
+ // · none → not previewed at all — the honest fallback points at the download
19
+ //
20
+ // ⭐ 2026-09-22 (C30 ①): video and audio joined so the gallery (image ∪ video) and the music place
21
+ // (audio) can gather files by kind. Stage ① gives them no player yet — FilePreview still treats
22
+ // both as "not previewed" until the streaming stages land.
23
+ //
24
+ // Pure: no DOM, no I/O, no state.
25
+ // ⚠ THE ORDER INSIDE `classify` IS THE SAFETY PROPERTY, not this table's contents.
26
+ // `svg` is present here, and only the early return below keeps it out of an
27
+ // `<img src=blob:image/svg+xml>`. Reorder those two lines — or delete the early return as
28
+ // "dead code, svg is right there in the table" — and an SVG someone else sent becomes a live
29
+ // document that can read this origin. `web/test/preview-classify.test.ts` makes that fail.
30
+ const IMAGE_MIME = {
31
+ png: "image/png",
32
+ jpg: "image/jpeg",
33
+ jpeg: "image/jpeg",
34
+ gif: "image/gif",
35
+ webp: "image/webp",
36
+ avif: "image/avif",
37
+ bmp: "image/bmp",
38
+ svg: "image/svg+xml",
39
+ };
40
+ // ⚠ No video/audio format can carry script into a `<video>`/`<audio>` element, and none of these
41
+ // extensions is also a document format — which is what lets them sit AFTER the svg early return
42
+ // without an early return of their own.
43
+ const VIDEO_MIME = {
44
+ mp4: "video/mp4",
45
+ m4v: "video/mp4",
46
+ mov: "video/quicktime",
47
+ webm: "video/webm",
48
+ mkv: "video/x-matroska",
49
+ };
50
+ const AUDIO_MIME = {
51
+ mp3: "audio/mpeg",
52
+ m4a: "audio/mp4",
53
+ aac: "audio/aac",
54
+ flac: "audio/flac",
55
+ ogg: "audio/ogg",
56
+ opus: "audio/ogg",
57
+ wav: "audio/wav",
58
+ };
59
+ // HTML/SVG source files are TEXT here on purpose — shown as source, never rendered as a document.
60
+ const TEXT_EXT = new Set([
61
+ "txt", "text", "md", "markdown", "csv", "tsv", "json", "log", "xml",
62
+ "yaml", "yml", "ini", "conf", "toml", "js", "mjs", "ts", "css", "html", "htm", "svg",
63
+ ]);
64
+ /**
65
+ * Decide how a file named `name` may be shown, from its extension alone.
66
+ *
67
+ * Extension-only is deliberate: the alternative is sniffing the decrypted bytes, which means
68
+ * deciding "is this really a PNG?" on content an attacker chose. An extension the person can see
69
+ * in their own file list is a worse signal about the format and a much better one about intent —
70
+ * and every branch below is safe even when the extension lies, because none of them hands the
71
+ * bytes to a renderer that would execute them.
72
+ *
73
+ * Unknown ⇒ `none`. The default must be refusal, never a guess about whether a format can execute.
74
+ */
75
+ export function classify(name) {
76
+ const dot = name.lastIndexOf(".");
77
+ const ext = dot >= 0 ? name.slice(dot + 1).toLowerCase() : "";
78
+ if (ext === "svg")
79
+ return { kind: "text", mime: "text/plain" }; // source, not a rendered SVG
80
+ // Read through `hasOwn` so `constructor` or `__proto__` is never an extension; the second check is
81
+ // for the command-line build, which reads every index as possibly missing.
82
+ const image = Object.hasOwn(IMAGE_MIME, ext) ? IMAGE_MIME[ext] : undefined;
83
+ if (image !== undefined)
84
+ return { kind: "image", mime: image };
85
+ const video = Object.hasOwn(VIDEO_MIME, ext) ? VIDEO_MIME[ext] : undefined;
86
+ if (video !== undefined)
87
+ return { kind: "video", mime: video };
88
+ const audio = Object.hasOwn(AUDIO_MIME, ext) ? AUDIO_MIME[ext] : undefined;
89
+ if (audio !== undefined)
90
+ return { kind: "audio", mime: audio };
91
+ if (ext === "pdf")
92
+ return { kind: "pdf", mime: "application/pdf" };
93
+ if (TEXT_EXT.has(ext))
94
+ return { kind: "text", mime: "text/plain" };
95
+ return { kind: "none", mime: "application/octet-stream" };
96
+ }
@@ -54,6 +54,8 @@ export interface WalletPutFile {
54
54
  parentId: string | null;
55
55
  /** The destination AS TYPED — part of the reservation key, so both runs of a resume agree. */
56
56
  destination: string;
57
+ /** A video's preview picture: the video's item id, written on the entry as `thumbOf`. */
58
+ thumbOf?: string | undefined;
57
59
  }
58
60
  /** The chain, the signatures, the wire and the four things a caller may be told. */
59
61
  export interface WalletPutSeams {
@@ -194,6 +194,7 @@ export async function walletPut(ctx, file, seams = {}) {
194
194
  updatedAt: now,
195
195
  dekWrapped: result.entry.dekWrapped,
196
196
  contentHashCt: result.entry.contentHashCt,
197
+ ...(file.thumbOf !== undefined ? { thumbOf: file.thumbOf } : {}),
197
198
  },
198
199
  });
199
200
  // ⛔ ONLY NOW, AND EVERY PART — the same order the credit rail keeps and for the same reason: a
@@ -12,3 +12,6 @@ into place only once the hash matches, one part held in memory at a time. `--out
12
12
  to stdout and writes nothing; in that mode every line for a person, including `--json`, goes to
13
13
  stderr, binary bytes are refused when stdout is a terminal, and files over 64 MiB are refused
14
14
  because a pipe cannot be taken back.
15
+
16
+ `--thumbnail` fetches the video's preview picture instead of the video (the one `put --thumbnail`
17
+ or the browser sent with it). A video without one exits 4 and writes nothing.
@@ -14,3 +14,8 @@ already seen, or a different list at the same version. Report that and stop; it
14
14
 
15
15
  `nmts listfile` writes this machine's copy of the sealed file list out as a file (`--out`, or
16
16
  `--out -` for stdout). It is sealed: without the NMTS key it says nothing.
17
+
18
+ `--media image|video|audio` keeps only files of that kind, judged by the name's extension. A
19
+ video's preview picture is never a line of its own while its video is in the list: fetch it with
20
+ `nmts get <video> --thumbnail`. It goes to the trash, comes back and is erased with its video. A
21
+ picture whose video is gone is listed like any file, so it can still be deleted.
@@ -34,3 +34,11 @@ fit|whole|<object id>` uses a free storage resource the wallet holds for a one-p
34
34
  cuts it to size and leaves the rest free, `whole` binds all of it with the file. Do not choose
35
35
  `--storage` for the person: the leftover is their decision. `--epochs` and `--storage` without
36
36
  `--pay wallet` exit 2.
37
+
38
+ **`--thumbnail`** on a video also sends one frame of it as `<saved name>.thumb.jpg`: an ordinary
39
+ small file, priced, sealed and paid for like any other, linked to the video so every app shows it
40
+ as the video's tile. The frame is taken by `ffmpeg` (one second in, 512 px on the long side);
41
+ `--thumbnail-file <picture>` sends that picture instead. Without `ffmpeg` the video is still stored
42
+ and the output says why it went alone. `--dry-run` prices both. With `--json` the one object is
43
+ the video's, with the picture's result under `thumbnail` (`{"skipped": "<why>"}` when none went).
44
+ On a file that is not a video the flag sends nothing more.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needmoretruth/nmts-cli",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "Command-line and MCP access to NMTS (NeedMoreTruthStorage, https://nmts.me): open-source, end-to-end encrypted storage on the Walrus network. No fee to NMTS; you pay the network from your own wallet. For people and for their agents.",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
package/server.json CHANGED
@@ -6,13 +6,13 @@
6
6
  "url": "https://github.com/needmoretruth/nmts-cli",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.44.0",
9
+ "version": "0.45.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "registryBaseUrl": "https://registry.npmjs.org",
14
14
  "identifier": "@needmoretruth/nmts-cli",
15
- "version": "0.44.0",
15
+ "version": "0.45.0",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  },