tacticremote 1.6.6 → 1.7.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/lib/authChallengeManager.js +1 -134
- package/lib/claudeSessionManager.js +1 -0
- package/lib/claudeTransport.js +1 -0
- package/lib/errorCodes.js +1 -127
- package/lib/execSafe.js +1 -218
- package/lib/fileService.js +1 -177
- package/lib/hookInstaller.js +21 -7
- package/lib/outputParser.js +1 -106
- package/lib/pushClient.js +1 -0
- package/lib/rateLimiter.js +1 -111
- package/lib/serverIdentity.js +1 -0
- package/lib/streamJsonParser.js +1 -0
- package/lib/tmuxManager.js +1 -671
- package/lib/uploadService.js +1 -366
- package/lib/validators.js +1 -350
- package/package.json +2 -1
- package/routes/wsHandler.js +418 -364
- package/server.js +67 -173
- package/shared/server-core/authChallengeManager.js +108 -0
- package/shared/server-core/claudeSessionManager.js +222 -0
- package/shared/server-core/claudeTransport.js +176 -0
- package/shared/server-core/errorCodes.js +91 -0
- package/shared/server-core/execSafe.js +185 -0
- package/shared/server-core/fileService.js +155 -0
- package/shared/server-core/outputParser.js +174 -0
- package/shared/server-core/protocol-manifest.json +59 -0
- package/shared/server-core/protocol-manifest.schema.json +90 -0
- package/shared/server-core/protocolManifest.js +42 -0
- package/shared/server-core/pushClient.js +198 -0
- package/shared/server-core/rateLimiter.js +98 -0
- package/shared/server-core/serverConnectionLifecycle.js +118 -0
- package/shared/server-core/serverHandshake.js +72 -0
- package/shared/server-core/serverIdentity.js +102 -0
- package/shared/server-core/streamJsonParser.js +321 -0
- package/shared/server-core/tmuxManager.js +596 -0
- package/shared/server-core/unixProcessLifecycle.js +96 -0
- package/shared/server-core/unixServerHooks.js +148 -0
- package/shared/server-core/unixWsRuntime.js +412 -0
- package/shared/server-core/uploadService.js +321 -0
- package/shared/server-core/validators.js +274 -0
- package/shared/server-core/windowsServerHooks.js +174 -0
- package/shared/server-core/windowsWsRuntime.js +413 -0
package/lib/hookInstaller.js
CHANGED
|
@@ -7,6 +7,9 @@ const os = require('os');
|
|
|
7
7
|
const HOOKS_DIR = path.join(os.homedir(), '.claude', 'hooks');
|
|
8
8
|
const SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
|
|
9
9
|
|
|
10
|
+
const HOOK_SCRIPT_VERSION = 2;
|
|
11
|
+
const HOOK_VERSION_TAG = `tactic-hook-version: ${HOOK_SCRIPT_VERSION}`;
|
|
12
|
+
|
|
10
13
|
const SCRIPT_FILES = {
|
|
11
14
|
'claude-remote-stop.sh': 'Stop',
|
|
12
15
|
'claude-remote-notification.sh': 'Notification',
|
|
@@ -20,6 +23,7 @@ const SCRIPT_FILES = {
|
|
|
20
23
|
function bashHookScript(eventName) {
|
|
21
24
|
return `#!/bin/bash
|
|
22
25
|
# Tactic Remote hook — ${eventName} event
|
|
26
|
+
# ${HOOK_VERSION_TAG}
|
|
23
27
|
|
|
24
28
|
PORT="\${CLAUDE_REMOTE_PORT:-8765}"
|
|
25
29
|
URL="http://localhost:\${PORT}/hook"
|
|
@@ -34,16 +38,13 @@ json_escape() {
|
|
|
34
38
|
printf '%s' "$value"
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
if [ -n "$TMUX" ]; then
|
|
39
|
-
TMUX_SESSION=$(tmux display-message -p '#S' 2>/dev/null || echo "")
|
|
40
|
-
fi
|
|
41
|
+
TACTIC_SESSION="\${TACTIC_SESSION_ID:-}"
|
|
41
42
|
|
|
42
43
|
PROJECT="$(basename "$PWD")"
|
|
43
44
|
TIMESTAMP=$(date +%s)
|
|
44
45
|
PROJECT_JSON=$(json_escape "$PROJECT")
|
|
45
|
-
|
|
46
|
-
JSON=$(printf '{"event":"%s","project":"%s","tmux_session":"%s","timestamp":%s}' "${eventName}" "$PROJECT_JSON" "$
|
|
46
|
+
TACTIC_SESSION_JSON=$(json_escape "$TACTIC_SESSION")
|
|
47
|
+
JSON=$(printf '{"event":"%s","project":"%s","tactic_session":"%s","tmux_session":"%s","timestamp":%s}' "${eventName}" "$PROJECT_JSON" "$TACTIC_SESSION_JSON" "$TACTIC_SESSION_JSON" "$TIMESTAMP")
|
|
47
48
|
|
|
48
49
|
API_KEY="\${CLAUDE_REMOTE_API_KEY:-}"
|
|
49
50
|
if [ -n "$API_KEY" ]; then
|
|
@@ -65,6 +66,7 @@ exit 0
|
|
|
65
66
|
function nodeHookScript() {
|
|
66
67
|
return `#!/usr/bin/env node
|
|
67
68
|
// Tactic Remote hook — tool use event
|
|
69
|
+
// ${HOOK_VERSION_TAG}
|
|
68
70
|
const http = require('http');
|
|
69
71
|
let input = '';
|
|
70
72
|
process.stdin.on('data', d => input += d);
|
|
@@ -72,7 +74,8 @@ process.stdin.on('end', () => {
|
|
|
72
74
|
try {
|
|
73
75
|
const data = JSON.parse(input);
|
|
74
76
|
data.project = require('path').basename(process.cwd());
|
|
75
|
-
|
|
77
|
+
data.tactic_session = process.env.TACTIC_SESSION_ID || '';
|
|
78
|
+
data.tmux_session = data.tactic_session;
|
|
76
79
|
const body = JSON.stringify(data);
|
|
77
80
|
const port = process.env.CLAUDE_REMOTE_PORT || 8765;
|
|
78
81
|
const headers = {'Content-Type':'application/json'};
|
|
@@ -94,6 +97,17 @@ function checkHooksInstalled() {
|
|
|
94
97
|
);
|
|
95
98
|
if (!allFilesExist) return false;
|
|
96
99
|
|
|
100
|
+
// Check script version (forces reinstall after upgrade)
|
|
101
|
+
for (const filename of Object.keys(SCRIPT_FILES)) {
|
|
102
|
+
const filepath = path.join(HOOKS_DIR, filename);
|
|
103
|
+
try {
|
|
104
|
+
const content = fs.readFileSync(filepath, 'utf-8');
|
|
105
|
+
if (!content.includes(HOOK_VERSION_TAG)) return false;
|
|
106
|
+
} catch (_e) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
// Check if registered in settings.json
|
|
98
112
|
if (!fs.existsSync(SETTINGS_PATH)) return false;
|
|
99
113
|
|
package/lib/outputParser.js
CHANGED
|
@@ -1,106 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Output parser for Claude Code terminal output
|
|
3
|
-
* Now preserves ANSI codes for iOS client to render colors
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Parse and clean Claude Code output
|
|
8
|
-
* Preserves ANSI color codes for client-side rendering
|
|
9
|
-
* @param {string} rawOutput - Raw terminal output with ANSI codes
|
|
10
|
-
* @param {Object} options - Parser options
|
|
11
|
-
* @param {boolean} options.preserveANSI - Whether to keep ANSI codes (default: true)
|
|
12
|
-
* @param {number} options.maxLines - Maximum lines to return (default: 500)
|
|
13
|
-
* @returns {Object} Parsed output with display text
|
|
14
|
-
*/
|
|
15
|
-
function parseClaudeOutput(rawOutput, options = {}) {
|
|
16
|
-
const { preserveANSI = true, maxLines = 5000 } = options;
|
|
17
|
-
|
|
18
|
-
let cleaned = rawOutput;
|
|
19
|
-
|
|
20
|
-
// Remove problematic control sequences but keep color codes
|
|
21
|
-
cleaned = cleaned
|
|
22
|
-
.replace(/\x1b\].*?\x07/g, '') // OSC sequences (terminal title etc)
|
|
23
|
-
.replace(/\x1b\[\?[0-9;]*[a-z]/g, '') // Private mode sequences
|
|
24
|
-
.replace(/\x1b\[[0-9;]*[ABCDEFGJKST]/g, '') // Cursor movement (but not 'm' for colors)
|
|
25
|
-
.replace(/\r/g, ''); // Carriage returns
|
|
26
|
-
|
|
27
|
-
if (!preserveANSI) {
|
|
28
|
-
// Strip all ANSI codes for plain text mode
|
|
29
|
-
cleaned = cleaned
|
|
30
|
-
.replace(/\x1b\[[0-9;]*m/g, '')
|
|
31
|
-
.replace(/[╭╮╰╯│─┬┴┼├┤┌┐└┘║═╔╗╚╝╠╣╦╩╬]/g, ' ');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Normalize excessive newlines
|
|
35
|
-
cleaned = cleaned.replace(/\n{4,}/g, '\n\n\n');
|
|
36
|
-
|
|
37
|
-
// Split and limit lines
|
|
38
|
-
const lines = cleaned.split('\n');
|
|
39
|
-
const displayLines = lines.slice(-maxLines);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
display: displayLines.join('\n'),
|
|
43
|
-
raw: rawOutput,
|
|
44
|
-
lineCount: displayLines.length,
|
|
45
|
-
hasANSI: /\x1b\[/.test(rawOutput)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check if Claude is waiting for user input
|
|
51
|
-
* @param {string} output - Terminal output to check
|
|
52
|
-
* @returns {boolean} Whether Claude is waiting for input
|
|
53
|
-
*/
|
|
54
|
-
function isWaitingForInput(output) {
|
|
55
|
-
return hasClaudeUI(output);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Positively detect Claude CLI's TUI by checking for its unique UI patterns.
|
|
60
|
-
* This avoids false positives from custom shell themes (oh-my-zsh, powerlevel10k,
|
|
61
|
-
* starship, etc.) that use box-drawing chars, icons, or the word "Claude" in paths.
|
|
62
|
-
*
|
|
63
|
-
* Claude Code's TUI uses rounded box-drawing borders (╭╰) that are distinct from
|
|
64
|
-
* the square corners (┌└) common in shell themes. We require at least 2 independent
|
|
65
|
-
* signals to confirm Claude is running.
|
|
66
|
-
*/
|
|
67
|
-
function hasClaudeUI(output) {
|
|
68
|
-
const lines = output.split('\n').slice(-20).join('\n');
|
|
69
|
-
|
|
70
|
-
// Strong signals — each one alone is sufficient
|
|
71
|
-
if (lines.includes('? for shortcuts')) return true;
|
|
72
|
-
// ╭─ and ╰─ together form Claude's characteristic box
|
|
73
|
-
if (lines.includes('╭─') && lines.includes('╰─')) return true;
|
|
74
|
-
|
|
75
|
-
// Medium signals — need at least 2 to confirm
|
|
76
|
-
let score = 0;
|
|
77
|
-
if (lines.includes('╭─')) score++;
|
|
78
|
-
if (lines.includes('╰─')) score++;
|
|
79
|
-
if (/│\s*>/.test(lines)) score++; // bordered input prompt
|
|
80
|
-
if (/claude/i.test(lines) && lines.includes('│')) score++; // "claude" inside bordered UI
|
|
81
|
-
if (lines.includes('●')) score++; // activity indicator
|
|
82
|
-
|
|
83
|
-
return score >= 2;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Check if Claude is currently running
|
|
88
|
-
* @param {string} output - Terminal output to check
|
|
89
|
-
* @returns {boolean} Whether Claude is running
|
|
90
|
-
*/
|
|
91
|
-
function isClaudeRunning(output) {
|
|
92
|
-
if (output.includes('Goodbye!') || output.includes('Session ended')) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
const lastLines = output.split('\n').slice(-10).join('\n');
|
|
96
|
-
if (lastLines.includes('error: An unknown error occurred')) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
return hasClaudeUI(output);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = {
|
|
103
|
-
parseClaudeOutput,
|
|
104
|
-
isWaitingForInput,
|
|
105
|
-
isClaudeRunning
|
|
106
|
-
};
|
|
1
|
+
module.exports = require('../shared/server-core/outputParser');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../shared/server-core/pushClient');
|
package/lib/rateLimiter.js
CHANGED
|
@@ -1,111 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Rate limiter module
|
|
3
|
-
* Simple in-memory rate limiting for authentication attempts
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
class RateLimiter {
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
// Default: 30 failed attempts per minute per IP
|
|
9
|
-
this.windowMs = options.windowMs || 60 * 1000;
|
|
10
|
-
this.maxAttempts = options.maxAttempts || 30;
|
|
11
|
-
this.records = new Map();
|
|
12
|
-
|
|
13
|
-
// Clean up expired records periodically
|
|
14
|
-
// Use the smaller of windowMs or 60 seconds for responsive cleanup
|
|
15
|
-
const cleanupMs = Math.min(this.windowMs, 60 * 1000);
|
|
16
|
-
this.cleanupInterval = setInterval(() => {
|
|
17
|
-
this.cleanup();
|
|
18
|
-
}, cleanupMs);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Check if an IP is rate limited
|
|
23
|
-
* @param {string} ip - Client IP address
|
|
24
|
-
* @returns {boolean} - true if allowed, false if rate limited
|
|
25
|
-
*/
|
|
26
|
-
isAllowed(ip) {
|
|
27
|
-
const now = Date.now();
|
|
28
|
-
const record = this.records.get(ip);
|
|
29
|
-
|
|
30
|
-
if (!record) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Reset if window has passed
|
|
35
|
-
if (now > record.resetTime) {
|
|
36
|
-
this.records.delete(ip);
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return record.count < this.maxAttempts;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Record a failed authentication attempt
|
|
45
|
-
* @param {string} ip - Client IP address
|
|
46
|
-
*/
|
|
47
|
-
recordFailure(ip) {
|
|
48
|
-
const now = Date.now();
|
|
49
|
-
let record = this.records.get(ip);
|
|
50
|
-
|
|
51
|
-
if (!record || now > record.resetTime) {
|
|
52
|
-
record = {
|
|
53
|
-
count: 0,
|
|
54
|
-
resetTime: now + this.windowMs
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
record.count++;
|
|
59
|
-
this.records.set(ip, record);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get remaining attempts for an IP
|
|
64
|
-
* @param {string} ip - Client IP address
|
|
65
|
-
* @returns {number} - Remaining attempts
|
|
66
|
-
*/
|
|
67
|
-
getRemainingAttempts(ip) {
|
|
68
|
-
const record = this.records.get(ip);
|
|
69
|
-
if (!record || Date.now() > record.resetTime) {
|
|
70
|
-
return this.maxAttempts;
|
|
71
|
-
}
|
|
72
|
-
return Math.max(0, this.maxAttempts - record.count);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Get time until reset for an IP (in seconds)
|
|
77
|
-
* @param {string} ip - Client IP address
|
|
78
|
-
* @returns {number} - Seconds until reset, 0 if not limited
|
|
79
|
-
*/
|
|
80
|
-
getResetTime(ip) {
|
|
81
|
-
const record = this.records.get(ip);
|
|
82
|
-
if (!record) {
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
const remaining = record.resetTime - Date.now();
|
|
86
|
-
return remaining > 0 ? Math.ceil(remaining / 1000) : 0;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Clean up expired records
|
|
91
|
-
*/
|
|
92
|
-
cleanup() {
|
|
93
|
-
const now = Date.now();
|
|
94
|
-
for (const [ip, record] of this.records.entries()) {
|
|
95
|
-
if (now > record.resetTime) {
|
|
96
|
-
this.records.delete(ip);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Stop the cleanup interval (for graceful shutdown)
|
|
103
|
-
*/
|
|
104
|
-
destroy() {
|
|
105
|
-
if (this.cleanupInterval) {
|
|
106
|
-
clearInterval(this.cleanupInterval);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
module.exports = { RateLimiter };
|
|
1
|
+
module.exports = require('../shared/server-core/rateLimiter');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../shared/server-core/serverIdentity');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../shared/server-core/streamJsonParser');
|