driggsby 0.1.21 → 0.1.23

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/bin/driggsby ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { readPackageJson, resolvePlatform, unsupportedPlatformMessage, } from "../lib/artifacts.js";
3
+ const packageJson = readPackageJson();
4
+ const resolution = resolvePlatform(packageJson);
5
+ if (!resolution.platform) {
6
+ console.error(unsupportedPlatformMessage(resolution));
7
+ process.exit(1);
8
+ }
9
+ console.error("Driggsby native binary is not active. Reinstall with npm scripts enabled, or rerun with npm_config_foreground_scripts=true to see installer output.");
10
+ process.exit(1);
package/install.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { createHash } from "node:crypto";
3
- import { chmodSync, createWriteStream, existsSync, lstatSync, mkdtempSync, mkdirSync, rmSync, } from "node:fs";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { chmodSync, createWriteStream, existsSync, lstatSync, mkdtempSync, mkdirSync, renameSync, rmSync, } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { basename, join } from "node:path";
6
6
  import { Transform } from "node:stream";
7
7
  import { pipeline } from "node:stream/promises";
8
- import { installDirectory, installedBinaryPath, readPackageJson, resolvePlatform, unsupportedPlatformMessage, } from "./lib/artifacts.js";
8
+ import { packageBinDirectory, packageBinPath, readPackageJson, resolvePlatform, unsupportedPlatformMessage, } from "./lib/artifacts.js";
9
9
  import { readCommandOutput, writeCommandOutputToFile } from "./lib/process.js";
10
10
  const maxArtifactBytes = 64 * 1024 * 1024;
11
11
  const packageJson = readPackageJson();
@@ -13,14 +13,15 @@ try {
13
13
  await install();
14
14
  }
15
15
  catch (error) {
16
- if (error instanceof Error) {
17
- console.error(error.message);
18
- }
19
- else {
20
- console.error(error);
21
- }
16
+ console.error(publicInstallErrorMessage(error));
22
17
  process.exit(1);
23
18
  }
19
+ function publicInstallErrorMessage(error) {
20
+ if (error instanceof Error && error.message.startsWith("Driggsby ")) {
21
+ return error.message;
22
+ }
23
+ return "Driggsby native binary could not be installed. Check your network connection and reinstall with npm scripts enabled.";
24
+ }
24
25
  async function install() {
25
26
  const resolution = resolvePlatform(packageJson);
26
27
  const platform = resolution.platform;
@@ -28,12 +29,10 @@ async function install() {
28
29
  console.warn(unsupportedPlatformMessage(resolution));
29
30
  return;
30
31
  }
31
- const binaryPath = installedBinaryPath(platform.binaryPath);
32
- if (existsSync(binaryPath)) {
33
- return;
34
- }
35
- rmSync(installDirectory, { force: true, recursive: true });
36
- mkdirSync(installDirectory, { recursive: true });
32
+ validatePlatformConfig(platform);
33
+ ensurePackageBinDirectory();
34
+ const binaryPath = packageBinPath;
35
+ const tempBinaryPath = join(packageBinDirectory, `.${platform.binaryPath}.${randomUUID()}.tmp`);
37
36
  const artifactUrl = `${packageJson.driggsbyArtifacts.baseUrl}/${platform.artifactName}`;
38
37
  const tempDirectory = mkdtempSync(join(tmpdir(), "driggsby-install-"));
39
38
  chmodSync(tempDirectory, 0o700);
@@ -44,17 +43,35 @@ async function install() {
44
43
  throw new Error(`Driggsby package is missing a checksum for ${platform.artifactName}.`);
45
44
  }
46
45
  await downloadAndVerifyFile(artifactUrl, tempArtifact, expectedChecksum);
47
- extractTarball(tempArtifact, installDirectory, platform.binaryPath);
48
- chmodSync(binaryPath, 0o755);
46
+ extractTarball(tempArtifact, tempBinaryPath, platform.binaryPath);
47
+ chmodSync(tempBinaryPath, 0o755);
48
+ renameSync(tempBinaryPath, binaryPath);
49
49
  }
