@skrr-ai/cli 0.1.164 → 0.1.165

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 (88) hide show
  1. package/README.md +13 -0
  2. package/dist/base-command.d.ts +14 -1
  3. package/dist/base-command.js +166 -46
  4. package/dist/commands/agent/message/send.d.ts +1 -0
  5. package/dist/commands/agent/message/send.js +3 -0
  6. package/dist/commands/agents/mini-computer/app/set.js +1 -1
  7. package/dist/commands/agents/mini-computer/tasks-view.js +1 -1
  8. package/dist/commands/apps/check.js +3 -8
  9. package/dist/commands/apps/data/batch.d.ts +1 -0
  10. package/dist/commands/apps/data/batch.js +19 -2
  11. package/dist/commands/apps/data/delete.d.ts +1 -0
  12. package/dist/commands/apps/data/delete.js +14 -2
  13. package/dist/commands/apps/data/patch.d.ts +1 -0
  14. package/dist/commands/apps/data/patch.js +11 -2
  15. package/dist/commands/apps/data/put.d.ts +1 -0
  16. package/dist/commands/apps/data/put.js +17 -3
  17. package/dist/commands/apps/install.js +7 -2
  18. package/dist/commands/apps/installations/compatibility.d.ts +13 -0
  19. package/dist/commands/apps/installations/compatibility.js +60 -0
  20. package/dist/commands/apps/installations/show.js +9 -3
  21. package/dist/commands/apps/installations/snapshot.js +5 -2
  22. package/dist/commands/apps/operations/check.d.ts +16 -0
  23. package/dist/commands/apps/operations/check.js +127 -0
  24. package/dist/commands/apps/publish/propose.js +33 -4
  25. package/dist/commands/apps/reconsent.js +7 -1
  26. package/dist/commands/apps/reference.d.ts +4 -2
  27. package/dist/commands/apps/reference.js +7 -4
  28. package/dist/commands/apps/rollback.d.ts +9 -0
  29. package/dist/commands/apps/rollback.js +81 -2
  30. package/dist/commands/apps/upgrade.d.ts +8 -0
  31. package/dist/commands/apps/upgrade.js +67 -2
  32. package/dist/commands/apps/version/cat.d.ts +22 -0
  33. package/dist/commands/apps/version/cat.js +220 -0
  34. package/dist/commands/apps/version/show.js +3 -1
  35. package/dist/commands/commerce/incidents/release.d.ts +24 -0
  36. package/dist/commands/commerce/incidents/release.js +46 -0
  37. package/dist/commands/duties/cases.js +12 -1
  38. package/dist/commands/duties/hypotheses.js +10 -3
  39. package/dist/commands/duties/observations.d.ts +4 -0
  40. package/dist/commands/duties/observations.js +14 -3
  41. package/dist/commands/outbox/list.d.ts +11 -4
  42. package/dist/commands/outbox/list.js +56 -9
  43. package/dist/commands/outbox/retry.d.ts +8 -2
  44. package/dist/commands/outbox/retry.js +76 -16
  45. package/dist/commands/outbox/show.d.ts +20 -0
  46. package/dist/commands/outbox/show.js +83 -0
  47. package/dist/commands/proposals/list.js +13 -9
  48. package/dist/commands/requests/show.d.ts +12 -0
  49. package/dist/commands/requests/show.js +42 -23
  50. package/dist/commands/spaces/deletion/cancel.d.ts +21 -0
  51. package/dist/commands/spaces/deletion/cancel.js +70 -0
  52. package/dist/commands/spaces/workflows/run.js +12 -0
  53. package/dist/commands/widgets/check.d.ts +9 -0
  54. package/dist/commands/widgets/check.js +16 -3
  55. package/dist/generated/agent-guides.json +17 -17
  56. package/dist/lib/api-fetch.d.ts +5 -0
  57. package/dist/lib/api-fetch.js +53 -21
  58. package/dist/lib/appCompatibility.d.ts +31 -0
  59. package/dist/lib/appCompatibility.js +66 -0
  60. package/dist/lib/appData.d.ts +46 -4
  61. package/dist/lib/appData.js +156 -31
  62. package/dist/lib/appInstallations.d.ts +32 -5
  63. package/dist/lib/appInstallations.js +197 -34
  64. package/dist/lib/appVersionFile.d.ts +82 -0
  65. package/dist/lib/appVersionFile.js +195 -0
  66. package/dist/lib/apps-command.d.ts +14 -3
  67. package/dist/lib/apps-command.js +68 -60
  68. package/dist/lib/appsCheck.js +16 -2
  69. package/dist/lib/commerce.d.ts +6 -0
  70. package/dist/lib/commerce.js +9 -0
  71. package/dist/lib/duties.d.ts +15 -1
  72. package/dist/lib/duties.js +21 -3
  73. package/dist/lib/json-output.d.ts +2 -0
  74. package/dist/lib/json-output.js +8 -4
  75. package/dist/lib/node-adapter.d.ts +2 -0
  76. package/dist/lib/node-adapter.js +35 -8
  77. package/dist/lib/outbox.d.ts +110 -1
  78. package/dist/lib/outbox.js +261 -35
  79. package/dist/lib/space-deletion-cancel.d.ts +47 -0
  80. package/dist/lib/space-deletion-cancel.js +141 -0
  81. package/dist/lib/widgetCheck.js +1 -1
  82. package/dist/lib/widgetStaticScan.d.ts +11 -5
  83. package/dist/lib/widgetStaticScan.js +73 -165
  84. package/dist/lib/write-outcome.d.ts +74 -0
  85. package/dist/lib/write-outcome.js +176 -0
  86. package/dist/node_modules/@skrr-ai/data-provider/index.js +11839 -11318
  87. package/oclif.manifest.json +1940 -16
  88. package/package.json +9 -3
