thinkncollab-shell 0.0.20 → 2.0.0-beta.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 +82 -0
- package/Readme.md +246 -502
- package/dist/bin/thinknsh.js +8 -0
- package/dist/src/commands/auth/login.js +7 -0
- package/dist/src/commands/auth/logout.js +7 -0
- package/dist/src/commands/auth/register.js +7 -0
- package/dist/src/commands/auth/whoami.js +7 -0
- package/dist/src/commands/dock/bench.js +7 -0
- package/dist/src/commands/dock/ci.js +7 -0
- package/dist/src/commands/dock/cluster.js +7 -0
- package/dist/src/commands/dock/containers.js +7 -0
- package/dist/src/commands/dock/dock.js +7 -0
- package/dist/src/commands/github/commits.js +7 -0
- package/dist/src/commands/github/issue-create.js +7 -0
- package/dist/src/commands/github/issues.js +7 -0
- package/dist/src/commands/github/pulls.js +7 -0
- package/dist/src/commands/github/statusgh.js +7 -0
- package/dist/src/commands/index.js +7 -0
- package/dist/src/commands/message/say.js +7 -0
- package/dist/src/commands/room/join.js +7 -0
- package/dist/src/commands/room/leave.js +7 -0
- package/dist/src/commands/room/rooms.js +7 -0
- package/dist/src/commands/room/sync.js +7 -0
- package/dist/src/commands/sandbox/console.js +7 -0
- package/dist/src/commands/sandbox/dep.js +7 -0
- package/dist/src/commands/sandbox/deploy.js +7 -0
- package/dist/src/commands/sandbox/dev.js +7 -0
- package/dist/src/commands/sandbox/exec.js +7 -0
- package/dist/src/commands/sandbox/freeze.js +7 -0
- package/dist/src/commands/sandbox/push.js +7 -0
- package/dist/src/commands/sandbox/resume.js +7 -0
- package/dist/src/commands/sandbox/sandbox.js +7 -0
- package/dist/src/commands/sandbox/share.js +7 -0
- package/dist/src/commands/sandbox/snapshot.js +7 -0
- package/dist/src/commands/sandbox/sync-deps.js +7 -0
- package/dist/src/commands/shell/doctor.js +7 -0
- package/dist/src/commands/shell/notifications.js +7 -0
- package/dist/src/commands/shell/notify.js +7 -0
- package/dist/src/commands/shell/status.js +7 -0
- package/dist/src/commands/shell/version.js +7 -0
- package/dist/src/commands/tasks/build.js +7 -0
- package/dist/src/commands/tasks/complete.js +7 -0
- package/dist/src/commands/tasks/create-task.js +7 -0
- package/dist/src/commands/tasks/loadtest.js +7 -0
- package/dist/src/commands/tasks/task-status.js +7 -0
- package/dist/src/commands/tasks/task.js +7 -0
- package/dist/src/commands/tasks/tasks.js +7 -0
- package/dist/src/commands/team/invite.js +7 -0
- package/dist/src/commands/team/myteam.js +7 -0
- package/dist/src/commands/team/teammates.js +7 -0
- package/dist/src/commands/terminal/share.js +7 -0
- package/dist/src/core/api-client.js +7 -0
- package/dist/src/core/crypto/e2ee-vault.js +7 -0
- package/dist/src/core/dep-store.js +7 -0
- package/dist/src/core/dependency-tracker.js +7 -0
- package/dist/src/core/geekload.js +7 -0
- package/dist/src/core/local-runner.js +7 -0
- package/dist/src/core/multi-lang-scanner.js +7 -0
- package/dist/src/core/notification-window.js +8 -0
- package/dist/src/core/notify-auth.js +7 -0
- package/dist/src/core/project-config.js +7 -0
- package/dist/src/core/sandbox/arch-shim.js +7 -0
- package/dist/src/core/sandbox/capsule-builder.js +7 -0
- package/dist/src/core/sandbox/cgroups.js +7 -0
- package/dist/src/core/sandbox/container-monitor.js +7 -0
- package/dist/src/core/sandbox/crun-manager.js +7 -0
- package/dist/src/core/sandbox/engine.js +7 -0
- package/dist/src/core/sandbox/image-manager.js +7 -0
- package/dist/src/core/sandbox/image-store.js +7 -0
- package/dist/src/core/sandbox/index.js +7 -0
- package/dist/src/core/sandbox/macos-sandbox.js +7 -0
- package/dist/src/core/sandbox/microvm-manager.js +7 -0
- package/dist/src/core/sandbox/native-service-manager.js +7 -0
- package/dist/src/core/sandbox/network.js +7 -0
- package/dist/src/core/sandbox/oci-exporter.js +7 -0
- package/dist/src/core/sandbox/oci-puller.js +7 -0
- package/dist/src/core/sandbox/oci-runtime-spec.js +7 -0
- package/dist/src/core/sandbox/policy-engine.js +7 -0
- package/dist/src/core/sandbox/port-proxy-daemon.js +7 -0
- package/dist/src/core/sandbox/room-sync-manager.js +7 -0
- package/dist/src/core/sandbox/runtime-manager.js +7 -0
- package/dist/src/core/sandbox/snapshot-manager.js +7 -0
- package/dist/src/core/sandbox/storage.js +7 -0
- package/dist/src/core/sandbox/supervisor.js +7 -0
- package/dist/src/core/sandbox/tunnel-daemon.js +7 -0
- package/dist/src/core/sandbox/tunnel.js +7 -0
- package/dist/src/core/sandbox/window-launcher.js +7 -0
- package/dist/src/core/sandbox/windows-wsl2.js +7 -0
- package/dist/src/core/sandbox-window.js +8 -0
- package/dist/src/core/shell.js +7 -0
- package/dist/src/core/websocket.js +7 -0
- package/dist/src/dock/api/routes.js +7 -0
- package/dist/src/dock/api/server.js +7 -0
- package/dist/src/dock/api/wire.js +7 -0
- package/dist/src/dock/bench/memory.js +7 -0
- package/dist/src/dock/bench/runner.js +7 -0
- package/dist/src/dock/build/builder.js +7 -0
- package/dist/src/dock/build/buildfile.js +7 -0
- package/dist/src/dock/build/buildkit.js +7 -0
- package/dist/src/dock/build/changes.js +7 -0
- package/dist/src/dock/ci/actions.js +7 -0
- package/dist/src/dock/ci/runner.js +7 -0
- package/dist/src/dock/ci/workflow.js +7 -0
- package/dist/src/dock/cli/api.js +7 -0
- package/dist/src/dock/cli/args.js +7 -0
- package/dist/src/dock/cli/commands.js +7 -0
- package/dist/src/dock/cli/compose.js +7 -0
- package/dist/src/dock/cli/context.js +7 -0
- package/dist/src/dock/cli/files.js +7 -0
- package/dist/src/dock/cli/format.js +7 -0
- package/dist/src/dock/cli/manage.js +7 -0
- package/dist/src/dock/cli/moved.js +7 -0
- package/dist/src/dock/cli/services.js +7 -0
- package/dist/src/dock/cli/session.js +7 -0
- package/dist/src/dock/cli/workspace.js +7 -0
- package/dist/src/dock/client.js +7 -0
- package/dist/src/dock/compat/cases.js +7 -0
- package/dist/src/dock/compat/runner.js +7 -0
- package/dist/src/dock/config.js +7 -0
- package/dist/src/dock/daemon-main.js +7 -0
- package/dist/src/dock/daemon.js +7 -0
- package/dist/src/dock/deploy/compose.js +7 -0
- package/dist/src/dock/engine.js +7 -0
- package/dist/src/dock/image/archive.js +7 -0
- package/dist/src/dock/image/auth.js +7 -0
- package/dist/src/dock/image/reference.js +7 -0
- package/dist/src/dock/image/registry.js +7 -0
- package/dist/src/dock/image/tar.js +7 -0
- package/dist/src/dock/index.js +7 -0
- package/dist/src/dock/linux/host.js +7 -0
- package/dist/src/dock/paths.js +7 -0
- package/dist/src/dock/runtime/emulation.js +7 -0
- package/dist/src/dock/runtime/fsevents.js +7 -0
- package/dist/src/dock/runtime/fsops.js +7 -0
- package/dist/src/dock/runtime/hostfwd.js +7 -0
- package/dist/src/dock/runtime/logs.js +7 -0
- package/dist/src/dock/runtime/network.js +7 -0
- package/dist/src/dock/runtime/ports.js +7 -0
- package/dist/src/dock/runtime/rootfs.js +7 -0
- package/dist/src/dock/runtime/seccomp-profile.LICENSE +202 -0
- package/dist/src/dock/runtime/seccomp-profile.json +1227 -0
- package/dist/src/dock/runtime/seccomp.js +7 -0
- package/dist/src/dock/runtime/spec.js +7 -0
- package/dist/src/dock/runtime/stats.js +7 -0
- package/dist/src/dock/runtime/volumes.js +7 -0
- package/dist/src/dock/selftest.js +7 -0
- package/dist/src/dock/setup/app.js +7 -0
- package/dist/src/dock/setup/autostart.js +7 -0
- package/dist/src/dock/setup/index.js +7 -0
- package/dist/src/dock/setup/integrate.js +7 -0
- package/dist/src/dock/setup/migrate.js +7 -0
- package/dist/src/dock/state/store.js +7 -0
- package/dist/src/dock/ui/page.js +385 -0
- package/dist/src/dock/ui/server.js +7 -0
- package/dist/src/dock/version.js +7 -0
- package/dist/src/dock/workspace/apps.js +7 -0
- package/dist/src/dock/workspace/workspace.js +7 -0
- package/dist/src/events/notifications.js +7 -0
- package/dist/src/utils/logger.js +7 -0
- package/dist/src/utils/terminalCrypto.js +7 -0
- package/package.json +41 -16
- package/bin/thinknsh.js +0 -71
- package/src/commands/auth/login.js +0 -84
- package/src/commands/auth/logout.js +0 -32
- package/src/commands/auth/register.js +0 -52
- package/src/commands/auth/whoami.js +0 -52
- package/src/commands/github/commits.js +0 -58
- package/src/commands/github/issue-create.js +0 -59
- package/src/commands/github/issues.js +0 -57
- package/src/commands/github/pulls.js +0 -58
- package/src/commands/github/statusgh.js +0 -50
- package/src/commands/index.js +0 -136
- package/src/commands/message/say.js +0 -49
- package/src/commands/room/join.js +0 -142
- package/src/commands/room/leave.js +0 -24
- package/src/commands/room/rooms.js +0 -66
- package/src/commands/shell/notify.js +0 -88
- package/src/commands/shell/status.js +0 -73
- package/src/commands/shell/version.js +0 -18
- package/src/commands/tasks/build.js +0 -190
- package/src/commands/tasks/complete.js +0 -940
- package/src/commands/tasks/create-task.js +0 -101
- package/src/commands/tasks/loadtest.js +0 -101
- package/src/commands/tasks/suggestTask.js +0 -0
- package/src/commands/tasks/task-status.js +0 -72
- package/src/commands/tasks/task.js +0 -182
- package/src/commands/tasks/tasks.js +0 -184
- package/src/commands/team/invite.js +0 -46
- package/src/commands/team/myteam.js +0 -78
- package/src/commands/team/teammates.js +0 -52
- package/src/commands/terminal/share.js +0 -261
- package/src/core/api-client.js +0 -246
- package/src/core/geekload.js +0 -524
- package/src/core/local-runner.js +0 -861
- package/src/core/notification-window.js +0 -165
- package/src/core/project-config.js +0 -100
- package/src/core/shell.js +0 -734
- package/src/core/websocket.js +0 -657
- package/src/events/notifications.js +0 -184
- package/src/utils/logger.js +0 -159
- package/src/utils/terminalCrypto.js +0 -47
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Notification System for ThinkNCollab Shell
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const EventEmitter = require('events');
|
|
6
|
-
const chalk = require('chalk');
|
|
7
|
-
|
|
8
|
-
class NotificationManager extends EventEmitter {
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
super();
|
|
11
|
-
|
|
12
|
-
this.options = {
|
|
13
|
-
sound: options.sound || false,
|
|
14
|
-
desktop: options.desktop || false,
|
|
15
|
-
...options
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
this.notifications = [];
|
|
19
|
-
this.maxNotifications = 100;
|
|
20
|
-
this.unreadCount = 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* Show a notification
|
|
24
|
-
*/
|
|
25
|
-
show(notification) {
|
|
26
|
-
const notif = {
|
|
27
|
-
id: `notif_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
28
|
-
type: notification.type || 'info',
|
|
29
|
-
title: notification.title || 'Notification',
|
|
30
|
-
message: notification.message,
|
|
31
|
-
timestamp: new Date(),
|
|
32
|
-
read: false,
|
|
33
|
-
data: notification.data || {}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
this.notifications.unshift(notif);
|
|
37
|
-
this.unreadCount++;
|
|
38
|
-
|
|
39
|
-
// Trim old notifications
|
|
40
|
-
if (this.notifications.length > this.maxNotifications) {
|
|
41
|
-
this.notifications.pop();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Emit event
|
|
45
|
-
this.emit('notification', notif);
|
|
46
|
-
|
|
47
|
-
// Show in console
|
|
48
|
-
this.showInConsole(notif);
|
|
49
|
-
|
|
50
|
-
// Desktop notification
|
|
51
|
-
if (this.options.desktop) {
|
|
52
|
-
this.showDesktopNotification(notif);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Sound
|
|
56
|
-
if (this.options.sound) {
|
|
57
|
-
this.playSound();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return notif;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/* Show notification in console
|
|
64
|
-
*/
|
|
65
|
-
showInConsole(notification) {
|
|
66
|
-
let color = chalk.blue;
|
|
67
|
-
let symbol = 'ℹ';
|
|
68
|
-
|
|
69
|
-
switch (notification.type) {
|
|
70
|
-
case 'success':
|
|
71
|
-
color = chalk.green;
|
|
72
|
-
symbol = '✓';
|
|
73
|
-
break;
|
|
74
|
-
case 'warning':
|
|
75
|
-
color = chalk.yellow;
|
|
76
|
-
symbol = '⚠';
|
|
77
|
-
break;
|
|
78
|
-
case 'error':
|
|
79
|
-
color = chalk.red;
|
|
80
|
-
symbol = '✗';
|
|
81
|
-
break;
|
|
82
|
-
case 'info':
|
|
83
|
-
default:
|
|
84
|
-
color = chalk.blue;
|
|
85
|
-
symbol = 'ℹ';
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
console.log(color(`${symbol} ${notification.title}: ${notification.message}`));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/* Show desktop notification (if supported)
|
|
93
|
-
*/
|
|
94
|
-
showDesktopNotification(notification) {
|
|
95
|
-
// Check if running in Electron
|
|
96
|
-
if (process.type === 'renderer' || process.type === 'browser') {
|
|
97
|
-
try {
|
|
98
|
-
const { Notification } = require('electron');
|
|
99
|
-
new Notification({
|
|
100
|
-
title: notification.title,
|
|
101
|
-
body: notification.message,
|
|
102
|
-
silent: !this.options.sound
|
|
103
|
-
}).show();
|
|
104
|
-
} catch (error) {
|
|
105
|
-
// Electron not available
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/* Play notification sound
|
|
111
|
-
*/
|
|
112
|
-
playSound() {
|
|
113
|
-
process.stdout.write('\x07'); // terminal bell — zero dependencies
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/* Mark notification as read
|
|
117
|
-
*/
|
|
118
|
-
markAsRead(id) {
|
|
119
|
-
const notif = this.notifications.find(n => n.id === id);
|
|
120
|
-
if (notif && !notif.read) {
|
|
121
|
-
notif.read = true;
|
|
122
|
-
this.unreadCount--;
|
|
123
|
-
this.emit('read', notif);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/* Mark all as read
|
|
128
|
-
*/
|
|
129
|
-
markAllAsRead() {
|
|
130
|
-
this.notifications.forEach(n => {
|
|
131
|
-
if (!n.read) {
|
|
132
|
-
n.read = true;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
this.unreadCount = 0;
|
|
136
|
-
this.emit('allRead');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/* Get unread notifications
|
|
140
|
-
*/
|
|
141
|
-
getUnread() {
|
|
142
|
-
return this.notifications.filter(n => !n.read);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/* Get all notifications
|
|
146
|
-
*/
|
|
147
|
-
getAll() {
|
|
148
|
-
return this.notifications;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/* Clear all notifications
|
|
152
|
-
*/
|
|
153
|
-
clear() {
|
|
154
|
-
this.notifications = [];
|
|
155
|
-
this.unreadCount = 0;
|
|
156
|
-
this.emit('cleared');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/* Create success notification
|
|
160
|
-
*/
|
|
161
|
-
success(title, message, data = {}) {
|
|
162
|
-
return this.show({ type: 'success', title, message, data });
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/* Create error notification
|
|
166
|
-
*/
|
|
167
|
-
error(title, message, data = {}) {
|
|
168
|
-
return this.show({ type: 'error', title, message, data });
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/* Create warning notification
|
|
172
|
-
*/
|
|
173
|
-
warning(title, message, data = {}) {
|
|
174
|
-
return this.show({ type: 'warning', title, message, data });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/* Create info notification
|
|
178
|
-
*/
|
|
179
|
-
info(title, message, data = {}) {
|
|
180
|
-
return this.show({ type: 'info', title, message, data });
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
module.exports = NotificationManager;
|
package/src/utils/logger.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/* Logger for ThinkNCollab Shell
|
|
2
|
-
*/
|
|
3
|
-
|
|
4
|
-
const fs = require('fs-extra');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
|
|
8
|
-
class Logger {
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
this.options = {
|
|
11
|
-
logDir: options.logDir || path.join(os.homedir(), '.thinkncollab', 'logs'),
|
|
12
|
-
level: options.level || 'info',
|
|
13
|
-
maxFiles: options.maxFiles || 5,
|
|
14
|
-
maxSize: options.maxSize || 10 * 1024 * 1024, // 10MB
|
|
15
|
-
...options
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// Ensure log directory exists
|
|
19
|
-
fs.ensureDirSync(this.options.logDir);
|
|
20
|
-
|
|
21
|
-
this.levels = {
|
|
22
|
-
debug: 0,
|
|
23
|
-
info: 1,
|
|
24
|
-
warn: 2,
|
|
25
|
-
error: 3
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
this.currentLogFile = this.getLogFileName();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/* Get log file name
|
|
32
|
-
*/
|
|
33
|
-
getLogFileName() {
|
|
34
|
-
const date = new Date().toISOString().split('T')[0];
|
|
35
|
-
return path.join(this.options.logDir, `thinknsh-${date}.log`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/* Write to log file
|
|
39
|
-
*/
|
|
40
|
-
async write(level, message, data = null) {
|
|
41
|
-
if (this.levels[level] < this.levels[this.options.level]) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const logEntry = {
|
|
46
|
-
timestamp: new Date().toISOString(),
|
|
47
|
-
level,
|
|
48
|
-
message,
|
|
49
|
-
data,
|
|
50
|
-
pid: process.pid
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const logLine = JSON.stringify(logEntry) + '\n';
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
await fs.appendFile(this.currentLogFile, logLine);
|
|
57
|
-
await this.rotateIfNeeded();
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.error('Failed to write log:', error);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/* Rotate log files if needed
|
|
64
|
-
*/
|
|
65
|
-
async rotateIfNeeded() {
|
|
66
|
-
try {
|
|
67
|
-
const stat = await fs.stat(this.currentLogFile);
|
|
68
|
-
|
|
69
|
-
if (stat.size > this.options.maxSize) {
|
|
70
|
-
// Rename current file
|
|
71
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
72
|
-
const rotatedFile = this.currentLogFile.replace('.log', `-${timestamp}.log`);
|
|
73
|
-
await fs.rename(this.currentLogFile, rotatedFile);
|
|
74
|
-
|
|
75
|
-
// Create new log file
|
|
76
|
-
this.currentLogFile = this.getLogFileName();
|
|
77
|
-
|
|
78
|
-
// Clean up old files
|
|
79
|
-
await this.cleanOldLogs();
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
// File might not exist yet
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/* Clean old log files
|
|
87
|
-
*/
|
|
88
|
-
async cleanOldLogs() {
|
|
89
|
-
try {
|
|
90
|
-
const files = await fs.readdir(this.options.logDir);
|
|
91
|
-
const logFiles = files
|
|
92
|
-
.filter(f => f.startsWith('thinknsh-') && f.endsWith('.log'))
|
|
93
|
-
.map(f => ({
|
|
94
|
-
name: f,
|
|
95
|
-
path: path.join(this.options.logDir, f),
|
|
96
|
-
time: fs.statSync(path.join(this.options.logDir, f)).mtime.getTime()
|
|
97
|
-
}))
|
|
98
|
-
.sort((a, b) => b.time - a.time);
|
|
99
|
-
|
|
100
|
-
// Keep only maxFiles most recent
|
|
101
|
-
if (logFiles.length > this.options.maxFiles) {
|
|
102
|
-
const toDelete = logFiles.slice(this.options.maxFiles);
|
|
103
|
-
for (const file of toDelete) {
|
|
104
|
-
await fs.remove(file.path);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error('Failed to clean old logs:', error);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/* Debug log
|
|
113
|
-
*/
|
|
114
|
-
debug(message, data = null) {
|
|
115
|
-
return this.write('debug', message, data);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/* Info log
|
|
119
|
-
*/
|
|
120
|
-
info(message, data = null) {
|
|
121
|
-
return this.write('info', message, data);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/* Warn log
|
|
125
|
-
*/
|
|
126
|
-
warn(message, data = null) {
|
|
127
|
-
return this.write('warn', message, data);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/* Error log
|
|
131
|
-
*/
|
|
132
|
-
error(message, data = null) {
|
|
133
|
-
return this.write('error', message, data);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/* Get recent logs
|
|
137
|
-
*/
|
|
138
|
-
async getRecentLogs(lines = 100) {
|
|
139
|
-
try {
|
|
140
|
-
if (!await fs.pathExists(this.currentLogFile)) {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const content = await fs.readFile(this.currentLogFile, 'utf8');
|
|
145
|
-
const logs = content
|
|
146
|
-
.split('\n')
|
|
147
|
-
.filter(line => line.trim())
|
|
148
|
-
.map(line => JSON.parse(line))
|
|
149
|
-
.slice(-lines);
|
|
150
|
-
|
|
151
|
-
return logs;
|
|
152
|
-
} catch (error) {
|
|
153
|
-
console.error('Failed to read logs:', error);
|
|
154
|
-
return [];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
module.exports = Logger;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/utils/terminalCrypto.js
|
|
3
|
-
* CLI-side AES-256-GCM End-to-End Encryption (E2EE) module
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const crypto = require('crypto');
|
|
7
|
-
|
|
8
|
-
function deriveKey(secret, salt = 'thinkncollab-e2ee-salt') {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
crypto.pbkdf2(secret, salt, 100000, 32, 'sha256', (err, derivedKey) => {
|
|
11
|
-
if (err) return reject(err);
|
|
12
|
-
resolve(derivedKey);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function encryptPayload(plaintext, key) {
|
|
18
|
-
const iv = crypto.randomBytes(12);
|
|
19
|
-
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
20
|
-
|
|
21
|
-
let encrypted = cipher.update(plaintext, 'utf8', 'hex');
|
|
22
|
-
encrypted += cipher.final('hex');
|
|
23
|
-
const authTag = cipher.getAuthTag().toString('hex');
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
ciphertext: encrypted,
|
|
27
|
-
iv: iv.toString('hex'),
|
|
28
|
-
authTag: authTag
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function decryptPayload(ciphertext, ivHex, authTagHex, key) {
|
|
33
|
-
const iv = Buffer.from(ivHex, 'hex');
|
|
34
|
-
const authTag = Buffer.from(authTagHex, 'hex');
|
|
35
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
|
|
36
|
-
decipher.setAuthTag(authTag);
|
|
37
|
-
|
|
38
|
-
let decrypted = decipher.update(ciphertext, 'hex', 'utf8');
|
|
39
|
-
decrypted += decipher.final('utf8');
|
|
40
|
-
return decrypted;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = {
|
|
44
|
-
deriveKey,
|
|
45
|
-
encryptPayload,
|
|
46
|
-
decryptPayload
|
|
47
|
-
};
|