dsh-version-manager 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +232 -2
- package/cordis.patch.yml +12 -0
- package/docs/baseline.md +224 -0
- package/lib/client.js +2365 -0
- package/lib/host/compat.js +303 -0
- package/lib/host/git-routes.js +376 -0
- package/lib/host/git-skill.js +1133 -0
- package/lib/host/inventory.js +228 -0
- package/lib/host/locate.js +169 -0
- package/lib/host/lockfile.js +124 -0
- package/lib/host/operations.js +185 -0
- package/lib/host/routes.js +1332 -0
- package/lib/host/skill-restore.js +346 -0
- package/lib/host/skills.js +327 -0
- package/lib/host/snapshot-store.js +335 -0
- package/lib/host/spec.js +274 -0
- package/lib/index.js +49 -0
- package/package.json +60 -4
|
@@ -0,0 +1,1332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON surface the panel talks to.
|
|
3
|
+
*
|
|
4
|
+
* Every route is read-only unless its name says otherwise, and the two write
|
|
5
|
+
* routes (`snapshot`, `update`) demand an explicit `{ confirm: true }` body in
|
|
6
|
+
* addition to passing the host's own admission check. There is no timer here and
|
|
7
|
+
* no work starts on its own: a refresh is a request, and a change is a request,
|
|
8
|
+
* which keeps the plugin's cost equal to what the user asked for.
|
|
9
|
+
*
|
|
10
|
+
* Admission comes from `connection.admit(req)`, the same check the host applies
|
|
11
|
+
* to its own browser traffic. When that service is absent the route refuses
|
|
12
|
+
* rather than falling back to "it is localhost so it is fine" — a local port is
|
|
13
|
+
* shared by every process on the machine.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-version-manager/lib/host/routes
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { readFile } from 'node:fs/promises'
|
|
19
|
+
import { join } from 'node:path'
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
buildPluginRows,
|
|
23
|
+
readLoaderPhases,
|
|
24
|
+
readProfileManifest,
|
|
25
|
+
} from './inventory.js'
|
|
26
|
+
import { evaluateCompatibility, manifestVersion } from './compat.js'
|
|
27
|
+
import { hostInfo, readInstalledManifest } from './locate.js'
|
|
28
|
+
import { registryFor } from './lockfile.js'
|
|
29
|
+
import { readRegistry } from './git-skill.js'
|
|
30
|
+
import {
|
|
31
|
+
listGitSkills,
|
|
32
|
+
previewGitRoute,
|
|
33
|
+
registerGitRoute,
|
|
34
|
+
restoreGitRoute,
|
|
35
|
+
unregisterGitRoute,
|
|
36
|
+
updateGitRoute,
|
|
37
|
+
} from './git-routes.js'
|
|
38
|
+
import { listSkillSnapshots, readSkills, snapshotSkill } from './skills.js'
|
|
39
|
+
import { previewSkillRestore, restoreSkillSnapshot, skillRestoreRefusal } from './skill-restore.js'
|
|
40
|
+
import { TERMINAL, beginOperation, listOperations, transition, unresolved } from './operations.js'
|
|
41
|
+
import {
|
|
42
|
+
deleteSnapshot,
|
|
43
|
+
fingerprintTree,
|
|
44
|
+
listSnapshots,
|
|
45
|
+
recoveryVerdict,
|
|
46
|
+
snapshotsBeyondRetention,
|
|
47
|
+
writeSnapshot,
|
|
48
|
+
} from './snapshot-store.js'
|
|
49
|
+
import { classifySpec, declaredSpecMatches, isPrerelease, updateRefusal } from './spec.js'
|
|
50
|
+
|
|
51
|
+
/** Every route this plugin publishes, so the panel and the tests share one list. */
|
|
52
|
+
export const ROUTE_BASE = '/dsh-version-manager'
|
|
53
|
+
|
|
54
|
+
/** Bodies are tiny here; anything larger is not a request this plugin serves. */
|
|
55
|
+
const MAX_BODY = 64 * 1024
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Send JSON and never let a rejected promise silence the response.
|
|
59
|
+
*
|
|
60
|
+
* @param {import('node:http').ServerResponse} response
|
|
61
|
+
* @param {number} status
|
|
62
|
+
* @param {unknown} body
|
|
63
|
+
*/
|
|
64
|
+
export function sendJson(response, status, body) {
|
|
65
|
+
const text = JSON.stringify(body)
|
|
66
|
+
response.writeHead(status, {
|
|
67
|
+
'content-type': 'application/json; charset=utf-8',
|
|
68
|
+
// A version panel that answers with a cached body describes a machine state
|
|
69
|
+
// that may no longer exist, and every row shows its own `observedAt`.
|
|
70
|
+
'cache-control': 'no-store',
|
|
71
|
+
})
|
|
72
|
+
response.end(text)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Read a JSON body, bounded.
|
|
77
|
+
*
|
|
78
|
+
* @param {import('node:http').IncomingMessage} request
|
|
79
|
+
* @returns {Promise<{ ok: true, value: any } | { ok: false, status: number, message: string }>}
|
|
80
|
+
*/
|
|
81
|
+
export async function readJsonBody(request) {
|
|
82
|
+
const chunks = []
|
|
83
|
+
let size = 0
|
|
84
|
+
try {
|
|
85
|
+
for await (const chunk of request) {
|
|
86
|
+
size += chunk.length
|
|
87
|
+
if (size > MAX_BODY) return { ok: false, status: 413, message: 'request body too large' }
|
|
88
|
+
chunks.push(chunk)
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
return { ok: false, status: 400, message: 'request body could not be read' }
|
|
92
|
+
}
|
|
93
|
+
if (size === 0) return { ok: true, value: {} }
|
|
94
|
+
try {
|
|
95
|
+
return { ok: true, value: JSON.parse(Buffer.concat(chunks).toString('utf8')) }
|
|
96
|
+
} catch {
|
|
97
|
+
return { ok: false, status: 400, message: 'request body was not JSON' }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Is this request allowed to run anything at all?
|
|
103
|
+
*
|
|
104
|
+
* @param {any} ctx
|
|
105
|
+
* @param {import('node:http').IncomingMessage} request
|
|
106
|
+
* @returns {{ ok: true, principal: string } | { ok: false, status: number }}
|
|
107
|
+
*/
|
|
108
|
+
export function admit(ctx, request) {
|
|
109
|
+
const connection = ctx?.get?.('connection')
|
|
110
|
+
if (connection === undefined || connection === null || typeof connection.admit !== 'function') {
|
|
111
|
+
// No admission service means no way to tell the browser from any other local
|
|
112
|
+
// process. Refusing is the only answer that does not invent a security model.
|
|
113
|
+
return { ok: false, status: 401 }
|
|
114
|
+
}
|
|
115
|
+
let admission
|
|
116
|
+
try {
|
|
117
|
+
admission = connection.admit(request)
|
|
118
|
+
} catch {
|
|
119
|
+
return { ok: false, status: 401 }
|
|
120
|
+
}
|
|
121
|
+
if (admission === null || typeof admission !== 'object') return { ok: false, status: 401 }
|
|
122
|
+
if ('rejection' in admission) return { ok: false, status: admission.rejection }
|
|
123
|
+
const kind = admission.peer?.principal?.kind
|
|
124
|
+
if (kind !== 'owner') return { ok: false, status: 403 }
|
|
125
|
+
return { ok: true, principal: kind }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Everything the panel needs to draw the first screen.
|
|
130
|
+
*
|
|
131
|
+
* @param {any} ctx
|
|
132
|
+
* @returns {Promise<Object>}
|
|
133
|
+
*/
|
|
134
|
+
export async function buildOverview(ctx) {
|
|
135
|
+
const profile = readProfileContext(ctx)
|
|
136
|
+
const pluginManager = ctx?.get?.('pluginManager')
|
|
137
|
+
|
|
138
|
+
let bundles = []
|
|
139
|
+
let inventoryError = null
|
|
140
|
+
if (pluginManager === undefined || pluginManager === null) {
|
|
141
|
+
inventoryError = 'The plugin manager service is not available in this host.'
|
|
142
|
+
} else {
|
|
143
|
+
try {
|
|
144
|
+
bundles = await pluginManager.listBundles()
|
|
145
|
+
} catch (error) {
|
|
146
|
+
inventoryError = error instanceof Error ? error.message : String(error)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const phases = await readLoaderPhases(ctx)
|
|
151
|
+
const manifest = await readManifest(profile.dir)
|
|
152
|
+
const lock = await readLockfile(profile.dir)
|
|
153
|
+
const { runtimeVersion, runtimeSource } = readRuntime(ctx)
|
|
154
|
+
const exemptions = await readExemptions(profile.dir)
|
|
155
|
+
const hostRoot = hostInfo().root
|
|
156
|
+
|
|
157
|
+
const rows = buildPluginRows({
|
|
158
|
+
bundles: Array.isArray(bundles) ? bundles : [],
|
|
159
|
+
phases: phases.byName,
|
|
160
|
+
phaseAvailable: phases.available,
|
|
161
|
+
phaseDiagnostic: phases.diagnostic,
|
|
162
|
+
profileId: profile.id,
|
|
163
|
+
runtimeVersion,
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
for (const row of rows) {
|
|
167
|
+
// A registry is stored per install, not per profile: an explicit `--registry`
|
|
168
|
+
// lands in the lockfile as an https tarball, and an ordinary install leaves
|
|
169
|
+
// the host unrecorded. Both answers are shown, and "unknown" keeps its reason.
|
|
170
|
+
const fromLock = registryFor({
|
|
171
|
+
name: row.targetId,
|
|
172
|
+
lockText: lock.text,
|
|
173
|
+
lockfileReadable: lock.readable,
|
|
174
|
+
declaredSpec: row.declaredSpec,
|
|
175
|
+
})
|
|
176
|
+
row.source.registry = fromLock.registry
|
|
177
|
+
row.source.registryReason = fromLock.reason
|
|
178
|
+
|
|
179
|
+
// The profile manifest stores the bare range ("1.7.3", "^0.4.0"), while the
|
|
180
|
+
// host reports the install spec ("name@range"). Compare the range half so a
|
|
181
|
+
// matching pair is not reported as a drift. A profile with no manifest is
|
|
182
|
+
// normal right after it is created, and it must degrade to "nothing recorded"
|
|
183
|
+
// rather than take the whole overview down with it.
|
|
184
|
+
const declared = manifest?.dependencies?.[row.targetId]
|
|
185
|
+
row.declaredSpecObserved = typeof declared === 'string' ? declared : null
|
|
186
|
+
row.declaredSpecMatchesManifest = declaredSpecMatches(
|
|
187
|
+
row.declaredSpec,
|
|
188
|
+
row.declaredSpecObserved,
|
|
189
|
+
row.targetId,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
// Compatibility is evaluated from the installed manifest the same way the
|
|
193
|
+
// host evaluates it before loading a bundle. Without a manifest the answer
|
|
194
|
+
// is "unknown", never "fine".
|
|
195
|
+
const installed = readInstalledManifest(row.targetId, { profileDir: profile.dir, hostRoot })
|
|
196
|
+
row.compatibility = evaluateCompatibility({
|
|
197
|
+
manifest: installed,
|
|
198
|
+
runtimeVersion,
|
|
199
|
+
exemptions,
|
|
200
|
+
packageVersion: manifestVersion(installed) ?? row.installedVersion ?? null,
|
|
201
|
+
exemptionKey: `${row.targetId}@${manifestVersion(installed) ?? row.installedVersion ?? ''}`,
|
|
202
|
+
})
|
|
203
|
+
row.compatibility.detail = typeof row.loadError === 'string' ? row.loadError : null
|
|
204
|
+
|
|
205
|
+
row.snapshots = (await listSnapshots(profile.home, profile.id, row.targetId)).map(summarise)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const operations = await listOperations(profile.home, profile.id, 30)
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
schemaVersion: 1,
|
|
212
|
+
observedAt: new Date().toISOString(),
|
|
213
|
+
profile: {
|
|
214
|
+
id: profile.id,
|
|
215
|
+
// A directory is a local fact. The panel shows it; a shared report does not.
|
|
216
|
+
dir: profile.dir ?? null,
|
|
217
|
+
home: profile.home ?? null,
|
|
218
|
+
kind: profile.kind,
|
|
219
|
+
identitySource: profile.identitySource,
|
|
220
|
+
},
|
|
221
|
+
host: {
|
|
222
|
+
runtimeVersion,
|
|
223
|
+
runtimeSource,
|
|
224
|
+
node: process.versions?.node ?? null,
|
|
225
|
+
platform: process.platform,
|
|
226
|
+
pluginManager: pluginManager !== undefined && pluginManager !== null,
|
|
227
|
+
loader: phases.available,
|
|
228
|
+
},
|
|
229
|
+
counts: {
|
|
230
|
+
total: rows.length,
|
|
231
|
+
updatable: rows.filter((row) => row.updateRefusal === null).length,
|
|
232
|
+
official: rows.filter((row) => row.official).length,
|
|
233
|
+
// Three useful totals: what can be updated, what the host would refuse to
|
|
234
|
+
// load, and what this plugin could not evaluate.
|
|
235
|
+
unsatisfied: rows.filter((row) => row.compatibility?.verdict === 'unsatisfied').length,
|
|
236
|
+
unknownCompatibility: rows.filter((row) => row.compatibility?.verdict === 'unknown').length,
|
|
237
|
+
},
|
|
238
|
+
plugins: rows,
|
|
239
|
+
operations: operations.map(summariseOperation),
|
|
240
|
+
unresolved: unresolved(operations).map((record) => record.id),
|
|
241
|
+
error: inventoryError,
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @param {object} row
|
|
247
|
+
* @returns {object}
|
|
248
|
+
*/
|
|
249
|
+
function summarise(row) {
|
|
250
|
+
return {
|
|
251
|
+
seq: row.seq,
|
|
252
|
+
id: row.id,
|
|
253
|
+
takenAt: row.takenAt,
|
|
254
|
+
reason: row.reason,
|
|
255
|
+
installedVersion: row.installedVersion,
|
|
256
|
+
file: row.file,
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @param {object} record
|
|
262
|
+
* @returns {object}
|
|
263
|
+
*/
|
|
264
|
+
function summariseOperation(record) {
|
|
265
|
+
return {
|
|
266
|
+
id: record.id,
|
|
267
|
+
startedAt: record.startedAt,
|
|
268
|
+
state: record.state,
|
|
269
|
+
targetId: record.target?.targetId ?? null,
|
|
270
|
+
fromVersion: record.target?.fromVersion ?? null,
|
|
271
|
+
toVersion: record.target?.toVersion ?? null,
|
|
272
|
+
snapshotId: record.snapshotId ?? null,
|
|
273
|
+
error: record.error ?? null,
|
|
274
|
+
terminal: TERMINAL.includes(record.state),
|
|
275
|
+
transitions: record.transitions ?? [],
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Read the profile identity from the host, and say where each part came from.
|
|
281
|
+
*
|
|
282
|
+
* A profile whose identity cannot be established is not a profile this plugin
|
|
283
|
+
* will write into: snapshots are keyed by it, so a guessed key would put two
|
|
284
|
+
* different profiles' history in one place.
|
|
285
|
+
*
|
|
286
|
+
* @param {any} ctx
|
|
287
|
+
* @returns {{ id: string, dir: string | null, home: string | null, kind: string, identitySource: string }}
|
|
288
|
+
*/
|
|
289
|
+
export function readProfileContext(ctx) {
|
|
290
|
+
const profile = ctx?.get?.('profileContext')
|
|
291
|
+
const name = profile?.name
|
|
292
|
+
const home = profile?.home ?? process.env.DSH_HOME ?? null
|
|
293
|
+
const cwd = typeof profile?.cwd === 'string' ? profile.cwd : null
|
|
294
|
+
if (typeof name === 'string' && name !== '') {
|
|
295
|
+
return {
|
|
296
|
+
id: name,
|
|
297
|
+
dir: typeof profile?.dir === 'string' ? profile.dir : null,
|
|
298
|
+
home,
|
|
299
|
+
cwd,
|
|
300
|
+
kind: 'dsh-profile',
|
|
301
|
+
identitySource: 'profileContext',
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
id: 'unknown',
|
|
306
|
+
dir: null,
|
|
307
|
+
home,
|
|
308
|
+
cwd,
|
|
309
|
+
kind: 'unknown',
|
|
310
|
+
identitySource: 'no profileContext service',
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Read the host's runtime version, or admit that it is not readable.
|
|
316
|
+
*
|
|
317
|
+
* `pluginContext`-independent: the version DSH writes into compatibility checks
|
|
318
|
+
* belongs to the app-boot package, and importing it here would tie this plugin to
|
|
319
|
+
* a peer that a newer host may move. The panel therefore reports what it could
|
|
320
|
+
* observe and marks the rest unknown.
|
|
321
|
+
*
|
|
322
|
+
* @param {any} ctx
|
|
323
|
+
* @returns {{ runtimeVersion: string | null }}
|
|
324
|
+
*/
|
|
325
|
+
export function readRuntime(ctx) {
|
|
326
|
+
const fromHost = ctx?.get?.('dshRuntimeVersion')
|
|
327
|
+
if (typeof fromHost === 'string' && fromHost !== '') {
|
|
328
|
+
return { runtimeVersion: fromHost, runtimeSource: 'host service' }
|
|
329
|
+
}
|
|
330
|
+
const env = process.env.DSH_VERSION
|
|
331
|
+
if (typeof env === 'string' && env !== '') {
|
|
332
|
+
return { runtimeVersion: env, runtimeSource: 'DSH_VERSION' }
|
|
333
|
+
}
|
|
334
|
+
// The host does not expose its own version as a service, but the package that
|
|
335
|
+
// owns the compatibility rule is on disk next to the running process. Reading
|
|
336
|
+
// its manifest is the same number the host compares against, so this is an
|
|
337
|
+
// observation rather than a guess.
|
|
338
|
+
const located = hostInfo()
|
|
339
|
+
if (located.runtimeVersion !== null) {
|
|
340
|
+
return { runtimeVersion: located.runtimeVersion, runtimeSource: located.source }
|
|
341
|
+
}
|
|
342
|
+
return { runtimeVersion: null, runtimeSource: null }
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Read the profile's exact-version exemptions.
|
|
347
|
+
*
|
|
348
|
+
* The file is written by `dsh plugin allow-version` and lives at the profile
|
|
349
|
+
* root. A malformed or absent file means "no exemptions", which only ever makes
|
|
350
|
+
* the panel stricter, never looser.
|
|
351
|
+
*
|
|
352
|
+
* @param {string | null} dir
|
|
353
|
+
* @returns {Promise<Record<string, string[]>>}
|
|
354
|
+
*/
|
|
355
|
+
async function readExemptions(dir) {
|
|
356
|
+
if (dir === null) return {}
|
|
357
|
+
try {
|
|
358
|
+
const parsed = JSON.parse(await readFile(join(dir, 'compatibility.json'), 'utf8'))
|
|
359
|
+
if (parsed === null || typeof parsed !== 'object') return {}
|
|
360
|
+
/** @type {Record<string, string[]>} */
|
|
361
|
+
const out = {}
|
|
362
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
363
|
+
if (Array.isArray(value)) out[key] = value.filter((item) => typeof item === 'string')
|
|
364
|
+
}
|
|
365
|
+
return out
|
|
366
|
+
} catch {
|
|
367
|
+
return {}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @param {string | null} dir
|
|
373
|
+
* @returns {Promise<object | null>}
|
|
374
|
+
*/
|
|
375
|
+
async function readManifest(dir) {
|
|
376
|
+
if (dir === null) return null
|
|
377
|
+
try {
|
|
378
|
+
return JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'))
|
|
379
|
+
} catch {
|
|
380
|
+
return null
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @param {string | null} dir
|
|
386
|
+
* @returns {Promise<{ text: string | null, readable: boolean }>}
|
|
387
|
+
*/
|
|
388
|
+
async function readLockfile(dir) {
|
|
389
|
+
if (dir === null) return { text: null, readable: false }
|
|
390
|
+
for (const file of ['pnpm-lock.yaml', 'pnpm-lock.yml', 'package-lock.json']) {
|
|
391
|
+
try {
|
|
392
|
+
return { text: await readFile(join(dir, file), 'utf8'), readable: true }
|
|
393
|
+
} catch {
|
|
394
|
+
// Try the next lockfile format. A profile may have none at all.
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return { text: null, readable: false }
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Versions newer than the installed one, with the facts needed to decide.
|
|
402
|
+
*
|
|
403
|
+
* Prereleases are separated rather than filtered away: a user who is already on
|
|
404
|
+
* a prerelease must see their own channel, and a user on a stable release must
|
|
405
|
+
* not be pushed onto one by default.
|
|
406
|
+
*
|
|
407
|
+
* @param {any} ctx
|
|
408
|
+
* @param {string} name
|
|
409
|
+
* @param {{ registry?: string }} options
|
|
410
|
+
* @returns {Promise<object>}
|
|
411
|
+
*/
|
|
412
|
+
export async function readVersions(ctx, name, options = {}) {
|
|
413
|
+
const profile = readProfileContext(ctx)
|
|
414
|
+
const pluginManager = ctx?.get?.('pluginManager')
|
|
415
|
+
if (pluginManager === undefined || pluginManager === null) {
|
|
416
|
+
return { status: 'unavailable', reason: 'no-plugin-manager', versions: [] }
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
let bundles = []
|
|
420
|
+
try {
|
|
421
|
+
bundles = await pluginManager.listBundles()
|
|
422
|
+
} catch (error) {
|
|
423
|
+
return { status: 'unavailable', reason: 'inventory-failed', message: messageOf(error), versions: [] }
|
|
424
|
+
}
|
|
425
|
+
const row = bundles.find((bundle) => bundle.name === name)
|
|
426
|
+
if (row === undefined) {
|
|
427
|
+
return { status: 'unknown-target', reason: 'not-in-profile', versions: [] }
|
|
428
|
+
}
|
|
429
|
+
const parsed = classifySpec(row.source, { official: row.official })
|
|
430
|
+
const refusal = updateRefusal(row, parsed)
|
|
431
|
+
if (refusal !== null) {
|
|
432
|
+
return {
|
|
433
|
+
status: 'read_only',
|
|
434
|
+
reason: 'update-not-offered',
|
|
435
|
+
message: refusal,
|
|
436
|
+
versions: [],
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let result
|
|
441
|
+
try {
|
|
442
|
+
result = await pluginManager.listVersions(name, options.registry === undefined ? undefined : { registry: options.registry })
|
|
443
|
+
} catch (error) {
|
|
444
|
+
return { status: 'error', reason: 'list-failed', message: messageOf(error), versions: [] }
|
|
445
|
+
}
|
|
446
|
+
if (result === null || typeof result !== 'object') {
|
|
447
|
+
return { status: 'error', reason: 'bad-response', versions: [] }
|
|
448
|
+
}
|
|
449
|
+
if (result.status === 'refused') {
|
|
450
|
+
return {
|
|
451
|
+
status: 'read_only',
|
|
452
|
+
reason: result.problem ?? 'refused',
|
|
453
|
+
message: typeof result.reason === 'string' ? result.reason : null,
|
|
454
|
+
versions: [],
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const versions = Array.isArray(result.versions) ? result.versions : []
|
|
459
|
+
const stable = []
|
|
460
|
+
const prerelease = []
|
|
461
|
+
for (const entry of versions) {
|
|
462
|
+
const item = {
|
|
463
|
+
version: typeof entry.version === 'string' ? entry.version : null,
|
|
464
|
+
publishedAt: entry.publishedAt ?? null,
|
|
465
|
+
deprecated: entry.deprecated ?? null,
|
|
466
|
+
isBundle: entry.bundle === true,
|
|
467
|
+
compatibility: entry.compatibility ?? null,
|
|
468
|
+
prerelease: isPrerelease(entry.version),
|
|
469
|
+
}
|
|
470
|
+
if (item.version === null) continue
|
|
471
|
+
if (item.prerelease) prerelease.push(item)
|
|
472
|
+
else stable.push(item)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
status: 'ok',
|
|
477
|
+
observedAt: new Date().toISOString(),
|
|
478
|
+
profileId: profile.id,
|
|
479
|
+
installed: typeof row.version === 'string' ? row.version : null,
|
|
480
|
+
registry: result.registry ?? null,
|
|
481
|
+
attempts: result.attempts ?? [],
|
|
482
|
+
omitted: result.omitted ?? 0,
|
|
483
|
+
stable,
|
|
484
|
+
prerelease,
|
|
485
|
+
versions: [...stable, ...prerelease],
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* @param {unknown} error
|
|
491
|
+
* @returns {string}
|
|
492
|
+
*/
|
|
493
|
+
function messageOf(error) {
|
|
494
|
+
if (error instanceof Error) return error.message
|
|
495
|
+
return String(error)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Take a snapshot of one installed target.
|
|
500
|
+
*
|
|
501
|
+
* @param {any} ctx
|
|
502
|
+
* @param {{ targetId: string, reason?: string }} body
|
|
503
|
+
* @returns {Promise<{ status: number, body: object }>}
|
|
504
|
+
*/
|
|
505
|
+
/**
|
|
506
|
+
* Copy one skill directory into the snapshot store.
|
|
507
|
+
*
|
|
508
|
+
* The skill is located through the host's own catalog rather than from a path
|
|
509
|
+
* in the request, so a crafted body cannot point this at an arbitrary folder.
|
|
510
|
+
*/
|
|
511
|
+
export async function takeSkillSnapshot(ctx, body) {
|
|
512
|
+
const profile = readProfileContext(ctx)
|
|
513
|
+
if (profile.home === null || profile.id === 'unknown') {
|
|
514
|
+
return { status: 409, body: { error: 'profile-identity-unknown' } }
|
|
515
|
+
}
|
|
516
|
+
const name = typeof body.name === 'string' ? body.name : ''
|
|
517
|
+
if (name === '') return { status: 400, body: { error: 'missing-name' } }
|
|
518
|
+
|
|
519
|
+
const catalog = await readSkills(ctx, { cwd: profile.cwd })
|
|
520
|
+
const skill = catalog.skills.find((entry) => entry.name === name)
|
|
521
|
+
if (skill === undefined) {
|
|
522
|
+
return {
|
|
523
|
+
status: 404,
|
|
524
|
+
body: {
|
|
525
|
+
error: 'unknown-skill',
|
|
526
|
+
message: catalog.available ? 'That skill is not in the host catalog.' : catalog.reason,
|
|
527
|
+
},
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (skill.directory === null) {
|
|
531
|
+
return {
|
|
532
|
+
status: 409,
|
|
533
|
+
body: {
|
|
534
|
+
error: 'no-directory',
|
|
535
|
+
message: 'This skill is a single file, so there is no directory to copy.',
|
|
536
|
+
},
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
const result = await snapshotSkill({
|
|
541
|
+
dshHome: profile.home,
|
|
542
|
+
profileId: profile.id,
|
|
543
|
+
name,
|
|
544
|
+
directory: skill.directory,
|
|
545
|
+
git: skill.git,
|
|
546
|
+
})
|
|
547
|
+
return {
|
|
548
|
+
status: 200,
|
|
549
|
+
body: {
|
|
550
|
+
ok: true,
|
|
551
|
+
snapshot: {
|
|
552
|
+
takenAt: result.manifest.takenAt,
|
|
553
|
+
digest: result.manifest.skill.digest,
|
|
554
|
+
fileCount: result.manifest.skill.fileCount,
|
|
555
|
+
revision: result.manifest.git?.revision ?? null,
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
}
|
|
559
|
+
} catch (error) {
|
|
560
|
+
return { status: 409, body: { error: 'snapshot-failed', message: messageOf(error) } }
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Resolve one skill from the host catalog, never from a path in the request.
|
|
566
|
+
*
|
|
567
|
+
* @param {any} ctx
|
|
568
|
+
* @param {string} name
|
|
569
|
+
* @returns {Promise<{ ok: true, profile: object, skill: object } | { ok: false, status: number, body: object }>}
|
|
570
|
+
*/
|
|
571
|
+
async function locateSkill(ctx, name) {
|
|
572
|
+
const profile = readProfileContext(ctx)
|
|
573
|
+
if (profile.home === null || profile.id === 'unknown') {
|
|
574
|
+
return { ok: false, status: 409, body: { error: 'profile-identity-unknown' } }
|
|
575
|
+
}
|
|
576
|
+
if (name === '') return { ok: false, status: 400, body: { error: 'missing-name' } }
|
|
577
|
+
const catalog = await readSkills(ctx, { cwd: profile.cwd })
|
|
578
|
+
const skill = catalog.skills.find((entry) => entry.name === name)
|
|
579
|
+
if (skill === undefined) {
|
|
580
|
+
return {
|
|
581
|
+
ok: false,
|
|
582
|
+
status: 404,
|
|
583
|
+
body: {
|
|
584
|
+
error: 'unknown-skill',
|
|
585
|
+
message: catalog.available ? 'That skill is not in the host catalog.' : catalog.reason,
|
|
586
|
+
},
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (skill.directory === null) {
|
|
590
|
+
return {
|
|
591
|
+
ok: false,
|
|
592
|
+
status: 409,
|
|
593
|
+
body: { error: 'no-directory', message: 'This skill is a single file, so there is no directory to restore.' },
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return { ok: true, profile, skill }
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Say what a restore would do, including every reason it would be refused.
|
|
601
|
+
*
|
|
602
|
+
* @param {any} ctx
|
|
603
|
+
* @param {string} name
|
|
604
|
+
* @param {string} file
|
|
605
|
+
* @returns {Promise<{ status: number, body: object }>}
|
|
606
|
+
*/
|
|
607
|
+
export async function previewSkillRestoreRoute(ctx, name, file) {
|
|
608
|
+
const located = await locateSkill(ctx, name)
|
|
609
|
+
if (!located.ok) return { status: located.status, body: located.body }
|
|
610
|
+
try {
|
|
611
|
+
const preview = await previewSkillRestore({
|
|
612
|
+
dshHome: located.profile.home,
|
|
613
|
+
profileId: located.profile.id,
|
|
614
|
+
name,
|
|
615
|
+
directory: located.skill.directory,
|
|
616
|
+
// The snapshot may exist, but a bundled skill is DSH's own file tree.
|
|
617
|
+
source: located.skill.source ?? null,
|
|
618
|
+
file,
|
|
619
|
+
})
|
|
620
|
+
return {
|
|
621
|
+
status: 200,
|
|
622
|
+
body: {
|
|
623
|
+
schemaVersion: 1,
|
|
624
|
+
ok: preview.ok,
|
|
625
|
+
reason: preview.reason,
|
|
626
|
+
detail: preview.detail,
|
|
627
|
+
skill: {
|
|
628
|
+
name,
|
|
629
|
+
directory: located.skill.directory,
|
|
630
|
+
source: located.skill.source ?? null,
|
|
631
|
+
restoreRefusal: skillRestoreRefusal(located.skill),
|
|
632
|
+
file,
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
}
|
|
636
|
+
} catch (error) {
|
|
637
|
+
return { status: 500, body: { error: 'preview-failed', message: messageOf(error) } }
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Replace one skill directory with the bytes a snapshot recorded.
|
|
643
|
+
*
|
|
644
|
+
* @param {any} ctx
|
|
645
|
+
* @param {{ name?: string, file?: string }} body
|
|
646
|
+
* @returns {Promise<{ status: number, body: object }>}
|
|
647
|
+
*/
|
|
648
|
+
export async function restoreSkillRoute(ctx, body) {
|
|
649
|
+
const name = typeof body.name === 'string' ? body.name : ''
|
|
650
|
+
const file = typeof body.file === 'string' ? body.file : ''
|
|
651
|
+
if (file === '') return { status: 400, body: { error: 'missing-file' } }
|
|
652
|
+
const located = await locateSkill(ctx, name)
|
|
653
|
+
if (!located.ok) return { status: located.status, body: located.body }
|
|
654
|
+
try {
|
|
655
|
+
const result = await restoreSkillSnapshot({
|
|
656
|
+
dshHome: located.profile.home,
|
|
657
|
+
profileId: located.profile.id,
|
|
658
|
+
name,
|
|
659
|
+
directory: located.skill.directory,
|
|
660
|
+
source: located.skill.source ?? null,
|
|
661
|
+
file,
|
|
662
|
+
})
|
|
663
|
+
if (!result.ok) {
|
|
664
|
+
// Every refusal is a 409: the request was understood, the state is what
|
|
665
|
+
// makes it unsafe.
|
|
666
|
+
return {
|
|
667
|
+
status: 409,
|
|
668
|
+
body: {
|
|
669
|
+
error: result.reason,
|
|
670
|
+
message: result.message,
|
|
671
|
+
evidence: result.evidence,
|
|
672
|
+
restoredTo: null,
|
|
673
|
+
undo: result.undo,
|
|
674
|
+
},
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
const after = await readSkills(ctx, { cwd: located.profile.cwd })
|
|
678
|
+
const current = after.skills.find((entry) => entry.name === name)
|
|
679
|
+
return {
|
|
680
|
+
status: 200,
|
|
681
|
+
body: {
|
|
682
|
+
ok: true,
|
|
683
|
+
restoredTo: result.restoredTo,
|
|
684
|
+
undo: result.undo,
|
|
685
|
+
evidence: result.evidence,
|
|
686
|
+
message: null,
|
|
687
|
+
note: 'This restores the skill directory only. It does not touch Git, and it does not restore anything outside that directory.',
|
|
688
|
+
current: current ?? null,
|
|
689
|
+
},
|
|
690
|
+
}
|
|
691
|
+
} catch (error) {
|
|
692
|
+
return { status: 500, body: { error: 'restore-failed', message: messageOf(error) } }
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
export async function takeSnapshot(ctx, body) {
|
|
697
|
+
const profile = readProfileContext(ctx)
|
|
698
|
+
if (profile.dir === null || profile.id === 'unknown') {
|
|
699
|
+
return { status: 409, body: { error: 'profile-identity-unknown' } }
|
|
700
|
+
}
|
|
701
|
+
const overview = await buildOverview(ctx)
|
|
702
|
+
const row = overview.plugins.find((entry) => entry.targetId === body.targetId)
|
|
703
|
+
if (row === undefined) return { status: 404, body: { error: 'unknown-target' } }
|
|
704
|
+
|
|
705
|
+
const directory = join(profile.dir, 'node_modules', row.targetId)
|
|
706
|
+
const fingerprint = await fingerprintTree(directory).catch(() => null)
|
|
707
|
+
if (fingerprint === null) {
|
|
708
|
+
return {
|
|
709
|
+
status: 409,
|
|
710
|
+
body: {
|
|
711
|
+
error: 'not-installed',
|
|
712
|
+
message: 'The package directory could not be read, so there is nothing to fingerprint.',
|
|
713
|
+
},
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
const document = await writeSnapshot({
|
|
717
|
+
dshHome: profile.home,
|
|
718
|
+
profileId: profile.id,
|
|
719
|
+
target: row,
|
|
720
|
+
fingerprint,
|
|
721
|
+
reason: typeof body.reason === 'string' ? body.reason : 'manual',
|
|
722
|
+
})
|
|
723
|
+
return {
|
|
724
|
+
status: 200,
|
|
725
|
+
body: {
|
|
726
|
+
ok: true,
|
|
727
|
+
snapshot: { id: document.id, seq: document.seq, takenAt: document.takenAt },
|
|
728
|
+
},
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Update one target to one version, recording every step.
|
|
734
|
+
*
|
|
735
|
+
* The order is: verify the target is still updatable, snapshot, verify the
|
|
736
|
+
* snapshot, mark applying, hand off to the host, then read the result back. The
|
|
737
|
+
* host is the only writer of the profile; this function never edits
|
|
738
|
+
* `package.json` itself.
|
|
739
|
+
*
|
|
740
|
+
* @param {any} ctx
|
|
741
|
+
* @param {{ targetId: string, toVersion: string, allowPrerelease?: boolean }} body
|
|
742
|
+
* @returns {Promise<{ status: number, body: object }>}
|
|
743
|
+
*/
|
|
744
|
+
export async function runUpdate(ctx, body) {
|
|
745
|
+
const profile = readProfileContext(ctx)
|
|
746
|
+
if (profile.dir === null || profile.id === 'unknown') {
|
|
747
|
+
return { status: 409, body: { error: 'profile-identity-unknown' } }
|
|
748
|
+
}
|
|
749
|
+
const pluginManager = ctx?.get?.('pluginManager')
|
|
750
|
+
if (pluginManager === undefined || pluginManager === null) {
|
|
751
|
+
return { status: 409, body: { error: 'no-plugin-manager' } }
|
|
752
|
+
}
|
|
753
|
+
const toVersion = body.toVersion
|
|
754
|
+
if (typeof toVersion !== 'string' || toVersion === '') {
|
|
755
|
+
return { status: 400, body: { error: 'missing-version' } }
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const overview = await buildOverview(ctx)
|
|
759
|
+
const row = overview.plugins.find((entry) => entry.targetId === body.targetId)
|
|
760
|
+
if (row === undefined) return { status: 404, body: { error: 'unknown-target' } }
|
|
761
|
+
if (row.updateRefusal !== null) {
|
|
762
|
+
return { status: 409, body: { error: 'not-updatable', message: row.updateRefusal } }
|
|
763
|
+
}
|
|
764
|
+
if (isPrerelease(toVersion) && body.allowPrerelease !== true) {
|
|
765
|
+
return {
|
|
766
|
+
status: 409,
|
|
767
|
+
body: {
|
|
768
|
+
error: 'prerelease-not-confirmed',
|
|
769
|
+
message: 'The target version is a prerelease and this request did not opt in.',
|
|
770
|
+
},
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (toVersion === row.installedVersion) {
|
|
774
|
+
return { status: 409, body: { error: 'already-at-version' } }
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
const directory = join(profile.dir, 'node_modules', row.targetId)
|
|
778
|
+
const fingerprint = await fingerprintTree(directory).catch(() => null)
|
|
779
|
+
const snapshot = await writeSnapshot({
|
|
780
|
+
dshHome: profile.home,
|
|
781
|
+
profileId: profile.id,
|
|
782
|
+
target: row,
|
|
783
|
+
fingerprint,
|
|
784
|
+
reason: `before update to ${toVersion}`,
|
|
785
|
+
})
|
|
786
|
+
|
|
787
|
+
// Verify the snapshot can be read back before anything is touched: a snapshot
|
|
788
|
+
// taken but unreadable is the same as no snapshot.
|
|
789
|
+
const written = await listSnapshots(profile.home, profile.id, row.targetId)
|
|
790
|
+
const verified = written.find((entry) => entry.id === snapshot.id)
|
|
791
|
+
if (verified === undefined) {
|
|
792
|
+
return { status: 500, body: { error: 'snapshot-not-verifiable', snapshotId: snapshot.id } }
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
const record = await beginOperation({
|
|
796
|
+
dshHome: profile.home,
|
|
797
|
+
profileId: profile.id,
|
|
798
|
+
target: row,
|
|
799
|
+
toVersion,
|
|
800
|
+
})
|
|
801
|
+
await transition(profile.home, profile.id, record, 'snapshot_verified', {
|
|
802
|
+
snapshotId: snapshot.id,
|
|
803
|
+
})
|
|
804
|
+
await transition(profile.home, profile.id, record, 'applying')
|
|
805
|
+
|
|
806
|
+
// The host owns every write to the profile. An update is its removal plus its
|
|
807
|
+
// installation; a failure between them is the host's `restore` path, not ours.
|
|
808
|
+
let result
|
|
809
|
+
try {
|
|
810
|
+
result = await pluginManager.updateBundle(row.targetId, toVersion, {})
|
|
811
|
+
} catch (error) {
|
|
812
|
+
await transition(profile.home, profile.id, record, 'failed', { error: messageOf(error) })
|
|
813
|
+
return {
|
|
814
|
+
status: 502,
|
|
815
|
+
body: { error: 'update-threw', message: messageOf(error), operationId: record.id, snapshotId: snapshot.id },
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
await transition(profile.home, profile.id, record, 'verifying')
|
|
820
|
+
const outcome = classifyUpdateResult(result)
|
|
821
|
+
const finalState = outcome.ok ? 'succeeded' : 'recovery_required'
|
|
822
|
+
await transition(profile.home, profile.id, record, finalState, {
|
|
823
|
+
error: outcome.message,
|
|
824
|
+
})
|
|
825
|
+
|
|
826
|
+
const after = await buildOverview(ctx)
|
|
827
|
+
const afterRow = after.plugins.find((entry) => entry.targetId === body.targetId)
|
|
828
|
+
|
|
829
|
+
return {
|
|
830
|
+
status: outcome.ok ? 200 : 502,
|
|
831
|
+
body: {
|
|
832
|
+
ok: outcome.ok,
|
|
833
|
+
operationId: record.id,
|
|
834
|
+
snapshotId: snapshot.id,
|
|
835
|
+
fromVersion: row.installedVersion,
|
|
836
|
+
toVersion,
|
|
837
|
+
observedVersion: afterRow?.installedVersion ?? null,
|
|
838
|
+
result,
|
|
839
|
+
message: outcome.message,
|
|
840
|
+
},
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Reinstall one exact version through the host.
|
|
847
|
+
*
|
|
848
|
+
* The host's installer refuses to install a package that is already present
|
|
849
|
+
* while hot module replacement is on ("already-installed"), because the loader
|
|
850
|
+
* still holds the running copy. Its own update path therefore removes first and
|
|
851
|
+
* installs second. A restore has the same shape: the package is present at the
|
|
852
|
+
* wrong version, and the only way back is to remove it and install the recorded
|
|
853
|
+
* version. Nothing here edits the profile; both steps go through the host's own
|
|
854
|
+
* manager so its manifest writer lock and logging still apply.
|
|
855
|
+
*
|
|
856
|
+
* @param {any} ctx
|
|
857
|
+
* @param {any} pluginManager
|
|
858
|
+
* @param {string} targetId
|
|
859
|
+
* @param {string} version
|
|
860
|
+
* @param {{ registry?: string }} options
|
|
861
|
+
* @returns {Promise<object>}
|
|
862
|
+
*/
|
|
863
|
+
async function reinstallVersion(ctx, pluginManager, targetId, version, options) {
|
|
864
|
+
const spec = `${targetId}@${version}`
|
|
865
|
+
const installOptions = {
|
|
866
|
+
saveExact: true,
|
|
867
|
+
registry: options.registry,
|
|
868
|
+
enabled: true,
|
|
869
|
+
}
|
|
870
|
+
const first = await pluginManager.installBundle(spec, installOptions)
|
|
871
|
+
if (!isAlreadyInstalled(first)) return first
|
|
872
|
+
if (typeof pluginManager.removeBundle !== 'function') {
|
|
873
|
+
throw new Error('The host cannot remove a bundle, so an already installed version cannot be replaced.')
|
|
874
|
+
}
|
|
875
|
+
await pluginManager.removeBundle(targetId)
|
|
876
|
+
return pluginManager.installBundle(spec, installOptions)
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Did the host refuse because the package was already present?
|
|
881
|
+
*
|
|
882
|
+
* The host reports this as a result body rather than as a thrown error:
|
|
883
|
+
* `result.result.error.code === 'already-installed'`. Both the nested and the
|
|
884
|
+
* hoisted shape are read, because the refusal is checked structurally and not
|
|
885
|
+
* by matching a message string.
|
|
886
|
+
*
|
|
887
|
+
* @param {unknown} result
|
|
888
|
+
* @returns {boolean}
|
|
889
|
+
*/
|
|
890
|
+
export function isAlreadyInstalled(result) {
|
|
891
|
+
if (result === null || typeof result !== 'object') return false
|
|
892
|
+
const levels = [result, result.result].filter((level) => level !== null && typeof level === 'object')
|
|
893
|
+
return levels.some((level) => level.error?.code === 'already-installed')
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Did the host's update actually change anything?
|
|
898
|
+
*
|
|
899
|
+
* `changed: false` is not a failure of the request — it is the host saying the
|
|
900
|
+
* application did not run. Reporting that as success would be the "claimed but
|
|
901
|
+
* never happened" bug this plugin exists to avoid.
|
|
902
|
+
*
|
|
903
|
+
* @param {unknown} result
|
|
904
|
+
* @returns {{ ok: boolean, message: string | null }}
|
|
905
|
+
*/
|
|
906
|
+
export function classifyUpdateResult(result) {
|
|
907
|
+
if (result === null || typeof result !== 'object') {
|
|
908
|
+
return { ok: false, message: 'The host returned no update result.' }
|
|
909
|
+
}
|
|
910
|
+
// The host nests the applied result one level down: { from, to, step,
|
|
911
|
+
// result: { stage, target, changed, application, ... } }. Both levels are
|
|
912
|
+
// read because a future host may hoist the flag, and neither level is
|
|
913
|
+
// invented when absent.
|
|
914
|
+
const inner = result.result !== null && typeof result.result === 'object' ? result.result : {}
|
|
915
|
+
const changed = result.changed === true || inner.changed === true
|
|
916
|
+
const application = result.application ?? inner.application ?? 'not-applied'
|
|
917
|
+
if (!changed) {
|
|
918
|
+
const detail = result.error?.message ?? inner.error?.message ?? result.diagnostic ?? inner.diagnostic ?? null
|
|
919
|
+
return {
|
|
920
|
+
ok: false,
|
|
921
|
+
message: detail === null ? `The host reported "${application}" without applying the update.` : String(detail),
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (application !== 'applied') {
|
|
925
|
+
return {
|
|
926
|
+
ok: false,
|
|
927
|
+
message: `The host changed files but reported application "${application}".`,
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return { ok: true, message: null }
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Restore a target from one snapshot.
|
|
935
|
+
*
|
|
936
|
+
* Only the version is restored, and only when the files still match the
|
|
937
|
+
* fingerprint taken before that change. Configuration, the dependency tree and
|
|
938
|
+
* agent presets are explicitly out of scope, and the reply says so.
|
|
939
|
+
*
|
|
940
|
+
* @param {any} ctx
|
|
941
|
+
* @param {{ targetId: string, snapshotId: string }} body
|
|
942
|
+
* @returns {Promise<{ status: number, body: object }>}
|
|
943
|
+
*/
|
|
944
|
+
export async function restoreSnapshot(ctx, body) {
|
|
945
|
+
const profile = readProfileContext(ctx)
|
|
946
|
+
if (profile.dir === null || profile.id === 'unknown') {
|
|
947
|
+
return { status: 409, body: { error: 'profile-identity-unknown' } }
|
|
948
|
+
}
|
|
949
|
+
const pluginManager = ctx?.get?.('pluginManager')
|
|
950
|
+
if (pluginManager === undefined || pluginManager === null) {
|
|
951
|
+
return { status: 409, body: { error: 'no-plugin-manager' } }
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
const rows = await listSnapshots(profile.home, profile.id, body.targetId)
|
|
955
|
+
const chosen = rows.find((entry) => entry.id === body.snapshotId)
|
|
956
|
+
if (chosen === undefined) return { status: 404, body: { error: 'unknown-snapshot' } }
|
|
957
|
+
|
|
958
|
+
const document = await readSnapshotDocument(profile.home, profile.id, body.targetId, chosen.file)
|
|
959
|
+
if (document === null) return { status: 409, body: { error: 'snapshot-unreadable' } }
|
|
960
|
+
|
|
961
|
+
const directory = join(profile.dir, 'node_modules', body.targetId)
|
|
962
|
+
const current = await fingerprintTree(directory).catch(() => null)
|
|
963
|
+
const verdict = recoveryVerdict(document, current)
|
|
964
|
+
|
|
965
|
+
if (!verdict.ok) {
|
|
966
|
+
return {
|
|
967
|
+
status: 409,
|
|
968
|
+
body: {
|
|
969
|
+
error: verdict.reason,
|
|
970
|
+
message: verdict.detail,
|
|
971
|
+
// Restoring is refused, and the reason names the exact condition that
|
|
972
|
+
// failed so the user can decide what to do instead of retrying blindly.
|
|
973
|
+
note: 'Version restore only; configuration, dependency tree and presets are not rolled back.',
|
|
974
|
+
},
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// What the fingerprint check actually proved, kept as evidence rather than
|
|
979
|
+
// folded into the verdict: "the files are not the ones this snapshot recorded"
|
|
980
|
+
// is the normal case right after an update, and it is worth showing.
|
|
981
|
+
const evidence = {
|
|
982
|
+
filesMatch: verdict.filesMatch,
|
|
983
|
+
recordedDigest: document.target.fingerprint?.digest ?? null,
|
|
984
|
+
currentDigest: current?.digest ?? null,
|
|
985
|
+
registry: document.target.source.registry ?? null,
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
const targetVersion = document.target.installedVersion
|
|
989
|
+
const overview = await buildOverview(ctx)
|
|
990
|
+
const row = overview.plugins.find((entry) => entry.targetId === body.targetId)
|
|
991
|
+
|
|
992
|
+
// Nothing to reinstall when the profile already carries that version. Saying
|
|
993
|
+
// "restored" here would claim an action that never ran; the reply says what
|
|
994
|
+
// is true instead, and keeps the fingerprint evidence because a version match
|
|
995
|
+
// does not prove the files are untouched.
|
|
996
|
+
if (row !== undefined && row.installedVersion === targetVersion) {
|
|
997
|
+
return {
|
|
998
|
+
status: 200,
|
|
999
|
+
body: {
|
|
1000
|
+
ok: true,
|
|
1001
|
+
alreadyAtVersion: true,
|
|
1002
|
+
restoredVersion: targetVersion,
|
|
1003
|
+
observedVersion: row.installedVersion,
|
|
1004
|
+
message: null,
|
|
1005
|
+
evidence,
|
|
1006
|
+
note: 'Version restore only; configuration, dependency tree and presets are not rolled back.',
|
|
1007
|
+
},
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
const record = await beginOperation({
|
|
1011
|
+
dshHome: profile.home,
|
|
1012
|
+
profileId: profile.id,
|
|
1013
|
+
target: row ?? { kind: 'plugin', targetId: body.targetId, installedVersion: current?.digest ?? null, declaredSpec: document.target.declaredSpec, source: { kind: 'registry' } },
|
|
1014
|
+
toVersion: targetVersion,
|
|
1015
|
+
})
|
|
1016
|
+
|
|
1017
|
+
// An update snapshots what it is about to replace, and a restore replaces a
|
|
1018
|
+
// version too. Without this, restoring is the only write in the plugin with no
|
|
1019
|
+
// way back: the moment it runs, the version you were on is unreachable. The
|
|
1020
|
+
// snapshot is taken before the swap and verified by reading it back, for the
|
|
1021
|
+
// same reason the update path verifies its own.
|
|
1022
|
+
const currentFingerprint = await fingerprintTree(directory).catch(() => null)
|
|
1023
|
+
const undo = await writeSnapshot({
|
|
1024
|
+
dshHome: profile.home,
|
|
1025
|
+
profileId: profile.id,
|
|
1026
|
+
// The row when the host still lists the target, otherwise what the snapshot
|
|
1027
|
+
// being restored recorded about it. Both carry the fields a later restore
|
|
1028
|
+
// reads back; neither invents a value the host did not report.
|
|
1029
|
+
target: row ?? {
|
|
1030
|
+
kind: 'plugin',
|
|
1031
|
+
targetId: body.targetId,
|
|
1032
|
+
declaredSpec: document.target.declaredSpec,
|
|
1033
|
+
installedVersion: document.target.installedVersion,
|
|
1034
|
+
source: document.target.source,
|
|
1035
|
+
enabledState: document.target.enabledState,
|
|
1036
|
+
compatibility: document.target.compatibility,
|
|
1037
|
+
},
|
|
1038
|
+
fingerprint: currentFingerprint,
|
|
1039
|
+
reason: `before restore to ${targetVersion}`,
|
|
1040
|
+
})
|
|
1041
|
+
const written = await listSnapshots(profile.home, profile.id, body.targetId)
|
|
1042
|
+
if (written.find((entry) => entry.id === undo.id) === undefined) {
|
|
1043
|
+
await transition(profile.home, profile.id, record, 'failed', { error: 'snapshot-not-verifiable' })
|
|
1044
|
+
return { status: 500, body: { error: 'snapshot-not-verifiable', snapshotId: undo.id, operationId: record.id } }
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
await transition(profile.home, profile.id, record, 'snapshot_verified', { snapshotId: undo.id })
|
|
1048
|
+
await transition(profile.home, profile.id, record, 'applying', {
|
|
1049
|
+
detail: 'restoring a recorded version',
|
|
1050
|
+
})
|
|
1051
|
+
|
|
1052
|
+
let result
|
|
1053
|
+
try {
|
|
1054
|
+
result = await reinstallVersion(ctx, pluginManager, body.targetId, targetVersion, {
|
|
1055
|
+
registry: document.target.source.registry ?? undefined,
|
|
1056
|
+
})
|
|
1057
|
+
} catch (error) {
|
|
1058
|
+
await transition(profile.home, profile.id, record, 'failed', { error: messageOf(error) })
|
|
1059
|
+
return { status: 502, body: { error: 'restore-threw', message: messageOf(error), operationId: record.id } }
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
await transition(profile.home, profile.id, record, 'verifying')
|
|
1063
|
+
// Same nesting as an update: the host reports the applied stage under
|
|
1064
|
+
// `result`. A restore that only *started* must not be reported as done.
|
|
1065
|
+
const outcome = classifyUpdateResult(result)
|
|
1066
|
+
const ok = outcome.ok
|
|
1067
|
+
await transition(profile.home, profile.id, record, ok ? 'succeeded' : 'recovery_required', {
|
|
1068
|
+
error: outcome.message,
|
|
1069
|
+
})
|
|
1070
|
+
|
|
1071
|
+
return {
|
|
1072
|
+
status: ok ? 200 : 502,
|
|
1073
|
+
body: {
|
|
1074
|
+
ok,
|
|
1075
|
+
operationId: record.id,
|
|
1076
|
+
restoredVersion: targetVersion,
|
|
1077
|
+
observedVersion: (await buildOverview(ctx)).plugins.find((entry) => entry.targetId === body.targetId)?.installedVersion ?? null,
|
|
1078
|
+
message: outcome.message,
|
|
1079
|
+
evidence,
|
|
1080
|
+
// The snapshot taken before the swap, so the version that was just
|
|
1081
|
+
// replaced can itself be restored.
|
|
1082
|
+
undo: { id: undo.id, seq: undo.seq, version: row?.installedVersion ?? null },
|
|
1083
|
+
result,
|
|
1084
|
+
note: 'Version restore only; configuration, dependency tree and presets are not rolled back.',
|
|
1085
|
+
},
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Read one stored snapshot document by its file name.
|
|
1091
|
+
*
|
|
1092
|
+
* @param {string} dshHome
|
|
1093
|
+
* @param {string} profileId
|
|
1094
|
+
* @param {string} targetId
|
|
1095
|
+
* @param {string} file
|
|
1096
|
+
* @returns {Promise<object | null>}
|
|
1097
|
+
*/
|
|
1098
|
+
async function readSnapshotDocument(dshHome, profileId, targetId, file) {
|
|
1099
|
+
if (typeof file !== 'string' || file.includes('/') || file.includes('\\') || file.includes('..')) {
|
|
1100
|
+
return null
|
|
1101
|
+
}
|
|
1102
|
+
const path = join(
|
|
1103
|
+
dshHome,
|
|
1104
|
+
'version-manager',
|
|
1105
|
+
'snapshots',
|
|
1106
|
+
String(profileId).replace(/\//g, '%2F'),
|
|
1107
|
+
String(targetId).replace(/\//g, '%2F'),
|
|
1108
|
+
file,
|
|
1109
|
+
)
|
|
1110
|
+
try {
|
|
1111
|
+
return JSON.parse(await readFile(path, 'utf8'))
|
|
1112
|
+
} catch {
|
|
1113
|
+
return null
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
export { snapshotsBeyondRetention, deleteSnapshot }
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Register every route on the host webserver.
|
|
1121
|
+
*
|
|
1122
|
+
* @param {any} ctx
|
|
1123
|
+
* @param {{ webServer: { register: (route: any) => () => void } }} scope
|
|
1124
|
+
* @returns {() => void[]} disposers
|
|
1125
|
+
*/
|
|
1126
|
+
export function registerRoutes(ctx, scope) {
|
|
1127
|
+
const { webServer } = scope
|
|
1128
|
+
const disposers = []
|
|
1129
|
+
const publish = (path, handler) => {
|
|
1130
|
+
const dispose = webServer.register({ kind: 'exact', path: `${ROUTE_BASE}${path}`, handler })
|
|
1131
|
+
disposers.push(dispose)
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/** @param {(request: any, response: any, body: any) => Promise<{status: number, body: unknown}>} run */
|
|
1135
|
+
const writeRoute = (path, run) => {
|
|
1136
|
+
publish(path, async (request, response) => {
|
|
1137
|
+
const allowed = admit(ctx, request)
|
|
1138
|
+
if (!allowed.ok) {
|
|
1139
|
+
sendJson(response, allowed.status, { error: allowed.status === 403 ? 'forbidden' : 'unauthorized' })
|
|
1140
|
+
return
|
|
1141
|
+
}
|
|
1142
|
+
if (request.method !== 'POST') {
|
|
1143
|
+
response.writeHead(405, { allow: 'POST' })
|
|
1144
|
+
response.end()
|
|
1145
|
+
return
|
|
1146
|
+
}
|
|
1147
|
+
const parsed = await readJsonBody(request)
|
|
1148
|
+
if (!parsed.ok) {
|
|
1149
|
+
sendJson(response, parsed.status, { error: parsed.message })
|
|
1150
|
+
return
|
|
1151
|
+
}
|
|
1152
|
+
if (parsed.value?.confirm !== true) {
|
|
1153
|
+
// The confirmation is per request. A UI that forgets to send it gets a
|
|
1154
|
+
// refusal, not a silent write.
|
|
1155
|
+
sendJson(response, 400, { error: 'confirm required' })
|
|
1156
|
+
return
|
|
1157
|
+
}
|
|
1158
|
+
try {
|
|
1159
|
+
const result = await run(request, response, parsed.value)
|
|
1160
|
+
sendJson(response, result.status, result.body)
|
|
1161
|
+
} catch (error) {
|
|
1162
|
+
// A thrown handler would be turned into a bare 400 by the host, losing
|
|
1163
|
+
// which step failed. Answering here keeps the reason.
|
|
1164
|
+
sendJson(response, 500, { error: 'handler-failed', message: messageOf(error) })
|
|
1165
|
+
}
|
|
1166
|
+
})
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
publish('/overview', async (request, response) => {
|
|
1170
|
+
const allowed = admit(ctx, request)
|
|
1171
|
+
if (!allowed.ok) {
|
|
1172
|
+
sendJson(response, allowed.status, { error: allowed.status === 403 ? 'forbidden' : 'unauthorized' })
|
|
1173
|
+
return
|
|
1174
|
+
}
|
|
1175
|
+
if (request.method !== 'GET') {
|
|
1176
|
+
response.writeHead(405, { allow: 'GET' })
|
|
1177
|
+
response.end()
|
|
1178
|
+
return
|
|
1179
|
+
}
|
|
1180
|
+
try {
|
|
1181
|
+
sendJson(response, 200, await buildOverview(ctx))
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
sendJson(response, 500, { error: 'overview-failed', message: messageOf(error) })
|
|
1184
|
+
}
|
|
1185
|
+
})
|
|
1186
|
+
|
|
1187
|
+
publish('/versions', async (request, response) => {
|
|
1188
|
+
const allowed = admit(ctx, request)
|
|
1189
|
+
if (!allowed.ok) {
|
|
1190
|
+
sendJson(response, allowed.status, { error: allowed.status === 403 ? 'forbidden' : 'unauthorized' })
|
|
1191
|
+
return
|
|
1192
|
+
}
|
|
1193
|
+
if (request.method !== 'GET') {
|
|
1194
|
+
response.writeHead(405, { allow: 'GET' })
|
|
1195
|
+
response.end()
|
|
1196
|
+
return
|
|
1197
|
+
}
|
|
1198
|
+
const url = new URL(request.url ?? '/', 'http://localhost')
|
|
1199
|
+
const name = url.searchParams.get('target')
|
|
1200
|
+
if (name === null || name === '') {
|
|
1201
|
+
sendJson(response, 400, { error: 'missing target' })
|
|
1202
|
+
return
|
|
1203
|
+
}
|
|
1204
|
+
try {
|
|
1205
|
+
sendJson(response, 200, await readVersions(ctx, name))
|
|
1206
|
+
} catch (error) {
|
|
1207
|
+
sendJson(response, 500, { error: 'versions-failed', message: messageOf(error) })
|
|
1208
|
+
}
|
|
1209
|
+
})
|
|
1210
|
+
|
|
1211
|
+
publish('/skills', async (request, response) => {
|
|
1212
|
+
const allowed = admit(ctx, request)
|
|
1213
|
+
if (!allowed.ok) {
|
|
1214
|
+
sendJson(response, allowed.status, { error: allowed.status === 403 ? 'forbidden' : 'unauthorized' })
|
|
1215
|
+
return
|
|
1216
|
+
}
|
|
1217
|
+
if (request.method !== 'GET') {
|
|
1218
|
+
response.writeHead(405, { allow: 'GET' })
|
|
1219
|
+
response.end()
|
|
1220
|
+
return
|
|
1221
|
+
}
|
|
1222
|
+
try {
|
|
1223
|
+
const profile = readProfileContext(ctx)
|
|
1224
|
+
const host = readRuntime(ctx)
|
|
1225
|
+
const catalog = await readSkills(ctx, { cwd: profile.cwd })
|
|
1226
|
+
const gitRegistry = profile.home === null ? [] : await readRegistry(profile.home, profile.id)
|
|
1227
|
+
const gitByName = new Map(gitRegistry.map((entry) => [entry.name, entry]))
|
|
1228
|
+
const skills = []
|
|
1229
|
+
for (const skill of catalog.skills) {
|
|
1230
|
+
const managed = gitByName.get(skill.name)
|
|
1231
|
+
skills.push({
|
|
1232
|
+
...skill,
|
|
1233
|
+
// Whether this row may be written at all. A single-file skill, a
|
|
1234
|
+
// bundled skill and a skill inside a Git checkout are all listed and
|
|
1235
|
+
// none of them is restorable. A Skill this plugin itself keeps in step
|
|
1236
|
+
// with a Git tree is the one exception: it was registered on purpose
|
|
1237
|
+
// and its history is known.
|
|
1238
|
+
restoreRefusal: skillRestoreRefusal(skill),
|
|
1239
|
+
// Present only for a Skill this plugin keeps in step with a Git tree.
|
|
1240
|
+
// `restoreRefusal` above stays the same for it: registration refuses
|
|
1241
|
+
// directories inside a checkout, so a registered Skill never reads as
|
|
1242
|
+
// `inside-git-checkout`.
|
|
1243
|
+
gitManaged:
|
|
1244
|
+
managed === undefined
|
|
1245
|
+
? null
|
|
1246
|
+
: { remote: managed.remote, subpath: managed.subpath, revision: managed.revision },
|
|
1247
|
+
snapshots:
|
|
1248
|
+
skill.directory === null
|
|
1249
|
+
? []
|
|
1250
|
+
: await listSkillSnapshots(profile.home, profile.id, skill.name),
|
|
1251
|
+
})
|
|
1252
|
+
}
|
|
1253
|
+
sendJson(response, 200, {
|
|
1254
|
+
schemaVersion: 1,
|
|
1255
|
+
observedAt: new Date().toISOString(),
|
|
1256
|
+
profile: { id: profile.id, dir: profile.dir, home: profile.home },
|
|
1257
|
+
host,
|
|
1258
|
+
available: catalog.available,
|
|
1259
|
+
reason: catalog.reason,
|
|
1260
|
+
complete: catalog.complete,
|
|
1261
|
+
provider: catalog.provider,
|
|
1262
|
+
skills,
|
|
1263
|
+
git: await listGitSkills(ctx, profile).then((result) => result.body),
|
|
1264
|
+
})
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
sendJson(response, 500, { error: 'skills-failed', message: messageOf(error) })
|
|
1267
|
+
}
|
|
1268
|
+
})
|
|
1269
|
+
|
|
1270
|
+
publish('/skills/restore-preview', async (request, response) => {
|
|
1271
|
+
const allowed = admit(ctx, request)
|
|
1272
|
+
if (!allowed.ok) {
|
|
1273
|
+
sendJson(response, allowed.status, { error: allowed.status === 403 ? 'forbidden' : 'unauthorized' })
|
|
1274
|
+
return
|
|
1275
|
+
}
|
|
1276
|
+
if (request.method !== 'GET') {
|
|
1277
|
+
response.writeHead(405, { allow: 'GET' })
|
|
1278
|
+
response.end()
|
|
1279
|
+
return
|
|
1280
|
+
}
|
|
1281
|
+
const url = new URL(request.url ?? '/', 'http://localhost')
|
|
1282
|
+
const name = url.searchParams.get('name') ?? ''
|
|
1283
|
+
const file = url.searchParams.get('file') ?? ''
|
|
1284
|
+
if (file === '') {
|
|
1285
|
+
sendJson(response, 400, { error: 'missing-file' })
|
|
1286
|
+
return
|
|
1287
|
+
}
|
|
1288
|
+
const result = await previewSkillRestoreRoute(ctx, name, file)
|
|
1289
|
+
sendJson(response, result.status, result.body)
|
|
1290
|
+
})
|
|
1291
|
+
|
|
1292
|
+
publish('/skills/git', async (request, response) => {
|
|
1293
|
+
const allowed = admit(ctx, request)
|
|
1294
|
+
if (!allowed.ok) {
|
|
1295
|
+
sendJson(response, allowed.status, { error: allowed.status === 403 ? 'forbidden' : 'unauthorized' })
|
|
1296
|
+
return
|
|
1297
|
+
}
|
|
1298
|
+
if (request.method !== 'GET') {
|
|
1299
|
+
response.writeHead(405, { allow: 'GET' })
|
|
1300
|
+
response.end()
|
|
1301
|
+
return
|
|
1302
|
+
}
|
|
1303
|
+
const result = await listGitSkills(ctx, readProfileContext(ctx))
|
|
1304
|
+
sendJson(response, result.status, result.body)
|
|
1305
|
+
})
|
|
1306
|
+
|
|
1307
|
+
writeRoute('/skills/git/register', async (_request, _response, body) =>
|
|
1308
|
+
registerGitRoute(ctx, readProfileContext(ctx), body),
|
|
1309
|
+
)
|
|
1310
|
+
writeRoute('/skills/git/remove', async (_request, _response, body) =>
|
|
1311
|
+
unregisterGitRoute(readProfileContext(ctx), body),
|
|
1312
|
+
)
|
|
1313
|
+
// A preview reaches the network (it fetches the remote into this plugin's own
|
|
1314
|
+
// cache), so it is a POST as well: the method says what the call costs.
|
|
1315
|
+
writeRoute('/skills/git/preview', async (_request, _response, body) =>
|
|
1316
|
+
previewGitRoute(readProfileContext(ctx), body),
|
|
1317
|
+
)
|
|
1318
|
+
writeRoute('/skills/git/update', async (_request, _response, body) =>
|
|
1319
|
+
updateGitRoute(readProfileContext(ctx), body),
|
|
1320
|
+
)
|
|
1321
|
+
writeRoute('/skills/git/restore', async (_request, _response, body) =>
|
|
1322
|
+
restoreGitRoute(readProfileContext(ctx), body),
|
|
1323
|
+
)
|
|
1324
|
+
|
|
1325
|
+
writeRoute('/skills/snapshot', async (_request, _response, body) => takeSkillSnapshot(ctx, body))
|
|
1326
|
+
writeRoute('/skills/restore', async (_request, _response, body) => restoreSkillRoute(ctx, body))
|
|
1327
|
+
writeRoute('/snapshot', async (_request, _response, body) => takeSnapshot(ctx, body))
|
|
1328
|
+
writeRoute('/update', async (_request, _response, body) => runUpdate(ctx, body))
|
|
1329
|
+
writeRoute('/restore', async (_request, _response, body) => restoreSnapshot(ctx, body))
|
|
1330
|
+
|
|
1331
|
+
return disposers
|
|
1332
|
+
}
|