nothumanallowed 14.1.51 → 14.1.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nothumanallowed",
3
- "version": "14.1.51",
3
+ "version": "14.1.53",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '14.1.51';
8
+ export const VERSION = '14.1.53';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -51,9 +51,30 @@ export function register(router) {
51
51
  const { promisify } = await import('util');
52
52
  const execAsync = promisify(exec);
53
53
 
54
- // npm update -g doesn't cross major/minor versions use install @latest
55
- const { stdout, stderr } = await execAsync('npm install -g nothumanallowed@latest', {
56
- timeout: 120000
54
+ // Detect the package manager and global prefix to handle permissions correctly
55
+ let cmd = 'npm install -g nothumanallowed@latest';
56
+
57
+ // On macOS/Linux, check if we need special handling for permission
58
+ if (process.platform !== 'win32') {
59
+ try {
60
+ // Check if npm global dir is writable by current user
61
+ const { stdout: prefix } = await execAsync('npm config get prefix', { timeout: 5000 });
62
+ const globalDir = prefix.trim();
63
+ await fs.promises.access(path.join(globalDir, 'lib'), fs.constants.W_OK);
64
+ } catch {
65
+ // Global dir not writable — return error with clear instructions
66
+ sendJSON(res, 200, {
67
+ success: false,
68
+ error: 'EACCES: permission denied',
69
+ message: 'Permission denied. Run: sudo npm install -g nothumanallowed@latest'
70
+ });
71
+ return;
72
+ }
73
+ }
74
+
75
+ const { stdout, stderr } = await execAsync(cmd, {
76
+ timeout: 120_000,
77
+ env: { ...process.env, NODE_ENV: 'production' },
57
78
  });
58
79
 
59
80
  sendJSON(res, 200, {
@@ -63,10 +84,13 @@ export function register(router) {
63
84
  stderr: stderr.trim()
64
85
  });
65
86
  } catch (e) {
66
- sendJSON(res, 500, {
87
+ const isPermission = e.message?.includes('EACCES') || e.message?.includes('permission denied');
88
+ sendJSON(res, 200, {
67
89
  success: false,
68
- error: e.message,
69
- message: 'Update failed. Try running: npm install -g nothumanallowed@latest'
90
+ error: isPermission ? 'EACCES: permission denied' : e.message,
91
+ message: isPermission
92
+ ? 'Permission denied. Run: sudo npm install -g nothumanallowed@latest'
93
+ : 'Update failed. Try running: npm install -g nothumanallowed@latest'
70
94
  });
71
95
  }
72
96
  });
@@ -9,6 +9,92 @@ import { loadConfig } from '../../config.mjs';
9
9
  import { NHA_DIR } from '../../constants.mjs';
10
10
  import { getUnreadImportant, getMessage, listMessages, getTodayEmails, sendEmail, createDraft } from '../../services/mail-router.mjs';
11
11
 
12
+ /**
13
+ * Persist a single Gmail API message to the local SQLite DB.
14
+ * Non-blocking — errors are caught and logged, never thrown to the caller.
15
+ */
16
+ async function persistGmailMessageToDb(config, msg) {
17
+ if (!msg || !msg.id) return;
18
+
19
+ const { SQLITE_AVAILABLE, getDb, ensureGoogleAccount, upsertFolder } = await import('../../services/email-db.mjs');
20
+ if (!SQLITE_AVAILABLE) return;
21
+
22
+ const db = getDb();
23
+
24
+ // Determine the user's email from config
25
+ let accountEmail = 'gmail@account';
26
+ try {
27
+ accountEmail = config.google?.email || config.email || accountEmail;
28
+ } catch {}
29
+ // Fallback: extract from 'to' field
30
+ if (accountEmail === 'gmail@account' && msg.to) {
31
+ const match = msg.to.match(/<(.+?)>$/);
32
+ accountEmail = match ? match[1] : msg.to;
33
+ }
34
+
35
+ // Ensure Google account exists
36
+ const googleAccount = ensureGoogleAccount({
37
+ id: 'google',
38
+ display_name: 'Gmail',
39
+ email_address: accountEmail,
40
+ imap_host: 'gmail.googleapis.com',
41
+ imap_port: 993,
42
+ is_active: 1
43
+ });
44
+ if (!googleAccount) return;
45
+
46
+ // Determine folder from labels
47
+ let folderKey = 'INBOX';
48
+ if (msg.labels && Array.isArray(msg.labels)) {
49
+ if (msg.labels.includes('SENT')) folderKey = 'SENT';
50
+ else if (msg.labels.includes('DRAFT')) folderKey = 'DRAFTS';
51
+ else if (msg.labels.includes('SPAM')) folderKey = 'SPAM';
52
+ else if (msg.labels.includes('TRASH')) folderKey = 'TRASH';
53
+ }
54
+
55
+ const folderMap = {
56
+ 'INBOX': { name: 'Inbox', type: 'inbox' },
57
+ 'SENT': { name: 'Sent', type: 'sent' },
58
+ 'DRAFTS': { name: 'Drafts', type: 'drafts' },
59
+ 'SPAM': { name: 'Spam', type: 'spam' },
60
+ 'TRASH': { name: 'Trash', type: 'trash' },
61
+ };
62
+ const folderInfo = folderMap[folderKey] || { name: 'Inbox', type: 'inbox' };
63
+ const folderId = upsertFolder(googleAccount.id, folderKey, folderInfo.name, folderInfo.type, 1, 0);
64
+ if (!folderId) return;
65
+
66
+ // Extract email/name from "Name <email>" format
67
+ const fromEmail = msg.from ? (msg.from.match(/<(.+?)>$/)?.[1] || msg.from) : '';
68
+ const fromName = msg.from ? (msg.from.match(/^(.+?)\s*<.+>$/)?.[1]?.replace(/['"]/g, '') || '') : '';
69
+
70
+ // Insert or replace message
71
+ db.prepare(`
72
+ INSERT OR REPLACE INTO email_messages
73
+ (id, account_id, folder_id, imap_folder_path, uid, message_id, thread_id,
74
+ subject, from_address, from_name, to_addresses, body_text, body_html, body_preview,
75
+ internal_date, has_attachments, source)
76
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
77
+ `).run(
78
+ msg.id, googleAccount.id, folderId, folderKey,
79
+ Date.now() + (Math.random() * 1000 | 0),
80
+ msg.id, msg.threadId || msg.id,
81
+ msg.subject || '(no subject)',
82
+ fromEmail, fromName,
83
+ msg.to || '',
84
+ msg.body || '', msg.bodyHtml || '',
85
+ msg.snippet || '',
86
+ new Date(msg.date || Date.now()).toISOString(),
87
+ (msg.attachments && msg.attachments.length > 0) ? 1 : 0,
88
+ 'gmail_api'
89
+ );
90
+
91
+ // Persist read/starred state
92
+ db.prepare(`
93
+ INSERT OR REPLACE INTO email_message_state (message_id, is_read, is_starred)
94
+ VALUES (?, ?, ?)
95
+ `).run(msg.id, msg.isUnread ? 0 : 1, msg.isImportant ? 1 : 0);
96
+ }
97
+
12
98
  export function register(router) {
13
99
  // ── Gmail ──────────────────────────────────────────────────────────────
14
100
 
@@ -50,6 +136,13 @@ export function register(router) {
50
136
  : folder;
51
137
  const emails = await getAllEmails(config, gmailFolder, limit + offset);
52
138
  sendJSON(res, 200, { emails: emails.slice(offset, offset + limit), total: emails.length });
139
+
140
+ // Persist fetched emails to local SQLite DB (fire-and-forget, non-blocking)
141
+ setImmediate(() => {
142
+ for (const msg of emails) {
143
+ persistGmailMessageToDb(config, msg).catch(() => {});
144
+ }
145
+ });
53
146
  } catch (providerErr) {
54
147
  if (providerErr.message?.includes('No mail provider') || providerErr.message?.includes('token')) {
55
148
  try {
@@ -90,6 +183,12 @@ export function register(router) {
90
183
  try {
91
184
  const msg = await getMessage(config, msgId);
92
185
  console.log('[EMAIL READ SUCCESS] Gmail API returned:', JSON.stringify(msg, null, 2).slice(0, 500));
186
+
187
+ // Persist to local SQLite DB for offline/local-first access
188
+ persistGmailMessageToDb(config, msg).catch(e =>
189
+ console.warn('[EMAIL READ] Failed to persist to DB:', e.message)
190
+ );
191
+
93
192
  sendJSON(res, 200, { message: msg });
94
193
  } catch (providerErr) {
95
194
  // Gmail API failed — fall back to local IMAP DB
@@ -24,12 +24,15 @@ export function register(router) {
24
24
 
25
25
  router.get('/api/github', async (req, res) => {
26
26
  try {
27
- const { listNotifications } = await import('../../services/github.mjs');
27
+ const { listNotificationsRaw } = await import('../../services/github.mjs');
28
28
  const config = loadConfig();
29
- sendJSON(res, 200, { notifications: await listNotifications(config) });
29
+ const notifications = await listNotificationsRaw(config);
30
+ sendJSON(res, 200, { notifications: Array.isArray(notifications) ? notifications : [] });
30
31
  } catch (e) {
31
- if (e.message?.includes('token') || e.message?.includes('not configured')) return sendJSON(res, 200, { notifications: [], authRequired: true });
32
- sendError(res, 500, e.message);
32
+ if (e.message?.includes('token') || e.message?.includes('not configured') || e.message?.includes('401')) {
33
+ return sendJSON(res, 200, { notifications: [], error: 'GitHub token not configured or expired. Run: nha config set github-token YOUR_PAT' });
34
+ }
35
+ sendJSON(res, 200, { notifications: [], error: e.message });
33
36
  }
34
37
  });
35
38
 
@@ -59,7 +59,7 @@ const BOUNDARY_WORDS = new Set([
59
59
  ]);
60
60
 
61
61
  // Single characters commonly produced by BPE fragmentation in Italian/English
62
- const BPE_SINGLE_CHARS = new Set(['a','c','d','e','i','l','m','n','o','p','r','s','t','u','v']);
62
+ const BPE_SINGLE_CHARS = new Set('abcdefghijklmnopqrstuvwxyzàèéìòù'.split(''));
63
63
 
64
64
  /**
65
65
  * Enterprise-grade linguistic scorer for Italian/English word candidates.
@@ -693,8 +693,8 @@ export async function callNHA(apiKey, model, systemPrompt, userMessage, stream =
693
693
  let content = data.choices?.[0]?.message?.content || '';
694
694
  // Strip thinking tags if present
695
695
  content = content.replace(/<think>[\s\S]*?<\/think>/g, '').trim();
696
- // Fix Qwen3 BPE tokenizer artifacts (words fused without spaces)
697
- content = fixQwen3BPE(content);
696
+ // NOTE: Do NOT apply fixQwen3BPE here. With stream:false, vLLM returns
697
+ // correctly-spaced text. The BPE repair regex corrupts normal words.
698
698
  return content;
699
699
  }
700
700
 
@@ -962,13 +962,9 @@ export async function callLLMStream(config, systemPrompt, userMessage, onToken,
962
962
  let fullNhaText = nhaJson.choices?.[0]?.message?.content || '';
963
963
  // Strip <think>...</think> blocks
964
964
  fullNhaText = fullNhaText.replace(/<think>[\s\S]*?<\/think>/g, '').trim();
965
- // Fix Qwen3 BPE tokenizer artifacts: words joined without spaces.
966
- // Qwen3 streaming via vLLM occasionally produces subword tokens that arrive
967
- // concatenated e.g. "lacorrelazione" instead of "la correlazione",
968
- // "ilprezzodell'oro" instead of "il prezzo dell'oro".
969
- // We fix this by inserting spaces before Italian/English articles and
970
- // prepositions that appear fused at word boundaries.
971
- fullNhaText = fixQwen3BPE(fullNhaText);
965
+ // NOTE: Do NOT apply fixQwen3BPE here. With stream:false, vLLM returns
966
+ // correctly-spaced text. The BPE repair regex is too aggressive and
967
+ // corrupts normal Italian words (e.g. "assistente" "ass ist ente").
972
968
  if (onToken) onToken(fullNhaText);
973
969
  return fullNhaText;
974
970
  }
@@ -1233,8 +1229,6 @@ async function streamSSEWithCallback(res, format, onToken) {
1233
1229
  }
1234
1230
  }
1235
1231
 
1236
- // Apply BPE repair to the final accumulated text before returning
1237
- fullText = fixQwen3BPE(fullText);
1238
1232
  return fullText;
1239
1233
  }
1240
1234