@mudramo/mudcode 1.0.1 → 1.0.4

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/mudcode +199 -1
  2. package/package.json +6 -4
  3. package/bin/discode +0 -199
package/bin/mudcode CHANGED
@@ -1,3 +1,201 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import './discode';
3
+ import childProcess from 'child_process';
4
+ import fs from 'fs';
5
+ import os from 'os';
6
+ import path from 'path';
7
+ import { fileURLToPath } from 'url';
8
+ import { createRequire } from 'module';
9
+
10
+ const require = createRequire(import.meta.url);
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+ const selfPackageName = readSelfPackageName();
14
+
15
+ function normalizeScope(raw) {
16
+ const trimmed = (raw || '').trim();
17
+ if (!trimmed) return '';
18
+ return trimmed.startsWith('@') ? trimmed : `@${trimmed}`;
19
+ }
20
+
21
+ function readSelfPackageName() {
22
+ const candidates = [
23
+ path.join(__dirname, '..', 'package.json'),
24
+ path.join(__dirname, '..', '..', 'package.json'),
25
+ ];
26
+
27
+ for (const candidate of candidates) {
28
+ try {
29
+ const parsed = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
30
+ if (typeof parsed?.name === 'string' && parsed.name.length > 0) {
31
+ return parsed.name;
32
+ }
33
+ } catch {
34
+ // continue
35
+ }
36
+ }
37
+
38
+ return '';
39
+ }
40
+
41
+ function resolvePackageScope() {
42
+ const envScope = normalizeScope(process.env.DISCODE_NPM_SCOPE);
43
+ if (envScope) return envScope;
44
+
45
+ const packageName = readSelfPackageName();
46
+ const match = packageName.match(/^(@[^/]+)\//);
47
+ if (match) return match[1];
48
+
49
+ return '@mudramo';
50
+ }
51
+
52
+ const packageScope = resolvePackageScope();
53
+
54
+ function spawnAndExit(command, args) {
55
+ const result = childProcess.spawnSync(command, args, {
56
+ stdio: 'inherit',
57
+ env: {
58
+ ...process.env,
59
+ ...(selfPackageName ? { DISCODE_NPM_PACKAGE: selfPackageName } : {}),
60
+ },
61
+ });
62
+ if (result.error) {
63
+ console.error(result.error.message);
64
+ process.exit(1);
65
+ }
66
+ process.exit(typeof result.status === 'number' ? result.status : 0);
67
+ }
68
+
69
+ function spawnAndExitWithEnv(command, args, envPatch) {
70
+ const result = childProcess.spawnSync(command, args, {
71
+ stdio: 'inherit',
72
+ env: {
73
+ ...process.env,
74
+ ...(selfPackageName ? { DISCODE_NPM_PACKAGE: selfPackageName } : {}),
75
+ ...envPatch,
76
+ },
77
+ });
78
+ if (result.error) {
79
+ console.error(result.error.message);
80
+ process.exit(1);
81
+ }
82
+ process.exit(typeof result.status === 'number' ? result.status : 0);
83
+ }
84
+
85
+ function isMuslLinux() {
86
+ if (os.platform() !== 'linux') return false;
87
+ if (fs.existsSync('/etc/alpine-release')) return true;
88
+ try {
89
+ const out = childProcess.execSync('ldd --version 2>&1', { encoding: 'utf-8' });
90
+ return out.toLowerCase().includes('musl');
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+
96
+ function needsBaselineX64() {
97
+ if (os.arch() !== 'x64') return false;
98
+ if (os.platform() === 'linux') {
99
+ try {
100
+ const cpuinfo = fs.readFileSync('/proc/cpuinfo', 'utf-8').toLowerCase();
101
+ return !cpuinfo.includes('avx2');
102
+ } catch {
103
+ return false;
104
+ }
105
+ }
106
+ if (os.platform() === 'darwin') {
107
+ try {
108
+ const out = childProcess.execSync('sysctl -n hw.optional.avx2_0', { encoding: 'utf-8' }).trim();
109
+ return out !== '1';
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+ return false;
115
+ }
116
+
117
+ function packageCandidates() {
118
+ const platformMap = {
119
+ darwin: 'darwin',
120
+ linux: 'linux',
121
+ win32: 'windows',
122
+ };
123
+ const archMap = {
124
+ x64: 'x64',
125
+ arm64: 'arm64',
126
+ };
127
+ const platform = platformMap[os.platform()] || os.platform();
128
+ const arch = archMap[os.arch()] || os.arch();
129
+ const scopedBase = `${packageScope}/mudcode-${platform}-${arch}`;
130
+
131
+ const candidates = [];
132
+ if (platform === 'linux' && isMuslLinux()) {
133
+ if (arch === 'x64' && needsBaselineX64()) candidates.push(`${scopedBase}-baseline-musl`);
134
+ candidates.push(`${scopedBase}-musl`);
135
+ }
136
+ if (arch === 'x64' && needsBaselineX64()) candidates.push(`${scopedBase}-baseline`);
137
+ candidates.push(scopedBase);
138
+ return candidates;
139
+ }
140
+
141
+ function findPlatformBinary() {
142
+ const binaryName = os.platform() === 'win32' ? 'mudcode.exe' : 'mudcode';
143
+ for (const pkg of packageCandidates()) {
144
+ try {
145
+ const packageJsonPath = require.resolve(`${pkg}/package.json`);
146
+ const packageDir = path.dirname(packageJsonPath);
147
+ const binaryPath = path.join(packageDir, 'bin', binaryName);
148
+ if (fs.existsSync(binaryPath)) {
149
+ return { binaryPath, packageDir };
150
+ }
151
+ } catch {
152
+ // try next package candidate
153
+ }
154
+ }
155
+ return null;
156
+ }
157
+
158
+ function resolveRustSidecarFromDir(dir) {
159
+ const sidecarName = os.platform() === 'win32' ? 'discode-rs.exe' : 'discode-rs';
160
+ const sidecarPath = path.join(dir, sidecarName);
161
+ return fs.existsSync(sidecarPath) ? sidecarPath : null;
162
+ }
163
+
164
+ function findLocalDevEntrypoint() {
165
+ const scriptDir = __dirname;
166
+ const candidates = [
167
+ path.join(scriptDir, '..', 'dist', 'bin', 'mudcode.js'),
168
+ path.join(scriptDir, '..', 'dist', 'bin', 'discode.js'),
169
+ path.join(scriptDir, '..', '..', 'dist', 'bin', 'mudcode.js'),
170
+ path.join(scriptDir, '..', '..', 'dist', 'bin', 'discode.js'),
171
+ ];
172
+ return candidates.find((file) => fs.existsSync(file)) || null;
173
+ }
174
+
175
+ const explicitBinary = process.env.DISCODE_BIN_PATH;
176
+ if (explicitBinary) {
177
+ const rustSidecar = resolveRustSidecarFromDir(path.dirname(explicitBinary));
178
+ if (rustSidecar && !process.env.DISCODE_RS_BIN) {
179
+ spawnAndExitWithEnv(explicitBinary, process.argv.slice(2), { DISCODE_RS_BIN: rustSidecar });
180
+ }
181
+ spawnAndExit(explicitBinary, process.argv.slice(2));
182
+ }
183
+
184
+ const platformBinary = findPlatformBinary();
185
+ if (platformBinary) {
186
+ const rustSidecar = resolveRustSidecarFromDir(path.join(platformBinary.packageDir, 'bin'));
187
+ if (rustSidecar && !process.env.DISCODE_RS_BIN) {
188
+ spawnAndExitWithEnv(platformBinary.binaryPath, process.argv.slice(2), { DISCODE_RS_BIN: rustSidecar });
189
+ }
190
+ spawnAndExit(platformBinary.binaryPath, process.argv.slice(2));
191
+ }
192
+
193
+ const devEntrypoint = findLocalDevEntrypoint();
194
+ if (devEntrypoint) {
195
+ spawnAndExit(process.execPath, [devEntrypoint, ...process.argv.slice(2)]);
196
+ }
197
+
198
+ const packageName = readSelfPackageName() || `${packageScope}/mudcode`;
199
+ console.error('No runnable mudcode binary found for this platform.');
200
+ console.error(`Try reinstalling with: npm i -g ${packageName}`);
201
+ process.exit(1);
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@mudramo/mudcode",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "Bridge AI agent outputs to Discord via Claude Code hooks and tmux",
5
5
  "license": "MIT",
6
6
  "bin": {
7
- "mudcode": "bin/mudcode",
8
- "discode": "bin/discode"
7
+ "mudcode": "bin/mudcode"
9
8
  },
10
9
  "scripts": {
11
10
  "postinstall": "node ./postinstall.mjs"
12
11
  },
13
12
  "optionalDependencies": {
14
- "@mudramo/discode-linux-x64": "1.0.1"
13
+ "@mudramo/mudcode-linux-x64": "1.0.4",
14
+ "@mudramo/mudcode-linux-x64-baseline": "1.0.4",
15
+ "@mudramo/mudcode-linux-x64-musl": "1.0.4",
16
+ "@mudramo/mudcode-linux-x64-baseline-musl": "1.0.4"
15
17
  }
16
18
  }
package/bin/discode DELETED
@@ -1,199 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import childProcess from 'child_process';
4
- import fs from 'fs';
5
- import os from 'os';
6
- import path from 'path';
7
- import { fileURLToPath } from 'url';
8
- import { createRequire } from 'module';
9
-
10
- const require = createRequire(import.meta.url);
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = path.dirname(__filename);
13
- const selfPackageName = readSelfPackageName();
14
-
15
- function normalizeScope(raw) {
16
- const trimmed = (raw || '').trim();
17
- if (!trimmed) return '';
18
- return trimmed.startsWith('@') ? trimmed : `@${trimmed}`;
19
- }
20
-
21
- function readSelfPackageName() {
22
- const candidates = [
23
- path.join(__dirname, '..', 'package.json'),
24
- path.join(__dirname, '..', '..', 'package.json'),
25
- ];
26
-
27
- for (const candidate of candidates) {
28
- try {
29
- const parsed = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
30
- if (typeof parsed?.name === 'string' && parsed.name.length > 0) {
31
- return parsed.name;
32
- }
33
- } catch {
34
- // continue
35
- }
36
- }
37
-
38
- return '';
39
- }
40
-
41
- function resolvePackageScope() {
42
- const envScope = normalizeScope(process.env.DISCODE_NPM_SCOPE);
43
- if (envScope) return envScope;
44
-
45
- const packageName = readSelfPackageName();
46
- const match = packageName.match(/^(@[^/]+)\//);
47
- if (match) return match[1];
48
-
49
- return '@siisee11';
50
- }
51
-
52
- const packageScope = resolvePackageScope();
53
-
54
- function spawnAndExit(command, args) {
55
- const result = childProcess.spawnSync(command, args, {
56
- stdio: 'inherit',
57
- env: {
58
- ...process.env,
59
- ...(selfPackageName ? { DISCODE_NPM_PACKAGE: selfPackageName } : {}),
60
- },
61
- });
62
- if (result.error) {
63
- console.error(result.error.message);
64
- process.exit(1);
65
- }
66
- process.exit(typeof result.status === 'number' ? result.status : 0);
67
- }
68
-
69
- function spawnAndExitWithEnv(command, args, envPatch) {
70
- const result = childProcess.spawnSync(command, args, {
71
- stdio: 'inherit',
72
- env: {
73
- ...process.env,
74
- ...(selfPackageName ? { DISCODE_NPM_PACKAGE: selfPackageName } : {}),
75
- ...envPatch,
76
- },
77
- });
78
- if (result.error) {
79
- console.error(result.error.message);
80
- process.exit(1);
81
- }
82
- process.exit(typeof result.status === 'number' ? result.status : 0);
83
- }
84
-
85
- function isMuslLinux() {
86
- if (os.platform() !== 'linux') return false;
87
- if (fs.existsSync('/etc/alpine-release')) return true;
88
- try {
89
- const out = childProcess.execSync('ldd --version 2>&1', { encoding: 'utf-8' });
90
- return out.toLowerCase().includes('musl');
91
- } catch {
92
- return false;
93
- }
94
- }
95
-
96
- function needsBaselineX64() {
97
- if (os.arch() !== 'x64') return false;
98
- if (os.platform() === 'linux') {
99
- try {
100
- const cpuinfo = fs.readFileSync('/proc/cpuinfo', 'utf-8').toLowerCase();
101
- return !cpuinfo.includes('avx2');
102
- } catch {
103
- return false;
104
- }
105
- }
106
- if (os.platform() === 'darwin') {
107
- try {
108
- const out = childProcess.execSync('sysctl -n hw.optional.avx2_0', { encoding: 'utf-8' }).trim();
109
- return out !== '1';
110
- } catch {
111
- return false;
112
- }
113
- }
114
- return false;
115
- }
116
-
117
- function packageCandidates() {
118
- const platformMap = {
119
- darwin: 'darwin',
120
- linux: 'linux',
121
- win32: 'windows',
122
- };
123
- const archMap = {
124
- x64: 'x64',
125
- arm64: 'arm64',
126
- };
127
- const platform = platformMap[os.platform()] || os.platform();
128
- const arch = archMap[os.arch()] || os.arch();
129
- const scopedBase = `${packageScope}/discode-${platform}-${arch}`;
130
-
131
- const candidates = [];
132
- if (platform === 'linux' && isMuslLinux()) {
133
- if (arch === 'x64' && needsBaselineX64()) candidates.push(`${scopedBase}-baseline-musl`);
134
- candidates.push(`${scopedBase}-musl`);
135
- }
136
- if (arch === 'x64' && needsBaselineX64()) candidates.push(`${scopedBase}-baseline`);
137
- candidates.push(scopedBase);
138
- return candidates;
139
- }
140
-
141
- function findPlatformBinary() {
142
- const binaryName = os.platform() === 'win32' ? 'discode.exe' : 'discode';
143
- for (const pkg of packageCandidates()) {
144
- try {
145
- const packageJsonPath = require.resolve(`${pkg}/package.json`);
146
- const packageDir = path.dirname(packageJsonPath);
147
- const binaryPath = path.join(packageDir, 'bin', binaryName);
148
- if (fs.existsSync(binaryPath)) {
149
- return { binaryPath, packageDir };
150
- }
151
- } catch {
152
- // try next package candidate
153
- }
154
- }
155
- return null;
156
- }
157
-
158
- function resolveRustSidecarFromDir(dir) {
159
- const sidecarName = os.platform() === 'win32' ? 'discode-rs.exe' : 'discode-rs';
160
- const sidecarPath = path.join(dir, sidecarName);
161
- return fs.existsSync(sidecarPath) ? sidecarPath : null;
162
- }
163
-
164
- function findLocalDevEntrypoint() {
165
- const scriptDir = __dirname;
166
- const candidates = [
167
- path.join(scriptDir, '..', 'dist', 'bin', 'discode.js'),
168
- path.join(scriptDir, '..', '..', 'dist', 'bin', 'discode.js'),
169
- ];
170
- return candidates.find((file) => fs.existsSync(file)) || null;
171
- }
172
-
173
- const explicitBinary = process.env.DISCODE_BIN_PATH;
174
- if (explicitBinary) {
175
- const rustSidecar = resolveRustSidecarFromDir(path.dirname(explicitBinary));
176
- if (rustSidecar && !process.env.DISCODE_RS_BIN) {
177
- spawnAndExitWithEnv(explicitBinary, process.argv.slice(2), { DISCODE_RS_BIN: rustSidecar });
178
- }
179
- spawnAndExit(explicitBinary, process.argv.slice(2));
180
- }
181
-
182
- const platformBinary = findPlatformBinary();
183
- if (platformBinary) {
184
- const rustSidecar = resolveRustSidecarFromDir(path.join(platformBinary.packageDir, 'bin'));
185
- if (rustSidecar && !process.env.DISCODE_RS_BIN) {
186
- spawnAndExitWithEnv(platformBinary.binaryPath, process.argv.slice(2), { DISCODE_RS_BIN: rustSidecar });
187
- }
188
- spawnAndExit(platformBinary.binaryPath, process.argv.slice(2));
189
- }
190
-
191
- const devEntrypoint = findLocalDevEntrypoint();
192
- if (devEntrypoint) {
193
- spawnAndExit(process.execPath, [devEntrypoint, ...process.argv.slice(2)]);
194
- }
195
-
196
- const packageName = readSelfPackageName() || `${packageScope}/mudcode`;
197
- console.error('No runnable mudcode binary found for this platform.');
198
- console.error(`Try reinstalling with: npm i -g ${packageName}`);
199
- process.exit(1);