@zelanton/agent-workspace 0.12.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.
Files changed (3) hide show
  1. package/bin/wt.js +69 -0
  2. package/install.js +61 -0
  3. package/package.json +37 -0
package/bin/wt.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execFileSync } = require("child_process");
4
+ const { join } = require("path");
5
+
6
+ // ============================================================
7
+ // Platform Detection
8
+ // ============================================================
9
+
10
+ const PLATFORMS = {
11
+ "darwin-arm64": "@zelanton/agent-workspace-darwin-arm64",
12
+ "linux-x64": "@zelanton/agent-workspace-linux-x64",
13
+ "win32-x64": "@zelanton/agent-workspace-win32-x64",
14
+ };
15
+
16
+ function getPlatformPackage() {
17
+ const key = `${process.platform}-${process.arch}`;
18
+ const pkg = PLATFORMS[key];
19
+ if (!pkg) {
20
+ console.error(`Unsupported platform: ${key}`);
21
+ console.error(`Supported platforms: ${Object.keys(PLATFORMS).join(", ")}`);
22
+ process.exit(1);
23
+ }
24
+ return pkg;
25
+ }
26
+
27
+ // ============================================================
28
+ // Binary Resolution
29
+ // ============================================================
30
+
31
+ function getBinaryPath() {
32
+ const pkg = getPlatformPackage();
33
+ const exe = process.platform === "win32" ? "wt.exe" : "wt";
34
+ try {
35
+ const pkgPath = require.resolve(`${pkg}/package.json`);
36
+ return join(pkgPath, "..", "bin", exe);
37
+ } catch {
38
+ console.error(`Platform package not found: ${pkg}`);
39
+ console.error("Try reinstalling: npm install -g @zelanton/agent-workspace");
40
+ process.exit(1);
41
+ }
42
+ }
43
+
44
+ // ============================================================
45
+ // Execute
46
+ // ============================================================
47
+
48
+ const binary = getBinaryPath();
49
+ const args = process.argv.slice(2);
50
+
51
+ try {
52
+ execFileSync(binary, args, { stdio: "inherit" });
53
+ } catch (err) {
54
+ if (err.status !== undefined) {
55
+ process.exit(err.status);
56
+ }
57
+ if (err.code === "ENOENT") {
58
+ console.error(`Binary not found: ${binary}`);
59
+ console.error("Try reinstalling: npm install -g @zelanton/agent-workspace");
60
+ process.exit(1);
61
+ }
62
+ if (err.code === "EACCES") {
63
+ console.error(`Permission denied: ${binary}`);
64
+ console.error("Try: chmod +x " + binary);
65
+ process.exit(1);
66
+ }
67
+ console.error(`Failed to execute wt: ${err.message}`);
68
+ process.exit(1);
69
+ }
package/install.js ADDED
@@ -0,0 +1,61 @@
1
+ // ============================================================
2
+ // Postinstall: Verify Platform Package & Setup Shell Integration
3
+ // ============================================================
4
+ //
5
+ // Runs after `npm install -g @zelanton/agent-workspace`. Responsibilities:
6
+ // 1. Resolve the platform-specific binary that npm installed as an
7
+ // optional dependency.
8
+ // 2. Invoke `wt setup` to install shell-wrapper functions in the user's
9
+ // rc files (the wrapper is required for `wt cd`, `wt new`, etc. to
10
+ // actually change shell cwd).
11
+ // 3. Stamp the install-channel marker file so `wt update` knows to
12
+ // re-invoke npm rather than self-replace from GitHub Releases.
13
+
14
+ const { execFileSync } = require("child_process");
15
+ const { join } = require("path");
16
+ const fs = require("fs");
17
+ const os = require("os");
18
+
19
+ const PLATFORMS = {
20
+ "darwin-arm64": "@zelanton/agent-workspace-darwin-arm64",
21
+ "linux-x64": "@zelanton/agent-workspace-linux-x64",
22
+ "win32-x64": "@zelanton/agent-workspace-win32-x64",
23
+ };
24
+
25
+ const key = `${process.platform}-${process.arch}`;
26
+ const pkg = PLATFORMS[key];
27
+
28
+ if (!pkg) {
29
+ console.warn(`[agent-workspace] Warning: Unsupported platform ${key}`);
30
+ console.warn(`[agent-workspace] Supported: ${Object.keys(PLATFORMS).join(", ")}`);
31
+ process.exit(0);
32
+ }
33
+
34
+ let pkgJsonPath;
35
+ try {
36
+ pkgJsonPath = require.resolve(`${pkg}/package.json`);
37
+ } catch {
38
+ console.warn(`[agent-workspace] Warning: Platform package ${pkg} not installed`);
39
+ console.warn(`[agent-workspace] This may happen if npm failed to install optional dependencies`);
40
+ process.exit(0);
41
+ }
42
+
43
+ // Run 'wt setup' to install shell integration
44
+ const exe = process.platform === "win32" ? "wt.exe" : "wt";
45
+ const binaryPath = join(pkgJsonPath, "..", "bin", exe);
46
+ try {
47
+ execFileSync(binaryPath, ["setup"], { stdio: "inherit" });
48
+ } catch {
49
+ console.warn("[agent-workspace] Auto-setup failed. Run 'wt setup' manually.");
50
+ }
51
+
52
+ // Stamp the install-channel marker so `wt update` re-invokes npm rather than
53
+ // self-replacing from GitHub Releases. Honors AGENT_WORKSPACE_DIR to match the
54
+ // Rust side's Config::base_dir() resolution.
55
+ try {
56
+ const baseDir = process.env.AGENT_WORKSPACE_DIR || join(os.homedir(), ".agent-workspace");
57
+ fs.mkdirSync(baseDir, { recursive: true });
58
+ fs.writeFileSync(join(baseDir, "install_channel"), "npm");
59
+ } catch (err) {
60
+ console.warn(`[agent-workspace] Could not write install_channel marker: ${err.message}`);
61
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@zelanton/agent-workspace",
3
+ "version": "0.12.0",
4
+ "description": "Git worktree workflow tool for AI agents",
5
+ "keywords": ["cli", "git", "worktree", "ai", "agent"],
6
+ "license": "MIT",
7
+ "author": "ZelAnton",
8
+ "homepage": "https://github.com/ZelAnton/agent-workspace",
9
+ "bugs": {
10
+ "url": "https://github.com/ZelAnton/agent-workspace/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/ZelAnton/agent-workspace.git"
15
+ },
16
+ "bin": {
17
+ "wt": "bin/wt.js"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "install.js"
22
+ ],
23
+ "scripts": {
24
+ "postinstall": "node install.js"
25
+ },
26
+ "optionalDependencies": {
27
+ "@zelanton/agent-workspace-darwin-arm64": "0.12.0",
28
+ "@zelanton/agent-workspace-linux-x64": "0.12.0",
29
+ "@zelanton/agent-workspace-win32-x64": "0.12.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=14"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }