@forgeailab/smith 0.2.9 → 0.2.12

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.
Files changed (3) hide show
  1. package/README.md +15 -0
  2. package/bin/cli.js +85 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -21,6 +21,21 @@ npx @forgeailab/smith setup # guided provider/model setup
21
21
  npx @forgeailab/smith --help
22
22
  ```
23
23
 
24
+ ## Installing a permanent `smith` command
25
+
26
+ `--install` copies the downloaded binary onto your PATH so later runs skip npm
27
+ entirely. It writes to a user-owned directory, so it never needs sudo:
28
+
29
+ ```bash
30
+ npx @forgeailab/smith --install # -> ~/.local/bin/smith
31
+ npx @forgeailab/smith --install --install-dir ~/bin # somewhere else
32
+ SMITH_INSTALL_DIR=~/bin npx @forgeailab/smith --install
33
+ npx @forgeailab/smith --uninstall # remove it again
34
+ ```
35
+
36
+ If the install directory is not on your `PATH`, the command prints the
37
+ `export PATH=...` line to add to your shell profile.
38
+
24
39
  By default, the wrapper downloads the GitHub release tag that matches the npm
25
40
  package version. For testing a different release:
26
41
 
package/bin/cli.js CHANGED
@@ -26,12 +26,18 @@ Examples:
26
26
  npx ${PACKAGE.name} # interactive TUI
27
27
  npx ${PACKAGE.name} -p "explain this repo" # one headless turn
28
28
  npx ${PACKAGE.name} setup # guided provider/model setup
29
+ npx ${PACKAGE.name} --install # install 'smith' into ~/.local/bin
30
+ npx ${PACKAGE.name} --uninstall # remove that installed binary
29
31
 
30
32
  Options handled by the bootstrapper:
33
+ --install Copy the smith binary onto your PATH, then exit
34
+ --uninstall Remove a smith binary this bootstrapper installed
35
+ --install-dir <dir> Install/uninstall location (default: ~/.local/bin)
31
36
  --release <tag|latest> Download a specific GitHub release tag
32
37
  --version Show the npm bootstrapper version
33
38
  --help Show this help
34
39
 
40
+ --install never needs sudo: it writes to a user-owned directory.
35
41
  All other options are passed through to the smith binary.`);
36
42
  }
37
43
 
@@ -43,11 +49,17 @@ function isVersion(args) {
43
49
  return args.includes("--version") || args.includes("-V");
44
50
  }
45
51
 
52
+ function defaultInstallDir(env = process.env, homedir = os.homedir()) {
53
+ return env.SMITH_INSTALL_DIR || path.join(homedir, ".local", "bin");
54
+ }
55
+
46
56
  function parseArgs(argv, packageVersion = PACKAGE.version, env = process.env) {
47
57
  const args = [...argv];
48
58
  let release =
49
59
  env.SMITH_NPX_TAG ||
50
60
  (packageVersion === "0.0.0" ? "latest" : `v${packageVersion}`);
61
+ let installDir = defaultInstallDir(env);
62
+ let mode = "run";
51
63
  const passthrough = [];
52
64
 
53
65
  for (let i = 0; i < args.length; i += 1) {
@@ -65,10 +77,31 @@ function parseArgs(argv, packageVersion = PACKAGE.version, env = process.env) {
65
77
  release = arg.slice("--release=".length);
66
78
  continue;
67
79
  }
80
+ if (arg === "--install-dir") {
81
+ const value = args[i + 1];
82
+ if (!value) {
83
+ throw new Error("--install-dir requires a directory value");
84
+ }
85
+ installDir = value;
86
+ i += 1;
87
+ continue;
88
+ }
89
+ if (arg.startsWith("--install-dir=")) {
90
+ installDir = arg.slice("--install-dir=".length);
91
+ continue;
92
+ }
93
+ if (arg === "--install") {
94
+ mode = "install";
95
+ continue;
96
+ }
97
+ if (arg === "--uninstall") {
98
+ mode = "uninstall";
99
+ continue;
100
+ }
68
101
  passthrough.push(arg);
69
102
  }
70
103
 
71
- return { passthrough, release };
104
+ return { passthrough, release, mode, installDir };
72
105
  }
73
106
 
74
107
  function platformInfo(platform = process.platform, archInput = process.arch) {
@@ -284,6 +317,44 @@ async function ensureRelease(release) {
284
317
  return { binaryPath, installDir, tag };
285
318
  }
286
319
 
320
+ function onPath(dir, env = process.env) {
321
+ const entries = (env.PATH || "").split(path.delimiter).filter(Boolean);
322
+ return entries.some((entry) => path.resolve(entry) === path.resolve(dir));
323
+ }
324
+
325
+ function installBinary(sourcePath, installDir, tag) {
326
+ const target = path.join(installDir, "smith");
327
+ fs.mkdirSync(installDir, { recursive: true });
328
+
329
+ const temp = `${target}.tmp-${process.pid}`;
330
+ fs.copyFileSync(sourcePath, temp);
331
+ fs.chmodSync(temp, 0o755);
332
+ fs.renameSync(temp, target);
333
+
334
+ console.log(`Installed Smith ${tag} -> ${target}`);
335
+ if (onPath(installDir)) {
336
+ console.log("Run 'smith --help' to get started.");
337
+ } else {
338
+ console.log(`${installDir} is not on your PATH. Add it:`);
339
+ console.log(` export PATH="${installDir}:$PATH"`);
340
+ }
341
+ return target;
342
+ }
343
+
344
+ function uninstallBinary(installDir) {
345
+ const target = path.join(installDir, "smith");
346
+ try {
347
+ fs.unlinkSync(target);
348
+ console.log(`Removed ${target}`);
349
+ } catch (error) {
350
+ if (error.code === "ENOENT") {
351
+ console.log(`Nothing to remove: ${target} does not exist`);
352
+ return;
353
+ }
354
+ throw error;
355
+ }
356
+ }
357
+
287
358
  function runBinary(binary, args, env) {
288
359
  const child = childProcess.spawn(binary, args, {
289
360
  env,
@@ -318,11 +389,23 @@ async function main() {
318
389
  }
319
390
 
320
391
  const options = parseArgs(rawArgs);
392
+
393
+ if (options.mode === "uninstall") {
394
+ uninstallBinary(options.installDir);
395
+ return;
396
+ }
397
+
321
398
  const release = await ensureRelease(options.release);
399
+
400
+ if (options.mode === "install") {
401
+ installBinary(release.binaryPath, options.installDir, release.tag);
402
+ return;
403
+ }
404
+
322
405
  runBinary(release.binaryPath, options.passthrough, { ...process.env });
323
406
  }
324
407
 
325
- module.exports = { parseArgs, platformInfo };
408
+ module.exports = { defaultInstallDir, onPath, parseArgs, platformInfo };
326
409
 
327
410
  if (require.main === module) {
328
411
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgeailab/smith",
3
- "version": "0.2.9",
3
+ "version": "0.2.12",
4
4
  "description": "NPX bootstrapper for the Smith terminal-first coding agent",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "homepage": "https://github.com/ForgeAILab/smith#readme",