@umer-jahangier/claude-nonstop 0.0.0-stage → 1.16.2

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +417 -2
  3. package/bin/claude-nonstop.js +14 -0
  4. package/package.json +51 -4
  5. package/src/accounts.js +288 -0
  6. package/src/chatgpt-models.js +64 -0
  7. package/src/checks.js +66 -0
  8. package/src/classify.js +21 -0
  9. package/src/claude.js +252 -0
  10. package/src/cli.js +98 -0
  11. package/src/clients.js +104 -0
  12. package/src/codex.js +145 -0
  13. package/src/commands.js +841 -0
  14. package/src/config.js +60 -0
  15. package/src/connectorcheck.js +88 -0
  16. package/src/desktop.js +267 -0
  17. package/src/desktopadvice.js +111 -0
  18. package/src/directory.json +7197 -0
  19. package/src/elevate.js +39 -0
  20. package/src/events.js +43 -0
  21. package/src/files.js +54 -0
  22. package/src/gateway.js +976 -0
  23. package/src/hosts.js +46 -0
  24. package/src/hostsfile.js +68 -0
  25. package/src/http.js +65 -0
  26. package/src/keys.js +81 -0
  27. package/src/keystore.js +141 -0
  28. package/src/launch.js +233 -0
  29. package/src/marketplace.js +52 -0
  30. package/src/openai-auth.js +249 -0
  31. package/src/paths.js +25 -0
  32. package/src/prompt.js +66 -0
  33. package/src/providers.js +168 -0
  34. package/src/relay.js +78 -0
  35. package/src/server.js +285 -0
  36. package/src/service.js +208 -0
  37. package/src/shell.js +119 -0
  38. package/src/ssh.js +163 -0
  39. package/src/state.js +76 -0
  40. package/src/supervise.js +377 -0
  41. package/src/system.js +105 -0
  42. package/src/tls.js +260 -0
  43. package/src/translate/chat.js +150 -0
  44. package/src/translate/index.js +52 -0
  45. package/src/translate/ir.js +140 -0
  46. package/src/translate/messages.js +333 -0
  47. package/src/translate/responses.js +495 -0
  48. package/src/translate/sse.js +44 -0
  49. package/src/ui/index.html +3206 -0
  50. package/src/ui.js +623 -0
  51. package/src/update.js +122 -0
  52. package/src/usage.js +147 -0
  53. package/src/vault.js +68 -0
  54. package/src/winpath.js +48 -0
