@insmind/cli 1.5.3 → 1.5.5
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/dist/bin/postinstall.js
CHANGED
|
@@ -5,6 +5,7 @@ import { dirname, resolve } from "node:path";
|
|
|
5
5
|
import { loadBundledSkills } from "../src/features/skill/bundled-skills.js";
|
|
6
6
|
import { syncBundledSkills } from "../src/features/skill/installer.js";
|
|
7
7
|
import { markWorkBuddyInstallation, readInstallationOwner } from "../src/platform/installation-owner.js";
|
|
8
|
+
import { pinWorkBuddyRuntime } from "../src/platform/workbuddy-runtime.js";
|
|
8
9
|
export function isSupportedGlobalLifecycle(env) {
|
|
9
10
|
const userAgent = env.npm_config_user_agent ?? "";
|
|
10
11
|
if (env.npm_config_global === "true") {
|
|
@@ -45,6 +46,7 @@ export async function runPostinstall(options = {}) {
|
|
|
45
46
|
const packageRoot = dirname(dirname(primarySkill.sourceDirectory));
|
|
46
47
|
if (env.GD_CLI_INSTALL_OWNER === "workbuddy") {
|
|
47
48
|
markWorkBuddyInstallation(packageRoot);
|
|
49
|
+
pinWorkBuddyRuntime(packageRoot);
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
52
|
const owner = readInstallationOwner(packageRoot);
|
|
@@ -2,7 +2,6 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import * as nodeFileSystem from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
5
|
-
import { createLocalJsonFile } from "./local-json-file.js";
|
|
6
5
|
/** Local bakery lock: unique owner files avoid deleting a new owner's lock
|
|
7
6
|
* when several processes simultaneously recover a dead writer. */
|
|
8
7
|
export async function withFileLock(path, run, options = {}) {
|
|
@@ -56,7 +55,11 @@ export async function withFileLock(path, run, options = {}) {
|
|
|
56
55
|
try {
|
|
57
56
|
await handle.writeFile('{"ticket":null}');
|
|
58
57
|
const ticket = 1 + Math.max(0, ...(await contenders()).map(owner => owner.ticket ?? 0));
|
|
59
|
-
|
|
58
|
+
// Empty/partial owner files already mean "choosing" to readers. Write in
|
|
59
|
+
// place because Windows can reject replacement while another reader is open.
|
|
60
|
+
await handle.truncate(0);
|
|
61
|
+
await handle.write(JSON.stringify({ ticket }), 0, "utf8");
|
|
62
|
+
await handle.close();
|
|
60
63
|
for (;;) {
|
|
61
64
|
if (Date.now() >= deadline)
|
|
62
65
|
throw new Error("Local state lock timed out.");
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readlinkSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
/** Pin only this managed CLI, not the host's shared `node` or other connectors. */
|
|
4
|
+
export function pinWorkBuddyRuntime(packageRoot) {
|
|
5
|
+
const windows = process.platform === "win32";
|
|
6
|
+
const prefix = resolve(packageRoot, windows ? "../../.." : "../../../..");
|
|
7
|
+
const expectedRoot = join(prefix, ...(windows ? [] : ["lib"]), "node_modules", "@gaoding", "cli");
|
|
8
|
+
if (resolve(packageRoot) !== expectedRoot) {
|
|
9
|
+
throw new Error("无法确认 WorkBuddy CLI 的 npm 安装目录。");
|
|
10
|
+
}
|
|
11
|
+
const binDirectory = windows ? prefix : join(prefix, "bin");
|
|
12
|
+
const bin = join(binDirectory, "gd-cli");
|
|
13
|
+
const entry = join(packageRoot, "dist", "bin", "gd-cli.js");
|
|
14
|
+
const node = process.execPath;
|
|
15
|
+
if (!windows) {
|
|
16
|
+
const launcher = join(packageRoot, "dist", "bin", "workbuddy-gd-cli.sh");
|
|
17
|
+
const target = resolve(binDirectory, readlinkSync(bin));
|
|
18
|
+
if (target !== entry && target !== launcher) {
|
|
19
|
+
throw new Error("WorkBuddy gd-cli 启动入口不属于当前安装。");
|
|
20
|
+
}
|
|
21
|
+
writeFileSync(launcher, `#!/bin/sh\nexec ${shellQuote(node)} ${shellQuote(entry)} "$@"\n`, { mode: 0o755 });
|
|
22
|
+
// Keep an in-package symlink so npm can recognize, update and uninstall its bin.
|
|
23
|
+
unlinkSync(bin);
|
|
24
|
+
symlinkSync(relative(binDirectory, launcher), bin);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const target = "node_modules/@gaoding/cli/dist/bin/gd-cli.js";
|
|
28
|
+
// Preserve npm's recognizable target syntax for upgrades/uninstalls on Windows.
|
|
29
|
+
writeFileSync(`${bin}.cmd`, [
|
|
30
|
+
"@ECHO OFF",
|
|
31
|
+
"SETLOCAL DISABLEDELAYEDEXPANSION",
|
|
32
|
+
`"${node.replace(/%/gu, "%%")}" "%~dp0\\${target.replace(/\//gu, "\\")}" %*`,
|
|
33
|
+
"EXIT /b %ERRORLEVEL%",
|
|
34
|
+
""
|
|
35
|
+
].join("\r\n"));
|
|
36
|
+
const powershellNode = `'${node.replace(/'/gu, "''")}'`;
|
|
37
|
+
writeFileSync(`${bin}.ps1`, [
|
|
38
|
+
"\uFEFF#!/usr/bin/env pwsh",
|
|
39
|
+
"$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent",
|
|
40
|
+
"if ($MyInvocation.ExpectingInput) {",
|
|
41
|
+
` $input | & ${powershellNode} "$basedir/${target}" $args`,
|
|
42
|
+
"} else {",
|
|
43
|
+
` & ${powershellNode} "$basedir/${target}" $args`,
|
|
44
|
+
"}",
|
|
45
|
+
"exit $LASTEXITCODE",
|
|
46
|
+
""
|
|
47
|
+
].join("\n"));
|
|
48
|
+
writeFileSync(bin, [
|
|
49
|
+
"#!/bin/sh",
|
|
50
|
+
'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
|
|
51
|
+
`exec ${shellQuote(node.replace(/\\/gu, "/"))} "$basedir/${target}" "$@"`,
|
|
52
|
+
""
|
|
53
|
+
].join("\n"), { mode: 0o755 });
|
|
54
|
+
}
|
|
55
|
+
function shellQuote(value) {
|
|
56
|
+
return `'${value.replace(/'/gu, "'\\''")}'`;
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insmind/cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@gaoding/cli": "workspace:*"
|
|
47
47
|
},
|
|
48
48
|
"gaodingRelease": {
|
|
49
|
-
"sourceCommit": "
|
|
50
|
-
"pipelineId": "
|
|
51
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
49
|
+
"sourceCommit": "ff1c91af6c4b668886646eaf77f8b8ad8fb2e103",
|
|
50
|
+
"pipelineId": "199043",
|
|
51
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/199043"
|
|
52
52
|
}
|
|
53
53
|
}
|