@skrr-ai/cli 0.1.163 → 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 (102) hide show
  1. package/README.md +13 -0
  2. package/dist/base-command.d.ts +14 -1
  3. package/dist/base-command.js +190 -58
  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/show.js +7 -1
  8. package/dist/commands/agents/mini-computer/tasks-view.js +1 -1
  9. package/dist/commands/agents/supervision.d.ts +25 -0
  10. package/dist/commands/agents/supervision.js +129 -0
  11. package/dist/commands/apps/check.js +3 -8
  12. package/dist/commands/apps/data/batch.d.ts +1 -0
  13. package/dist/commands/apps/data/batch.js +19 -2
  14. package/dist/commands/apps/data/delete.d.ts +1 -0
  15. package/dist/commands/apps/data/delete.js +14 -2
  16. package/dist/commands/apps/data/patch.d.ts +1 -0
  17. package/dist/commands/apps/data/patch.js +11 -2
  18. package/dist/commands/apps/data/put.d.ts +1 -0
  19. package/dist/commands/apps/data/put.js +17 -3
  20. package/dist/commands/apps/install.js +7 -2
  21. package/dist/commands/apps/installations/compatibility.d.ts +13 -0
  22. package/dist/commands/apps/installations/compatibility.js +60 -0
  23. package/dist/commands/apps/installations/show.js +9 -3
  24. package/dist/commands/apps/installations/snapshot.js +5 -2
  25. package/dist/commands/apps/operations/check.d.ts +16 -0
  26. package/dist/commands/apps/operations/check.js +127 -0
  27. package/dist/commands/apps/publish/propose.js +33 -4
  28. package/dist/commands/apps/reconsent.js +7 -1
  29. package/dist/commands/apps/reference.d.ts +4 -2
  30. package/dist/commands/apps/reference.js +7 -4
  31. package/dist/commands/apps/rollback.d.ts +9 -0
  32. package/dist/commands/apps/rollback.js +81 -2
  33. package/dist/commands/apps/upgrade.d.ts +8 -0
  34. package/dist/commands/apps/upgrade.js +67 -2
  35. package/dist/commands/apps/version/cat.d.ts +22 -0
  36. package/dist/commands/apps/version/cat.js +220 -0
  37. package/dist/commands/apps/version/show.js +3 -1
  38. package/dist/commands/commerce/incidents/release.d.ts +24 -0
  39. package/dist/commands/commerce/incidents/release.js +46 -0
  40. package/dist/commands/duties/action-proposal.js +19 -11
  41. package/dist/commands/duties/cadence-decisions.js +7 -0
  42. package/dist/commands/duties/cases.js +12 -1
  43. package/dist/commands/duties/hypotheses.js +10 -3
  44. package/dist/commands/duties/observations.d.ts +4 -0
  45. package/dist/commands/duties/observations.js +14 -3
  46. package/dist/commands/duties/trigger-status.js +2 -2
  47. package/dist/commands/duties/wake-capabilities.js +12 -6
  48. package/dist/commands/outbox/list.d.ts +11 -4
  49. package/dist/commands/outbox/list.js +56 -9
  50. package/dist/commands/outbox/retry.d.ts +8 -2
  51. package/dist/commands/outbox/retry.js +76 -16
  52. package/dist/commands/outbox/show.d.ts +20 -0
  53. package/dist/commands/outbox/show.js +83 -0
  54. package/dist/commands/proposals/list.js +13 -9
  55. package/dist/commands/requests/show.d.ts +12 -0
  56. package/dist/commands/requests/show.js +42 -23
  57. package/dist/commands/spaces/deletion/cancel.d.ts +21 -0
  58. package/dist/commands/spaces/deletion/cancel.js +70 -0
  59. package/dist/commands/spaces/workflows/run.js +12 -0
  60. package/dist/commands/widgets/check.d.ts +9 -0
  61. package/dist/commands/widgets/check.js +16 -3
  62. package/dist/generated/agent-guides.json +17 -17
  63. package/dist/lib/api-fetch.d.ts +5 -0
  64. package/dist/lib/api-fetch.js +53 -21
  65. package/dist/lib/appCompatibility.d.ts +31 -0
  66. package/dist/lib/appCompatibility.js +66 -0
  67. package/dist/lib/appData.d.ts +46 -4
  68. package/dist/lib/appData.js +156 -31
  69. package/dist/lib/appInstallations.d.ts +32 -5
  70. package/dist/lib/appInstallations.js +218 -34
  71. package/dist/lib/appVersionFile.d.ts +82 -0
  72. package/dist/lib/appVersionFile.js +195 -0
  73. package/dist/lib/apps-command.d.ts +14 -3
  74. package/dist/lib/apps-command.js +68 -60
  75. package/dist/lib/appsCheck.js +31 -6
  76. package/dist/lib/chat-supervision.d.ts +21 -0
  77. package/dist/lib/chat-supervision.js +37 -0
  78. package/dist/lib/commerce.d.ts +6 -0
  79. package/dist/lib/commerce.js +9 -0
  80. package/dist/lib/duties.d.ts +19 -1
  81. package/dist/lib/duties.js +21 -3
  82. package/dist/lib/json-output.d.ts +2 -0
  83. package/dist/lib/json-output.js +8 -4
  84. package/dist/lib/miniComputer.d.ts +1 -0
  85. package/dist/lib/miniComputer.js +7 -2
  86. package/dist/lib/miniComputerCommand.js +4 -1
  87. package/dist/lib/node-adapter.d.ts +2 -0
  88. package/dist/lib/node-adapter.js +35 -8
  89. package/dist/lib/outbox.d.ts +110 -1
  90. package/dist/lib/outbox.js +261 -35
  91. package/dist/lib/roles.d.ts +1 -1
  92. package/dist/lib/space-deletion-cancel.d.ts +47 -0
  93. package/dist/lib/space-deletion-cancel.js +141 -0
  94. package/dist/lib/widgetCheck.js +30 -4
  95. package/dist/lib/widgetStaticScan.d.ts +24 -9
  96. package/dist/lib/widgetStaticScan.js +207 -192
  97. package/dist/lib/write-outcome.d.ts +74 -0
  98. package/dist/lib/write-outcome.js +176 -0
  99. package/dist/node_modules/@skrr-ai/data-provider/APP_HTML_PARSER_LICENSES.txt +36 -0
  100. package/dist/node_modules/@skrr-ai/data-provider/index.js +20204 -15169
  101. package/oclif.manifest.json +2143 -25
  102. package/package.json +10 -3
