@needmoretruth/nmts-cli 0.42.0 → 0.44.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 (72) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +41 -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 +16 -0
  8. package/dist/args.js +5 -2
  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/login.js +2 -2
  17. package/dist/commands/push-wallet.js +4 -1
  18. package/dist/commands/push.d.ts +3 -0
  19. package/dist/commands/put-payer.d.ts +3 -1
  20. package/dist/commands/put-payer.js +13 -1
  21. package/dist/commands/put-wallet.d.ts +31 -0
  22. package/dist/commands/put-wallet.js +84 -10
  23. package/dist/commands/put.d.ts +5 -0
  24. package/dist/commands/whoami.d.ts +4 -0
  25. package/dist/commands/whoami.js +14 -1
  26. package/dist/crypto-surface.d.ts +11 -0
  27. package/dist/crypto-surface.js +6 -0
  28. package/dist/drive-edit/tree.d.ts +12 -0
  29. package/dist/drive-edit/tree.js +25 -4
  30. package/dist/drive-erase.d.ts +5 -3
  31. package/dist/drive-erase.js +7 -2
  32. package/dist/help-options.d.ts +2 -0
  33. package/dist/help-options.js +142 -0
  34. package/dist/help.js +10 -123
  35. package/dist/main.js +14 -19
  36. package/dist/mcp-tools/reads.js +4 -3
  37. package/dist/portable.d.ts +1 -1
  38. package/dist/portable.js +1 -1
  39. package/dist/product.d.ts +1 -1
  40. package/dist/product.js +1 -1
  41. package/dist/refill-source.d.ts +69 -0
  42. package/dist/refill-source.js +143 -0
  43. package/dist/risk.d.ts +12 -0
  44. package/dist/risk.js +16 -0
  45. package/dist/shared/lib/wallet/activity.js +23 -1
  46. package/dist/standing-tip.d.ts +26 -0
  47. package/dist/standing-tip.js +31 -0
  48. package/dist/storage-control/extend.d.ts +10 -0
  49. package/dist/storage-control/extend.js +1 -1
  50. package/dist/upload-store.d.ts +10 -0
  51. package/dist/upload-wallet-plan.d.ts +8 -0
  52. package/dist/upload-wallet-plan.js +12 -3
  53. package/dist/upload-wallet-put.d.ts +16 -0
  54. package/dist/upload-wallet-put.js +4 -2
  55. package/dist/upload-wallet.d.ts +11 -0
  56. package/dist/upload-wallet.js +14 -0
  57. package/dist/wallet-sign-external.d.ts +120 -0
  58. package/dist/wallet-sign-external.js +221 -0
  59. package/dist/wallet-sign.js +3 -1
  60. package/dist/walrus.d.ts +9 -1
  61. package/dist/walrus.js +17 -3
  62. package/docs/commands/ai-account.md +25 -0
  63. package/docs/commands/login.md +4 -3
  64. package/docs/commands/verify.md +1 -1
  65. package/docs/commands/whoami.md +4 -0
  66. package/examples/podman.sh +48 -0
  67. package/package.json +6 -1
  68. package/server.json +2 -2
  69. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +42 -6
  70. package/vendor/nmts-crypto/nmts_crypto_wasm.js +105 -2
  71. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  72. 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;
@@ -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
@@ -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
  }