package/src/elevate.js ADDED
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ // Runs a short script with administrator rights through the system's own prompt: the
4
+ // macOS password dialog, one Windows confirmation, or sudo / pkexec on Linux. claude-nonstop
5
+ // gathers everything it changes outside your home folder into a single call of this.
6
+
7
+ const { spawnSync } = require('child_process');
8
+
9
+ const ok = (r) => Boolean(r && !r.error && r.status === 0);
10
+ const shQuote = (s) => `'${String(s).replace(/'/g, "'\\''")}'`;
11
+ const psQuote = (s) => `'${String(s).replace(/'/g, "''")}'`;
12
+
13
+ function run({ sh, ps, why }) {
14
+ if (process.platform === 'win32') {
15
+ if (!ps) return true;
16
+ const inner = Buffer.from(`$ErrorActionPreference = 'Stop'; ${ps}`, 'utf16le').toString('base64');
17
+ // Start-Process shows the UAC prompt; declining it throws, so the exit code says whether it ran.
18
+ const outer = `try { $p = Start-Process -FilePath powershell.exe -Verb RunAs -Wait -PassThru -WindowStyle Hidden -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-EncodedCommand','${inner}'; exit $p.ExitCode } catch { exit 1 }`;
19
+ return ok(spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(outer, 'utf16le').toString('base64')], { stdio: 'ignore', windowsHide: true }));
20
+ }
21
+ if (!sh) return true;
22
+ const script = `set -e\n${sh}`;
23
+ if (process.platform === 'darwin') {
24
+ const escaped = script.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
25
+ const apple = `do shell script "${escaped}" with prompt "${why.replace(/"/g, "'")}" with administrator privileges`;
26
+ if (ok(spawnSync('osascript', ['-e', apple], { stdio: 'ignore' }))) return true;
27
+ }
28
+ if (ok(spawnSync('sudo', ['-n', 'sh', '-c', script], { stdio: 'ignore' }))) return true;
29
+ if (process.stdin.isTTY) {
30
+ process.stdout.write(`claude-nonstop: ${why} Your password is needed once (press Ctrl-C to skip).\n`);
31
+ if (ok(spawnSync('sudo', ['sh', '-c', script], { stdio: 'inherit' }))) return true;
32
+ }
33
+ if (process.platform === 'linux' && (process.env.DISPLAY || process.env.WAYLAND_DISPLAY)) {
34
+ if (ok(spawnSync('pkexec', ['sh', '-c', script], { stdio: 'ignore' }))) return true;
35
+ }
36
+ return false;
37
+ }
38
+
39
+ module.exports = { run, shQuote, psQuote };
package/src/events.js ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ // Live events from the gateway and the relay, for the web UI's activity feed and the
4
+ // pulses that travel along the rope. Kept in memory only: the last 60 events and
5
+ // today's request counts.
6
+
7
+ const { EventEmitter } = require('events');
8
+
9
+ const bus = new EventEmitter();
10
+ bus.setMaxListeners(100);
11
+ const recent = [];
12
+ let today = { day: new Date().toDateString(), requests: 0, errors: 0, byKey: {} };
13
+
14
+ function rollDay() {
15
+ const day = new Date().toDateString();
16
+ if (today.day !== day) today = { day, requests: 0, errors: 0, byKey: {} };
17
+ }
18
+
19
+ function emit(type, data = {}) {
20
+ rollDay();
21
+ if (type === 'request') {
22
+ today.requests += 1;
23
+ if (data.status >= 400) today.errors += 1;
24
+ if (data.keyId) today.byKey[data.keyId] = (today.byKey[data.keyId] || 0) + 1;
25
+ }
26
+ const event = { type, at: Date.now(), ...data };
27
+ recent.push(event);
28
+ if (recent.length > 60) recent.shift();
29
+ bus.emit('event', event);
30
+ return event;
31
+ }
32
+
33
+ // Tells open pages that something changed, without adding it to the activity feed.
34
+ function notify(type, data = {}) {
35
+ bus.emit('event', { type, at: Date.now(), ...data });
36
+ }
37
+
38
+ function stats() {
39
+ rollDay();
40
+ return { requestsToday: today.requests, errorsToday: today.errors, byKey: { ...today.byKey } };
41
+ }
42
+
43
+ module.exports = { bus, emit, notify, stats, recent: () => recent.slice() };
package/src/files.js ADDED
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const paths = require('./paths');
6
+
7
+ function ensureHome() {
8
+ fs.mkdirSync(paths.HOME, { recursive: true, mode: 0o700 });
9
+ }
10
+
11
+ function readJson(file, fallback) {
12
+ try {
13
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
14
+ } catch {
15
+ return fallback;
16
+ }
17
+ }
18
+
19
+ function sleepSync(ms) {
20
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
21
+ }
22
+
23
+ // Writes through a temp file and a rename, so a crash never leaves half a file behind.
24
+ // Files are created readable by your user only.
25
+ function writeJson(file, value) {
26
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
27
+ const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
28
+ fs.writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
29
+ for (let attempt = 0; ; attempt++) {
30
+ try {
31
+ fs.renameSync(tmp, file);
32
+ return;
33
+ } catch (err) {
34
+ // Windows refuses the rename while another process has the file open; retry briefly.
35
+ if (attempt >= 40 || !['EPERM', 'EACCES', 'EBUSY'].includes(err.code)) {
36
+ fs.rmSync(tmp, { force: true });
37
+ throw err;
38
+ }
39
+ sleepSync(25);
40
+ }
41
+ }
42
+ }
43
+
44
+ function log(message) {
45
+ try {
46
+ ensureHome();
47
+ try {
48
+ if (fs.statSync(paths.LOG).size > 1024 * 1024) fs.renameSync(paths.LOG, `${paths.LOG}.1`);
49
+ } catch {}
50
+ fs.appendFileSync(paths.LOG, `${new Date().toISOString()} ${message}\n`, { mode: 0o600 });
51
+ } catch {}
52
+ }
53
+
54
+ module.exports = { ensureHome, readJson, writeJson, log };