jbai-cli 1.9.6 → 2.1.1
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/README.md +34 -38
- package/bin/jbai-claude-opus.js +6 -0
- package/bin/jbai-claude-sonnet.js +6 -0
- package/bin/jbai-claude.js +3 -17
- package/bin/jbai-codex-5.2.js +6 -0
- package/bin/jbai-codex-5.3.js +6 -0
- package/bin/jbai-codex-5.4.js +6 -0
- package/bin/jbai-codex-rockhopper.js +6 -0
- package/bin/jbai-codex.js +13 -17
- package/bin/jbai-continue.js +3 -17
- package/bin/jbai-council.js +1 -1
- package/bin/jbai-gemini-3.1.js +6 -0
- package/bin/jbai-gemini-supernova.js +6 -0
- package/bin/jbai-gemini.js +3 -17
- package/bin/jbai-goose.js +3 -18
- package/bin/jbai-opencode-deepseek.js +6 -0
- package/bin/jbai-opencode-grok.js +6 -0
- package/bin/jbai-opencode-rockhopper.js +6 -0
- package/bin/jbai-opencode.js +6 -51
- package/bin/jbai-proxy.js +27 -5
- package/bin/jbai.js +337 -122
- package/lib/completions.js +255 -0
- package/lib/config.js +18 -82
- package/lib/model-list.js +2 -2
- package/lib/postinstall.js +3 -23
- package/lib/shortcut.js +47 -0
- package/package.json +13 -4
- package/lib/handoff.js +0 -152
- package/lib/interactive-handoff.js +0 -220
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const { spawn } = require('child_process');
|
|
3
|
-
const pty = require('node-pty');
|
|
4
|
-
const { createHandoff } = require('./handoff');
|
|
5
|
-
|
|
6
|
-
const DEFAULT_TRIGGER = '\x1d'; // Ctrl+]
|
|
7
|
-
const DEFAULT_TRIGGER_LABEL = 'Ctrl+]';
|
|
8
|
-
|
|
9
|
-
function stripHandoffFlag(args) {
|
|
10
|
-
const cleaned = [];
|
|
11
|
-
let disabled = false;
|
|
12
|
-
for (const arg of args) {
|
|
13
|
-
if (arg === '--no-handoff') {
|
|
14
|
-
disabled = true;
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
cleaned.push(arg);
|
|
18
|
-
}
|
|
19
|
-
return { args: cleaned, disabled };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isPrintableChar(char) {
|
|
23
|
-
const code = char.charCodeAt(0);
|
|
24
|
-
return code >= 32 && code !== 127;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function shouldIgnoreLine(line) {
|
|
28
|
-
const trimmed = line.trim();
|
|
29
|
-
if (!trimmed) return true;
|
|
30
|
-
if (trimmed.startsWith('/')) return true;
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function buildTrigger() {
|
|
35
|
-
const trigger = process.env.JBAI_HANDOFF_TRIGGER || DEFAULT_TRIGGER;
|
|
36
|
-
const label = process.env.JBAI_HANDOFF_TRIGGER_LABEL || DEFAULT_TRIGGER_LABEL;
|
|
37
|
-
return { trigger, label };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function runWithHandoff({
|
|
41
|
-
command,
|
|
42
|
-
args,
|
|
43
|
-
env,
|
|
44
|
-
toolName,
|
|
45
|
-
handoffDefaults = {},
|
|
46
|
-
}) {
|
|
47
|
-
const { trigger, label } = buildTrigger();
|
|
48
|
-
const canUsePty = process.stdin.isTTY && process.stdout.isTTY;
|
|
49
|
-
|
|
50
|
-
if (!canUsePty || handoffDefaults.enabled === false) {
|
|
51
|
-
const child = spawn(command, args, { stdio: 'inherit', env });
|
|
52
|
-
return child;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
process.stderr.write(`ℹ️ Handoff trigger: ${label}\n`);
|
|
56
|
-
|
|
57
|
-
let ptyProcess;
|
|
58
|
-
try {
|
|
59
|
-
ptyProcess = pty.spawn(command, args, {
|
|
60
|
-
name: 'xterm-256color',
|
|
61
|
-
cols: process.stdout.columns || 80,
|
|
62
|
-
rows: process.stdout.rows || 24,
|
|
63
|
-
cwd: process.cwd(),
|
|
64
|
-
env,
|
|
65
|
-
});
|
|
66
|
-
} catch (err) {
|
|
67
|
-
// node-pty throws synchronous errors (e.g., posix_spawnp failed) when executable not found
|
|
68
|
-
const error = new Error(err.message || 'Failed to spawn process');
|
|
69
|
-
// Check if this is likely a "command not found" error
|
|
70
|
-
const isNotFound = err.message && (
|
|
71
|
-
err.message.includes('posix_spawnp failed') ||
|
|
72
|
-
err.message.includes('ENOENT') ||
|
|
73
|
-
err.message.includes('not found')
|
|
74
|
-
);
|
|
75
|
-
error.code = isNotFound ? 'ENOENT' : 'SPAWN_ERROR';
|
|
76
|
-
error.command = command;
|
|
77
|
-
error.originalError = err;
|
|
78
|
-
// Return a minimal event emitter that immediately emits the error
|
|
79
|
-
const { EventEmitter } = require('events');
|
|
80
|
-
const fakeChild = new EventEmitter();
|
|
81
|
-
setImmediate(() => fakeChild.emit('error', error));
|
|
82
|
-
return fakeChild;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let lineBuffer = '';
|
|
86
|
-
let lastPrompt = '';
|
|
87
|
-
let inEscape = false;
|
|
88
|
-
let handoffInProgress = false;
|
|
89
|
-
|
|
90
|
-
const updateLineBuffer = (text) => {
|
|
91
|
-
for (const char of text) {
|
|
92
|
-
if (char === '\u001b') {
|
|
93
|
-
inEscape = true;
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (inEscape) {
|
|
97
|
-
if (/[a-zA-Z~]/.test(char)) {
|
|
98
|
-
inEscape = false;
|
|
99
|
-
}
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (char === '\r' || char === '\n') {
|
|
103
|
-
if (!shouldIgnoreLine(lineBuffer)) {
|
|
104
|
-
lastPrompt = lineBuffer.trim();
|
|
105
|
-
}
|
|
106
|
-
lineBuffer = '';
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (char === '\u007f' || char === '\b') {
|
|
110
|
-
if (lineBuffer.length > 0) {
|
|
111
|
-
lineBuffer = lineBuffer.slice(0, -1);
|
|
112
|
-
}
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (!isPrintableChar(char)) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
lineBuffer += char;
|
|
119
|
-
if (lineBuffer.length > 4000) {
|
|
120
|
-
lineBuffer = lineBuffer.slice(-4000);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const triggerHandoff = async () => {
|
|
126
|
-
if (handoffInProgress) return;
|
|
127
|
-
handoffInProgress = true;
|
|
128
|
-
try {
|
|
129
|
-
const fallbackTask = process.env.JBAI_HANDOFF_TASK;
|
|
130
|
-
const task = (lastPrompt && lastPrompt.trim()) || fallbackTask || '';
|
|
131
|
-
if (!task) {
|
|
132
|
-
process.stderr.write('⚠️ No recent prompt detected; set JBAI_HANDOFF_TASK.\n');
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
process.stderr.write('🚀 Creating Orca Lab handoff...\n');
|
|
137
|
-
const result = await createHandoff({
|
|
138
|
-
task,
|
|
139
|
-
repoUrl: process.env.JBAI_HANDOFF_REPO || handoffDefaults.repoUrl,
|
|
140
|
-
ref: process.env.JBAI_HANDOFF_REF || handoffDefaults.ref,
|
|
141
|
-
branchName: process.env.JBAI_HANDOFF_BRANCH || handoffDefaults.branchName,
|
|
142
|
-
gitToken: process.env.GITHUB_TOKEN || process.env.GH_TOKEN || handoffDefaults.gitToken,
|
|
143
|
-
facadeToken: process.env.FACADE_JWT_TOKEN || handoffDefaults.facadeToken,
|
|
144
|
-
orcaUrl: process.env.ORCA_LAB_URL || handoffDefaults.orcaUrl,
|
|
145
|
-
grazieToken: handoffDefaults.grazieToken,
|
|
146
|
-
grazieEnvironment: handoffDefaults.grazieEnvironment,
|
|
147
|
-
grazieModel: handoffDefaults.grazieModel,
|
|
148
|
-
source: toolName || 'jbai-cli',
|
|
149
|
-
autoStart: true,
|
|
150
|
-
shouldOpen: true,
|
|
151
|
-
cwd: handoffDefaults.cwd,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
process.stderr.write(`✅ Handoff ready: ${result.environmentUrl}\n`);
|
|
155
|
-
} catch (error) {
|
|
156
|
-
const message = error instanceof Error ? error.message : 'Handoff failed';
|
|
157
|
-
process.stderr.write(`❌ ${message}\n`);
|
|
158
|
-
} finally {
|
|
159
|
-
handoffInProgress = false;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
ptyProcess.onData((data) => process.stdout.write(data));
|
|
164
|
-
|
|
165
|
-
const onStdinData = (data) => {
|
|
166
|
-
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
167
|
-
const hasTrigger = buffer.includes(Buffer.from(trigger));
|
|
168
|
-
|
|
169
|
-
const sanitized = hasTrigger
|
|
170
|
-
? Buffer.from(buffer.toString('utf8').split(trigger).join(''), 'utf8')
|
|
171
|
-
: buffer;
|
|
172
|
-
|
|
173
|
-
if (hasTrigger) {
|
|
174
|
-
triggerHandoff();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (sanitized.length > 0) {
|
|
178
|
-
updateLineBuffer(sanitized.toString('utf8'));
|
|
179
|
-
ptyProcess.write(sanitized);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const onResize = () => {
|
|
184
|
-
try {
|
|
185
|
-
ptyProcess.resize(process.stdout.columns || 80, process.stdout.rows || 24);
|
|
186
|
-
} catch {
|
|
187
|
-
// Ignore resize errors
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
process.stdin.setRawMode(true);
|
|
192
|
-
process.stdin.resume();
|
|
193
|
-
process.stdin.on('data', onStdinData);
|
|
194
|
-
|
|
195
|
-
if (process.stdout.isTTY) {
|
|
196
|
-
process.stdout.on('resize', onResize);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const cleanup = () => {
|
|
200
|
-
if (process.stdin.isTTY) {
|
|
201
|
-
process.stdin.setRawMode(false);
|
|
202
|
-
}
|
|
203
|
-
process.stdin.off('data', onStdinData);
|
|
204
|
-
if (process.stdout.isTTY) {
|
|
205
|
-
process.stdout.off('resize', onResize);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
ptyProcess.onExit(({ exitCode }) => {
|
|
210
|
-
cleanup();
|
|
211
|
-
process.exit(exitCode || 0);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
return ptyProcess;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
module.exports = {
|
|
218
|
-
runWithHandoff,
|
|
219
|
-
stripHandoffFlag,
|
|
220
|
-
};
|