@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
@@ -4,4 +4,72 @@ export interface BalanceOptions {
4
4
  json?: boolean;
5
5
  write?: (line: string) => void;
6
6
  }
7
+ /** What the narrow read answers. Everything is optional here because a server may be older. */
8
+ export interface Summary {
9
+ credits: {
10
+ remaining: number;
11
+ soonest_expiry: string | null;
12
+ file_cap: number;
13
+ daily_cap: number;
14
+ held: number;
15
+ deposits: number;
16
+ /**
17
+ * The deposit's two numbers, as the SERVER states them: the most one file may set aside, and
18
+ * what a file sets aside when nobody chose.
19
+ *
20
+ * ⛔ READ FROM THE ACCOUNT VIEW, NOT FROM A CONSTANT HERE, for the same reason the two
21
+ * ceilings above are: this build can be older than the server, and a number printed from a
22
+ * constant would be this tool's opinion rather than what the ledger will actually do.
23
+ */
24
+ deposit_max: number;
25
+ deposit_default: number;
26
+ };
27
+ quota: {
28
+ granted: number;
29
+ used: number;
30
+ };
31
+ storage: {
32
+ parts: number;
33
+ earliest_expiry_epoch: number | null;
34
+ };
35
+ terms: {
36
+ acceptance_required: boolean;
37
+ };
38
+ /**
39
+ * Whether this account was made UNDER another one — an AI account.
40
+ *
41
+ * ⛔ IT RIDES HERE BECAUSE THIS IS THE ONLY ACCOUNT VIEW A KEY CAN REACH. `whoami` would be the
42
+ * obvious home, and it cannot have it: that command answers with no server and no API key at
43
+ * all, so a fact only the server holds is one it can never print without becoming a different
44
+ * command. A server that predates the field says nothing, which reads as `false` — the state
45
+ * every account was in before AI accounts existed.
46
+ */
47
+ ai_account: boolean;
48
+ /**
49
+ * Whether this account asks its uploads to carry the recovery list into the storage network.
50
+ *
51
+ * ⛔ IT SAYS WHAT WAS ASKED FOR, NOT WHAT EXISTS. The switch is an intention; whether a copy is
52
+ * out there is a different fact this read does not carry.
53
+ *
54
+ * ⚠ A SERVER THAT PREDATES THE FIELD READS AS `false`, which is indistinguishable from a switch
55
+ * that is off. What reads it (`put --pay wallet`'s review) only ADDS a sentence when it is on,
56
+ * so the older server's answer costs a sentence and never states something untrue.
57
+ */
58
+ network_copy: boolean;
59
+ /** One row per stored file that has a deposit: what it set aside, and what has been spent of it. */
60
+ deposits: DepositRow[];
61
+ }
62
+ /** One file's deposit, as the account view lists it. */
63
+ interface DepositRow {
64
+ deposit_credits: number;
65
+ spent_credits: number;
66
+ }
67
+ /**
68
+ * The narrow account read, typed — for the other commands that need one number out of it.
69
+ *
70
+ * ⛔ ONE READER OF THIS ROUTE. A second command that narrowed the answer itself would be a second
71
+ * opinion about which fields a server is allowed to be missing.
72
+ */
73
+ export declare function readAccountSummary(server: string, apiKey: string): Promise<Summary>;
7
74
  export declare function balance(options?: BalanceOptions): Promise<number>;
75
+ export {};
@@ -64,9 +64,19 @@ function asSummary(value) {
64
64
  },
65
65
  terms: { acceptance_required: isRecord(terms) && terms["acceptance_required"] === true },
66
66
  ai_account: value["ai_account"] === true,
67
+ network_copy: value["network_copy"] === true,
67
68
  deposits: depositRows(credits["deposits"]),
68
69
  };
69
70
  }
71
+ /**
72
+ * The narrow account read, typed — for the other commands that need one number out of it.
73
+ *
74
+ * ⛔ ONE READER OF THIS ROUTE. A second command that narrowed the answer itself would be a second
75
+ * opinion about which fields a server is allowed to be missing.
76
+ */
77
+ export async function readAccountSummary(server, apiKey) {
78
+ return asSummary(await request(server, "/v1/account/summary", { token: apiKey }));
79
+ }
70
80
  /**
71
81
  * The per-file deposit rows, when the answer carries them.
72
82
  *
@@ -96,7 +106,7 @@ function plural(n, one, many) {
96
106
  export async function balance(options = {}) {
97
107
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
98
108
  const session = await openSession({ server: options.server, network: options.network });
99
- const summary = asSummary(await request(session.server, "/v1/account/summary", { token: session.apiKey }));
109
+ const summary = await readAccountSummary(session.server, session.apiKey);
100
110
  if (options.json === true) {
101
111
  say(JSON.stringify(summary));
102
112
  return 0;
@@ -27,6 +27,9 @@ export interface ExtendOptions {
27
27
  sign?: SignExtension;
28
28
  /** The instant to measure against. Passed in so one run reports one moment. */