@@ -146,8 +146,43 @@ const STORE_WRITER_WORDS = {
146
146
  agent: "only agents acting for people with edit access can change it; the app's own code can only read it",
147
147
  person: "only people can change it; the app's own code can only read it",
148
148
  };
149
+ /** Names as a sentence lists them, each in quotes: "a", "a" and "b", "a", "b" and "c". */
150
+ function quotedList(names) {
151
+ const quoted = names.map((name) => `"${name}"`);
152
+ const last = quoted.pop();
153
+ if (last === undefined) {
154
+ return '';
155
+ }
156
+ return quoted.length === 0 ? last : `${quoted.join(', ')} and ${last}`;
157
+ }
158
+ /**
159
+ * What can wake a job declared as `on@change:<collection>`, said from the writers THE COLLECTION DECLARES (`appChangeWakeFacts`),
160
+ * so the line cannot name a source the "keep its own data" line above it says is impossible (OSK-23757: "an app-window write"
161
+ * over a collection the app's own code could only read). `declared` is `undefined` when this disclosure does not list the
162
+ * collection's writers (an older server, or a collection the app cannot read), and the line then says it does not know.
163
+ */
164
+ function describeChangeWake(name, declared) {
165
+ const target = `"${name}"`;
166
+ const never = 'agent writes and webhook deliveries never wake it this way';
167
+ const facts = (0, data_provider_1.appChangeWakeFacts)(declared);
168
+ if (!facts.known) {
169
+ return `can wake on a permitted write by a person or the app's own code to ${target} (who may write it is not shown here; ${never}; not on a clock)`;
170
+ }
171
+ const person = facts.sources.includes('person');
172
+ const app = facts.sources.includes('app');
173
+ if (person && app) {
174
+ return `can wake when a person or the app's own code changes ${target} (${never}; not on a clock)`;
175
+ }
176
+ if (person) {
177
+ return `can wake when a person changes ${target} (the app's own code cannot write it; ${never}; not on a clock)`;
178
+ }
179
+ if (app) {
180
+ return `can wake when the app's own code changes ${target} (people cannot write it; ${never}; not on a clock)`;
181
+ }
182
+ return `cannot be woken by a change to ${target} (no writer it declares can start a wake: an agent's writes never do; not on a clock)`;
183
+ }
149
184
  /** A job's schedule in words, beside the text the author wrote (which is always still shown). */
