@shubhamcodess/whatcmd 0.0.0-stage → 0.1.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/dist/util.js ADDED
@@ -0,0 +1,58 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { spawnSync } from "node:child_process";
4
+ const whichCache = new Map();
5
+ function isExecutable(p) {
6
+ try {
7
+ if (!fs.statSync(p).isFile())
8
+ return false;
9
+ fs.accessSync(p, fs.constants.X_OK);
10
+ return true;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ }
16
+ /** Find an executable on PATH without spawning a process. */
17
+ export function which(name) {
18
+ const hit = whichCache.get(name);
19
+ if (hit !== undefined)
20
+ return hit;
21
+ let found = null;
22
+ if (name.includes("/")) {
23
+ found = isExecutable(name) ? name : null;
24
+ }
25
+ else {
26
+ for (const dir of (process.env.PATH ?? "").split(path.delimiter)) {
27
+ if (!dir)
28
+ continue;
29
+ const p = path.join(dir, name);
30
+ if (isExecutable(p)) {
31
+ found = p;
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ whichCache.set(name, found);
37
+ return found;
38
+ }
39
+ export function clearWhichCache() {
40
+ whichCache.clear();
41
+ }
42
+ /** Run a program synchronously with a timeout. Never throws. */
43
+ export function run(cmd, args, opts = {}) {
44
+ const r = spawnSync(cmd, args, {
45
+ encoding: "utf8",
46
+ timeout: opts.timeoutMs ?? 2000,
47
+ env: { ...process.env, ...opts.env },
48
+ stdio: ["ignore", "pipe", "pipe"],
49
+ maxBuffer: 4 * 1024 * 1024,
50
+ });
51
+ return {
52
+ ok: r.status === 0 && !r.error,
53
+ status: r.status,
54
+ timedOut: r.error?.code === "ETIMEDOUT",
55
+ stdout: r.stdout ?? "",
56
+ stderr: r.stderr ?? "",
57
+ };
58
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@shubhamcodess/whatcmd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Type plain English in your terminal, get a shell command back. Runs locally on Ollama, grounded in your own system.",
5
+ "type": "module",
6
+ "bin": {
7
+ "whatcmd": "dist/cli.js"
8
+ },
9
+ "files": [
10
+ "dist/**/*.js",
11
+ "!dist/**/*.test.js",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=21"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc -p . && chmod +x dist/cli.js",
20
+ "prepare": "npm run build",
21
+ "prepack": "npm run build",
22
+ "test": "npm run build && node --test \"dist/**/*.test.js\"",
23
+ "eval": "npm run build && node scripts/eval.mjs",
24
+ "prepublishOnly": "npm test",
25
+ "check": "npm run build && node scripts/check-links.mjs && node scripts/check-pack.mjs"
26
+ },
27
+ "keywords": [
28
+ "cli",
29
+ "terminal",
30
+ "shell",
31
+ "ollama",
32
+ "llm",
33
+ "copilot",
34
+ "natural-language",
35
+ "bash",
36
+ "zsh"
37
+ ],
38
+ "author": "shubhamcodess",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/shubhamcodess/whatcmd.git"
43
+ },
44
+ "homepage": "https://github.com/shubhamcodess/whatcmd#readme",
45
+ "bugs": {
46
+ "url": "https://github.com/shubhamcodess/whatcmd/issues"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^22.10.0",
54
+ "typescript": "^5.6.3"
55
+ }
56
+ }