29
29
  now?: number;
30
+ /** `--trust-server-tip-address`: let THIS SERVER name where the standing gift goes. Off unless
31
+ * typed, and only for a server the caller runs (`standing-tip.ts`). */
32
+ trustServerTipAddress?: boolean;
30
33
  /** ⚠ SEAMS, NOT OPTIONS — the standing tip's own read and signature. No flag reaches them. */
31
34
  tip?: Pick<StandingTipInput, "readDonation" | "sign">;
32
35
  /** `--wallet N`: which wallet pays, this run only. Absent = the account's own number. */
@@ -143,6 +143,7 @@ export async function extend(target, options = {}) {
143
143
  wallet: plan.wallet,
144
144
  paidWalFrost: budget.priceFrost,
145
145
  say: options.json === true ? (line) => void process.stderr.write(`${line}\n`) : say,
146
+ trustServerAddress: options.trustServerTipAddress === true,
146
147
  ...(options.tip ?? {}),
147
148
  });
148
149
  return 0;
@@ -11,6 +11,8 @@ export interface GetOptions {
11
11
  /** Overwrite an existing file. Off by default, and saying so is the point. */
12
12
  force?: boolean;
13
13
  json?: boolean;
14
+ /** Fetch the video's preview picture — the small JPEG uploaded with it — instead of the video. */
15
+ thumbnail?: boolean;
14
16
  write?: (line: string) => void;
15
17
  /** Where the file's own bytes go when `out` is `-`. Injectable so a test can read them. */
16
18
  stdout?: ByteDestination;
@@ -66,7 +66,9 @@ export async function get(target, options = {}) {
66
66
  const wanted = normalisePath(target);
67
67
  // ⚠ Looked up WITHOUT a kind filter on purpose: a path that names a folder must be told apart
68
68
  // from a path that names nothing, and a filtered lookup can only say "nothing is there".
69
- const entry = entryAt(list.manifest.entries, wanted, { nothingHappened: "Nothing was written." });
69
+ const named = entryAt(list.manifest.entries, wanted, { nothingHappened: "Nothing was written." });
70
+ // `--thumbnail`: the video's preview picture instead of the video.
71
+ const entry = options.thumbnail === true ? pictureOf(index, named) : named;
70
72
  if (entry.kind !== KIND_FILE) {
71
73
  throw new NmtsError(`No file at "${fullPathOf(index, entry)}".`, {
72
74
  exitCode: 4,
@@ -128,3 +130,13 @@ export async function get(target, options = {}) {
128
130
  }
129
131
  return 0;
130
132
  }
133
+ /** The preview picture uploaded with this video, or a refusal that says how one is made. */
134
+ function pictureOf(index, video) {
135
+ const picture = index.byId.get(index.previews.get(video.id)?.[0] ?? "");
136
+ if (picture !== undefined)
137
+ return picture;
138
+ throw new NmtsError(`"${fullPathOf(index, video)}" has no preview picture.`, {
139
+ exitCode: 4,
140
+ nextStep: `Nothing was written. \`${BINARY_NAME} put <video> --thumbnail\` sends one with a video.`,
141
+ });
142
+ }
@@ -58,12 +58,12 @@ export async function login(options = {}) {
58
58
  // line mode, where it echoes what is typed and swallows lines the next prompt never sees —
59
59
  // and this command asks up to three things with a check in the middle.
60
60
  const exit = await holdTerminal(async () => {
61
- const code = await readTheCode(options, server);
61
+ const typed = await readTheCode(options, server);
62
62
  // ⛔ CHECKED BEFORE IT IS WRITTEN. The engine verifies the code's own check symbol offline, so
63
63
  // a mistyped code fails here as "that is not a code" instead of being stored and coming
64
64
  // back later as a sign-in failure indistinguishable from a wrong password or a suspended
65
65
  // account.
66
- await assertUsableCode(code);
66
+ const code = await assertUsableCode(typed);
67
67
  if (options.env === true)
68
68
  return printEnvForm(code, say);
69
69
  // ⛔ THE KEY IS SETTLED BEFORE THE PASSPHRASE IS ASKED FOR, for the reason the code is checked
@@ -5,6 +5,8 @@ export interface LsOptions {
5
5
  json?: boolean;
6
6
  /** Include entries that are in the trash. */
7
7
  all?: boolean;
8
+ /** Only files of this kind — `image`, `video` or `audio`, judged by name as the gallery does. */
9
+ media?: string | undefined;
8
10
  /**
9
11
  * Keep only files whose name contains this text, case-insensitively.
10
12
  *
@@ -17,8 +17,9 @@
17
17
  // line, not a failing account, so it costs no round trip and reads as exit 2 — otherwise an
18
18
  // agent that mistyped a key goes off investigating the account instead of its own arguments.
19
19
  import { CODE_ENV_VAR } from "../credentials.js";
20
- import { buildIndex, fullPathOf, isLive, KIND_FOLDER, trashedAt } from "../drive-paths.js";
20
+ import { buildIndex, fullPathOf, isLive, KIND_FOLDER, shown as inViews, trashedAt } from "../drive-paths.js";
21
21
  import { NmtsError } from "../errors.js";
22
+ import { classify } from "../shared/lib/drive/preview-classify.js";
22
23
  import { marksOf, markSuffix } from "../mark-render.js";
23
24
  import { idsForQuery, needleOf } from "../list-view-find.js";
24
25
  import { orderRows, parseSortKey } from "../list-view-order.js";
@@ -56,6 +57,8 @@ function byPath(rows, dir) {
56
57
  return dir === "desc" ? sorted.reverse() : sorted;
57
58
  }
58
59
  export async function ls(options = {}) {
60
+ // A kind that cannot mean anything is refused before the account is read.
61
+ const media = mediaOf(options.media);
59
62
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
60
63
  const now = options.now ?? Date.now();
61
64
  const dir = options.desc === true ? "desc" : "asc";
@@ -89,10 +92,12 @@ export async function ls(options = {}) {
89
92
  // built to avoid, and it shipped: `hiddenTrashed` said 1 while two unreachable files were
90
93
  // printed as live (2026-08-23).
91
94
  const index = buildIndex(list.manifest.entries);
92
- const listed = options.all
93
- ? list.manifest.entries
94
- : list.manifest.entries.filter((e) => isLive(index, e));
95
- const hidden = list.manifest.entries.length - listed.length;
95
+ // A video's preview picture is part of the video, never a line of its own — and it is
96
+ // not counted among what `--all` would add either.
97
+ const visible = list.manifest.entries.filter((e) => inViews(index, e));
98
+ const kept = media === null ? visible : visible.filter((e) => e.kind !== KIND_FOLDER && classify(e.name).kind === media);
99
+ const listed = options.all ? kept : kept.filter((e) => isLive(index, e));
100
+ const hidden = kept.length - listed.length;
96
101
  // The query runs over what was going to be shown, so `--find` and `--all` compose instead of one
97
102
  // quietly widening the other: a search without `--all` searches the drive, not the trash.
98
103
  const keep = needle === null ? null : idsForQuery(index, listed, needle);
@@ -200,3 +205,11 @@ export async function ls(options = {}) {
200
205
  }
201
206
  return 0;
202
207
  }
208
+ /** `--media`, checked: the three kinds the gallery and the music place gather, or null for all. */
209
+ function mediaOf(asked) {
210
+ if (asked === undefined)
211
+ return null;
212
+ if (asked === "image" || asked === "video" || asked === "audio")
213
+ return asked;
214
+ throw new NmtsError(`--media takes image, video or audio, not "${asked}".`, { exitCode: 2 });
215
+ }
@@ -14,7 +14,7 @@ import { folderFor } from "./push.js";
14
14
  /** The wallet rail, one file at a time, stopping at the first failure as the credit rail does. */
15
15
  export async function pushWithWallet(session, options, run) {
16
16
  const { say } = run;
17
- const { uploadOneWithWallet } = await import("./put-wallet.js");
17
+ const { readNetworkCopy, uploadOneWithWallet } = await import("./put-wallet.js");
18
18
  const ctx = {
19
19
  code: session.code,
20
20
  apiKey: session.apiKey,
@@ -31,6 +31,9 @@ export async function pushWithWallet(session, options, run) {
31
31
  ...options,
32
32
  readActiveWallet: async () => activeWalletOf(run.settings),
33
33
  }),
34
+ // ⛔ ONCE FOR THE WHOLE RUN, not per file: it decides one sentence in each review and a read
35
+ // per file would be one request per file for nothing. `--json` prints no review at all.
36
+ networkCopy: options.json === true ? false : await readNetworkCopy(session.server, session.apiKey),
34
37
  progress: new Progress(options.json === true ? silentSink() : stderrSink(), "uploading"),
35
38
  say,
36
39
  json: options.json === true,
@@ -21,6 +21,9 @@ export interface PushOptions {
21
21
  storage?: string | undefined;
22
22
  /** `--pay wallet`: which of this key's wallets pays, this run only. Absent = the account's own. */
23
23
  wallet?: string | undefined;
24
+ /** `--trust-server-tip-address`: let THIS SERVER name where the standing gift goes. Off unless
25
+ * typed, and only for a server the caller runs (`standing-tip.ts`). */
26
+ trustServerTipAddress?: boolean;
24
27
  json?: boolean;
25
28
  write?: (line: string) => void;
26
29
  /**
@@ -1,8 +1,10 @@
1
1
  /** Who pays, or a refusal for a payer this tool does not know. */
2
2
  export declare function payerOf(pay: string | undefined): "credits" | "wallet";
3
- /** The two options that only mean something when the wallet pays, refused when it does not. */
3
+ /** The options that only mean something when the wallet pays, refused when it does not. */
4
4
  export declare function refuseWalletOnlyOptions(options: {
5
5
  epochs?: string | number | undefined;
6
6
  storage?: string | undefined;
7
7
  wallet?: string | undefined;
8
+ trustServerTipAddress?: boolean;
9
+ from?: string | undefined;
8
10
  }): void;
@@ -18,7 +18,7 @@ export function payerOf(pay) {
18
18
  nextStep: `Nothing was sent. --pay wallet buys the storage from the wallet this NMTS key derives; without it credits pay.`,
19
19
  });
20
20
  }
21
- /** The two options that only mean something when the wallet pays, refused when it does not. */
21
+ /** The options that only mean something when the wallet pays, refused when it does not. */
22
22
  export function refuseWalletOnlyOptions(options) {
23
23
  if (options.wallet !== undefined) {
24
24
  throw new NmtsError("--wallet only applies with --pay wallet: credits are not held in a wallet.", {
@@ -38,4 +38,16 @@ export function refuseWalletOnlyOptions(options) {
38
38
  nextStep: `Nothing was sent. Add --pay wallet to use a storage resource this wallet holds.`,
39
39
  });
40
40
  }
41
+ if (options.from !== undefined) {
42
+ throw new NmtsError("--from only applies with --pay wallet: it is how a credit-paid file moves onto the wallet.", {
43
+ exitCode: 2,
44
+ nextStep: `Nothing was sent. Add --pay wallet, which is what the re-upload is for.`,
45
+ });
46
+ }
47
+ if (options.trustServerTipAddress === true) {
48
+ throw new NmtsError("--trust-server-tip-address only applies with --pay wallet: a standing gift follows a wallet payment.", {
49
+ exitCode: 2,
50
+ nextStep: `Nothing was sent. A credit-paid upload sends no gift, so there is no address to trust.`,
51
+ });
52
+ }
41
53
  }
@@ -0,0 +1,4 @@
1
+ import type { PutOptions } from "./put.ts";
2
+ type PutOne = (target: string | undefined, options: PutOptions) => Promise<number>;
3
+ export declare function putWithThumbnail(target: string | undefined, options: PutOptions, putOne: PutOne): Promise<number>;
4
+ export {};
@@ -0,0 +1,119 @@
1
+ // `nmts put <video> --thumbnail` — the video, then its preview picture as an ordinary file linked to
2
+ // it.
3
+ //
4
+ // THE PICTURE IS A SECOND `put`, not a new kind of upload: it is priced, sealed, paid for and listed
5
+ // exactly like any small file, and its list entry carries the video's id (`thumbOf`) so every app
6
+ // hides it while the video is there. `--dry-run` prices both and sends neither.
7
+ //
8
+ // WHERE THE PICTURE COMES FROM: `--thumbnail-file <picture>`, or one frame taken by `ffmpeg` if it is
9
+ // on this machine's PATH (one second in, 512 px on the long side). Without either the video is
10
+ // still stored, and the output says why it went alone.
11
+ //
12
+ // ⚠ ONE JSON LINE PER COMMAND, as everywhere in this tool: with `--json` both runs are captured and
13
+ // printed as the video's object with the picture's under `thumbnail`.
14
+ import { execFile } from "node:child_process";
15
+ import { mkdtemp, rm, stat } from "node:fs/promises";
16
+ import { tmpdir } from "node:os";
17
+ import { basename, join, resolve } from "node:path";
18
+ import { promisify } from "node:util";
19
+ import { classify } from "../shared/lib/drive/preview-classify.js";
20
+ import { BINARY_NAME } from "../product.js";
21
+ const run = promisify(execFile);
22
+ /** Long edge of the frame, px — the same picture the browser makes (spec §4). */
23
+ const FRAME_PX = 512;
24
+ export async function putWithThumbnail(target, options, putOne) {
25
+ const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
26
+ const name = options.name ?? basename(target ?? "");
27
+ if (classify(name).kind !== "video") {
28
+ say(` ${name} is not a video, so no preview picture goes with it.`);
29
+ return putOne(target, withoutThumbnail(options));
30
+ }
31
+ const captured = [];
32
+ // A holder rather than a `let`: the callback fills it, and a narrowed `let` would read as never set.
33
+ const got = { video: null };
34
+ const code = await putOne(target, {
35
+ ...withoutThumbnail(options),
36
+ onStored: (id, savedAs) => {
37
+ got.video = { id, name: savedAs };
38
+ },
39
+ ...(options.json === true ? { write: (line) => captured.push(line) } : {}),
40
+ });
41
+ const video = got.video;
42
+ if (code !== 0 || (video === null && options.dryRun !== true))
43
+ return finish(code, captured, null, options, say);
44
+ const picture = await pictureFor(target ?? "", options);
45
+ if ("reason" in picture)
46
+ return finish(code, captured, { skipped: picture.reason }, options, say);
47
+ try {
48
+ const pictureLines = [];
49
+ if (options.json !== true)
50
+ say(` with its preview picture:`);
51
+ const pictureCode = await putOne(picture.path, {
52
+ ...withoutThumbnail(options),
53
+ name: `${video?.name ?? name}.thumb.jpg`,
54
+ ...(video !== null ? { thumbOf: video.id } : {}),
55
+ write: options.json === true ? (line) => pictureLines.push(line) : (line) => say(` ${line}`),
56
+ });
57
+ const parsed = pictureLines.length > 0 ? parseLast(pictureLines) : null;
58
+ return finish(pictureCode === 0 ? code : pictureCode, captured, parsed ?? {}, options, say);
59
+ }
60
+ finally {
61
+ await picture.cleanup();
62
+ }
63
+ }
64
+ function withoutThumbnail(options) {
65
+ const { thumbnail: _asked, thumbnailFile: _file, ...rest } = options;
66
+ return rest;
67
+ }
68
+ /** The video's JSON line with the picture's result folded in, or nothing more in human mode. */
69
+ function finish(code, captured, thumbnail, options, say) {
70
+ if (options.json === true) {
71
+ const video = parseLast(captured) ?? {};
72
+ say(JSON.stringify({ ...video, thumbnail }));
73
+ }
74
+ else if (thumbnail !== null && typeof thumbnail.skipped === "string") {
75
+ say(` No preview picture went with it: ${thumbnail.skipped}`);
76
+ }
77
+ return code;
78
+ }
79
+ function parseLast(lines) {
80
+ const last = lines.at(-1);
81
+ if (last === undefined)
82
+ return null;
83
+ try {
84
+ const value = JSON.parse(last);
85
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? { ...value } : null;
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
91
+ /** The picture to send, and how to tidy up after it — or why there is none. */
92
+ async function pictureFor(videoPath, options) {
93
+ if (options.thumbnailFile !== undefined)
94
+ return { path: resolve(options.thumbnailFile), cleanup: async () => undefined };
95
+ const dir = await mkdtemp(join(tmpdir(), "nmts-thumb-"));
96
+ const out = join(dir, "frame.jpg");
97
+ const cleanup = () => rm(dir, { recursive: true, force: true });
98
+ const scale = `scale='if(gt(iw,ih),${FRAME_PX},-2)':'if(gt(iw,ih),-2,${FRAME_PX})'`;
99
+ // One second in first; a clip shorter than that has its first frame instead.
100
+ for (const at of ["1", "0"]) {
101
+ try {
102
+ await run("ffmpeg", ["-hide_banner", "-loglevel", "error", "-y", "-ss", at, "-i", resolve(videoPath), "-frames:v", "1", "-vf", scale, "-q:v", "5", out]);
103
+ // ⚠ Past the end, ffmpeg exits 0 having written nothing — only a file with bytes is a frame.
104
+ if ((await stat(out).catch(() => null))?.size)
105
+ return { path: out, cleanup };
106
+ }
107
+ catch (error) {
108
+ if (isMissing(error)) {
109
+ await cleanup();
110
+ return { reason: `ffmpeg is not on this machine's PATH. Give the picture yourself: ${BINARY_NAME} put <video> --thumbnail-file <picture>` };
111
+ }
112
+ }
113
+ }
114
+ await cleanup();
115
+ return { reason: "ffmpeg could not take a frame from this file." };
116
+ }
117
+ function isMissing(error) {
118
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
119
+ }
@@ -15,6 +15,14 @@ export interface WalletPayOptions {
15
15
  epochs?: string | number | undefined;
16
16
  /** `fit`, `whole`, or a held resource's object id. Absent = buy new storage. */
17
17
  storage?: string | undefined;
18
+ /**
19
+ * `--from <drive path>`: re-upload a file the account's CREDITS paid for, on the wallet's money.
20
+ *
21
+ * ⛔ IT IS A DOWNLOAD, A RE-SEAL AND AN OVERWRITE, not a transfer: no chain call can move the
22
+ * treasury's storage object to somebody's own wallet (`refill-source.ts`). The new file takes
23
+ * the old one's name and folder, and the old one goes to the trash.
24
+ */
25
+ from?: string | undefined;
18
26
  /** `--wallet N`: which wallet pays, this run only. Absent = the account's own number. */
19
27
  wallet?: string | undefined;
20
28
  /** The instant the wallet agreement is measured against. */
@@ -26,6 +34,13 @@ export interface WalletPayOptions {
26
34
  register: SignBlobRegister;
27
35
  certify: SignBlobCertify;
28
36
  };
37
+ /**
38
+ * `--trust-server-tip-address`: let THIS SERVER name where the standing gift goes.
39
+ *
40
+ * ⛔ UNLIKE `tip` BELOW, THIS ONE IS A FLAG. It is off unless somebody typed it, and it belongs
41
+ * to a server they run themselves — see `standing-tip.ts` for what it costs elsewhere.
42
+ */
43
+ trustServerTipAddress?: boolean;
29
44
  /** ⚠ SEAMS, NOT OPTIONS — the standing tip's own read and signature. No flag reaches them. */
30
45
  tip?: Pick<StandingTipInput, "readDonation" | "sign">;
31
46
  /** The storage-network protocol and the server calls — seams for the tests, as `upload.ts` has. */
@@ -43,6 +58,8 @@ export interface WalletUploadFile {
43
58
  parentId: string | null;
44
59
  /** The destination AS TYPED — part of the reservation key. */
45
60
  destination: string;
61
+ /** A video's preview picture: the video's item id (`put-thumbnail.ts`). */
62
+ thumbOf?: string | undefined;
46
63
  }
47
64
  export interface WalletUploadContext {
48
65
  code: string;
@@ -58,6 +75,13 @@ export interface WalletUploadContext {
58
75
  settings?: AccountSettings | undefined;
59
76
  /** Which of this key's wallets pays (`wallet-pay-index.ts`). Read from the same list as above. */
60
77
  wallet: number;
78
+ /**
79
+ * Does this account ask its uploads to carry the recovery list's storage-network copy?
80
+ *
81
+ * ⛔ IT ONLY CHANGES A SENTENCE IN THE REVIEW, never what is signed or sent — which is why a read
82
+ * that fails arrives here as `null` instead of stopping an upload (`readNetworkCopy`).
83
+ */
84
+ networkCopy: boolean | null;
61
85
  progress: Progress;
62
86
  say: (line: string) => void;
63
87
  json: boolean;
@@ -81,3 +105,12 @@ export declare function uploadOneWithWallet(ctx: WalletUploadContext, file: Wall
81
105
  resumed: boolean;
82
106
  facts: Record<string, unknown>;
83
107
  } | null>;
108
+ /**
109
+ * Whether this account asks its uploads to carry the recovery list's copy — for the review's one
110
+ * sentence about it, and for nothing else.
111
+ *
112
+ * ⛔ A FAILED READ IS `null`, NOT A FAILED UPLOAD. What hangs on this is a sentence; a server that
113
+ * could not answer, or one older than the field, must not cost somebody the upload they asked
114
+ * for. `--json` skips the read entirely — there is no review to print.
115
+ */
116
+ export declare function readNetworkCopy(server: string, apiKey: string): Promise<boolean | null>;