backtrace-console 0.0.2 → 0.0.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # backtrace-console
2
2
 
3
- CLI for querying Backtrace fingerprints, collecting artifacts, and generating repair plans.
3
+ Server manager for [backtrace-console](https://github.com/your-org/backtrace-console) start, stop, and manage the Express server process from the command line.
4
4
 
5
5
  ## Install
6
6
 
@@ -8,15 +8,32 @@ CLI for querying Backtrace fingerprints, collecting artifacts, and generating re
8
8
  npm install -g backtrace-console
9
9
  ```
10
10
 
11
- ## Commands
11
+ ## Usage
12
+
13
+ Run all commands from the **backtrace-console project root directory**.
12
14
 
13
15
  ```bash
14
- backtrace list
15
- backtrace fingerprint --fingerprint <value>
16
- backtrace collect --fingerprint <value>
17
- backtrace summarize-errors --fingerprint <value>
18
- backtrace fix-plan --fingerprint <value>
19
- backtrace apply-fix --fingerprint <value>
16
+ # 前台启动(Ctrl+C 停止)
17
+ backtrace-server run
18
+
19
+ # 后台守护进程启动
20
+ backtrace-server start
21
+
22
+ # 停止后台进程
23
+ backtrace-server stop
24
+
25
+ # 查看运行状态
26
+ backtrace-server status
20
27
  ```
21
28
 
22
- Run `backtrace --help` for the full option list.
29
+ ## How it works
30
+
31
+ - `run` — loads `.env` in the current directory and starts `bin/www` in the foreground.
32
+ - `start` — spawns `bin/www` as a detached background process. PID is saved to `.backtrace-server.pid` and logs are appended to `.backtrace-server.log`.
33
+ - `stop` — reads `.backtrace-server.pid` and sends `SIGTERM` to the process.
34
+ - `status` — checks whether the recorded PID is still alive.
35
+
36
+ ## Requirements
37
+
38
+ - Node.js 18+
39
+ - Must be run inside a `backtrace-console` project directory (i.e. `bin/www` must exist).
@@ -2,31 +2,38 @@
2
2
 
3
3
  'use strict';
4
4
 
5
- require('dotenv').config();
6
-
7
5
  var path = require('node:path');
8
6
  var fs = require('node:fs');
9
7
  var { spawn } = require('node:child_process');
10
8
 
11
- var ROOT = path.resolve(__dirname, '..');
12
- var PID_FILE = path.join(ROOT, '.backtrace-server.pid');
13
- var LOG_FILE = path.join(ROOT, '.backtrace-server.log');
14
- var WWW = path.join(__dirname, 'www');
9
+ // 在当前工作目录下查找项目入口
10
+ var CWD = process.cwd();
11
+ var WWW = path.join(CWD, 'bin', 'www');
12
+ var PID_FILE = path.join(CWD, '.backtrace-server.pid');
13
+ var LOG_FILE = path.join(CWD, '.backtrace-server.log');
15
14
 
16
15
  var cmd = process.argv[2];
17
16
 
17
+ if (cmd === 'run' || cmd === 'start') {
18
+ if (!fs.existsSync(WWW)) {
19
+ console.error('[backtrace-server] 未找到入口文件: ' + WWW);
20
+ console.error('[backtrace-server] 请在 backtrace-console 项目根目录下运行此命令');
21
+ process.exit(1);
22
+ }
23
+ }
24
+
18
25
  if (cmd === 'run') {
19
- // 前台运行,直接 require www(同进程)
20
- require('./www');
26
+ // 前台运行,加载 .env 后直接 require 入口
27
+ try { require('dotenv').config({ path: path.join(CWD, '.env') }); } catch (_) {}
28
+ require(WWW);
21
29
  return;
22
30
  }
23
31
 
24
32
  if (cmd === 'start') {
25
- // 检查是否已在运行
26
33
  if (fs.existsSync(PID_FILE)) {
27
34
  var existingPid = parseInt(fs.readFileSync(PID_FILE, 'utf8').trim(), 10);
28
35
  if (existingPid && isRunning(existingPid)) {
29
- console.log('[backtrace] server already running, pid=' + existingPid);
36
+ console.log('[backtrace-server] already running, pid=' + existingPid);
30
37
  process.exit(0);
31
38
  }
32
39
  fs.unlinkSync(PID_FILE);
@@ -37,31 +44,31 @@ if (cmd === 'start') {
37
44
  detached: true,
38
45
  stdio: ['ignore', logFd, logFd],
39
46
  env: process.env,
40
- cwd: ROOT,
47
+ cwd: CWD,
41
48
  });
42
49
  child.unref();
43
50
  fs.writeFileSync(PID_FILE, String(child.pid), 'utf8');
44
- console.log('[backtrace] server started, pid=' + child.pid + ', log=' + LOG_FILE);
51
+ console.log('[backtrace-server] started, pid=' + child.pid + ', log=' + LOG_FILE);
45
52
  process.exit(0);
46
53
  }
47
54
 
48
55
  if (cmd === 'stop') {
49
56
  if (!fs.existsSync(PID_FILE)) {
50
- console.log('[backtrace] server is not running (no pid file)');
57
+ console.log('[backtrace-server] not running (no pid file)');
51
58
  process.exit(0);
52
59
  }
53
60
  var pid = parseInt(fs.readFileSync(PID_FILE, 'utf8').trim(), 10);
54
61
  if (!pid || !isRunning(pid)) {
55
- console.log('[backtrace] server is not running (pid=' + pid + ')');
62
+ console.log('[backtrace-server] not running (pid=' + pid + ')');
56
63
  fs.unlinkSync(PID_FILE);
57
64
  process.exit(0);
58
65
  }
59
66
  try {
60
67
  process.kill(pid, 'SIGTERM');
61
68
  fs.unlinkSync(PID_FILE);
62
- console.log('[backtrace] server stopped, pid=' + pid);
69
+ console.log('[backtrace-server] stopped, pid=' + pid);
63
70
  } catch (err) {
64
- console.error('[backtrace] failed to stop server:', err.message);
71
+ console.error('[backtrace-server] failed to stop:', err.message);
65
72
  process.exit(1);
66
73
  }
67
74
  process.exit(0);
@@ -69,14 +76,14 @@ if (cmd === 'stop') {
69
76
 
70
77
  if (cmd === 'status') {
71
78
  if (!fs.existsSync(PID_FILE)) {
72
- console.log('[backtrace] server is not running');
79
+ console.log('[backtrace-server] not running');
73
80
  process.exit(0);
74
81
  }
75
82
  var statusPid = parseInt(fs.readFileSync(PID_FILE, 'utf8').trim(), 10);
76
83
  if (statusPid && isRunning(statusPid)) {
77
- console.log('[backtrace] server is running, pid=' + statusPid);
84
+ console.log('[backtrace-server] running, pid=' + statusPid);
78
85
  } else {
79
- console.log('[backtrace] server is not running (stale pid=' + statusPid + ')');
86
+ console.log('[backtrace-server] not running (stale pid=' + statusPid + ')');
80
87
  fs.unlinkSync(PID_FILE);
81
88
  }
82
89
  process.exit(0);
@@ -84,18 +91,15 @@ if (cmd === 'status') {
84
91
 
85
92
  console.log([
86
93
  'Usage:',
87
- ' backtrace-server run 前台启动服务器',
94
+ ' backtrace-server run 前台启动(Ctrl+C 停止)',
88
95
  ' backtrace-server start 后台守护进程启动',
89
96
  ' backtrace-server stop 停止后台进程',
90
97
  ' backtrace-server status 查看运行状态',
98
+ '',
99
+ '请在 backtrace-console 项目根目录下运行。',
91
100
  ].join('\n'));
92
101
  process.exit(1);
93
102
 
94
103
  function isRunning(pid) {
95
- try {
96
- process.kill(pid, 0);
97
- return true;
98
- } catch (_) {
99
- return false;
100
- }
104
+ try { process.kill(pid, 0); return true; } catch (_) { return false; }
101
105
  }
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "backtrace-console",
3
- "version": "0.0.2",
4
- "description": "CLI for querying Backtrace fingerprints, collecting artifacts, and generating repair plans.",
3
+ "version": "0.0.3",
4
+ "description": "CLI server manager for backtrace-console run/start/stop the Express server.",
5
5
  "private": false,
6
6
  "files": [
7
- "app.js",
8
- "bin",
9
- "lib",
10
- "public",
11
- "routes"
7
+ "bin/backtrace-server.js"
12
8
  ],
13
9
  "bin": {
14
- "backtrace": "bin/backtrace-cli.js",
15
10
  "backtrace-server": "bin/backtrace-server.js"
16
11
  },
17
12
  "scripts": {
@@ -22,12 +17,12 @@
22
17
  "server:stop": "node ./bin/backtrace-server.js stop",
23
18
  "server:status": "node ./bin/backtrace-server.js status"
24
19
  },
25
- "dependencies": {
20
+ "devDependencies": {
26
21
  "@openai/codex-sdk": "^0.128.0",
27
22
  "cookie-parser": "~1.4.4",
28
23
  "debug": "~2.6.9",
29
24
  "dotenv": "^17.4.1",
30
- "express": "~4.16.1",
25
+ "express": "~4.21.0",
31
26
  "morgan": "~1.9.1",
32
27
  "node-cron": "^4.2.1",
33
28
  "undici": "^7.24.8"
package/app.js DELETED
@@ -1,23 +0,0 @@
1
- var express = require('express');
2
- var path = require('path');
3
- var cookieParser = require('cookie-parser');
4
- var logger = require('morgan');
5
-
6
- var indexRouter = require('./routes/index');
7
- var usersRouter = require('./routes/users');
8
- var backtraceRouter = require('./routes/backtrace');
9
-
10
- var app = express();
11
-
12
- app.use(logger('dev'));
13
- app.use(express.json({ limit: '50mb' }));
14
- app.use(express.urlencoded({ extended: false, limit: '50mb' }));
15
- app.use(cookieParser());
16
- app.use(express.static(path.join(__dirname, 'public')));
17
-
18
- app.use('/', indexRouter);
19
- app.use('/users', usersRouter);
20
-
21
- app.use('/api/backtrace', backtraceRouter);
22
-
23
- module.exports = app;
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require("dotenv").config();
4
-
5
- const { parseCliArgs, printCliUsage } = require("../lib/cli/args");
6
- const { runCliCommand } = require("../lib/cli/run");
7
-
8
- async function main() {
9
- const parsed = parseCliArgs(process.argv.slice(2));
10
- if (parsed.help) {
11
- printCliUsage();
12
- return;
13
- }
14
- await runCliCommand(parsed.options);
15
- process.exit(0);
16
- }
17
-
18
- main().catch((error) => {
19
- console.error("backtrace-cli failed:");
20
- console.error(error instanceof Error ? error.stack || error.message : error);
21
- process.exit(1);
22
- });
package/bin/www DELETED
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Module dependencies.
5
- */
6
- require("dotenv").config();
7
-
8
- var app = require('../app');
9
- var debug = require('debug')('backtrace-console:server');
10
- var http = require('http');
11
-
12
- /**
13
- * Get port from environment and store in Express.
14
- */
15
-
16
- var port = normalizePort(process.env.PORT || '3000');
17
- app.set('port', port);
18
-
19
- /**
20
- * Create HTTP server.
21
- */
22
-
23
- var server = http.createServer(app);
24
-
25
- /**
26
- * Listen on provided port, on all network interfaces.
27
- */
28
-
29
- server.listen(port);
30
- server.on('error', onError);
31
- server.on('listening', onListening);
32
-
33
- require('../lib/scheduler').start();
34
-
35
- /**
36
- * Normalize a port into a number, string, or false.
37
- */
38
-
39
- function normalizePort(val) {
40
- var port = parseInt(val, 10);
41
-
42
- if (isNaN(port)) {
43
- // named pipe
44
- return val;
45
- }
46
-
47
- if (port >= 0) {
48
- // port number
49
- return port;
50
- }
51
-
52
- return false;
53
- }
54
-
55
- /**
56
- * Event listener for HTTP server "error" event.
57
- */
58
-
59
- function onError(error) {
60
- if (error.syscall !== 'listen') {
61
- throw error;
62
- }
63
-
64
- var bind = typeof port === 'string'
65
- ? 'Pipe ' + port
66
- : 'Port ' + port;
67
-
68
- // handle specific listen errors with friendly messages
69
- switch (error.code) {
70
- case 'EACCES':
71
- console.error(bind + ' requires elevated privileges');
72
- process.exit(1);
73
- break;
74
- case 'EADDRINUSE':
75
- console.error(bind + ' is already in use');
76
- process.exit(1);
77
- break;
78
- default:
79
- throw error;
80
- }
81
- }
82
-
83
- /**
84
- * Event listener for HTTP server "listening" event.
85
- */
86
-
87
- function onListening() {
88
- var addr = server.address();
89
- var bind = typeof addr === 'string'
90
- ? 'pipe ' + addr
91
- : 'port ' + addr.port;
92
- debug('Listening on ' + bind);
93
- }
@@ -1,32 +0,0 @@
1
- // 保留历史导入入口,实际能力全部委托给
2
- // lib/backtrace 和 lib/analysis 下的新模块实现。
3
- const {
4
- DEFAULT_QUERY_URL,
5
- DEFAULT_WORKDIR,
6
- DEFAULT_PROXY,
7
- DEFAULT_SELECT,
8
- DEFAULT_LIMIT,
9
- DEFAULT_DOWNLOAD_CONCURRENCY,
10
- DEFAULT_RETRIES,
11
- DEFAULT_STORAGE_DIR,
12
- } = require("./backtrace/constants");
13
- const { printUsage, parseArgs, createOptions } = require("./backtrace/options");
14
- const { printList } = require("./backtrace/analysis");
15
- const { BacktraceCodexTool, runBacktraceCommand } = require("./backtrace/tool");
16
-
17
- module.exports = {
18
- BacktraceCodexTool,
19
- runBacktraceCommand,
20
- createOptions,
21
- parseArgs,
22
- printUsage,
23
- printList,
24
- DEFAULT_QUERY_URL,
25
- DEFAULT_WORKDIR,
26
- DEFAULT_PROXY,
27
- DEFAULT_SELECT,
28
- DEFAULT_LIMIT,
29
- DEFAULT_DOWNLOAD_CONCURRENCY,
30
- DEFAULT_RETRIES,
31
- DEFAULT_STORAGE_DIR,
32
- };