@zerwiz/sessrumnir 0.1.12 → 0.1.13
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/bin/sessrumnir.js +166 -10
- package/package.json +1 -1
package/bin/sessrumnir.js
CHANGED
|
@@ -1,11 +1,167 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* pi-desktop — CLI launcher for Pi Desktop GUI
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* pi-desktop # Launch the app
|
|
8
|
+
* pi-desktop --help # Show help
|
|
9
|
+
* pi-desktop --version # Show version
|
|
10
|
+
* pi-desktop /path/to/dir # Launch with workspace
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { spawn } = require('child_process')
|
|
14
|
+
const { existsSync } = require('fs')
|
|
15
|
+
const { join, resolve } = require('path')
|
|
16
|
+
|
|
17
|
+
const VERSION = require('../package.json').version
|
|
18
|
+
|
|
19
|
+
// ─── Parse args ──────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
const args = process.argv.slice(2)
|
|
22
|
+
|
|
23
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
24
|
+
console.log(`
|
|
25
|
+
pi-desktop v${VERSION} — Desktop GUI for the Pi coding agent
|
|
26
|
+
|
|
27
|
+
Usage:
|
|
28
|
+
pi-desktop Launch the app
|
|
29
|
+
pi-desktop <path> Launch with workspace directory
|
|
30
|
+
pi-desktop --help Show this help
|
|
31
|
+
pi-desktop --version Show version
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
pi-desktop # Launch with default workspace
|
|
35
|
+
pi-desktop ~/my-project # Launch with specific project
|
|
36
|
+
pi-desktop . # Launch with current directory
|
|
37
|
+
|
|
38
|
+
Install:
|
|
39
|
+
See https://github.com/FaqFirebase/pi-desktop for releases
|
|
40
|
+
and build-from-source instructions.
|
|
41
|
+
|
|
42
|
+
The app requires Pi to be installed:
|
|
43
|
+
curl -fsSL https://pi.dev/install.sh | sh
|
|
44
|
+
# or
|
|
45
|
+
npm install -g @earendil-works/pi-coding-agent
|
|
46
|
+
`)
|
|
47
|
+
process.exit(0)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
51
|
+
console.log(VERSION)
|
|
52
|
+
process.exit(0)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── Find Electron binary ────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
function findElectron() {
|
|
58
|
+
// Try to find electron from the package's own node_modules
|
|
59
|
+
const candidates = [
|
|
60
|
+
join(__dirname, '..', 'node_modules', 'electron', 'dist', 'electron'),
|
|
61
|
+
join(__dirname, '..', 'node_modules', '.bin', 'electron'),
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
for (const candidate of candidates) {
|
|
65
|
+
if (existsSync(candidate)) {
|
|
66
|
+
return candidate
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Try to find globally installed electron
|
|
71
|
+
try {
|
|
72
|
+
const { execSync } = require('child_process')
|
|
73
|
+
const electronPath = execSync('which electron', { encoding: 'utf8', timeout: 5000 }).trim()
|
|
74
|
+
if (existsSync(electronPath)) {
|
|
75
|
+
return electronPath
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
// Not found
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.error('Error: Electron not found. Please install dependencies:')
|
|
82
|
+
console.error(' cd ' + join(__dirname, '..') + ' && npm install')
|
|
83
|
+
process.exit(1)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ─── Find app resources ─────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
function findAppResources() {
|
|
89
|
+
// Packaged app: resources are in app.asar or app directory
|
|
90
|
+
const packagedPaths = [
|
|
91
|
+
join(__dirname, '..', 'app.asar'),
|
|
92
|
+
join(__dirname, '..', 'app'),
|
|
93
|
+
join(__dirname, '..', 'resources', 'app.asar'),
|
|
94
|
+
join(__dirname, '..', 'resources', 'app'),
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
for (const p of packagedPaths) {
|
|
98
|
+
if (existsSync(p)) {
|
|
99
|
+
return p
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Development: use the project root (electron-vite builds to out/)
|
|
104
|
+
const devPath = join(__dirname, '..')
|
|
105
|
+
if (existsSync(join(devPath, 'out', 'main', 'index.js'))) {
|
|
106
|
+
return devPath
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Build first
|
|
110
|
+
console.error('Error: App not built. Run "npm run build" first.')
|
|
111
|
+
process.exit(1)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ─── Launch ──────────────────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
function launch() {
|
|
117
|
+
const electronPath = findElectron()
|
|
118
|
+
const appPath = findAppResources()
|
|
119
|
+
|
|
120
|
+
// Resolve workspace path if provided
|
|
121
|
+
let workspacePath = null
|
|
122
|
+
if (args.length > 0 && !args[0].startsWith('-')) {
|
|
123
|
+
workspacePath = resolve(args[0])
|
|
124
|
+
if (!existsSync(workspacePath)) {
|
|
125
|
+
console.error(`Error: Path does not exist: ${workspacePath}`)
|
|
126
|
+
process.exit(1)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Build electron args.
|
|
131
|
+
// --no-sandbox is required so Pi subprocesses can spawn.
|
|
132
|
+
// --disable-gpu is intentionally NOT passed by default — it breaks window
|
|
133
|
+
// creation on some Wayland + AMD setups. If the GPU process crashes on your
|
|
134
|
+
// system, re-add it locally as an escape hatch.
|
|
135
|
+
const electronArgs = [
|
|
136
|
+
appPath,
|
|
137
|
+
'--no-sandbox',
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
// Pass workspace path via environment variable
|
|
141
|
+
const env = { ...process.env }
|
|
142
|
+
if (workspacePath) {
|
|
143
|
+
env.PI_DESKTOP_WORKSPACE = workspacePath
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Launch Electron
|
|
147
|
+
const child = spawn(electronPath, electronArgs, {
|
|
148
|
+
stdio: 'inherit',
|
|
149
|
+
env,
|
|
150
|
+
detached: false,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
child.on('error', (err) => {
|
|
154
|
+
console.error('Failed to start Pi Desktop:', err.message)
|
|
155
|
+
process.exit(1)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
child.on('exit', (code) => {
|
|
159
|
+
process.exit(code ?? 0)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
// Forward signals
|
|
163
|
+
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
164
|
+
process.on('SIGTERM', () => child.kill('SIGTERM'))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
launch()
|