@@ -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. */
@@ -58,6 +73,13 @@ export interface WalletUploadContext {
58
73
  settings?: AccountSettings | undefined;
59
74
  /** Which of this key's wallets pays (`wallet-pay-index.ts`). Read from the same list as above. */
60
75
  wallet: number;
76
+ /**
77
+ * Does this account ask its uploads to carry the recovery list's storage-network copy?
78
+ *
79
+ * ⛔ IT ONLY CHANGES A SENTENCE IN THE REVIEW, never what is signed or sent — which is why a read
80
+ * that fails arrives here as `null` instead of stopping an upload (`readNetworkCopy`).
81
+ */
82
+ networkCopy: boolean | null;
61
83
  progress: Progress;
62
84
  say: (line: string) => void;
63
85
  json: boolean;
@@ -81,3 +103,12 @@ export declare function uploadOneWithWallet(ctx: WalletUploadContext, file: Wall
81
103
  resumed: boolean;
82
104
  facts: Record<string, unknown>;
83
105
  } | null>;
106
+ /**
107
+ * Whether this account asks its uploads to carry the recovery list's copy — for the review's one
108
+ * sentence about it, and for nothing else.
109
+ *
110
+ * ⛔ A FAILED READ IS `null`, NOT A FAILED UPLOAD. What hangs on this is a sentence; a server that
111
+ * could not answer, or one older than the field, must not cost somebody the upload they asked
112
+ * for. `--json` skips the read entirely — there is no review to print.
113
+ */
114
+ export declare function readNetworkCopy(server: string, apiKey: string): Promise<boolean | null>;
@@ -32,6 +32,7 @@ import { resolveServer } from "../server.js";
32
32
  import { fileSource } from "../upload-file-node.js";
33
33
  import { partSizeFor } from "../upload-price.js";
34
34
  import { measureLocal } from "../upload-price-node.js";
35
+ import { downloadForRefill, findOriginal, settleRefill } from "../refill-source.js";
35
36
  import { describeUploadReview } from "../upload-wallet-plan.js";
36
37
  import { walletPut } from "../upload-wallet-put.js";
37
38
  import { coinAmount } from "../wallet.js";
@@ -39,7 +40,9 @@ import { recordWalletSpend, requireWalletGrant } from "../wallet-grant.js";
39
40
  import { folderIdFor } from "./put.js";
40
41
  export async function putWithWallet(target, options) {
41
42
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
42
- if (target === undefined || target === "") {
43
+ const from = options.from;
44
+ refuseFromClashes(target, options);
45
+ if (from === undefined && (target === undefined || target === "")) {
43
46
  throw new NmtsError("Say which file to put.", { exitCode: 2, nextStep: `\`${BINARY_NAME} put <file> --pay wallet\`` });
44
47
  }
45
48
  const resolved = await requireAccountCode();
@@ -50,8 +53,9 @@ export async function putWithWallet(target, options) {
50
53
  nextStep: `Make a key on the account screen at nmts.me and put it in ${API_KEY_ENV_VAR}, or store it with \`${BINARY_NAME} login\`.`,
51
54
  });
52
55
  }
53
- const localPath = resolve(target);
54
- const size = measureLocal(localPath);
56
+ // ⛔ MEASURED BEFORE A SINGLE NETWORK CALL, as it always was: a path that is not a file is a
57
+ // command line to fix, and finding that out after three chain reads wastes somebody's time.
58
+ const local = from === undefined ? { localPath: resolve(target ?? ""), size: measureLocal(resolve(target ?? "")) } : null;
55
59
  const stored = readCredentialsFile();
56
60
  const server = resolveServer(options.server ?? stored?.server);
57
61
  const network = resolveNetwork(server, options.network ?? stored?.network);
@@ -66,9 +70,12 @@ export async function putWithWallet(target, options) {
66
70
  ...options,
67
71
  readActiveWallet: async () => activeWalletOf(list.manifest?.settings),
68
72
  });
