saturndocs 0.1.2 → 0.3.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 (63) hide show
  1. package/dist/auth-OIEL34E4.js +16 -0
  2. package/dist/{chunk-3V753MRI.js → chunk-32ATWMIS.js} +3 -3
  3. package/dist/{chunk-U7PKMSB3.js → chunk-3EW6ZPL6.js} +5 -5
  4. package/dist/{chunk-GYRVGWDM.js → chunk-3KCCCMQY.js} +408 -36
  5. package/dist/{chunk-SABK3R2P.js → chunk-3X2NBWZN.js} +245 -161
  6. package/dist/chunk-5ZYUBLEH.js +5154 -0
  7. package/dist/{chunk-N7QPZMLP.js → chunk-6EKGBIUR.js} +2 -2
  8. package/dist/{chunk-CMNX5DLQ.js → chunk-BOWRQKXR.js} +12 -6
  9. package/dist/chunk-E3G56DR2.js +949 -0
  10. package/dist/chunk-FUZE54DG.js +905 -0
  11. package/dist/chunk-HBSJ4Z4S.js +53 -0
  12. package/dist/{chunk-5KX4ZK5E.js → chunk-IJOYWJVM.js} +13 -7
  13. package/dist/chunk-IWIVHHZI.js +426 -0
  14. package/dist/{chunk-XO4CUC7V.js → chunk-PU37LVIF.js} +3 -3
  15. package/dist/{chunk-STCCGFKC.js → chunk-RKM7YWPD.js} +25 -6
  16. package/dist/{chunk-KGJESHJC.js → chunk-T3MCJYSF.js} +1 -1
  17. package/dist/chunk-TEYHAN2L.js +90 -0
  18. package/dist/chunk-VDGVERLX.js +87 -0
  19. package/dist/{chunk-S45UWCML.js → chunk-W3FZTCKV.js} +15 -13
  20. package/dist/chunk-WMS6FUKK.js +414 -0
  21. package/dist/chunk-WXLJZ7RD.js +115 -0
  22. package/dist/chunk-YGVC4N4V.js +29 -0
  23. package/dist/chunk-YPWPLIEZ.js +86 -0
  24. package/dist/cli.js +6 -6
  25. package/dist/coverage-SRIA65FT.js +15 -0
  26. package/dist/dist-LJSALT4X.js +150 -0
  27. package/dist/index.d.ts +99 -34
  28. package/dist/index.js +142 -49
  29. package/dist/{init-7T5TEPBH.js → init-Y3GDNDWW.js} +5 -3
  30. package/dist/lint-XM26WIGE.js +13 -0
  31. package/dist/login-HIXLPRUI.js +22 -0
  32. package/dist/{manage-MKH27U3B.js → manage-3HEBB3EQ.js} +6 -2
  33. package/dist/nav-K43WZJ4J.js +14 -0
  34. package/dist/openapiCheck-CL2AH3YC.js +105 -0
  35. package/dist/pages-4VWB7Z4S.js +16 -0
  36. package/dist/{read-DMSJUEDA.js → read-DYGYUOFK.js} +5 -4
  37. package/dist/{read-ZEVUZNNB.js → read-RKT6HUZ7.js} +41 -7
  38. package/dist/requests-CZYE6GI3.js +13 -0
  39. package/dist/{schema-XJUEZSIW.js → schema-QMJMGD5P.js} +3 -3
  40. package/dist/{sites-I4WI2MPG.js → sites-JKS25SEM.js} +5 -4
  41. package/dist/{status-7R3NOI5H.js → status-FM2ALQUJ.js} +4 -4
  42. package/dist/{suggestions-4WFQ3APX.js → suggestions-Z6XIHMFN.js} +13 -7
  43. package/dist/unavailable-DVPNUO3J.js +40 -0
  44. package/dist/validate-X42T4TJ6.js +12 -0
  45. package/package.json +14 -7
  46. package/dist/auth-FRCFGNYT.js +0 -14
  47. package/dist/brokenLinks-TTOBP4P7.js +0 -48
  48. package/dist/build-F5PWGP57.js +0 -39
  49. package/dist/chunk-3P2OFTXR.js +0 -71
  50. package/dist/chunk-I6U4V7B4.js +0 -1552
  51. package/dist/chunk-OEAEX5YW.js +0 -51
  52. package/dist/chunk-OZWTXMO3.js +0 -584
  53. package/dist/chunk-QLFODLVN.js +0 -46
  54. package/dist/chunk-R3X2DPFF.js +0 -568
  55. package/dist/chunk-TKISMN3P.js +0 -39
  56. package/dist/chunk-VNYDYHXM.js +0 -22
  57. package/dist/chunk-VXEUNRVA.js +0 -26
  58. package/dist/deploy-QU7DCKWU.js +0 -11
  59. package/dist/dev-VDSDCBO2.js +0 -43
  60. package/dist/openapiCheck-KGBQJTIQ.js +0 -66
  61. package/dist/pages-HIPXRLSY.js +0 -15
  62. package/dist/requests-H5MIGBIS.js +0 -13
  63. package/dist/validate-VXL4PL42.js +0 -30
@@ -25,14 +25,16 @@ var REQUEST_THREAD_AUTHORS = ["owner", "agent", "platform"];
25
25
  var REQUEST_THREAD_KINDS = ["request", "understood", "question", "answer", "draft", "no_change", "failed"];
26
26
  var GIT_CONNECTION_TRANSITIONS = Object.freeze({ active: Object.freeze(["broken"]), broken: Object.freeze(["active"]) });
27
27
  var GIT_CONNECTION_UNIQUENESS = Object.freeze({ activeSite: ["siteId"], activeSource: ["provider", "installationId", "repositoryId", "branch", "docsRoot"] });
28
+ var SCHEDULE_INTERVAL_MS = Object.freeze({ daily: 24 * 60 * 60 * 1e3, weekly: 7 * 24 * 60 * 60 * 1e3 });
28
29
  var DEFAULT_SKIP_LABELS = Object.freeze(["no-docs", "skip-docs"]);
29
30
  var DEFAULT_IGNORE_GLOBS = Object.freeze(["**/*.test.*", "**/__tests__/**", "**/*.lock", "**/node_modules/**", ".github/**"]);
30
31
  var DEFAULT_SKIP_AUTHORS = Object.freeze(["*[bot]"]);
31
32
  var ENFORCEMENT = Object.freeze({ ownership: "d1_transaction", heads: "d1_transaction", hostname: "d1_transaction", gitConnections: "d1_transaction", webhookDeliveries: "d1_transaction", tombstone: "d1_transaction", jobRelations: "d1_transaction", records: "d1_transaction", sourceBlobs: "r2_ordering", releaseObjects: "r2_ordering" });
33
+ var PR_PREVIEW_IDLE_MS = 30 * 24 * 60 * 60 * 1e3;
32
34
 
33
35
  // ../owner-contract/dist/index.js
34
36
  import { z } from "zod";
