@quangnv13/nonstop 1.0.0

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/dist/config.js ADDED
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ENV_EXAMPLE_FILE_PATH = exports.ENV_FILE_PATH = void 0;
37
+ exports.parseConfigFromEnv = parseConfigFromEnv;
38
+ exports.getMissingConfigFields = getMissingConfigFields;
39
+ exports.serializeConfigToEnv = serializeConfigToEnv;
40
+ exports.loadConfigFromDisk = loadConfigFromDisk;
41
+ exports.saveConfigToDisk = saveConfigToDisk;
42
+ exports.ensureEnvExampleFile = ensureEnvExampleFile;
43
+ exports.applyConfigToProcessEnv = applyConfigToProcessEnv;
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ const DEFAULTS = {
47
+ telegramBotToken: '',
48
+ adminUsername: '',
49
+ clientName: 'LocalClient',
50
+ telegramUsername: '',
51
+ language: 'en',
52
+ startupMode: 'disabled',
53
+ outputInterval: 20000,
54
+ maxOutputLines: 50,
55
+ maxRenderLines: 200,
56
+ codexCmd: 'codex',
57
+ codexArgs: '[]',
58
+ antigravityCmd: 'agy',
59
+ antigravityArgs: '[]'
60
+ };
61
+ exports.ENV_FILE_PATH = path.join(process.cwd(), '.env');
62
+ exports.ENV_EXAMPLE_FILE_PATH = path.join(process.cwd(), '.env.example');
63
+ function parseConfigFromEnv(env) {
64
+ return {
65
+ telegramBotToken: env.TELEGRAM_BOT_TOKEN?.trim() || DEFAULTS.telegramBotToken,
66
+ adminUsername: normalizeUsername(env.ADMIN_USERNAME || ''),
67
+ clientName: env.CLIENT_NAME?.trim() || DEFAULTS.clientName,
68
+ telegramUsername: normalizeUsername(env.TELEGRAM_USERNAME || ''),
69
+ language: parseLanguage(env.APP_LANGUAGE),
70
+ startupMode: parseStartupMode(env.STARTUP_MODE),
71
+ outputInterval: parseInteger(env.OUTPUT_INTERVAL, DEFAULTS.outputInterval),
72
+ maxOutputLines: parseInteger(env.MAX_OUTPUT_LINES, DEFAULTS.maxOutputLines),
73
+ maxRenderLines: parseInteger(env.MAX_RENDER_LINES, DEFAULTS.maxRenderLines),
74
+ codexCmd: env.CODEX_CMD?.trim() || DEFAULTS.codexCmd,
75
+ codexArgs: env.CODEX_ARGS?.trim() || DEFAULTS.codexArgs,
76
+ antigravityCmd: env.ANTIGRAVITY_CMD?.trim() || DEFAULTS.antigravityCmd,
77
+ antigravityArgs: env.ANTIGRAVITY_ARGS?.trim() || DEFAULTS.antigravityArgs
78
+ };
79
+ }
80
+ function getMissingConfigFields(config) {
81
+ const missing = [];
82
+ if (!config.telegramBotToken) {
83
+ missing.push('telegramBotToken');
84
+ }
85
+ if (!config.adminUsername) {
86
+ missing.push('adminUsername');
87
+ }
88
+ return missing;
89
+ }
90
+ function serializeConfigToEnv(config) {
91
+ return [
92
+ `TELEGRAM_BOT_TOKEN=${config.telegramBotToken}`,
93
+ `ADMIN_USERNAME=${config.adminUsername}`,
94
+ `CLIENT_NAME=${config.clientName}`,
95
+ `TELEGRAM_USERNAME=${config.telegramUsername}`,
96
+ `APP_LANGUAGE=${config.language}`,
97
+ `STARTUP_MODE=${config.startupMode}`,
98
+ `OUTPUT_INTERVAL=${config.outputInterval}`,
99
+ `MAX_OUTPUT_LINES=${config.maxOutputLines}`,
100
+ `MAX_RENDER_LINES=${config.maxRenderLines}`,
101
+ '',
102
+ '# CLI OVERRIDES (Optional)',
103
+ `CODEX_CMD=${config.codexCmd}`,
104
+ `CODEX_ARGS=${config.codexArgs}`,
105
+ `ANTIGRAVITY_CMD=${config.antigravityCmd}`,
106
+ `ANTIGRAVITY_ARGS=${config.antigravityArgs}`,
107
+ ''
108
+ ].join('\n');
109
+ }
110
+ function loadConfigFromDisk() {
111
+ if (!fs.existsSync(exports.ENV_FILE_PATH)) {
112
+ return DEFAULTS;
113
+ }
114
+ const raw = fs.readFileSync(exports.ENV_FILE_PATH, 'utf8');
115
+ const env = {};
116
+ for (const line of raw.split(/\r?\n/)) {
117
+ const trimmed = line.trim();
118
+ if (!trimmed || trimmed.startsWith('#')) {
119
+ continue;
120
+ }
121
+ const separatorIndex = trimmed.indexOf('=');
122
+ if (separatorIndex === -1) {
123
+ continue;
124
+ }
125
+ const key = trimmed.slice(0, separatorIndex).trim();
126
+ const value = trimmed.slice(separatorIndex + 1);
127
+ env[key] = value;
128
+ }
129
+ return parseConfigFromEnv(env);
130
+ }
131
+ function saveConfigToDisk(config) {
132
+ fs.writeFileSync(exports.ENV_FILE_PATH, serializeConfigToEnv(config), 'utf8');
133
+ }
134
+ function ensureEnvExampleFile() {
135
+ if (fs.existsSync(exports.ENV_EXAMPLE_FILE_PATH)) {
136
+ return;
137
+ }
138
+ fs.writeFileSync(exports.ENV_EXAMPLE_FILE_PATH, serializeConfigToEnv(DEFAULTS), 'utf8');
139
+ }
140
+ function applyConfigToProcessEnv(config) {
141
+ process.env.TELEGRAM_BOT_TOKEN = config.telegramBotToken;
142
+ process.env.ADMIN_USERNAME = config.adminUsername;
143
+ process.env.CLIENT_NAME = config.clientName;
144
+ process.env.TELEGRAM_USERNAME = config.telegramUsername;
145
+ process.env.APP_LANGUAGE = config.language;
146
+ process.env.STARTUP_MODE = config.startupMode;
147
+ process.env.OUTPUT_INTERVAL = String(config.outputInterval);
148
+ process.env.MAX_OUTPUT_LINES = String(config.maxOutputLines);
149
+ process.env.MAX_RENDER_LINES = String(config.maxRenderLines);
150
+ process.env.CODEX_CMD = config.codexCmd;
151
+ process.env.CODEX_ARGS = config.codexArgs;
152
+ process.env.ANTIGRAVITY_CMD = config.antigravityCmd;
153
+ process.env.ANTIGRAVITY_ARGS = config.antigravityArgs;
154
+ }
155
+ function normalizeUsername(value) {
156
+ const trimmed = value.trim();
157
+ if (!trimmed) {
158
+ return '';
159
+ }
160
+ return trimmed.startsWith('@') ? trimmed : `@${trimmed}`;
161
+ }
162
+ function parseInteger(value, fallback) {
163
+ const parsed = parseInt(value || '', 10);
164
+ return Number.isFinite(parsed) ? parsed : fallback;
165
+ }
166
+ function parseLanguage(value) {
167
+ return value === 'vi' ? 'vi' : 'en';
168
+ }
169
+ function parseStartupMode(value) {
170
+ if (value === 'background' || value === 'open-ui') {
171
+ return value;
172
+ }
173
+ return 'disabled';
174
+ }
package/dist/i18n.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTranslator = createTranslator;
4
+ const MESSAGES = {
5
+ en: {
6
+ 'wizard.title': 'nonstop setup wizard',
7
+ 'wizard.language': 'Choose language (en/vi)',
8
+ 'wizard.token': 'Telegram bot token',
9
+ 'wizard.admin': 'Telegram username to allow (example: @yourname)',
10
+ 'wizard.clientName': 'Client name',
11
+ 'wizard.startupMode': 'Startup mode',
12
+ 'wizard.complete': 'Setup saved.',
13
+ 'dashboard.title': 'nonstop client',
14
+ 'dashboard.running': 'RUNNING',
15
+ 'dashboard.stopped': 'STOPPED',
16
+ 'dashboard.menu': 'Menu',
17
+ 'dashboard.choice': 'Choose an option',
18
+ 'menu.toggleRuntime': 'Start/Stop background runtime',
19
+ 'menu.settings': 'Edit config',
20
+ 'menu.workspaces': 'Manage workspaces',
21
+ 'menu.startup': 'Configure startup',
22
+ 'menu.language': 'Switch language',
23
+ 'menu.logs': 'View recent logs',
24
+ 'menu.exit': 'Exit',
25
+ 'settings.saved': 'Settings saved.',
26
+ 'startup.disabled': 'Disabled',
27
+ 'startup.background': 'Background',
28
+ 'startup.openUi': 'Open UI'
29
+ },
30
+ vi: {
31
+ 'wizard.title': 'Thiết lập nonstop',
32
+ 'wizard.language': 'Chọn ngôn ngữ (en/vi)',
33
+ 'wizard.token': 'Bot token Telegram',
34
+ 'wizard.admin': 'Username Telegram được phép (ví dụ: @yourname)',
35
+ 'wizard.clientName': 'Tên máy / client',
36
+ 'wizard.startupMode': 'Chế độ khởi động cùng hệ thống',
37
+ 'wizard.complete': 'Đã lưu cấu hình.',
38
+ 'dashboard.title': 'nonstop client',
39
+ 'dashboard.running': 'ĐANG CHẠY',
40
+ 'dashboard.stopped': 'ĐANG DỪNG',
41
+ 'dashboard.menu': 'Menu',
42
+ 'dashboard.choice': 'Chọn một tùy chọn',
43
+ 'menu.toggleRuntime': 'Bật/Tắt runtime nền',
44
+ 'menu.settings': 'Sửa cấu hình',
45
+ 'menu.workspaces': 'Quản lý workspace',
46
+ 'menu.startup': 'Cấu hình khởi động',
47
+ 'menu.language': 'Đổi ngôn ngữ',
48
+ 'menu.logs': 'Xem nhật ký gần đây',
49
+ 'menu.exit': 'Thoát',
50
+ 'settings.saved': 'Đã lưu cấu hình.',
51
+ 'startup.disabled': 'Tắt',
52
+ 'startup.background': 'Chạy nền',
53
+ 'startup.openUi': 'Mở giao diện'
54
+ }
55
+ };
56
+ function createTranslator(language) {
57
+ return (key) => MESSAGES[language][key] || MESSAGES.en[key];
58
+ }
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const config_js_1 = require("./config.js");
5
+ const logger_js_1 = require("./logger.js");
6
+ const runtime_js_1 = require("./runtime.js");
7
+ const ui_js_1 = require("./ui.js");
8
+ async function main() {
9
+ (0, config_js_1.ensureEnvExampleFile)();
10
+ const args = new Set(process.argv.slice(2));
11
+ const isBackground = args.has('--background');
12
+ const config = (0, config_js_1.loadConfigFromDisk)();
13
+ (0, config_js_1.applyConfigToProcessEnv)(config);
14
+ if (isBackground) {
15
+ const missingFields = (0, config_js_1.getMissingConfigFields)(config);
16
+ if (missingFields.length > 0) {
17
+ logger_js_1.logger.error('Cannot start background runtime because config is incomplete', {
18
+ missingFields
19
+ });
20
+ process.exitCode = 1;
21
+ return;
22
+ }
23
+ const runtime = new runtime_js_1.NonstopRuntime(config, 'background');
24
+ await runtime.startBot();
25
+ const shutdown = async () => {
26
+ await runtime.stopBot();
27
+ process.exit(0);
28
+ };
29
+ process.on('SIGINT', shutdown);
30
+ process.on('SIGTERM', shutdown);
31
+ process.on('uncaughtException', async (error) => {
32
+ logger_js_1.logger.error('Unhandled exception', {
33
+ error: error.message,
34
+ stack: error.stack
35
+ });
36
+ await runtime.stopBot();
37
+ process.exit(1);
38
+ });
39
+ process.on('unhandledRejection', async (reason) => {
40
+ logger_js_1.logger.error('Unhandled promise rejection', {
41
+ reason: reason instanceof Error ? reason.message : String(reason)
42
+ });
43
+ await runtime.stopBot();
44
+ process.exit(1);
45
+ });
46
+ return;
47
+ }
48
+ await (0, ui_js_1.launchControlCenter)();
49
+ }
50
+ void main();
package/dist/logger.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.logger = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const LOG_FILE_PATH = path.join(process.cwd(), 'data', 'nonstop.log');
40
+ function formatMeta(meta) {
41
+ if (!meta || Object.keys(meta).length === 0) {
42
+ return '';
43
+ }
44
+ try {
45
+ return ` ${JSON.stringify(meta)}`;
46
+ }
47
+ catch {
48
+ return ' {"meta":"[unserializable]"}';
49
+ }
50
+ }
51
+ function log(level, message, meta) {
52
+ const line = `[${new Date().toISOString()}] [nonstop] [${level}] ${message}${formatMeta(meta)}`;
53
+ writeLogFile(line);
54
+ if (level === 'ERROR') {
55
+ console.error(line);
56
+ return;
57
+ }
58
+ if (level === 'WARN') {
59
+ console.warn(line);
60
+ return;
61
+ }
62
+ console.log(line);
63
+ }
64
+ function writeLogFile(line) {
65
+ try {
66
+ fs.mkdirSync(path.dirname(LOG_FILE_PATH), { recursive: true });
67
+ fs.appendFileSync(LOG_FILE_PATH, `${line}\n`, 'utf8');
68
+ }
69
+ catch {
70
+ return;
71
+ }
72
+ }
73
+ exports.logger = {
74
+ debug(message, meta) {
75
+ log('DEBUG', message, meta);
76
+ },
77
+ info(message, meta) {
78
+ log('INFO', message, meta);
79
+ },
80
+ warn(message, meta) {
81
+ log('WARN', message, meta);
82
+ },
83
+ error(message, meta) {
84
+ log('ERROR', message, meta);
85
+ }
86
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectConfirmationPrompt = detectConfirmationPrompt;
4
+ function detectConfirmationPrompt(text) {
5
+ const normalized = normalizePromptText(text);
6
+ if (!normalized) {
7
+ return false;
8
+ }
9
+ const explicitPatterns = [
10
+ /\[[^\]]*(?:y\/n|yes\/no)[^\]]*\]/i,
11
+ /\b(?:y\/n|yes\/no)\b/i,
12
+ /\bcontinue\?/i,
13
+ /\bare you sure\??\b/i,
14
+ /\bpress enter to confirm\b/i,
15
+ /\bconfirm(?:\?| this\?| action\?| this \[[^\]]*(?:y\/n|yes\/no)[^\]]*\]| action \[[^\]]*(?:y\/n|yes\/no)[^\]]*\])(?!\w)/i
16
+ ];
17
+ return explicitPatterns.some((pattern) => pattern.test(normalized));
18
+ }
19
+ function normalizePromptText(text) {
20
+ return text
21
+ .replace(/\u001b\][^\u0007]*\u0007/g, ' ')
22
+ .replace(/\r/g, '\n')
23
+ .replace(/[ \t]+/g, ' ')
24
+ .replace(/\n{2,}/g, '\n')
25
+ .trim()
26
+ .toLowerCase();
27
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getRuntimeStatus = getRuntimeStatus;
37
+ exports.startBackgroundRuntime = startBackgroundRuntime;
38
+ exports.stopBackgroundRuntime = stopBackgroundRuntime;
39
+ const child_process_1 = require("child_process");
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const runtime_state_js_1 = require("./runtime-state.js");
43
+ function getRuntimeStatus() {
44
+ const snapshot = (0, runtime_state_js_1.loadRuntimeState)();
45
+ if (!snapshot) {
46
+ return { running: false, snapshot: null };
47
+ }
48
+ if (!(0, runtime_state_js_1.isPidRunning)(snapshot.pid)) {
49
+ return { running: false, snapshot: null };
50
+ }
51
+ return { running: true, snapshot };
52
+ }
53
+ function startBackgroundRuntime() {
54
+ const entryScriptPath = path.join(process.cwd(), 'dist', 'index.js');
55
+ if (!fs.existsSync(entryScriptPath)) {
56
+ throw new Error('dist/index.js not found. Run "npm run build" first.');
57
+ }
58
+ const child = (0, child_process_1.spawn)(process.execPath, [entryScriptPath, '--background'], {
59
+ cwd: process.cwd(),
60
+ detached: true,
61
+ stdio: 'ignore'
62
+ });
63
+ child.unref();
64
+ return `Started nonstop background runtime (pid ${child.pid ?? 'unknown'}).`;
65
+ }
66
+ function stopBackgroundRuntime(snapshot) {
67
+ if (!snapshot || !(0, runtime_state_js_1.isPidRunning)(snapshot.pid)) {
68
+ return 'Background runtime is not running.';
69
+ }
70
+ try {
71
+ process.kill(snapshot.pid);
72
+ return `Stopped nonstop background runtime (${snapshot.pid}).`;
73
+ }
74
+ catch (error) {
75
+ throw new Error(`Failed to stop background runtime (${snapshot.pid}): ${error instanceof Error ? error.message : String(error)}`);
76
+ }
77
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.saveRuntimeState = saveRuntimeState;
37
+ exports.loadRuntimeState = loadRuntimeState;
38
+ exports.clearRuntimeState = clearRuntimeState;
39
+ exports.isPidRunning = isPidRunning;
40
+ exports.getRuntimeStatePath = getRuntimeStatePath;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const RUNTIME_STATE_PATH = path.join(process.cwd(), 'data', 'runtime-state.json');
44
+ function saveRuntimeState(snapshot) {
45
+ fs.mkdirSync(path.dirname(RUNTIME_STATE_PATH), { recursive: true });
46
+ fs.writeFileSync(RUNTIME_STATE_PATH, JSON.stringify(snapshot, null, 2), 'utf8');
47
+ }
48
+ function loadRuntimeState() {
49
+ if (!fs.existsSync(RUNTIME_STATE_PATH)) {
50
+ return null;
51
+ }
52
+ try {
53
+ return JSON.parse(fs.readFileSync(RUNTIME_STATE_PATH, 'utf8'));
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
59
+ function clearRuntimeState() {
60
+ if (fs.existsSync(RUNTIME_STATE_PATH)) {
61
+ fs.unlinkSync(RUNTIME_STATE_PATH);
62
+ }
63
+ }
64
+ function isPidRunning(pid) {
65
+ if (!Number.isFinite(pid) || pid <= 0) {
66
+ return false;
67
+ }
68
+ try {
69
+ process.kill(pid, 0);
70
+ return true;
71
+ }
72
+ catch {
73
+ return false;
74
+ }
75
+ }
76
+ function getRuntimeStatePath() {
77
+ return RUNTIME_STATE_PATH;
78
+ }