@flintttan/hapi 0.5.43 → 0.5.44

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 (2) hide show
  1. package/bin/hapi.cjs +159 -42
  2. package/package.json +6 -6
package/bin/hapi.cjs CHANGED
@@ -1,48 +1,165 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { execFileSync } = require('child_process');
4
- const path = require('path');
3
+ const { execFileSync } = require('child_process')
4
+ const path = require('path')
5
5
 
6
- const platform = process.platform;
7
- const arch = process.arch;
8
- const pkgName = `@flintttan/hapi-${platform}-${arch}`;
6
+ const platform = process.platform
7
+ const arch = process.arch
8
+ const PACKAGE_NAME = '@flintttan/hapi'
9
+ const RELEASE_URL = 'https://github.com/flintttan/hapi/releases'
10
+ const OFFICIAL_NPM_REGISTRY = 'https://registry.npmjs.org'
11
+ const SUPPORTED_PLATFORMS = [
12
+ {
13
+ key: 'darwin-arm64',
14
+ label: 'darwin-arm64 (macOS Apple Silicon)'
15
+ },
16
+ {
17
+ key: 'darwin-x64',
18
+ label: 'darwin-x64 (macOS Intel)'
19
+ },
20
+ {
21
+ key: 'linux-arm64',
22
+ label: 'linux-arm64'
23
+ },
24
+ {
25
+ key: 'linux-x64',
26
+ label: 'linux-x64'
27
+ },
28
+ {
29
+ key: 'win32-x64',
30
+ label: 'win32-x64'
31
+ }
32
+ ]
33
+
34
+ function getPlatformKey(platformName = platform, archName = arch) {
35
+ return `${platformName}-${archName}`
36
+ }
37
+
38
+ function getPlatformPackageName(platformName = platform, archName = arch) {
39
+ return `${PACKAGE_NAME}-${platformName}-${archName}`
40
+ }
41
+
42
+ function isSupportedPlatform(platformName = platform, archName = arch) {
43
+ return SUPPORTED_PLATFORMS.some((item) => item.key === getPlatformKey(platformName, archName))
44
+ }
45
+
46
+ function getBinaryPath(platformName = platform, archName = arch) {
47
+ const pkgName = getPlatformPackageName(platformName, archName)
9
48
 
10
- function getBinaryPath() {
11
49
  try {
12
- // Try to find the platform-specific package
13
- const pkgPath = require.resolve(`${pkgName}/package.json`);
14
- const binName = platform === 'win32' ? 'hapi.exe' : 'hapi';
15
- return path.join(path.dirname(pkgPath), 'bin', binName);
16
- } catch (e) {
17
- return null;
18
- }
19
- }
20
-
21
- const binPath = getBinaryPath();
22
-
23
- if (!binPath) {
24
- console.error(`Unsupported platform: ${platform}-${arch}`);
25
- console.error('');
26
- console.error('Supported platforms:');
27
- console.error(' - darwin-arm64 (macOS Apple Silicon)');
28
- console.error(' - darwin-x64 (macOS Intel)');
29
- console.error(' - linux-arm64');
30
- console.error(' - linux-x64');
31
- console.error(' - win32-x64');
32
- console.error('');
33
- console.error('You can download the binary manually from:');
34
- console.error(' https://github.com/flintttan/hapi/releases');
35
- process.exit(1);
36
- }
37
-
38
- try {
39
- execFileSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
40
- } catch (e) {
41
- // If the binary execution fails, exit with the same code
42
- if (e.status !== undefined) {
43
- process.exit(e.status);
44
- }
45
- // For other errors (e.g., binary not found), print and exit
46
- console.error(`Failed to execute ${binPath}:`, e.message);
47
- process.exit(1);
50
+ const pkgPath = require.resolve(`${pkgName}/package.json`)
51
+ const binName = platformName === 'win32' ? 'hapi.exe' : 'hapi'
52
+ return path.join(path.dirname(pkgPath), 'bin', binName)
53
+ } catch {
54
+ return null
55
+ }
56
+ }
57
+
58
+ function formatCommand(binPath, args) {
59
+ return [binPath, ...args].map((arg) => JSON.stringify(String(arg))).join(' ')
60
+ }
61
+
62
+ function normalizeExecError(error) {
63
+ return {
64
+ status: typeof error?.status === 'number' ? error.status : null,
65
+ signal: typeof error?.signal === 'string' ? error.signal : null,
66
+ message: error?.message ? String(error.message) : null
67
+ }
68
+ }
69
+
70
+ function reportExecutionFailure(error, binPath, args, log = console.error) {
71
+ const { status, signal, message } = normalizeExecError(error)
72
+
73
+ log(`Failed to execute: ${formatCommand(binPath, args)}`)
74
+
75
+ if (signal) {
76
+ log(`Binary terminated by signal ${signal}.`)
77
+ }
78
+
79
+ if (status !== null) {
80
+ log(`Binary exited with status ${status}.`)
81
+ }
82
+
83
+ if (message) {
84
+ log(message)
85
+ }
86
+
87
+ return { status, signal }
88
+ }
89
+
90
+ function reportUnsupportedPlatform(platformName = platform, archName = arch, log = console.error) {
91
+ log(`Unsupported platform: ${platformName}-${archName}`)
92
+ log('')
93
+ log('Supported platforms:')
94
+ for (const item of SUPPORTED_PLATFORMS) {
95
+ log(` - ${item.label}`)
96
+ }
97
+ log('')
98
+ log('You can download the binary manually from:')
99
+ log(` ${RELEASE_URL}`)
100
+ }
101
+
102
+ function reportMissingPlatformPackage(platformName = platform, archName = arch, log = console.error) {
103
+ const platformPackage = getPlatformPackageName(platformName, archName)
104
+ log(`Missing platform package: ${platformPackage}`)
105
+ log('')
106
+ log(`Detected platform ${platformName}-${archName} is supported, but the platform binary package was not installed.`)
107
+ log('This may happen when using a registry mirror that has not synced all optionalDependencies.')
108
+ log('')
109
+ log('Try reinstalling with the official npm registry:')
110
+ log(` npm install -g ${PACKAGE_NAME} --registry=${OFFICIAL_NPM_REGISTRY}`)
111
+ log('')
112
+ log('Or download the binary manually from:')
113
+ log(` ${RELEASE_URL}`)
114
+ }
115
+
116
+ function main() {
117
+ if (!isSupportedPlatform()) {
118
+ reportUnsupportedPlatform()
119
+ process.exit(1)
120
+ }
121
+
122
+ const binPath = getBinaryPath()
123
+ if (!binPath) {
124
+ reportMissingPlatformPackage()
125
+ process.exit(1)
126
+ }
127
+
128
+ const args = process.argv.slice(2)
129
+
130
+ try {
131
+ execFileSync(binPath, args, { stdio: 'inherit' })
132
+ } catch (error) {
133
+ const { status, signal } = reportExecutionFailure(error, binPath, args)
134
+
135
+ if (status !== null) {
136
+ process.exit(status)
137
+ }
138
+
139
+ if (signal) {
140
+ try {
141
+ process.kill(process.pid, signal)
142
+ } catch {
143
+ // ignore unsupported/invalid signal names on this platform
144
+ }
145
+ }
146
+
147
+ process.exit(1)
148
+ }
149
+ }
150
+
151
+ if (require.main === module) {
152
+ main()
153
+ }
154
+
155
+ module.exports = {
156
+ formatCommand,
157
+ getBinaryPath,
158
+ getPlatformKey,
159
+ getPlatformPackageName,
160
+ isSupportedPlatform,
161
+ normalizeExecError,
162
+ reportExecutionFailure,
163
+ reportMissingPlatformPackage,
164
+ reportUnsupportedPlatform
48
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flintttan/hapi",
3
- "version": "0.5.43",
3
+ "version": "0.5.44",
4
4
  "description": "App for agentic coding - access coding agent anywhere",
5
5
  "author": "Kirill Dubovitskiy & weishu",
6
6
  "license": "AGPL-3.0-only",
@@ -20,10 +20,10 @@
20
20
  "NOTICE"
21
21
  ],
22
22
  "optionalDependencies": {
23
- "@flintttan/hapi-darwin-arm64": "0.5.43",
24
- "@flintttan/hapi-darwin-x64": "0.5.43",
25
- "@flintttan/hapi-linux-arm64": "0.5.43",
26
- "@flintttan/hapi-linux-x64": "0.5.43",
27
- "@flintttan/hapi-win32-x64": "0.5.43"
23
+ "@flintttan/hapi-darwin-arm64": "0.5.44",
24
+ "@flintttan/hapi-darwin-x64": "0.5.44",
25
+ "@flintttan/hapi-linux-arm64": "0.5.44",
26
+ "@flintttan/hapi-linux-x64": "0.5.44",
27
+ "@flintttan/hapi-win32-x64": "0.5.44"
28
28
  }
29
29
  }