nothumanallowed 16.0.13 → 16.0.14

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": "16.0.13",
3
+ "version": "16.0.14",
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 = '16.0.13';
8
+ export const VERSION = '16.0.14';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -2010,18 +2010,45 @@ class TelegramResponder {
2010
2010
  // If the previous turn ran a LIST/LAST-SHOWN and the user now says
2011
2011
  // "cancellalo / eliminalo / quello / si / conferma / fallo", resolve the
2012
2012
  // referent from this._lastContextByChatId[chatId].lastCalendarEvents.
2013
- const isAnaphoric = /\b(cancell|elimin|rimuov)[aeiloy]+(lo|la|li|le|gli)?\b/.test(lower)
2013
+ // Wider regex: matches "cancellalo", "cancellali", "cancellatelo!",
2014
+ // "eliminali tutti", with any trailing punctuation.
2015
+ const isAnaphoric = /(cancell|elimin|rimuov)\w*\s*[!.?]?$/i.test(userMessage.trim())
2014
2016
  && !this._extractCalendarProposal(userMessage).date
2015
2017
  && !this._extractCalendarProposal(userMessage).title;
2016
2018
  const isYesConfirm = /^\s*(s[ìi]\b|si\s|sì\s|ok\b|okay\b|certo\b|certamente\b|d'?accordo\b|fai|fallo|procedi|esegui|conferm[oa]|yes\b|yep\b|confirm\b|do\s*it|go\s*ahead)/i.test(userMessage.trim());
2017
- if (chatId && (isAnaphoric || isYesConfirm)) {
2018
- const ctx = this._lastContextByChatId[chatId] || {};
2019
+ if (isAnaphoric || isYesConfirm) {
2020
+ // Look up the event list across multiple keys, in order of preference:
2021
+ // 1. exact chatId (if the caller passed one)
2022
+ // 2. any context key whose lastCalendarListAt is the most recent
2023
+ // This fixes a class of bugs where the chat UI generates a fresh
2024
+ // conversationId between turns, breaking the strict key lookup.
2025
+ let ctx = chatId ? (this._lastContextByChatId[chatId] || {}) : {};
2026
+ if (!ctx.lastCalendarEvents || ctx.lastCalendarEvents.length === 0) {
2027
+ // Fallback: scan every stored context for the most recent calendar list.
2028
+ let bestKey = null, bestAt = 0;
2029
+ for (const [k, v] of Object.entries(this._lastContextByChatId)) {
2030
+ if (Array.isArray(v?.lastCalendarEvents) && v.lastCalendarEvents.length > 0
2031
+ && (v.lastCalendarListAt || 0) > bestAt) {
2032
+ bestKey = k;
2033
+ bestAt = v.lastCalendarListAt || 0;
2034
+ }
2035
+ }
2036
+ if (bestKey) {
2037
+ this.log(`[direct] anaphoric fallback: chatId=${chatId} empty, using bestKey=${bestKey} (${Date.now() - bestAt}ms ago)`);
2038
+ ctx = this._lastContextByChatId[bestKey];
2039
+ }
2040
+ } else {
2041
+ this.log(`[direct] anaphoric hit: chatId=${chatId} eventsCount=${ctx.lastCalendarEvents.length}`);
2042
+ }
2019
2043
  const pendingEvents = ctx.lastCalendarEvents || ctx.pendingDeleteEvents || [];
2020
2044
  // Strict: only auto-execute if the previous turn LIST/proposal had a
2021
2045
  // single deletable event, or if pendingDelete is explicitly set.
2022
2046
  const eligible = ctx.pendingDeleteEvents && ctx.pendingDeleteEvents.length > 0
2023
2047
  ? ctx.pendingDeleteEvents
2024
2048
  : (pendingEvents.length === 1 ? pendingEvents : null);
2049
+ if (!eligible) {
2050
+ this.log(`[direct] anaphoric SKIP: ${isAnaphoric ? 'anaphoric' : 'yes-confirm'} matched but no eligible event. ctx keys: ${Object.keys(this._lastContextByChatId).join(',')}`);
2051
+ }
2025
2052
  if (eligible && eligible.length > 0) {
2026
2053
  let ok = 0, ko = 0;
2027
2054
  const failed = [];
@@ -2237,16 +2264,18 @@ class TelegramResponder {
2237
2264
  try {
2238
2265
  const out = await executeTool(toolName, args, config);
2239
2266
  const events = this._parseEventsFromToolOutput(String(out));
2240
- if (chatId) {
2241
- const prev = this._lastContextByChatId[chatId] || {};
2242
- this._lastContextByChatId[chatId] = {
2243
- ...prev,
2244
- lastCalendarEvents: events,
2245
- lastCalendarListAt: Date.now(),
2246
- lastCalendarSource: { tool: toolName, args },
2247
- };
2248
- try { saveTelegramContext(this._lastContextByChatId); } catch {}
2249
- }
2267
+ // Even without chatId, save to a global fallback bucket so the
2268
+ // anaphoric resolution can still find it.
2269
+ const persistKey = chatId || '__last_list__';
2270
+ const prev = this._lastContextByChatId[persistKey] || {};
2271
+ this._lastContextByChatId[persistKey] = {
2272
+ ...prev,
2273
+ lastCalendarEvents: events,
2274
+ lastCalendarListAt: Date.now(),
2275
+ lastCalendarSource: { tool: toolName, args },
2276
+ };
2277
+ this.log(`[direct] LIST stored: chatId=${persistKey} eventsCount=${events.length} tool=${toolName}`);
2278
+ try { saveTelegramContext(this._lastContextByChatId); } catch (e) { this.log(`[direct] persist FAILED: ${e.message}`); }
2250
2279
  return { action: actionKey, success: true, message: String(out) };
2251
2280
  } catch (e) { return { action: actionKey, success: false, message: `Errore: ${e.message}` }; }
2252
2281
  };