dsh-computers 1.1.0 → 1.3.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/PROTOCOL.md +135 -0
- package/README.md +45 -16
- package/agent/README.md +112 -5
- package/agent/dsh-computers-agent.mjs +835 -20
- package/client.js +777 -10
- package/cordis.patch.yml +2 -0
- package/index.js +32 -2
- package/lib/access.js +397 -0
- package/lib/fs-ops.js +162 -0
- package/lib/hub.js +346 -140
- package/lib/routes.js +425 -38
- package/lib/state.js +11 -2
- package/lib/tools.js +684 -85
- package/lib/version.js +62 -0
- package/package.json +1 -1
package/lib/version.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny semantic-version helpers for the agent version gate (PROTOCOL §11.1,
|
|
3
|
+
* §11.6.5). Agent versions are ordinary `x.y.z` strings (optionally `v`-prefixed);
|
|
4
|
+
* anything unparseable fails the gate closed with an actionable message.
|
|
5
|
+
*
|
|
6
|
+
* Node builtins only.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parse `1.2.3` / `v1.2.3` / `1.2` into numeric parts, or null.
|
|
11
|
+
* @param {unknown} value - version text.
|
|
12
|
+
* @returns {number[] | null} up to three numbers.
|
|
13
|
+
*/
|
|
14
|
+
export function parseVersion(value) {
|
|
15
|
+
if (typeof value !== 'string') return null
|
|
16
|
+
const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/.exec(value.trim())
|
|
17
|
+
if (match === null) return null
|
|
18
|
+
return [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The `major.minor` prefix of a version (the default agent version gate).
|
|
23
|
+
* @param {unknown} value - version text.
|
|
24
|
+
* @returns {string} major.minor, or '' when unparseable.
|
|
25
|
+
*/
|
|
26
|
+
export function majorMinor(value) {
|
|
27
|
+
const parts = parseVersion(value)
|
|
28
|
+
return parts === null ? '' : `${parts[0]}.${parts[1]}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether `actual` is at least `minimum`. A missing/unparseable `minimum`
|
|
33
|
+
* admits everything; a missing/unparseable `actual` is treated as v0 and so
|
|
34
|
+
* fails any real minimum (an unknown agent is an old agent).
|
|
35
|
+
* @param {unknown} actual - reported agent version.
|
|
36
|
+
* @param {unknown} minimum - required version, or empty for none.
|
|
37
|
+
* @returns {boolean} whether the agent satisfies the gate.
|
|
38
|
+
*/
|
|
39
|
+
export function versionAtLeast(actual, minimum) {
|
|
40
|
+
const required = parseVersion(minimum)
|
|
41
|
+
if (required === null) return true
|
|
42
|
+
const reported = parseVersion(actual)
|
|
43
|
+
if (reported === null) return false
|
|
44
|
+
for (let index = 0; index < 3; index += 1) {
|
|
45
|
+
if (reported[index] > required[index]) return true
|
|
46
|
+
if (reported[index] < required[index]) return false
|
|
47
|
+
}
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether two reported versions differ enough to show a drift badge.
|
|
53
|
+
* @param {unknown} actual - reported version.
|
|
54
|
+
* @param {unknown} expected - host plugin version.
|
|
55
|
+
* @returns {boolean} true when they differ or the agent version is unknown.
|
|
56
|
+
*/
|
|
57
|
+
export function versionsDiffer(actual, expected) {
|
|
58
|
+
const left = parseVersion(actual)
|
|
59
|
+
const right = parseVersion(expected)
|
|
60
|
+
if (left === null || right === null) return true
|
|
61
|
+
return left[0] !== right[0] || left[1] !== right[1] || left[2] !== right[2]
|
|
62
|
+
}
|