35
- var MANAGEMENT_SCOPES = ["manage:read", "manage:write", "manage:approve", "manage:access"];
37
+ var MANAGEMENT_SCOPES = ["manage:read", "manage:write", "manage:approve", "manage:access", "rollback"];
36
38
  var ManagementCredential = z.object({
37
39
  token_id: z.string(),
38
40
  site_id: z.string(),
@@ -48,7 +50,7 @@ var ManagementCredential = z.object({
48
50
  var ManagementCredentials = z.object({ site_id: z.string(), credentials: z.array(ManagementCredential) });
49
51
  var CreateManagementCredential = z.object({
50
52
  label: z.string().trim().min(1).max(80),
51
- scopes: z.array(z.enum(MANAGEMENT_SCOPES)).min(1).max(4).refine((scopes) => new Set(scopes).size === scopes.length, "Permissions must be unique"),
53
+ scopes: z.array(z.enum(MANAGEMENT_SCOPES)).min(1).max(MANAGEMENT_SCOPES.length).refine((scopes) => new Set(scopes).size === scopes.length, "Permissions must be unique"),
52
54
  expires_at: z.iso.datetime()
53
55
  }).strict();
54
56
  var IssuedManagementCredential = z.object({ credential: ManagementCredential, token: z.string() });
@@ -56,9 +58,21 @@ var OWNER_PREFIX = "/__gs-portal";
56
58
  var MAX_SESSION_EVIDENCE = 20;
57
59
  var OWNER_PATHS = {
58
60
  login: `${OWNER_PREFIX}/login`,
59
- magicRequest: `${OWNER_PREFIX}/magic/request`,
60
- magicVerify: `${OWNER_PREFIX}/magic/verify`,
61
+ start: `${OWNER_PREFIX}/start`,
61
62
  logout: `${OWNER_PREFIX}/logout`,
63
+ account: `${OWNER_PREFIX}/account`,
64
+ accountRequirePasskey: `${OWNER_PREFIX}/account/require-passkey`,
65
+ accountSignOutEverywhere: `${OWNER_PREFIX}/account/sign-out-everywhere`,
66
+ accountSession: (id) => OWNER_PREFIX + "/account/sessions/" + encodeURIComponent(id),
67
+ accountPasskey: (id) => `${OWNER_PREFIX}/account/passkeys/${encodeURIComponent(id)}`,
68
+ passkeyRegisterOptions: `${OWNER_PREFIX}/auth/passkey/generate-register-options`,
69
+ passkeyRegister: `${OWNER_PREFIX}/auth/passkey/verify-registration`,
70
+ organization: `${OWNER_PREFIX}/organization`,
71
+ organizationLeave: `${OWNER_PREFIX}/organization/leave`,
72
+ audit: `${OWNER_PREFIX}/audit`,
73
+ billing: `${OWNER_PREFIX}/billing`,
74
+ billingCheckout: `${OWNER_PREFIX}/billing/checkout`,
75
+ billingPortal: `${OWNER_PREFIX}/billing/portal`,
62
76
  switch: `${OWNER_PREFIX}/switch`,
63
77
  site: `${OWNER_PREFIX}/site`,
64
78
  sites: `${OWNER_PREFIX}/sites`,
@@ -77,6 +91,7 @@ var OWNER_PATHS = {
77
91
  gaps: `${OWNER_PREFIX}/gaps`,
78
92
  gapWork: `${OWNER_PREFIX}/gaps/work`,
79
93
  pages: `${OWNER_PREFIX}/pages`,
94
+ releaseRollback: `${OWNER_PREFIX}/releases/rollback`,
80
95
  releases: `${OWNER_PREFIX}/releases`,
81
96
  metrics: `${OWNER_PREFIX}/metrics`,
82
97
  domains: `${OWNER_PREFIX}/domains`,
@@ -87,6 +102,7 @@ var OWNER_PATHS = {
87
102
  buildRetry: `${OWNER_PREFIX}/builds/retry`,
88
103
  build: `${OWNER_PREFIX}/builds`,
89
104
  notifications: `${OWNER_PREFIX}/notifications`,
105
+ previews: `${OWNER_PREFIX}/previews`,
90
106
  owners: `${OWNER_PREFIX}/owners`,
91
107
  owner: (email) => `${OWNER_PREFIX}/owners/${encodeURIComponent(email)}`,
92
108
  settingsProposal: `${OWNER_PREFIX}/settings/proposal`,
@@ -97,12 +113,17 @@ var OWNER_PATHS = {
97
113
  settingsAssistant: `${OWNER_PREFIX}/settings/assistant`,
98
114
  docsRepo: `${OWNER_PREFIX}/docs-repo`,
99
115
  docsRepoReconnect: `${OWNER_PREFIX}/docs-repo/reconnect`,
116
+ docsRepoInspect: `${OWNER_PREFIX}/docs-repo/inspect`,
117
+ docsRepoScaffold: `${OWNER_PREFIX}/docs-repo/scaffold`,
100
118
  productConnections: `${OWNER_PREFIX}/product-connections`,
101
119
  productConnection: (id) => `${OWNER_PREFIX}/product-connections/${encodeURIComponent(id)}`,
102
120
  productConnectionAction: (id, action) => `${OWNER_PREFIX}/product-connections/${encodeURIComponent(id)}/${action}`,
103
121
  productConnectionAnalyse: (id) => `${OWNER_PREFIX}/product-connections/${encodeURIComponent(id)}/analyse`,
122
+ analysisLimit: `${OWNER_PREFIX}/analysis-limit`,
104
123
  githubInstall: `${OWNER_PREFIX}/github/install`,
124
+ githubConnect: `${OWNER_PREFIX}/github/connect`,
105
125
  githubSetup: `${OWNER_PREFIX}/github/setup`,
126
+ githubLink: `${OWNER_PREFIX}/github/link`,
106
127
  githubRepositories: `${OWNER_PREFIX}/github/repositories`,
107
128
  slackInstall: `${OWNER_PREFIX}/slack/install`
108
129
  };
@@ -161,11 +182,12 @@ var SessionSocketServerFrame = z2.discriminatedUnion("type", [SessionSocketDelta
161
182
  var SUGGESTION_TABS = ["pending", "revising", "published", "dismissed", "failed"];
162
183
  var SUGGESTION_ROW_STATES = ["pending_review", "changes_requested", "revising", "publishing", "published", "dismissed", "failed", "superseded"];
163
184
  var MERGE_MODES = ["review", "slack_approval", "autonomous"];
185
+ var TRIGGER_MODES = ["off", "manual", "daily", "weekly", "push"];
164
186
  var CONNECTION_STATES = ["active", "paused", "broken"];
165
187
  var CONNECTION_BROKEN_REASONS = ["uninstalled", "repository_transferred", "branch_deleted"];
166
188
  var INSTALLATION_HEALTH = ["healthy", "stale", "broken"];
167
- var SKIP_REASONS = ["no_matching_connection", "branch_mismatch", "connection_paused", "connection_broken", "no_watched_paths", "deleted_ref", "bot_author", "skip_label", "invalid_sha"];
168
- var ACTIVITY_OPERATIONS = ["product_push", "manual_request", "git_push", "rebuild", "bundle_upload"];
189
+ var ROLLBACK_ACTIVITY_ACCEPT = "application/json; activity=rollback";
190
+ var ACTIVITY_OPERATIONS = ["product_push", "manual_request", "git_push", "rebuild", "bundle_upload", "rollback"];
169
191
  var CONFIDENCES = ["high", "medium", "low"];
170
192
  var TRIAGES = ["user_facing", "internal", "unclear"];
171
193
  var PAGE_CHANGE_OPS = ["create", "update", "delete"];
@@ -185,11 +207,28 @@ var ActiveRelease = z2.object({
185
207
  generation: z2.number().int(),
186
208
  activated_at: nullableString
187
209
  });
210
+ var JobDiagnostic = z2.object({
211
+ path: nullableString,
212
+ code: z2.string(),
213
+ severity: z2.enum(["error", "warning"]),
214
+ message: z2.string(),
215
+ requirement: z2.string().optional(),
216
+ example: z2.string().optional()
217
+ });
218
+ var JobDiagnostics = z2.object({
219
+ total: z2.number().int().nonnegative(),
220
+ items: z2.array(JobDiagnostic)
221
+ });
188
222
  var LatestJob = z2.object({
189
223
  state: z2.string(),
190
224
  error_code: nullableString,
191
225
  error_message: nullableString,
192
- updated_at: isoString
226
+ updated_at: isoString,
227
+ diagnostics: JobDiagnostics.nullable().optional()
228
+ });
229
+ var LatestAuthoringJob = LatestJob.extend({
230
+ /** False when the job failed before it wrote a suggestion, so nothing waits for review (#625). */
231
+ suggestion_created: z2.boolean().optional()
193
232
  });
194
233
  var UsageMeter = z2.object({ used: z2.number(), limit: z2.number() });
195
234
  var PortalUsage = z2.object({
@@ -231,6 +270,7 @@ var ProductConnection = z2.object({
231
270
  state: z2.enum(CONNECTION_STATES),
232
271
  broken_reason: z2.enum(CONNECTION_BROKEN_REASONS).nullable(),
233
272
  merge_mode: z2.enum(MERGE_MODES),
273
+ trigger_mode: z2.enum(TRIGGER_MODES).optional(),
234
274
  last_event_at: nullableString
235
275
  });
236
276
  var ProductConnectionRules = ProductConnection.omit({ last_event_at: true }).extend({
@@ -239,6 +279,8 @@ var ProductConnectionRules = ProductConnection.omit({ last_event_at: true }).ext
239
279
  ignore_globs: z2.array(z2.string()),
240
280
  skip_authors: z2.array(z2.string()),
241
281
  skip_labels: z2.array(z2.string()),
282
+ trigger_mode: z2.enum(TRIGGER_MODES),
283
+ last_scheduled_at: nullableString.optional(),
242
284
  connection_generation: z2.number().int()
243
285
  });
244
286
  var OWNER_ROLES = ["owner", "viewer"];
@@ -249,15 +291,21 @@ var PortalSite = z2.object({
249
291
  hostnames: z2.array(z2.string()),
250
292
  active_release: ActiveRelease.nullable(),
251
293
  latest_job: LatestJob.nullable(),
252
- latest_authoring_job: LatestJob.nullable().optional(),
294
+ latest_authoring_job: LatestAuthoringJob.nullable().optional(),
253
295
  reader_status: z2.enum(["published", "unpublished", "unknown"]).optional(),
296
+ repo_watcher: z2.boolean().optional(),
254
297
  connections: z2.array(ProductConnection),
255
298
  docs_repo: DocsRepo.nullable(),
256
299
  installations: z2.array(Installation).optional(),
257
300
  slack: SlackConnection.nullable().optional(),
258
301
  usage: PortalUsage.optional()
259
302
  });
260
- var SiteSummary = z2.object({ site_id: z2.string(), primary_host: z2.string().nullable() });
303
+ var SiteSummary = z2.object({
304
+ site_id: z2.string(),
305
+ primary_host: z2.string().nullable(),
306
+ organization_id: z2.string().nullable().optional(),
307
+ organization_name: z2.string().nullable().optional()
308
+ });
261
309
  var SitesResponse = z2.object({ current: z2.string(), sites: z2.array(SiteSummary) });
262
310
  var RationaleEntry = z2.object({ change: z2.string(), affects: z2.array(z2.string()) });
263
311
  var PreviewBlock = z2.object({
@@ -418,7 +466,9 @@ var RequestChangesBody = z2.object({ note: z2.string().min(1).max(MAX_REQUEST_CH
418
466
  var RetryBody = z2.object({});
419
467
  var SessionMessageBody = z2.object({
420
468
  message: z2.string().min(1).max(MAX_SESSION_MESSAGE_CHARS),
421
- question_id: z2.string().min(1).max(MAX_QUESTION_ID_CHARS).optional()
469
+ question_id: z2.string().min(1).max(MAX_QUESTION_ID_CHARS).optional(),
470
+ /** The session object's dedup key: a replay with the same id and message gets the first turn's result, not a second turn. */
471
+ turn_id: z2.string().uuid().optional()
422
472
  });
423
473
  var SessionResponse = z2.object({
424
474
  answer: z2.string().min(1).max(2e3),
@@ -451,7 +501,7 @@ var ActivityEvent = z2.object({
451
501
  pr_number: z2.number().int().nullable(),
452
502
  triage: z2.enum(TRIAGES).nullable().optional(),
453
503
  pages_considered: nullableString.optional(),
454
- skip_reason: z2.enum(SKIP_REASONS).nullable().optional(),
504
+ skip_reason: z2.string().nullable().optional(),
455
505
  reason: nullableString.optional(),
456
506
  release: ActivityRelease.nullable().optional(),
457
507
  pusher: nullableString.optional(),
@@ -569,7 +619,48 @@ var ReleaseRecord = z2.object({
569
619
  generation: z2.number().int().nullable(),
570
620
  job: z2.object({ job_id: z2.string(), operation: nullableString, commit_sha: nullableString, requested_by: nullableString })
571
621
  });
622
+ var rollbackReleaseId = z2.string().min(1).max(200).regex(/^[^/\\\s\u0000]+$/u).refine((id) => id !== "." && id !== "..");
623
+ var ReleaseRollbackBody = z2.strictObject({
624
+ release_id: rollbackReleaseId,
625
+ expected_active_release_id: rollbackReleaseId,
626
+ expected_generation: z2.number().int().nonnegative()
627
+ });
628
+ var ReleaseRollbackResponse = z2.object({
629
+ site_id: z2.string(),
630
+ active_release_id: z2.string(),
631
+ previous_release_id: z2.string(),
632
+ generation: z2.number().int().positive(),
633
+ security_epoch: z2.number().int().nonnegative(),
634
+ message: z2.string()
635
+ });
636
+ function rollbackProofMatches(site, body, proof) {
637
+ return proof.site_id === site && proof.active_release_id === body.release_id && proof.previous_release_id === body.expected_active_release_id && proof.generation === body.expected_generation + 1;
638
+ }
639
+ var SUPERSEDED_ROLLBACK = "rollback_applied_then_superseded";
640
+ var SupersededRollbackReceipt = z2.object({
641
+ error: z2.literal(SUPERSEDED_ROLLBACK),
642
+ site_id: z2.string().min(1),
643
+ release_id: rollbackReleaseId,
644
+ previous_release_id: rollbackReleaseId,
645
+ applied_generation: z2.number().int().positive(),
646
+ active_release_id: rollbackReleaseId,
647
+ generation: z2.number().int().positive()
648
+ });
649
+ function matchSupersededRollback(site, body, value) {
650
+ const parsed = SupersededRollbackReceipt.safeParse(value);
651
+ if (!parsed.success) return null;
652
+ const receipt = parsed.data;
653
+ return receipt.site_id === site && receipt.release_id === body.release_id && receipt.previous_release_id === body.expected_active_release_id && receipt.applied_generation === body.expected_generation + 1 && receipt.generation > receipt.applied_generation ? receipt : null;
654
+ }
655
+ function describeSupersededRollback(receipt) {
656
+ return `Rollback to ${receipt.release_id} was applied at generation ${receipt.applied_generation} and later superseded by ${receipt.active_release_id} at generation ${receipt.generation}.`;
657
+ }
658
+ var ROLLBACK_RECOVERY = "The rollback may already have been applied. Check the active release and generation. To reconcile, repeat the original rollback with the same site, target, expected active release, and generation.";
659
+ function uncertainRollbackRefusal(status, code) {
660
+ return code === "rollback_superseded" || (status ?? 0) >= 500 && code !== "limit_unavailable";
661
+ }
572
662
  var ReleasesPage = z2.object({
663
+ active_generation: z2.number().int().nullable().optional(),
573
664
  site_id: z2.string(),
574
665
  active_release_id: nullableString,
575
666
  active_release_status: z2.enum(["known", "unknown"]).optional(),
@@ -700,16 +791,101 @@ var NotificationPut = z2.object({
700
791
  event: z2.enum(OWNER_NOTIFICATION_EVENTS),
701
792
  mode: z2.enum(OWNER_NOTIFICATION_MODES)
702
793
  });
703
- var OwnerRow = z2.object({ email: z2.string(), role: OwnerRole.optional(), added_at: isoString, you: z2.boolean() });
704
- var OwnersResponse = z2.object({ site_id: z2.string(), owners: z2.array(OwnerRow) });
705
- var OwnerResponse = z2.object({ owner: OwnerRow });
706
- var AddOwnerBody = z2.object({ email: z2.string().min(3).max(320), role: OwnerRole.optional() });
707
- var OwnerRoleBody = z2.object({ role: OwnerRole });
794
+ var PreviewSettings = z2.object({ pr_previews: z2.boolean() });
795
+ var ORGANIZATION_ROLES = ["owner", "admin", "editor", "viewer"];
796
+ var OrganizationRole = z2.enum(ORGANIZATION_ROLES);
797
+ var OrganizationSummary = z2.object({ id: z2.string(), name: z2.string() });
798
+ var OwnerRow = z2.object({ member_id: z2.string().optional(), email: z2.string(), role: OrganizationRole.optional(), added_at: isoString, you: z2.boolean() });
799
+ var OwnersResponse = z2.object({ site_id: z2.string(), organization: OrganizationSummary.optional(), owners: z2.array(OwnerRow) });
800
+ var OwnerResponse = z2.object({ owner: OwnerRow, organization: OrganizationSummary.optional() });
801
+ var AddOwnerBody = z2.object({ email: z2.string().min(3).max(320), role: OrganizationRole.optional() });
802
+ var OwnerRoleBody = z2.object({ role: OrganizationRole, member_id: z2.string().min(1) });
803
+ var OrganizationResponse = z2.object({
804
+ id: z2.string(),
805
+ name: z2.string(),
806
+ role: OrganizationRole.nullable(),
807
+ sites: z2.array(z2.object({ site_id: z2.string(), primary_host: z2.string().nullable() })),
808
+ can_leave: z2.boolean().optional(),
809
+ member_count: z2.number().int().nonnegative()
810
+ });
811
+ var OrganizationLeaveResponse = z2.object({ left: z2.string() });
812
+ var AuditResponse = z2.object({
813
+ entries: z2.array(z2.object({
814
+ id: z2.number().int(),
815
+ organization_id: z2.string(),
816
+ site_id: z2.string(),
817
+ actor: z2.string().nullable(),
818
+ op: z2.string(),
819
+ outcome: z2.string(),
820
+ subject: z2.string().nullable(),
821
+ created_at: z2.string(),
822
+ detail: z2.record(z2.string(), z2.union([z2.string(), z2.number(), z2.boolean(), z2.null()]))
823
+ })),
824
+ next_cursor: z2.string().nullable()
825
+ });
826
+ var OrganizationRenameBody = z2.object({ name: z2.string().min(1).max(80) });
827
+ var AccountPasskey = z2.object({
828
+ id: z2.string(),
829
+ name: z2.string().nullable(),
830
+ device_type: z2.string(),
831
+ backed_up: z2.boolean(),
832
+ created_at: z2.string().nullable()
833
+ });
834
+ var AccountResponse = z2.object({
835
+ id: z2.string(),
836
+ email: z2.string(),
837
+ signed_in_with: z2.enum(["email-otp", "passkey"]),
838
+ sessions: z2.array(z2.object({
839
+ id: z2.string(),
840
+ device: z2.string(),
841
+ host: z2.string().nullable(),
842
+ signed_in: z2.string(),
843
+ last_active: z2.string(),
844
+ method: z2.string().nullable(),
845
+ current: z2.boolean()
846
+ })),
847
+ require_passkey: z2.boolean(),
848
+ passkeys: z2.array(AccountPasskey),
849
+ organizations: z2.array(OrganizationSummary.extend({ role: OrganizationRole }))
850
+ });
851
+ var AccountActionResponse = z2.object({ ok: z2.literal(true) });
852
+ var AccountLastOwnerResponse = z2.object({ error: z2.literal("last_owner"), organizations: z2.array(OrganizationSummary) });
853
+ var RequirePasskeyBody = z2.object({ enabled: z2.boolean() });
854
+ var SignOutEverywhereResponse = z2.object({ signed_out: z2.number().int().nonnegative() });
855
+ var BILLING_PLANS = ["none", "standard", "enterprise", "complimentary"];
856
+ var BillingPlan = z2.enum(BILLING_PLANS);
857
+ var BILLING_STATUSES = ["none", "trialing", "active", "past_due", "unpaid", "canceled", "incomplete", "incomplete_expired", "paused"];
858
+ var BillingStatus = z2.enum(BILLING_STATUSES);
859
+ var BillingResponse = z2.object({
860
+ organization: OrganizationSummary,
861
+ plan: BillingPlan,
862
+ offer: z2.literal("early_adopter").nullable().default(null),
863
+ offer_price_cents: z2.number().int().nonnegative().nullable().default(null),
864
+ offer_started_at: z2.string().nullable().default(null),
865
+ offer_locked_until: z2.string().nullable().default(null),
866
+ status: BillingStatus,
867
+ paid: z2.boolean(),
868
+ previewing: z2.boolean(),
869
+ in_grace: z2.boolean(),
870
+ current_period_end: z2.string().nullable(),
871
+ cancel_at_period_end: z2.boolean(),
872
+ site_limit: z2.number().int().nonnegative().nullable(),
873
+ sites_used: z2.number().int().nonnegative(),
874
+ entitlements: z2.object({ custom_domain: z2.boolean(), agent_updates: z2.boolean() }),
875
+ enforced: z2.boolean(),
876
+ checkout_available: z2.boolean(),
877
+ has_customer: z2.boolean(),
878
+ can_subscribe: z2.boolean(),
879
+ portal_available: z2.boolean(),
880
+ reconcile_pending: z2.boolean(),
881
+ can_manage: z2.boolean()
882
+ });
883
+ var BillingRedirect = z2.object({ url: z2.url() });
708
884
  var RemoveOwnerResponse = z2.object({ removed: z2.string(), signed_out: z2.boolean() });
709
885
  var PendingSettingsPr = z2.object({ pr_number: z2.number().int(), html_url: z2.string() });
710
886
  var LogoValue = z2.union([z2.string(), z2.object({ light: z2.string().optional(), dark: z2.string().optional() })]);
711
887
  var RedirectEntry = z2.object({ source: z2.string(), destination: z2.string(), permanent: z2.boolean().optional() });
712
- var MAX_REDIRECTS = 500;
888
+ var MAX_REDIRECTS = 5e3;
713
889
  var SettingsValues = z2.object({
714
890
  name: nullableString.optional(),
715
891
  colors: z2.object({ primary: nullableString }).optional(),
@@ -786,8 +962,35 @@ var DocsRepoConnectBody = z2.object({
786
962
  installation_id: z2.number().int(),
787
963
  repository_id: z2.number().int(),
788
964
  branch: z2.string().min(1),
789
- docs_root: z2.string()
965
+ docs_root: z2.string(),
966
+ first_build: z2.enum(["now", "deferred"]).optional()
967
+ });
968
+ var DocsRepoInspectBody = DocsRepoConnectBody.omit({ first_build: true });
969
+ var BootstrapPr = z2.object({ pr_number: z2.number().int(), html_url: z2.string() });
970
+ var DocsRepoScaffoldBody = DocsRepoConnectBody.omit({ first_build: true }).extend({ mode: z2.enum(["starter", "convert"]), source_mode: z2.enum(["folder", "root_copy"]).optional() });
971
+ var DocsRepoScaffoldSummary = z2.object({ pages: z2.number().int(), starter_added: z2.boolean(), unconverted: z2.number().int(), copied: z2.boolean().optional() });
972
+ var DocsRepoScaffoldResponse = z2.object({ docs_repo: DocsRepo, pending: BootstrapPr, summary: DocsRepoScaffoldSummary.nullable().optional() });
973
+ var DocsRepoBootstrapStatus = z2.object({
974
+ pending: BootstrapPr.nullable(),
975
+ state: z2.enum(["none", "open", "merged", "closed"]),
976
+ pull: BootstrapPr.nullable(),
977
+ docs_json: z2.boolean().nullable(),
978
+ source_mode: z2.enum(["root_copy", "folder"]).optional()
979
+ });
980
+ var DocsRepoSourceBlocked = z2.object({
981
+ error: z2.literal("source_blocked"),
982
+ reason: z2.string(),
983
+ path: z2.string().nullable(),
984
+ scope: z2.enum(["repository", "docs_root"]),
985
+ export_ignore: z2.string().nullable(),
986
+ message: z2.string()
790
987
  });
988
+ var DocsCounts = z2.object({ pages: z2.number().int(), assets: z2.number().int(), unconverted: z2.number().int(), total: z2.number().int() });
989
+ var DocsPlatform = z2.enum(["mintlify", "docusaurus", "mkdocs", "docsify", "mdbook", "sphinx", "gitbook", "jekyll", "antora"]).nullable();
990
+ var DocsInspection = z2.discriminatedUnion("verdict", [
991
+ z2.object({ verdict: z2.enum(["saturndocs", "incompatible", "empty"]), platform: DocsPlatform, counts: DocsCounts, structure_violations: z2.number().int(), site_folder: z2.string().optional() }),
992
+ z2.object({ verdict: z2.literal("unknown"), reason: z2.enum(["token_refused", "branch_missing", "tree_truncated", "github_error"]) })
993
+ ]);
791
994
  var ProductConnectionsResponse = z2.object({ site_id: z2.string().optional(), product_connections: z2.array(ProductConnectionRules) });
792
995
  var ProductConnectionCreateBody = z2.object({
793
996
  installation_id: z2.number().int(),
@@ -797,15 +1000,24 @@ var ProductConnectionCreateBody = z2.object({
797
1000
  ignore_globs: z2.array(z2.string()).optional(),
798
1001
  skip_authors: z2.array(z2.string()).optional(),
799
1002
  skip_labels: z2.array(z2.string()).optional(),
800
- merge_mode: z2.enum(MERGE_MODES).optional()
1003
+ merge_mode: z2.enum(MERGE_MODES).optional(),
1004
+ trigger_mode: z2.enum(TRIGGER_MODES).optional()
801
1005
  });
802
1006
  var ProductConnectionPatchBody = z2.object({
803
1007
  watch_globs: z2.array(z2.string()).optional(),
804
1008
  ignore_globs: z2.array(z2.string()).optional(),
805
1009
  skip_authors: z2.array(z2.string()).optional(),
806
1010
  skip_labels: z2.array(z2.string()).optional(),
807
- merge_mode: z2.enum(MERGE_MODES).optional()
1011
+ merge_mode: z2.enum(MERGE_MODES).optional(),
1012
+ trigger_mode: z2.enum(TRIGGER_MODES).optional()
1013
+ });
1014
+ var AnalysisLimit = z2.object({
1015
+ used: z2.number().int(),
1016
+ limit: z2.number().int(),
1017
+ platform_limit: z2.number().int(),
1018
+ owner_limit: z2.number().int().nullable()
808
1019
  });
1020
+ var AnalysisLimitBody = z2.object({ owner_limit: z2.number().int().min(1).nullable() });
809
1021
  var ProductConnectionWriteResponse = z2.object({
810
1022
  product_connection: ProductConnectionRules.optional(),
811
1023
  dry_run: z2.boolean().optional(),
@@ -814,6 +1026,20 @@ var ProductConnectionWriteResponse = z2.object({
814
1026
  var GrantedRepository = z2.object({ id: z2.number().int(), full_name: z2.string(), default_branch: z2.string().optional() });
815
1027
  var RepositoriesQuery = z2.object({ installation_id: z2.coerce.number().int() });
816
1028
  var RepositoriesResponse = z2.object({ installation_id: z2.number().int(), repositories: z2.array(GrantedRepository) });
1029
+ var GitHubLinkQuery = z2.object({ pick: z2.string().min(1).max(16384) });
1030
+ var GitHubLinkCandidate = z2.object({
1031
+ installation_id: z2.number().int(),
1032
+ account_login: nullableString,
1033
+ suspended: z2.boolean(),
1034
+ linked: z2.boolean()
1035
+ });
1036
+ var GitHubLinkCandidates = z2.object({
1037
+ site_id: z2.string(),
1038
+ expires_at: z2.string(),
1039
+ installations: z2.array(GitHubLinkCandidate)
1040
+ });
1041
+ var GitHubLinkBody = z2.object({ pick: z2.string().min(1).max(16384), installation_id: z2.number().int().positive() }).strict();
1042
+ var GitHubLinkOutcome = z2.object({ installation_id: z2.number().int(), linked: z2.literal(true), already_linked: z2.boolean() });
817
1043
  var SettingsApproval = z2.object({
818
1044
  revision: z2.string(),
819
1045
  pr_number: z2.number().int(),
@@ -1025,6 +1251,8 @@ var RequestChangesOutcome2 = RequestChangesOutcome.loose();
1025
1251
  var ErrorEnvelope2 = ErrorEnvelope.loose();
1026
1252
  var DocsRepoSettings2 = DocsRepoSettings.loose();
1027
1253
  var ProductConnectionsResponse2 = ProductConnectionsResponse.loose();
1254
+ var ReleaseRollbackResponse2 = ReleaseRollbackResponse;
1255
+ var ReleaseRollbackBody2 = ReleaseRollbackBody;
1028
1256
  var MANAGEMENT_SCOPES2 = MANAGEMENT_SCOPES;
1029
1257
  var SHA = /^[0-9a-f]{40}$/u;
1030
1258
  var ExactReviewInput = z32.object({
@@ -1097,6 +1325,7 @@ var P0_OPERATIONS = {
1097
1325
  response: ActivityPage2,
1098
1326
  note: "An exact job read comes from the jobs alone, so a queued job is found however many events came after it."
1099
1327
  },
1328
+ "releases.rollback": { path: "/releases/rollback", method: "POST", permission: "rollback", mutation: true, query: [], response: ReleaseRollbackResponse2, note: "Activate the named pin at the expected active release and generation." },
1100
1329
  "releases.list": {
1101
1330
  path: "/releases",
1102
1331
  method: "GET",
@@ -1274,11 +1503,17 @@ var cursor = { name: "--cursor", value: "string", required: false, description:
1274
1503
  var limit = { name: "--limit", value: "integer", required: false, description: "Page size, within the operation's server ceiling." };
1275
1504
  var P0_COMMANDS = [
1276
1505
  { name: "auth status", operation: "sites.list", operations: ["sites.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: READ_EXITS, summary: "Verify read access and report the credential's own site. Says nothing about scopes the server did not return." },
1506
+ { name: "login", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--new-site", value: "string", required: false, description: "Propose a new site address; the person creates the site while approving." }, { name: "--scope", value: "string", required: false, description: "Comma-separated permissions to request: read, draft, build, publish. Omit to let the person choose from the defaults." }, { name: "--no-wait", value: "boolean", required: false, description: "Print the approval link and exit; finish later with --resume." }, { name: "--resume", value: "boolean", required: false, description: "Wait for the approval started by an earlier --no-wait." }, { name: "--open", value: "boolean", required: false, description: "Open the approval link in the default browser." }], exits: WAIT_EXITS, summary: "Ask a person to approve this agent for one site in the browser, then save the resulting login." },
1507
+ { name: "logout", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--all", value: "boolean", required: false, description: "Revoke and forget every saved login for this API origin." }], exits: WRITE_EXITS, summary: "Revoke a saved login on the server and delete it from this computer." },
1508
+ { name: "sites create", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--scope", value: "string", required: false, description: "Comma-separated permissions to request: read, draft, build, publish. Omit to let the person choose from the defaults." }, { name: "--no-wait", value: "boolean", required: false, description: "Print the approval link and exit; finish later with saturndocs login --resume." }, { name: "--open", value: "boolean", required: false, description: "Open the approval link in the default browser." }], exits: WAIT_EXITS, summary: "Propose a new site; a person creates it while approving this agent, and the login is saved." },
1277
1509
  { name: "sites list", operation: "sites.list", operations: ["sites.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: READ_EXITS, summary: "The sites the presented credential resolves to." },
1278
1510
  { name: "sites get", operation: "site.get", operations: ["site.get", "docs-repo.get", "product-connections.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--connections", value: "boolean", required: false, description: "Also read the documentation repository and watched repositories." }], exits: READ_EXITS, summary: "One site's status, hostnames, publication, and usage." },
1279
1511
  { name: "pages list", operation: "pages.list", operations: ["pages.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--days", value: "integer", required: false, description: "Traffic window: 7, 30, or 90." }], exits: READ_EXITS, summary: "Published pages of the live release. An unpublished site is not an empty list." },
1280
1512
  { name: "status", operation: null, operations: ["site.get", "requests.list", "suggestions.list", "activity.list"], permission: "manage:read", mutation: false, requires_site: true, text_input: "none", text_limit: null, flags: [], exits: READ_EXITS, summary: "Bounded briefing. Each section reports available, empty, or unavailable on its own." },
1281
1513
  { name: "schema", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Versioned command metadata, locally. No credential and no network." },
1514
+ { name: "nav", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--outline", value: "string", required: true, description: "Path to the approved outline JSON." }], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Rewrite docs.json navigation from an approved outline. Local; no credential and no network." },
1515
+ { name: "lint", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Content lint and the known-pitfalls catalog over every page; exits 2 when any finding is an error. Local." },
1516
+ { name: "coverage", operation: null, operations: [], permission: null, mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [{ name: "--outline", value: "string", required: true, description: "Path to the approved outline JSON." }], exits: [EXIT.success, EXIT.invalid_input, EXIT.interrupted], summary: "Compare the pages on disk with an approved outline. Local." },
1282
1517
  { name: "manage", operation: null, operations: [], permission: null, mutation: false, requires_site: true, text_input: "optional", text_limit: null, flags: [{ name: "--data", value: "string", required: false, description: "JSON body, or @path to read one." }, { name: "--file", value: "string", required: false, description: "A multipart file part, repeatable." }, { name: "--revision", value: "string", required: false, description: "The quoted settings revision for If-Match." }], exits: WRITE_EXITS, summary: "One existing management operation chosen by the caller, under the same target and precondition rules as every other command." },
1283
1518
  { name: "requests create", operation: "requests.create", operations: ["requests.create"], permission: "manage:write", mutation: true, requires_site: true, text_input: "required", text_limit: REQUEST_TEXT_LIMIT, flags: [...TEXT, { name: "--submission-id", value: "string", required: true, description: "A UUID the caller keeps. Replaying it with the same payload recovers the same job." }, { name: "--page", value: "string", required: false, description: "The page the request is about." }], exits: WRITE_EXITS, summary: "Submit a documentation request and return its queued job and root thread." },
1284
1519
  { name: "requests reply", operation: "requests.create", operations: ["requests.create"], permission: "manage:write", mutation: true, requires_site: true, text_input: "required", text_limit: REQUEST_TEXT_LIMIT, flags: [...TEXT, { name: "--thread", value: "string", required: true, description: "The root job of the conversation being answered." }, { name: "--submission-id", value: "string", required: true, description: "A UUID the caller keeps, so a lost answer replays instead of duplicating." }], exits: WRITE_EXITS, summary: "Answer a clarification. The root thread is kept; a new job comes back." },
@@ -1300,6 +1535,23 @@ var P0_COMMANDS = [
1300
1535
  { name: "activity list", operation: "activity.list", operations: ["activity.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [cursor, limit, { name: "--outcome", value: "string", required: false, description: "suggestion, nochange, skipped, failed, or published." }, { name: "--repo", value: "string", required: false, description: "Full repository name." }, { name: "--from", value: "string", required: false, description: "Inclusive UTC date." }, { name: "--to", value: "string", required: false, description: "Inclusive UTC date." }], exits: READ_EXITS, summary: "Operational activity, newest first." },
1301
1536
  { name: "activity get", operation: "activity.list", operations: ["activity.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: READ_EXITS, summary: "One job by id, through the list operation's job_id filter. No page-one scan." },
1302
1537
  { name: "releases list", operation: "releases.list", operations: ["releases.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [cursor, limit], exits: READ_EXITS, summary: "Releases, newest first, with activation and current-active status." },
1538
+ {
1539
+ name: "releases rollback",
1540
+ operation: "releases.rollback",
1541
+ operations: ["releases.rollback"],
1542
+ permission: "rollback",
1543
+ mutation: true,
1544
+ requires_site: true,
1545
+ text_input: "none",
1546
+ text_limit: null,
1547
+ flags: [
1548
+ { name: "--expected-active", value: "string", required: true, description: "Currently active release id." },
1549
+ { name: "--expected-generation", value: "integer", required: true, description: "Currently active generation." },
1550
+ { name: "--yes", value: "boolean", required: true, description: "Confirm the rollback." }
1551
+ ],
1552
+ exits: WRITE_EXITS,
1553
+ summary: "Make the pinned release live until the next successful docs push."
1554
+ },
1303
1555
  { name: "releases get", operation: "releases.list", operations: ["releases.list"], permission: "manage:read", mutation: false, requires_site: false, text_input: "none", text_limit: null, flags: [], exits: READ_EXITS, summary: "One release by id, including one older than the first page." }
1304
1556
  ];
1305
1557
  var P0_COMMAND_NAMES = Object.freeze(P0_COMMANDS.map((command) => command.name));
@@ -1441,6 +1693,7 @@ function parseRetryAfter(header, now) {
1441
1693
  async function readBounded(response, maxBytes) {
1442
1694
  const declared = response.headers.get("content-length");
1443
1695
  if (declared !== null && /^\d+$/u.test(declared) && Number(declared) > maxBytes) {
1696
+ await response.body?.cancel().catch(() => void 0);
1444
1697
  throw new Error(`The response is ${declared} bytes, over the ${maxBytes}-byte read limit.`);
1445
1698
  }
1446
1699
  const body = response.body;
@@ -1491,7 +1744,9 @@ function defaultSleep(ms, signal) {
1491
1744
  }
1492
1745
  function createClient(config = {}) {
1493
1746
  const origin = parseOrigin(config.origin);
1494
- const token = config.token;
1747
+ let token = config.token;
1748
+ let pendingToken = null;
1749
+ const provider = config.token === void 0 ? config.tokenProvider : void 0;
1495
1750
  const fetchImpl = config.fetchImpl ?? fetch;
1496
1751
  const callerSignal = config.signal;
1497
1752
  const defaultDeadline = config.deadlineMs ?? DEFAULT_DEADLINE_MS;
@@ -1509,9 +1764,14 @@ function createClient(config = {}) {
1509
1764
  if (input.method === "GET" && (input.body !== void 0 || input.rawBody !== void 0)) throw invalidInput("A GET request does not carry a body.");
1510
1765
  if (input.body !== void 0 && input.rawBody !== void 0) throw invalidInput("A request carries either a JSON body or an encoded one, never both.");
1511
1766
  const anonymous = input.anonymous === true;
1512
- if (!anonymous && (token === void 0 || token === "")) throw invalidInput("Set SATURNDOCS_MANAGEMENT_TOKEN to a management credential for this site.");
1767
+ if (!anonymous && token === void 0 && provider !== void 0) {
1768
+ pendingToken ??= provider();
1769
+ token = await pendingToken;
1770
+ secrets.push(token);
1771
+ }
1772
+ if (!anonymous && (token === void 0 || token === "")) throw invalidInput("Run saturndocs login, or set SATURNDOCS_MANAGEMENT_TOKEN to a management credential for this site.");
1513
1773
  const mutation = input.mutation === true || !IDEMPOTENT.has(input.method);
1514
- const headers = new Headers({ accept: "application/json" });
1774
+ const headers = new Headers({ accept: input.accept ?? "application/json" });
1515
1775
  if (!anonymous) headers.set("authorization", `Bearer ${token}`);
1516
1776
  if (input.revision !== void 0) headers.set("if-match", ifMatchHeader(input.revision));
1517
1777
  const body = input.rawBody ?? (input.body === void 0 ? void 0 : JSON.stringify(input.body));
@@ -1553,6 +1813,7 @@ function createClient(config = {}) {
1553
1813
  try {
1554
1814
  text = await readBounded(response, maxBytes);
1555
1815
  } catch (cause) {
1816
+ if (cancelled(input.signal)) throw interrupted(mutation ? "unknown" : "not_submitted");
1556
1817
  const message = clean(cause instanceof Error ? cause.message : String(cause));
1557
1818
  if (mutation && response.ok) throw unknownOutcome(`The write was accepted but its answer could not be read: ${message} Read the site's state before sending anything again.`);
1558
1819
  throw transportFailure(`The management answer could not be read: ${message}`, mutation ? "unknown" : "not_submitted");
@@ -1574,6 +1835,7 @@ function createClient(config = {}) {
1574
1835
  correlationId,
1575
1836
  mutation: "not_submitted"
1576
1837
  });
1838
+ if (response.status === 409 && input.classifyConflict) throw input.classifyConflict(refusal, data);
1577
1839
  const retryable = !mutation && RETRYABLE_STATUS.has(response.status) && attempts < MAX_READ_ATTEMPTS;
1578
1840
  if (!retryable) throw refusal;
1579
1841
  const waitMs = retryAfter === null ? null : retryAfter * 1e3;
@@ -1672,7 +1934,7 @@ async function resolveTarget(client, request = {}) {
1672
1934
  if (request.mutation === true && request.site === void 0) {
1673
1935
  throw invalidInput("This command writes, so it needs an explicit --site naming the site to act on.");
1674
1936
  }
1675
- const response = await client.get("/v1/sites", { signal: request.signal, deadlineMs: request.deadlineMs });
1937
+ const response = await client.get("/v1/sites", { signal: request.signal, deadlineMs: request.deadlineMs, query: { for: request.forOperation } });
1676
1938
  const parsed = SitesResponse2.safeParse(response.data);
1677
1939
  if (!parsed.success) {
1678
1940
  throw managementError(
@@ -1788,7 +2050,7 @@ function commandMetadata(name, details) {
1788
2050
  }),
1789
2051
  permissions: Object.freeze({
1790
2052
  server: spec.permission,
1791
- preflight: spec.mutation ? "manage:read" : null
2053
+ preflight: spec.permission === "rollback" ? "rollback" : spec.mutation ? "manage:read" : null
1792
2054
  }),
1793
2055
  side_effects: Object.freeze({
1794
2056
  mutation: spec.mutation,
@@ -1908,6 +2170,7 @@ async function listActivity(client, siteId, options = {}) {
1908
2170
  const query = activityQuery({ cursor: cursor2, limit: limit2, outcome, repo, from, to });
1909
2171
  const response = await client.get(operationPath("activity.list", siteId), {
1910
2172
  ...read,
2173
+ accept: ROLLBACK_ACTIVITY_ACCEPT,
1911
2174
  ...Object.keys(query).length === 0 ? {} : { query }
1912
2175
  });
1913
2176
  return parseResponse(ActivityPageRead, response.data, `The activity listing for ${siteId}`);
@@ -2753,6 +3016,39 @@ async function readRequestThread(client, input) {
2753
3016
  });
2754
3017
  return parseResponse(RequestThread2, response.data, "The request thread");
2755
3018
  }
3019
+ async function rollbackRelease(client, siteId, input, signal) {
3020
+ const parsed = ReleaseRollbackBody2.safeParse(input);
3021
+ if (!parsed.success || parsed.data.release_id === parsed.data.expected_active_release_id) {
3022
+ throw invalidInput("Name the pinned release, a different active release, and the current generation.");
3023
+ }
3024
+ const body = parsed.data;
3025
+ const response = await client.request({
3026
+ method: "POST",
3027
+ path: operationPath("releases.rollback", siteId),
3028
+ body,
3029
+ signal,
3030
+ classifyConflict(error, payload) {
3031
+ const { server } = error.detail;
3032
+ if (server?.code !== SUPERSEDED_ROLLBACK) return error;
3033
+ const receipt = matchSupersededRollback(siteId, body, payload);
3034
+ if (!receipt) return unknownOutcome(ROLLBACK_RECOVERY);
3035
+ const message = describeSupersededRollback(receipt);
3036
+ return managementError("conflict", message, { server: { ...server, message }, mutation: "known" });
3037
+ }
3038
+ }).catch((error) => {
3039
+ if (!isManagementError(error)) throw error;
3040
+ const { server } = error.detail;
3041
+ if (server && uncertainRollbackRefusal(server.status, server.code)) {
3042
+ throw managementError("unknown_outcome", ROLLBACK_RECOVERY, { server });
3043
+ }
3044
+ throw error;
3045
+ });
3046
+ const proof = ReleaseRollbackResponse2.safeParse(response.data);
3047
+ if (!proof.success || !rollbackProofMatches(siteId, body, proof.data)) {
3048
+ throw unknownOutcome(ROLLBACK_RECOVERY);
3049
+ }
3050
+ return proof.data;
3051
+ }
2756
3052
  var REQUEST_PAGE_LIMIT = 400;
2757
3053
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
2758
3054
  function checkedSubmissionId(value) {
@@ -3118,6 +3414,12 @@ function previewIds(result) {
3118
3414
  return { suggestion_id: result.suggestion_id };
3119
3415
  }
3120
3416
  var SESSION_MESSAGE_LIMIT2 = MAX_SESSION_MESSAGE_CHARS;
3417
+ var SESSION_MESSAGE_DEADLINE_MS = 5 * 6e4;
3418
+ var SESSION_ATTEMPT_MS = DEFAULT_DEADLINE_MS;
3419
+ var MAX_UNREACHABLE_SENDS = 3;
3420
+ var UNREACHABLE_BACKOFF_MS = 250;
3421
+ var RUNNING_BACKOFF_MS = 1e3;
3422
+ var MAX_REPLAY_BACKOFF_MS = 5e3;
3121
3423
  function requireSuggestionId3(value, usage) {
3122
3424
  if (value.trim() === "") throw invalidInput(`Name the suggestion to act on, as ${usage}.`);
3123
3425
  return value;
@@ -3133,6 +3435,13 @@ function unreadableTurn(suggestionId) {
3133
3435
  `The message was accepted and its answer was not in the shape this client understands, so whether it queued a revision is not reported here. Read the transcript with saturndocs suggestions conversation ${suggestionId} before sending anything again; sending this message again would ask the suggestion twice.`
3134
3436
  );
3135
3437
  }
3438
+ function unansweredTurn(suggestionId, why) {
3439
+ throw managementError(
3440
+ "transport_failure",
3441
+ `${why} The turn may still complete and may queue a revision. Read the transcript with saturndocs suggestions conversation ${suggestionId} before sending anything again; sending this message again would ask the suggestion twice.`,
3442
+ { mutation: "unknown", retryable: false }
3443
+ );
3444
+ }
3136
3445
  async function readConversation(client, input) {
3137
3446
  const suggestionId = requireSuggestionId3(input.suggestionId, "saturndocs suggestions conversation <suggestion-id>");
3138
3447
  const response = await client.get(resourcePath(input.site, ["suggestions", suggestionId, "session"]), {
@@ -3151,20 +3460,79 @@ async function readConversation(client, input) {
3151
3460
  async function sendSessionMessage(client, input) {
3152
3461
  const suggestionId = requireSuggestionId3(input.suggestionId, "saturndocs suggestions message <suggestion-id>");
3153
3462
  const questionId = input.questionId === void 0 || input.questionId === null || input.questionId === "" ? void 0 : input.questionId;
3154
- const body = SessionMessageBody.safeParse({ message: input.message, ...questionId === void 0 ? {} : { question_id: questionId } });
3463
+ const body = SessionMessageBody.safeParse({
3464
+ message: input.message,
3465
+ turn_id: input.turnId ?? crypto.randomUUID(),
3466
+ ...questionId === void 0 ? {} : { question_id: questionId }
3467
+ });
3155
3468
  if (!body.success) {
3156
- const onQuestion = body.error.issues.some((issue) => issue.path[0] === "question_id");
3469
+ const fields = new Set(body.error.issues.map((issue) => issue.path[0]));
3157
3470
  throw invalidInput(
3158
- onQuestion ? `--question-id takes a question id this suggestion carries, and this one is not a length the server mints. Read the suggestion's questions first; a request thread id is not a suggestion question.` : `saturndocs suggestions message accepts at most ${SESSION_MESSAGE_LIMIT2} characters and no empty message. Nothing was sent.`
3471
+ fields.has("message") ? `saturndocs suggestions message accepts at most ${SESSION_MESSAGE_LIMIT2} characters and no empty message. Nothing was sent.` : fields.has("question_id") ? `--question-id takes a question id this suggestion carries, and this one is not a length the server mints. Read the suggestion's questions first; a request thread id is not a suggestion question.` : "A turn id is a UUID, so a replay can be matched to the turn it repeats. Nothing was sent."
3159
3472
  );
3160
3473
  }
3161
- const response = await client.request({
3162
- method: "POST",
3163
- path: resourcePath(input.site, ["suggestions", suggestionId, "session"]),
3164
- body: body.data,
3165
- signal: input.signal,
3166
- deadlineMs: input.deadlineMs
3167
- });
3474
+ const deadlineMs = input.deadlineMs ?? SESSION_MESSAGE_DEADLINE_MS;
3475
+ const attemptMs = input.attemptMs ?? SESSION_ATTEMPT_MS;
3476
+ if (!Number.isFinite(deadlineMs) || deadlineMs <= 0 || !Number.isFinite(attemptMs) || attemptMs <= 0) {
3477
+ throw invalidInput("The timeout must be a positive number of seconds. Nothing was sent.");
3478
+ }
3479
+ const sleep = input.sleep ?? defaultSleep2;
3480
+ const cancelled = () => input.signal?.aborted === true;
3481
+ const startedAt = Date.now();
3482
+ const remaining = () => deadlineMs - (Date.now() - startedAt);
3483
+ const seconds = Math.round(deadlineMs / 1e3);
3484
+ let sends = 0;
3485
+ let unreachable = 0;
3486
+ let running = 0;
3487
+ let response;
3488
+ for (; ; ) {
3489
+ if (cancelled()) throw interrupted(sends === 0 ? "not_submitted" : "unknown");
3490
+ const left = remaining();
3491
+ if (left <= 0) {
3492
+ unansweredTurn(
3493
+ suggestionId,
3494
+ running > 0 ? `The suggestion did not answer within ${seconds}s, and the server last reported the turn as still running.` : `The suggestion did not answer within ${seconds}s.`
3495
+ );
3496
+ }
3497
+ const attempt = AbortSignal.timeout(Math.min(attemptMs, left));
3498
+ sends += 1;
3499
+ let backoff = 0;
3500
+ try {
3501
+ const answered = await client.request({
3502
+ method: "POST",
3503
+ path: resourcePath(input.site, ["suggestions", suggestionId, "session"]),
3504
+ body: body.data,
3505
+ signal: input.signal === void 0 ? attempt : AbortSignal.any([attempt, input.signal]),
3506
+ deadlineMs: left
3507
+ });
3508
+ unreachable = 0;
3509
+ if (answered.status !== 202) {
3510
+ response = answered;
3511
+ break;
3512
+ }
3513
+ running += 1;
3514
+ backoff = Math.min(MAX_REPLAY_BACKOFF_MS, RUNNING_BACKOFF_MS * 2 ** (running - 1));
3515
+ } catch (cause) {
3516
+ if (cancelled() || !isManagementError(cause)) throw cause;
3517
+ if (cause.detail.code !== "transport_failure" && !(attempt.aborted && cause.detail.code === "interrupted")) throw cause;
3518
+ if (!attempt.aborted && remaining() > 0) {
3519
+ unreachable += 1;
3520
+ if (unreachable >= MAX_UNREACHABLE_SENDS) {
3521
+ unansweredTurn(suggestionId, `The session route could not be reached after ${unreachable} tries in a row: ${cause.detail.message}`);
3522
+ }
3523
+ backoff = UNREACHABLE_BACKOFF_MS * 2 ** (unreachable - 1);
3524
+ }
3525
+ }
3526
+ const wait = Math.min(backoff, remaining());
3527
+ if (wait > 0) {
3528
+ try {
3529
+ await sleep(wait, input.signal ?? new AbortController().signal);
3530
+ } catch (cause) {
3531
+ if (cancelled()) throw interrupted("unknown");
3532
+ throw cause;
3533
+ }
3534
+ }
3535
+ }
3168
3536
  const parsed = SessionResponse2.safeParse(response.data);
3169
3537
  if (!parsed.success) unreadableTurn(suggestionId);
3170
3538
  const outcome = parsed.data;
@@ -3423,8 +3791,10 @@ export {
3423
3791
  CLIENT_SCHEMA_VERSION,
3424
3792
  GLOBAL_FLAGS,
3425
3793
  REQUEST_TEXT_LIMIT,
3794
+ invalidInput,
3426
3795
  isManagementError,
3427
3796
  requireCommitSha,
3797
+ parseOrigin,
3428
3798
  createClient,
3429
3799
  resolveTarget,
3430
3800
  COMMAND_SCHEMA_VERSION,
@@ -3463,6 +3833,7 @@ export {
3463
3833
  waitForSuggestion,
3464
3834
  listRequestThreads,
3465
3835
  readRequestThread,
3836
+ rollbackRelease,
3466
3837
  checkedSubmissionId,
3467
3838
  checkedRequestText,
3468
3839
  createRequest,
@@ -3489,10 +3860,11 @@ export {
3489
3860
  applyGlobalFlagsDeep,
3490
3861
  resolveGlobalOptions,
3491
3862
  CliError,
3492
- invalidInput2 as invalidInput,
3863
+ invalidInput2,
3493
3864
  interrupted2 as interrupted,
3494
3865
  clientError2 as clientError,
3495
3866
  successResult,
3867
+ messageOf,
3496
3868
  failureResult,
3497
3869
  createResultWriter,
3498
3870
  wantsJson