150
- function describeSchedule(schedule) {
185
+ function describeSchedule(schedule, collectionWriters) {
151
186
  const reading = (0, data_provider_1.readAppJobSchedule)(schedule);
152
187
  switch (reading.kind) {
153
188
  case 'daily':
@@ -157,7 +192,7 @@ function describeSchedule(schedule) {
157
192
  case 'event':
158
193
  return reading.source === 'webhook'
159
194
  ? `can wake when the app's "${reading.name}" webhook delivers an event (not on a clock)`
160
- : `can wake on a permitted person or app-window write to "${reading.name}" (see collection permissions; agent and webhook writes do not trigger this change wake; not on a clock)`;
195
+ : describeChangeWake(reading.name, collectionWriters?.get(reading.name));
161
196
  case 'configured':
162
197
  return "on a schedule set in the app's settings";
163
198
  default:
@@ -390,7 +425,7 @@ function jobNextLine(job) {
390
425
  }
391
426
  return [` next: ${stateReason.next.replace(FORMAT_JOB_STATES_RE, '<installation id>')}`];
392
427
  }
393
- function itemLines(item) {
428
+ function itemLines(item, collectionWriters) {
394
429
  switch (item.kind) {
395
430
  case 'store':
396
431
  return item.collections.map((collection) => {
@@ -438,17 +473,16 @@ function itemLines(item) {
438
473
  return [
439
474
  `run these jobs automatically, unattended. ${item.statement} That is accepted when you install it, and each job is listed so you can weigh it:`,
440
475
  ...item.jobs.flatMap((job) => [
441
- ` - ${(0, data_provider_1.plainAppLabel)(job.title)} (${job.schedule}): ${describeSchedule(job.schedule)}${job.guide ? `, following ${job.guide}` : ''}${mark(job.consent)}${describeJobState(job)}`,
476
+ ` - ${(0, data_provider_1.plainAppLabel)(job.title)} (${job.schedule}): ${describeSchedule(job.schedule, collectionWriters)}${job.guide ? `, following ${job.guide}` : ''}${mark(job.consent)}${describeJobState(job)}`,
442
477
  ...jobNextLine(job),
443
478
  ]),
444
- ...(item.jobs.some((job) => {
445
- const kind = (0, data_provider_1.readAppJobSchedule)(job.schedule).kind;
446
- return kind === 'event' || kind === 'configured';
447
- })
448
- ? [' If a job is event-triggered, limits or delivery failures can cause it to miss events. A recorded change or webhook delivery does not guarantee a run.']
449
- : []),
479
+ // how a wake is delivered, said once and only for an app with a job an event can start (OSK-23917); the sentence is the
480
+ // contract's, the same one the web draws and the reference prints
481
+ ...((0, data_provider_1.appDisclosureHasEventWake)(item.jobs) ? [` ${data_provider_1.APP_EVENT_WAKE_BEST_EFFORT}`] : []),
450
482
  ...(item.jobs.some((job) => (0, data_provider_1.readAppJobSchedule)(job.schedule).kind === 'configured')
451
- ? [' If a settings-based schedule resolves to an event, the job may not wake at all. A scheduled status does not confirm it can wake.']
483
+ ? [
484
+ ' If a settings-based schedule resolves to an event, the job may not wake at all. A scheduled status does not confirm it can wake.',
485
+ ]
452
486
  : []),
453
487
  ...(item.notices?.some((notice) => notice.kind === 'trigger_detached')
454
488
  ? [
@@ -466,12 +500,52 @@ const REASON_WORDS = {
466
500
  capability_expanded: 'this version asks for more than was approved',
467
501
  egress_code_changed: `the app changed, and what it may send out of ${data_provider_1.BRAND.displayName} is approved only for the code you saw`,
468
502
  jobs_changed: 'a job was added or changed',
469
- store_writers_expanded: "this version lets something new change the data the app keeps, such as the app's own code",
503
+ // The fallback for a reason that names no writer (`items` absent or unreadable): it names none either. It used to say
504
+ // "such as the app's own code" over every version, including one that added only an Agent writer (OSK-23751).
505
+ store_writers_expanded: 'this version lets a kind of writer you have not approved change data the app already keeps',
470
506
  };
471
- /** The words for each reason a grant stopped covering a version; a kind it does not know is said as it came. */
472
- function describeGrantReasons(kinds) {
507
+ /**
508
+ * Who a version newly lets change a collection, as a noun phrase a sentence can take. A `Record` over the contract's writers, so
509
+ * a writer added there does not compile here until it has words. The same three phrases as the web's
510
+ * `com_app_reason_store_writers_added_*` sentences, which read the same facts (`appStoreWritersAdded`).
511
+ */
512
+ const STORE_WRITER_ADDED_WORDS = {
513
+ app: "the app's own code",
514
+ agent: 'agents acting for people with edit access',
515
+ person: 'people with edit access',
516
+ };
517
+ /** One line of the new writers a version adds, for one kind of writer: which collections it can now change. */
518
+ function storeWritersAddedLine(added) {
519
+ const who = added.known
520
+ ? STORE_WRITER_ADDED_WORDS[added.writer]
521
+ : `a kind of writer this CLI does not know ("${(0, data_provider_1.plainAppLabel)(added.writer, 40)}")`;
522
+ return `this version lets ${who} change ${quotedList(added.collections)} (you have not approved that)`;
523
+ }
524
+ /**
525
+ * The words for each reason a grant stopped covering a version; a kind it does not know is said as it came. A reason that
526
+ * carries facts says them: `store_writers_expanded` lists, for each kind of writer a version adds, the collections it can now
527
+ * change (`digest:app` is "the app's own code ... "digest""), from the `items` the server sent, and says the neutral
528
+ * sentence when it sent none. All the store-writer reasons of a list are said together, once.
529
+ */
530
+ function describeGrantReasons(reasons) {
473
531
  const words = REASON_WORDS;
474
- return kinds.map((kind) => words[kind] ?? kind);
532
+ const lines = [];
533
+ let writersSaid = false;
534
+ for (const reason of reasons) {
535
+ if (reason.kind === 'store_writers_expanded') {
536
+ if (writersSaid) {
537
+ continue;
538
+ }
539
+ writersSaid = true;
540
+ const added = (0, data_provider_1.appStoreWritersAdded)(reasons);
541
+ if (added.length > 0) {
542
+ lines.push(...added.map(storeWritersAddedLine));
543
+ continue;
544
+ }
545
+ }
546
+ lines.push(words[reason.kind] ?? reason.kind);
547
+ }
548
+ return lines;
475
549
  }
476
550
  /**
477
551
  * The sentences of the note on an app installed on a PERSON that are true of this app, and none of the others (OSK-23975).
@@ -547,13 +621,15 @@ function formatDisclosure(raw, facts) {
547
621
  lines.push(`For an installation on ${disclosure.scope.principal.kind} ${disclosure.scope.principal.id}.`);
548
622
  }
549
623
  }
624
+ // a job woken by a change to a collection is said from who that collection lets write (OSK-23757)
625
+ const collectionWriters = (0, data_provider_1.appDisclosureCollectionWriters)(disclosure.can);
550
626
  if (disclosure.can.length === 0) {
551
627
  lines.push('It asks for nothing: it can only draw itself.');
552
628
  }
553
629
  else {
554
630
  lines.push('It can:');
555
631
  for (const item of disclosure.can) {
556
- const [first, ...rest] = itemLines(item);
632
+ const [first, ...rest] = itemLines(item, collectionWriters);
557
633
  if (first !== undefined) {
558
634
  lines.push(` - ${first}`);
559
635
  lines.push(...rest.map((line) => ` ${line.replace(FORMAT_DISCLOSURE_RE, '')}`.replace(FORMAT_DISCLOSURE_RE_2, ' ')));
@@ -562,7 +638,7 @@ function formatDisclosure(raw, facts) {
562
638
  }
563
639
  if (disclosure.consent.status === 'needs_reconsent') {
564
640
  lines.push('Why it needs approving again:');
565
- for (const reason of describeGrantReasons(disclosure.consent.reasons.map((r) => r.kind))) {
641
+ for (const reason of describeGrantReasons(disclosure.consent.reasons)) {
566
642
  lines.push(` - ${reason}`);
567
643
  }
568
644
  }
@@ -783,6 +859,12 @@ const CHECK_OUTCOME_WORDS = {
783
859
  findings: 'found things to look at',
784
860
  nothing_found: 'found nothing it looks for',
785
861
  };
862
+ /**
863
+ * The check's rule for a call the app's window has and the platform has nothing to run (`unansweredIssue` in
864
+ * data-provider's `appCheck.ts`; its title and `why` are in `appCheckRules.ts`). The rule id is the contract's, spelled
865
+ * here because the summary names a rule by it; `apps-installation-commands.spec.ts` fails if the contract stops having it.
866
+ */
867
+ const UNANSWERED_CALL_RULE = 'capability/unanswered';
786
868
  const REVIEW_LIMIT_REMINDER = 'This automatic check does not include a human review and cannot tell whether anyone else has reviewed the app.';
787
869
  const KNOWN_SAFETY_HEADLINE = 'This is an automatic check of the files in the package. It can find obvious problems; it cannot show that an app is safe.';
788
870
  /**
@@ -816,10 +898,25 @@ function describeDisclosureCheck(check) {
816
898
  if (counts.block + counts.warn + counts.info + counts.unanalyzable > 0) {
817
899
  lines.push(` ${counts.block} would keep it out of the store, ${counts.warn} to read, ${counts.info} low-key, ${counts.unanalyzable} could not be read`);
818
900
  }
901
+ let unansweredWhySaid = false;
819
902
  for (const found of summary.findings.slice(0, 5)) {
820
903
  const title = summary.rules[found.rule]?.title ?? found.rule;
821
904
  const place = found.path ? ` (${found.line ? `${found.path}:${found.line}` : found.path})` : '';
822
905
  lines.push(` - ${(0, data_provider_1.plainAppLabel)(title, 160)}${place}`);
906
+ if (found.rule === UNANSWERED_CALL_RULE) {
907
+ // The title alone ("A call the platform cannot answer yet") does not say WHICH call, or that it fails every time.
908
+ // The finding's own message does, and the rule's `why` says what that means for the app. Both are the server's
909
+ // words, so the web screen says the same; both are drawn as plain one-line text.
910
+ const message = (0, data_provider_1.plainAppLabel)(found.message, 400);
911
+ if (message) {
912
+ lines.push(` ${message}`);
913
+ }
914
+ const why = (0, data_provider_1.plainAppLabel)(summary.rules[found.rule]?.why, 600);
915
+ if (why && !unansweredWhySaid) {
916
+ lines.push(` ${why}`);
917
+ unansweredWhySaid = true;
918
+ }
919
+ }
823
920
  }
824
921
  const more = summary.findings.length - 5 + summary.omitted;
825
922
  if (more > 0) {
@@ -887,6 +984,47 @@ const FORBIDDEN_REASON_WORDS = {
887
984
  // the installation was suspended by the platform, not by the person: resuming it is not theirs to do
888
985
  suspended_by_moderation: 'The platform suspended this app, not you, and only the platform can lift that. There is nothing to resume from here.',
889
986
  };
987
+ const INSTALLATION_ID_PATTERN = /^appi_[A-Za-z0-9_-]{1,60}(?![\s\S])/;
988
+ const VERSION_ID_PATTERN = /^appv_[A-Za-z0-9_-]{1,60}(?![\s\S])/;
989
+ const AGENT_ID_PATTERN = /^agent_[A-Za-z0-9_-]{1,60}(?![\s\S])/;
990
+ /** An id of the shape a command takes, or null. A refusal's ids come from the server, and none goes into a command unread. */
991
+ function idOf(pattern, value) {
992
+ return typeof value === 'string' && pattern.test(value) ? value : null;
993
+ }
994
+ /** What did not happen, by what the command was doing. A refusal is made before anything is written, so "changed" is true of every command. */
995
+ function nothingWas(context) {
996
+ switch (context.action) {
997
+ case 'install':
998
+ return 'Nothing was installed.';
999
+ case 'reconsent':
1000
+ return 'Nothing was approved.';
1001
+ default:
1002
+ return 'Nothing was changed.';
1003
+ }
1004
+ }
1005
+ /**
1006
+ * The command that shows a version's disclosure, with the argument it requires (the version) and the option that makes
1007
+ * its answer about the place in question: the installation being approved again or moved, or who an install is for.
1008
+ */
1009
+ function disclosureCommand(bin, context, versionId) {
1010
+ const version = idOf(VERSION_ID_PATTERN, versionId) ?? '<version>';
1011
+ const installation = idOf(INSTALLATION_ID_PATTERN, context.subject);
1012
+ if (installation) {
1013
+ return `${bin} apps disclosure ${version} --installation ${installation}`;
1014
+ }
1015
+ if (context.principal?.kind === 'user') {
1016
+ return `${bin} apps disclosure ${version} --me`;
1017
+ }
1018
+ const agent = idOf(AGENT_ID_PATTERN, context.principal?.id);
1019
+ if (context.principal?.kind === 'agent' && agent) {
1020
+ return `${bin} apps disclosure ${version} --agent ${agent}`;
1021
+ }
1022
+ return `${bin} apps disclosure ${version}`;
1023
+ }
1024
+ /** The version a refusal says an installation runs now (`current.versionId`), or null. */
1025
+ function currentVersionOf(refusal) {
1026
+ return idOf(VERSION_ID_PATTERN, refusal.current?.versionId);
1027
+ }
890
1028
  /**
891
1029
  * Every reason an installation call is refused, with the sentence and the next step. A `Record` over the
892
1030
  * contract's list, so a reason added there does not compile here until it has words.
@@ -900,19 +1038,32 @@ const CONFLICT_WORDS = {
900
1038
  version_not_found: () => 'There is no such version of that app that you can use.',
901
1039
  version_not_installable: () => 'That version is not available for this action. If an install or version change was attempted, check the installation list for the same account and destination, then inspect its current state and data before deciding what to do next; do not retry blindly.',
902
1040
  manifest_invalid: () => "That version's manifest is not one this platform will run, so it was not installed.",
903
- consent_mismatch: (_refusal, bin) => `The bundle you were shown is not the one on record for that version. Nothing was installed. Run \`${bin} apps disclosure\` again and approve what it shows.`,
904
- version_changed: (refusal, bin) => `The installation moved to another version while you were deciding${refusal.current ? ` (now ${refusal.current.versionId})` : ''}. Nothing was changed. Read \`${bin} apps disclosure\` again and approve what it shows.`,
1041
+ consent_mismatch: (_refusal, bin, context) => `The bundle you were shown is not the one on record for that version. ${nothingWas(context)} Run \`${disclosureCommand(bin, context, context.versionId)}\` again and approve what it shows.`,
1042
+ version_changed: (refusal, bin, context) => {
1043
+ const installation = idOf(INSTALLATION_ID_PATTERN, context.subject);
1044
+ const now = currentVersionOf(refusal);
1045
+ return `The installation moved to another version while you were deciding${refusal.current ? ` (now ${refusal.current.versionId})` : ''}. Nothing was changed. Read \`${disclosureCommand(bin, context, now ?? context.versionId)}\` again and approve what it shows${installation ? ` with \`${bin} apps reconsent ${installation} --yes\`` : ''}.`;
1046
+ },
905
1047
  invalid_update_policy: () => 'That update policy is not one of manual, auto_minor or beta.',
906
1048
  binding_required: (refusal) => describeBindingRefusal(refusal),
907
- already_installed: (refusal, bin) => `That app is already installed on this agent${refusal.installationId ? ` (${refusal.installationId})` : ''}. Move it to a newer version with \`${bin} apps upgrade\`.`,
1049
+ already_installed: (refusal, bin, context) => {
1050
+ const where = context.principal === undefined
1051
+ ? ''
1052
+ : context.principal.kind === 'user'
1053
+ ? ' on you'
1054
+ : ' on this agent';
1055
+ const prior = idOf(INSTALLATION_ID_PATTERN, refusal.installationId);
1056
+ const wanted = idOf(VERSION_ID_PATTERN, context.versionId);
1057
+ return `That app is already installed${where}${refusal.installationId ? ` (${refusal.installationId})` : ''}. To ${wanted ? `run the version you asked for (${wanted}) instead` : 'move it to another version'}, use \`${bin} apps upgrade ${prior ?? '<installation>'} --version ${wanted ?? '<version>'}\`${prior ? `; \`${bin} apps installations show ${prior}\` says which version it runs now` : ''}.`;
1058
+ },
908
1059
  not_found: () => 'There is no such installation that you can see.',
909
1060
  changed: () => 'The installation changed while this was running. Read its current state before deciding what to do next.',
910
1061
  not_auto_updatable: () => 'That installation does not update on its own.',
911
1062
  data_deletion_not_confirmed: (refusal) => `Removing this app also deletes its data (${refusal.docCount ?? 'some'} document${refusal.docCount === 1 ? '' : 's'}), which is yours to confirm. Nothing was removed. Say it, with --delete-data, if you mean it.`,
912
1063
  installation_incomplete: () => 'This installation points at a version that can no longer be read. It can be removed, not run.',
913
- principal_scope_unserved: (refusal) => `This app asks for ${describeScopeIssues(refusal.unserved)}, which cannot work for the place it would be installed (an app installed on a person reaches that person's own data, never an agent's or a space's, and has no agent to run it yet).${needsOperator(refusal.unserved)
1064
+ principal_scope_unserved: (refusal, _bin, context) => `This app asks for ${describeScopeIssues(refusal.unserved)}, which cannot work for the place it would be installed (an app installed on a person reaches that person's own data, never an agent's or a space's, and has no agent to run it yet).${needsOperator(refusal.unserved)
914
1065
  ? ' An app that needs an agent to run it can, for now, only be installed on one of your agents.'
915
- : ''} Nothing was installed.`,
1066
+ : ''} ${nothingWas(context)}`,
916
1067
  no_previous_version: () => 'This installation has never been moved onto the version it runs, so there is no earlier version to go back to. Nothing was changed.',
917
1068
  job_schedule_invalid: (refusal, bin) => {
918
1069
  const issues = Array.isArray(refusal.issues)
@@ -921,15 +1072,25 @@ const CONFLICT_WORDS = {
921
1072
  return `${issues > 0 ? `${issues} of this app's scheduled jobs have` : 'A scheduled job has'} a schedule or event target that cannot be used. Review the selected settings and declared targets; \`${bin} apps check\` checks the app package.`;
922
1073
  },
923
1074
  };
924
- /** The sentence for a refusal the server made on an installation call, or null for one that is not. */
925
- function describeInstallationConflict(refusal, bin, subject) {
1075
+ /**
1076
+ * The sentence for a refusal the server made on an installation call, or null for one that is not. `context` is what the
1077
+ * command knows (the installation it was about, the version, what it was doing); a bare string is the installation, as
1078
+ * the callers that only ever had that pass it.
1079
+ */
1080
+ function describeInstallationConflict(refusal, bin, context) {
926
1081
  if (!(0, data_provider_1.isAppInstallationConflict)(refusal.error)) {
927
1082
  return null;
928
1083
  }
929
- if (refusal.error === 'changed' && subject && /^appi_[A-Za-z0-9_-]{1,60}(?![\s\S])/.test(subject)) {
930
- return `The installation changed while this was running. Read its current state with \`${bin} apps installations show ${subject}\` using the same account, deployment, profile and workspace before deciding what to do next.`;
1084
+ const known = typeof context === 'string' ? { subject: context } : (context ?? {});
1085
+ if (refusal.error === 'changed' && refusal.reason === 'rollback_target_changed') {
1086
+ // refused before anything was written: the server compares the target first, so this one can say nothing was moved
1087
+ const named = known.subject && /^appi_[A-Za-z0-9_-]{1,60}(?![\s\S])/.test(known.subject);
1088
+ return `The version this rollback would go back to is no longer the one you expected, so nothing was moved. Read the installation's versions again${named ? ` with \`${bin} apps installations versions ${known.subject}\`` : ''} before deciding what to do next.`;
931
1089
  }
932
- return CONFLICT_WORDS[refusal.error](refusal, bin);
1090
+ if (refusal.error === 'changed' && idOf(INSTALLATION_ID_PATTERN, known.subject)) {
1091
+ return `The installation changed while this was running. Read its current state with \`${bin} apps installations show ${known.subject}\` using the same account, deployment, profile and workspace before deciding what to do next.`;
1092
+ }
1093
+ return CONFLICT_WORDS[refusal.error](refusal, bin, known);
933
1094
  }
934
1095
  /** The machine code of every installation refusal: `APP_<REASON>`. */
935
1096
  exports.ALL_INSTALLATION_REFUSAL_CODES = Object.fromEntries(Object.keys(CONFLICT_WORDS).map((conflict) => [conflict, `APP_${conflict.toUpperCase()}`]));
@@ -1079,9 +1240,11 @@ function installationRefusalExit(conflict) {
1079
1240
  /** Why a version that needs no new approval was still not applied by the opt-in, in a clause. */
1080
1241
  const AUTO_APPLY_HOLD_WORDS = {
1081
1242
  installation_suspended: 'the installation is paused',
1082
- cut_by_another_person: "it was not made by the person who enabled automatic updates or their own agents (apply it yourself if you trust it)",
1243
+ cut_by_another_person: 'it was not made by the person who enabled automatic updates or their own agents (apply it yourself if you trust it)',
1083
1244
  version_not_installable: 'the version was rejected or withdrawn',
1084
1245
  principal_scope_unserved: 'it declares something this installation cannot serve',
1246
+ data_incompatible: 'the installation holds data that version’s schemas do not fit (see `apps installations compatibility`)',
1247
+ data_unproven: 'it could not be proven that the installation’s stored data fits that version’s schemas (see `apps installations compatibility`); unknown is not a pass',
1085
1248
  };
1086
1249
  /** Names come from an app's version; show a bounded summary and keep the full disclosure as the review step. */
1087
1250
  function pendingReasonDetails(reason) {
@@ -1103,6 +1266,17 @@ function pendingReasonDetails(reason) {
1103
1266
  }
1104
1267
  return lines;
1105
1268
  }
1269
+ /**
1270
+ * A pending notice (`pending.notices`), in a line. It is worth reading before the version is applied and it is NOT a reason
1271
+ * for approving again: the version's `status` and the instructions beside it are exactly what they were, and nothing here reads
1272
+ * a document (OSK-23684).
1273
+ */
1274
+ function describePendingNotice(notice) {
1275
+ switch (notice.kind) {
1276
+ case 'interface_major_changed':
1277
+ return `note: this version changes the app's data interface from major ${notice.from} to major ${notice.to}, so its collections may have a new shape. Applying it does not check or migrate documents the installation already holds, and some may not satisfy the new schema. This is a notice, not a block.`;
1278
+ }
1279
+ }
1106
1280
  /**
1107
1281
  * What the versions view says, as lines a person reads: which version is installed, what is waiting and what it needs,
1108
1282
  * the opt-in and the currently observed rollback target. `needs_reconsent` is said as "asks for more than you approved", never as a verdict on the
@@ -1113,10 +1287,16 @@ function formatInstallationVersions(view, bin, requestedInstallationId) {
1113
1287
  // commands unless they match the requested installation and are safe as unquoted arguments.
1114
1288
  const safeId = (value) => typeof value === 'string' && /^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}(?![\s\S])/.test(value);
1115
1289
  const safeVersion = (value) => Number.isSafeInteger(value) && Number(value) > 0;
1116
- if (!view || !safeId(requestedInstallationId) || view.installationId !== requestedInstallationId ||
1117
- !safeId(view.installationId) || !/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}(?![\s\S])/.test(bin) ||
1118
- !view.current || !safeId(view.current.versionId) || !safeVersion(view.current.version) ||
1119
- typeof view.viewer?.canManage !== 'boolean' || typeof view.autoApply?.enabled !== 'boolean' ||
1290
+ if (!view ||
1291
+ !safeId(requestedInstallationId) ||
1292
+ view.installationId !== requestedInstallationId ||
1293
+ !safeId(view.installationId) ||
1294
+ !/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}(?![\s\S])/.test(bin) ||
1295
+ !view.current ||
1296
+ !safeId(view.current.versionId) ||
1297
+ !safeVersion(view.current.version) ||
1298
+ typeof view.viewer?.canManage !== 'boolean' ||
1299
+ typeof view.autoApply?.enabled !== 'boolean' ||
1120
1300
  !Array.isArray(view.history) ||
1121
1301
  (view.pending && (!safeId(view.pending.versionId) || !safeVersion(view.pending.version))) ||
1122
1302
  (view.rollback && (!safeId(view.rollback.versionId) || !safeVersion(view.rollback.version)))) {
@@ -1135,10 +1315,14 @@ function formatInstallationVersions(view, bin, requestedInstallationId) {
1135
1315
  if (view.pending) {
1136
1316
  const pending = view.pending;
1137
1317
  lines.push(`waiting: v${pending.version} (${pending.versionId})${pending.changelog ? ` - ${(0, data_provider_1.plainAppLabel)(pending.changelog, 120)}` : ''}`);
1318
+ // said whatever its status: a version that asks for nothing new can still change what the installation's documents must be
1319
+ for (const notice of (0, data_provider_1.readAppPendingNotices)(pending.notices)) {
1320
+ lines.push(` ${describePendingNotice(notice)}`);
1321
+ }
1138
1322
  if (pending.status === 'needs_reconsent') {
1139
1323
  lines.push(' it asks for more than you approved, so it does not run until you approve it:');
1140
1324
  for (const reason of pending.reasons) {
1141
- for (const line of describeGrantReasons([reason.kind]))
1325
+ for (const line of describeGrantReasons([reason]))
1142
1326
  lines.push(` ${line}`);
1143
1327
  for (const line of pendingReasonDetails(reason))
1144
1328
  lines.push(` ${line}`);
@@ -1160,7 +1344,7 @@ function formatInstallationVersions(view, bin, requestedInstallationId) {
1160
1344
  lines.push('waiting: no newer version is shown as waiting; the installed version may still need approval.');
1161
1345
  }
1162
1346
  lines.push(view.rollback
1163
- ? `going back: the currently observed previous version is v${view.rollback.version} (${view.rollback.versionId}). Run \`${bin} apps rollback ${view.installationId} --expected-version ${view.current.versionId}\` to request a rollback. The server selects the target from its history when it handles the request; --expected-version checks the current version, not the target or history.`
1347
+ ? `going back: the currently observed previous version is v${view.rollback.version} (${view.rollback.versionId}). Run \`${bin} apps rollback ${view.installationId} --expected-version ${view.current.versionId} --expected-target ${view.rollback.versionId}\` to request a rollback to that version only. The server selects the target from its history when it handles the request; --expected-version checks the current version, not the target or history, and --expected-target refuses the rollback, moving nothing, if the target is a different version by then.`
1164
1348
  : 'going back: no rollback option is available right now');
1165
1349
  for (const move of view.history.slice(-5)) {
1166
1350
  lines.push(` ${move.at} ${move.cause}${move.by === 'policy' ? ' (by the platform, on your opt-in)' : ` (${move.by})`} ${move.from} -> ${move.to}`);
@@ -0,0 +1,82 @@
1
+ import type { AppVersionDetail, AppVersionFileChunk } from '@skrr-ai/data-provider';
2
+ /** The most a read will hold. A package file is far smaller (`APP_DRAFT_LIMITS`); a server that says otherwise is not believed. */
3
+ export declare const VERSION_FILE_READ_MAX_BYTES: number;
4
+ /** The machine code and exit under which a mismatch is reported. A distinct exit: a harness must not read "6" as an ordinary failure. */
5
+ export declare const VERSION_FILE_INTEGRITY_CODE = "APP_VERSION_FILE_INTEGRITY";
6
+ export declare const VERSION_FILE_INTEGRITY_EXIT = 6;
7
+ /** What disagreed, in a closed set a harness can switch on. */
8
+ export type VersionFileProblemKind =
9
+ /** the version's file list does not hash to its `bundleHash` */
10
+ 'bundle_hash'
11
+ /** the server says the bytes it holds are not the bytes the version recorded */
12
+ | 'server_integrity'
13
+ /** a slice names another version, bundle, path, digest or size than the version's record */
14
+ | 'record'
15
+ /** a slice does not start where the last one ended, or is not the length asked for */
16
+ | 'continuity'
17
+ /** a slice's bytes are not valid base64, or do not hash to the digest it states */
18
+ | 'chunk_digest'
19
+ /** the slices joined are not the size, or do not hash to the digest, the version recorded */
20
+ | 'file_digest';
21
+ /** The bytes are not provably the version's. Carries what disagreed; never the bytes. */
22
+ export declare class VersionFileIntegrityError extends Error {
23
+ readonly kind: VersionFileProblemKind;
24
+ readonly details: Record<string, unknown>;
25
+ constructor(kind: VersionFileProblemKind, message: string, details?: Record<string, unknown>);
26
+ }
27
+ /** The path is not one the version lists. Carries a bounded sample of the ones it does. */
28
+ export declare class VersionFileNotListedError extends Error {
29
+ readonly path: string;
30
+ readonly listed: string[];
31
+ constructor(path: string, listed: string[]);
32
+ }
33
+ /** The caller asked for something that cannot be read (an offset past the end, a file past what the CLI will hold). */
34
+ export declare class VersionFileInputError extends Error {
35
+ readonly code: string;
36
+ constructor(code: string, message: string);
37
+ }
38
+ /** The two calls a read makes. `dataService` is the real one; a spec hands in its own. */
39
+ export interface VersionFileReader {
40
+ getVersion(versionId: string): Promise<AppVersionDetail>;
41
+ readChunk(versionId: string, params: {
42
+ path: string;
43
+ offset: number;
44
+ limit: number;
45
+ }): Promise<AppVersionFileChunk>;
46
+ }
47
+ export interface VersionFileRead {
48
+ versionId: string;
49
+ bundleHash: string;
50
+ path: string;
51
+ /** Where the bytes start, and how many there are. */
52
+ offset: number;
53
+ length: number;
54
+ /** The file's size, as the version recorded it. */
55
+ total: number;
56
+ /** The file's digest, as the version recorded it. */
57
+ fileSha256: string;
58
+ /** Slices asked for. */
59
+ chunks: number;
60
+ /** True when the whole file was read and its size and digest matched the record. False is a partial read, not a failure. */
61
+ wholeFileVerified: boolean;
62
+ bytes: Buffer;
63
+ }
64
+ /**
65
+ * Read `path` of `versionId` from `offset` for at most `limit` bytes (to the end when absent), checking everything the file
66
+ * header lists, and return the bytes only if all of it held. Throws {@link VersionFileIntegrityError},
67
+ * {@link VersionFileNotListedError} or {@link VersionFileInputError}; anything else is the API's own failure and is the
68
+ * caller's to say.
69
+ */
70
+ export declare function readVersionFile(reader: VersionFileReader, input: {
71
+ versionId: string;
72
+ path: string;
73
+ offset?: number;
74
+ limit?: number;
75
+ }): Promise<VersionFileRead>;
76
+ /** True when these bytes cannot be shown as text: a NUL, or not valid UTF-8. */
77
+ export declare function isBinary(bytes: Uint8Array): boolean;
78
+ /** The text with every unsafe character shown as `\u{hex}`, and how many there were. The bytes are not changed by `--raw` or `--out`. */
79
+ export declare function escapeForTerminal(text: string): {
80
+ text: string;
81
+ escaped: number;
82
+ };