@skrr-ai/cli 0.1.164 → 0.1.166

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 (111) 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/migrate/abort.d.ts +13 -0
  21. package/dist/commands/apps/installations/migrate/abort.js +45 -0
  22. package/dist/commands/apps/installations/migrate/cutover.d.ts +15 -0
  23. package/dist/commands/apps/installations/migrate/cutover.js +102 -0
  24. package/dist/commands/apps/installations/migrate/plan.d.ts +13 -0
  25. package/dist/commands/apps/installations/migrate/plan.js +51 -0
  26. package/dist/commands/apps/installations/migrate/rollback.d.ts +16 -0
  27. package/dist/commands/apps/installations/migrate/rollback.js +103 -0
  28. package/dist/commands/apps/installations/migrate/stage.d.ts +15 -0
  29. package/dist/commands/apps/installations/migrate/stage.js +96 -0
  30. package/dist/commands/apps/installations/migrate/status.d.ts +12 -0
  31. package/dist/commands/apps/installations/migrate/status.js +52 -0
  32. package/dist/commands/apps/installations/migrate/validate.d.ts +14 -0
  33. package/dist/commands/apps/installations/migrate/validate.js +58 -0
  34. package/dist/commands/apps/installations/show.js +14 -9
  35. package/dist/commands/apps/installations/snapshot.js +5 -2
  36. package/dist/commands/apps/operations/check.d.ts +16 -0
  37. package/dist/commands/apps/operations/check.js +127 -0
  38. package/dist/commands/apps/publish/propose.js +33 -4
  39. package/dist/commands/apps/reconsent.js +7 -1
  40. package/dist/commands/apps/reference.d.ts +4 -2
  41. package/dist/commands/apps/reference.js +7 -4
  42. package/dist/commands/apps/resume.js +1 -1
  43. package/dist/commands/apps/rollback.d.ts +9 -0
  44. package/dist/commands/apps/rollback.js +81 -2
  45. package/dist/commands/apps/settings/set.js +22 -10
  46. package/dist/commands/apps/upgrade.d.ts +8 -0
  47. package/dist/commands/apps/upgrade.js +67 -2
  48. package/dist/commands/apps/version/cat.d.ts +22 -0
  49. package/dist/commands/apps/version/cat.js +220 -0
  50. package/dist/commands/apps/version/show.js +3 -1
  51. package/dist/commands/commerce/incidents/release.d.ts +24 -0
  52. package/dist/commands/commerce/incidents/release.js +46 -0
  53. package/dist/commands/duties/cases.js +12 -1
  54. package/dist/commands/duties/hypotheses.js +10 -3
  55. package/dist/commands/duties/observations.d.ts +4 -0
  56. package/dist/commands/duties/observations.js +14 -3
  57. package/dist/commands/outbox/list.d.ts +11 -4
  58. package/dist/commands/outbox/list.js +56 -9
  59. package/dist/commands/outbox/retry.d.ts +8 -2
  60. package/dist/commands/outbox/retry.js +76 -16
  61. package/dist/commands/outbox/show.d.ts +20 -0
  62. package/dist/commands/outbox/show.js +83 -0
  63. package/dist/commands/proposals/list.js +13 -9
  64. package/dist/commands/requests/show.d.ts +12 -0
  65. package/dist/commands/requests/show.js +42 -23
  66. package/dist/commands/spaces/deletion/cancel.d.ts +21 -0
  67. package/dist/commands/spaces/deletion/cancel.js +70 -0
  68. package/dist/commands/spaces/workflows/run.js +12 -0
  69. package/dist/commands/widgets/check.d.ts +9 -0
  70. package/dist/commands/widgets/check.js +16 -3
  71. package/dist/generated/agent-guides.json +17 -17
  72. package/dist/lib/api-fetch.d.ts +5 -0
  73. package/dist/lib/api-fetch.js +81 -22
  74. package/dist/lib/appCompatibility.d.ts +31 -0
  75. package/dist/lib/appCompatibility.js +66 -0
  76. package/dist/lib/appData.d.ts +46 -4
  77. package/dist/lib/appData.js +161 -32
  78. package/dist/lib/appDataMigration.d.ts +204 -0
  79. package/dist/lib/appDataMigration.js +753 -0
  80. package/dist/lib/appDataMigrationCommand.d.ts +39 -0
  81. package/dist/lib/appDataMigrationCommand.js +90 -0
  82. package/dist/lib/appInstallations.d.ts +40 -5
  83. package/dist/lib/appInstallations.js +251 -35
  84. package/dist/lib/appVersionFile.d.ts +82 -0
  85. package/dist/lib/appVersionFile.js +195 -0
  86. package/dist/lib/apps-command.d.ts +14 -3
  87. package/dist/lib/apps-command.js +80 -65
  88. package/dist/lib/appsCheck.js +16 -2
  89. package/dist/lib/commerce.d.ts +6 -0
  90. package/dist/lib/commerce.js +9 -0
  91. package/dist/lib/duties.d.ts +15 -1
  92. package/dist/lib/duties.js +21 -3
  93. package/dist/lib/json-output.d.ts +2 -0
  94. package/dist/lib/json-output.js +8 -4
  95. package/dist/lib/node-adapter.js +69 -38
  96. package/dist/lib/outbox.d.ts +110 -1
  97. package/dist/lib/outbox.js +261 -35
  98. package/dist/lib/rate-limit-retry.d.ts +4 -5
  99. package/dist/lib/rate-limit-retry.js +6 -10
  100. package/dist/lib/refresh.d.ts +2 -0
  101. package/dist/lib/refresh.js +6 -0
  102. package/dist/lib/space-deletion-cancel.d.ts +47 -0
  103. package/dist/lib/space-deletion-cancel.js +141 -0
  104. package/dist/lib/widgetCheck.js +1 -1
  105. package/dist/lib/widgetStaticScan.d.ts +11 -5
  106. package/dist/lib/widgetStaticScan.js +73 -165
  107. package/dist/lib/write-outcome.d.ts +76 -0
  108. package/dist/lib/write-outcome.js +190 -0
  109. package/dist/node_modules/@skrr-ai/data-provider/index.js +11955 -11231
  110. package/oclif.manifest.json +3019 -499
  111. package/package.json +12 -3
