@skrr-ai/cli 0.1.94 → 0.1.95

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 (120) hide show
  1. package/README.md +153 -165
  2. package/bin/run.js +32 -0
  3. package/bin/update-npm-runner.cjs +33 -0
  4. package/bin/update-session.cjs +194 -0
  5. package/bin/update-worker.cjs +208 -0
  6. package/dist/base-command.js +0 -15
  7. package/dist/commands/code/doctor.d.ts +1 -0
  8. package/dist/commands/code/doctor.js +6 -0
  9. package/dist/commands/code/index.js +4 -0
  10. package/dist/commands/code/install.d.ts +5 -62
  11. package/dist/commands/code/install.js +86 -279
  12. package/dist/commands/code/rollback.d.ts +8 -0
  13. package/dist/commands/code/rollback.js +20 -0
  14. package/dist/commands/code/update.d.ts +8 -37
  15. package/dist/commands/code/update.js +134 -213
  16. package/dist/commands/daemon/install.js +4 -0
  17. package/dist/commands/generate-recovery-code.d.ts +13 -1
  18. package/dist/commands/generate-recovery-code.js +146 -13
  19. package/dist/commands/instructions/guide.d.ts +20 -0
  20. package/dist/commands/instructions/guide.js +84 -0
  21. package/dist/commands/instructions/install.js +57 -33
  22. package/dist/commands/instructions/setup.d.ts +14 -0
  23. package/dist/commands/instructions/setup.js +72 -0
  24. package/dist/commands/integrations/execute.js +1 -1
  25. package/dist/commands/login.d.ts +5 -6
  26. package/dist/commands/login.js +27 -11
  27. package/dist/commands/logout.js +7 -7
  28. package/dist/commands/security/overview.d.ts +11 -0
  29. package/dist/commands/security/overview.js +158 -0
  30. package/dist/commands/spaces/claim.d.ts +12 -0
  31. package/dist/commands/spaces/claim.js +42 -0
  32. package/dist/commands/spaces/ownership.d.ts +12 -0
  33. package/dist/commands/spaces/ownership.js +46 -0
  34. package/dist/commands/tasks/cancel-cascade.js +1 -1
  35. package/dist/commands/tasks/create-tree.d.ts +5 -1
  36. package/dist/commands/tasks/create-tree.js +35 -7
  37. package/dist/commands/tasks/interrupt.js +2 -2
  38. package/dist/commands/tasks/pause-schedule.js +1 -1
  39. package/dist/commands/token/list.d.ts +3 -5
  40. package/dist/commands/token/list.js +99 -57
  41. package/dist/commands/update.d.ts +14 -0
  42. package/dist/commands/update.js +61 -0
  43. package/dist/generated/managed-instruction-guides.json +9 -0
  44. package/dist/hooks/init.d.ts +5 -0
  45. package/dist/hooks/init.js +27 -0
  46. package/dist/lib/commitments.d.ts +0 -8
  47. package/dist/lib/commitments.js +0 -52
  48. package/dist/lib/daemon-installer.d.ts +2 -0
  49. package/dist/lib/daemon-installer.js +100 -24
  50. package/dist/lib/first-party-harness-doctor.js +31 -1
  51. package/dist/lib/first-party-harness-remote-install.d.ts +71 -0
  52. package/dist/lib/first-party-harness-remote-install.js +310 -0
  53. package/dist/lib/first-party-harness-remote-update.d.ts +46 -0
  54. package/dist/lib/first-party-harness-remote-update.js +242 -0
  55. package/dist/lib/first-party-harness-startup-update.d.ts +26 -0
  56. package/dist/lib/first-party-harness-startup-update.js +166 -0
  57. package/dist/lib/first-party-harness-update.d.ts +46 -0
  58. package/dist/lib/first-party-harness-update.js +289 -0
  59. package/dist/lib/first-party-harness.js +7 -4
  60. package/dist/lib/managed-instruction-local.d.ts +12 -0
  61. package/dist/lib/managed-instruction-local.js +58 -0
  62. package/dist/lib/managed-instruction-setup.d.ts +35 -0
  63. package/dist/lib/managed-instruction-setup.js +306 -0
  64. package/dist/lib/memory-sync.d.ts +1 -0
  65. package/dist/lib/memory-sync.js +279 -68
  66. package/dist/lib/platform-update-local.d.ts +2 -0
  67. package/dist/lib/platform-update-local.js +113 -0
  68. package/dist/lib/platform-update.d.ts +39 -0
  69. package/dist/lib/platform-update.js +84 -0
  70. package/dist/lib/profile-machine-identity-guard.d.ts +2 -0
  71. package/dist/lib/profile-machine-identity-guard.js +13 -0
  72. package/dist/lib/prompt.d.ts +1 -0
  73. package/dist/lib/prompt.js +4 -3
  74. package/dist/lib/task-batch.d.ts +9 -0
  75. package/dist/lib/task-batch.js +94 -17
  76. package/dist/lib/task-instruction-offer.d.ts +1 -4
  77. package/dist/lib/task-instruction-offer.js +3 -129
  78. package/dist/lib/update-check.d.ts +61 -53
  79. package/dist/lib/update-check.js +453 -314
  80. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessChannels.d.ts +3 -4
  81. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessChannels.js +3 -4
  82. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessReleaseKeys.d.ts +82 -0
  83. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessReleaseKeys.js +105 -0
  84. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessUpdater.d.ts +110 -0
  85. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessUpdater.js +945 -0
  86. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessPermissionControls.d.ts +32 -0
  87. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessPermissionControls.js +62 -0
  88. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +2 -0
  89. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +4 -1
  90. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/machineUuid.js +35 -5
  91. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/releasePolicy.d.ts +63 -0
  92. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/releasePolicy.js +169 -0
  93. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/releaseVersions.d.ts +2 -0
  94. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/releaseVersions.js +44 -0
  95. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessChannels.d.ts +3 -4
  96. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessChannels.js +3 -4
  97. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessReleaseKeys.d.ts +82 -0
  98. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessReleaseKeys.js +102 -0
  99. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessUpdater.d.ts +110 -0
  100. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessUpdater.js +923 -0
  101. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessPermissionControls.d.ts +32 -0
  102. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessPermissionControls.js +59 -0
  103. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +2 -0
  104. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +2 -0
  105. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/machineUuid.js +35 -5
  106. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/releasePolicy.d.ts +63 -0
  107. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/releasePolicy.js +163 -0
  108. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/releaseVersions.d.ts +2 -0
  109. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/releaseVersions.js +41 -0
  110. package/dist/node_modules/@skrr-ai/auth-core/package.json +31 -1
  111. package/dist/node_modules/@skrr-ai/data-provider/index.js +6584 -6567
  112. package/docs/v1/README.md +28 -0
  113. package/docs/v1/api.md +55 -0
  114. package/docs/v1/changelog.md +16 -0
  115. package/docs/v1/check-examples.mjs +178 -0
  116. package/docs/v1/examples/api-readonly.mjs +144 -0
  117. package/docs/v1/operations.md +87 -0
  118. package/docs/v1/quickstart.md +71 -0
  119. package/oclif.manifest.json +46007 -45462
  120. package/package.json +13 -11
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const auth_core_1 = require("@skrr-ai/auth-core");
5
+ const base_command_1 = require("../base-command");
6
+ const api_fetch_1 = require("./api-fetch");
7
+ const daemon_target_1 = require("./daemon-target");
8
+ const first_party_harness_1 = require("./first-party-harness");
9
+ /**
10
+ * `skrr code install` — install the engine from the terminal.
11
+ *
12
+ * ── Why this command exists ────────────────────────────────────────────────
13
+ *
14
+ * `skrr code`'s not-installed message offered exactly two routes and neither
15
+ * worked without a browser: "In the web app: the runtime menu … → Install", or
16
+ * point the engine-path override at a build you already have — which is the thing
17
+ * you are trying to obtain, and the route that gives up provenance. So the
18
+ * ordinary case for a coding harness (a dev box over SSH, a CI runner, a cloud
19
+ * VM) had no way in (dogfood OSK-276).
20
+ *
21
+ * Nothing underneath was missing. The daemon has performed the verified install
22
+ * since 2026-08-08, and `POST /api/daemons/:id/cli-installers/:provider/install`
23
+ * has fronted it since June. The install was API-exposed and CLI-unreachable —
24
+ * the shape the root `CLAUDE.md` names under CLI ↔ API parity: "an endpoint the
25
+ * API exposes must be reachable from `skrr`."
26
+ *
27
+ * So this adds a SURFACE and no mechanism. Same route the web app posts, same
28
+ * daemon job, same signature verification. A second install path would be a
29
+ * second thing to keep in step with the first, and the first is the one that
30
+ * verifies the signed manifest.
31
+ */
32
+ class CodeInstall extends base_command_1.BaseCommand {
33
+ static description = `Install the ${auth_core_1.FIRST_PARTY_HARNESS.displayName} engine on this machine, through the daemon`;
34
+ static examples = [
35
+ '<%= config.bin %> code install',
36
+ '<%= config.bin %> code install --daemon <daemon-id>',
37
+ '<%= config.bin %> code install --json',
38
+ ];
39
+ static flags = {
40
+ daemon: core_1.Flags.string({
41
+ description: 'Which daemon installs it. Defaults to this machine on a Dedicated Runtime, otherwise to the only active one; required when you have several.',
42
+ }),
43
+ wait: core_1.Flags.boolean({
44
+ default: true,
45
+ allowNo: true,
46
+ description: 'Follow the install job until it finishes. --no-wait returns the job id.',
47
+ }),
48
+ json: core_1.Flags.boolean({ description: 'Emit the result as JSON' }),
49
+ };
50
+ async run() {
51
+ const { flags } = await this.parse(CodeInstall);
52
+ const daemonId = this.installTarget(await this.resolveTarget(flags.daemon));
53
+ let started;
54
+ try {
55
+ started = await (0, api_fetch_1.apiFetch)(`/api/daemons/${encodeURIComponent(daemonId)}/cli-installers/${PROVIDER}/install`, { method: 'POST', body: {}, credential: this.resolvedCredential });
56
+ }
57
+ catch (err) {
58
+ this.handleApiError(err);
59
+ }
60
+ // The daemon distinguishes three refusals, and only one of them attaches a
61
+ // job worth following:
62
+ //
63
+ // - `alreadyInstalled` carries the LAST job the provider ran — context, not
64
+ // this request's work. Following it replays a stale outcome as though it
65
+ // had just happened: `code install` on an engine one release behind
66
+ // reprinted the previous update's log tail verbatim and reported that job
67
+ // as its result (OSK-10650). The right answer is the daemon's own
68
+ // installDisabledReason plus where the update actually comes from.
69
+ // - `alreadyRunning` carries the LIVE job — following it attaches the user
70
+ // to work that is really in flight, which is what they asked for.
71
+ // - `started` carries the job this request began.
72
+ if (started.alreadyInstalled) {
73
+ if (flags.json) {
74
+ this.log(JSON.stringify({ daemonId, ...started }, null, 2));
75
+ return;
76
+ }
77
+ const state = started.provider;
78
+ const reason = state?.installDisabledReason?.trim();
79
+ const version = state?.version?.trim();
80
+ this.log(`Nothing to do on ${daemonId} — ${reason || 'Already installed.'}${version ? ` (${version})` : ''}`);
81
+ if (state?.updatable === true) {
82
+ this.log(`To update it: ${this.config.bin} code update`);
83
+ }
84
+ else {
85
+ const why = state?.updateDisabledReason?.trim();
86
+ if (why)
87
+ this.log(`Updating: ${why}`);
88
+ }
89
+ return;
90
+ }
91
+ const jobId = started.job?.id;
92
+ // A 202 carrying NO job is not a queued install. It is the daemon
93
+ // acknowledging the call and returning nothing, and the route builds its
94
+ // body as `{ daemonId, ...result }` — so an empty result and a real one look
95
+ // identical from here. Dogfooded (OSK-287): this printed "Install requested"
96
+ // and exited 0 against a daemon that answered an unrelated RPC in 83ms and
97
+ // then installed nothing for 130 seconds. Reporting success for an empty
98
+ // acknowledgement is what let that reach a user as silence.
99
+ if (!jobId) {
100
+ if (flags.json) {
101
+ this.log(JSON.stringify({ daemonId, ...started }, null, 2));
102
+ return;
103
+ }
104
+ // A no-op is not a failure. The daemon says WHY it started nothing, and
105
+ // the commonest reason is the happy one — the engine is already there.
106
+ //
107
+ // This branch used to treat every job-less response as "nothing has been
108
+ // shown to start", which was right while the control-RPC relay dropped
109
+ // every reply (OSK-287) and wrong the moment it was fixed: with real
110
+ // payloads flowing, running `code install` twice would have reported a
111
+ // problem for the ordinary case of already having the engine. That is the
112
+ // same defect this dogfood run kept finding in other people's error copy —
113
+ // a message asserting a cause it has not observed — so it does not get to
114
+ // survive in mine.
115
+ const reason = await this.installerNote(daemonId);
116
+ if (reason) {
117
+ this.log(`Nothing to do on ${daemonId} — ${reason}`);
118
+ return;
119
+ }
120
+ this.failWithCliError({
121
+ message: `The daemon on ${daemonId} accepted the request and returned no ` +
122
+ 'install job, and does not say why. Nothing has been shown to start. ' +
123
+ `Check what it offers with \`${this.config.bin} harnesses installers --daemon ${daemonId}\`, and ` +
124
+ `\`${this.config.bin} code doctor\` here once you expect it to have landed.`,
125
+ code: 'INSTALL_NOT_TRACKED',
126
+ exit: 1,
127
+ // Retryable: the daemon is reachable and the call was accepted, so the
128
+ // same command may well work once whatever swallowed it is understood.
129
+ retryable: true,
130
+ });
131
+ }
132
+ if (!flags.wait) {
133
+ if (flags.json) {
134
+ this.log(JSON.stringify({ daemonId, ...started }, null, 2));
135
+ return;
136
+ }
137
+ this.log(`Install started on ${daemonId} — job ${jobId}.`);
138
+ return;
139
+ }
140
+ const job = await this.followJob(daemonId, jobId, flags.json === true);
141
+ if (flags.json) {
142
+ this.log(JSON.stringify({ daemonId, job }, null, 2));
143
+ }
144
+ if (job.status === 'failed') {
145
+ // The daemon's own message, verbatim. It carries the failure CODE
146
+ // (`runSignedInstall` puts it there deliberately) because "the feed is
147
+ // down" and "the signature did not verify" need very different responses.
148
+ this.failWithCliError({
149
+ message: job.error || 'The install failed and the daemon gave no reason.',
150
+ code: 'INSTALL_FAILED',
151
+ exit: 1,
152
+ retryable: false,
153
+ });
154
+ }
155
+ if (!flags.json) {
156
+ this.log(`${auth_core_1.FIRST_PARTY_HARNESS.displayName} installed. Run \`${this.config.bin} code\` to start it.`);
157
+ }
158
+ }
159
+ /** Which daemon the install targets, by the rule every daemon-picking command shares. */
160
+ async resolveTarget(explicit) {
161
+ try {
162
+ return await (0, daemon_target_1.resolveDaemonTarget)({
163
+ explicit,
164
+ local: (0, daemon_target_1.localMachine)({ baseURL: this.cliConfig?.baseURL }),
165
+ listActiveDaemons: () => (0, daemon_target_1.listConnectedDaemons)(this.resolvedCredential),
166
+ });
167
+ }
168
+ catch (err) {
169
+ this.handleApiError(err);
170
+ }
171
+ }
172
+ /**
173
+ * The daemon id to install through, or the refusal.
174
+ *
175
+ * Refuses rather than guessing when several are active. Picking one would mean
176
+ * installing a hundred megabytes onto a machine the user was not thinking
177
+ * about. The candidates are CONNECTED daemons by the id the installer routes
178
+ * take (`listConnectedDaemons`), so the error names values that work — the
179
+ * Daemon resource list `skrr list-daemons` prints is a different id space
180
+ * (OSK-9993).
181
+ *
182
+ * A Dedicated Runtime's own machine is refused here, before any request. The
183
+ * daemon and the API refuse it too; saying so locally is what keeps the answer
184
+ * the same whether or not this machine's daemon is reachable, and whether or
185
+ * not it has published its id. Another of the owner's machines, named with
186
+ * `--daemon`, is not this machine and goes to the API like anywhere else.
187
+ */
188
+ installTarget(target) {
189
+ if (target.kind === 'daemon')
190
+ return target.daemonId;
191
+ if (target.kind === 'this-machine') {
192
+ this.failWithCliError({
193
+ message: target.explicit
194
+ ? first_party_harness_1.DEDICATED_RUNTIME_ENGINE_MESSAGE
195
+ : `${first_party_harness_1.DEDICATED_RUNTIME_ENGINE_MESSAGE} This command installs on the machine it runs on; ` +
196
+ 'to install on another of your machines, name it with --daemon.',
197
+ code: 'DEDICATED_RUNTIME_ENGINE_SHIPS_WITH_IMAGE',
198
+ exit: 1,
199
+ retryable: false,
200
+ });
201
+ }
202
+ if (target.kind === 'none') {
203
+ this.failWithCliError({
204
+ message: 'No daemon is connected for this account, so nothing can perform the install. ' +
205
+ `Start the background service on this computer with \`${this.config.bin} daemon start\`, then run this again.`,
206
+ code: 'NO_DAEMON',
207
+ exit: 1,
208
+ retryable: false,
209
+ });
210
+ }
211
+ const { daemons } = target;
212
+ const choices = daemons
213
+ .slice(0, 10)
214
+ .map((d) => ` ${d.id} ${d.name || '—'}`)
215
+ .join('\n');
216
+ this.failWithCliError({
217
+ message: `${daemons.length} connected daemons — say which machine should install the engine:\n${choices}\n` +
218
+ `Pass one with --daemon, or see each daemon id in the DAEMON ID column of \`${this.config.bin} harnesses list\`.`,
219
+ code: 'AMBIGUOUS_DAEMON',
220
+ exit: 1,
221
+ retryable: false,
222
+ });
223
+ }
224
+ /**
225
+ * What the daemon says about this provider, when it started no job.
226
+ *
227
+ * Read from the SAME list route the web app uses, so the CLI reports the
228
+ * daemon's own words rather than inventing an explanation for silence. Best
229
+ * effort: a failure here means falling back to the honest "does not say why",
230
+ * never to a guess.
231
+ */
232
+ async installerNote(daemonId) {
233
+ try {
234
+ const res = await (0, api_fetch_1.apiFetch)(`/api/daemons/${encodeURIComponent(daemonId)}/cli-installers`, { credential: this.resolvedCredential });
235
+ // Any accepted spelling: a daemon lists the provider the way it registered it,
236
+ // and during a rename's alias window one that predates or postdates the flip
237
+ // spells it differently.
238
+ const row = (res.providers ?? []).find((p) => (0, auth_core_1.isFirstPartyHarnessProvider)(p.provider));
239
+ const reason = row?.installDisabledReason?.trim();
240
+ if (!reason)
241
+ return null;
242
+ // The version is what turns "Already installed." into something a reader
243
+ // can act on — it is the difference between reassurance and a shrug.
244
+ return row?.version ? `${reason} (${row.version})` : reason;
245
+ }
246
+ catch {
247
+ return null;
248
+ }
249
+ }
250
+ /**
251
+ * Poll the job until it settles, printing each new log line.
252
+ *
253
+ * The daemon already writes a progress log — "Fetching the signed release
254
+ * manifest", "Verified and installed …" — and it is the only account
255
+ * of a hundred-megabyte download the user is waiting on. Printing only the
256
+ * lines not yet seen keeps a poll loop from repeating the whole log.
257
+ */
258
+ async followJob(daemonId, jobId, quiet) {
259
+ const deadline = Date.now() + MAX_WAIT_MS;
260
+ let printed = 0;
261
+ for (;;) {
262
+ let res;
263
+ try {
264
+ res = await (0, api_fetch_1.apiFetch)(`/api/daemons/${encodeURIComponent(daemonId)}/cli-installers/jobs/${encodeURIComponent(jobId)}`, { credential: this.resolvedCredential });
265
+ }
266
+ catch (err) {
267
+ this.handleApiError(err);
268
+ }
269
+ const job = res.job;
270
+ if (!job) {
271
+ this.failWithCliError({
272
+ message: `The daemon no longer has install job ${jobId}.`,
273
+ code: 'JOB_MISSING',
274
+ exit: 1,
275
+ retryable: false,
276
+ });
277
+ }
278
+ if (!quiet) {
279
+ for (const line of (job.log ?? []).slice(printed))
280
+ this.logToStderr(` ${line}`);
281
+ printed = (job.log ?? []).length;
282
+ }
283
+ if (job.status === 'succeeded' || job.status === 'failed')
284
+ return job;
285
+ if (Date.now() > deadline) {
286
+ // NOT a failure: the daemon is still working, and saying "install
287
+ // failed" because this process ran out of patience would be a lie that
288
+ // sends someone to debug a download that is going fine.
289
+ this.failWithCliError({
290
+ message: `Still installing after ${Math.round(MAX_WAIT_MS / 60000)} minutes — the daemon is ` +
291
+ `still working on job ${jobId}. Check \`${this.config.bin} code doctor\` in a while.`,
292
+ code: 'INSTALL_PENDING',
293
+ exit: 1,
294
+ retryable: true,
295
+ });
296
+ }
297
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
298
+ }
299
+ }
300
+ }
301
+ exports.default = CodeInstall;
302
+ /**
303
+ * The daemon's id for skrr's own engine — the CANONICAL spelling, read from the
304
+ * identity module rather than written here. The install route accepts every
305
+ * spelling; canonical is what the platform stores and returns.
306
+ */
307
+ const PROVIDER = auth_core_1.FIRST_PARTY_HARNESS.provider;
308
+ /** A 100 MB download over a hotel connection is the case this has to survive. */
309
+ const MAX_WAIT_MS = 10 * 60_000;
310
+ const POLL_INTERVAL_MS = 2_000;
@@ -0,0 +1,46 @@
1
+ import { BaseCommand } from '../base-command';
2
+ /**
3
+ * `skrr code update` — pull the engine's signed release down through the daemon.
4
+ *
5
+ * ── Why this command exists ────────────────────────────────────────────────
6
+ *
7
+ * The update verb has been API-exposed and daemon-implemented since OSK-10096 —
8
+ * `POST /api/daemons/:id/cli-installers/:provider/update` re-fetches the signed
9
+ * manifest and installs whatever the channel points at. But the only CLI that
10
+ * reached it was `skrr harnesses install <provider> --update`: a flag on a
11
+ * command a `code` user has no reason to read. On stable that left no
12
+ * discoverable path at all — `code install` answered "Already installed." with
13
+ * no next step, and the channel moving past the installed build was invisible
14
+ * from the surface that owns the engine (OSK-10650).
15
+ *
16
+ * So this adds a SURFACE and no mechanism. Same route `harnesses install
17
+ * --update` posts, same inventory pre-check, same 504 recovery — one update
18
+ * path, spelled where the engine's users look.
19
+ */
20
+ export default class CodeUpdate extends BaseCommand {
21
+ static description: string;
22
+ static examples: string[];
23
+ static flags: {
24
+ daemon: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
25
+ wait: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ };
28
+ run(): Promise<void>;
29
+ /** Which daemon the update targets, by the rule every daemon-picking command shares. */
30
+ private resolveTarget;
31
+ /**
32
+ * The daemon id to update through, or the refusal — identical rules to
33
+ * `code install`: a Dedicated Runtime's own machine is image-managed, several
34
+ * connected daemons get named rather than guessed.
35
+ */
36
+ private updateTarget;
37
+ /**
38
+ * Start the update, and survive a gateway that cut the request off — the same
39
+ * 504 recovery `harnesses install --update` uses: the relay can drop the
40
+ * answer while the daemon runs the job it started, so on a server-side
41
+ * failure we ask the daemon and follow the job it reports.
42
+ */
43
+ private start;
44
+ /** Follow a job to its end, or report why it could not be followed (and return nothing). */
45
+ private follow;
46
+ }
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const auth_core_1 = require("@skrr-ai/auth-core");
5
+ const base_command_1 = require("../base-command");
6
+ const cli_installers_1 = require("./cli-installers");
7
+ const daemon_target_1 = require("./daemon-target");
8
+ const first_party_harness_1 = require("./first-party-harness");
9
+ /**
10
+ * `skrr code update` — pull the engine's signed release down through the daemon.
11
+ *
12
+ * ── Why this command exists ────────────────────────────────────────────────
13
+ *
14
+ * The update verb has been API-exposed and daemon-implemented since OSK-10096 —
15
+ * `POST /api/daemons/:id/cli-installers/:provider/update` re-fetches the signed
16
+ * manifest and installs whatever the channel points at. But the only CLI that
17
+ * reached it was `skrr harnesses install <provider> --update`: a flag on a
18
+ * command a `code` user has no reason to read. On stable that left no
19
+ * discoverable path at all — `code install` answered "Already installed." with
20
+ * no next step, and the channel moving past the installed build was invisible
21
+ * from the surface that owns the engine (OSK-10650).
22
+ *
23
+ * So this adds a SURFACE and no mechanism. Same route `harnesses install
24
+ * --update` posts, same inventory pre-check, same 504 recovery — one update
25
+ * path, spelled where the engine's users look.
26
+ */
27
+ class CodeUpdate extends base_command_1.BaseCommand {
28
+ static description = `Update the ${auth_core_1.FIRST_PARTY_HARNESS.displayName} engine on this machine, through the daemon`;
29
+ static examples = [
30
+ '<%= config.bin %> code update',
31
+ '<%= config.bin %> code update --daemon <daemon-id>',
32
+ '<%= config.bin %> code update --json',
33
+ ];
34
+ static flags = {
35
+ daemon: core_1.Flags.string({
36
+ description: 'Which daemon runs the update. Defaults to this machine on a Dedicated Runtime, otherwise to the only active one; required when you have several.',
37
+ }),
38
+ wait: core_1.Flags.boolean({
39
+ default: true,
40
+ allowNo: true,
41
+ description: 'Follow the update job until it finishes. --no-wait returns the job id.',
42
+ }),
43
+ json: core_1.Flags.boolean({ description: 'Emit the result as JSON' }),
44
+ };
45
+ async run() {
46
+ const { flags } = await this.parse(CodeUpdate);
47
+ const daemonId = this.updateTarget(await this.resolveTarget(flags.daemon));
48
+ // Ask the inventory before posting: a daemon older than managed updates has
49
+ // no handler for the request and would leave it to time out, and an engine
50
+ // that updates some other way has a reason the daemon already words.
51
+ let inventory;
52
+ try {
53
+ inventory = await (0, cli_installers_1.listCliInstallers)(daemonId, this.resolvedCredential);
54
+ }
55
+ catch (err) {
56
+ this.handleApiError(err);
57
+ }
58
+ const row = (inventory.providers ?? []).find((p) => (0, auth_core_1.isFirstPartyHarnessProvider)(p.provider));
59
+ if (!row) {
60
+ this.failWithCliError({
61
+ message: `${auth_core_1.FIRST_PARTY_HARNESS.displayName} is not installed on ${daemonId}. ` +
62
+ `Install it with \`${this.config.bin} code install\`.`,
63
+ code: 'NOT_INSTALLED',
64
+ exit: 1,
65
+ retryable: false,
66
+ });
67
+ }
68
+ if (row.updatable === undefined) {
69
+ this.failWithCliError({
70
+ message: `The daemon ${daemonId} (${inventory.daemonVersion ?? 'version not reported'}) cannot update ${auth_core_1.FIRST_PARTY_HARNESS.displayName}: it predates managed updates. ` +
71
+ `Update the daemon, then run this again.`,
72
+ code: 'DAEMON_UPDATE_UNSUPPORTED',
73
+ exit: 1,
74
+ retryable: false,
75
+ });
76
+ }
77
+ if (!row.updatable) {
78
+ this.failWithCliError({
79
+ message: row.updateDisabledReason?.trim() ||
80
+ `${auth_core_1.FIRST_PARTY_HARNESS.displayName}: the daemon cannot update it here.`,
81
+ code: 'CLI_NOT_UPDATABLE',
82
+ exit: 1,
83
+ retryable: false,
84
+ });
85
+ }
86
+ const start = await this.start(daemonId, flags.json === true);
87
+ if (!start)
88
+ return;
89
+ const jobId = start.job?.id;
90
+ if (!start.started || !jobId) {
91
+ if (flags.json) {
92
+ this.log(JSON.stringify({ daemonId, ...start }, null, 2));
93
+ return;
94
+ }
95
+ this.log(start.alreadyRunning
96
+ ? `${auth_core_1.FIRST_PARTY_HARNESS.displayName}: an install or update is already running (job ${start.job?.id ?? 'unknown'}).`
97
+ : `${auth_core_1.FIRST_PARTY_HARNESS.displayName}: ${start.provider?.updateDisabledReason?.trim() || 'the daemon started no update job.'}`);
98
+ return;
99
+ }
100
+ if (!flags.wait) {
101
+ if (flags.json) {
102
+ this.log(JSON.stringify({ daemonId, ...start }, null, 2));
103
+ return;
104
+ }
105
+ this.log(`Update started on ${daemonId} — job ${jobId}.`);
106
+ return;
107
+ }
108
+ if (!flags.json) {
109
+ this.logToStderr(`Updating ${auth_core_1.FIRST_PARTY_HARNESS.displayName} ${row.version ? `${row.version} ` : ''}on ${daemonId}…`);
110
+ }
111
+ const job = await this.follow(daemonId, jobId, flags.json === true);
112
+ if (!job)
113
+ return;
114
+ if (flags.json) {
115
+ this.log(JSON.stringify({ daemonId, job }, null, 2));
116
+ if (job.status !== 'succeeded')
117
+ process.exitCode = 1;
118
+ return;
119
+ }
120
+ if (job.status === 'failed') {
121
+ this.failWithCliError({
122
+ message: job.error || 'The update failed and the daemon gave no reason.',
123
+ code: 'UPDATE_FAILED',
124
+ exit: 1,
125
+ retryable: false,
126
+ });
127
+ }
128
+ this.log((0, cli_installers_1.updateOutcomeLine)(job) ??
129
+ `${auth_core_1.FIRST_PARTY_HARNESS.displayName} updated${job.installedVersion ? ` to ${job.installedVersion}` : ''}.`);
130
+ }
131
+ /** Which daemon the update targets, by the rule every daemon-picking command shares. */
132
+ async resolveTarget(explicit) {
133
+ try {
134
+ return await (0, daemon_target_1.resolveDaemonTarget)({
135
+ explicit,
136
+ local: (0, daemon_target_1.localMachine)({ baseURL: this.cliConfig?.baseURL }),
137
+ listActiveDaemons: () => (0, daemon_target_1.listConnectedDaemons)(this.resolvedCredential),
138
+ });
139
+ }
140
+ catch (err) {
141
+ this.handleApiError(err);
142
+ }
143
+ }
144
+ /**
145
+ * The daemon id to update through, or the refusal — identical rules to
146
+ * `code install`: a Dedicated Runtime's own machine is image-managed, several
147
+ * connected daemons get named rather than guessed.
148
+ */
149
+ updateTarget(target) {
150
+ if (target.kind === 'daemon')
151
+ return target.daemonId;
152
+ if (target.kind === 'this-machine') {
153
+ this.failWithCliError({
154
+ message: target.explicit
155
+ ? first_party_harness_1.DEDICATED_RUNTIME_ENGINE_MESSAGE
156
+ : `${first_party_harness_1.DEDICATED_RUNTIME_ENGINE_MESSAGE} This command updates the machine it runs on; ` +
157
+ 'to update another of your machines, name it with --daemon.',
158
+ code: 'DEDICATED_RUNTIME_ENGINE_SHIPS_WITH_IMAGE',
159
+ exit: 1,
160
+ retryable: false,
161
+ });
162
+ }
163
+ if (target.kind === 'none') {
164
+ this.failWithCliError({
165
+ message: 'No daemon is connected for this account, so nothing can perform the update. ' +
166
+ `Start the background service on this computer with \`${this.config.bin} daemon start\`, then run this again.`,
167
+ code: 'NO_DAEMON',
168
+ exit: 1,
169
+ retryable: false,
170
+ });
171
+ }
172
+ const { daemons } = target;
173
+ const choices = daemons
174
+ .slice(0, 10)
175
+ .map((d) => ` ${d.id} ${d.name || '—'}`)
176
+ .join('\n');
177
+ this.failWithCliError({
178
+ message: `${daemons.length} connected daemons — say which machine should update the engine:\n${choices}\n` +
179
+ `Pass one with --daemon, or see each daemon id in the DAEMON ID column of \`${this.config.bin} harnesses list\`.`,
180
+ code: 'AMBIGUOUS_DAEMON',
181
+ exit: 1,
182
+ retryable: false,
183
+ });
184
+ }
185
+ /**
186
+ * Start the update, and survive a gateway that cut the request off — the same
187
+ * 504 recovery `harnesses install --update` uses: the relay can drop the
188
+ * answer while the daemon runs the job it started, so on a server-side
189
+ * failure we ask the daemon and follow the job it reports.
190
+ */
191
+ async start(daemonId, json) {
192
+ try {
193
+ return await (0, cli_installers_1.startManagedCliUpdate)(daemonId, PROVIDER, this.resolvedCredential);
194
+ }
195
+ catch (err) {
196
+ const status = err.status ?? 0;
197
+ if (status >= 500 || status === 408) {
198
+ const job = await (0, cli_installers_1.jobStartedDespiteTimeout)(daemonId, PROVIDER, this.resolvedCredential);
199
+ if (job?.id) {
200
+ if (!json) {
201
+ this.logToStderr(`The request to ${daemonId} did not come back (HTTP ${status}), but the daemon started job ${job.id}. Following it.`);
202
+ }
203
+ return { started: true, job };
204
+ }
205
+ }
206
+ this.handleApiError(err);
207
+ return undefined;
208
+ }
209
+ }
210
+ /** Follow a job to its end, or report why it could not be followed (and return nothing). */
211
+ async follow(daemonId, jobId, json) {
212
+ const outcome = await (0, cli_installers_1.followManagedCliInstallJob)({
213
+ daemonId,
214
+ jobId,
215
+ credential: this.resolvedCredential,
216
+ onLogLine: json ? undefined : (line) => this.logToStderr(` ${line}`),
217
+ });
218
+ if (outcome.kind === 'missing') {
219
+ this.failWithCliError({
220
+ message: `The daemon no longer has update job ${jobId}.`,
221
+ code: 'JOB_MISSING',
222
+ exit: 1,
223
+ retryable: false,
224
+ });
225
+ return undefined;
226
+ }
227
+ if (outcome.kind === 'timeout') {
228
+ this.failWithCliError({
229
+ message: `Still updating after ${Math.round(cli_installers_1.INSTALL_MAX_WAIT_MS / 60000)} minutes — the daemon is ` +
230
+ `still working on job ${jobId}. Check \`${this.config.bin} code doctor\` in a while.`,
231
+ code: 'UPDATE_PENDING',
232
+ exit: 1,
233
+ retryable: true,
234
+ });
235
+ return undefined;
236
+ }
237
+ return outcome.job;
238
+ }
239
+ }
240
+ exports.default = CodeUpdate;
241
+ /** Same canonical provider id `code install` posts — read from the identity module. */
242
+ const PROVIDER = auth_core_1.FIRST_PARTY_HARNESS.provider;
@@ -0,0 +1,26 @@
1
+ import { checkLocalCodeUpdate, updateLocalCode, type LocalCodeUpdateStatus } from './first-party-harness-update';
2
+ export type CodeUpdateChoice = 'update' | 'once' | 'version' | 'disable';
3
+ export declare function configureCodeStartupChecks(enabled: boolean, env?: NodeJS.ProcessEnv): {
4
+ enabled: boolean;
5
+ preferencesPath: string;
6
+ };
7
+ export declare function shouldCheckCodeAtStartup(input: {
8
+ argv: string[];
9
+ env?: NodeJS.ProcessEnv;
10
+ stdinTTY?: boolean;
11
+ stdoutTTY?: boolean;
12
+ stderrTTY?: boolean;
13
+ }): boolean;
14
+ export declare function ttyCodeUpdateAsker(): (result: LocalCodeUpdateStatus) => Promise<CodeUpdateChoice>;
15
+ /** The only caller is a new interactive TUI launch, before any broker or lease. */
16
+ export declare function maybeOfferCodeUpdate(input: {
17
+ argv: string[];
18
+ env?: NodeJS.ProcessEnv;
19
+ say: (line: string) => void;
20
+ stdinTTY?: boolean;
21
+ stdoutTTY?: boolean;
22
+ stderrTTY?: boolean;
23
+ ask?: (result: LocalCodeUpdateStatus) => Promise<CodeUpdateChoice>;
24
+ check?: typeof checkLocalCodeUpdate;
25
+ update?: typeof updateLocalCode;
26
+ }): Promise<void>;