package/README.md CHANGED
@@ -900,6 +900,19 @@ When stdin is not a TTY (piped input, CI), the command refuses to prompt and
900
900
  exits with code 7 unless `--yes` is passed. This prevents hangs in
901
901
  non-interactive environments.
902
902
 
903
+ ### `sky spaces deletion cancel <id>`
904
+
905
+ Cancel a Space deletion that is waiting to finish, so the Space is kept. Needs
906
+ delete access, does not prompt (it is the direction that preserves data), and
907
+ exits 0 with "No deletion is pending" when there is nothing to cancel. Only a
908
+ signed-in person can run it: an access token (`SKRR_TOKEN`) is refused with
909
+ `PAT_ROUTE_NOT_ALLOWED`, so automation cannot undo a deletion a person ordered.
910
+
911
+ ```bash
912
+ sky spaces deletion cancel <space-id>
913
+ sky spaces deletion cancel <space-id> --json
914
+ ```
915
+
903
916
  ### `sky spaces archive <id>` / `sky spaces unarchive <id>`
904
917
 
905
918
  Reversible alternative to `spaces delete`. Archives the space (setting
@@ -9,6 +9,7 @@ import { type CliConfig } from './lib/config';
9
9
  import { type AuthResolutionDiagnostic } from './lib/auth-diagnostics';
10
10
  import { type CompletionCacheScope } from './lib/completion-index';
11
11
  import { type OutboxMethod } from './lib/outbox';
12
+ import { type FailedRequest } from './lib/write-outcome';
12
13
  import { type CredentialProvenance, type ResolvedCredential } from './lib/credential-resolver';
13
14
  import { type BrokerRefusalDescription } from './lib/daemonBrokerRefusal';
14
15
  import { type TaskResourceReferenceCache } from './lib/task-resource-references';
@@ -35,7 +36,19 @@ export declare abstract class BaseCommand extends Command {
35
36
  * acquiring unrelated account authority. Human invocations are unaffected.
36
37
  */
37
38
  static autonomousCredentialPolicy: 'delegated' | 'bound-session';
39
+ /**
40
+ * What a managed command may do when the daemon cannot mint the delegated credential it asked for.
41
+ * `none` fails, as always. `bound-session-when-daemon-brokered` keeps the bound session credential
42
+ * only when the daemon has flagged this session for its own message broker
43
+ * (OVERSKY_OFFLINE_MESSAGE_SUBMIT_VIA_DAEMON=1): that route is WAL-first and needs no cloud
44
+ * credential, so a machine that is cut off from the server can still hand the message to the daemon
45
+ * (OSK-23049). It never widens authority: the session credential is what the command was given.
46
+ */
47
+ static autonomousCredentialFallback: 'none' | 'bound-session-when-daemon-brokered';
38
48
  static sessionReadPolicy?: 'memory-history-v1';
49
+ /** Report a refused delegated credential and exit; `failWithCliError` throws. */
50
+ private failDelegatedCredentialUnavailable;
51
+ private mayKeepBoundSessionCredential;
39
52
  /** Add the owning agent's web detail link without overwriting resource URLs. */
40
53
  protected withAgentContext<T>(agentId: string, value: T): T & {
41
54
  agentUrl: string | null;
@@ -668,7 +681,7 @@ export declare function isTypedServerRefusal(body: Record<string, unknown> | nul
668
681
  * stays in the outage branch: it says nothing a reader could act on.
669
682
  */
670
683
  export declare function isApplicationCodedUnavailable(status: number | undefined, body: Record<string, unknown> | null): boolean;
671
- export declare function isRetryableFailure(status: number | undefined, body: Record<string, unknown> | null): boolean;
684
+ export declare function isRetryableFailure(status: number | undefined, body: Record<string, unknown> | null, request?: FailedRequest): boolean;
672
685
  /**
673
686
  * The human text of an API error body (OSK-16986). The server's error envelope guarantees
674
687
  * `message`; the legacy `error` string and the nested `{ error: { message } }` (`/v1`) are read
@@ -62,6 +62,7 @@ const workspace_header_1 = require("./lib/workspace-header");
62
62
  const cli_id_1 = require("./lib/cli-id");
63
63
  const keychain_2 = require("./lib/keychain");
64
64
  const outbox_1 = require("./lib/outbox");
65
+ const write_outcome_1 = require("./lib/write-outcome");
65
66
  const node_adapter_1 = require("./lib/node-adapter");
66
67
  const memory_history_session_1 = require("./lib/memory-history-session");
67
68
  const migrate_1 = require("./lib/migrate");
@@ -156,7 +157,56 @@ class BaseCommand extends core_1.Command {
156
157
  * acquiring unrelated account authority. Human invocations are unaffected.
157
158
  */
158
159
  static autonomousCredentialPolicy = 'delegated';
160
+ /**
161
+ * What a managed command may do when the daemon cannot mint the delegated credential it asked for.
162
+ * `none` fails, as always. `bound-session-when-daemon-brokered` keeps the bound session credential
163
+ * only when the daemon has flagged this session for its own message broker
164
+ * (OVERSKY_OFFLINE_MESSAGE_SUBMIT_VIA_DAEMON=1): that route is WAL-first and needs no cloud
165
+ * credential, so a machine that is cut off from the server can still hand the message to the daemon
166
+ * (OSK-23049). It never widens authority: the session credential is what the command was given.
167
+ */
168
+ static autonomousCredentialFallback = 'none';
159
169
  static sessionReadPolicy;
170
+ /** Report a refused delegated credential and exit; `failWithCliError` throws. */
171
+ failDelegatedCredentialUnavailable(err) {
172
+ // OSK-15990 — a refusal only a new daemon sign-in repairs (e.g.
173
+ // DEVICE_PROOF_PIN_MISMATCH) is NOT retryable: exit 75 told every
174
+ // caller to loop on it. Say so, and say what to run.
175
+ // Matched by name, not instanceof: specs mock `./lib/delegated-cli`
176
+ // down to one or two functions, and a missing class would throw here.
177
+ if (err?.name === 'DelegatedCliUnavailableError') {
178
+ const e = err;
179
+ const remedy = e.remedy && !e.message.includes(e.remedy) ? ` Fix: ${e.remedy}` : '';
180
+ this.failWithCliError({
181
+ message: `Daemon delegated skrr credential is unavailable: ${e.message}${remedy}`,
182
+ code: 'DELEGATED_CLI_CREDENTIAL_UNAVAILABLE',
183
+ // 75 (EX_TEMPFAIL) only when waiting can help; 77 (EX_NOPERM) when
184
+ // the daemon must be signed in again first.
185
+ exit: e.retryable ? 75 : 77,
186
+ retryable: e.retryable,
187
+ details: {
188
+ ...(e.upstreamStatus !== undefined ? { upstreamStatus: e.upstreamStatus } : {}),
189
+ ...(e.upstreamCode ? { upstreamCode: e.upstreamCode } : {}),
190
+ ...(e.upstreamReason ? { upstreamReason: e.upstreamReason } : {}),
191
+ ...(e.retryAt ? { retryAt: e.retryAt } : {}),
192
+ ...(e.remedy ? { remedy: e.remedy } : {}),
193
+ },
194
+ });
195
+ }
196
+ this.failWithCliError({
197
+ message: `Daemon delegated skrr credential is unavailable: ${err.message}`,
198
+ code: 'DELEGATED_CLI_CREDENTIAL_UNAVAILABLE',
199
+ exit: 75,
200
+ retryable: true,
201
+ });
202
+ }
203
+ mayKeepBoundSessionCredential(err, haveBoundSessionCredential) {
204
+ return (haveBoundSessionCredential &&
205
+ this.constructor.autonomousCredentialFallback ===
206
+ 'bound-session-when-daemon-brokered' &&
207
+ process.env.OVERSKY_OFFLINE_MESSAGE_SUBMIT_VIA_DAEMON === '1' &&
208
+ err?.name === 'DelegatedCliUnavailableError');
209
+ }
160
210
  /** Add the owning agent's web detail link without overwriting resource URLs. */
161
211
  withAgentContext(agentId, value) {
162
212
  const agentUrl = (0, web_url_1.agentUrlFrom)(this.cliConfig.baseURL, { id: agentId });
@@ -396,51 +446,35 @@ class BaseCommand extends core_1.Command {
396
446
  // time with the exit signal as its cause: two JSON documents on stdout and a message ending
397
447
  // in `EEXIT: 75` (OSK-23475).
398
448
  let delegatedCredential;
449
+ let keepBoundSession = false;
399
450
  try {
400
451
  delegatedCredential = await (0, delegated_cli_1.fetchDelegatedCliCredential)();
401
452
  }
402
453
  catch (err) {
403
- // OSK-15990 — a refusal only a new daemon sign-in repairs (e.g.
404
- // DEVICE_PROOF_PIN_MISMATCH) is NOT retryable: exit 75 told every
405
- // caller to loop on it. Say so, and say what to run.
406
- // Matched by name, not instanceof: specs mock `./lib/delegated-cli`
407
- // down to one or two functions, and a missing class would throw here.
408
- if (err?.name === 'DelegatedCliUnavailableError') {
409
- const e = err;
410
- const remedy = e.remedy && !e.message.includes(e.remedy) ? ` Fix: ${e.remedy}` : '';
454
+ // OSK-23049 — a session the daemon flagged for its own message broker does not need the cloud
455
+ // credential to hand a message over, so a refused mint keeps the bound session credential for a
456
+ // command that declared it. Everything else reports the refusal exactly as before.
457
+ // `resolveTrustedAutonomousCredential` answers an object with `token: null` when the session token is
458
+ // missing (so the command fails closed), which is truthy: ask for the token itself.
459
+ if (this.mayKeepBoundSessionCredential(err, Boolean(autonomousCredential?.token))) {
460
+ keepBoundSession = true;
461
+ }
462
+ else {
463
+ this.failDelegatedCredentialUnavailable(err);
464
+ }
465
+ }
466
+ if (!keepBoundSession) {
467
+ if (!delegatedCredential) {
411
468
  this.failWithCliError({
412
- message: `Daemon delegated skrr credential is unavailable: ${e.message}${remedy}`,
469
+ message: 'Daemon delegated skrr credential is unavailable.',
413
470
  code: 'DELEGATED_CLI_CREDENTIAL_UNAVAILABLE',
414
- // 75 (EX_TEMPFAIL) only when waiting can help; 77 (EX_NOPERM) when
415
- // the daemon must be signed in again first.
416
- exit: e.retryable ? 75 : 77,
417
- retryable: e.retryable,
418
- details: {
419
- ...(e.upstreamStatus !== undefined ? { upstreamStatus: e.upstreamStatus } : {}),
420
- ...(e.upstreamCode ? { upstreamCode: e.upstreamCode } : {}),
421
- ...(e.upstreamReason ? { upstreamReason: e.upstreamReason } : {}),
422
- ...(e.retryAt ? { retryAt: e.retryAt } : {}),
423
- ...(e.remedy ? { remedy: e.remedy } : {}),
424
- },
471
+ exit: 75,
472
+ retryable: true,
425
473
  });
426
474
  }
427
- this.failWithCliError({
428
- message: `Daemon delegated skrr credential is unavailable: ${err.message}`,
429
- code: 'DELEGATED_CLI_CREDENTIAL_UNAVAILABLE',
430
- exit: 75,
431
- retryable: true,
432
- });
475
+ autonomousCredential = delegatedCredential;
476
+ this.credentialProvenance = { kind: 'daemon-delegated' };
433
477
  }
434
- if (!delegatedCredential) {
435
- this.failWithCliError({
436
- message: 'Daemon delegated skrr credential is unavailable.',
437
- code: 'DELEGATED_CLI_CREDENTIAL_UNAVAILABLE',
438
- exit: 75,
439
- retryable: true,
440
- });
441
- }
442
- autonomousCredential = delegatedCredential;
443
- this.credentialProvenance = { kind: 'daemon-delegated' };
444
478
  }
445
479
  if (autonomousCredential) {
446
480
  // Parse for normal oclif flag validation, but intentionally ignore both
@@ -1565,6 +1599,13 @@ class BaseCommand extends core_1.Command {
1565
1599
  this.lastRetryAfterMs = e.retryAfterMs;
1566
1600
  const body = parseErrorBody(e.body);
1567
1601
  const bodyCode = refusalCodeOf(body);
1602
+ // A write the server may have applied and no route receipt will recognise a repeat of (OSK-24076). Not for a server
1603
+ // that states its own verdict (`retryable`), a typed 5xx refusal, or a 502/503/504 it wrote with a code: those answer.
1604
+ const unknownWrite = typeof body?.retryable !== 'boolean' &&
1605
+ !isTypedServerRefusal(body) &&
1606
+ !isApplicationCodedUnavailable(e.status, body)
1607
+ ? (0, write_outcome_1.unknownWriteOf)(e, body)
1608
+ : null;
1568
1609
  // A body path the person never typed is read back as the flag that wrote it (OSK-15313).
1569
1610
  // The server answers every error with `message` (OSK-16986); `errorBodyMessage` keeps the
1570
1611
  // older `error` string and the nested `/v1` shape as fallbacks for a server without it.
@@ -1644,6 +1685,16 @@ class BaseCommand extends core_1.Command {
1644
1685
  details: envelopeDetails(body),
1645
1686
  });
1646
1687
  }
1688
+ else if (bodyCode === 'DUTY_REFLECTION_APPROVAL_UNVERIFIED') {
1689
+ this.failWithCliError({
1690
+ message: say('Approving a Reflection recommendation is unavailable because its Duty source cannot be verified. You can still reject it.'),
1691
+ code: bodyCode,
1692
+ status: e.status,
1693
+ exit: 1,
1694
+ retryable: false,
1695
+ details: envelopeDetails(body),
1696
+ });
1697
+ }
1647
1698
  else if (bodyCode === 'DUTY_REFLECTION_SOURCE_UNVERIFIED') {
1648
1699
  this.failWithCliError({
1649
1700
  message: say('Reflection history and decisions are unavailable because the original Duty source cannot be verified.'),
@@ -1785,6 +1836,44 @@ class BaseCommand extends core_1.Command {
1785
1836
  details: envelopeDetails(body),
1786
1837
  });
1787
1838
  }
1839
+ else if (unknownWrite) {
1840
+ // The branch the write contract adds (OSK-24076): 408, 425, a 5xx, no answer, or a failure tagged `after_write`, for
1841
+ // a write on a route that keeps no receipt. It is neither "failed" nor "retry". A route that DOES keep a receipt,
1842
+ // and a request that never left, keep the branches below.
1843
+ // A gateway status may also mean the platform is down. That note is about the platform, not about this write, and
1844
+ // it was recorded for these statuses before; a dropped connection never was, since it can be this machine's own.
1845
+ // An edge 504 page is not proof of an outage either (OSK-8700), as before.
1846
+ const edgeTimeoutPage = e.status === 504 &&
1847
+ !body &&
1848
+ (0, edge_error_page_1.describeEdgeErrorPage)({ status: e.status, body: e.body, method: e.method }) !== null;
1849
+ if (typeof e.status === 'number' && (0, outbox_1.isOutageFailure)(e) && !edgeTimeoutPage) {
1850
+ this.noteControlPlaneOutage(e.status);
1851
+ }
1852
+ const requestId = stringProp(body, 'requestId') || e.requestId;
1853
+ const originalCode = bodyCode && /^[A-Za-z0-9._:-]{1,128}$/.test(bodyCode) ? bodyCode : undefined;
1854
+ this.failWithCliError({
1855
+ message: say((0, write_outcome_1.describeUnknownWrite)({
1856
+ baseURL: this.cliConfig.baseURL,
1857
+ unknown: unknownWrite,
1858
+ ...(e.status ? { status: e.status } : {}),
1859
+ ...(bodyMessage && !isRedactedServerMessage(bodyMessage)
1860
+ ? { serverMessage: bodyMessage }
1861
+ : {}),
1862
+ ...(requestId ? { requestId } : {}),
1863
+ })),
1864
+ code: write_outcome_1.WRITE_OUTCOME_UNKNOWN_CODE,
1865
+ ...(e.status ? { status: e.status } : {}),
1866
+ exit: 5,
1867
+ retryable: false,
1868
+ details: {
1869
+ outcome: 'unknown',
1870
+ reason: unknownWrite.outcome.reason,
1871
+ method: (unknownWrite.request.method ?? '').toUpperCase(),
1872
+ ...(originalCode ? { originalCode } : {}),
1873
+ },
1874
+ ...(requestId ? { requestId } : {}),
1875
+ });
1876
+ }
1788
1877
  else if (e.status === 401) {
1789
1878
  // ADD-CLI6 — bare mode follows the `EX_TEMPFAIL` (75) convention
1790
1879
  // for needs-reauth, matching the daemon's `bare-mode.ts:117`.
@@ -1972,7 +2061,7 @@ class BaseCommand extends core_1.Command {
1972
2061
  code: bodyCode || `HTTP_${e.status}`,
1973
2062
  status: e.status,
1974
2063
  exit: 1,
1975
- retryable: isRetryableFailure(e.status, body),
2064
+ retryable: isRetryableFailure(e.status, body, (0, write_outcome_1.requestOfError)(e)),
1976
2065
  details: envelopeDetails(body),
1977
2066
  requestId: stringProp(body, 'requestId') || e.requestId,
1978
2067
  });
@@ -1994,17 +2083,24 @@ class BaseCommand extends core_1.Command {
1994
2083
  // No incident is recorded: one route refusing in its own words is not
1995
2084
  // evidence the control plane is failing. `isOutageFailure` is left
1996
2085
  // alone because it also decides whether the outbox queues a write.
1997
- const retryable = isRetryableFailure(e.status, body);
2086
+ const retryable = isRetryableFailure(e.status, body, (0, write_outcome_1.requestOfError)(e));
1998
2087
  const authored = bodyMessage && !isRedactedServerMessage(bodyMessage) ? bodyMessage : '';
1999
2088
  const requestId = stringProp(body, 'requestId') || e.requestId;
2089
+ let retryAdvice = 'Retrying the same request will not help until that condition changes.';
2090
+ if (retryable) {
2091
+ retryAdvice = 'Retrying may succeed once that condition clears.';
2092
+ }
2093
+ else if (writeWithoutReceipt(e, body)) {
2094
+ // `retryable` is false because a repeat could apply the write twice, not because it cannot succeed (OSK-24076).
2095
+ retryAdvice =
2096
+ 'The response does not say whether the change was made: check the current state before trying again.';
2097
+ }
2000
2098
  this.failWithCliError({
2001
2099
  message: say(`${this.cliConfig.baseURL} refused this request (HTTP ${e.status}, ${bodyCode})` +
2002
2100
  `${authored ? `: ${authored}` : '.'} ` +
2003
2101
  'The API answered this itself, so the request did not time out at the gateway. ' +
2004
2102
  (authored ? '' : 'It did not say why in this response. ') +
2005
- (retryable
2006
- ? 'Retrying may succeed once that condition clears.'
2007
- : 'Retrying the same request will not help until that condition changes.') +
2103
+ retryAdvice +
2008
2104
  (requestId && !authored
2009
2105
  ? ` Request id ${requestId} — quote it when reporting this.`
2010
2106
  : '')),
@@ -2077,7 +2173,7 @@ class BaseCommand extends core_1.Command {
2077
2173
  code: bodyCode || `HTTP_${e.status}`,
2078
2174
  status: e.status,
2079
2175
  exit: 1,
2080
- retryable: isRetryableFailure(e.status, body),
2176
+ retryable: isRetryableFailure(e.status, body, (0, write_outcome_1.requestOfError)(e)),
2081
2177
  details: envelopeDetails(body),
2082
2178
  });
2083
2179
  }
@@ -2087,7 +2183,7 @@ class BaseCommand extends core_1.Command {
2087
2183
  code: bodyCode || e.code || (e.status ? `HTTP_${e.status}` : 'CLI_ERROR'),
2088
2184
  status: e.status,
2089
2185
  exit: 1,
2090
- retryable: isRetryableFailure(e.status, body),
2186
+ retryable: isRetryableFailure(e.status, body, (0, write_outcome_1.requestOfError)(e)),
2091
2187
  details: envelopeDetails(body),
2092
2188
  });
2093
2189
  }
@@ -2140,8 +2236,10 @@ class BaseCommand extends core_1.Command {
2140
2236
  // read the WIDE predicate: a 401 here is precisely the case where an
2141
2237
  // authored payload was being dropped, because `outbox` only ever queued on
2142
2238
  // `status >= 500`.
2143
- if (!(0, outbox_1.isRetryableWrite)(err)) {
2144
- this.handleApiError(err);
2239
+ const request = { method: write.method, path: (0, write_outcome_1.requestPathOf)(write.url) };
2240
+ if (!(0, outbox_1.isRetryableWrite)(err, request)) {
2241
+ // The error names the request when the transport threw it. A caller's own error may not: say which write this was.
2242
+ this.handleApiError((0, write_outcome_1.stampRequest)(err, write.method, write.url));
2145
2243
  }
2146
2244
  const e = err;
2147
2245
  // ...but the incident note stays on the NARROW one, so an expired token
@@ -2149,6 +2247,13 @@ class BaseCommand extends core_1.Command {
2149
2247
  if ((0, outbox_1.isOutageFailure)(err))
2150
2248
  this.noteControlPlaneOutage(e.status);
2151
2249
  const workspaceId = process.env.OVERSKY_SESSION_WORKSPACE_ID?.trim() || process.env.OVERSKY_WORKSPACE_ID?.trim();
2250
+ // OSK-23807 — record where and as whom this write was authored (no secret),
2251
+ // so `outbox retry` can refuse to send it anywhere else.
2252
+ const binding = (0, outbox_1.outboxBindingFor)({
2253
+ baseURL: this.cliConfig?.baseURL,
2254
+ token: this.resolvedCredential?.token,
2255
+ profile: (0, keychain_2.getActiveProfile)(),
2256
+ });
2152
2257
  let queuedId;
2153
2258
  try {
2154
2259
  const entry = (0, outbox_1.enqueueWrite)({
@@ -2159,6 +2264,7 @@ class BaseCommand extends core_1.Command {
2159
2264
  url: write.url,
2160
2265
  body: write.body,
2161
2266
  ...(workspaceId ? { workspaceId } : {}),
2267
+ ...(binding ?? {}),
2162
2268
  reason: {
2163
2269
  ...(e.status !== undefined ? { status: e.status } : {}),
2164
2270
  ...(e.code ? { code: e.code } : {}),
@@ -2918,15 +3024,29 @@ const REDACTED_SERVER_MESSAGE = 'An unexpected error occurred.';
2918
3024
  function isRedactedServerMessage(message) {
2919
3025
  return message.trim() === REDACTED_SERVER_MESSAGE;
2920
3026
  }
2921
- function isRetryableFailure(status, body) {
3027
+ function isRetryableFailure(status, body, request) {
2922
3028
  const declared = body?.retryable;
2923
3029
  if (typeof declared === 'boolean')
2924
3030
  return declared;
2925
3031
  const code = refusalCodeOf(body);
2926
3032
  if (code && TERMINAL_ERROR_CODES.has(code))
2927
3033
  return false;
3034
+ // A WRITE that timed out or failed on the server is retried automatically only if the route keeps a receipt for its key
3035
+ // (OSK-24076). Naming the request is what makes it a write; a caller that does not name it is asking about a read, or
3036
+ // about a status alone, and gets the answer the status gives.
3037
+ if ((0, write_outcome_1.isKnownWrite)(request) && (0, write_outcome_1.isAmbiguousStatus)(status)) {
3038
+ return (0, write_outcome_1.classifyRequestOutcome)({ request, status, body }).retryable;
3039
+ }
2928
3040
  return status === 408 || status === 425 || status === 429 || !!(status && status >= 500);
2929
3041
  }
3042
+ /**
3043
+ * A write on a route that keeps no replay receipt, whose failure the server did not give a verdict on. Its `retryable` is
3044
+ * false because a repeat could apply it twice (OSK-24076), not because retrying cannot succeed, and the words say which.
3045
+ */
3046
+ function writeWithoutReceipt(err, body) {
3047
+ const request = (0, write_outcome_1.requestOfError)(err);
3048
+ return (typeof body?.retryable !== 'boolean' && (0, write_outcome_1.isKnownWrite)(request) && !(0, write_outcome_1.requestHasReceipt)(request));
3049
+ }
2930
3050
  /** True when a message already carries this CLI's `→` remedy line. */
2931
3051
  function hasRemedyLine(message) {
2932
3052
  return HAS_REMEDY_LINE_RE.test(message);
@@ -75,6 +75,7 @@ export type CanonicalIntentEnvelope = {
75
75
  * a compromised producer cannot elevate itself into a session principal.
76
76
  */
77
77
  export default class AgentMessageSend extends BaseCommand {
78
+ static autonomousCredentialFallback: "bound-session-when-daemon-brokered";
78
79
  private attemptedMessageKey?;
79
80
  private partialSequence?;
80
81
  protected failWithCliError(input: {
@@ -80,6 +80,9 @@ const PROTOCOL_VERSION = 1;
80
80
  * a compromised producer cannot elevate itself into a session principal.
81
81
  */
82
82
  class AgentMessageSend extends base_command_1.BaseCommand {
83
+ // OSK-23049: inside a daemon-flagged autonomous session the message goes to the daemon's own WAL-first broker,
84
+ // so a machine cut off from the server must not fail before it gets there on a refused credential mint.
85
+ static autonomousCredentialFallback = 'bound-session-when-daemon-brokered';
83
86
  attemptedMessageKey;
84
87
  partialSequence;
85
88
  failWithCliError(input) {
@@ -30,7 +30,7 @@ class AgentsMiniComputerAppSet extends miniComputerCommand_1.MiniComputerCommand
30
30
  exactlyOne: ['config', 'file'],
31
31
  }),
32
32
  'expected-rev': core_1.Flags.integer({
33
- description: 'Only write if the app is at this revision (0: never configured)',
33
+ description: 'Only write if the app is at this revision (0: nothing is stored now, which does not show whether it was configured before an older reset)',
34
34
  min: 0,
35
35
  }),
36
36
  };
@@ -56,7 +56,7 @@ class AgentsMiniComputerTasksView extends miniComputerCommand_1.MiniComputerComm
56
56
  after: core_1.Flags.string({ description: 'Window start, yyyy-mm-dd, inclusive' }),
57
57
  before: core_1.Flags.string({ description: 'Window end, yyyy-mm-dd, inclusive' }),
58
58
  'expected-rev': core_1.Flags.integer({
59
- description: 'Only write or reset if Tasks is at this revision (0: never configured)',
59
+ description: 'Only write or reset if Tasks is at this revision (0: nothing is stored now, which does not show whether it was configured before an older reset)',
60
60
  min: 0,
61
61
  }),
62
62
  };
@@ -4,6 +4,7 @@ exports.APPS_CHECK_EXIT = void 0;
4
4
  const core_1 = require("@oclif/core");
5
5
  const appsCheck_1 = require("../../lib/appsCheck");
6
6
  const appsFs_1 = require("../../lib/appsFs");
7
+ const drain_stdio_1 = require("../../lib/drain-stdio");
7
8
  const json_output_1 = require("../../lib/json-output");
8
9
  /**
9
10
  * `skrr apps check [dir]`: the offline self-check of an app's package, the one a harness runs in Bash
@@ -22,12 +23,6 @@ const json_output_1 = require("../../lib/json-output");
22
23
  * default policy). A security finding is never an ERROR: drafts and private installs are not held back.
23
24
  */
24
25
  exports.APPS_CHECK_EXIT = { ok: 0, notOk: 1, unreadable: 2 };
25
- /** Wait for queued output before oclif's exit handler calls process.exit(). */
26
- async function flushOutput() {
27
- await Promise.all([process.stdout, process.stderr].map((stream) => new Promise((resolve, reject) => {
28
- stream.write('', (error) => error ? reject(error) : resolve());
29
- })));
30
- }
31
26
  class AppsCheck extends core_1.Command {
32
27
  static description = "Check an app's package in a local directory, offline: the manifest, the files it names, sizes, JavaScript syntax, what the frame would refuse, and the capability calls the script makes against the ones app.json declares. Needs no sign-in. A symbolic link in the directory is refused, never followed.";
33
28
  static examples = [
@@ -77,7 +72,7 @@ class AppsCheck extends core_1.Command {
77
72
  else {
78
73
  process.stderr.write(`error: ${message}\n`);
79
74
  }
80
- await flushOutput();
75
+ await (0, drain_stdio_1.drainStdio)();
81
76
  this.exit(exports.APPS_CHECK_EXIT.unreadable);
82
77
  }
83
78
  const report = (0, appsCheck_1.checkLocalFiles)(pkg.files, {
@@ -95,7 +90,7 @@ class AppsCheck extends core_1.Command {
95
90
  const warnings = report.issues.filter((i) => i.severity === 'warn' && i.tier !== 'info').length;
96
91
  const keptOut = flags.store && report.security !== undefined && !report.security.store.admitted;
97
92
  const failed = !report.ok || (flags.strict && warnings > 0) || keptOut;
98
- await flushOutput();
93
+ await (0, drain_stdio_1.drainStdio)();
99
94
  this.exit(failed ? exports.APPS_CHECK_EXIT.notOk : exports.APPS_CHECK_EXIT.ok);
100
95
  }
101
96
  }
@@ -10,6 +10,7 @@ export default class AppsDataBatch extends AppsCommand {
10
10
  writes: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
11
  'from-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
12
  stdin: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ 'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
14
  };
14
15
  run(): Promise<void>;
15
16
  }
@@ -24,6 +24,9 @@ class AppsDataBatch extends apps_command_1.AppsCommand {
24
24
  description: 'Read the writes from this local file (a symbolic link is refused, never followed)',
25
25
  }),
26
26
  stdin: core_1.Flags.boolean({ description: 'Read the writes from stdin', default: false }),
27
+ 'idempotency-key': core_1.Flags.string({
28
+ description: "A key for THIS write (1 to 200 characters: letters, digits and . _ : / -). Default: a fresh one per run, shown if the outcome is unknown. The same key with the same request is answered from the server's operation receipt, when it keeps one, instead of writing again; without a receipt, sending it again writes again",
29
+ }),
27
30
  };
28
31
  async run() {
29
32
  this.requireAuth();
@@ -37,7 +40,12 @@ class AppsDataBatch extends apps_command_1.AppsCommand {
37
40
  let responseConfirmed = false;
38
41
  let batchHasGeneratedIds = false;
39
42
  let batchTargets;
43
+ let idempotencyKey;
40
44
  try {
45
+ idempotencyKey =
46
+ flags['idempotency-key'] === undefined
47
+ ? (0, appData_1.mintDataWriteKey)()
48
+ : (0, appData_1.checkIdempotencyKey)(flags['idempotency-key']);
41
49
  const body = await (0, appData_1.readBatchInput)({
42
50
  writes: flags.writes,
43
51
  fromFile: flags['from-file'],
@@ -46,7 +54,9 @@ class AppsDataBatch extends apps_command_1.AppsCommand {
46
54
  batchHasGeneratedIds = body.writes.some((write) => write.op === 'put' && write.id === undefined);
47
55
  batchTargets = body.writes.map((write) => ({ collection: write.collection, id: write.id }));
48
56
  requestStarted = true;
49
- const result = await data_provider_1.dataService.batchAppInstallationData(args.installation, body);
57
+ const result = await data_provider_1.dataService.batchAppInstallationData(args.installation, body, {
58
+ idempotencyKey,
59
+ });
50
60
  (0, appData_1.assertAppDataWriteResult)(result, { verb: 'batch', writes: body.writes });
51
61
  if (result.written !== true) {
52
62
  return this.failPersonData({ status: 409, body: JSON.stringify({ code: 'conflict', ...result }) }, { ...target, batchTargets });
@@ -59,11 +69,18 @@ class AppsDataBatch extends apps_command_1.AppsCommand {
59
69
  for (const entry of result.results) {
60
70
  this.log(`${entry.op} ${entry.collection}/${entry.id} (rev ${entry.rev})`);
61
71
  }
72
+ this.logOperationReference(result);
62
73
  }
63
74
  catch (error) {
64
75
  if (responseConfirmed)
65
76
  return this.failConfirmedDataOutput();
66
- return this.failPersonData(error, { ...target, requestStarted, batchHasGeneratedIds, batchTargets });
77
+ return this.failPersonData(error, {
78
+ ...target,
79
+ requestStarted,
80
+ batchHasGeneratedIds,
81
+ batchTargets,
82
+ idempotencyKey,
83
+ });
67
84
  }
68
85
  }
69
86
  }
@@ -10,6 +10,7 @@ export default class AppsDataDelete extends AppsCommand {
10
10
  static flags: {
11
11
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
12
  'expected-rev': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
14
  };
14
15
  run(): Promise<void>;
15
16
  }
@@ -29,6 +29,9 @@ class AppsDataDelete extends apps_command_1.AppsCommand {
29
29
  description: 'The revision you last read: the document is deleted only if it is still at it (required for a local coding agent)',
30
30
  min: 1,
31
31
  }),
32
+ 'idempotency-key': core_1.Flags.string({
33
+ description: "A key for THIS write (1 to 200 characters: letters, digits and . _ : / -). Default: a fresh one per run, shown if the outcome is unknown. The same key with the same request is answered from the server's operation receipt, when it keeps one, instead of writing again; without a receipt, sending it again writes again",
34
+ }),
32
35
  };
33
36
  async run() {
34
37
  this.requireAuth();
@@ -41,9 +44,17 @@ class AppsDataDelete extends apps_command_1.AppsCommand {
41
44
  };
42
45
  let requestStarted = false;
43
46
  let responseConfirmed = false;
47
+ let idempotencyKey;
44
48
  try {
49
+ idempotencyKey =
50
+ flags['idempotency-key'] === undefined
51
+ ? (0, appData_1.mintDataWriteKey)()
52
+ : (0, appData_1.checkIdempotencyKey)(flags['idempotency-key']);
45
53
  requestStarted = true;
46
- const result = await data_provider_1.dataService.deleteAppInstallationData(args.installation, args.collection, args.id, flags['expected-rev'] === undefined ? {} : { expectedRev: flags['expected-rev'] });
54
+ const result = await data_provider_1.dataService.deleteAppInstallationData(args.installation, args.collection, args.id, {
55
+ ...(flags['expected-rev'] === undefined ? {} : { expectedRev: flags['expected-rev'] }),
56
+ idempotencyKey,
57
+ });
47
58
  (0, appData_1.assertAppDataWriteResult)(result, { verb: 'delete', id: args.id });
48
59
  if (result.deleted !== true) {
49
60
  return this.failPersonData({ status: 409, body: JSON.stringify({ code: 'conflict', ...result }) }, target);
@@ -54,11 +65,12 @@ class AppsDataDelete extends apps_command_1.AppsCommand {
54
65
  return;
55
66
  }
56
67
  this.log(`deleted ${args.collection}/${result.id} (it was at rev ${result.rev})`);
68
+ this.logOperationReference(result);
57
69
  }
58
70
  catch (error) {
59
71
  if (responseConfirmed)
60
72
  return this.failConfirmedDataOutput();
61
- return this.failPersonData(error, { ...target, requestStarted });
73
+ return this.failPersonData(error, { ...target, requestStarted, idempotencyKey });
62
74
  }
63
75
  }
64
76
  }
@@ -12,6 +12,7 @@ export default class AppsDataPatch extends AppsCommand {
12
12
  set: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
13
  unset: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
14
  'expected-rev': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ 'idempotency-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
16
  };
16
17
  run(): Promise<void>;
17
18
  }
@@ -36,6 +36,9 @@ class AppsDataPatch extends apps_command_1.AppsCommand {
36
36
  description: 'The revision you last read: the patch applies only if the document is still at it',
37
37
  min: 1,
38
38
  }),
39
+ 'idempotency-key': core_1.Flags.string({
40
+ description: "A key for THIS write (1 to 200 characters: letters, digits and . _ : / -). Default: a fresh one per run, shown if the outcome is unknown. The same key with the same request is answered from the server's operation receipt, when it keeps one, instead of writing again; without a receipt, sending it again writes again",
41
+ }),
39
42
  };
40
43
  async run() {
41
44
  this.requireAuth();
@@ -48,14 +51,19 @@ class AppsDataPatch extends apps_command_1.AppsCommand {
48
51
  };
49
52
  let requestStarted = false;
50
53
  let responseConfirmed = false;
54
+ let idempotencyKey;
51
55
  try {
56
+ idempotencyKey =
57
+ flags['idempotency-key'] === undefined
58
+ ? (0, appData_1.mintDataWriteKey)()
59
+ : (0, appData_1.checkIdempotencyKey)(flags['idempotency-key']);
52
60
  const change = (0, appData_1.readPatchInput)({ set: flags.set, unset: flags.unset });
53
61
  requestStarted = true;
54
62
  const result = await data_provider_1.dataService.patchAppInstallationData(args.installation, args.collection, args.id, {
55
63
  ...(change.set === undefined ? {} : { set: change.set }),
56
64
  ...(change.unset === undefined ? {} : { unset: change.unset }),
57
65
  ...(flags['expected-rev'] === undefined ? {} : { expectedRev: flags['expected-rev'] }),
58
- });
66
+ }, { idempotencyKey });
59
67
  (0, appData_1.assertAppDataWriteResult)(result, { verb: 'patch', id: args.id });
60
68
  if (result.written !== true) {
61
69
  return this.failPersonData({ status: 409, body: JSON.stringify({ code: 'conflict', ...result }) }, target);
@@ -66,11 +74,12 @@ class AppsDataPatch extends apps_command_1.AppsCommand {
66
74
  return;
67
75
  }
68
76
  this.log(`patched ${args.collection}/${result.id} (rev ${result.rev})`);
77
+ this.logOperationReference(result);
69
78
  }
70
79
  catch (error) {
71
80
  if (responseConfirmed)
72
81
  return this.failConfirmedDataOutput();
73
- return this.failPersonData(error, { ...target, requestStarted });
82
+ return this.failPersonData(error, { ...target, requestStarted, idempotencyKey });
74
83
  }
75
84
  }
76
85
  }