@mp-lb/forum-cli 0.1.50 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2103,7 +2103,7 @@ var prepareCheckoutIgnore = async ({
2103
2103
  // src/index.ts
2104
2104
  import { realpathSync, watch as watch2 } from "fs";
2105
2105
  import path27 from "path";
2106
- import { lstat as lstat6, mkdir as mkdir7, readFile as readFile10, rm as rm8, writeFile as writeFile6 } from "fs/promises";
2106
+ import { lstat as lstat6, mkdir as mkdir7, readFile as readFile11, rm as rm8, writeFile as writeFile6 } from "fs/promises";
2107
2107
  import { createInterface as createInterface2 } from "readline/promises";
2108
2108
  import { pathToFileURL } from "url";
2109
2109
 
@@ -5145,13 +5145,13 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
5145
5145
  }
5146
5146
  return propValues;
5147
5147
  });
5148
- const isObject4 = isObject;
5148
+ const isObject5 = isObject;
5149
5149
  const catchall = def.catchall;
5150
5150
  let value;
5151
5151
  inst._zod.parse = (payload, ctx) => {
5152
5152
  value ?? (value = _normalized.value);
5153
5153
  const input = payload.value;
5154
- if (!isObject4(input)) {
5154
+ if (!isObject5(input)) {
5155
5155
  payload.issues.push({
5156
5156
  expected: "object",
5157
5157
  code: "invalid_type",
@@ -5278,7 +5278,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
5278
5278
  return (payload, ctx) => fn(shape, payload, ctx);
5279
5279
  };
5280
5280
  let fastpass;
5281
- const isObject4 = isObject;
5281
+ const isObject5 = isObject;
5282
5282
  const jit = !globalConfig.jitless;
5283
5283
  const allowsEval2 = allowsEval;
5284
5284
  const fastEnabled = jit && allowsEval2.value;
@@ -5287,7 +5287,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
5287
5287
  inst._zod.parse = (payload, ctx) => {
5288
5288
  value ?? (value = _normalized.value);
5289
5289
  const input = payload.value;
5290
- if (!isObject4(input)) {
5290
+ if (!isObject5(input)) {
5291
5291
  payload.issues.push({
5292
5292
  expected: "object",
5293
5293
  code: "invalid_type",
@@ -17450,6 +17450,244 @@ var decryptTextForUser = async ({
17450
17450
  // ../../packages/encryption/src/keyBinding/formatEncryptionFingerprint.ts
17451
17451
  var formatEncryptionFingerprint = (fingerprint) => (fingerprint.toUpperCase().match(/.{1,4}/g) ?? []).join(" ");
17452
17452
 
17453
+ // ../../packages/encryption/src/rekey/resolveKeepFingerprint.ts
17454
+ var resolveKeepFingerprint = (recipientId, candidate) => encryptionFingerprintSchema.safeParse(recipientId).success ? recipientId : candidate.trustedFingerprint ?? null;
17455
+
17456
+ // ../../packages/encryption/src/rekey/planRecipientRekey.ts
17457
+ var planRecipientRekey = ({
17458
+ candidates,
17459
+ recipients,
17460
+ reissueRecipientIds = [],
17461
+ removeRecipientIds = []
17462
+ }) => {
17463
+ const known = new Set(recipients.map((recipient) => recipient.recipientId));
17464
+ for (const recipientId of [...removeRecipientIds, ...reissueRecipientIds]) {
17465
+ if (!known.has(recipientId)) {
17466
+ throw new Error(`Unknown encryption recipient: ${recipientId}`);
17467
+ }
17468
+ }
17469
+ const removed = new Set(removeRecipientIds);
17470
+ const reissued = new Set(reissueRecipientIds);
17471
+ for (const recipientId of removed) {
17472
+ if (reissued.has(recipientId)) {
17473
+ throw new Error(
17474
+ `Recipient ${recipientId} cannot be both removed and reissued.`
17475
+ );
17476
+ }
17477
+ }
17478
+ const candidateById = new Map(
17479
+ candidates.map((candidate) => [candidate.userEncryption.keyId, candidate])
17480
+ );
17481
+ const plan = [];
17482
+ const issues = [];
17483
+ for (const recipient of recipients) {
17484
+ const { label, recipientId } = recipient;
17485
+ if (removed.has(recipientId)) {
17486
+ plan.push({ action: "remove", recipientId });
17487
+ continue;
17488
+ }
17489
+ if (reissued.has(recipientId)) {
17490
+ plan.push({ action: "reissue", recipientId });
17491
+ continue;
17492
+ }
17493
+ const candidate = candidateById.get(recipientId);
17494
+ if (candidate) {
17495
+ const expectedFingerprint = resolveKeepFingerprint(
17496
+ recipientId,
17497
+ candidate
17498
+ );
17499
+ if (expectedFingerprint) {
17500
+ plan.push({
17501
+ action: "keep",
17502
+ expectedFingerprint,
17503
+ recipientId,
17504
+ userEncryption: candidate.userEncryption
17505
+ });
17506
+ } else {
17507
+ issues.push({
17508
+ ...label ? { label } : {},
17509
+ reason: "public_key_unverified",
17510
+ recipientId
17511
+ });
17512
+ }
17513
+ continue;
17514
+ }
17515
+ issues.push({
17516
+ ...label ? { label } : {},
17517
+ reason: recipient.wrappedDataKey.cipher === publicKeyCipher ? "public_key_unavailable" : "secret_not_retained",
17518
+ recipientId
17519
+ });
17520
+ }
17521
+ return { issues, plan };
17522
+ };
17523
+
17524
+ // ../../packages/encryption/src/rekey/assertCompleteRekeyPlan.ts
17525
+ var assertCompleteRekeyPlan = ({
17526
+ actorKeyId,
17527
+ plan,
17528
+ recipients
17529
+ }) => {
17530
+ const current = new Set(recipients.map((recipient) => recipient.recipientId));
17531
+ const seen = /* @__PURE__ */ new Set();
17532
+ for (const entry of plan) {
17533
+ if (!current.has(entry.recipientId)) {
17534
+ throw new Error(`Unknown encryption recipient: ${entry.recipientId}`);
17535
+ }
17536
+ if (seen.has(entry.recipientId)) {
17537
+ throw new Error(
17538
+ `Recipient ${entry.recipientId} appears more than once in the rekey plan.`
17539
+ );
17540
+ }
17541
+ seen.add(entry.recipientId);
17542
+ if (entry.action === "keep" && entry.userEncryption.keyId !== entry.recipientId) {
17543
+ throw new Error(
17544
+ `Recipient ${entry.recipientId} cannot be kept under a different public key.`
17545
+ );
17546
+ }
17547
+ }
17548
+ const missing = [...current].filter((recipientId) => !seen.has(recipientId));
17549
+ if (missing.length) {
17550
+ throw new Error(
17551
+ `Rekey plan does not say what to do with recipient(s): ${missing.join(", ")}`
17552
+ );
17553
+ }
17554
+ if (!plan.some(
17555
+ (entry) => entry.action === "keep" && entry.recipientId === actorKeyId
17556
+ )) {
17557
+ throw new Error(
17558
+ "Rekey must keep your own access, otherwise nobody could save later versions."
17559
+ );
17560
+ }
17561
+ };
17562
+
17563
+ // ../../packages/encryption/src/rekey/generateFileKey.ts
17564
+ var generateFileKey = async () => crypto.subtle.generateKey({ length: 256, name: encryptedFileCipher }, true, [
17565
+ "decrypt",
17566
+ "encrypt"
17567
+ ]);
17568
+
17569
+ // ../../packages/encryption/src/rekey/rekeyEncryptedPlainText.ts
17570
+ var keyBytes = async (key) => new Uint8Array(await crypto.subtle.exportKey("raw", key));
17571
+ var sameBytes = (left, right) => left.length === right.length && left.every((byte, i) => byte === right[i]);
17572
+ var rekeyEncryptedPlainText = async ({
17573
+ actorKeyId,
17574
+ actorUserKey,
17575
+ encryptedText,
17576
+ fileKey,
17577
+ plan,
17578
+ workspaceAccess
17579
+ }) => {
17580
+ const payload = parseEncryptedPlainTextPayload(encryptedText);
17581
+ assertCompleteRekeyPlan({ actorKeyId, plan, recipients: payload.recipients });
17582
+ const plaintext = await decryptPlainTextWithFileKey({
17583
+ encryptedText,
17584
+ fileKey
17585
+ });
17586
+ const nextFileKey = await generateFileKey();
17587
+ if (sameBytes(await keyBytes(fileKey), await keyBytes(nextFileKey))) {
17588
+ throw new Error("Rekey produced the same file key; refusing to continue.");
17589
+ }
17590
+ const byId = new Map(
17591
+ payload.recipients.map((recipient) => [recipient.recipientId, recipient])
17592
+ );
17593
+ const recipients = [];
17594
+ const issuedSecrets = [];
17595
+ const removedRecipientIds = [];
17596
+ for (const entry of plan) {
17597
+ const previous = byId.get(entry.recipientId);
17598
+ if (entry.action === "remove") {
17599
+ removedRecipientIds.push(entry.recipientId);
17600
+ continue;
17601
+ }
17602
+ if (entry.action === "keep") {
17603
+ recipients.push(
17604
+ await createUserRecipientGrant({
17605
+ expectedFingerprint: entry.expectedFingerprint,
17606
+ fileKey: nextFileKey,
17607
+ label: previous.label,
17608
+ userEncryption: entry.userEncryption
17609
+ })
17610
+ );
17611
+ continue;
17612
+ }
17613
+ const label = previous.label ?? entry.recipientId;
17614
+ const grant = await createExternalRecipientGrant({
17615
+ fileKey: nextFileKey,
17616
+ name: label
17617
+ });
17618
+ recipients.push(grant.recipient);
17619
+ issuedSecrets.push({
17620
+ label,
17621
+ previousRecipientId: entry.recipientId,
17622
+ recipientId: grant.recipient.recipientId,
17623
+ secret: grant.secret
17624
+ });
17625
+ }
17626
+ const actorFileKey = await unwrapFileKey({
17627
+ recipients,
17628
+ recipientId: actorKeyId,
17629
+ userKey: actorUserKey
17630
+ }).catch(() => null);
17631
+ if (!actorFileKey || !sameBytes(await keyBytes(actorFileKey), await keyBytes(nextFileKey))) {
17632
+ throw new Error(
17633
+ "Your new grant does not open with your unlocked key; refusing to rekey."
17634
+ );
17635
+ }
17636
+ const nextWorkspaceAccess = workspaceAccess ?? payload.workspaceAccess ?? "personal";
17637
+ const nextEncryptedText = await encryptPlainTextWithFileKey({
17638
+ fileKey: nextFileKey,
17639
+ plaintext,
17640
+ recipients,
17641
+ version: currentEncryptedFileVersion,
17642
+ workspaceAccess: nextWorkspaceAccess
17643
+ });
17644
+ const verified = await decryptPlainTextWithFileKey({
17645
+ encryptedText: nextEncryptedText,
17646
+ fileKey: nextFileKey
17647
+ });
17648
+ if (verified !== plaintext) {
17649
+ throw new Error("Rekeyed file did not round-trip; refusing to write.");
17650
+ }
17651
+ return {
17652
+ encryptedText: nextEncryptedText,
17653
+ encryption: {
17654
+ kind: "encrypted-file",
17655
+ recipients,
17656
+ version: currentEncryptedFileVersion,
17657
+ workspaceAccess: nextWorkspaceAccess
17658
+ },
17659
+ fileKey: nextFileKey,
17660
+ issuedSecrets,
17661
+ removedRecipientIds
17662
+ };
17663
+ };
17664
+
17665
+ // ../../packages/encryption/src/parseUserRecipientLabel.ts
17666
+ var userRecipientLabelPrefix = "user:";
17667
+ var parseUserRecipientLabel = (label) => {
17668
+ if (!label?.startsWith(userRecipientLabelPrefix)) {
17669
+ return null;
17670
+ }
17671
+ const value = label.slice(userRecipientLabelPrefix.length);
17672
+ const separatorIndex = value.indexOf(":");
17673
+ if (separatorIndex === -1) {
17674
+ return { displayName: null, userId: value };
17675
+ }
17676
+ const userId = value.slice(0, separatorIndex);
17677
+ const encodedDisplayName = value.slice(separatorIndex + 1);
17678
+ if (!encodedDisplayName) {
17679
+ return { displayName: null, userId };
17680
+ }
17681
+ try {
17682
+ return {
17683
+ displayName: decodeURIComponent(encodedDisplayName),
17684
+ userId
17685
+ };
17686
+ } catch {
17687
+ return { displayName: encodedDisplayName, userId };
17688
+ }
17689
+ };
17690
+
17453
17691
  // ../../packages/core/src/fileTypes.ts
17454
17692
  var textStorageClass = "text";
17455
17693
  var binaryStorageClass = "binary";
@@ -23953,6 +24191,29 @@ var skillScanSchema = external_exports.object({
23953
24191
  )
23954
24192
  });
23955
24193
 
24194
+ // ../../packages/core/src/cliSessions/cliSessionSchema.ts
24195
+ var cliSessionSchema = external_exports.object({
24196
+ id: external_exports.string().trim().min(1),
24197
+ userId: external_exports.string().trim().min(1),
24198
+ workspaceId: external_exports.string().trim().min(1),
24199
+ clientLabel: external_exports.string().trim().min(1).max(120).nullable().default(null),
24200
+ createdAt: external_exports.string().datetime(),
24201
+ expiresAt: external_exports.string().datetime(),
24202
+ lastUsedAt: external_exports.string().datetime().nullable().default(null),
24203
+ revokedAt: external_exports.string().datetime().nullable().default(null)
24204
+ });
24205
+
24206
+ // ../../packages/core/src/cliSessions/revokeOwnCliSessionInputSchema.ts
24207
+ var revokeOwnCliSessionInputSchema = external_exports.object({
24208
+ sessionId: external_exports.string().trim().min(1)
24209
+ });
24210
+
24211
+ // ../../packages/core/src/cliSessions/listOwnCliSessionsInputSchema.ts
24212
+ var listOwnCliSessionsInputSchema = external_exports.object({});
24213
+
24214
+ // ../../packages/core/src/cliSessions/revokeCurrentCliSessionInputSchema.ts
24215
+ var revokeCurrentCliSessionInputSchema = external_exports.object({});
24216
+
23956
24217
  // ../../packages/store-tree/src/patterns.ts
23957
24218
  var escapeRegex2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
23958
24219
  var basename2 = (path28) => {
@@ -24014,6 +24275,9 @@ var storeRootPathFromId2 = (storeId) => {
24014
24275
  return `/${normalizeStoreId2(storeId)}`;
24015
24276
  };
24016
24277
 
24278
+ // src/auth.ts
24279
+ import { hostname as hostname3 } from "os";
24280
+
24017
24281
  // src/openInBrowser.ts
24018
24282
  import { execFile } from "child_process";
24019
24283
  import { promisify } from "util";
@@ -24384,7 +24648,8 @@ var interactiveLogin = async ({
24384
24648
  {
24385
24649
  method: "POST",
24386
24650
  headers: { "Content-Type": "application/json" },
24387
- body: "{}"
24651
+ // Shown in `fm auth sessions` so users can tell their sessions apart.
24652
+ body: JSON.stringify({ clientLabel: hostname3() })
24388
24653
  }
24389
24654
  );
24390
24655
  if (!startResponse.ok) {
@@ -31668,6 +31933,7 @@ var isTransientForumApiFailure = (error51) => {
31668
31933
  var retrySafeOperations = /* @__PURE__ */ new Set([
31669
31934
  "stores.list",
31670
31935
  "stores.readByRef",
31936
+ "cliSessions.list",
31671
31937
  "userPreferences.read",
31672
31938
  "files.listDirectory",
31673
31939
  "files.listDirectoryByRef",
@@ -31789,7 +32055,17 @@ var createStoreClient = ({
31789
32055
  scanSkills: (input) => call("skills.scan", () => trpc.skills.scan.query(input)),
31790
32056
  listSkillFolders: (input) => call("skills.folders", () => trpc.skills.folders.query(input)),
31791
32057
  readSkill: (input) => call("skills.read", () => trpc.skills.read.query(input)),
32058
+ listCliSessions: () => call("cliSessions.list", () => trpc.cliSessions.list.query({})),
32059
+ revokeCliSession: (input) => call("cliSessions.revoke", () => trpc.cliSessions.revoke.mutate(input)),
32060
+ revokeCurrentCliSession: () => call(
32061
+ "cliSessions.revokeCurrent",
32062
+ () => trpc.cliSessions.revokeCurrent.mutate({})
32063
+ ),
31792
32064
  readUserPreferences: () => call("userPreferences.read", () => trpc.userPreferences.read.query({})),
32065
+ readPublicEncryptionKeys: (input) => call(
32066
+ "userPreferences.readPublicEncryptionKeys",
32067
+ () => trpc.userPreferences.readPublicEncryptionKeys.query(input)
32068
+ ),
31793
32069
  upsertUserPreferences: (input) => call(
31794
32070
  "userPreferences.upsert",
31795
32071
  () => trpc.userPreferences.upsert.mutate(input)
@@ -32172,6 +32448,98 @@ var readConfig = async (stateDir) => {
32172
32448
  };
32173
32449
  };
32174
32450
 
32451
+ // src/authSessions/describeLogoutOutcome.ts
32452
+ var describeLogoutOutcome = (outcome) => {
32453
+ if (outcome.kind === "no-credential") {
32454
+ return ["Logged out. No local CLI credential was stored."];
32455
+ }
32456
+ if (outcome.kind === "revoked") {
32457
+ return ["Logged out. CLI session revoked and local credential removed."];
32458
+ }
32459
+ if (outcome.kind === "already-invalid") {
32460
+ return [
32461
+ "Logged out. Local CLI credential removed.",
32462
+ "The server had already ended this session (revoked or expired)."
32463
+ ];
32464
+ }
32465
+ return [
32466
+ "Logged out locally. Local CLI credential removed.",
32467
+ `Could not revoke the session on the server: ${outcome.reason}`,
32468
+ "Anyone holding a copy of the token can use it until it expires. Revoke it with `fm auth sessions` and `fm auth revoke <sessionId>` from another login."
32469
+ ];
32470
+ };
32471
+
32472
+ // src/authSessions/formatCliSessionRows.ts
32473
+ var formatTimestamp = (value) => value ? value.replace("T", " ").replace(/\.\d+Z$/, "Z") : "never";
32474
+ var formatCliSessionRows = (sessions) => [
32475
+ ["SESSION", "CLIENT", "WORKSPACE", "CREATED", "LAST USED", "EXPIRES"],
32476
+ ...sessions.map((session) => [
32477
+ `${session.id}${session.isCurrent ? " (this CLI)" : ""}`,
32478
+ session.clientLabel ?? "-",
32479
+ session.workspaceId,
32480
+ formatTimestamp(session.createdAt),
32481
+ formatTimestamp(session.lastUsedAt),
32482
+ formatTimestamp(session.expiresAt)
32483
+ ])
32484
+ ];
32485
+
32486
+ // src/authSessions/readTrpcErrorCode.ts
32487
+ var isObject4 = (value) => Boolean(value) && typeof value === "object";
32488
+ var readTrpcErrorCode = (error51) => {
32489
+ let current = error51;
32490
+ for (let depth = 0; depth < 5 && isObject4(current); depth += 1) {
32491
+ const data = current.data;
32492
+ if (isObject4(data) && typeof data.code === "string") {
32493
+ return data.code;
32494
+ }
32495
+ current = current.cause;
32496
+ }
32497
+ return null;
32498
+ };
32499
+
32500
+ // src/authSessions/logoutCliSession.ts
32501
+ var defaultRemoteTimeoutMs = 1e4;
32502
+ var withTimeout = async (operation, timeoutMs) => {
32503
+ let timer;
32504
+ try {
32505
+ await Promise.race([
32506
+ operation,
32507
+ new Promise((_, reject) => {
32508
+ timer = setTimeout(
32509
+ () => reject(new Error(`timed out after ${timeoutMs}ms`)),
32510
+ timeoutMs
32511
+ );
32512
+ })
32513
+ ]);
32514
+ } finally {
32515
+ clearTimeout(timer);
32516
+ }
32517
+ };
32518
+ var logoutCliSession = async ({
32519
+ clearLocalCredential,
32520
+ hasStoredCredential,
32521
+ remoteTimeoutMs = defaultRemoteTimeoutMs,
32522
+ revokeCurrentSession
32523
+ }) => {
32524
+ if (!hasStoredCredential) {
32525
+ await clearLocalCredential();
32526
+ return { kind: "no-credential" };
32527
+ }
32528
+ let outcome;
32529
+ try {
32530
+ await withTimeout(revokeCurrentSession(), remoteTimeoutMs);
32531
+ outcome = { kind: "revoked" };
32532
+ } catch (error51) {
32533
+ outcome = readTrpcErrorCode(error51) === "UNAUTHORIZED" ? { kind: "already-invalid" } : {
32534
+ kind: "remote-failed",
32535
+ reason: error51 instanceof Error ? error51.message : String(error51)
32536
+ };
32537
+ } finally {
32538
+ await clearLocalCredential();
32539
+ }
32540
+ return outcome;
32541
+ };
32542
+
32175
32543
  // src/credentials/removePrivateFile.ts
32176
32544
  import { rm as rm5 } from "fs/promises";
32177
32545
  var removePrivateFile = async (filePath) => {
@@ -33179,21 +33547,191 @@ var decryptTextForRecipientSecret = async (encryptedText, secretArg) => {
33179
33547
  }
33180
33548
  };
33181
33549
 
33550
+ // src/describeRekeyIssues.ts
33551
+ var reasonText = {
33552
+ public_key_unavailable: "their current public encryption key is unavailable, so the new file key cannot be wrapped for them",
33553
+ public_key_unverified: "their legacy encryption key has no fingerprint you have verified, so the new file key will not be wrapped for them (verify their key in the web app first)",
33554
+ secret_not_retained: "its secret is not stored by Forum, so it cannot be carried onto a new file key"
33555
+ };
33556
+ var describeRekeyIssues = (issues) => [
33557
+ "Rekeying would not preserve every remaining recipient:",
33558
+ ...issues.map(
33559
+ (issue2) => ` - ${issue2.label ?? issue2.recipientId} (${issue2.recipientId}): ${reasonText[issue2.reason]}.`
33560
+ ),
33561
+ "Decide for each one: pass --reissue <label-or-id> to mint a new secret (external recipients only) or --remove <label-or-id> to revoke it. Nothing was changed."
33562
+ ].join("\n");
33563
+
33564
+ // src/resolveRecipientPublicKeys.ts
33565
+ var resolveRecipientPublicKeys = async ({
33566
+ actor,
33567
+ lookupPublicKeys,
33568
+ recipients
33569
+ }) => {
33570
+ const userIds = [
33571
+ ...new Set(
33572
+ recipients.filter((recipient) => recipient.recipientId !== actor.keyId).map((recipient) => parseUserRecipientLabel(recipient.label)?.userId).filter((userId) => Boolean(userId))
33573
+ )
33574
+ ];
33575
+ const others = userIds.length ? await lookupPublicKeys(userIds) : [];
33576
+ const actorKey = actor.version === 3 ? { keyId: actor.keyId, publicKey: actor.publicKey, version: 3 } : { keyId: actor.keyId, publicKey: actor.publicKey, version: 2 };
33577
+ return [
33578
+ {
33579
+ trustedFingerprint: await verifyUserEncryptionPublicKey(actorKey),
33580
+ userEncryption: actorKey
33581
+ },
33582
+ ...others.flatMap(
33583
+ (entry) => entry.encryption ? [
33584
+ {
33585
+ ...entry.trustedFingerprint ? { trustedFingerprint: entry.trustedFingerprint } : {},
33586
+ userEncryption: entry.encryption
33587
+ }
33588
+ ] : []
33589
+ )
33590
+ ];
33591
+ };
33592
+
33593
+ // src/resolveRecipientSelectors.ts
33594
+ var resolveRecipientSelectors = ({
33595
+ recipients,
33596
+ selectors
33597
+ }) => selectors.map((selector) => {
33598
+ const byId = recipients.find(
33599
+ (recipient) => recipient.recipientId === selector
33600
+ );
33601
+ if (byId) {
33602
+ return byId.recipientId;
33603
+ }
33604
+ const byLabel = recipients.filter(
33605
+ (recipient) => recipient.label === selector
33606
+ );
33607
+ if (byLabel.length === 1) {
33608
+ return byLabel[0].recipientId;
33609
+ }
33610
+ if (byLabel.length > 1) {
33611
+ throw new Error(
33612
+ `Several recipients are labelled "${selector}"; select one by recipient id: ${byLabel.map((recipient) => recipient.recipientId).join(", ")}`
33613
+ );
33614
+ }
33615
+ throw new Error(`No recipient matches "${selector}".`);
33616
+ });
33617
+
33618
+ // src/rekeyEncryptedTextForUser.ts
33619
+ var rekeyEncryptedTextForUser = async ({
33620
+ encryptedText,
33621
+ lookupPublicKeys,
33622
+ password,
33623
+ reissue,
33624
+ remove,
33625
+ userEncryption
33626
+ }) => {
33627
+ if (userEncryption.version === 1) {
33628
+ throw new Error(
33629
+ "Legacy encryption must be migrated before rekeying (run `fm encryption migrate`)."
33630
+ );
33631
+ }
33632
+ const { recipients } = parseEncryptedPlainTextPayload(encryptedText);
33633
+ if (!findEncryptionRecipient({
33634
+ recipients,
33635
+ recipientId: userEncryption.keyId
33636
+ })) {
33637
+ throw new Error(
33638
+ "You are not a recipient of this file, so its key cannot be unwrapped."
33639
+ );
33640
+ }
33641
+ const removeRecipientIds = resolveRecipientSelectors({
33642
+ recipients,
33643
+ selectors: remove
33644
+ });
33645
+ const reissueRecipientIds = resolveRecipientSelectors({
33646
+ recipients,
33647
+ selectors: reissue
33648
+ });
33649
+ const userKey = await unlockUserEncryption({
33650
+ metadata: userEncryption,
33651
+ password
33652
+ });
33653
+ const fileKey = await unwrapFileKey({
33654
+ recipients,
33655
+ recipientId: userEncryption.keyId,
33656
+ userKey
33657
+ });
33658
+ const candidates = await resolveRecipientPublicKeys({
33659
+ actor: userEncryption,
33660
+ lookupPublicKeys,
33661
+ recipients
33662
+ });
33663
+ const { issues, plan } = planRecipientRekey({
33664
+ candidates,
33665
+ recipients,
33666
+ reissueRecipientIds,
33667
+ removeRecipientIds
33668
+ });
33669
+ if (issues.length) {
33670
+ throw new Error(describeRekeyIssues(issues));
33671
+ }
33672
+ const result = await rekeyEncryptedPlainText({
33673
+ actorKeyId: userEncryption.keyId,
33674
+ actorUserKey: userKey,
33675
+ encryptedText,
33676
+ fileKey,
33677
+ plan
33678
+ });
33679
+ return {
33680
+ encryptedText: result.encryptedText,
33681
+ issuedSecrets: result.issuedSecrets,
33682
+ removedRecipientIds: result.removedRecipientIds
33683
+ };
33684
+ };
33685
+
33182
33686
  // src/addExternalRecipient.ts
33183
33687
  var addExternalRecipientToEncryptedText = async ({
33184
33688
  encryptedText,
33185
33689
  force,
33690
+ lookupPublicKeys,
33186
33691
  name,
33187
33692
  password,
33693
+ reissue = [],
33694
+ remove = [],
33188
33695
  userEncryption
33189
33696
  }) => {
33190
33697
  const payload = parseEncryptedPlainTextPayload(encryptedText);
33191
- const duplicate = payload.recipients.some(
33698
+ const duplicates = payload.recipients.filter(
33192
33699
  (recipient2) => recipient2.label === name
33193
33700
  );
33194
- if (duplicate && !force) {
33701
+ if (duplicates.length && !force) {
33702
+ throw new Error(
33703
+ `A recipient named "${name}" already exists in this file. Pass --force to replace it; this rekeys the file so the old secret cannot read future versions.`
33704
+ );
33705
+ }
33706
+ if (duplicates.length) {
33707
+ const [replaced, ...extraDuplicates] = duplicates.map(
33708
+ (recipient2) => recipient2.recipientId
33709
+ );
33710
+ const result = await rekeyEncryptedTextForUser({
33711
+ encryptedText,
33712
+ lookupPublicKeys,
33713
+ password,
33714
+ reissue: [replaced, ...reissue],
33715
+ remove: [...extraDuplicates, ...remove],
33716
+ userEncryption
33717
+ });
33718
+ const replacement = result.issuedSecrets.find(
33719
+ (issued) => issued.previousRecipientId === replaced
33720
+ );
33721
+ return {
33722
+ encryptedText: result.encryptedText,
33723
+ otherIssuedSecrets: result.issuedSecrets.filter(
33724
+ (issued) => issued !== replacement
33725
+ ),
33726
+ rekeyed: true,
33727
+ recipientId: replacement.recipientId,
33728
+ removedRecipientIds: result.removedRecipientIds,
33729
+ secret: replacement.secret
33730
+ };
33731
+ }
33732
+ if (remove.length || reissue.length) {
33195
33733
  throw new Error(
33196
- `A recipient named "${name}" already exists in this file. Pass --force to replace it.`
33734
+ "--remove/--reissue only apply when replacing a recipient with --force; use `fm encrypt-rekey` to revoke recipients."
33197
33735
  );
33198
33736
  }
33199
33737
  const userKey = await unlockUserEncryption({
@@ -33209,13 +33747,15 @@ var addExternalRecipientToEncryptedText = async ({
33209
33747
  fileKey,
33210
33748
  name
33211
33749
  });
33212
- const retained = force ? payload.recipients.filter((existing) => existing.label !== name) : payload.recipients;
33213
33750
  return {
33214
33751
  encryptedText: updateEncryptedPlainTextRecipients({
33215
33752
  encryptedText,
33216
- recipients: [...retained, recipient]
33753
+ recipients: [...payload.recipients, recipient]
33217
33754
  }),
33755
+ otherIssuedSecrets: [],
33756
+ rekeyed: false,
33218
33757
  recipientId: recipient.recipientId,
33758
+ removedRecipientIds: [],
33219
33759
  secret
33220
33760
  };
33221
33761
  };
@@ -33423,9 +33963,25 @@ var runEncryptionIdentityCommand = async ({
33423
33963
  );
33424
33964
  };
33425
33965
 
33966
+ // src/writeTextFileIfUnchanged.ts
33967
+ import { readFile as readFile9 } from "fs/promises";
33968
+ var writeTextFileIfUnchanged = async ({
33969
+ expectedText,
33970
+ filePath,
33971
+ text
33972
+ }) => {
33973
+ const current = await readFile9(filePath, "utf8");
33974
+ if (current !== expectedText) {
33975
+ throw new Error(
33976
+ `${filePath} changed while this command was running; nothing was written. Re-run against the latest version.`
33977
+ );
33978
+ }
33979
+ await atomicWriteTextFile(filePath, text);
33980
+ };
33981
+
33426
33982
  // src/openInEditor.ts
33427
33983
  import { spawn } from "child_process";
33428
- import { mkdtemp as mkdtemp2, readFile as readFile9, rm as rm7, writeFile as writeFile5 } from "fs/promises";
33984
+ import { mkdtemp as mkdtemp2, readFile as readFile10, rm as rm7, writeFile as writeFile5 } from "fs/promises";
33429
33985
  import { tmpdir } from "os";
33430
33986
  import path26 from "path";
33431
33987
  var openInEditor = async (currentText, { extension = "" } = {}) => {
@@ -33446,7 +34002,7 @@ var openInEditor = async (currentText, { extension = "" } = {}) => {
33446
34002
  if (exitCode !== 0) {
33447
34003
  return null;
33448
34004
  }
33449
- return await readFile9(tempPath, "utf8");
34005
+ return await readFile10(tempPath, "utf8");
33450
34006
  } finally {
33451
34007
  await rm7(dir, { force: true, recursive: true }).catch(() => {
33452
34008
  });
@@ -33535,7 +34091,7 @@ var standaloneIncludeId = (paragraph) => {
33535
34091
  var textContent = (file2) => file2?.content && "text" in file2.content ? file2.content.text : null;
33536
34092
  var compileMarkdown = async ({
33537
34093
  entry,
33538
- readFile: readFile11,
34094
+ readFile: readFile12,
33539
34095
  optional: optional2,
33540
34096
  limits = {}
33541
34097
  }) => {
@@ -33579,7 +34135,7 @@ var compileMarkdown = async ({
33579
34135
  throw new Error(`Include cycle: ${[...chain, id].join(" -> ")}`);
33580
34136
  let target;
33581
34137
  try {
33582
- target = await readFile11(id);
34138
+ target = await readFile12(id);
33583
34139
  } catch (error51) {
33584
34140
  if (optional2) {
33585
34141
  warnings.push(`Omitted unreadable include ${id} from ${label}.`);
@@ -33658,7 +34214,8 @@ Usage:
33658
34214
  fm hash <filePath> [--store <storeId>] [--token <jwt>] [--local]
33659
34215
  fm encrypt (<text>|--file|-f <localPath>) [--password <password>] [--token <jwt>]
33660
34216
  fm decrypt (<encrypted-json>|--file|-f <localPath>) [--secret <recipient-secret>] [--password <password>] [--token <jwt>]
33661
- fm encrypt-add-recipient (<encrypted-json>|--file|-f <localPath>) --name <recipient-name> [--force] [--json] [--password <password>] [--token <jwt>]
34217
+ fm encrypt-add-recipient (<encrypted-json>|--file|-f <localPath>) --name <recipient-name> [--force [--reissue <label-or-id>]... [--remove <label-or-id>]...] [--json] [--password <password>] [--token <jwt>]
34218
+ fm encrypt-rekey (<encrypted-json>|--file|-f <localPath>) [--remove <label-or-id>]... [--reissue <label-or-id>]... [--json] [--password <password>] [--token <jwt>]
33662
34219
  fm edit (<localPath>|--file|-f <localPath>) [--password <password>] [--token <jwt>]
33663
34220
  fm query <filename-or-path> [-s <storeIds>] [--token <jwt>]
33664
34221
  fm q <filename-or-path> [-s <storeIds>] [--token <jwt>]
@@ -33712,6 +34269,8 @@ Usage:
33712
34269
 
33713
34270
  Auth, config:
33714
34271
  fm auth login|logout|status [--no-open]
34272
+ fm auth sessions list your active CLI sessions
34273
+ fm auth revoke <sessionId> revoke one of your CLI sessions
33715
34274
  fm config show [--state-dir <path>]
33716
34275
  fm config get <key> [--reveal] [--state-dir <path>]
33717
34276
  fm config set <key> <value> [--state-dir <path>]
@@ -33738,7 +34297,9 @@ Encryption:
33738
34297
  Provide your encryption password interactively, via --password, or via DOCTRINE_ENCRYPTION_PASSWORD.
33739
34298
  To decrypt as an external recipient (no account/login), pass --secret <recipient-secret> or set DOCTRINE_RECIPIENT_SECRET.
33740
34299
  encrypt-add-recipient grants a new external recipient (you must already be a recipient) and prints its doctrine-recipient-v1_ secret once \u2014 hand it to CI; with --file the secret is the only stdout line so SECRET=$(fm encrypt-add-recipient \u2026) captures it.
33741
- edit opens an encrypted file's plaintext in $EDITOR (fallback vi) and re-encrypts in place on save, keeping the SAME data key and recipients (unlike encrypt, which rotates the key and drops external recipients). Sync/commit afterward; run fm push for store-synced projects.
34300
+ encrypt-add-recipient --force replaces a same-name recipient by REKEYING the file (new file key, plaintext re-encrypted): the old secret cannot read the new or later versions. Remaining Forum users are kept by public key; other external recipients need --reissue (new secret) or --remove.
34301
+ encrypt-rekey revokes recipients (--remove) and/or reissues external secrets (--reissue) under a new file key. It refuses to drop anyone not named. Revocation covers future versions only \u2014 not earlier versions, backups, or already-copied plaintext/credentials.
34302
+ edit opens an encrypted file's plaintext in $EDITOR (fallback vi) and re-encrypts in place on save, keeping the SAME data key and recipients (unlike encrypt, which rotates the key and drops external recipients). Sync/commit afterward; run fm push for store-synced projects. Editing is not revocation: use encrypt-rekey to cut off a recipient.
33742
34303
  API:
33743
34304
  Uses ${DEFAULT_API_BASE_URL} by default. Set DOCTRINE_API_URL for local development.
33744
34305
  Output:
@@ -33747,7 +34308,7 @@ Output:
33747
34308
  `;
33748
34309
  var readCliVersion = async () => {
33749
34310
  const packageJson = JSON.parse(
33750
- await readFile10(new URL("../package.json", import.meta.url), "utf8")
34311
+ await readFile11(new URL("../package.json", import.meta.url), "utf8")
33751
34312
  );
33752
34313
  return typeof packageJson.version === "string" ? packageJson.version : "unknown";
33753
34314
  };
@@ -33798,6 +34359,8 @@ var parseArgs = (argv) => {
33798
34359
  let encryptionPassword = null;
33799
34360
  let recipientSecret = null;
33800
34361
  let recipientName = null;
34362
+ const removeRecipients = [];
34363
+ const reissueRecipients = [];
33801
34364
  let syncPath = null;
33802
34365
  let syncTarget = null;
33803
34366
  let pathsFile = null;
@@ -33895,6 +34458,23 @@ var parseArgs = (argv) => {
33895
34458
  recipientName = current.slice("--name=".length);
33896
34459
  continue;
33897
34460
  }
34461
+ if (current === "--remove" || current === "--reissue") {
34462
+ if (next) {
34463
+ (current === "--remove" ? removeRecipients : reissueRecipients).push(
34464
+ next
34465
+ );
34466
+ }
34467
+ index += 1;
34468
+ continue;
34469
+ }
34470
+ if (current.startsWith("--remove=")) {
34471
+ removeRecipients.push(current.slice("--remove=".length));
34472
+ continue;
34473
+ }
34474
+ if (current.startsWith("--reissue=")) {
34475
+ reissueRecipients.push(current.slice("--reissue=".length));
34476
+ continue;
34477
+ }
33898
34478
  if (current === "--ref") {
33899
34479
  if (!next) {
33900
34480
  throw new Error(
@@ -34037,6 +34617,8 @@ var parseArgs = (argv) => {
34037
34617
  encryptionPassword,
34038
34618
  recipientSecret,
34039
34619
  recipientName,
34620
+ removeRecipients,
34621
+ reissueRecipients,
34040
34622
  syncPath,
34041
34623
  syncTarget,
34042
34624
  pathsFile,
@@ -34537,7 +35119,7 @@ var readWriteTextInput = async (inlineText, inputFilePath) => {
34537
35119
  throw new Error("Provide either inline text or --file, not both.");
34538
35120
  }
34539
35121
  if (inputFilePath) {
34540
- return readFile10(inputFilePath, "utf8");
35122
+ return readFile11(inputFilePath, "utf8");
34541
35123
  }
34542
35124
  return inlineText ?? null;
34543
35125
  };
@@ -34847,7 +35429,7 @@ var diffRemoteFiles = async ({
34847
35429
  storeRef
34848
35430
  }) => {
34849
35431
  const leftText = await readRemoteTextFile(leftPath, storeRef, client);
34850
- const rightText = localRight ? await readFile10(path27.resolve(rightPath), "utf8") : await readRemoteTextFile(rightPath, storeRef, client);
35432
+ const rightText = localRight ? await readFile11(path27.resolve(rightPath), "utf8") : await readRemoteTextFile(rightPath, storeRef, client);
34851
35433
  return buildUnifiedDiff({
34852
35434
  leftLabel: leftPath,
34853
35435
  leftText,
@@ -35128,7 +35710,7 @@ var runEditCommand = async (rest, parsed, client) => {
35128
35710
  `Usage: ${commandNames} edit (<localPath>|--file|-f <localPath>) [--password <password>] [--token <jwt>]`
35129
35711
  );
35130
35712
  }
35131
- const encryptedText = await readFile10(filePath, "utf8");
35713
+ const encryptedText = await readFile11(filePath, "utf8");
35132
35714
  const [password, userEncryption] = await Promise.all([
35133
35715
  readEncryptionPassword(parsed),
35134
35716
  readUserEncryption(client)
@@ -35143,7 +35725,11 @@ var runEditCommand = async (rest, parsed, client) => {
35143
35725
  renderWarning("No changes; nothing written.");
35144
35726
  return;
35145
35727
  }
35146
- await atomicWriteTextFile(filePath, result.encryptedText);
35728
+ await writeTextFileIfUnchanged({
35729
+ expectedText: encryptedText,
35730
+ filePath,
35731
+ text: result.encryptedText
35732
+ });
35147
35733
  renderOutput(
35148
35734
  `Updated ${filePath}. Run \`${commandNames} push\` (and commit) for store-synced projects.`
35149
35735
  );
@@ -35164,7 +35750,7 @@ var runRecipientSecretDecryptCommand = async (rest, parsed) => {
35164
35750
  };
35165
35751
  var runEncryptAddRecipientCommand = async (rest, parsed, client) => {
35166
35752
  const name = parsed.recipientName?.trim();
35167
- const usage2 = `Usage: ${commandNames} encrypt-add-recipient (<encrypted-json>|--file <localPath>) --name <recipient-name> [--force] [--json]`;
35753
+ const usage2 = `Usage: ${commandNames} encrypt-add-recipient (<encrypted-json>|--file <localPath>) --name <recipient-name> [--force [--reissue <label-or-id>]... [--remove <label-or-id>]...] [--json]`;
35168
35754
  if (!name) {
35169
35755
  throw new Error(usage2);
35170
35756
  }
@@ -35182,24 +35768,38 @@ var runEncryptAddRecipientCommand = async (rest, parsed, client) => {
35182
35768
  const result = await addExternalRecipientToEncryptedText({
35183
35769
  encryptedText,
35184
35770
  force: parsed.force,
35771
+ lookupPublicKeys: createPublicKeyLookup(client),
35185
35772
  name,
35186
35773
  password,
35774
+ reissue: parsed.reissueRecipients,
35775
+ remove: parsed.removeRecipients,
35187
35776
  userEncryption: userEncryption.userEncryption
35188
35777
  });
35189
35778
  if (parsed.inputFilePath) {
35190
- await writeFile6(parsed.inputFilePath, result.encryptedText, "utf8");
35779
+ await writeTextFileIfUnchanged({
35780
+ expectedText: encryptedText,
35781
+ filePath: parsed.inputFilePath,
35782
+ text: result.encryptedText
35783
+ });
35191
35784
  }
35192
35785
  if (parsed.json) {
35193
35786
  renderOutput({
35194
35787
  name,
35195
35788
  recipientId: result.recipientId,
35789
+ rekeyed: result.rekeyed,
35790
+ removedRecipientIds: result.removedRecipientIds,
35791
+ reissued: result.otherIssuedSecrets,
35196
35792
  secret: result.secret,
35197
35793
  ...parsed.inputFilePath ? {} : { ciphertext: result.encryptedText }
35198
35794
  });
35199
35795
  return;
35200
35796
  }
35797
+ if (result.rekeyed) {
35798
+ renderWarning(rekeyNotice(result.removedRecipientIds));
35799
+ }
35800
+ renderIssuedSecretsToStderr(result.otherIssuedSecrets);
35201
35801
  renderWarning(
35202
- `Added recipient "${name}". Recipient secret (shown once \u2014 hand to CI):`
35802
+ `${result.rekeyed ? "Replaced" : "Added"} recipient "${name}". Recipient secret (shown once \u2014 hand to CI):`
35203
35803
  );
35204
35804
  if (parsed.inputFilePath) {
35205
35805
  process.stdout.write(`${result.secret}
@@ -35210,8 +35810,79 @@ var runEncryptAddRecipientCommand = async (rest, parsed, client) => {
35210
35810
  `);
35211
35811
  renderOutput(result.encryptedText);
35212
35812
  };
35813
+ var createPublicKeyLookup = (client) => async (userIds) => {
35814
+ const [keys, preferences] = await Promise.all([
35815
+ client.readPublicEncryptionKeys({ userIds }),
35816
+ client.readUserPreferences()
35817
+ ]);
35818
+ const trustedKeys = preferences.encryptionTrustedKeys ?? {};
35819
+ return keys.map((entry) => ({
35820
+ encryption: entry.encryption,
35821
+ ...trustedKeys[entry.userId] ? { trustedFingerprint: trustedKeys[entry.userId].fingerprint } : {},
35822
+ userId: entry.userId
35823
+ }));
35824
+ };
35825
+ var rekeyNotice = (removedRecipientIds) => [
35826
+ "Rekeyed: the file now uses a new file key.",
35827
+ removedRecipientIds.length ? `Revoked recipients: ${removedRecipientIds.join(", ")}.` : null,
35828
+ "Old secrets and wrappers cannot read this or later versions. They can still read earlier versions and backups, and anything already decrypted or copied; rotate the underlying credentials at their providers if that matters."
35829
+ ].filter(Boolean).join(" ");
35830
+ var renderIssuedSecretsToStderr = (issued) => {
35831
+ if (!issued.length) {
35832
+ return;
35833
+ }
35834
+ renderWarning(
35835
+ "Reissued recipient secrets (shown once \u2014 previous secrets no longer read new versions):"
35836
+ );
35837
+ for (const entry of issued) {
35838
+ process.stderr.write(`${entry.label} ${entry.secret}
35839
+ `);
35840
+ }
35841
+ };
35842
+ var runEncryptRekeyCommand = async (rest, parsed, client) => {
35843
+ const usage2 = `Usage: ${commandNames} encrypt-rekey (<encrypted-json>|--file <localPath>) [--remove <label-or-id>]... [--reissue <label-or-id>]... [--json]`;
35844
+ const encryptedText = await readCommandTextInput(
35845
+ rest.length ? rest.join(" ") : void 0,
35846
+ parsed.inputFilePath
35847
+ );
35848
+ if (encryptedText === null) {
35849
+ throw new Error(usage2);
35850
+ }
35851
+ const [password, userEncryption] = await Promise.all([
35852
+ readEncryptionPassword(parsed),
35853
+ readUserEncryption(client)
35854
+ ]);
35855
+ const result = await rekeyEncryptedTextForUser({
35856
+ encryptedText,
35857
+ lookupPublicKeys: createPublicKeyLookup(client),
35858
+ password,
35859
+ reissue: parsed.reissueRecipients,
35860
+ remove: parsed.removeRecipients,
35861
+ userEncryption: userEncryption.userEncryption
35862
+ });
35863
+ if (parsed.inputFilePath) {
35864
+ await writeTextFileIfUnchanged({
35865
+ expectedText: encryptedText,
35866
+ filePath: parsed.inputFilePath,
35867
+ text: result.encryptedText
35868
+ });
35869
+ }
35870
+ if (parsed.json) {
35871
+ renderOutput({
35872
+ reissued: result.issuedSecrets,
35873
+ removedRecipientIds: result.removedRecipientIds,
35874
+ ...parsed.inputFilePath ? {} : { ciphertext: result.encryptedText }
35875
+ });
35876
+ return;
35877
+ }
35878
+ renderWarning(rekeyNotice(result.removedRecipientIds));
35879
+ renderIssuedSecretsToStderr(result.issuedSecrets);
35880
+ renderOutput(
35881
+ parsed.inputFilePath ? `Updated ${parsed.inputFilePath}. Run \`${commandNames} push\` (and commit) for store-synced projects.` : result.encryptedText
35882
+ );
35883
+ };
35213
35884
  var defaultEncryptionMigrationBackupPath = () => path27.resolve(process.cwd(), "doctrine-encryption-migration.json");
35214
- var readEncryptionMigrationBackup = async (backupPath) => JSON.parse(await readFile10(backupPath, "utf8"));
35885
+ var readEncryptionMigrationBackup = async (backupPath) => JSON.parse(await readFile11(backupPath, "utf8"));
35215
35886
  var writeEncryptionMigrationBackup = async (backupPath, backup) => {
35216
35887
  await mkdir7(path27.dirname(backupPath), { recursive: true });
35217
35888
  await writeFile6(backupPath, `${JSON.stringify(backup, null, 2)}
@@ -38240,8 +38911,19 @@ var main = async (argv = process.argv.slice(2)) => {
38240
38911
  return;
38241
38912
  }
38242
38913
  if (subcommand === "logout") {
38243
- await deleteStoredToken(parsed.stateDir);
38244
- renderOutput("Logged out. Local CLI credential removed.");
38914
+ const storedToken = await readStoredToken(parsed.stateDir);
38915
+ const outcome = await withActivity(
38916
+ "Logging out",
38917
+ () => logoutCliSession({
38918
+ clearLocalCredential: () => deleteStoredToken(parsed.stateDir),
38919
+ hasStoredCredential: storedToken !== null,
38920
+ revokeCurrentSession: () => createClient({
38921
+ apiBaseUrl: ensureApiBaseUrl(config3.apiBaseUrl),
38922
+ token: storedToken
38923
+ }).revokeCurrentCliSession()
38924
+ })
38925
+ );
38926
+ describeLogoutOutcome(outcome).forEach((line) => renderOutput(line));
38245
38927
  if (process.env.DOCTRINE_TOKEN) {
38246
38928
  renderOutput("DOCTRINE_TOKEN is still set in this environment.");
38247
38929
  }
@@ -38251,7 +38933,29 @@ var main = async (argv = process.argv.slice(2)) => {
38251
38933
  renderOutput(config3.token ? "Authenticated" : "Not authenticated");
38252
38934
  return;
38253
38935
  }
38254
- throw new Error(`Usage: ${commandNames} auth login|logout|status`);
38936
+ if (subcommand === "sessions") {
38937
+ const sessions = await createClient(config3).listCliSessions();
38938
+ if (parsed.json) {
38939
+ renderOutput(sessions);
38940
+ return;
38941
+ }
38942
+ renderOutput(
38943
+ sessions.length === 0 ? "No active CLI sessions." : styleText.table(formatCliSessionRows(sessions))
38944
+ );
38945
+ return;
38946
+ }
38947
+ if (subcommand === "revoke") {
38948
+ const sessionId = rest[1]?.trim();
38949
+ if (!sessionId || rest.length > 2) {
38950
+ throw new Error(`Usage: ${commandNames} auth revoke <sessionId>`);
38951
+ }
38952
+ await createClient(config3).revokeCliSession({ sessionId });
38953
+ renderOutput(`Revoked CLI session ${sessionId}.`);
38954
+ return;
38955
+ }
38956
+ throw new Error(
38957
+ `Usage: ${commandNames} auth login|logout|status|sessions|revoke`
38958
+ );
38255
38959
  }
38256
38960
  if (command === "config") {
38257
38961
  const subcommand = rest[0];
@@ -38333,6 +39037,10 @@ var main = async (argv = process.argv.slice(2)) => {
38333
39037
  await runEncryptCommand(rest, parsed, client);
38334
39038
  return;
38335
39039
  }
39040
+ if (command === "encrypt-rekey") {
39041
+ await runEncryptRekeyCommand(rest, parsed, client);
39042
+ return;
39043
+ }
38336
39044
  if (command === "encrypt-add-recipient") {
38337
39045
  await runEncryptAddRecipientCommand(rest, parsed, client);
38338
39046
  return;