bashirweb 0.0.0-stage → 0.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/LICENSE +21 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/backend.d.ts +33 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +166 -0
- package/dist/backend.js.map +1 -0
- package/dist/bashirweb.d.ts +249 -0
- package/dist/bashirweb.d.ts.map +1 -0
- package/dist/bashirweb.js +470 -0
- package/dist/bashirweb.js.map +1 -0
- package/dist/browser-console.d.ts +42 -0
- package/dist/browser-console.d.ts.map +1 -0
- package/dist/browser-console.js +51 -0
- package/dist/browser-console.js.map +1 -0
- package/dist/browser-operator.d.ts +134 -0
- package/dist/browser-operator.d.ts.map +1 -0
- package/dist/browser-operator.js +253 -0
- package/dist/browser-operator.js.map +1 -0
- package/dist/browser-tools.d.ts +24 -0
- package/dist/browser-tools.d.ts.map +1 -0
- package/dist/browser-tools.js +316 -0
- package/dist/browser-tools.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/local.d.ts +61 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +200 -0
- package/dist/local.js.map +1 -0
- package/dist/page-actions.d.ts +11 -0
- package/dist/page-actions.d.ts.map +1 -0
- package/dist/page-actions.js +146 -0
- package/dist/page-actions.js.map +1 -0
- package/dist/remote.d.ts +260 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +299 -0
- package/dist/remote.js.map +1 -0
- package/dist/serve.d.ts +21 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +79 -0
- package/dist/serve.js.map +1 -0
- package/dist/tools.d.ts +5 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +439 -0
- package/dist/tools.js.map +1 -0
- package/dist/trace-viewer.d.ts +17 -0
- package/dist/trace-viewer.d.ts.map +1 -0
- package/dist/trace-viewer.js +235 -0
- package/dist/trace-viewer.js.map +1 -0
- package/dist/workflow-host.d.ts +20 -0
- package/dist/workflow-host.d.ts.map +1 -0
- package/dist/workflow-host.js +216 -0
- package/dist/workflow-host.js.map +1 -0
- package/package.json +53 -3
- package/README.md +0 -3
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { appendFileSync, existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
|
+
import { VERSION, BashirWebError, CONFIG_FILE_NAMES, serializeError } from '@dream_engine/core';
|
|
6
|
+
import { hasFts5, openDatabase } from '@dream_engine/storage';
|
|
7
|
+
import { BashirWeb } from '../bashirweb.js';
|
|
8
|
+
import { startServer } from '../serve.js';
|
|
9
|
+
import { startTraceViewer } from '../trace-viewer.js';
|
|
10
|
+
import { BrowserOperator } from '../browser-operator.js';
|
|
11
|
+
import { ComputerAgent } from '@dream_engine/computer';
|
|
12
|
+
import { MultiAgentOrchestrator, createLocalReasoningModel, detectLocalModel } from '@dream_engine/agent';
|
|
13
|
+
import { createLocalModel } from '@dream_engine/agent';
|
|
14
|
+
const HELP = `bashirweb ${VERSION} — browser automation, search and crawling
|
|
15
|
+
|
|
16
|
+
Usage: bashirweb <command> [options]
|
|
17
|
+
|
|
18
|
+
Commands:
|
|
19
|
+
init [--force] Create bashirweb.config.json in the current directory
|
|
20
|
+
version Print the version
|
|
21
|
+
config [--json] Print the resolved configuration (secrets redacted)
|
|
22
|
+
doctor Check Node.js, SQLite FTS5, browsers, data dir and sources
|
|
23
|
+
status [--json] Show index, crawl history and server status
|
|
24
|
+
search <query> [--mode local|sources|hybrid|live] [--limit n] [--page n] [--json]
|
|
25
|
+
crawl <url...> [--depth n] [--max-pages n] [--delay ms] [--no-sitemaps] [--render] [--json]
|
|
26
|
+
index add <url> | index stats Manage the local search index
|
|
27
|
+
extract <url> [--format markdown|text|html|json] [--render]
|
|
28
|
+
browser list List detected browser engines
|
|
29
|
+
browser launch [url] [--engine e] [--headed] Launch a browser and keep it open until Ctrl+C
|
|
30
|
+
browser install [engine...] [--with-deps] Download browsers (and ffmpeg, for video) for the bundled Playwright
|
|
31
|
+
artifacts list [kind] | artifacts stats Files under the data directory (screenshots, traces, HAR ...)
|
|
32
|
+
artifacts prune | artifacts delete <id> Apply the artifacts.* limits now / delete one artifact by id
|
|
33
|
+
workflow validate <file> Validate a workflow JSON file
|
|
34
|
+
workflow run <file|id> [--input k=v]... Run a workflow
|
|
35
|
+
workflow list | workflow history List saved workflows / recent runs
|
|
36
|
+
test [files...] [--grep <re>] [--grep-invert] [--tags a,b] [--project <n>]
|
|
37
|
+
Run tests (see @dream_engine/testing)
|
|
38
|
+
[--bail] [--list] [--timeout ms] [--retries n]
|
|
39
|
+
[--workers n] [--reporter r] [--browser e]
|
|
40
|
+
server start [--host h] [--port p] Start the hosted HTTP API (foreground)
|
|
41
|
+
server stop Stop a server started from this data directory
|
|
42
|
+
mcp Serve the agent tools over MCP (stdio)
|
|
43
|
+
agent run "<objective>" Run the unified multi-agent orchestrator (LOCAL AI only)
|
|
44
|
+
agent models Detect installed local models (Ollama / OpenAI-compatible)
|
|
45
|
+
agent status Show orchestration task persistence location
|
|
46
|
+
trace view <file.zip> [--host h] [--port p] Serve the offline trace viewer for a recorded trace
|
|
47
|
+
|
|
48
|
+
Global options:
|
|
49
|
+
--config <file> Use a specific config file
|
|
50
|
+
--data-dir <dir> Override the data directory
|
|
51
|
+
--remote <url> Use a remote BashirWeb server (token from BASHIRWEB_TOKEN)
|
|
52
|
+
--json Machine-readable output
|
|
53
|
+
-h, --help Show help
|
|
54
|
+
`;
|
|
55
|
+
const OPTIONS = {
|
|
56
|
+
help: { type: 'boolean', short: 'h' },
|
|
57
|
+
json: { type: 'boolean' },
|
|
58
|
+
config: { type: 'string' },
|
|
59
|
+
'data-dir': { type: 'string' },
|
|
60
|
+
remote: { type: 'string' },
|
|
61
|
+
force: { type: 'boolean' },
|
|
62
|
+
mode: { type: 'string' },
|
|
63
|
+
limit: { type: 'string' },
|
|
64
|
+
page: { type: 'string' },
|
|
65
|
+
depth: { type: 'string' },
|
|
66
|
+
'max-pages': { type: 'string' },
|
|
67
|
+
delay: { type: 'string' },
|
|
68
|
+
'no-sitemaps': { type: 'boolean' },
|
|
69
|
+
render: { type: 'boolean' },
|
|
70
|
+
format: { type: 'string' },
|
|
71
|
+
engine: { type: 'string' },
|
|
72
|
+
headed: { type: 'boolean' },
|
|
73
|
+
'with-deps': { type: 'boolean' },
|
|
74
|
+
input: { type: 'string', multiple: true },
|
|
75
|
+
host: { type: 'string' },
|
|
76
|
+
port: { type: 'string' },
|
|
77
|
+
// test command
|
|
78
|
+
grep: { type: 'string' },
|
|
79
|
+
'grep-invert': { type: 'boolean' },
|
|
80
|
+
tags: { type: 'string' },
|
|
81
|
+
project: { type: 'string' },
|
|
82
|
+
bail: { type: 'boolean' },
|
|
83
|
+
list: { type: 'boolean' },
|
|
84
|
+
timeout: { type: 'string' },
|
|
85
|
+
retries: { type: 'string' },
|
|
86
|
+
workers: { type: 'string' },
|
|
87
|
+
reporter: { type: 'string' },
|
|
88
|
+
browser: { type: 'string' },
|
|
89
|
+
};
|
|
90
|
+
function int(v, name) {
|
|
91
|
+
if (v === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
const n = Number(v);
|
|
94
|
+
if (!Number.isInteger(n) || n < 0)
|
|
95
|
+
throw new Error(`--${name} must be a non-negative integer`);
|
|
96
|
+
return n;
|
|
97
|
+
}
|
|
98
|
+
function out(values, data, human) {
|
|
99
|
+
if (values['json'])
|
|
100
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}\n`);
|
|
101
|
+
else
|
|
102
|
+
human();
|
|
103
|
+
}
|
|
104
|
+
function baseConfig(values) {
|
|
105
|
+
return values['data-dir'] ? { runtime: { dataDir: resolve(String(values['data-dir'])) } } : {};
|
|
106
|
+
}
|
|
107
|
+
async function withBw(values, fn) {
|
|
108
|
+
const remote = values['remote'] ? String(values['remote']) : undefined;
|
|
109
|
+
const bw = new BashirWeb({
|
|
110
|
+
config: baseConfig(values),
|
|
111
|
+
...(values['config'] ? { configFile: String(values['config']) } : {}),
|
|
112
|
+
...(remote ? { runtime: 'remote', endpoint: remote } : {}),
|
|
113
|
+
});
|
|
114
|
+
await bw.initialize();
|
|
115
|
+
try {
|
|
116
|
+
return await fn(bw);
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
await bw.shutdown();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function pidFile(dataDir) {
|
|
123
|
+
return join(dataDir, 'server.json');
|
|
124
|
+
}
|
|
125
|
+
function isAlive(pid) {
|
|
126
|
+
try {
|
|
127
|
+
process.kill(pid, 0);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function main(argv) {
|
|
135
|
+
const parsed = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true, strict: true });
|
|
136
|
+
const values = parsed.values;
|
|
137
|
+
const positionals = parsed.positionals;
|
|
138
|
+
const [cmd, sub, ...rest] = positionals;
|
|
139
|
+
if (values['help'] || !cmd || cmd === 'help') {
|
|
140
|
+
process.stdout.write(HELP);
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
switch (cmd) {
|
|
144
|
+
case 'version':
|
|
145
|
+
process.stdout.write(`${VERSION}\n`);
|
|
146
|
+
return 0;
|
|
147
|
+
case 'init': {
|
|
148
|
+
const existing = CONFIG_FILE_NAMES.find((n) => existsSync(join(process.cwd(), n)));
|
|
149
|
+
if (existing && !values['force'])
|
|
150
|
+
throw new Error(`${existing} already exists (use --force to overwrite bashirweb.config.json)`);
|
|
151
|
+
const config = {
|
|
152
|
+
browser: { engine: 'chromium', headless: true },
|
|
153
|
+
search: { mode: 'hybrid', sources: [] },
|
|
154
|
+
crawler: { maxDepth: 2, maxPages: 100, perDomainDelay: 500, respectRobots: true },
|
|
155
|
+
security: { approval: { mode: 'deny' } },
|
|
156
|
+
};
|
|
157
|
+
writeFileSync(join(process.cwd(), 'bashirweb.config.json'), `${JSON.stringify(config, null, 2)}\n`);
|
|
158
|
+
const gi = join(process.cwd(), '.gitignore');
|
|
159
|
+
if (!existsSync(gi) || !readFileSync(gi, 'utf8').split('\n').includes('.bashirweb/'))
|
|
160
|
+
appendFileSync(gi, `${existsSync(gi) ? '\n' : ''}.bashirweb/\n`);
|
|
161
|
+
process.stdout.write('Created bashirweb.config.json and added .bashirweb/ to .gitignore\n');
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
case 'config':
|
|
165
|
+
return withBw(values, async (bw) => {
|
|
166
|
+
process.stdout.write(`${JSON.stringify(bw.getConfig(), null, 2)}\n`);
|
|
167
|
+
return 0;
|
|
168
|
+
});
|
|
169
|
+
case 'doctor': {
|
|
170
|
+
const checks = [];
|
|
171
|
+
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
172
|
+
// node:sqlite bundles FTS5 from 22.16.0 and 24.0.0; no 23.x release has it.
|
|
173
|
+
checks.push({ name: 'Node.js 22.16+ or 24+', ok: major >= 24 || (major === 22 && minor >= 16), detail: process.versions.node });
|
|
174
|
+
try {
|
|
175
|
+
const db = openDatabase(':memory:');
|
|
176
|
+
checks.push({ name: 'SQLite FTS5 (node:sqlite)', ok: hasFts5(db), detail: hasFts5(db) ? 'available' : 'missing' });
|
|
177
|
+
db.close();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
checks.push({ name: 'SQLite FTS5 (node:sqlite)', ok: false, detail: error.message });
|
|
181
|
+
}
|
|
182
|
+
await withBw(values, async (bw) => {
|
|
183
|
+
checks.push({ name: 'Configuration', ok: true, detail: `runtime=${bw.runtime}, dataDir=${bw.getConfig().runtime.dataDir}` });
|
|
184
|
+
if (bw.runtime === 'remote') {
|
|
185
|
+
const h = await bw.health();
|
|
186
|
+
checks.push({ name: 'Remote server', ok: h.status !== 'error', detail: h.status });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
for (const e of bw.local.browsers.detectEngines())
|
|
190
|
+
checks.push({
|
|
191
|
+
name: `Browser: ${e.engine}`,
|
|
192
|
+
ok: e.source !== 'missing',
|
|
193
|
+
detail: e.executablePath ?? 'not installed (npx playwright install ' + e.engine + ')',
|
|
194
|
+
});
|
|
195
|
+
try {
|
|
196
|
+
const t0 = Date.now();
|
|
197
|
+
const browser = await bw.local.browsers.launch();
|
|
198
|
+
checks.push({ name: 'Browser launch', ok: true, detail: `${browser.engine} ${browser.version()} in ${Date.now() - t0}ms` });
|
|
199
|
+
await browser.close();
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
checks.push({ name: 'Browser launch', ok: false, detail: error.message.split('\n')[0] ?? '' });
|
|
203
|
+
}
|
|
204
|
+
for (const s of await bw.local.search.sourceHealth())
|
|
205
|
+
checks.push({ name: `Search source: ${s.name}`, ok: s.ok, detail: s.message });
|
|
206
|
+
});
|
|
207
|
+
out(values, checks, () => {
|
|
208
|
+
for (const c of checks)
|
|
209
|
+
process.stdout.write(`${c.ok ? '✔' : '✖'} ${c.name}: ${c.detail}\n`);
|
|
210
|
+
});
|
|
211
|
+
return checks.every((c) => c.ok || c.name.startsWith('Browser: ')) ? 0 : 1;
|
|
212
|
+
}
|
|
213
|
+
case 'status':
|
|
214
|
+
return withBw(values, async (bw) => {
|
|
215
|
+
const dataDir = bw.getConfig().runtime.dataDir;
|
|
216
|
+
let server = { running: false };
|
|
217
|
+
if (existsSync(pidFile(dataDir))) {
|
|
218
|
+
const info = JSON.parse(readFileSync(pidFile(dataDir), 'utf8'));
|
|
219
|
+
server = { running: isAlive(info.pid), ...info };
|
|
220
|
+
}
|
|
221
|
+
const status = bw.runtime === 'local'
|
|
222
|
+
? { runtime: 'local', dataDir, index: await bw.index.stats(), recentCrawls: bw.index.crawlHistory(5), server }
|
|
223
|
+
: { runtime: 'remote', health: await bw.health() };
|
|
224
|
+
out(values, status, () => process.stdout.write(`${JSON.stringify(status, null, 2)}\n`));
|
|
225
|
+
return 0;
|
|
226
|
+
});
|
|
227
|
+
case 'search': {
|
|
228
|
+
const query = [sub, ...rest].filter(Boolean).join(' ');
|
|
229
|
+
if (!query)
|
|
230
|
+
throw new Error('Usage: bashirweb search <query>');
|
|
231
|
+
return withBw(values, async (bw) => {
|
|
232
|
+
const r = await bw.search(query, {
|
|
233
|
+
...(values['mode'] ? { mode: String(values['mode']) } : {}),
|
|
234
|
+
...(values['limit'] ? { limit: int(values['limit'], 'limit') } : {}),
|
|
235
|
+
...(values['page'] ? { page: int(values['page'], 'page') } : {}),
|
|
236
|
+
});
|
|
237
|
+
out(values, r, () => {
|
|
238
|
+
process.stdout.write(`${r.results.length} result(s) for "${r.query}" [${r.mode}${r.cached ? ', cached' : ''}] in ${r.durationMs}ms\n\n`);
|
|
239
|
+
for (const x of r.results) {
|
|
240
|
+
process.stdout.write(`${x.rank}. ${x.title}\n ${x.url}\n [${x.source}${x.source === 'cache' ? `:${x.origin}` : ''}] ${x.providers.join(', ')}${x.publishedAt ? ` · published ${x.publishedAt.slice(0, 10)}` : ''}\n ${x.snippet}\n\n`);
|
|
241
|
+
}
|
|
242
|
+
for (const w of r.warnings)
|
|
243
|
+
process.stdout.write(`warning: ${w}\n`);
|
|
244
|
+
if (r.results.length === 0 && r.providers.every((p) => p.kind === 'index'))
|
|
245
|
+
process.stdout.write('Tip: the local index may be empty. Run `bashirweb crawl <url>` or configure a SearXNG source.\n');
|
|
246
|
+
});
|
|
247
|
+
return 0;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
case 'crawl': {
|
|
251
|
+
const seeds = [sub, ...rest].filter((s) => Boolean(s));
|
|
252
|
+
if (!seeds.length)
|
|
253
|
+
throw new Error('Usage: bashirweb crawl <url...>');
|
|
254
|
+
return withBw(values, async (bw) => {
|
|
255
|
+
if (bw.runtime === 'local' && !values['json']) {
|
|
256
|
+
bw.events.on('crawler:progress', (p) => process.stderr.write(`\rvisited ${p.visited} · queued ${p.queued} · failed ${p.failed} `));
|
|
257
|
+
}
|
|
258
|
+
const report = await bw.crawl({
|
|
259
|
+
seeds,
|
|
260
|
+
...(values['depth'] !== undefined ? { maxDepth: int(values['depth'], 'depth') } : {}),
|
|
261
|
+
...(values['max-pages'] !== undefined ? { maxPages: int(values['max-pages'], 'max-pages') } : {}),
|
|
262
|
+
...(values['delay'] !== undefined ? { perDomainDelay: int(values['delay'], 'delay') } : {}),
|
|
263
|
+
...(values['no-sitemaps'] ? { useSitemaps: false } : {}),
|
|
264
|
+
...(values['render'] ? { render: true } : {}),
|
|
265
|
+
});
|
|
266
|
+
out(values, report, () => {
|
|
267
|
+
process.stderr.write('\n');
|
|
268
|
+
process.stdout.write(`Crawl ${report.status}: ${report.fetched} fetched, ${report.skipped} skipped, ${report.failed} failed, ${report.blocked} blocked in ${report.durationMs}ms\n`);
|
|
269
|
+
for (const p of report.pages.filter((x) => x.outcome !== 'fetched').slice(0, 20))
|
|
270
|
+
process.stdout.write(` ${p.outcome}: ${p.url} (${p.reason})\n`);
|
|
271
|
+
});
|
|
272
|
+
return report.status === 'completed' ? 0 : 1;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
case 'index':
|
|
276
|
+
return withBw(values, async (bw) => {
|
|
277
|
+
if (sub === 'add' && rest[0]) {
|
|
278
|
+
const r = await bw.index.addUrl(rest[0]);
|
|
279
|
+
out(values, r, () => process.stdout.write(`${r.status}: ${r.title} (${r.url})\n`));
|
|
280
|
+
}
|
|
281
|
+
else if (sub === 'stats') {
|
|
282
|
+
const s = await bw.index.stats();
|
|
283
|
+
out(values, s, () => process.stdout.write(`${JSON.stringify(s, null, 2)}\n`));
|
|
284
|
+
}
|
|
285
|
+
else
|
|
286
|
+
throw new Error('Usage: bashirweb index add <url> | index stats');
|
|
287
|
+
return 0;
|
|
288
|
+
});
|
|
289
|
+
case 'extract': {
|
|
290
|
+
if (!sub)
|
|
291
|
+
throw new Error('Usage: bashirweb extract <url> [--format markdown|text|html|json] [--render]');
|
|
292
|
+
const format = String(values['format'] ?? 'markdown');
|
|
293
|
+
if (!['markdown', 'text', 'html', 'json'].includes(format))
|
|
294
|
+
throw new Error('--format must be markdown, text, html or json');
|
|
295
|
+
return withBw(values, async (bw) => {
|
|
296
|
+
// Plain HTTP unless --render: network policy and robots.txt apply (see crawler.respectRobots). Works with --remote.
|
|
297
|
+
const doc = await bw.extract(sub, { render: Boolean(values['render']) });
|
|
298
|
+
process.stdout.write(`${format === 'json' ? JSON.stringify(doc, null, 2) : format === 'text' ? doc.text : format === 'html' ? doc.html : doc.markdown}\n`);
|
|
299
|
+
return 0;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
case 'browser':
|
|
303
|
+
if (sub === 'install') {
|
|
304
|
+
// Delegates to the playwright-core version BashirWeb is built against.
|
|
305
|
+
const { playwrightCliPath } = await import('@dream_engine/browser');
|
|
306
|
+
const { spawnSync } = await import('node:child_process');
|
|
307
|
+
const engines = rest.length ? rest : ['chromium'];
|
|
308
|
+
const bad = engines.filter((e) => !['chromium', 'firefox', 'webkit', 'ffmpeg'].includes(e));
|
|
309
|
+
if (bad.length)
|
|
310
|
+
throw new Error(`Unknown engine(s): ${bad.join(', ')} (expected chromium, firefox, webkit or ffmpeg)`);
|
|
311
|
+
const r = spawnSync(process.execPath, [playwrightCliPath(), 'install', ...(values['with-deps'] ? ['--with-deps'] : []), ...engines], {
|
|
312
|
+
stdio: 'inherit',
|
|
313
|
+
});
|
|
314
|
+
return r.status ?? 1;
|
|
315
|
+
}
|
|
316
|
+
return withBw(values, async (bw) => {
|
|
317
|
+
if (sub === 'list') {
|
|
318
|
+
const engines = bw.local.browsers.detectEngines();
|
|
319
|
+
out(values, engines, () => {
|
|
320
|
+
for (const e of engines)
|
|
321
|
+
process.stdout.write(`${e.engine.padEnd(9)} ${e.source === 'missing' ? 'not installed' : `${e.executablePath} (${e.source})`}\n`);
|
|
322
|
+
});
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
if (sub === 'launch') {
|
|
326
|
+
const browser = await bw.local.browsers.launch({
|
|
327
|
+
...(values['engine'] ? { engine: String(values['engine']) } : {}),
|
|
328
|
+
headless: !values['headed'],
|
|
329
|
+
});
|
|
330
|
+
const ctx = await browser.newContext();
|
|
331
|
+
const page = await ctx.newPage();
|
|
332
|
+
if (rest[0])
|
|
333
|
+
await page.goto(rest[0]);
|
|
334
|
+
process.stdout.write(`${browser.engine} ${browser.version()} running${values['headed'] ? '' : ' (headless)'}. Press Ctrl+C to close.\n`);
|
|
335
|
+
await new Promise((r) => {
|
|
336
|
+
process.once('SIGINT', r);
|
|
337
|
+
process.once('SIGTERM', r);
|
|
338
|
+
browser.adapter.onDisconnected(() => r());
|
|
339
|
+
});
|
|
340
|
+
return 0;
|
|
341
|
+
}
|
|
342
|
+
throw new Error('Usage: bashirweb browser list | browser launch [url] | browser install [engine...] [--with-deps]');
|
|
343
|
+
});
|
|
344
|
+
case 'artifacts':
|
|
345
|
+
return withBw(values, async (bw) => {
|
|
346
|
+
const a = bw.artifacts;
|
|
347
|
+
if (!sub || sub === 'list') {
|
|
348
|
+
const list = a.list(rest[0] ? { kind: rest[0] } : {});
|
|
349
|
+
out(values, list, () => {
|
|
350
|
+
if (!list.length)
|
|
351
|
+
process.stdout.write('No artifacts.\n');
|
|
352
|
+
for (const x of list)
|
|
353
|
+
process.stdout.write(`${x.modifiedAt} ${String(x.bytes).padStart(10)} ${x.id}\n`);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
else if (sub === 'stats') {
|
|
357
|
+
const st = a.stats();
|
|
358
|
+
out(values, st, () => {
|
|
359
|
+
process.stdout.write(`${st.files} files, ${st.bytes} bytes\n`);
|
|
360
|
+
for (const [k, v] of Object.entries(st.byKind))
|
|
361
|
+
if (v.files)
|
|
362
|
+
process.stdout.write(` ${k.padEnd(12)} ${v.files} files, ${v.bytes} bytes\n`);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
else if (sub === 'prune') {
|
|
366
|
+
const r = await a.prune();
|
|
367
|
+
out(values, r, () => process.stdout.write(`Deleted ${r.deleted.length} files (${r.freedBytes} bytes).\n`));
|
|
368
|
+
}
|
|
369
|
+
else if (sub === 'delete' && rest[0]) {
|
|
370
|
+
const ok = a.delete(rest[0]);
|
|
371
|
+
out(values, { deleted: ok }, () => process.stdout.write(ok ? 'Deleted.\n' : 'Not found.\n'));
|
|
372
|
+
return ok ? 0 : 1;
|
|
373
|
+
}
|
|
374
|
+
else
|
|
375
|
+
throw new Error('Usage: bashirweb artifacts list [kind] | stats | prune | delete <id>');
|
|
376
|
+
return 0;
|
|
377
|
+
});
|
|
378
|
+
case 'workflow':
|
|
379
|
+
return withBw(values, async (bw) => {
|
|
380
|
+
if (sub === 'validate' && rest[0]) {
|
|
381
|
+
const def = JSON.parse(readFileSync(rest[0], 'utf8'));
|
|
382
|
+
const r = bw.workflows.validate(def);
|
|
383
|
+
out(values, r, () => process.stdout.write(r.valid ? 'Workflow is valid\n' : `Invalid workflow:\n${r.issues.map((i) => ` ${i.path}: ${i.message}`).join('\n')}\n`));
|
|
384
|
+
return r.valid ? 0 : 1;
|
|
385
|
+
}
|
|
386
|
+
if (sub === 'run' && rest[0]) {
|
|
387
|
+
const inputs = {};
|
|
388
|
+
for (const kv of values['input'] ?? []) {
|
|
389
|
+
const i = kv.indexOf('=');
|
|
390
|
+
if (i < 1)
|
|
391
|
+
throw new Error(`--input must be key=value (got "${kv}")`);
|
|
392
|
+
inputs[kv.slice(0, i)] = kv.slice(i + 1);
|
|
393
|
+
}
|
|
394
|
+
const ref = existsSync(rest[0]) ? JSON.parse(readFileSync(rest[0], 'utf8')) : rest[0];
|
|
395
|
+
const record = await bw.workflows.run(ref, { inputs });
|
|
396
|
+
out(values, record, () => {
|
|
397
|
+
process.stdout.write(`Run ${record.runId}: ${record.status} in ${record.durationMs}ms (${record.executedSteps} steps)\n`);
|
|
398
|
+
for (const s of record.steps)
|
|
399
|
+
process.stdout.write(` ${s.status === 'completed' ? '✔' : s.status === 'failed' ? '✖' : '-'} ${s.path} ${s.type}${s.name ? ` "${s.name}"` : ''}${s.error ? ` — ${s.error.message}` : ''}\n`);
|
|
400
|
+
});
|
|
401
|
+
return record.status === 'completed' ? 0 : 1;
|
|
402
|
+
}
|
|
403
|
+
if (sub === 'list') {
|
|
404
|
+
const list = bw.workflows.list();
|
|
405
|
+
out(values, list, () => list.forEach((w) => process.stdout.write(`${w.id} v${w.version} ${w.name} (${w.steps} steps)\n`)));
|
|
406
|
+
return 0;
|
|
407
|
+
}
|
|
408
|
+
if (sub === 'history') {
|
|
409
|
+
const h = bw.workflows.history({ limit: 20 });
|
|
410
|
+
out(values, h, () => h.forEach((r) => process.stdout.write(`${r.runId} ${r.status.padEnd(9)} ${r.workflowName} v${r.workflowVersion} ${r.startedAt}\n`)));
|
|
411
|
+
return 0;
|
|
412
|
+
}
|
|
413
|
+
throw new Error('Usage: bashirweb workflow validate <file> | run <file|id> | list | history');
|
|
414
|
+
});
|
|
415
|
+
case 'server': {
|
|
416
|
+
if (sub === 'start') {
|
|
417
|
+
const cfg = {
|
|
418
|
+
...baseConfig(values),
|
|
419
|
+
server: { ...(values['host'] ? { host: String(values['host']) } : {}), ...(values['port'] ? { port: int(values['port'], 'port') } : {}) },
|
|
420
|
+
};
|
|
421
|
+
const { server, url, config } = await startServer({ config: cfg, ...(values['config'] ? { configFile: String(values['config']) } : {}) });
|
|
422
|
+
writeFileSync(pidFile(config.runtime.dataDir), JSON.stringify({ pid: process.pid, url, startedAt: new Date().toISOString() }));
|
|
423
|
+
process.stdout.write(`BashirWeb server listening on ${url}${config.server.tokens.length ? '' : ' (no auth — loopback only)'}\n`);
|
|
424
|
+
await new Promise((r) => {
|
|
425
|
+
process.once('SIGINT', r);
|
|
426
|
+
process.once('SIGTERM', r);
|
|
427
|
+
});
|
|
428
|
+
process.stdout.write('Shutting down...\n');
|
|
429
|
+
await server.close();
|
|
430
|
+
rmSync(pidFile(config.runtime.dataDir), { force: true });
|
|
431
|
+
return 0;
|
|
432
|
+
}
|
|
433
|
+
if (sub === 'stop') {
|
|
434
|
+
return withBw(values, async (bw) => {
|
|
435
|
+
const file = pidFile(bw.getConfig().runtime.dataDir);
|
|
436
|
+
if (!existsSync(file))
|
|
437
|
+
throw new Error('No server is recorded for this data directory');
|
|
438
|
+
const info = JSON.parse(readFileSync(file, 'utf8'));
|
|
439
|
+
if (!isAlive(info.pid)) {
|
|
440
|
+
rmSync(file, { force: true });
|
|
441
|
+
process.stdout.write('Server was not running (stale record removed)\n');
|
|
442
|
+
return 0;
|
|
443
|
+
}
|
|
444
|
+
process.kill(info.pid, 'SIGTERM');
|
|
445
|
+
for (let i = 0; i < 100 && isAlive(info.pid); i++)
|
|
446
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
447
|
+
process.stdout.write(isAlive(info.pid) ? 'Sent SIGTERM; server is still shutting down\n' : 'Server stopped\n');
|
|
448
|
+
return 0;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
throw new Error('Usage: bashirweb server start | server stop');
|
|
452
|
+
}
|
|
453
|
+
case 'test': {
|
|
454
|
+
const { runTests } = await import('@dream_engine/testing');
|
|
455
|
+
const summary = await runTests({
|
|
456
|
+
...(values['config'] ? { configFile: String(values['config']) } : {}),
|
|
457
|
+
files: rest.length ? rest : undefined,
|
|
458
|
+
grep: values['grep'] ? String(values['grep']) : undefined,
|
|
459
|
+
grepInvert: Boolean(values['grep-invert']),
|
|
460
|
+
tags: values['tags']
|
|
461
|
+
? String(values['tags'])
|
|
462
|
+
.split(',')
|
|
463
|
+
.map((t) => t.trim())
|
|
464
|
+
.filter(Boolean)
|
|
465
|
+
: undefined,
|
|
466
|
+
project: values['project'] ? String(values['project']) : undefined,
|
|
467
|
+
bail: Boolean(values['bail']),
|
|
468
|
+
list: Boolean(values['list']),
|
|
469
|
+
overrides: {
|
|
470
|
+
...(values['timeout'] ? { timeout: int(values['timeout'], 'timeout') } : {}),
|
|
471
|
+
...(values['retries'] !== undefined ? { retries: int(values['retries'], 'retries') } : {}),
|
|
472
|
+
...(values['workers'] ? { workers: int(values['workers'], 'workers') } : {}),
|
|
473
|
+
...(values['reporter'] ? { reporter: String(values['reporter']) } : {}),
|
|
474
|
+
...(values['browser'] ? { browsers: [String(values['browser'])] } : {}),
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
if (values['json'])
|
|
478
|
+
process.stdout.write(`${JSON.stringify(summary, null, 2)}\n`);
|
|
479
|
+
return summary.exitCode;
|
|
480
|
+
}
|
|
481
|
+
case 'trace': {
|
|
482
|
+
const traceSub = sub;
|
|
483
|
+
if (traceSub !== 'view') {
|
|
484
|
+
process.stderr.write('Usage: bashirweb trace view <file.zip> [--host h] [--port p]\n');
|
|
485
|
+
return 1;
|
|
486
|
+
}
|
|
487
|
+
const traceFile = rest[0];
|
|
488
|
+
if (!traceFile) {
|
|
489
|
+
process.stderr.write('Usage: bashirweb trace view <file.zip> [--host h] [--port p]\n');
|
|
490
|
+
return 1;
|
|
491
|
+
}
|
|
492
|
+
const handle = await startTraceViewer(resolve(traceFile), {
|
|
493
|
+
host: values['host'] ? String(values['host']) : undefined,
|
|
494
|
+
port: values['port'] ? int(values['port'], 'port') : undefined,
|
|
495
|
+
});
|
|
496
|
+
const message = `Trace viewer serving ${handle.url} (trace: ${traceFile})\nPress Ctrl+C to stop.\n`;
|
|
497
|
+
process.stdout.write(message);
|
|
498
|
+
await new Promise((resolvePromise) => {
|
|
499
|
+
const stop = () => {
|
|
500
|
+
void handle.close().then(() => resolvePromise());
|
|
501
|
+
};
|
|
502
|
+
process.on('SIGINT', stop);
|
|
503
|
+
process.on('SIGTERM', stop);
|
|
504
|
+
});
|
|
505
|
+
return 0;
|
|
506
|
+
}
|
|
507
|
+
case 'mcp':
|
|
508
|
+
return withBw(values, async (bw) => {
|
|
509
|
+
await bw.mcp().serve();
|
|
510
|
+
return 0;
|
|
511
|
+
});
|
|
512
|
+
case 'agent': {
|
|
513
|
+
const action = (values._[1] ?? 'run');
|
|
514
|
+
if (action === 'models') {
|
|
515
|
+
return withBw(values, async (bw) => {
|
|
516
|
+
const config = bw.getConfig();
|
|
517
|
+
const client = createLocalModel(config.ai);
|
|
518
|
+
const result = await detectLocalModel(client);
|
|
519
|
+
if (values.json)
|
|
520
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
521
|
+
else {
|
|
522
|
+
process.stdout.write(`Local model available: ${result.available}\n${result.detail}\n`);
|
|
523
|
+
if (result.models)
|
|
524
|
+
process.stdout.write(`Models: ${result.models.join(', ')}\n`);
|
|
525
|
+
}
|
|
526
|
+
process.stdout.write(result.available ? 'Ready to run AI-driven orchestration.\n' : 'AI orchestration is NOT ready. Install Ollama and pull a model, then set ai.enabled=true.\n');
|
|
527
|
+
return 0;
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (action === 'status') {
|
|
531
|
+
return withBw(values, async (bw) => {
|
|
532
|
+
const storePath = join(bw.getConfig().runtime.dataDir, 'orchestration');
|
|
533
|
+
process.stdout.write(`Orchestration tasks are persisted under: ${storePath}\n`);
|
|
534
|
+
process.stdout.write('Run "bashirweb agent run" with an objective to execute.\n');
|
|
535
|
+
if (values.json)
|
|
536
|
+
process.stdout.write(`${JSON.stringify({ note: 'per-invocation orchestration', storePath }, null, 2)}\n`);
|
|
537
|
+
return 0;
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
const objective = (values._[2] ?? values.objective);
|
|
541
|
+
if (!objective)
|
|
542
|
+
throw new Error('Usage: bashirweb agent run "<objective>"');
|
|
543
|
+
return withBw(values, async (bw) => {
|
|
544
|
+
const config = bw.getConfig();
|
|
545
|
+
const client = createLocalModel(config.ai);
|
|
546
|
+
const availability = await detectLocalModel(client);
|
|
547
|
+
if (!availability.available) {
|
|
548
|
+
process.stderr.write('No local AI model is available. BashirWeb uses LOCAL models only — no cloud AI APIs.\n');
|
|
549
|
+
process.stderr.write(availability.detail + '\n');
|
|
550
|
+
process.stderr.write("To enable AI orchestration: install Ollama (https://ollama.com), run 'ollama pull llama3.1', and set ai.enabled=true, ai.provider=ollama, ai.model=llama3.1 in your config.\n");
|
|
551
|
+
return 2;
|
|
552
|
+
}
|
|
553
|
+
const model = createLocalReasoningModel(client);
|
|
554
|
+
const browserInstance = await bw.browser.launch();
|
|
555
|
+
try {
|
|
556
|
+
const browser = new BrowserOperator(browserInstance, model);
|
|
557
|
+
const computer = new ComputerAgent(model, { level: 'observe', cwd: process.cwd() });
|
|
558
|
+
const orch = new MultiAgentOrchestrator(browser, computer, model, { maxCycles: 20 });
|
|
559
|
+
const task = await orch.run(objective, {
|
|
560
|
+
onEvent: (event, task) => {
|
|
561
|
+
if (!values.json)
|
|
562
|
+
process.stdout.write(`[${task.id}:${event.type}] ${event.message}\n`);
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
if (values.json)
|
|
566
|
+
process.stdout.write(`${JSON.stringify(task, null, 2)}\n`);
|
|
567
|
+
else {
|
|
568
|
+
process.stdout.write(`\n=== Result [${task.status}] ===\n`);
|
|
569
|
+
if (task.report)
|
|
570
|
+
process.stdout.write(task.report + '\n');
|
|
571
|
+
if (task.intervention)
|
|
572
|
+
process.stdout.write(`Intervention needed: ${task.intervention}\n`);
|
|
573
|
+
}
|
|
574
|
+
return task.status === 'completed' ? 0 : 1;
|
|
575
|
+
}
|
|
576
|
+
finally {
|
|
577
|
+
await browserInstance.close();
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
default:
|
|
582
|
+
throw new Error(`Unknown command "${cmd}". Run "bashirweb --help".`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
main(process.argv.slice(2)).then((code) => {
|
|
586
|
+
process.exitCode = code;
|
|
587
|
+
}, (error) => {
|
|
588
|
+
const json = process.argv.includes('--json');
|
|
589
|
+
if (json)
|
|
590
|
+
process.stdout.write(`${JSON.stringify({ error: serializeError(error) }, null, 2)}\n`);
|
|
591
|
+
else {
|
|
592
|
+
process.stderr.write(`Error: ${error.message}\n`);
|
|
593
|
+
if (error instanceof BashirWebError && error.hint)
|
|
594
|
+
process.stderr.write(`Hint: ${error.hint}\n`);
|
|
595
|
+
}
|
|
596
|
+
process.exitCode = 1;
|
|
597
|
+
});
|
|
598
|
+
//# sourceMappingURL=main.js.map
|