50
50
  catch (error) {
51
- rmSync(installDirectory, { force: true, recursive: true });
51
+ rmSync(tempBinaryPath, { force: true });
52
52
  throw error;
53
53
  }
54
54
  finally {
55
55
  rmSync(tempDirectory, { force: true, recursive: true });
56
56
  }
57
57
  }
58
+ function validatePlatformConfig(platform) {
59
+ if (platform.binaryPath !== "driggsby") {
60
+ throw new Error("Driggsby package contains unsupported binary metadata.");
61
+ }
62
+ if (!/^driggsby-[A-Za-z0-9_-]+\.tar\.xz$/.test(platform.artifactName)) {
63
+ throw new Error("Driggsby package contains unsupported artifact metadata.");
64
+ }
65
+ }
66
+ function ensurePackageBinDirectory() {
67
+ if (!existsSync(packageBinDirectory)) {
68
+ mkdirSync(packageBinDirectory, { recursive: true });
69
+ }
70
+ const stats = lstatSync(packageBinDirectory);
71
+ if (!stats.isDirectory() || stats.isSymbolicLink()) {
72
+ throw new Error("Driggsby package bin directory is not a regular directory.");
73
+ }
74
+ }
58
75
  async function downloadAndVerifyFile(url, destination, expectedChecksum) {
59
76
  const response = await fetch(url);
60
77
  if (!response.ok || response.body === null) {
@@ -86,16 +103,24 @@ async function downloadAndVerifyFile(url, destination, expectedChecksum) {
86
103
  function extractTarball(artifactPath, destination, binaryPath) {
87
104
  const tarPath = trustedTarPath();
88
105
  const entry = findBinaryTarEntry(tarPath, artifactPath, binaryPath);
89
- const installedBinary = join(destination, binaryPath);
90
- writeCommandOutputToFile(tarPath, ["-xOf", artifactPath, "--", entry], installedBinary, maxArtifactBytes);
91
- if (!existsSync(installedBinary)) {
106
+ assertRegularTarEntry(tarPath, artifactPath, entry, binaryPath);
107
+ writeCommandOutputToFile(tarPath, ["-xOf", artifactPath, "--", entry], destination, maxArtifactBytes);
108
+ if (!existsSync(destination)) {
92
109
  throw new Error(`Driggsby archive did not contain expected binary ${binaryPath}.`);
93
110
  }
94
- const installedBinaryStats = lstatSync(installedBinary);
111
+ const installedBinaryStats = lstatSync(destination);
95
112
  if (!installedBinaryStats.isFile() || installedBinaryStats.isSymbolicLink()) {
96
113
  throw new Error(`Driggsby archive entry ${binaryPath} was not a regular file.`);
97
114
  }
98
115
  }
116
+ function assertRegularTarEntry(tarPath, artifactPath, entry, binaryPath) {
117
+ const listings = readCommandOutput(tarPath, ["-tvf", artifactPath, "--", entry])
118
+ .split("\n")
119
+ .filter((line) => line.trim().length > 0);
120
+ if (listings.length !== 1 || !listings[0]?.startsWith("-")) {
121
+ throw new Error(`Driggsby archive entry ${binaryPath} was not a regular file.`);
122
+ }
123
+ }
99
124
  function trustedTarPath() {
100
125
  for (const candidate of ["/usr/bin/tar", "/bin/tar"]) {
101
126
  if (existsSync(candidate)) {
package/lib/artifacts.js CHANGED
@@ -2,13 +2,11 @@ import { readFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  export const packageDirectory = dirname(dirname(fileURLToPath(import.meta.url)));
5
- export const installDirectory = join(packageDirectory, "node_modules", ".bin_real");
5
+ export const packageBinDirectory = join(packageDirectory, "bin");
6
+ export const packageBinPath = join(packageBinDirectory, "driggsby");
6
7
  export function readPackageJson() {
7
8
  return JSON.parse(readFileSync(join(packageDirectory, "package.json"), "utf8"));
8
9
  }
9
- export function installedBinaryPath(binaryPath) {
10
- return join(installDirectory, binaryPath);
11
- }
12
10
  export function resolvePlatform(packageJson) {
13
11
  const triple = targetTriple();
14
12
  return {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "driggsby",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Local MCP broker and CLI for connecting AI clients to Driggsby",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/thegoodsoftwareco/driggsby-cli",
7
7
  "type": "module",
8
8
  "bin": {
9
- "driggsby": "run-driggsby.js"
9
+ "driggsby": "bin/driggsby"
10
10
  },
11
11
  "scripts": {
12
12
  "postinstall": "node ./install.js"
@@ -16,20 +16,20 @@
16
16
  "npm": ">=9"
17
17
  },
18
18
  "files": [
19
+ "bin",
19
20
  "LICENSE",
20
21
  "README.md",
21
22
  "install.js",
22
23
  "lib",
23
- "package.json",
24
- "run-driggsby.js"
24
+ "package.json"
25
25
  ],
26
26
  "driggsbyArtifacts": {
27
- "baseUrl": "https://github.com/thegoodsoftwareco/driggsby-cli/releases/download/driggsby-v0.1.21",
27
+ "baseUrl": "https://github.com/thegoodsoftwareco/driggsby-cli/releases/download/driggsby-v0.1.23",
28
28
  "checksums": {
29
- "driggsby-aarch64-apple-darwin.tar.xz": "1bdd63ea017a771ed5ed6e7fa1ab8fe8469949509b6763d8a71b989251611e11",
30
- "driggsby-x86_64-apple-darwin.tar.xz": "cef45b06f66cd68aeb82ca288a4a52e79e1abd4d105acebb05d62ed7f04cf3a1",
31
- "driggsby-aarch64-unknown-linux-gnu.tar.xz": "93b2433dede66d40c2320a7fda9eb46f31406842b63c3d436ea11f2c78fab5eb",
32
- "driggsby-x86_64-unknown-linux-gnu.tar.xz": "9f41aac3cb140f59fe0cb62882f5571916b5f6fda873e30529f3732f48d80f70"
29
+ "driggsby-aarch64-apple-darwin.tar.xz": "cd778960741ab9c20393e1f2e47b8174e625c45f8ed74e0d111c5f19e7abc8e4",
30
+ "driggsby-x86_64-apple-darwin.tar.xz": "61e422da8748ef7049b7753004c83461ddc37994f35de1576d2c4e8ac5d03612",
31
+ "driggsby-aarch64-unknown-linux-gnu.tar.xz": "c8d53da5f0e9a4259fd5f1867ca6f624d8ebaec67890f32258611a8e5dfaac37",
32
+ "driggsby-x86_64-unknown-linux-gnu.tar.xz": "a6b1928f4a2302a6744a69b59fd42f924c0ef0e6592b7fc98204ae82f9616335"
33
33
  },
34
34
  "supportedPlatforms": {
35
35
  "aarch64-apple-darwin": {
package/run-driggsby.js DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import { existsSync } from "node:fs";
3
- import { installedBinaryPath, readPackageJson, resolvePlatform, unsupportedPlatformMessage, } from "./lib/artifacts.js";
4
- import { spawnFileAndExit } from "./lib/process.js";
5
- const packageJson = readPackageJson();
6
- const resolution = resolvePlatform(packageJson);
7
- if (!resolution.platform) {
8
- console.error(unsupportedPlatformMessage(resolution));
9
- process.exit(1);
10
- }
11
- const binaryPath = installedBinaryPath(resolution.platform.binaryPath);
12
- if (!existsSync(binaryPath)) {
13
- console.error("Driggsby native binary is not installed. Reinstall with npm scripts enabled, or rerun with npm_config_foreground_scripts=true to see installer output.");
14
- process.exit(1);
15
- }
16
- spawnFileAndExit(binaryPath, process.argv.slice(2));