@mmmbuto/nexuscrew 0.2.0 → 0.2.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.
- package/README.md +124 -56
- package/bin/nexuscrew.js +79 -152
- package/frontend/dist/assets/{index-8pw4eMB-.js → index-BsldfYnr.js} +1704 -1716
- package/frontend/dist/assets/index-DcQGg3dp.css +1 -0
- package/frontend/dist/index.html +2 -2
- package/lib/server/routes/hosts.js +3 -2
- package/lib/server/routes/launchers.js +12 -0
- package/lib/server/routes/models.js +16 -63
- package/lib/server/routes/runtime.js +10 -0
- package/lib/server/routes/send.js +97 -218
- package/lib/server/routes/sessions.js +7 -39
- package/lib/server/routes/status.js +16 -18
- package/lib/server/routes/tmux.js +88 -0
- package/lib/server/server.js +45 -65
- package/lib/services/engine-discovery.js +192 -445
- package/lib/services/session-store.js +86 -60
- package/lib/services/tmux-manager.js +103 -154
- package/package.json +3 -7
- package/frontend/dist/assets/index-BF0tdvNT.css +0 -1
- package/lib/config/manager.js +0 -362
- package/lib/config/models.js +0 -408
- package/lib/server/db/adapter.js +0 -274
- package/lib/server/db/drivers/sql-js.js +0 -75
- package/lib/server/db/migrate.js +0 -174
- package/lib/server/db/migrations/001_base_schema.sql +0 -70
- package/lib/server/middleware/auth.js +0 -134
- package/lib/server/middleware/rate-limit.js +0 -63
- package/lib/server/models/User.js +0 -128
- package/lib/server/routes/auth.js +0 -168
- package/lib/server/routes/keys.js +0 -15
- package/lib/server/routes/runtimes.js +0 -34
- package/lib/server/routes/speech.js +0 -75
- package/lib/server/routes/upload.js +0 -134
- package/lib/server/routes/wake-lock.js +0 -95
- package/lib/server/routes/workspaces.js +0 -101
- package/lib/server/services/context-bridge.js +0 -425
- package/lib/server/services/runtime-manager.js +0 -462
- package/lib/server/services/summary-generator.js +0 -309
- package/lib/server/services/workspace-manager.js +0 -79
- package/lib/utils/paths.js +0 -107
- package/lib/utils/termux.js +0 -145
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SummaryGenerator - produce contextual summaries for sessions.
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - Generate AI titles for new conversations
|
|
6
|
-
* - Generate contextual summaries for sessions
|
|
7
|
-
* - Auto-save summaries to session_summaries table
|
|
8
|
-
* - Support for summary-based context bridging
|
|
9
|
-
*
|
|
10
|
-
* Note: AI generation requires external provider configuration.
|
|
11
|
-
* This implementation provides the structure; actual AI calls
|
|
12
|
-
* can be integrated via environment-provided clients or webhooks.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const { v4: uuidv4 } = require('uuid');
|
|
16
|
-
const { prepare, saveDb } = require('../db/adapter');
|
|
17
|
-
|
|
18
|
-
class SummaryGenerator {
|
|
19
|
-
constructor(options = {}) {
|
|
20
|
-
this.options = options;
|
|
21
|
-
// AI client can be injected or configured later
|
|
22
|
-
this.aiClient = options.aiClient || null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Set AI client for summary generation
|
|
27
|
-
* @param {Object} client - AI client with sendMessage method
|
|
28
|
-
*/
|
|
29
|
-
setAIClient(client) {
|
|
30
|
-
this.aiClient = client;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Generate a short title for a new conversation (3-8 words)
|
|
35
|
-
* Called after first AI response, runs in background
|
|
36
|
-
* @param {string} userMessage - First user message
|
|
37
|
-
* @param {string} assistantResponse - First AI response (optional, for context)
|
|
38
|
-
* @returns {Promise<string>} Generated title
|
|
39
|
-
*/
|
|
40
|
-
async generateTitle(userMessage, assistantResponse = '') {
|
|
41
|
-
const startedAt = Date.now();
|
|
42
|
-
|
|
43
|
-
// Keep context brief for fast generation
|
|
44
|
-
const context = assistantResponse
|
|
45
|
-
? `User: ${userMessage.slice(0, 500)}\nAssistant: ${assistantResponse.slice(0, 500)}`
|
|
46
|
-
: `User: ${userMessage.slice(0, 800)}`;
|
|
47
|
-
|
|
48
|
-
const prompt = `Generate a brief title (3-8 words, no quotes) for this conversation:
|
|
49
|
-
|
|
50
|
-
${context}
|
|
51
|
-
|
|
52
|
-
Reply with ONLY the title, nothing else.`;
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
if (!this.aiClient) {
|
|
56
|
-
console.warn('[SummaryGenerator] No AI client configured, using fallback title generation');
|
|
57
|
-
return this.fallbackTitle(userMessage);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const result = await this.aiClient.sendMessage({
|
|
61
|
-
prompt,
|
|
62
|
-
conversationId: uuidv4(), // Ephemeral session
|
|
63
|
-
model: 'haiku',
|
|
64
|
-
onStatus: () => {} // Silence status
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Clean up the response
|
|
68
|
-
let title = result.text.trim()
|
|
69
|
-
.replace(/^["']|["']$/g, '') // Remove surrounding quotes
|
|
70
|
-
.replace(/^Title:\s*/i, '') // Remove "Title:" prefix
|
|
71
|
-
.slice(0, 60); // Max 60 chars
|
|
72
|
-
|
|
73
|
-
console.log(`[SummaryGenerator] Title generated in ${Date.now() - startedAt}ms: ${title}`);
|
|
74
|
-
return title || 'New Chat';
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error('[SummaryGenerator] Title generation failed:', error.message);
|
|
77
|
-
// Fallback to truncated first message
|
|
78
|
-
return this.fallbackTitle(userMessage);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Fallback title generation (simple truncation)
|
|
84
|
-
* @param {string} userMessage
|
|
85
|
-
* @returns {string}
|
|
86
|
-
*/
|
|
87
|
-
fallbackTitle(userMessage) {
|
|
88
|
-
return userMessage.slice(0, 50).trim() + (userMessage.length > 50 ? '...' : '');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Generate or refresh summary for a session.
|
|
93
|
-
* @param {Object} params
|
|
94
|
-
* @param {string} params.conversationId
|
|
95
|
-
* @param {Array} params.messages - Array of {role, content, created_at}
|
|
96
|
-
* @param {Object|null} params.existingSummary
|
|
97
|
-
* @returns {Promise<Object>} summary payload
|
|
98
|
-
*/
|
|
99
|
-
async generateSummary({ conversationId, messages = [], existingSummary = null }) {
|
|
100
|
-
if (!conversationId) throw new Error('conversationId is required');
|
|
101
|
-
|
|
102
|
-
const startedAt = Date.now();
|
|
103
|
-
|
|
104
|
-
// Build transcript snippet (limit to 40 latest messages for brevity)
|
|
105
|
-
const transcript = this.buildTranscript(messages.slice(-40));
|
|
106
|
-
|
|
107
|
-
const prompt = this.buildPrompt({ conversationId, transcript, existingSummary });
|
|
108
|
-
|
|
109
|
-
if (!this.aiClient) {
|
|
110
|
-
console.warn('[SummaryGenerator] No AI client configured, using fallback summary');
|
|
111
|
-
return this.fallbackSummary(messages);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const result = await this.aiClient.sendMessage({
|
|
115
|
-
prompt,
|
|
116
|
-
conversationId: uuidv4(), // Ephemeral session
|
|
117
|
-
model: 'haiku',
|
|
118
|
-
onStatus: () => {} // silence status for summaries
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const parsed = this.safeParseJson(result.text);
|
|
122
|
-
|
|
123
|
-
console.log(`[SummaryGenerator] Summary for ${conversationId} took ${Date.now() - startedAt}ms`);
|
|
124
|
-
|
|
125
|
-
return parsed;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Fallback summary generation (rule-based)
|
|
130
|
-
* @param {Array} messages
|
|
131
|
-
* @returns {Object}
|
|
132
|
-
*/
|
|
133
|
-
fallbackSummary(messages) {
|
|
134
|
-
const userMessages = messages.filter(m => m.role === 'user');
|
|
135
|
-
const assistantMessages = messages.filter(m => m.role === 'assistant');
|
|
136
|
-
|
|
137
|
-
// Extract first user message as summary
|
|
138
|
-
const firstUserMsg = userMessages[0]?.content || '';
|
|
139
|
-
const summary = firstUserMsg.slice(0, 200) + (firstUserMsg.length > 200 ? '...' : '');
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
summary_short: summary,
|
|
143
|
-
summary_long: null,
|
|
144
|
-
key_decisions: [],
|
|
145
|
-
tools_used: [],
|
|
146
|
-
files_modified: []
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Save summary to database
|
|
152
|
-
* @param {string} conversationId
|
|
153
|
-
* @param {Object} summary - {summary_short, summary_long, key_decisions, tools_used, files_modified}
|
|
154
|
-
* @returns {boolean} Success
|
|
155
|
-
*/
|
|
156
|
-
saveSummary(conversationId, summary) {
|
|
157
|
-
try {
|
|
158
|
-
const stmt = prepare(`
|
|
159
|
-
INSERT OR REPLACE INTO session_summaries
|
|
160
|
-
(conversation_id, summary_short, key_decisions, files_modified, updated_at)
|
|
161
|
-
VALUES (?, ?, ?, ?, ?)
|
|
162
|
-
`);
|
|
163
|
-
|
|
164
|
-
stmt.run(
|
|
165
|
-
conversationId,
|
|
166
|
-
summary.summary_short || '',
|
|
167
|
-
JSON.stringify(summary.key_decisions || []),
|
|
168
|
-
JSON.stringify(summary.files_modified || []),
|
|
169
|
-
Date.now()
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
saveDb();
|
|
173
|
-
console.log(`[SummaryGenerator] Saved summary for ${conversationId}`);
|
|
174
|
-
return true;
|
|
175
|
-
} catch (error) {
|
|
176
|
-
console.error(`[SummaryGenerator] Failed to save summary:`, error.message);
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Get existing summary from database
|
|
183
|
-
* @param {string} conversationId
|
|
184
|
-
* @returns {Object|null}
|
|
185
|
-
*/
|
|
186
|
-
getSummary(conversationId) {
|
|
187
|
-
try {
|
|
188
|
-
const stmt = prepare('SELECT * FROM session_summaries WHERE conversation_id = ?');
|
|
189
|
-
const row = stmt.get(conversationId);
|
|
190
|
-
|
|
191
|
-
if (!row) return null;
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
summary_short: row.summary_short,
|
|
195
|
-
summary_long: row.summary_long || null,
|
|
196
|
-
key_decisions: JSON.parse(row.key_decisions || '[]'),
|
|
197
|
-
files_modified: JSON.parse(row.files_modified || '[]'),
|
|
198
|
-
updated_at: row.updated_at
|
|
199
|
-
};
|
|
200
|
-
} catch (error) {
|
|
201
|
-
console.warn(`[SummaryGenerator] Failed to get summary:`, error.message);
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Generate summary and save to DB (convenience method)
|
|
208
|
-
* @param {string} conversationId
|
|
209
|
-
* @param {Array} messages
|
|
210
|
-
* @returns {Promise<Object|null>}
|
|
211
|
-
*/
|
|
212
|
-
async generateAndSave(conversationId, messages) {
|
|
213
|
-
try {
|
|
214
|
-
const existingSummary = this.getSummary(conversationId);
|
|
215
|
-
const summary = await this.generateSummary({ conversationId, messages, existingSummary });
|
|
216
|
-
this.saveSummary(conversationId, summary);
|
|
217
|
-
return summary;
|
|
218
|
-
} catch (error) {
|
|
219
|
-
console.error(`[SummaryGenerator] generateAndSave failed:`, error.message);
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Get summary text for context bridging
|
|
226
|
-
* Returns a formatted string suitable for prefixing prompts
|
|
227
|
-
* @param {string} conversationId
|
|
228
|
-
* @returns {string|null}
|
|
229
|
-
*/
|
|
230
|
-
getBridgeContext(conversationId) {
|
|
231
|
-
const summary = this.getSummary(conversationId);
|
|
232
|
-
if (!summary || !summary.summary_short) return null;
|
|
233
|
-
|
|
234
|
-
let context = `[Session Summary]\n${summary.summary_short}`;
|
|
235
|
-
|
|
236
|
-
if (summary.key_decisions && summary.key_decisions.length > 0) {
|
|
237
|
-
context += `\n\nKey decisions:\n- ${summary.key_decisions.slice(0, 5).join('\n- ')}`;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (summary.files_modified && summary.files_modified.length > 0) {
|
|
241
|
-
context += `\n\nFiles worked on:\n- ${summary.files_modified.slice(0, 10).join('\n- ')}`;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return context;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
buildTranscript(messages) {
|
|
248
|
-
return messages
|
|
249
|
-
.map(m => {
|
|
250
|
-
const role = m.role || 'assistant';
|
|
251
|
-
const content = (m.content || '').trim();
|
|
252
|
-
const ts = m.created_at ? new Date(m.created_at * 1000).toISOString() : '';
|
|
253
|
-
return `[${ts}] ${role.toUpperCase()}: ${content}`;
|
|
254
|
-
})
|
|
255
|
-
.join('\n')
|
|
256
|
-
.slice(-6000); // keep prompt size reasonable
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
buildPrompt({ conversationId, transcript, existingSummary }) {
|
|
260
|
-
const existing = existingSummary
|
|
261
|
-
? `Existing summary (for refresh): ${JSON.stringify(existingSummary)}`
|
|
262
|
-
: 'No existing summary.';
|
|
263
|
-
|
|
264
|
-
return `
|
|
265
|
-
You are a concise assistant. Summarize the coding/chat session into JSON.
|
|
266
|
-
Conversation ID: ${conversationId}
|
|
267
|
-
|
|
268
|
-
${existing}
|
|
269
|
-
|
|
270
|
-
Provide JSON with keys:
|
|
271
|
-
- summary_short (<=80 words)
|
|
272
|
-
- summary_long (<=200 words, optional)
|
|
273
|
-
- key_decisions (array of short bullet strings)
|
|
274
|
-
- tools_used (array of tool names or commands, optional)
|
|
275
|
-
- files_modified (array of file paths)
|
|
276
|
-
|
|
277
|
-
Do not include any extra text outside valid JSON.
|
|
278
|
-
|
|
279
|
-
Transcript:
|
|
280
|
-
${transcript}
|
|
281
|
-
`;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
safeParseJson(text) {
|
|
285
|
-
// Try to extract JSON block
|
|
286
|
-
const start = text.indexOf('{');
|
|
287
|
-
const end = text.lastIndexOf('}');
|
|
288
|
-
if (start === -1 || end === -1) {
|
|
289
|
-
throw new Error('Failed to parse summary JSON');
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const jsonString = text.slice(start, end + 1);
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
const parsed = JSON.parse(jsonString);
|
|
296
|
-
// Normalize array fields
|
|
297
|
-
['key_decisions', 'tools_used', 'files_modified'].forEach(key => {
|
|
298
|
-
if (parsed[key] && !Array.isArray(parsed[key])) {
|
|
299
|
-
parsed[key] = [parsed[key]].filter(Boolean);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
return parsed;
|
|
303
|
-
} catch (e) {
|
|
304
|
-
throw new Error('Invalid JSON returned by model');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
module.exports = SummaryGenerator;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workspace Manager - NexusCrew tmux-based version
|
|
3
|
-
*
|
|
4
|
-
* Simplified version that discovers workspaces from conversations table
|
|
5
|
-
* instead of reading .claude/projects/ JSONL files (NexusCLI approach).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const { prepare } = require('../db/adapter');
|
|
10
|
-
|
|
11
|
-
class WorkspaceManager {
|
|
12
|
-
/**
|
|
13
|
-
* Discover workspaces from conversations table
|
|
14
|
-
* Groups by workspace path and counts sessions
|
|
15
|
-
* @returns {Array} List of workspaces with metadata
|
|
16
|
-
*/
|
|
17
|
-
discoverWorkspaces() {
|
|
18
|
-
const stmt = prepare(`
|
|
19
|
-
SELECT workspace, COUNT(*) as session_count,
|
|
20
|
-
MAX(updated_at) as last_activity
|
|
21
|
-
FROM conversations
|
|
22
|
-
WHERE workspace != '' AND workspace IS NOT NULL
|
|
23
|
-
GROUP BY workspace
|
|
24
|
-
ORDER BY last_activity DESC
|
|
25
|
-
`);
|
|
26
|
-
|
|
27
|
-
return stmt.all().map(row => ({
|
|
28
|
-
path: row.workspace,
|
|
29
|
-
session_count: row.session_count,
|
|
30
|
-
last_activity: row.last_activity
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Validate workspace path exists on filesystem
|
|
36
|
-
* @param {string} wsPath - Absolute path to workspace
|
|
37
|
-
* @returns {boolean} True if path exists and is a directory
|
|
38
|
-
*/
|
|
39
|
-
validateWorkspace(wsPath) {
|
|
40
|
-
try {
|
|
41
|
-
return fs.statSync(wsPath).isDirectory();
|
|
42
|
-
} catch {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get conversations for a specific workspace
|
|
49
|
-
* @param {string} workspace - Workspace path
|
|
50
|
-
* @returns {Array} List of conversations in workspace
|
|
51
|
-
*/
|
|
52
|
-
getWorkspaceConversations(workspace) {
|
|
53
|
-
const stmt = prepare(`
|
|
54
|
-
SELECT * FROM conversations
|
|
55
|
-
WHERE workspace = ?
|
|
56
|
-
ORDER BY updated_at DESC
|
|
57
|
-
`);
|
|
58
|
-
return stmt.all(workspace);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get workspace statistics
|
|
63
|
-
* @param {string} workspace - Workspace path
|
|
64
|
-
* @returns {Object} Statistics for the workspace
|
|
65
|
-
*/
|
|
66
|
-
getWorkspaceStats(workspace) {
|
|
67
|
-
const stmt = prepare(`
|
|
68
|
-
SELECT
|
|
69
|
-
COUNT(*) as total_conversations,
|
|
70
|
-
SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) as active_conversations,
|
|
71
|
-
SUM(CASE WHEN pinned = 1 THEN 1 ELSE 0 END) as pinned_conversations
|
|
72
|
-
FROM conversations
|
|
73
|
-
WHERE workspace = ?
|
|
74
|
-
`);
|
|
75
|
-
return stmt.get(workspace);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
module.exports = WorkspaceManager;
|
package/lib/utils/paths.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard Paths for NexusCrew
|
|
3
|
-
* Termux Mobile First - all paths relative to $HOME
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const os = require('os');
|
|
9
|
-
|
|
10
|
-
const HOME = process.env.HOME || os.homedir();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* NexusCrew standard paths
|
|
14
|
-
*/
|
|
15
|
-
const PATHS = {
|
|
16
|
-
// Main config directory
|
|
17
|
-
CONFIG_DIR: path.join(HOME, '.nexuscrew'),
|
|
18
|
-
|
|
19
|
-
// Config file
|
|
20
|
-
CONFIG_FILE: path.join(HOME, '.nexuscrew', 'config.json'),
|
|
21
|
-
|
|
22
|
-
// Data directory (database, cache)
|
|
23
|
-
DATA_DIR: path.join(HOME, '.nexuscrew', 'data'),
|
|
24
|
-
|
|
25
|
-
// Database file
|
|
26
|
-
DATABASE: path.join(HOME, '.nexuscrew', 'data', 'nexuscrew.db'),
|
|
27
|
-
|
|
28
|
-
// Logs directory
|
|
29
|
-
LOGS_DIR: path.join(HOME, '.nexuscrew', 'logs'),
|
|
30
|
-
|
|
31
|
-
// Server log
|
|
32
|
-
SERVER_LOG: path.join(HOME, '.nexuscrew', 'logs', 'server.log'),
|
|
33
|
-
|
|
34
|
-
// PID file for daemon
|
|
35
|
-
PID_FILE: path.join(HOME, '.nexuscrew', 'nexuscrew.pid'),
|
|
36
|
-
|
|
37
|
-
// Engines config directory
|
|
38
|
-
ENGINES_DIR: path.join(HOME, '.nexuscrew', 'engines'),
|
|
39
|
-
|
|
40
|
-
// Termux boot script
|
|
41
|
-
BOOT_SCRIPT: path.join(HOME, '.termux', 'boot', 'nexuscrew-start.sh'),
|
|
42
|
-
|
|
43
|
-
// Claude CLI history (read-only)
|
|
44
|
-
CLAUDE_HISTORY: path.join(HOME, '.claude', 'history.jsonl'),
|
|
45
|
-
CLAUDE_PROJECTS: path.join(HOME, '.claude', 'projects'),
|
|
46
|
-
|
|
47
|
-
// Default workspace
|
|
48
|
-
DEFAULT_WORKSPACE: path.join(HOME, 'Dev')
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Ensure all required directories exist
|
|
53
|
-
*/
|
|
54
|
-
function ensureDirectories() {
|
|
55
|
-
const dirs = [
|
|
56
|
-
PATHS.CONFIG_DIR,
|
|
57
|
-
PATHS.DATA_DIR,
|
|
58
|
-
PATHS.LOGS_DIR,
|
|
59
|
-
PATHS.ENGINES_DIR
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
for (const dir of dirs) {
|
|
63
|
-
if (!fs.existsSync(dir)) {
|
|
64
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Ensure Termux boot directory exists
|
|
71
|
-
*/
|
|
72
|
-
function ensureBootDirectory() {
|
|
73
|
-
const bootDir = path.join(HOME, '.termux', 'boot');
|
|
74
|
-
if (!fs.existsSync(bootDir)) {
|
|
75
|
-
fs.mkdirSync(bootDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
return bootDir;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get path resolving ~ to HOME
|
|
82
|
-
*/
|
|
83
|
-
function resolvePath(p) {
|
|
84
|
-
if (p.startsWith('~')) {
|
|
85
|
-
return path.join(HOME, p.slice(1));
|
|
86
|
-
}
|
|
87
|
-
return path.resolve(p);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get relative path from HOME (for display)
|
|
92
|
-
*/
|
|
93
|
-
function toDisplayPath(p) {
|
|
94
|
-
if (p.startsWith(HOME)) {
|
|
95
|
-
return '~' + p.slice(HOME.length);
|
|
96
|
-
}
|
|
97
|
-
return p;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = {
|
|
101
|
-
PATHS,
|
|
102
|
-
HOME,
|
|
103
|
-
ensureDirectories,
|
|
104
|
-
ensureBootDirectory,
|
|
105
|
-
resolvePath,
|
|
106
|
-
toDisplayPath
|
|
107
|
-
};
|
package/lib/utils/termux.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Termux Detection and Utilities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const { execSync, spawn } = require('child_process');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Check if running in Termux environment
|
|
11
|
-
*/
|
|
12
|
-
function isTermux() {
|
|
13
|
-
return (
|
|
14
|
-
process.platform === 'android' ||
|
|
15
|
-
process.env.PREFIX?.includes('com.termux') ||
|
|
16
|
-
process.env.TERMUX_VERSION !== undefined
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get Termux prefix path
|
|
22
|
-
*/
|
|
23
|
-
function getPrefix() {
|
|
24
|
-
return process.env.PREFIX || '/data/data/com.termux/files/usr';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Check if a Termux package is installed
|
|
29
|
-
*/
|
|
30
|
-
function isPackageInstalled(pkg) {
|
|
31
|
-
try {
|
|
32
|
-
execSync(`which ${pkg}`, { stdio: 'ignore' });
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Install a Termux package
|
|
41
|
-
*/
|
|
42
|
-
function installPackage(pkg) {
|
|
43
|
-
try {
|
|
44
|
-
execSync(`pkg install -y ${pkg}`, { stdio: 'inherit' });
|
|
45
|
-
return true;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Check if Termux:API app is working
|
|
53
|
-
*/
|
|
54
|
-
function isTermuxApiWorking() {
|
|
55
|
-
try {
|
|
56
|
-
execSync('termux-battery-status', { timeout: 5000, stdio: 'ignore' });
|
|
57
|
-
return true;
|
|
58
|
-
} catch {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Check if Termux:Boot is available
|
|
65
|
-
*/
|
|
66
|
-
function isTermuxBootAvailable() {
|
|
67
|
-
const bootDir = path.join(process.env.HOME, '.termux', 'boot');
|
|
68
|
-
return fs.existsSync(bootDir);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Acquire Termux wake lock
|
|
73
|
-
*/
|
|
74
|
-
function acquireWakeLock() {
|
|
75
|
-
if (!isTermux()) return false;
|
|
76
|
-
try {
|
|
77
|
-
spawn('termux-wake-lock', [], { detached: true, stdio: 'ignore' }).unref();
|
|
78
|
-
return true;
|
|
79
|
-
} catch {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Release Termux wake lock
|
|
86
|
-
*/
|
|
87
|
-
function releaseWakeLock() {
|
|
88
|
-
if (!isTermux()) return false;
|
|
89
|
-
try {
|
|
90
|
-
spawn('termux-wake-unlock', [], { detached: true, stdio: 'ignore' }).unref();
|
|
91
|
-
return true;
|
|
92
|
-
} catch {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Send Termux notification
|
|
99
|
-
*/
|
|
100
|
-
function sendNotification(title, content, id = 'nexuscrew') {
|
|
101
|
-
if (!isTermux()) return false;
|
|
102
|
-
try {
|
|
103
|
-
execSync(`termux-notification --id ${id} --title "${title}" --content "${content}"`, {
|
|
104
|
-
stdio: 'ignore'
|
|
105
|
-
});
|
|
106
|
-
return true;
|
|
107
|
-
} catch {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Get required Termux packages
|
|
114
|
-
*/
|
|
115
|
-
function getRequiredPackages() {
|
|
116
|
-
return ['termux-api', 'termux-tools'];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Check all required packages
|
|
121
|
-
*/
|
|
122
|
-
function checkRequiredPackages() {
|
|
123
|
-
const packages = getRequiredPackages();
|
|
124
|
-
const status = {};
|
|
125
|
-
|
|
126
|
-
for (const pkg of packages) {
|
|
127
|
-
status[pkg] = isPackageInstalled(pkg);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return status;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
module.exports = {
|
|
134
|
-
isTermux,
|
|
135
|
-
getPrefix,
|
|
136
|
-
isPackageInstalled,
|
|
137
|
-
installPackage,
|
|
138
|
-
isTermuxApiWorking,
|
|
139
|
-
isTermuxBootAvailable,
|
|
140
|
-
acquireWakeLock,
|
|
141
|
-
releaseWakeLock,
|
|
142
|
-
sendNotification,
|
|
143
|
-
getRequiredPackages,
|
|
144
|
-
checkRequiredPackages
|
|
145
|
-
};
|