@lumi-ai-lab/harness-data 0.0.12 → 0.0.13
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/package.json +1 -1
- package/src/commands/install.js +6 -2
- package/src/commands/update.js +7 -37
- package/src/lib/tool-release.js +47 -0
package/package.json
CHANGED
package/src/commands/install.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ask, askSecret, chooseAgent } from "../lib/prompt.js";
|
|
|
6
6
|
import { resolveWorkspaceDir, writeState } from "../lib/paths.js";
|
|
7
7
|
import { installToolsFromManifest, manifestDigest, readManifest } from "../lib/manifest.js";
|
|
8
8
|
import { binaryName, platformKey } from "../lib/platform.js";
|
|
9
|
+
import { resolveLatestManifest } from "../lib/tool-release.js";
|
|
9
10
|
import { collectDoctor } from "./doctor.js";
|
|
10
11
|
import { packageVersion } from "../lib/package.js";
|
|
11
12
|
import { downloadReleaseAsset, findReleaseAsset, githubToken, hasGithubAuth, latestRelease } from "../lib/github.js";
|
|
@@ -236,10 +237,13 @@ export async function installCommand(options = {}) {
|
|
|
236
237
|
let manifest;
|
|
237
238
|
let localTools = {};
|
|
238
239
|
if (tokenMode) {
|
|
239
|
-
manifest =
|
|
240
|
+
manifest = readManifest(manifestPath);
|
|
241
|
+
const latestManifest = await resolveLatestManifest(manifest, key, options);
|
|
242
|
+
manifest = await installToolsFromManifest(runtimeDir, manifestPath, { ...options, manifestOverride: latestManifest });
|
|
240
243
|
} else {
|
|
241
244
|
manifest = readManifest(manifestPath);
|
|
242
|
-
await
|
|
245
|
+
const latestManifest = await resolveLatestManifest(manifest, key, { ...options, tools: ["data-harness-cli"] });
|
|
246
|
+
await installToolsFromManifest(runtimeDir, manifestPath, { ...options, manifestOverride: latestManifest });
|
|
243
247
|
localTools = await installLocalTools(runtimeDir, options);
|
|
244
248
|
}
|
|
245
249
|
ok(`${Object.keys(manifest.installedTools || {}).length + Object.keys(localTools).length} 个 CLI 已安装到 bin/`);
|
package/src/commands/update.js
CHANGED
|
@@ -7,6 +7,7 @@ import { installToolsFromManifest, manifestDigest, readManifest } from "../lib/m
|
|
|
7
7
|
import { packageVersion } from "../lib/package.js";
|
|
8
8
|
import { platformKey } from "../lib/platform.js";
|
|
9
9
|
import { githubToken, latestRelease } from "../lib/github.js";
|
|
10
|
+
import { resolveLatestTool } from "../lib/tool-release.js";
|
|
10
11
|
import { protocolFromUrl, runGitWithProtocol } from "../lib/git-auth.js";
|
|
11
12
|
import { buildAndCheck, installRuntimeBundle, printDoctorSummary } from "./install.js";
|
|
12
13
|
import { collectDoctor } from "./doctor.js";
|
|
@@ -23,48 +24,17 @@ async function npmLatest() {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function
|
|
27
|
-
if (url.endsWith(".zip")) return "zip";
|
|
28
|
-
if (url.endsWith(".tar.gz")) return "tar.gz";
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function toolAssetName(tool, tag, key) {
|
|
33
|
-
const current = tool.platforms?.[key]?.url || "";
|
|
34
|
-
const suffix = archiveSuffix(current) || (key.startsWith("windows-") ? "zip" : "tar.gz");
|
|
35
|
-
return `${tool.binary}-${tag}-${key}.${suffix}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function releaseAsset(release, name) {
|
|
39
|
-
return (release.assets || []).find((asset) => asset.name === name);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function oneToolManifest(manifest, tool, tag, asset, key) {
|
|
27
|
+
function oneToolManifest(manifest, tool) {
|
|
43
28
|
return {
|
|
44
29
|
...manifest,
|
|
45
|
-
tools: [
|
|
46
|
-
...tool,
|
|
47
|
-
version: tag,
|
|
48
|
-
platforms: {
|
|
49
|
-
[key]: {
|
|
50
|
-
url: asset.browser_download_url || `https://github.com/${tool.repo}/releases/download/${tag}/${asset.name}`,
|
|
51
|
-
sha256: ""
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}]
|
|
30
|
+
tools: [tool]
|
|
55
31
|
};
|
|
56
32
|
}
|
|
57
33
|
|
|
58
34
|
async function maybeUpdateTool(runtimeDir, manifest, tool, options, state) {
|
|
59
35
|
const key = platformKey();
|
|
60
|
-
const
|
|
61
|
-
const tag =
|
|
62
|
-
const assetName = toolAssetName(tool, tag, key);
|
|
63
|
-
const asset = releaseAsset(release, assetName);
|
|
64
|
-
if (!asset) {
|
|
65
|
-
warn(`${tool.name} 最新 release 缺少 ${assetName},已跳过`);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
36
|
+
const latestTool = await resolveLatestTool(tool, key, options);
|
|
37
|
+
const tag = latestTool.version;
|
|
68
38
|
const current = state.tools?.[tool.name] || {};
|
|
69
39
|
const tagChanged = current.version && current.version !== tag;
|
|
70
40
|
const firstInstall = !current.version;
|
|
@@ -78,12 +48,12 @@ async function maybeUpdateTool(runtimeDir, manifest, tool, options, state) {
|
|
|
78
48
|
options.skippedUpdates?.push(`${tool.name} ${tag}`);
|
|
79
49
|
return null;
|
|
80
50
|
}
|
|
81
|
-
const updatedManifest = oneToolManifest(manifest,
|
|
51
|
+
const updatedManifest = oneToolManifest(manifest, latestTool);
|
|
82
52
|
const installed = await installToolsFromManifest(runtimeDir, path.join(runtimeDir, ".bootstrap-cache", `${tool.name}-manifest.json`), {
|
|
83
53
|
...options,
|
|
84
54
|
manifestOverride: updatedManifest
|
|
85
55
|
});
|
|
86
|
-
const result = installed.installedTools?.[tool.name] || { version: tag
|
|
56
|
+
const result = installed.installedTools?.[tool.name] || { version: tag };
|
|
87
57
|
ok(`${tool.name} 已更新到 ${tag}`);
|
|
88
58
|
return result;
|
|
89
59
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { latestRelease } from "./github.js";
|
|
2
|
+
|
|
3
|
+
function archiveSuffix(asset, key) {
|
|
4
|
+
if (asset?.archive) return asset.archive;
|
|
5
|
+
if (asset?.url?.endsWith(".zip")) return "zip";
|
|
6
|
+
if (asset?.url?.endsWith(".tar.gz")) return "tar.gz";
|
|
7
|
+
return key.startsWith("windows-") ? "zip" : "tar.gz";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function toolAssetName(tool, tag, key) {
|
|
11
|
+
const suffix = archiveSuffix(tool.platforms?.[key], key);
|
|
12
|
+
return `${tool.binary}-${tag}-${key}.${suffix}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function releaseAsset(release, name) {
|
|
16
|
+
return (release.assets || []).find((asset) => asset.name === name);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function resolveLatestTool(tool, key, options = {}) {
|
|
20
|
+
const release = await latestRelease(tool.repo, options);
|
|
21
|
+
const tag = release.tag_name;
|
|
22
|
+
const name = toolAssetName(tool, tag, key);
|
|
23
|
+
const asset = releaseAsset(release, name);
|
|
24
|
+
if (!asset) {
|
|
25
|
+
throw new Error(`${tool.name} latest release ${tag} missing ${key} asset in ${tool.repo}: ${name}`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
...tool,
|
|
29
|
+
version: tag,
|
|
30
|
+
platforms: {
|
|
31
|
+
[key]: {
|
|
32
|
+
url: asset.browser_download_url || `https://github.com/${tool.repo}/releases/download/${tag}/${asset.name}`,
|
|
33
|
+
sha256: ""
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function resolveLatestManifest(manifest, key, options = {}) {
|
|
40
|
+
const only = options.tools ? new Set(options.tools) : null;
|
|
41
|
+
const tools = [];
|
|
42
|
+
for (const tool of manifest.tools || []) {
|
|
43
|
+
if (only && !only.has(tool.name)) continue;
|
|
44
|
+
tools.push(await resolveLatestTool(tool, key, options));
|
|
45
|
+
}
|
|
46
|
+
return { ...manifest, tools };
|
|
47
|
+
}
|