@@ -3,12 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
4
  const data_provider_1 = require("@skrr-ai/data-provider");
5
5
  const apps_command_1 = require("../../lib/apps-command");
6
+ const appCompatibility_1 = require("../../lib/appCompatibility");
6
7
  const appInstallations_1 = require("../../lib/appInstallations");
8
+ const drain_stdio_1 = require("../../lib/drain-stdio");
7
9
  class AppsRollback extends apps_command_1.AppsCommand {
8
- static description = 'Put an installation back on the version it ran before the current one, in one call. It works for you and for your agent, and it never widens what you approved: if the earlier version needs an approval you have since changed, the installation says it needs your approval again. Repeating it goes back one more step.';
10
+ static description = 'Put an installation back on the version it ran before the current one, in one call. It works for you and for your agent, and it never widens what you approved: if the earlier version needs an approval you have since changed, the installation says it needs your approval again. Repeating it goes back one more step. With --check-data it first checks whether the installation’s stored data fits the data schemas of the version it would go back to (`apps installations compatibility`) and prints the result; if the data is incompatible or could not be proven compatible it stops before moving, unless you add --yes. The server never refuses a rollback because of that check; getting back to what ran before is always yours to do.';
9
11
  static examples = [
10
12
  '<%= config.bin %> apps rollback appi_abc',
11
13
  '<%= config.bin %> apps rollback appi_abc --expected-version appv_current',
14
+ '<%= config.bin %> apps rollback appi_abc --expected-version appv_current --expected-target appv_previous',
15
+ '<%= config.bin %> apps rollback appi_abc --check-data',
16
+ '<%= config.bin %> apps rollback appi_abc --check-data --yes',
12
17
  ];
13
18
  static args = {
14
19
  installation: core_1.Args.string({
@@ -19,16 +24,42 @@ class AppsRollback extends apps_command_1.AppsCommand {
19
24
  };
20
25
  static flags = {
21
26
  'expected-version': core_1.Flags.string({
22
- description: 'Proceed only if this version (appv_...) is still installed. This does not pin the rollback target or history.',
27
+ description: 'Proceed only if this version (appv_...) is still installed. On its own this does not pin the version the rollback goes back to: use --expected-target for that.',
28
+ }),
29
+ 'expected-target': core_1.Flags.string({
30
+ description: 'Proceed only if the version this would go back to is this one (appv_...), as `apps installations versions` showed it. The server works the target out from the installation history when the request arrives; if it is a different version, nothing is moved.',
31
+ }),
32
+ 'check-data': core_1.Flags.boolean({
33
+ description: 'First check the installation’s stored data against the schemas of the version this would go back to, and print the result. Compatible: go back. Incompatible or unknown: stop (exit 1 or 5) unless --yes. The version checked is the one moved to (it is sent as --expected-target)',
34
+ default: false,
35
+ }),
36
+ yes: core_1.Flags.boolean({
37
+ description: 'With --check-data: go back even though the check found the data incompatible or could not prove it compatible. It changes no data',
38
+ default: false,
23
39
  }),
24
40
  json: core_1.Flags.boolean({ description: 'Output the installation as JSON' }),
25
41
  };
26
42
  async run() {
27
43
  this.requireAuth();
28
44
  const { args, flags } = await this.parse(AppsRollback);
45
+ if (flags.yes && !flags['check-data']) {
46
+ return this.failWithCliError({
47
+ message: '--yes only answers the question --check-data asks. Use `--check-data --yes`, or leave --yes out. Nothing was changed.',
48
+ code: 'APP_FLAG_INVALID',
49
+ exit: 2,
50
+ retryable: false,
51
+ });
52
+ }
53
+ // the version the check was about is the version the rollback must go to, so the check cannot be about one and the move another
54
+ const checkedTarget = flags['check-data']
55
+ ? await this.checkDataFirst(args.installation, flags['expected-target'], flags.yes, flags.json)
56
+ : undefined;
29
57
  try {
30
58
  const result = await data_provider_1.dataService.rollbackAppInstallation(args.installation, {
31
59
  ...(flags['expected-version'] ? { expectedVersionId: flags['expected-version'] } : {}),
60
+ ...(flags['expected-target'] || checkedTarget
61
+ ? { expectedTargetVersionId: flags['expected-target'] ?? checkedTarget }
62
+ : {}),
32
63
  });
33
64
  if (flags.json) {
34
65
  this.printJsonResult(result);
@@ -43,5 +74,53 @@ class AppsRollback extends apps_command_1.AppsCommand {
43
74
  this.failInstallation(error, { subject: args.installation });
44
75
  }
45
76
  }
77
+ /**
78
+ * `--check-data`: find the version a rollback would go to (the one named, else the server's current rollback target), check the data
79
+ * against it, print the result, and decide whether to go on (see `apps upgrade`). Returns the version checked, or `undefined` when
80
+ * there is nothing to go back to (the rollback then says so itself, as it always did).
81
+ */
82
+ async checkDataFirst(installation, named, yes, json) {
83
+ let target = named;
84
+ let view = null;
85
+ try {
86
+ if (target === undefined) {
87
+ target = (await data_provider_1.dataService.getAppInstallationVersions(installation)).rollback?.versionId;
88
+ }
89
+ if (target === undefined) {
90
+ return undefined;
91
+ }
92
+ view = await (0, appCompatibility_1.fetchCompatibility)(installation, target);
93
+ }
94
+ catch (error) {
95
+ return this.failInstallation(error, { subject: installation });
96
+ }
97
+ if (view === null) {
98
+ return this.failWithCliError({
99
+ message: `${appCompatibility_1.COMPATIBILITY_UNREADABLE_MESSAGE} Nothing was changed.`,
100
+ code: 'APP_COMPATIBILITY_UNREADABLE',
101
+ exit: 5,
102
+ retryable: false,
103
+ });
104
+ }
105
+ for (const line of (0, appCompatibility_1.formatCompatibility)(view)) {
106
+ if (json)
107
+ this.logToStderr(line);
108
+ else
109
+ this.log(line);
110
+ }
111
+ if (view.verdict === 'compatible' || yes) {
112
+ if (view.verdict !== 'compatible') {
113
+ this.logToStderr('Going back anyway, as you asked (--yes). No data is changed by a move.');
114
+ }
115
+ return target;
116
+ }
117
+ // `target` may come from the server: it is put in a command to copy only when it is a plain id
118
+ const pinned = /^appv_[A-Za-z0-9_-]{1,60}(?![\s\S])/.test(target ?? '')
119
+ ? ` --expected-target ${target}`
120
+ : '';
121
+ this.logToStderr(`Not moved. To go back anyway: \`${this.config.bin} apps rollback ${installation}${pinned} --check-data --yes\`. To go back without the check, leave out --check-data.`);
122
+ await (0, drain_stdio_1.drainStdio)();
123
+ return this.exit((0, appCompatibility_1.compatibilityExit)(view));
124
+ }
46
125
  }
47
126
  exports.default = AppsRollback;
@@ -36,14 +36,18 @@ class AppsSettingsSet extends apps_command_1.AppsCommand {
36
36
  ...(0, appSettings_1.formatAppSettings)(current.configuration, settings, current.timezone),
37
37
  ...(0, appSettings_1.formatInstallDefaults)(current.configuration, settings),
38
38
  ...(current.canEdit === false
39
- ? ['At the time of this read, the server says settings are not editable under the current access and approval state. This may change.']
39
+ ? [
40
+ 'At the time of this read, the server says settings are not editable under the current access and approval state. This may change.',
41
+ ]
40
42
  : current.canEdit !== true
41
43
  ? ['The server did not say whether settings are currently editable.']
42
44
  : []),
43
45
  ...(current.canEdit === false && current.canReviewBundleApproval === true
44
- ? [installationForDisplay === '<installation-id>'
46
+ ? [
47
+ installationForDisplay === '<installation-id>'
45
48
  ? 'To review the current version, first find a valid installation ID, then use apps reconsent without --yes.'
46
- : `To review the current version, run \`${this.config.bin} apps reconsent ${installationForDisplay}\` without --yes using the same account, deployment, profile and workspace.`]
49
+ : `To review the current version, run \`${this.config.bin} apps reconsent ${installationForDisplay}\` without --yes using the same account, deployment, profile and workspace.`,
50
+ ]
47
51
  : []),
48
52
  ];
49
53
  if (!flags.yes)
@@ -65,9 +69,11 @@ class AppsSettingsSet extends apps_command_1.AppsCommand {
65
69
  expectedGrantedAt: current.expectedGrantedAt,
66
70
  consent: { versionId: current.expectedVersionId, bundleHash: current.bundleHash, settings },
67
71
  });
68
- if (!result || !data_provider_1.AppSettingsSchema.safeParse(result.settings).success ||
72
+ if (!result ||
73
+ !data_provider_1.AppSettingsSchema.safeParse(result.settings).success ||
69
74
  !(0, data_provider_1.appSettingsEqual)(result.settings, settings) ||
70
- result.expectedVersionId !== current.expectedVersionId || result.bundleHash !== current.bundleHash ||
75
+ result.expectedVersionId !== current.expectedVersionId ||
76
+ result.bundleHash !== current.bundleHash ||
71
77
  typeof result.expectedGrantedAt !== 'string' ||
72
78
  !(Date.parse(result.expectedGrantedAt) > Date.parse(current.expectedGrantedAt)) ||
73
79
  !data_provider_1.AppSettingsManifestSchema.safeParse(result.configuration).success) {
@@ -79,13 +85,17 @@ class AppsSettingsSet extends apps_command_1.AppsCommand {
79
85
  this.log(`Saved settings for ${args.installation}. Schedule reconciliation was requested; use apps installations show to inspect job state.`);
80
86
  }
81
87
  catch (error) {
82
- if (error instanceof Error && ((0, base_command_1.isOclifExitError)(error) ||
83
- typeof error.oclif?.exit === 'number'))
88
+ if (error instanceof Error &&
89
+ ((0, base_command_1.isOclifExitError)(error) ||
90
+ typeof error.oclif?.exit === 'number'))
84
91
  throw error;
85
92
  if (responseValidated)
86
93
  return this.failConfirmedDataOutput();
87
94
  const refusal = (0, apps_1.readAppsRefusal)(error);
88
- if (refusal?.error === 'consent_mismatch' && writeStarted && refusal.status === 409 && refusal.reason === 'installation_reconsent_required') {
95
+ if (refusal?.error === 'consent_mismatch' &&
96
+ writeStarted &&
97
+ refusal.status === 409 &&
98
+ refusal.reason === 'installation_reconsent_required') {
89
99
  return this.failWithCliError({
90
100
  message: `This installation's current version needs approval again. Settings were not changed. Review it with \`${this.config.bin} apps reconsent ${installationForDisplay}\` (without --yes); after approving it, preview the settings again.`,
91
101
  code: 'APP_CONSENT_MISMATCH',
@@ -95,7 +105,9 @@ class AppsSettingsSet extends apps_command_1.AppsCommand {
95
105
  details: {
96
106
  reason: refusal.reason,
97
107
  ...(refusal.docCount === undefined ? {} : { docCount: refusal.docCount }),
98
- ...(refusal.installationId === undefined ? {} : { installationId: refusal.installationId }),
108
+ ...(refusal.installationId === undefined
109
+ ? {}
110
+ : { installationId: refusal.installationId }),
99
111
  ...(refusal.current ? { current: refusal.current } : {}),
100
112
  },
101
113
  });
@@ -124,7 +136,7 @@ class AppsSettingsSet extends apps_command_1.AppsCommand {
124
136
  retryable: false,
125
137
  });
126
138
  }
127
- this.failInstallation(error);
139
+ this.failInstallation(error, { subject: args.installation });
128
140
  }
129
141
  }
130
142
  }
@@ -9,6 +9,14 @@ export default class AppsUpgrade extends AppsCommand {
9
9
  json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
10
  version: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
11
  'expected-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'check-data': import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
14
  };
13
15
  run(): Promise<void>;
16
+ /**
17
+ * `--check-data`: ask, print, and decide whether to go on. Only a `compatible` answer goes on by itself; anything else stops, with the
18
+ * exit the check has (1 incompatible, 5 unknown, which an unreadable answer is), unless the person said --yes. A check that cannot be run
19
+ * (a request that fails) stops too: the person asked for the check and does not have it. Nothing is written by the check.
20
+ */
21
+ private checkDataFirst;
14
22
  }
@@ -3,12 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
4
  const data_provider_1 = require("@skrr-ai/data-provider");
5
5
  const apps_command_1 = require("../../lib/apps-command");
6
+ const appCompatibility_1 = require("../../lib/appCompatibility");
6
7
  const appInstallations_1 = require("../../lib/appInstallations");
8
+ const drain_stdio_1 = require("../../lib/drain-stdio");
7
9
  class AppsUpgrade extends apps_command_1.AppsCommand {
8
- static description = 'Move an installation to another version of its app (a newer one, or an older one to roll back). It never widens what was approved: a version that asks for more lands as needing your approval again, and does not run until you give it (`apps reconsent`).';
10
+ static description = 'Move an installation to another version of its app (a newer one, or an older one to roll back). It never widens what was approved: a version that asks for more lands as needing your approval again, and does not run until you give it (`apps reconsent`). With --check-data it first checks whether the installation’s stored data fits the data schemas that version declares (`apps installations compatibility`) and prints the result; if the data is incompatible or could not be proven compatible it stops before moving, unless you add --yes. The server never refuses a move because of that check; the choice is yours.';
9
11
  static examples = [
10
12
  '<%= config.bin %> apps upgrade appi_abc --version appv_xyz',
11
13
  '<%= config.bin %> apps upgrade appi_abc --version appv_xyz --expected-version appv_old',
14
+ '<%= config.bin %> apps upgrade appi_abc --version appv_xyz --check-data',
15
+ '<%= config.bin %> apps upgrade appi_abc --version appv_xyz --check-data --yes',
12
16
  ];
13
17
  static args = {
14
18
  installation: core_1.Args.string({
@@ -23,10 +27,29 @@ class AppsUpgrade extends apps_command_1.AppsCommand {
23
27
  'expected-version': core_1.Flags.string({
24
28
  description: 'Move only if it still runs this version (appv_...); otherwise nothing changes',
25
29
  }),
30
+ 'check-data': core_1.Flags.boolean({
31
+ description: 'First check the installation’s stored data against that version’s declared schemas and print the result. Compatible: move. Incompatible or unknown: stop (exit 1 or 5) unless --yes',
32
+ default: false,
33
+ }),
34
+ yes: core_1.Flags.boolean({
35
+ description: 'With --check-data: move even though the check found the data incompatible or could not prove it compatible. It changes no data; `apps rollback` goes back',
36
+ default: false,
37
+ }),
26
38
  };
27
39
  async run() {
28
40
  this.requireAuth();
29
41
  const { args, flags } = await this.parse(AppsUpgrade);
42
+ if (flags.yes && !flags['check-data']) {
43
+ return this.failWithCliError({
44
+ message: '--yes only answers the question --check-data asks. Use `--check-data --yes`, or leave --yes out. Nothing was changed.',
45
+ code: 'APP_FLAG_INVALID',
46
+ exit: 2,
47
+ retryable: false,
48
+ });
49
+ }
50
+ if (flags['check-data']) {
51
+ await this.checkDataFirst(args.installation, flags.version, flags.yes, flags.json);
52
+ }
30
53
  try {
31
54
  const result = await data_provider_1.dataService.activateAppInstallationVersion(args.installation, {
32
55
  versionId: flags.version,
@@ -42,8 +65,50 @@ class AppsUpgrade extends apps_command_1.AppsCommand {
42
65
  }
43
66
  }
44
67
  catch (error) {
45
- this.failInstallation(error);
68
+ this.failInstallation(error, {
69
+ action: 'upgrade',
70
+ subject: args.installation,
71
+ versionId: flags.version,
72
+ });
73
+ }
74
+ }
75
+ /**
76
+ * `--check-data`: ask, print, and decide whether to go on. Only a `compatible` answer goes on by itself; anything else stops, with the
77
+ * exit the check has (1 incompatible, 5 unknown, which an unreadable answer is), unless the person said --yes. A check that cannot be run
78
+ * (a request that fails) stops too: the person asked for the check and does not have it. Nothing is written by the check.
79
+ */
80
+ async checkDataFirst(installation, versionId, yes, json) {
81
+ let view;
82
+ try {
83
+ view = await (0, appCompatibility_1.fetchCompatibility)(installation, versionId);
84
+ }
85
+ catch (error) {
86
+ return this.failInstallation(error, { action: 'upgrade', subject: installation, versionId });
87
+ }
88
+ if (view === null) {
89
+ return this.failWithCliError({
90
+ message: `${appCompatibility_1.COMPATIBILITY_UNREADABLE_MESSAGE} Nothing was changed.`,
91
+ code: 'APP_COMPATIBILITY_UNREADABLE',
92
+ exit: 5,
93
+ retryable: false,
94
+ });
95
+ }
96
+ // The check is printed on STDERR with --json, so stdout stays one JSON document (the installation, as it always was).
97
+ for (const line of (0, appCompatibility_1.formatCompatibility)(view)) {
98
+ if (json)
99
+ this.logToStderr(line);
100
+ else
101
+ this.log(line);
102
+ }
103
+ if (view.verdict === 'compatible' || yes) {
104
+ if (view.verdict !== 'compatible') {
105
+ this.logToStderr('Moving anyway, as you asked (--yes). No data is changed by a move.');
106
+ }
107
+ return;
46
108
  }
109
+ this.logToStderr(`Not moved. To move anyway: \`${this.config.bin} apps upgrade ${installation} --version ${versionId} --check-data --yes\`. To move without the check, leave out --check-data.`);
110
+ await (0, drain_stdio_1.drainStdio)();
111
+ return this.exit((0, appCompatibility_1.compatibilityExit)(view));
47
112
  }
48
113
  }
49
114
  exports.default = AppsUpgrade;
@@ -0,0 +1,22 @@
1
+ import { AppsCommand } from '../../../lib/apps-command';
2
+ export default class AppsVersionCat extends AppsCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ version: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
7
+ path: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
8
+ };
9
+ static flags: {
10
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ out: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ raw: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ offset: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ limit: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ };
17
+ run(): Promise<void>;
18
+ /** What was checked, on stderr so stdout stays the file. */
19
+ private note;
20
+ /** Say what went wrong, in this command's terms where it has them. Never returns. */
21
+ private failVersionFile;
22
+ }
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_fs_1 = require("node:fs");
4
+ const node_path_1 = require("node:path");
5
+ const core_1 = require("@oclif/core");
6
+ const data_provider_1 = require("@skrr-ai/data-provider");
7
+ const apps_command_1 = require("../../../lib/apps-command");
8
+ const apps_1 = require("../../../lib/apps");
9
+ const appVersionFile_1 = require("../../../lib/appVersionFile");
10
+ class AppsVersionCat extends apps_command_1.AppsCommand {
11
+ static description = "Print the full text of one file of a FROZEN version, checked against the version's own hashes, so a reviewer reads exactly the bytes the version's bundle hash covers (never the draft, which may have moved). " +
12
+ "The file list is first tied to the bundle hash; each slice (at most 64 KiB) is checked against the version's record; and when the whole file is read, the joined bytes must match its sha-256 and size. Nothing is printed unless every check passed. " +
13
+ 'The text is untrusted: it was written by whoever authored the version. On a terminal, control and direction-changing characters are shown as \\u{...} escapes and a binary file is refused (use --out to save it, --raw for the exact bytes). ' +
14
+ `Exit ${appVersionFile_1.VERSION_FILE_INTEGRITY_EXIT}: the bytes are not the version's.`;
15
+ static examples = [
16
+ '<%= config.bin %> apps version cat appv_... app.js',
17
+ '<%= config.bin %> apps version cat appv_... app.json --json',
18
+ '<%= config.bin %> apps version cat appv_... icon.png --out ./icon.png',
19
+ '<%= config.bin %> apps version cat appv_... app.js --offset 30000 --limit 5000',
20
+ ];
21
+ static args = {
22
+ version: core_1.Args.string({
23
+ description: 'The version id (appv_...)',
24
+ required: true,
25
+ ignoreStdin: true,
26
+ }),
27
+ path: core_1.Args.string({
28
+ description: 'The file, exactly as `apps version show` lists it',
29
+ required: true,
30
+ ignoreStdin: true,
31
+ }),
32
+ };
33
+ static flags = {
34
+ json: core_1.Flags.boolean({
35
+ description: 'Output { versionId, bundleHash, path, offset, length, total, fileSha256, wholeFileVerified, encoding, content } as JSON',
36
+ exclusive: ['raw'],
37
+ }),
38
+ out: core_1.Flags.string({
39
+ description: 'Save the exact bytes to this file instead of printing them (written only after every check passed; an existing file is refused without --force)',
40
+ }),
41
+ force: core_1.Flags.boolean({
42
+ description: 'With --out, replace a file that already exists (never write through a symbolic link)',
43
+ default: false,
44
+ }),
45
+ raw: core_1.Flags.boolean({
46
+ description: 'Write the exact bytes to stdout even on a terminal, escaping nothing and refusing nothing',
47
+ exclusive: ['json', 'out'],
48
+ }),
49
+ offset: core_1.Flags.integer({
50
+ description: 'Start at this byte. A read that does not start at 0 or stops early checks each slice but cannot check the whole file, and says so',
51
+ min: 0,
52
+ }),
53
+ limit: core_1.Flags.integer({
54
+ description: `Read at most this many bytes in all (the server answers in slices of at most ${data_provider_1.APP_VERSION_FILE_LIMITS.chunkBytesMax})`,
55
+ min: 1,
56
+ }),
57
+ };
58
+ async run() {
59
+ this.requireAuth();
60
+ const { args, flags } = await this.parse(AppsVersionCat);
61
+ let read;
62
+ try {
63
+ read = await (0, appVersionFile_1.readVersionFile)({
64
+ getVersion: (versionId) => data_provider_1.dataService.getAppVersion(versionId),
65
+ readChunk: (versionId, params) => data_provider_1.dataService.readAppVersionFile(versionId, params),
66
+ }, {
67
+ versionId: args.version,
68
+ path: args.path,
69
+ ...(flags.offset === undefined ? {} : { offset: flags.offset }),
70
+ ...(flags.limit === undefined ? {} : { limit: flags.limit }),
71
+ });
72
+ }
73
+ catch (error) {
74
+ return this.failVersionFile(error);
75
+ }
76
+ const summary = {
77
+ versionId: read.versionId,
78
+ bundleHash: read.bundleHash,
79
+ path: read.path,
80
+ offset: read.offset,
81
+ length: read.length,
82
+ total: read.total,
83
+ fileSha256: read.fileSha256,
84
+ wholeFileVerified: read.wholeFileVerified,
85
+ };
86
+ if (flags.out !== undefined) {
87
+ try {
88
+ saveVerified(flags.out, read.bytes, flags.force);
89
+ }
90
+ catch (error) {
91
+ return this.failWithCliError({
92
+ message: `Could not write ${flags.out}: ${error.message}`,
93
+ code: 'APP_VERSION_FILE_OUT',
94
+ exit: 1,
95
+ retryable: false,
96
+ });
97
+ }
98
+ if (flags.json) {
99
+ this.printJsonResult({ ...summary, out: flags.out, bytesWritten: read.bytes.length });
100
+ }
101
+ else {
102
+ this.log(`wrote ${read.bytes.length} bytes to ${flags.out}`);
103
+ this.note(read);
104
+ }
105
+ return;
106
+ }
107
+ if (flags.json) {
108
+ const text = (0, appVersionFile_1.isBinary)(read.bytes) ? null : read.bytes.toString('utf8');
109
+ this.printJsonResult({
110
+ ...summary,
111
+ ...(text === null
112
+ ? { encoding: 'base64', content: read.bytes.toString('base64') }
113
+ : { encoding: 'utf8', content: text }),
114
+ });
115
+ return;
116
+ }
117
+ if (flags.raw || !process.stdout.isTTY) {
118
+ // The exact bytes, for a pipe or a file: `apps version cat ... > file` makes a clean file.
119
+ process.stdout.write(read.bytes);
120
+ this.note(read);
121
+ return;
122
+ }
123
+ if ((0, appVersionFile_1.isBinary)(read.bytes)) {
124
+ return this.failWithCliError({
125
+ message: `"${read.path}" is binary (${read.length} bytes), so it is not printed to a terminal. Save it with --out <file>, or write the exact bytes with --raw.`,
126
+ code: 'APP_VERSION_FILE_BINARY',
127
+ exit: 2,
128
+ retryable: false,
129
+ });
130
+ }
131
+ const shown = (0, appVersionFile_1.escapeForTerminal)(read.bytes.toString('utf8'));
132
+ process.stdout.write(shown.text);
133
+ if (!shown.text.endsWith('\n'))
134
+ process.stdout.write('\n');
135
+ if (shown.escaped > 0) {
136
+ process.stderr.write(`${shown.escaped} control or direction-changing character${shown.escaped === 1 ? '' : 's'} shown as \\u{...} escapes; --raw writes the exact bytes.\n`);
137
+ }
138
+ this.note(read);
139
+ }
140
+ /** What was checked, on stderr so stdout stays the file. */
141
+ note(read) {
142
+ const bundle = read.bundleHash.slice(0, 12);
143
+ process.stderr.write(read.wholeFileVerified
144
+ ? `verified: ${read.length} bytes, sha-256 ${read.fileSha256.slice(0, 12)} matches the record of version ${read.versionId} (bundle ${bundle})\n`
145
+ : `partial read (bytes ${read.offset}-${read.offset + read.length} of ${read.total}): each slice matches the record of version ${read.versionId}, but the whole file was not read, so its sha-256 was not checked\n`);
146
+ }
147
+ /** Say what went wrong, in this command's terms where it has them. Never returns. */
148
+ failVersionFile(error) {
149
+ if (error instanceof appVersionFile_1.VersionFileIntegrityError) {
150
+ return this.failWithCliError({
151
+ message: `${error.message} Nothing was printed. Do not approve this version on the strength of this file.`,
152
+ code: appVersionFile_1.VERSION_FILE_INTEGRITY_CODE,
153
+ exit: appVersionFile_1.VERSION_FILE_INTEGRITY_EXIT,
154
+ retryable: false,
155
+ details: { problem: error.kind, ...error.details },
156
+ });
157
+ }
158
+ if (error instanceof appVersionFile_1.VersionFileNotListedError) {
159
+ return this.failWithCliError({
160
+ message: `${error.message} It lists: ${error.listed.join(', ')}. \`${this.config.bin} apps version show <version>\` lists them with their hashes.`,
161
+ code: 'APP_VERSION_FILE_NOT_LISTED',
162
+ exit: 4,
163
+ retryable: false,
164
+ details: { path: error.path, listed: error.listed },
165
+ });
166
+ }
167
+ if (error instanceof appVersionFile_1.VersionFileInputError) {
168
+ return this.failWithCliError({
169
+ message: error.message,
170
+ code: error.code,
171
+ exit: 2,
172
+ retryable: false,
173
+ });
174
+ }
175
+ // The server checks the stored bytes against the record first and refuses, with the reason, when they disagree.
176
+ const refusal = (0, apps_1.readAppsRefusal)(error);
177
+ if (refusal?.error === 'integrity_mismatch') {
178
+ return this.failWithCliError({
179
+ message: `${refusal.message ?? 'The stored bytes of this file are not the bytes the version recorded.'} Nothing was printed. Do not approve this version on the strength of this file.`,
180
+ code: appVersionFile_1.VERSION_FILE_INTEGRITY_CODE,
181
+ ...(refusal.status === undefined ? {} : { status: refusal.status }),
182
+ exit: appVersionFile_1.VERSION_FILE_INTEGRITY_EXIT,
183
+ retryable: false,
184
+ details: {
185
+ problem: 'server_integrity',
186
+ ...(refusal.reason ? { reason: refusal.reason } : {}),
187
+ },
188
+ });
189
+ }
190
+ return this.failApps(error);
191
+ }
192
+ }
193
+ exports.default = AppsVersionCat;
194
+ /**
195
+ * Write `bytes` to `target` only once they are verified, and so that no reader sees a part of them: a file of the same name
196
+ * in the same directory, then a rename. An existing target is refused unless `force`, and a symbolic link is never written
197
+ * through (the rename replaces the link itself).
198
+ */
199
+ function saveVerified(target, bytes, force) {
200
+ let existing = null;
201
+ try {
202
+ existing = (0, node_fs_1.lstatSync)(target);
203
+ }
204
+ catch (error) {
205
+ if (error.code !== 'ENOENT')
206
+ throw error;
207
+ }
208
+ if (existing && !force)
209
+ throw new Error('it already exists; use --force to replace it');
210
+ if (existing?.isDirectory())
211
+ throw new Error('it is a directory');
212
+ const staging = (0, node_path_1.join)((0, node_path_1.dirname)(target), `.${(0, node_path_1.basename)(target)}.${process.pid}.partial`);
213
+ try {
214
+ (0, node_fs_1.writeFileSync)(staging, bytes, { flag: 'wx', mode: 0o644 });
215
+ (0, node_fs_1.renameSync)(staging, target);
216
+ }
217
+ finally {
218
+ (0, node_fs_1.rmSync)(staging, { force: true });
219
+ }
220
+ }
@@ -4,7 +4,7 @@ const core_1 = require("@oclif/core");
4
4
  const data_provider_1 = require("@skrr-ai/data-provider");
5
5
  const apps_command_1 = require("../../../lib/apps-command");
6
6
  class AppsVersionShow extends apps_command_1.AppsCommand {
7
- static description = 'Show one version: its bundle hash, its files, what it declares and where it stands.';
7
+ static description = 'Show one version: its bundle hash, its files, what it declares and where it stands. To read the full text of a file, checked against these hashes, use `apps version cat`.';
8
8
  static examples = ['<%= config.bin %> apps version show appv_...'];
9
9
  static args = {
10
10
  version: core_1.Args.string({
@@ -30,6 +30,8 @@ class AppsVersionShow extends apps_command_1.AppsCommand {
30
30
  this.log(`bundle ${version.bundleHash}`);
31
31
  for (const file of version.files)
32
32
  this.log(`${file.path} ${file.size} bytes ${file.sha256.slice(0, 12)}`);
33
+ // a digest is not something a person can read: the text itself, checked against these hashes, is one command away
34
+ this.log(`read a file in full, checked against its hash: ${this.config.bin} apps version cat ${version.id} <path>`);
33
35
  }
34
36
  catch (error) {
35
37
  this.failApps(error);
@@ -0,0 +1,24 @@
1
+ import { BaseCommand } from '../../../base-command';
2
+ /**
3
+ * `skrr commerce incidents release` — a person's decision to release a held refund.
4
+ *
5
+ * An open Store Agent incident whose id another Agent now holds cannot prove its access is
6
+ * gone, so a retry (manual or automatic) never moves it. This records the decision to release
7
+ * it anyway, with a reason and evidence, then runs it: the pinned Agent's own permissions are
8
+ * removed, the replacement's data under the id is left in place, and the buyer is refunded
9
+ * through the ordinary path. It is a decision, not a retry, which is why it is its own verb and
10
+ * why the body is required: an administrator cannot release a refund without saying why.
11
+ * The server refuses unless that is exactly the live state of the incident.
12
+ */
13
+ export default class CommerceIncidentsRelease extends BaseCommand {
14
+ static description: string;
15
+ static examples: string[];
16
+ static args: {
17
+ reconciliation: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
18
+ };
19
+ static flags: {
20
+ file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
+ };
23
+ run(): Promise<void>;
24
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const base_command_1 = require("../../../base-command");
5
+ const commerce_1 = require("../../../lib/commerce");
6
+ const commerce_command_1 = require("../../../lib/commerce-command");
7
+ /**
8
+ * `skrr commerce incidents release` — a person's decision to release a held refund.
9
+ *
10
+ * An open Store Agent incident whose id another Agent now holds cannot prove its access is
11
+ * gone, so a retry (manual or automatic) never moves it. This records the decision to release
12
+ * it anyway, with a reason and evidence, then runs it: the pinned Agent's own permissions are
13
+ * removed, the replacement's data under the id is left in place, and the buyer is refunded
14
+ * through the ordinary path. It is a decision, not a retry, which is why it is its own verb and
15
+ * why the body is required: an administrator cannot release a refund without saying why.
16
+ * The server refuses unless that is exactly the live state of the incident.
17
+ */
18
+ class CommerceIncidentsRelease extends base_command_1.BaseCommand {
19
+ static description = "Release a Store refund held because another Agent holds the install's id (admin). A recorded decision with a reason and evidence — not a retry; for that see `commerce incidents retry`.";
20
+ static examples = [
21
+ '<%= config.bin %> commerce incidents release <reconciliation-id> --file ./release.json',
22
+ ];
23
+ static args = {
24
+ reconciliation: core_1.Args.string({
25
+ description: 'Fulfillment reconciliation id',
26
+ required: true,
27
+ ignoreStdin: true,
28
+ }),
29
+ };
30
+ static flags = { ...commerce_command_1.jsonBodyFlags };
31
+ async run() {
32
+ this.requireAuth();
33
+ const { args, flags } = await this.parse(CommerceIncidentsRelease);
34
+ const body = await (0, commerce_command_1.jsonBodyFrom)(this, flags.file, { required: true });
35
+ let result;
36
+ try {
37
+ result = await (0, commerce_1.releaseFulfillmentReplacementHold)(args.reconciliation, body);
38
+ }
39
+ catch (error) {
40
+ this.handleApiError(error);
41
+ return;
42
+ }
43
+ this.printJsonResult(result);
44
+ }
45
+ }
46
+ exports.default = CommerceIncidentsRelease;