69
- const name = options.name ?? basename(localPath);
70
- const destination = (options.to ?? "").replace(/^\.?\//, "").replace(/\/$/, "");
71
- const parentId = folderIdFor(options.to, list.manifest?.entries ?? []);
73
+ // ⛔ THE PLACE COMES FROM THE ORIGINAL, NOT FROM THE COMMAND LINE, when there is one: this
74
+ // replaces a file where it already sits, so its name and its folder are not open questions.
75
+ const original = from === undefined ? null : findOriginal(list.manifest?.entries ?? [], from);
76
+ const name = original?.name ?? options.name ?? basename(local?.localPath ?? "");
77
+ const destination = original?.destination ?? (options.to ?? "").replace(/^\.?\//, "").replace(/\/$/, "");
78
+ const parentId = original === null ? folderIdFor(options.to, list.manifest?.entries ?? []) : original.parentId;
72
79
  const ctx = {
73
80
  code: resolved.code,
74
81
  apiKey: key.key,
@@ -81,19 +88,44 @@ export async function putWithWallet(target, options) {
81
88
  onCollision: asked,
82
89
  settings: list.manifest?.settings,
83
90
  wallet,
91
+ networkCopy: options.json === true ? false : await readNetworkCopy(server, key.key),
84
92
  progress: new Progress(options.json === true ? silentSink() : stderrSink(), "uploading"),
85
93
  say,
86
94
  json: options.json === true,
87
95
  };
88
- const done = await uploadOneWithWallet(ctx, { localPath, size, name, parentId, destination }, options);
96
+ // ⛔ NOTHING IS DOWNLOADED FOR A DRY RUN. The price is arithmetic over the size the sealed list
97
+ // already holds, and `walletPut` returns at the review before the source is read — so the
98
+ // empty path below can only be reached by a run that got past the review, which is this one.
99
+ const scratch = original === null || options.dryRun === true ? null : await downloadForRefill({ server, apiKey: key.key, code: resolved.code, network, original });
100
+ let done;
101
+ try {
102
+ const size = local?.size ?? original?.entry.size ?? 0;
103
+ const localPath = local?.localPath ?? scratch?.localPath ?? "";
104
+ done = await uploadOneWithWallet(ctx, { localPath, size, name, parentId, destination }, options);
105
+ }
106
+ finally {
107
+ // ⛔ ON EVERY PATH OUT, INCLUDING THE FAILING ONES. What it removes is a decrypted copy of
108
+ // somebody's file; leaving one behind because a signature was refused is the worst case.
109
+ scratch?.remove();
110
+ }
89
111
  if (done === null)
90
112
  return 0;
113
+ // ⛔ THE NAME AND THE TRASH, AFTER THE PAID-FOR BYTES ARE IN THE LIST. See `settleRefill` for why
114
+ // this is a second write rather than an overwrite on the commit.
115
+ const settled = original === null
116
+ ? null
117
+ : await settleRefill({ server, apiKey: key.key, code: resolved.code, accountId: identity.accountId }, original, done.itemId);
118
+ const savedAs = original?.name ?? done.savedAs;
91
119
  if (options.json) {
92
- say(JSON.stringify({ id: done.itemId, name: done.savedAs, ...done.facts, resumed: done.resumed, renamed: done.savedAs !== name, ...(done.replaced ? { replacedIntoTrash: done.replaced } : {}), fileListVersion: done.seq }));
120
+ say(JSON.stringify({ id: done.itemId, name: savedAs, ...done.facts, resumed: done.resumed, renamed: savedAs !== name, ...(original !== null ? { replacedIntoTrash: original.entry.id } : done.replaced ? { replacedIntoTrash: done.replaced } : {}), fileListVersion: settled ?? done.seq }));
93
121
  return 0;
94
122
  }
95
- say(` saved as ${done.savedAs}`);
96
- if (done.replaced)
123
+ say(` saved as ${savedAs}`);
124
+ if (original !== null) {
125
+ say(` The file credits paid for is in the trash now — ${BINARY_NAME} restore brings it back for 30 days.`);
126
+ say(` Erasing it releases its storage and settles its deposit: ${BINARY_NAME} erase --release-storage.`);
127
+ }
128
+ else if (done.replaced)
97
129
  say(` A file called ${name} was already there. It is in the trash now — ${BINARY_NAME} restore brings it back for 30 days.`);
98
130
  else if (done.savedAs !== name)
99
131
  say(` A file called ${name} was already there, so this one was numbered rather than replacing it.`);
@@ -101,6 +133,29 @@ export async function putWithWallet(target, options) {
101
133
  say(` This finished an upload a previous run had already signed for. Nothing was signed now.`);
102
134
  return 0;
103
135
  }
136
+ /**
137
+ * The options `--from` leaves no room for, refused before anything is read.
138
+ *
139
+ * ⛔ REFUSED RATHER THAN IGNORED, for the reason `put-payer.ts` refuses the wallet-only options:
140
+ * somebody who typed `--name` meant it, and an upload that quietly used a different name would
141
+ * be discovered as a file in the wrong place, after the money moved.
142
+ */
143
+ function refuseFromClashes(target, options) {
144
+ if (options.from === undefined)
145
+ return;
146
+ const nothing = `Nothing was signed and nothing was sent.`;
147
+ const clash = (what, why) => new NmtsError(`${what} does not apply with --from: ${why}`, { exitCode: 2, nextStep: nothing });
148
+ if (target !== undefined && target !== "") {
149
+ throw clash(`a local file`, `--from names the file, in the drive, and one run re-uploads one file.`);
150
+ }
151
+ if (options.name !== undefined)
152
+ throw clash(`--name`, `the re-upload keeps the name the file has.`);
153
+ if (options.to !== undefined)
154
+ throw clash(`--to`, `the re-upload keeps the folder the file is in.`);
155
+ if (options.onCollision !== undefined) {
156
+ throw clash(`--on-collision`, `a re-upload replaces the file it came from; that is what it is for.`);
157
+ }
158
+ }
104
159
  /**
105
160
  * Review, agree, upload and record ONE file for a person who is watching. Null when `--dry-run`
106
161
  * stopped at the review.
@@ -148,6 +203,7 @@ export async function uploadOneWithWallet(ctx, file, options) {
148
203
  tipMist: review.tipMist,
149
204
  storage: review.storage,
150
205
  heldResources: review.heldResources,
206
+ networkCopy: ctx.networkCopy,
151
207
  }, review.budget);
152
208
  },
153
209
  agree: (review) => {
@@ -182,10 +238,28 @@ export async function uploadOneWithWallet(ctx, file, options) {
182
238
  wallet: ctx.wallet,
183
239
  paidWalFrost: outcome.resumed ? 0n : outcome.review.budget.walNeededFrost,
184
240
  say: ctx.json ? (line) => void process.stderr.write(`${line}\n`) : say,
241
+ trustServerAddress: options.trustServerTipAddress === true,
185
242
  ...(options.tip ?? {}),
186
243
  });
187
244
  return { itemId: outcome.itemId, savedAs: outcome.savedAs, replaced: outcome.replaced, seq: outcome.fileListVersion, resumed: outcome.resumed, facts };
188
245
  }
246
+ /**
247
+ * Whether this account asks its uploads to carry the recovery list's copy — for the review's one
248
+ * sentence about it, and for nothing else.
249
+ *
250
+ * ⛔ A FAILED READ IS `null`, NOT A FAILED UPLOAD. What hangs on this is a sentence; a server that
251
+ * could not answer, or one older than the field, must not cost somebody the upload they asked
252
+ * for. `--json` skips the read entirely — there is no review to print.
253
+ */
254
+ export async function readNetworkCopy(server, apiKey) {
255
+ try {
256
+ const { readAccountSummary } = await import("./balance.js");
257
+ return (await readAccountSummary(server, apiKey)).network_copy;
258
+ }
259
+ catch {
260
+ return null;
261
+ }
262
+ }
189
263
  /** The review as `--json` prints it: base units as strings, with the coin amounts beside them. */
190
264
  function factsOf(review) {
191
265
  const { budget, storage } = review;
@@ -35,8 +35,13 @@ export interface PutOptions {
35
35
  epochs?: string | number | undefined;
36
36
  /** `--pay wallet`: a held storage resource to use — `fit`, `whole`, or its object id. */
37
37
  storage?: string | undefined;
38
+ /** `--pay wallet`: re-upload this file of the drive's on the wallet's money (`put-wallet.ts`). */
39
+ from?: string | undefined;
38
40
  /** `--pay wallet`: which of this key's wallets pays, this run only. Absent = the account's own. */
39
41
  wallet?: string | undefined;
42
+ /** `--trust-server-tip-address`: let THIS SERVER name where the standing gift goes. Off unless
43
+ * typed, and only for a server the caller runs (`standing-tip.ts`). */
44
+ trustServerTipAddress?: boolean;
40
45
  json?: boolean;
41
46
  write?: (line: string) => void;
42
47
  }
@@ -4,6 +4,10 @@ export interface WhoamiOptions {
4
4
  write?: (line: string) => void;
5
5
  /** Print the NMTS key itself. A person's act — see the header. */
6
6
  reveal?: boolean;
7
+ /** With `reveal`: print the key as its 15-word recovery phrase instead. */
8
+ phrase?: boolean;
9
+ /** The phrase's word list: `en` (default) or `ko`. */
10
+ lang?: string | undefined;
7
11
  /** Machine-readable output. Only `--reveal` has one; the listing is for a person. */
8
12
  json?: boolean;
9
13
  }
@@ -11,7 +11,10 @@
11
11
  // situation, a person copying it out of a machine they are sitting at, and it is refused while
12
12
  // a mode is on. There is no MCP tool for it either: an agent driving this tool was handed the
13
13
  // code already, so a surface that prints it can only ever move it somewhere new.
14
- import { identityOf } from "../account.js";
14
+ //
15
+ // ⭐ `--reveal --phrase` prints the same key as its 15-word recovery phrase (`--lang ko` for the
16
+ // Korean list). It is the key in another spelling, so it rides the same flag and the same rule.
17
+ import { identityOf, phraseOf } from "../account.js";
15
18
  import { requireAccountCode } from "../code-access.js";
16
19
  import { CODE_ENV_VAR, readCredentialsFile } from "../credentials.js";
17
20
  import { resolveNetwork } from "../network.js";
@@ -20,6 +23,16 @@ export async function whoami(options = {}) {
20
23
  const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
21
24
  const resolved = await requireAccountCode();
22
25
  const identity = await identityOf(resolved.code);
26
+ if (options.reveal === true && options.phrase === true) {
27
+ const phrase = await phraseOf(resolved.code, options.lang);
28
+ if (options.json === true) {
29
+ say(JSON.stringify({ recovery_phrase: phrase }));
30
+ return 0;
31
+ }
32
+ say(`This phrase is the NMTS key in 15 words: anyone who reads it can open every file.`);
33
+ say(phrase);
34
+ return 0;
35
+ }
23
36
  if (options.reveal === true) {
24
37
  if (options.json === true) {
25
38
  say(JSON.stringify({ account_code: identity.displayCode }));
@@ -52,8 +52,19 @@ export interface CryptoGlue {
52
52
  account_code_parse(input: string): Uint8Array;
53
53
  /** The grouped, human-readable spelling of a code. */
54
54
  account_code_display(codeBytes: Uint8Array): string;
55
+ /** The same code as its 15-word recovery phrase (BIP-39), `en` or `ko`. */
56
+ account_code_phrase(codeBytes: Uint8Array, lang: string): string;
55
57
  /** The full derivation output. Offsets are named in DERIVED below. */
56
58
  kdf_derive(codeBytes: Uint8Array): Uint8Array;
59
+ /**
60
+ * The NMTS KEY of this account's AI account number `index` (1-based), from the 32-byte
61
+ * `aiAccountRoot` slice of the derivation (NCF-3 §1.5).
62
+ *
63
+ * ⛔ IT IS A KEY, NOT A SEED, and the same root and index always give the same one back — which
64
+ * is why a place that was erased can be re-derived rather than lost, and why nothing has to
65
+ * store what it returns. ⚠ Wipe the root after calling: it is the parent of every one of them.
66
+ */
67
+ derive_ai_account_code(aiAccountRoot: Uint8Array, index: number): string;
57
68
  /** Display form — the grouped PUBLIC CODE a person reads, copies and types. */
58
69
  share_address_display(address: Uint8Array): string;
59
70
  /**
@@ -14,6 +14,7 @@ const REQUIRED = [
14
14
  "account_code_generate",
15
15
  "account_code_parse",
16
16
  "account_code_display",
17
+ "account_code_phrase",
17
18
  "kdf_derive",
18
19
  "share_address_display",
19
20
  "share_address_parse",
@@ -37,6 +38,11 @@ const REQUIRED = [
37
38
  "opener_seal",
38
39
  "opener_open",
39
40
  "wallet_seed_for",
41
+ // The AI-account derivation (NCF-3 §1.5). Required rather than optional for the reason the
42
+ // opener surface is: a build of the engine without it cannot make an AI account at all, and
43
+ // "this function is missing" said at load time is a different day's problem from
44
+ // `undefined is not a function` in the middle of deriving somebody's second account.
45
+ "derive_ai_account_code",
40
46
  ];
41
47
  export function isCryptoGlue(value) {
42
48
  return missingExports(value).length === 0;
@@ -13,3 +13,15 @@ export declare function uniqueById(files: readonly ManifestEntry[]): ManifestEnt
13
13
  * `rm` takes this set whole. `restore` cannot: see the note at the call site.
14
14
  */
15
15
  export declare function filesUnder(entries: readonly ManifestEntry[], rootId: string): ManifestEntry[];
16
+ /**
17
+ * Every FOLDER under one entry, the root itself excluded. Empty when the root is a file.
18
+ *
19
+ * ⛔ IT EXISTS BECAUSE A FOLDER WITH NO FILE IN IT HAS NOTHING TO CARRY IT OUT. What leaves the
20
+ * sealed list is decided from the files under a named folder; a sub-folder holding none was in
21
+ * nobody's set, so it stayed — an entry whose parent had gone, which the list still showed and
22
+ * nothing could open or reach (2026-09-20).
23
+ *
24
+ * ⚠ Trashed descendants are included, for the reason `filesUnder` includes them: somebody who
25
+ * trashed a sub-folder last week and then erases its parent expects both to be gone.
26
+ */
27
+ export declare function foldersUnder(entries: readonly ManifestEntry[], rootId: string): ManifestEntry[];
@@ -1,6 +1,6 @@
1
1
  // Walking the list: the three questions the edits below ask about where an entry sits, and the one
2
2
  // that gathers the files a folder carries.
3
- import { buildIndex, KIND_FILE } from "../drive-paths.js";
3
+ import { buildIndex, KIND_FILE, KIND_FOLDER } from "../drive-paths.js";
4
4
  /** Is `id` at or under `rootId`? Used to refuse moving a folder into its own subtree. */
5
5
  export function isUnder(entries, id, rootId) {
6
6
  const byId = buildIndex(entries).byId;
@@ -43,11 +43,32 @@ export function uniqueById(files) {
43
43
  * `rm` takes this set whole. `restore` cannot: see the note at the call site.
44
44
  */
45
45
  export function filesUnder(entries, rootId) {
46
+ return under(entries, rootId, KIND_FILE);
47
+ }
48
+ /**
49
+ * Every FOLDER under one entry, the root itself excluded. Empty when the root is a file.
50
+ *
51
+ * ⛔ IT EXISTS BECAUSE A FOLDER WITH NO FILE IN IT HAS NOTHING TO CARRY IT OUT. What leaves the
52
+ * sealed list is decided from the files under a named folder; a sub-folder holding none was in
53
+ * nobody's set, so it stayed — an entry whose parent had gone, which the list still showed and
54
+ * nothing could open or reach (2026-09-20).
55
+ *
56
+ * ⚠ Trashed descendants are included, for the reason `filesUnder` includes them: somebody who
57
+ * trashed a sub-folder last week and then erases its parent expects both to be gone.
58
+ */
59
+ export function foldersUnder(entries, rootId) {
60
+ const root = entries.find((e) => e.id === rootId);
61
+ if (root === undefined || root.kind === KIND_FILE)
62
+ return [];
63
+ return under(entries, rootId, KIND_FOLDER);
64
+ }
65
+ /** The walk both of the two above make: everything of one kind at or under `rootId`. */
66
+ function under(entries, rootId, kind) {
46
67
  const root = entries.find((e) => e.id === rootId);
47
68
  if (root === undefined)
48
69
  return [];
49
70
  if (root.kind === KIND_FILE)
50
- return [root];
71
+ return kind === KIND_FILE ? [root] : [];
51
72
  const childrenOf = new Map();
52
73
  for (const e of entries) {
53
74
  const list = childrenOf.get(e.parentId);
@@ -67,9 +88,9 @@ export function filesUnder(entries, rootId) {
67
88
  if (seen.has(child.id))
68
89
  continue;
69
90
  seen.add(child.id);
70
- if (child.kind === KIND_FILE)
91
+ if (child.kind === kind)
71
92
  out.push(child);
72
- else
93
+ if (child.kind !== KIND_FILE)
73
94
  queue.push(child.id);
74
95
  }
75
96
  }
@@ -24,10 +24,12 @@ export interface ErasePlan {
24
24
  /** Every FILE going: the ones named, and every file under a folder that was named. */
25
25
  readonly files: readonly ErasePath[];
26
26
  /**
27
- * The ids leaving the sealed list — the files above and the folders that were named.
27
+ * The ids leaving the sealed list — the files above, the folders that were named, and every
28
+ * folder under one of them.
28
29
  *
29
- * ⚠ WIDER THAN `files` ON PURPOSE. A named folder has no server row of its own, so nothing is
30
- * erased for it; its entry still has to go, or the list keeps a folder whose contents are gone.
30
+ * ⚠ WIDER THAN `files` ON PURPOSE. A folder has no server row of its own, so nothing is erased
31
+ * for it; its entry still has to go, or the list keeps a folder whose contents are gone — and
32
+ * a sub-folder left behind is the worse half of that, because its parent went too.
31
33
  */
32
34
  readonly going: readonly string[];
33
35
  }
@@ -30,7 +30,7 @@
30
30
  // from each other. This is a sibling of that family rather than an outside caller.
31
31
  import { request, ServerError } from "./api.js";
32
32
  import { DriveEditError, resolving } from "./drive-edit/errors.js";
33
- import { filesUnder, uniqueById } from "./drive-edit/tree.js";
33
+ import { filesUnder, foldersUnder, uniqueById } from "./drive-edit/tree.js";
34
34
  import { buildIndex, fullPathOf, KIND_FILE } from "./drive-paths.js";
35
35
  import { NmtsError } from "./errors.js";
36
36
  import { readFileList } from "./manifest.js";
@@ -54,7 +54,12 @@ export async function planErase(input, paths) {
54
54
  const index = buildIndex(entries);
55
55
  const targets = resolving(() => batchTargets(entries, paths, { includeTrashed: true, nothingHappened: "Nothing was erased." }));
56
56
  const files = uniqueById(targets.flatMap((t) => (t.kind === KIND_FILE ? [t] : filesUnder(entries, t.id))));
57
- const going = uniqueById([...targets, ...files]);
57
+ // ⛔ AND THE FOLDERS UNDER A NAMED FOLDER, which `targets + files` left behind. A sub-folder
58
+ // holding no file was in neither set, so it stayed in the sealed list with its parent gone —
59
+ // a folder the drive still showed, sitting under nothing, that no command could reach
60
+ // (2026-09-20). What is erased on the server is unchanged: folders have no row there.
61
+ const folders = uniqueById(targets.flatMap((t) => (t.kind === KIND_FILE ? [] : foldersUnder(entries, t.id))));
62
+ const going = uniqueById([...targets, ...files, ...folders]);
58
63
  if (files.length === 0) {
59
64
  throw new DriveEditError("NOT_FOUND", `Nothing named holds a file; empty folders are removed with \`${BINARY_NAME} rm\`.`, {
60
65
  exitCode: 4,
@@ -0,0 +1,2 @@
1
+ /** The lines under `OPTIONS`, in the order they are printed. */
2
+ export declare function optionLines(): string[];