@bahulam/code 0.1.10 → 0.1.12
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/package.json +5 -2
- package/src/agents/loader.mjs +26 -4
- package/src/auth/bahulam-auth.mjs +2 -13
- package/src/auth/tarang-auth.mjs +313 -0
- package/src/commands/agent.mjs +7 -7
- package/src/commands/plugin-manage.mjs +449 -0
- package/src/commands/plugin.mjs +247 -0
- package/src/config/cli-args.mjs +16 -0
- package/src/config/env.mjs +2 -0
- package/src/config/hook-runner.mjs +8 -8
- package/src/config/memory-loader.mjs +7 -3
- package/src/config/settings-loader.mjs +5 -3
- package/src/core/attachments.mjs +2 -2
- package/src/core/background-tasks.mjs +186 -0
- package/src/core/headless.mjs +59 -3
- package/src/core/local-agent.mjs +10 -1
- package/src/core/local-store.mjs +10 -10
- package/src/core/paths.mjs +10 -96
- package/src/core/policy-resolver.mjs +1 -1
- package/src/core/project-context-loader.mjs +2 -2
- package/src/core/risk-tier.mjs +1 -0
- package/src/core/stream-client.mjs +148 -1
- package/src/core/system-prompt.mjs +31 -12
- package/src/core/tool-executor.mjs +457 -12
- package/src/local-service/agent-relay.mjs +139 -12
- package/src/local-service/server.mjs +345 -20
- package/src/orchestration/approval.mjs +30 -0
- package/src/orchestration/completion-triggers.mjs +40 -0
- package/src/orchestration/dispatch.mjs +118 -0
- package/src/orchestration/events.mjs +19 -0
- package/src/orchestration/graph.mjs +126 -0
- package/src/orchestration/node-runner.mjs +193 -0
- package/src/orchestration/runner.mjs +200 -0
- package/src/plugins/executor.mjs +121 -0
- package/src/plugins/loader.mjs +123 -123
- package/src/plugins/manifest.mjs +291 -0
- package/src/plugins/preflight.mjs +227 -0
- package/src/plugins/registry.mjs +233 -0
- package/src/plugins/state.mjs +290 -0
- package/src/terminal/agents.mjs +26 -4
- package/src/terminal/init.mjs +2 -2
- package/src/terminal/main.mjs +83 -4
- package/src/terminal/repl-explore.mjs +1 -1
- package/src/terminal/repl-render.mjs +67 -12
- package/src/terminal/repl-state.mjs +4 -2
- package/src/terminal/repl.mjs +621 -99
- package/src/tools/agent.mjs +6 -2
- package/src/tools/analyze-image.mjs +1 -1
- package/src/tools/project-overview.mjs +7 -7
- package/src/tools/registry.mjs +88 -4
- package/src/ui/slash-commands.mjs +19 -1
- package/src/ui/sub-agent.mjs +14 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bahulam/code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Bahulam Code — abundance, in your terminal. CLI-first, reliability-first, sub-agents, 65.6% SWE-bench Verified.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "node src/terminal/main.mjs",
|
|
19
|
-
"test": "
|
|
19
|
+
"test": "node scripts/run-tests.mjs",
|
|
20
|
+
"test:unit": "node scripts/run-tests.mjs --unit",
|
|
21
|
+
"test:integration": "node scripts/run-tests.mjs --integration",
|
|
20
22
|
"sync-catalog": "node scripts/sync-catalog.mjs",
|
|
21
23
|
"prepublishOnly": "node scripts/sync-catalog.mjs"
|
|
22
24
|
},
|
|
@@ -47,6 +49,7 @@
|
|
|
47
49
|
"url": "git+https://github.com/BahulamAI/BahulamCode-CLI.git"
|
|
48
50
|
},
|
|
49
51
|
"dependencies": {
|
|
52
|
+
"js-yaml": "^5.4.1",
|
|
50
53
|
"mermaid": "^11.17.2",
|
|
51
54
|
"monaco-editor": "^0.56.0",
|
|
52
55
|
"pdf-parse": "^1.1.1",
|
package/src/agents/loader.mjs
CHANGED
|
@@ -24,13 +24,9 @@ export class AgentLoader {
|
|
|
24
24
|
* @param {string} [cwd] - project working directory
|
|
25
25
|
*/
|
|
26
26
|
load(cwd = process.cwd()) {
|
|
27
|
-
// Prefer .bahulam/, but also scan legacy .kepler/ so agents defined
|
|
28
|
-
// under the old convention keep loading for existing projects.
|
|
29
27
|
this.searchPaths = [
|
|
30
28
|
path.join(cwd, '.bahulam', 'agents'),
|
|
31
|
-
path.join(cwd, '.kepler', 'agents'),
|
|
32
29
|
path.join(process.env.HOME || '', '.bahulam', 'agents'),
|
|
33
|
-
path.join(process.env.HOME || '', '.kepler', 'agents'),
|
|
34
30
|
];
|
|
35
31
|
|
|
36
32
|
for (const dir of this.searchPaths) {
|
|
@@ -66,6 +62,32 @@ export class AgentLoader {
|
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Load agents from plugin manifests.
|
|
67
|
+
* Plugin agents have lower priority than project .bahulam/agents agents.
|
|
68
|
+
* @param {object[]} plugins - List of plugin manifests
|
|
69
|
+
* @returns {this}
|
|
70
|
+
*/
|
|
71
|
+
loadFromPlugins(plugins) {
|
|
72
|
+
if (!Array.isArray(plugins)) return this;
|
|
73
|
+
for (const plugin of plugins) {
|
|
74
|
+
const agents = plugin.spec?.agents || [];
|
|
75
|
+
for (const agentDef of agents) {
|
|
76
|
+
const slug = agentDef.slug || agentDef.name || '';
|
|
77
|
+
if (!slug) continue;
|
|
78
|
+
// Project agents take precedence — skip if already registered
|
|
79
|
+
if (this.agents.has(slug)) continue;
|
|
80
|
+
this.agents.set(slug, {
|
|
81
|
+
...agentDef,
|
|
82
|
+
slug,
|
|
83
|
+
source: `plugin:${plugin.metadata?.name || 'unknown'}`,
|
|
84
|
+
source_scope: 'plugin',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
69
91
|
/**
|
|
70
92
|
* Get an agent definition by name.
|
|
71
93
|
* @param {string} name
|
|
@@ -11,8 +11,8 @@ import { getLoginSuccessHTML } from '../ui/banner.mjs';
|
|
|
11
11
|
import { resolveBackendUrl } from '../core/backend-url.mjs';
|
|
12
12
|
import { bahulamHome } from '../core/paths.mjs';
|
|
13
13
|
|
|
14
|
-
// Note: computed via a function (not a constant) so that BAHULAM_HOME
|
|
15
|
-
//
|
|
14
|
+
// Note: computed via a function (not a constant) so that BAHULAM_HOME
|
|
15
|
+
// env-var swaps mid-process still work.
|
|
16
16
|
function configDir() { return bahulamHome(); }
|
|
17
17
|
function configPath() { return path.join(configDir(), 'config.json'); }
|
|
18
18
|
|
|
@@ -24,17 +24,6 @@ const CONFIG_PATH = configPath();
|
|
|
24
24
|
let _tokenEnvNoticeShown = false;
|
|
25
25
|
function readTokenFromEnv() {
|
|
26
26
|
if (process.env.B0_TOKEN) return process.env.B0_TOKEN;
|
|
27
|
-
if (process.env.KEPLER_TOKEN) {
|
|
28
|
-
if (!_tokenEnvNoticeShown && process.env.B0_QUIET_MIGRATION !== '1') {
|
|
29
|
-
_tokenEnvNoticeShown = true;
|
|
30
|
-
try {
|
|
31
|
-
process.stderr.write(
|
|
32
|
-
' \x1b[2mnote: KEPLER_TOKEN is deprecated; set B0_TOKEN instead.\x1b[0m\n'
|
|
33
|
-
);
|
|
34
|
-
} catch {}
|
|
35
|
-
}
|
|
36
|
-
return process.env.KEPLER_TOKEN;
|
|
37
|
-
}
|
|
38
27
|
return null;
|
|
39
28
|
}
|
|
40
29
|
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bahulam Code Authentication — GitHub OAuth + config management.
|
|
3
|
+
* Reads/writes ~/.bahulam/config.json (fallback: ~/.kepler/config.json for
|
|
4
|
+
* legacy installs — see src/core/paths.mjs for the resolver).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import * as http from 'node:http';
|
|
10
|
+
import { getLoginSuccessHTML } from '../ui/banner.mjs';
|
|
11
|
+
import { resolveBackendUrl } from '../core/backend-url.mjs';
|
|
12
|
+
import { bahulamHome } from '../core/paths.mjs';
|
|
13
|
+
|
|
14
|
+
// Note: computed via a function (not a constant) so that BAHULAM_HOME /
|
|
15
|
+
// KEPLER_HOME env-var swaps mid-process still work.
|
|
16
|
+
function configDir() { return bahulamHome(); }
|
|
17
|
+
function configPath() { return path.join(configDir(), 'config.json'); }
|
|
18
|
+
|
|
19
|
+
// Legacy exports kept for backwards compat with any tests/scripts that
|
|
20
|
+
// still import CONFIG_DIR / CONFIG_PATH by name.
|
|
21
|
+
const CONFIG_DIR = configDir();
|
|
22
|
+
const CONFIG_PATH = configPath();
|
|
23
|
+
|
|
24
|
+
let _tokenEnvNoticeShown = false;
|
|
25
|
+
function readTokenFromEnv() {
|
|
26
|
+
if (process.env.B0_TOKEN) return process.env.B0_TOKEN;
|
|
27
|
+
if (process.env.KEPLER_TOKEN) {
|
|
28
|
+
if (!_tokenEnvNoticeShown && process.env.B0_QUIET_MIGRATION !== '1') {
|
|
29
|
+
_tokenEnvNoticeShown = true;
|
|
30
|
+
try {
|
|
31
|
+
process.stderr.write(
|
|
32
|
+
' \x1b[2mnote: KEPLER_TOKEN is deprecated; set B0_TOKEN instead.\x1b[0m\n'
|
|
33
|
+
);
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
return process.env.KEPLER_TOKEN;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class TarangAuth {
|
|
42
|
+
constructor() {
|
|
43
|
+
this._config = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Ensure ~/.bahulam/ (or legacy ~/.kepler/) exists with secure permissions. */
|
|
47
|
+
_ensureConfigDir() {
|
|
48
|
+
const dir = configDir();
|
|
49
|
+
if (!fs.existsSync(dir)) {
|
|
50
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Load credentials and settings from config.json. */
|
|
55
|
+
loadCredentials() {
|
|
56
|
+
const cfgPath = configPath();
|
|
57
|
+
try {
|
|
58
|
+
if (fs.existsSync(cfgPath)) {
|
|
59
|
+
const raw = fs.readFileSync(cfgPath, 'utf-8');
|
|
60
|
+
this._config = JSON.parse(raw);
|
|
61
|
+
} else {
|
|
62
|
+
this._config = {};
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
this._config = {};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
token: readTokenFromEnv() || this._config.token || null,
|
|
69
|
+
openRouterKey: this._config.openrouter_key || process.env.OPENROUTER_API_KEY || null,
|
|
70
|
+
anthropicKey: this._config.anthropic_api_key || process.env.ANTHROPIC_API_KEY || null,
|
|
71
|
+
openaiKey: this._config.openai_api_key || process.env.OPENAI_API_KEY || null,
|
|
72
|
+
googleKey: this._config.google_api_key || process.env.GOOGLE_API_KEY || null,
|
|
73
|
+
backendUrl: resolveBackendUrl(),
|
|
74
|
+
mode: this._config.mode || 'auto',
|
|
75
|
+
gatewayType: this._config.gateway_type || 'openrouter',
|
|
76
|
+
models: this._config.models || {},
|
|
77
|
+
configuredProviders: this._config.configured_providers || [],
|
|
78
|
+
gatewayConfig: this._config.gateway_config || {},
|
|
79
|
+
// PRD-076 W7: persisted /model picks. `modelConfig` mirrors the
|
|
80
|
+
// Python-side key read_local_model_config() looks for; keep the
|
|
81
|
+
// snake_case JSON key so the runtime picks it up unchanged.
|
|
82
|
+
modelConfig: this._config.model_config || {},
|
|
83
|
+
modelMode: this._config.model_mode || null,
|
|
84
|
+
routePreference: this._config.route_preference || null,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Get the raw config object. */
|
|
89
|
+
getRawConfig() {
|
|
90
|
+
if (!this._config) this.loadCredentials();
|
|
91
|
+
return this._config || {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Clear credentials — remove token and keys from config. */
|
|
95
|
+
logout() {
|
|
96
|
+
try {
|
|
97
|
+
const cfgPath = configPath();
|
|
98
|
+
if (fs.existsSync(cfgPath)) {
|
|
99
|
+
fs.unlinkSync(cfgPath);
|
|
100
|
+
}
|
|
101
|
+
this._config = null;
|
|
102
|
+
return true;
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Save credentials atomically (temp-file + rename). */
|
|
109
|
+
saveCredentials(updates) {
|
|
110
|
+
this._ensureConfigDir();
|
|
111
|
+
const current = this._config || {};
|
|
112
|
+
const merged = { ...current, ...updates };
|
|
113
|
+
const cfgPath = configPath();
|
|
114
|
+
const tmpPath = `${cfgPath}.tmp.${process.pid}`;
|
|
115
|
+
fs.writeFileSync(tmpPath, JSON.stringify(merged, null, 2), { mode: 0o600 });
|
|
116
|
+
fs.renameSync(tmpPath, cfgPath);
|
|
117
|
+
this._config = merged;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Check if user has a valid auth token. */
|
|
121
|
+
isAuthenticated() {
|
|
122
|
+
const creds = this.loadCredentials();
|
|
123
|
+
return !!creds.token;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Check if OpenRouter key is configured. */
|
|
127
|
+
hasOpenRouterKey() {
|
|
128
|
+
const creds = this.loadCredentials();
|
|
129
|
+
return !!creds.openRouterKey;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Save an API key by provider name. */
|
|
133
|
+
saveProviderKey(provider, key) {
|
|
134
|
+
const keyMap = {
|
|
135
|
+
openrouter: 'openrouter_key',
|
|
136
|
+
anthropic: 'anthropic_api_key',
|
|
137
|
+
openai: 'openai_api_key',
|
|
138
|
+
googleai: 'google_api_key',
|
|
139
|
+
azureopenai: 'azure_api_key',
|
|
140
|
+
bedrock: 'aws_access_key',
|
|
141
|
+
databricks: 'databricks_token',
|
|
142
|
+
};
|
|
143
|
+
const field = keyMap[provider];
|
|
144
|
+
if (!field) throw new Error(`Unknown provider: ${provider}`);
|
|
145
|
+
this.saveCredentials({ [field]: key });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Save OpenRouter API key. */
|
|
149
|
+
saveOpenRouterKey(key) {
|
|
150
|
+
this.saveProviderKey('openrouter', key);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Save Anthropic API key. */
|
|
154
|
+
saveAnthropicKey(key) {
|
|
155
|
+
this.saveProviderKey('anthropic', key);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Save OpenAI API key. */
|
|
159
|
+
saveOpenAIKey(key) {
|
|
160
|
+
this.saveProviderKey('openai', key);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Save Google AI API key. */
|
|
164
|
+
saveGoogleKey(key) {
|
|
165
|
+
this.saveProviderKey('googleai', key);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Sync settings from web backend and save locally. */
|
|
169
|
+
async syncSettings() {
|
|
170
|
+
const { fetchRemoteSettings, mergeRemoteSettings } = await import('../core/settings-sync.mjs');
|
|
171
|
+
const creds = this.loadCredentials();
|
|
172
|
+
if (!creds.token) throw new Error('Not logged in. Run `bahulam-code login` first.');
|
|
173
|
+
|
|
174
|
+
const remote = await fetchRemoteSettings(creds.token);
|
|
175
|
+
if (!remote) throw new Error('Failed to fetch settings from server.');
|
|
176
|
+
|
|
177
|
+
const merged = mergeRemoteSettings(this.getRawConfig(), remote);
|
|
178
|
+
this.saveCredentials(merged);
|
|
179
|
+
return remote;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Set default mode. */
|
|
183
|
+
setMode(mode) {
|
|
184
|
+
const valid = ['local', 'remote', 'auto'];
|
|
185
|
+
if (!valid.includes(mode)) {
|
|
186
|
+
throw new Error(`Invalid mode: ${mode}. Must be one of: ${valid.join(', ')}`);
|
|
187
|
+
}
|
|
188
|
+
this.saveCredentials({ mode });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Display config (styled). */
|
|
192
|
+
printConfig() {
|
|
193
|
+
const creds = this.loadCredentials();
|
|
194
|
+
const GREEN = '\x1b[32m', RED = '\x1b[31m', DIM = '\x1b[2m', BOLD = '\x1b[1m', CYAN = '\x1b[36m', RESET = '\x1b[0m';
|
|
195
|
+
const check = `${GREEN}\u2713${RESET}`;
|
|
196
|
+
const cross = `${RED}\u2717${RESET}`;
|
|
197
|
+
|
|
198
|
+
const env = process.env.TARANG_ENV || process.env.NODE_ENV || 'production';
|
|
199
|
+
|
|
200
|
+
process.stderr.write(`\n${BOLD}Bahulam Code Configuration${RESET}\n`);
|
|
201
|
+
process.stderr.write(`${'─'.repeat(50)}\n`);
|
|
202
|
+
process.stderr.write(` Auth: ${creds.token ? `${check} logged in` : `${cross} not logged in ${DIM}(/login)${RESET}`}\n`);
|
|
203
|
+
process.stderr.write(` Environment: ${DIM}${env}${RESET}\n`);
|
|
204
|
+
process.stderr.write(` Backend: ${DIM}${creds.backendUrl}${RESET}\n`);
|
|
205
|
+
process.stderr.write(` Mode: ${DIM}${creds.mode || 'auto'}${RESET}\n`);
|
|
206
|
+
process.stderr.write(` Gateway: ${DIM}${creds.gatewayType}${RESET}\n`);
|
|
207
|
+
|
|
208
|
+
const models = creds.models || {};
|
|
209
|
+
const planningModel = models.planning || models.orchestrator;
|
|
210
|
+
if (planningModel || models.reasoning || models.local) {
|
|
211
|
+
process.stderr.write(`\n${BOLD} Models${RESET}\n`);
|
|
212
|
+
if (planningModel) process.stderr.write(` Planning: ${DIM}${planningModel}${RESET}\n`);
|
|
213
|
+
if (models.reasoning) process.stderr.write(` Coding: ${DIM}${models.reasoning}${RESET}\n`);
|
|
214
|
+
if (models.local) process.stderr.write(` Local: ${DIM}${models.local}${RESET}\n`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const providers = creds.configuredProviders || [];
|
|
218
|
+
if (providers.length > 0) {
|
|
219
|
+
process.stderr.write(` Providers: ${DIM}${providers.join(', ')}${RESET}\n`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const raw = this.getRawConfig();
|
|
223
|
+
if (raw.last_synced_at) {
|
|
224
|
+
process.stderr.write(` Last synced: ${DIM}${new Date(raw.last_synced_at).toLocaleString()}${RESET}\n`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
process.stderr.write(`\n ${DIM}Run ${RESET}${CYAN}bahulam-code sync${RESET}${DIM} to sync settings from web.${RESET}\n`);
|
|
228
|
+
process.stderr.write(` ${DIM}Run ${RESET}${CYAN}bahulam-code configure${RESET}${DIM} to open settings in browser.${RESET}\n`);
|
|
229
|
+
process.stderr.write('\n');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Run login flow via web app.
|
|
234
|
+
*
|
|
235
|
+
* Flow:
|
|
236
|
+
* 1. CLI starts local HTTP server on random port
|
|
237
|
+
* 2. Opens browser to web /auth/cli?callback=http://127.0.0.1:{port}/callback
|
|
238
|
+
* 3. Web checks Supabase session (if none → GitHub OAuth → Supabase)
|
|
239
|
+
* 4. Web generates CLI token via /api/cli/token
|
|
240
|
+
* 5. Web redirects browser to CLI callback with token
|
|
241
|
+
* 6. CLI receives token, saves to ~/.bahulam/config.json
|
|
242
|
+
*/
|
|
243
|
+
async login() {
|
|
244
|
+
const { resolveWebUrl } = await import('../core/backend-url.mjs');
|
|
245
|
+
const webUrl = resolveWebUrl();
|
|
246
|
+
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
const server = http.createServer(async (req, res) => {
|
|
249
|
+
const url = new URL(req.url, `http://localhost`);
|
|
250
|
+
|
|
251
|
+
// The web app redirects here with ?token=<cli_token>
|
|
252
|
+
const token = url.searchParams.get('token');
|
|
253
|
+
|
|
254
|
+
if (!token) {
|
|
255
|
+
// Maybe an error or missing token
|
|
256
|
+
const error = url.searchParams.get('error');
|
|
257
|
+
if (error) {
|
|
258
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
259
|
+
res.end(`<html><body><h2>Login failed</h2><p>${error}</p></body></html>`);
|
|
260
|
+
server.close();
|
|
261
|
+
reject(new Error(error));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
// Ignore other requests (favicon, etc.)
|
|
265
|
+
res.writeHead(200);
|
|
266
|
+
res.end('');
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Save the CLI token
|
|
271
|
+
this.saveCredentials({ token });
|
|
272
|
+
|
|
273
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
274
|
+
res.end(getLoginSuccessHTML());
|
|
275
|
+
|
|
276
|
+
server.close();
|
|
277
|
+
resolve(true);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
server.listen(0, '127.0.0.1', () => {
|
|
281
|
+
const port = server.address().port;
|
|
282
|
+
const callbackUrl = `http://127.0.0.1:${port}/callback`;
|
|
283
|
+
const authUrl = `${webUrl}/auth/cli?callback=${encodeURIComponent(callbackUrl)}`;
|
|
284
|
+
|
|
285
|
+
process.stderr.write(`\n\x1b[36mOpening browser for login...\x1b[0m\n`);
|
|
286
|
+
process.stderr.write(`\x1b[2mIf browser doesn't open, visit:\x1b[0m\n \x1b[4m${authUrl}\x1b[0m\n\n`);
|
|
287
|
+
|
|
288
|
+
// Open browser
|
|
289
|
+
const openCmd = process.platform === 'darwin' ? 'open' :
|
|
290
|
+
process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
291
|
+
import('node:child_process').then(({ exec }) => {
|
|
292
|
+
exec(`${openCmd} "${authUrl}"`, () => {});
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// Timeout after 120s
|
|
297
|
+
setTimeout(() => {
|
|
298
|
+
server.close();
|
|
299
|
+
reject(new Error('Login timed out after 120s'));
|
|
300
|
+
}, 120_000);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Ensure user is authenticated, prompt login if not.
|
|
306
|
+
*/
|
|
307
|
+
async ensureAuth() {
|
|
308
|
+
if (!this.isAuthenticated()) {
|
|
309
|
+
process.stderr.write('\x1b[33mNot logged in.\x1b[0m Starting login flow...\n');
|
|
310
|
+
await this.login();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
package/src/commands/agent.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent CLI Commands — list, get, sync user-defined agents.
|
|
2
|
+
* Agent CLI Commands — list, get, sync backend-published user-defined agents.
|
|
3
3
|
*
|
|
4
4
|
* Commands:
|
|
5
5
|
* bahulam-code agent list
|
|
@@ -47,9 +47,9 @@ export async function handleAgentCommand(args) {
|
|
|
47
47
|
|
|
48
48
|
function printAgentUsage() {
|
|
49
49
|
process.stderr.write(`${BOLD}AGENT COMMANDS${RESET}\n`);
|
|
50
|
-
process.stderr.write(` ${CYAN}bahulam-code agent list${RESET} List
|
|
51
|
-
process.stderr.write(` ${CYAN}bahulam-code agent get <slug>${RESET} Show agent details\n`);
|
|
52
|
-
process.stderr.write(` ${CYAN}bahulam-code agent sync [--dir <path>]${RESET}
|
|
50
|
+
process.stderr.write(` ${CYAN}bahulam-code agent list${RESET} List backend-published agents\n`);
|
|
51
|
+
process.stderr.write(` ${CYAN}bahulam-code agent get <slug>${RESET} Show backend-published agent details\n`);
|
|
52
|
+
process.stderr.write(` ${CYAN}bahulam-code agent sync [--dir <path>]${RESET} Publish local agent YAML files for account/cloud reuse\n`);
|
|
53
53
|
process.stderr.write('\n');
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -110,11 +110,11 @@ async function handleList(args) {
|
|
|
110
110
|
|
|
111
111
|
const agents = result.agents || [];
|
|
112
112
|
if (agents.length === 0) {
|
|
113
|
-
process.stderr.write(`${DIM}No
|
|
113
|
+
process.stderr.write(`${DIM}No backend-published agents found. Local .bahulam/agents files can still be delegated in their workspace.${RESET}\n`);
|
|
114
114
|
process.exit(0);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
process.stderr.write(`${BOLD}
|
|
117
|
+
process.stderr.write(`${BOLD}Backend-published Agents:${RESET}\n`);
|
|
118
118
|
for (const a of agents) {
|
|
119
119
|
const source = a.source === 'platform' ? `${DIM}(platform)${RESET}` : `${DIM}(user)${RESET}`;
|
|
120
120
|
process.stderr.write(` ${CYAN}${a.slug}${RESET} ${a.name || a.slug} ${source}\n`);
|
|
@@ -184,7 +184,7 @@ async function handleSync(args) {
|
|
|
184
184
|
agents: selected,
|
|
185
185
|
});
|
|
186
186
|
const synced = result.synced ?? selected.length;
|
|
187
|
-
process.stderr.write(`${GREEN}✓ Synced ${synced} agent${synced === 1 ? '' : 's'} to
|
|
187
|
+
process.stderr.write(`${GREEN}✓ Synced ${synced} agent${synced === 1 ? '' : 's'} to the backend for account/cloud reuse.${RESET}\n`);
|
|
188
188
|
process.stdout.write(JSON.stringify({ synced, agents: result.agents || [] }, null, 2) + '\n');
|
|
189
189
|
} catch (err) {
|
|
190
190
|
process.stderr.write(`${RED}✗ Agent sync failed: ${err.message}${RESET}\n`);
|