@resolveio/server-lib 22.1.15 → 22.1.17

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.
@@ -551,6 +551,7 @@ var AI_ASSISTANT_SYSTEM_PROMPT = [
551
551
  '- Do not modify files, run destructive commands, or access databases directly.',
552
552
  '- Read-only data access is allowed only via the REPORT_BUILDER_READ/REPORT_BUILDER_AGG directives (see below).',
553
553
  '- Do not access secrets, credentials, or user data.',
554
+ '- If asked about the underlying AI/model/provider/runtime (including Codex/OpenAI/local-vs-hosted/version details), refuse. This information is not available to users, including admins and super admins.',
554
555
  '- If the user has a customer portal scope (other.id_customer), only discuss that customer\'s data and what is visible in their customer portal. Never reference other customers or internal/admin-only data. If asked for anything outside the portal, say it isn\'t available.',
555
556
  '- Do not assist with hacking, bypassing security, or abuse.',
556
557
  'Accuracy & tools:',
@@ -1254,7 +1255,7 @@ function loadAiTerminalMethods(methodManager) {
1254
1255
  }
1255
1256
  function executeAiTerminalRun(payload, context) {
1256
1257
  return __awaiter(this, void 0, void 0, function () {
1257
- var input, message, requestId, isSuperAdmin, guardrailsEnabled, guardrail, conversation_1, now_1, userMsg, assistantMsg, conversation, now, attachments, attachmentData, config, systemPrompt, userPromptTemplate, userPrompt, historyLimit, history, _a, messages, openaiSettings, client, response, usage, idClient, userDoc, assistantDoc, insertResult;
1258
+ var input, message, requestId, identityGuardrail, conversation_1, now_1, userMsg, assistantMsg, isSuperAdmin, guardrailsEnabled, guardrail, conversation_2, now_2, userMsg, assistantMsg, conversation, now, attachments, attachmentData, config, systemPrompt, userPromptTemplate, userPrompt, historyLimit, history, _a, messages, openaiSettings, client, response, usage, idClient, userDoc, assistantDoc, insertResult;
1258
1259
  return __generator(this, function (_b) {
1259
1260
  switch (_b.label) {
1260
1261
  case 0:
@@ -1264,15 +1265,10 @@ function executeAiTerminalRun(payload, context) {
1264
1265
  throw new Error('Message is required.');
1265
1266
  }
1266
1267
  requestId = normalizeOptionalString(input.request_id);
1267
- return [4 /*yield*/, resolveIsSuperAdmin(context === null || context === void 0 ? void 0 : context.id_user)];
1268
- case 1:
1269
- isSuperAdmin = _b.sent();
1270
- guardrailsEnabled = input.guardrails !== false && !isSuperAdmin;
1271
- if (!guardrailsEnabled) return [3 /*break*/, 6];
1272
- guardrail = evaluateGuardrails(message);
1273
- if (!(guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked)) return [3 /*break*/, 6];
1268
+ identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(message);
1269
+ if (!(identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked)) return [3 /*break*/, 5];
1274
1270
  return [4 /*yield*/, ensureConversation(input, 'openai', context === null || context === void 0 ? void 0 : context.id_user)];
1275
- case 2:
1271
+ case 1:
1276
1272
  conversation_1 = _b.sent();
1277
1273
  now_1 = new Date();
1278
1274
  userMsg = {
@@ -1286,47 +1282,88 @@ function executeAiTerminalRun(payload, context) {
1286
1282
  assistantMsg = {
1287
1283
  id_conversation: conversation_1._id,
1288
1284
  role: 'assistant',
1289
- content: guardrail.response,
1290
- metadata: __assign({ blocked: true, reason: guardrail.reason }, (requestId ? { request_id: requestId } : {})),
1285
+ content: identityGuardrail.response,
1286
+ metadata: __assign({ blocked: true, reason: identityGuardrail.reason }, (requestId ? { request_id: requestId } : {})),
1291
1287
  createdAt: now_1,
1292
1288
  updatedAt: now_1
1293
1289
  };
1294
1290
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(userMsg)];
1295
- case 3:
1291
+ case 2:
1296
1292
  _b.sent();
1297
1293
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(assistantMsg)];
1298
- case 4:
1294
+ case 3:
1299
1295
  _b.sent();
1300
1296
  return [4 /*yield*/, touchConversation(conversation_1._id, now_1)];
1301
- case 5:
1297
+ case 4:
1302
1298
  _b.sent();
1303
1299
  return [2 /*return*/, {
1304
1300
  conversation: conversation_1,
1305
1301
  message: assistantMsg,
1306
- guardrails: { blocked: true, reason: guardrail.reason }
1302
+ guardrails: { blocked: true, reason: identityGuardrail.reason }
1307
1303
  }];
1308
- case 6: return [4 /*yield*/, ensureConversation(input, 'openai', context === null || context === void 0 ? void 0 : context.id_user)];
1304
+ case 5: return [4 /*yield*/, resolveIsSuperAdmin(context === null || context === void 0 ? void 0 : context.id_user)];
1305
+ case 6:
1306
+ isSuperAdmin = _b.sent();
1307
+ guardrailsEnabled = input.guardrails !== false && !isSuperAdmin;
1308
+ if (!guardrailsEnabled) return [3 /*break*/, 11];
1309
+ guardrail = evaluateGuardrails(message);
1310
+ if (!(guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked)) return [3 /*break*/, 11];
1311
+ return [4 /*yield*/, ensureConversation(input, 'openai', context === null || context === void 0 ? void 0 : context.id_user)];
1309
1312
  case 7:
1313
+ conversation_2 = _b.sent();
1314
+ now_2 = new Date();
1315
+ userMsg = {
1316
+ id_conversation: conversation_2._id,
1317
+ role: 'user',
1318
+ content: message,
1319
+ metadata: requestId ? { request_id: requestId } : undefined,
1320
+ createdAt: now_2,
1321
+ updatedAt: now_2
1322
+ };
1323
+ assistantMsg = {
1324
+ id_conversation: conversation_2._id,
1325
+ role: 'assistant',
1326
+ content: guardrail.response,
1327
+ metadata: __assign({ blocked: true, reason: guardrail.reason }, (requestId ? { request_id: requestId } : {})),
1328
+ createdAt: now_2,
1329
+ updatedAt: now_2
1330
+ };
1331
+ return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(userMsg)];
1332
+ case 8:
1333
+ _b.sent();
1334
+ return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(assistantMsg)];
1335
+ case 9:
1336
+ _b.sent();
1337
+ return [4 /*yield*/, touchConversation(conversation_2._id, now_2)];
1338
+ case 10:
1339
+ _b.sent();
1340
+ return [2 /*return*/, {
1341
+ conversation: conversation_2,
1342
+ message: assistantMsg,
1343
+ guardrails: { blocked: true, reason: guardrail.reason }
1344
+ }];
1345
+ case 11: return [4 /*yield*/, ensureConversation(input, 'openai', context === null || context === void 0 ? void 0 : context.id_user)];
1346
+ case 12:
1310
1347
  conversation = _b.sent();
1311
1348
  now = new Date();
1312
1349
  attachments = Array.isArray(input.attachments) ? input.attachments : [];
1313
1350
  return [4 /*yield*/, readAttachmentContents(attachments)];
1314
- case 8:
1351
+ case 13:
1315
1352
  attachmentData = _b.sent();
1316
1353
  config = sanitizeConfig(input.config || {});
1317
1354
  systemPrompt = normalizeOptionalString(config.system_prompt) || '';
1318
1355
  userPromptTemplate = normalizeOptionalString(config.user_prompt_template);
1319
1356
  userPrompt = buildUserPrompt(userPromptTemplate, message, attachmentData.promptText);
1320
1357
  historyLimit = normalizeHistoryLimit(input.max_history);
1321
- if (!(historyLimit > 0)) return [3 /*break*/, 10];
1358
+ if (!(historyLimit > 0)) return [3 /*break*/, 15];
1322
1359
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.find({ id_conversation: conversation._id, role: { $in: ['user', 'assistant'] } }, { sort: { createdAt: 1 }, limit: historyLimit * 2 })];
1323
- case 9:
1360
+ case 14:
1324
1361
  _a = _b.sent();
1325
- return [3 /*break*/, 11];
1326
- case 10:
1362
+ return [3 /*break*/, 16];
1363
+ case 15:
1327
1364
  _a = [];
1328
- _b.label = 11;
1329
- case 11:
1365
+ _b.label = 16;
1366
+ case 16:
1330
1367
  history = _a;
1331
1368
  messages = [];
1332
1369
  if (systemPrompt) {
@@ -1345,13 +1382,13 @@ function executeAiTerminalRun(payload, context) {
1345
1382
  openaiSettings = resolveOpenAISettings(config);
1346
1383
  client = new openai_client_1.OpenAIClient(openaiSettings);
1347
1384
  return [4 /*yield*/, client.chat(messages, { timeoutMs: 60000, responseFormat: config.response_format })];
1348
- case 12:
1385
+ case 17:
1349
1386
  response = _b.sent();
1350
1387
  usage = response.usage || estimateUsage(messages, response.content, openaiSettings.model);
1351
1388
  return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
1352
- case 13:
1389
+ case 18:
1353
1390
  idClient = _b.sent();
1354
- if (!idClient) return [3 /*break*/, 15];
1391
+ if (!idClient) return [3 /*break*/, 20];
1355
1392
  return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)({
1356
1393
  id_client: idClient,
1357
1394
  model: response.model || openaiSettings.model || 'unknown',
@@ -1361,10 +1398,10 @@ function executeAiTerminalRun(payload, context) {
1361
1398
  category: 'ai-terminal',
1362
1399
  id_conversation: conversation._id
1363
1400
  })];
1364
- case 14:
1401
+ case 19:
1365
1402
  _b.sent();
1366
- _b.label = 15;
1367
- case 15:
1403
+ _b.label = 20;
1404
+ case 20:
1368
1405
  userDoc = {
1369
1406
  id_conversation: conversation._id,
1370
1407
  role: 'user',
@@ -1389,20 +1426,20 @@ function executeAiTerminalRun(payload, context) {
1389
1426
  updatedAt: now
1390
1427
  };
1391
1428
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(userDoc)];
1392
- case 16:
1429
+ case 21:
1393
1430
  _b.sent();
1394
1431
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(assistantDoc)];
1395
- case 17:
1432
+ case 22:
1396
1433
  insertResult = _b.sent();
1397
1434
  return [4 /*yield*/, touchConversation(conversation._id, now, insertResult._id)];
1398
- case 18:
1435
+ case 23:
1399
1436
  _b.sent();
1400
- if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 20];
1437
+ if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 25];
1401
1438
  return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
1402
- case 19:
1439
+ case 24:
1403
1440
  _b.sent();
1404
- _b.label = 20;
1405
- case 20: return [2 /*return*/, {
1441
+ _b.label = 25;
1442
+ case 25: return [2 /*return*/, {
1406
1443
  conversation: conversation,
1407
1444
  message: assistantDoc,
1408
1445
  usage: assistantDoc.usage
@@ -1482,7 +1519,7 @@ function executeAiFormPatch(payload, context) {
1482
1519
  }
1483
1520
  function executeAiAssistantCodexRun(payload, context) {
1484
1521
  return __awaiter(this, void 0, void 0, function () {
1485
- var input, message, aiWorkerDebug, requestId, codexModel, codexFallbackModels, guardrail, conversation_2, now_2, userMsg, assistantMsg, user, isSuperAdmin, hasInvoiceAccess, customerId, conversation, now, attachments, navigationFastPath, userMsg, assistantMsg, assistantInsert, assistantMessageId_1, changeHistoryFastPath, userMsg, assistantMsg, assistantInsert, assistantMessageId_2, attachmentData, historyLimit, history, _a, historyLines, recentToolError, userDoc, initialProgress, assistantDoc, insertResult, assistantMessageId;
1522
+ var input, message, aiWorkerDebug, requestId, codexModel, codexFallbackModels, guardrail, conversation_3, now_3, userMsg, assistantMsg, user, isSuperAdmin, canViewDebug, hasInvoiceAccess, customerId, conversation, now, attachments, navigationFastPath, userMsg, assistantMsg, assistantInsert, assistantMessageId_1, changeHistoryFastPath, changeHistoryFastPathBypassedReason, userMsg, assistantMsg, assistantInsert, assistantMessageId_2, attachmentData, historyLimit, history, _a, historyLines, recentToolError, userDoc, initialProgress, assistantDoc, insertResult, assistantMessageId;
1486
1523
  var _this = this;
1487
1524
  var _b, _c, _d;
1488
1525
  return __generator(this, function (_e) {
@@ -1504,23 +1541,23 @@ function executeAiAssistantCodexRun(payload, context) {
1504
1541
  if (!(guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked)) return [3 /*break*/, 5];
1505
1542
  return [4 /*yield*/, ensureConversation(input, 'codex', context === null || context === void 0 ? void 0 : context.id_user)];
1506
1543
  case 1:
1507
- conversation_2 = _e.sent();
1508
- now_2 = new Date();
1544
+ conversation_3 = _e.sent();
1545
+ now_3 = new Date();
1509
1546
  userMsg = {
1510
- id_conversation: conversation_2._id,
1547
+ id_conversation: conversation_3._id,
1511
1548
  role: 'user',
1512
1549
  content: message,
1513
1550
  metadata: requestId ? { request_id: requestId } : undefined,
1514
- createdAt: now_2,
1515
- updatedAt: now_2
1551
+ createdAt: now_3,
1552
+ updatedAt: now_3
1516
1553
  };
1517
1554
  assistantMsg = {
1518
- id_conversation: conversation_2._id,
1555
+ id_conversation: conversation_3._id,
1519
1556
  role: 'assistant',
1520
1557
  content: guardrail.response,
1521
1558
  metadata: __assign({ blocked: true, reason: guardrail.reason }, (requestId ? { request_id: requestId } : {})),
1522
- createdAt: now_2,
1523
- updatedAt: now_2
1559
+ createdAt: now_3,
1560
+ updatedAt: now_3
1524
1561
  };
1525
1562
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(userMsg)];
1526
1563
  case 2:
@@ -1528,11 +1565,11 @@ function executeAiAssistantCodexRun(payload, context) {
1528
1565
  return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.insertOne(assistantMsg)];
1529
1566
  case 3:
1530
1567
  _e.sent();
1531
- return [4 /*yield*/, touchConversation(conversation_2._id, now_2)];
1568
+ return [4 /*yield*/, touchConversation(conversation_3._id, now_3)];
1532
1569
  case 4:
1533
1570
  _e.sent();
1534
1571
  return [2 /*return*/, {
1535
- conversation: conversation_2,
1572
+ conversation: conversation_3,
1536
1573
  message: assistantMsg,
1537
1574
  guardrails: { blocked: true, reason: guardrail.reason }
1538
1575
  }];
@@ -1540,6 +1577,7 @@ function executeAiAssistantCodexRun(payload, context) {
1540
1577
  case 6:
1541
1578
  user = _e.sent();
1542
1579
  isSuperAdmin = !!((_b = user === null || user === void 0 ? void 0 : user.roles) === null || _b === void 0 ? void 0 : _b.super_admin);
1580
+ canViewDebug = isAssistantDebugUser(user);
1543
1581
  hasInvoiceAccess = userHasInvoiceAccess(user);
1544
1582
  customerId = normalizeOptionalString((_c = user === null || user === void 0 ? void 0 : user.other) === null || _c === void 0 ? void 0 : _c.id_customer);
1545
1583
  return [4 /*yield*/, ensureConversation(input, 'codex', context === null || context === void 0 ? void 0 : context.id_user)];
@@ -1608,7 +1646,12 @@ function executeAiAssistantCodexRun(payload, context) {
1608
1646
  })];
1609
1647
  case 12:
1610
1648
  changeHistoryFastPath = _e.sent();
1611
- if (!changeHistoryFastPath) return [3 /*break*/, 16];
1649
+ changeHistoryFastPathBypassedReason = (changeHistoryFastPath
1650
+ && (changeHistoryFastPath.reason === 'no_repo' || changeHistoryFastPath.reason === 'error')
1651
+ && !shouldReturnAssistantChangeHistoryUnavailableFastPath())
1652
+ ? changeHistoryFastPath.reason
1653
+ : '';
1654
+ if (!(changeHistoryFastPath && !changeHistoryFastPathBypassedReason)) return [3 /*break*/, 16];
1612
1655
  userMsg = {
1613
1656
  id_conversation: conversation._id,
1614
1657
  role: 'user',
@@ -1781,6 +1824,11 @@ function executeAiAssistantCodexRun(payload, context) {
1781
1824
  contextRoute = normalizeOptionalString((_k = input === null || input === void 0 ? void 0 : input.context) === null || _k === void 0 ? void 0 : _k.route);
1782
1825
  contextMode = normalizeOptionalString((_l = input === null || input === void 0 ? void 0 : input.context) === null || _l === void 0 ? void 0 : _l.mode);
1783
1826
  recordStep('Queued', { requestId: requestId || undefined });
1827
+ if (changeHistoryFastPathBypassedReason) {
1828
+ recordStep('Planning: change-history fast path unavailable', {
1829
+ reason: changeHistoryFastPathBypassedReason
1830
+ });
1831
+ }
1784
1832
  recordStep('Planning: request classification', {
1785
1833
  type: requestClassification.type,
1786
1834
  source: requestClassification.source,
@@ -1880,7 +1928,8 @@ function executeAiAssistantCodexRun(payload, context) {
1880
1928
  fieldHints: fieldHints,
1881
1929
  methodHints: methodHints,
1882
1930
  publicationHints: publicationHints,
1883
- recentToolError: recentToolError
1931
+ recentToolError: recentToolError,
1932
+ changeHistoryFastPathBypassedReason: changeHistoryFastPathBypassedReason
1884
1933
  });
1885
1934
  heuristicDirectivePrecomputed = dataQuestion
1886
1935
  ? buildAssistantHeuristicDirective(message, collectionHints, collectionNames)
@@ -2408,7 +2457,7 @@ function executeAiAssistantCodexRun(payload, context) {
2408
2457
  });
2409
2458
  }
2410
2459
  finalNow = new Date();
2411
- if (isSuperAdmin) {
2460
+ if (canViewDebug) {
2412
2461
  finishedAt = Date.now();
2413
2462
  codexMs = timingBreakdown.directiveMs
2414
2463
  + timingBreakdown.plannerMs
@@ -2475,7 +2524,9 @@ function executeAiAssistantCodexRun(payload, context) {
2475
2524
  }
2476
2525
  });
2477
2526
  }
2478
- finalMetadata = __assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), (toolResult ? { tool_result: toolResult } : {})), (assistantDebug ? { debug: assistantDebug } : {}));
2527
+ finalMetadata = __assign(__assign(__assign(__assign(__assign({ model: codexModel }, (codexFallbackModels.length ? { model_fallbacks: codexFallbackModels } : {})), (requestId ? { request_id: requestId } : {})), (changeHistoryFastPathBypassedReason ? {
2528
+ fast_path_change_history_bypassed_reason: changeHistoryFastPathBypassedReason
2529
+ } : {})), (toolResult ? { tool_result: toolResult } : {})), (assistantDebug ? { debug: assistantDebug } : {}));
2479
2530
  finalUsage = codexUsage.total_tokens > 0 ? {
2480
2531
  model: codexModel || 'unknown',
2481
2532
  input_tokens: codexUsage.input_tokens,
@@ -2671,7 +2722,7 @@ function executeAiAssistantReportIssue(payload, context) {
2671
2722
  }
2672
2723
  function executeAiAssistantMongoRead(payload, context) {
2673
2724
  return __awaiter(this, void 0, void 0, function () {
2674
- var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _e, activeFallback, fallbackRead, fallbackDocs, _f, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
2725
+ var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, strippedClient, clientScopedQuery, scopedQuery, normalized, findOptions, runFindWithRepair, initialRead, documents, executedQuery, probeDocs, dateFallback, fallbackQuery, fallbackRead, fallbackDocs, expanded, fallbackRead, fallbackDocs, nameFallback, fallbackRead, fallbackDocs, _c, chemicalLookup, fallbackRead, fallbackDocs, queryFields, _d, aliases, rewrittenQuery, fallbackRead, fallbackDocs, _e, activeFallback, fallbackRead, fallbackDocs, _f, idLookup, fallbackRead, fallbackDocs, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, hasActiveStatusFilters, crossCollectionCandidates, crossCollectionCandidates_1, crossCollectionCandidates_1_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, existingFallbacks, rejectedQuality, error_5, existingErrors, e_1_1, nameFields, dateFields, diagnostics, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, total, sanitizedDocuments, requestedFields, missingFields, _o, projectionAliases, expandedProjection, refreshedDocs, includeIds, fieldAliases, displayDocs, idLookupDisplay, priorityFields, displayMaxRows, display;
2675
2726
  var e_1, _p;
2676
2727
  var _this = this;
2677
2728
  var _q, _r;
@@ -2709,7 +2760,7 @@ function executeAiAssistantMongoRead(payload, context) {
2709
2760
  : input.permissionView;
2710
2761
  return [4 /*yield*/, ensureAssistantReadAccess(context, effectivePermissionView, collection)];
2711
2762
  case 3:
2712
- _a = _s.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin;
2763
+ _a = _s.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin, canViewDebug = _a.canViewDebug;
2713
2764
  if (!isSuperAdmin && AI_ASSISTANT_BLOCKED_COLLECTIONS.has(collection)) {
2714
2765
  throw new Error('AI assistant report builder bridge: Access denied.');
2715
2766
  }
@@ -3039,7 +3090,7 @@ function executeAiAssistantMongoRead(payload, context) {
3039
3090
  case 33:
3040
3091
  fallbackResult = _s.sent();
3041
3092
  if (Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) && fallbackResult.documents.length) {
3042
- if (isSuperAdmin && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
3093
+ if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
3043
3094
  existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
3044
3095
  ? fallbackResult.debug.fallbacks
3045
3096
  : {};
@@ -3051,7 +3102,7 @@ function executeAiAssistantMongoRead(payload, context) {
3051
3102
  }
3052
3103
  return [2 /*return*/, fallbackResult];
3053
3104
  }
3054
- if (isSuperAdmin) {
3105
+ if (canViewDebug) {
3055
3106
  fallbackMeta.reportFallback = { from: collection, to: baseCollection, attempted: true, used: false };
3056
3107
  }
3057
3108
  _s.label = 34;
@@ -3092,7 +3143,7 @@ function executeAiAssistantMongoRead(payload, context) {
3092
3143
  fallbackResult = _s.sent();
3093
3144
  fallbackDocs = Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) ? fallbackResult.documents : [];
3094
3145
  if (fallbackDocs.length && shouldAcceptAssistantFallbackDocuments(fallbackDocs)) {
3095
- if (isSuperAdmin && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
3146
+ if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
3096
3147
  existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
3097
3148
  ? fallbackResult.debug.fallbacks
3098
3149
  : {};
@@ -3106,7 +3157,7 @@ function executeAiAssistantMongoRead(payload, context) {
3106
3157
  }
3107
3158
  return [2 /*return*/, fallbackResult];
3108
3159
  }
3109
- if (fallbackDocs.length && isSuperAdmin && fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
3160
+ if (fallbackDocs.length && canViewDebug && fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
3110
3161
  rejectedQuality = Array.isArray(fallbackMeta.collectionRetry.rejectedQuality)
3111
3162
  ? fallbackMeta.collectionRetry.rejectedQuality
3112
3163
  : [];
@@ -3146,7 +3197,7 @@ function executeAiAssistantMongoRead(payload, context) {
3146
3197
  return [7 /*endfinally*/];
3147
3198
  case 45: return [3 /*break*/, 47];
3148
3199
  case 46:
3149
- if (!documents.length && crossCollectionRetryEnabled && hasActiveStatusFilters && isSuperAdmin) {
3200
+ if (!documents.length && crossCollectionRetryEnabled && hasActiveStatusFilters && canViewDebug) {
3150
3201
  fallbackMeta.collectionRetry = {
3151
3202
  from: collection,
3152
3203
  root: retryRootCollection,
@@ -3157,7 +3208,7 @@ function executeAiAssistantMongoRead(payload, context) {
3157
3208
  }
3158
3209
  _s.label = 47;
3159
3210
  case 47:
3160
- if (!(!documents.length && isSuperAdmin)) return [3 /*break*/, 64];
3211
+ if (!(!documents.length && canViewDebug)) return [3 /*break*/, 64];
3161
3212
  nameFields = collectMatchFieldsByCondition(executedQuery, function (field, condition) { return isRegexMatchCondition(condition)
3162
3213
  || (typeof condition === 'string' && shouldApplyAssistantNameRegex(field)); });
3163
3214
  dateFields = collectMatchFieldsByCondition(executedQuery, function (_field, condition) { return isDateCondition(condition); });
@@ -3328,7 +3379,7 @@ function executeAiAssistantMongoRead(payload, context) {
3328
3379
  if (Object.keys(fieldAliases).length) {
3329
3380
  fallbackMeta.fieldAliases = fieldAliases;
3330
3381
  }
3331
- return [2 /*return*/, __assign({ documents: sanitizedDocuments, total: total, display: display }, (isSuperAdmin ? {
3382
+ return [2 /*return*/, __assign({ documents: sanitizedDocuments, total: total, display: display }, (canViewDebug ? {
3332
3383
  debug: {
3333
3384
  collection: collection,
3334
3385
  collectionRequested: rawCollection,
@@ -3350,7 +3401,7 @@ function executeAiAssistantMongoRead(payload, context) {
3350
3401
  }
3351
3402
  function executeAiAssistantMongoAggregate(payload, context) {
3352
3403
  return __awaiter(this, void 0, void 0, function () {
3353
- var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, aggregateOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, verification, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
3404
+ var input, rawCollection, retryState, triedCollections, crossCollectionRetryEnabled, dbName, db, collectionResolution, collection, bridgeCollection, retryRootCollection, schemaFields, effectivePermissionView, _a, user, isSuperAdmin, canViewDebug, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, executedPipeline, dateField, aggregateOptions, runAggregateWithRepair, initialAggregate, documents, probeDocs, fallback, fallbackPipeline, fallbackAggregate, fallbackDocs, createdFallback, createdPipeline, createdAggregate, createdDocs, expanded, expandedAggregate, expandedDocs, completionFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackAggregate, fallbackDocs, nameFallback, fallbackPipeline, fallbackAggregate, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackAggregate, fallbackDocs, _loop_2, i, state_2, nestedFallbacks, nestedFallbacks_1, nestedFallbacks_1_1, nestedFallback, fallbackPayload, fallbackResult, existingFallbacks, error_7, errorMessage, existingErrors, e_2_1, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, fallbackAcceptanceOptions, crossCollectionCandidates, crossCollectionCandidates_2, crossCollectionCandidates_2_1, candidateCollection, fallbackPayload, fallbackResult, fallbackDocs, fallbackQuality, existingFallbacks, rejectedQuality, error_8, existingErrors, e_3_1, matchStages, diagnostics, combinedMatch, nameFields, dateFields, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, verification, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
3354
3405
  var e_2, _o, e_3, _p;
3355
3406
  var _this = this;
3356
3407
  var _q, _r;
@@ -3388,7 +3439,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
3388
3439
  : input.permissionView;
3389
3440
  return [4 /*yield*/, ensureAssistantReadAccess(context, effectivePermissionView, collection)];
3390
3441
  case 3:
3391
- _a = _s.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin;
3442
+ _a = _s.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin, canViewDebug = _a.canViewDebug;
3392
3443
  if (!isSuperAdmin && AI_ASSISTANT_BLOCKED_COLLECTIONS.has(collection)) {
3393
3444
  throw new Error('AI assistant report builder bridge: Access denied.');
3394
3445
  }
@@ -3952,7 +4003,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
3952
4003
  case 47:
3953
4004
  fallbackResult = _s.sent();
3954
4005
  if (Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) && fallbackResult.documents.length) {
3955
- if (isSuperAdmin && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
4006
+ if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
3956
4007
  existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
3957
4008
  ? fallbackResult.debug.fallbacks
3958
4009
  : {};
@@ -4008,7 +4059,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4008
4059
  case 55:
4009
4060
  fallbackResult = _s.sent();
4010
4061
  if (Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) && fallbackResult.documents.length) {
4011
- if (isSuperAdmin && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
4062
+ if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
4012
4063
  existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
4013
4064
  ? fallbackResult.debug.fallbacks
4014
4065
  : {};
@@ -4020,7 +4071,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4020
4071
  }
4021
4072
  return [2 /*return*/, fallbackResult];
4022
4073
  }
4023
- if (isSuperAdmin) {
4074
+ if (canViewDebug) {
4024
4075
  fallbackMeta.reportFallback = { from: collection, to: baseCollection, attempted: true, used: false };
4025
4076
  }
4026
4077
  _s.label = 56;
@@ -4062,7 +4113,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4062
4113
  fallbackDocs = Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) ? fallbackResult.documents : [];
4063
4114
  fallbackQuality = evaluateAssistantFallbackDocumentsQuality(fallbackDocs, fallbackAcceptanceOptions);
4064
4115
  if (fallbackDocs.length && fallbackQuality.accepted) {
4065
- if (isSuperAdmin && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
4116
+ if (canViewDebug && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
4066
4117
  existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
4067
4118
  ? fallbackResult.debug.fallbacks
4068
4119
  : {};
@@ -4076,7 +4127,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4076
4127
  }
4077
4128
  return [2 /*return*/, fallbackResult];
4078
4129
  }
4079
- if (fallbackDocs.length && isSuperAdmin && fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
4130
+ if (fallbackDocs.length && canViewDebug && fallbackMeta.collectionRetry && typeof fallbackMeta.collectionRetry === 'object') {
4080
4131
  rejectedQuality = Array.isArray(fallbackMeta.collectionRetry.rejectedQuality)
4081
4132
  ? fallbackMeta.collectionRetry.rejectedQuality
4082
4133
  : [];
@@ -4120,7 +4171,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4120
4171
  finally { if (e_3) throw e_3.error; }
4121
4172
  return [7 /*endfinally*/];
4122
4173
  case 67:
4123
- if (!(!documents.length && isSuperAdmin)) return [3 /*break*/, 84];
4174
+ if (!(!documents.length && canViewDebug)) return [3 /*break*/, 84];
4124
4175
  matchStages = (executedPipeline || []).filter(function (stage) { return stage && typeof stage === 'object' && stage.$match && typeof stage.$match === 'object'; });
4125
4176
  diagnostics = {};
4126
4177
  if (!matchStages.length) return [3 /*break*/, 84];
@@ -4241,7 +4292,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
4241
4292
  maxRows: normalizedOptions.limit || sanitizedDocuments.length,
4242
4293
  includeGroupFromId: false
4243
4294
  });
4244
- return [2 /*return*/, __assign(__assign({ documents: sanitizedDocuments, display: display }, (verification ? { verification: verification } : {})), (isSuperAdmin ? {
4295
+ return [2 /*return*/, __assign(__assign({ documents: sanitizedDocuments, display: display }, (verification ? { verification: verification } : {})), (canViewDebug ? {
4245
4296
  debug: __assign(__assign({ collection: collection, collectionRequested: rawCollection, collectionResolved: collection, collectionMatched: collectionResolution.matched, collectionCandidates: collectionResolution.candidates, collectionScore: collectionResolution.score, bridge: 'report-builder', database: dbName, query: scopedQuery, options: normalizedOptions.aggregateOptions, originalPipeline: limitedPipeline, executedPipeline: executedPipeline }, (verification ? { verification: verification } : {})), { fallbacks: fallbackMeta })
4246
4297
  } : {}))];
4247
4298
  }
@@ -9636,7 +9687,7 @@ function isDisplayObjectLike(value) {
9636
9687
  }
9637
9688
  function ensureAssistantReadAccess(context, permissionView, collection) {
9638
9689
  return __awaiter(this, void 0, void 0, function () {
9639
- var idUser, user, isSuperAdmin, normalizedCollection, normalizedPermission, requiresInvoiceAccess, hasInvoiceAccess, hasViewAccess;
9690
+ var idUser, user, isSuperAdmin, canViewDebug, normalizedCollection, normalizedPermission, requiresInvoiceAccess, hasInvoiceAccess, hasViewAccess;
9640
9691
  var _a;
9641
9692
  return __generator(this, function (_b) {
9642
9693
  switch (_b.label) {
@@ -9652,8 +9703,9 @@ function ensureAssistantReadAccess(context, permissionView, collection) {
9652
9703
  throw new Error('AI assistant report builder bridge: Unauthorized.');
9653
9704
  }
9654
9705
  isSuperAdmin = !!((_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.super_admin);
9706
+ canViewDebug = isAssistantDebugUser(user);
9655
9707
  if (isSuperAdmin) {
9656
- return [2 /*return*/, { user: user, isSuperAdmin: isSuperAdmin }];
9708
+ return [2 /*return*/, { user: user, isSuperAdmin: isSuperAdmin, canViewDebug: canViewDebug }];
9657
9709
  }
9658
9710
  normalizedCollection = normalizeOptionalString(collection);
9659
9711
  normalizedPermission = normalizeAssistantPermissionView(permissionView, normalizedCollection);
@@ -9669,7 +9721,7 @@ function ensureAssistantReadAccess(context, permissionView, collection) {
9669
9721
  if (requiresInvoiceAccess && !hasInvoiceAccess) {
9670
9722
  throw new Error('AI assistant report builder bridge: Access denied.');
9671
9723
  }
9672
- return [2 /*return*/, { user: user, isSuperAdmin: isSuperAdmin }];
9724
+ return [2 /*return*/, { user: user, isSuperAdmin: isSuperAdmin, canViewDebug: canViewDebug }];
9673
9725
  }
9674
9726
  });
9675
9727
  });
@@ -16845,6 +16897,11 @@ function parseAssistantPathList(value) {
16845
16897
  .map(function (entry) { return normalizeOptionalString(entry); })
16846
16898
  .filter(Boolean);
16847
16899
  }
16900
+ function resolveAssistantConfiguredWorkspaceRoots(serverConfigParam, envParam) {
16901
+ var serverConfig = serverConfigParam || resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
16902
+ var env = envParam || process.env || {};
16903
+ return mergeAssistantHintValues(parseAssistantPathList(serverConfig['AI_ASSISTANT_WORKSPACE_ROOTS']), parseAssistantPathList(env['AI_ASSISTANT_WORKSPACE_ROOTS']), parseAssistantPathList(serverConfig['AI_ASSISTANT_GIT_ROOTS']), parseAssistantPathList(env['AI_ASSISTANT_GIT_ROOTS']), parseAssistantPathList(serverConfig['AI_ASSISTANT_WORKSPACE_ROOT']), parseAssistantPathList(env['AI_ASSISTANT_WORKSPACE_ROOT']), parseAssistantPathList(serverConfig['AI_ASSISTANT_ROOT_WORKSPACE']), parseAssistantPathList(env['AI_ASSISTANT_ROOT_WORKSPACE']), parseAssistantPathList(serverConfig['AI_TERMINAL_WORKSPACE_ROOT']), parseAssistantPathList(env['AI_TERMINAL_WORKSPACE_ROOT']), parseAssistantPathList(serverConfig['AI_DASHBOARD_WORKSPACE_ROOT']), parseAssistantPathList(env['AI_DASHBOARD_WORKSPACE_ROOT']));
16904
+ }
16848
16905
  function buildAssistantParentDirectoryCandidates(basePath, maxDepth) {
16849
16906
  if (maxDepth === void 0) { maxDepth = 4; }
16850
16907
  var normalized = normalizeOptionalString(basePath);
@@ -16869,7 +16926,7 @@ function buildAssistantWorkspaceRootCandidates(params) {
16869
16926
  var cwdValue = normalizeOptionalString((params === null || params === void 0 ? void 0 : params.cwd) || process.cwd());
16870
16927
  var dirnameValue = normalizeOptionalString((params === null || params === void 0 ? void 0 : params.dirname) || __dirname);
16871
16928
  var homeDir = normalizeOptionalString(os.homedir());
16872
- var configuredRoots = mergeAssistantHintValues(parseAssistantPathList(serverConfig['AI_ASSISTANT_WORKSPACE_ROOTS']), parseAssistantPathList(env['AI_ASSISTANT_WORKSPACE_ROOTS']), parseAssistantPathList(serverConfig['AI_ASSISTANT_GIT_ROOTS']), parseAssistantPathList(env['AI_ASSISTANT_GIT_ROOTS']));
16929
+ var configuredRoots = resolveAssistantConfiguredWorkspaceRoots(serverConfig, env);
16873
16930
  var pathCandidates = __spreadArray(__spreadArray(__spreadArray([
16874
16931
  serverConfig['AI_ASSISTANT_WORKSPACE_ROOT'],
16875
16932
  env['AI_ASSISTANT_WORKSPACE_ROOT'],
@@ -16904,20 +16961,21 @@ function buildAssistantWorkspaceRootCandidates(params) {
16904
16961
  }
16905
16962
  function resolveAssistantWorkspaceRoot() {
16906
16963
  return __awaiter(this, void 0, void 0, function () {
16907
- var candidates, firstExisting, candidates_8, candidates_8_1, candidate, _a, gitRoot, e_44_1;
16964
+ var candidates, firstExisting, firstNestedGitRoot, candidates_8, candidates_8_1, candidate, _a, gitRoot, nestedGitRoots, e_44_1;
16908
16965
  var e_44, _b;
16909
16966
  return __generator(this, function (_c) {
16910
16967
  switch (_c.label) {
16911
16968
  case 0:
16912
16969
  candidates = buildAssistantWorkspaceRootCandidates();
16913
16970
  firstExisting = '';
16971
+ firstNestedGitRoot = '';
16914
16972
  _c.label = 1;
16915
16973
  case 1:
16916
- _c.trys.push([1, 8, 9, 10]);
16974
+ _c.trys.push([1, 9, 10, 11]);
16917
16975
  candidates_8 = __values(candidates), candidates_8_1 = candidates_8.next();
16918
16976
  _c.label = 2;
16919
16977
  case 2:
16920
- if (!!candidates_8_1.done) return [3 /*break*/, 7];
16978
+ if (!!candidates_8_1.done) return [3 /*break*/, 8];
16921
16979
  candidate = candidates_8_1.value;
16922
16980
  _a = !candidate;
16923
16981
  if (_a) return [3 /*break*/, 4];
@@ -16927,7 +16985,7 @@ function resolveAssistantWorkspaceRoot() {
16927
16985
  _c.label = 4;
16928
16986
  case 4:
16929
16987
  if (_a) {
16930
- return [3 /*break*/, 6];
16988
+ return [3 /*break*/, 7];
16931
16989
  }
16932
16990
  if (!firstExisting) {
16933
16991
  firstExisting = candidate;
@@ -16936,24 +16994,34 @@ function resolveAssistantWorkspaceRoot() {
16936
16994
  case 5:
16937
16995
  gitRoot = _c.sent();
16938
16996
  if (gitRoot) {
16939
- return [2 /*return*/, candidate];
16997
+ return [2 /*return*/, gitRoot];
16940
16998
  }
16941
- _c.label = 6;
16999
+ if (!!firstNestedGitRoot) return [3 /*break*/, 7];
17000
+ return [4 /*yield*/, resolveAssistantWorkspaceGitRoots(candidate)];
16942
17001
  case 6:
17002
+ nestedGitRoots = _c.sent();
17003
+ if (nestedGitRoots.length) {
17004
+ firstNestedGitRoot = nestedGitRoots[0];
17005
+ }
17006
+ _c.label = 7;
17007
+ case 7:
16943
17008
  candidates_8_1 = candidates_8.next();
16944
17009
  return [3 /*break*/, 2];
16945
- case 7: return [3 /*break*/, 10];
16946
- case 8:
17010
+ case 8: return [3 /*break*/, 11];
17011
+ case 9:
16947
17012
  e_44_1 = _c.sent();
16948
17013
  e_44 = { error: e_44_1 };
16949
- return [3 /*break*/, 10];
16950
- case 9:
17014
+ return [3 /*break*/, 11];
17015
+ case 10:
16951
17016
  try {
16952
17017
  if (candidates_8_1 && !candidates_8_1.done && (_b = candidates_8.return)) _b.call(candidates_8);
16953
17018
  }
16954
17019
  finally { if (e_44) throw e_44.error; }
16955
17020
  return [7 /*endfinally*/];
16956
- case 10:
17021
+ case 11:
17022
+ if (firstNestedGitRoot) {
17023
+ return [2 /*return*/, firstNestedGitRoot];
17024
+ }
16957
17025
  if (firstExisting) {
16958
17026
  return [2 /*return*/, firstExisting];
16959
17027
  }
@@ -17730,6 +17798,11 @@ function buildAssistantContext(input, userContext) {
17730
17798
  if (recentToolError) {
17731
17799
  lines.push("Most recent data-query error: ".concat(recentToolError));
17732
17800
  }
17801
+ var changeHistoryBypassReason = normalizeOptionalString(userContext === null || userContext === void 0 ? void 0 : userContext.changeHistoryFastPathBypassedReason);
17802
+ if (changeHistoryBypassReason) {
17803
+ lines.push("Change history fast path unavailable: ".concat(changeHistoryBypassReason));
17804
+ lines.push('For change-history requests, run git history lookups through available repository tooling before concluding history is unavailable.');
17805
+ }
17733
17806
  var mongoDb = normalizeOptionalString((_c = input === null || input === void 0 ? void 0 : input.mongo) === null || _c === void 0 ? void 0 : _c.database);
17734
17807
  var mongoDbs = Array.isArray((_d = input === null || input === void 0 ? void 0 : input.mongo) === null || _d === void 0 ? void 0 : _d.databases)
17735
17808
  ? input.mongo.databases.map(function (value) { return normalizeOptionalString(value); }).filter(Boolean)
@@ -18695,7 +18768,7 @@ function resolveAssistantWorkspaceGitRoots(workspaceRoot) {
18695
18768
  return [4 /*yield*/, resolveAssistantGitRoot(workspaceRoot)];
18696
18769
  case 1:
18697
18770
  _a.apply(void 0, [_h.sent()]);
18698
- configuredRoots = mergeAssistantHintValues(parseAssistantPathList(process.env.AI_ASSISTANT_GIT_ROOTS), parseAssistantPathList(process.env.AI_ASSISTANT_WORKSPACE_ROOTS));
18771
+ configuredRoots = resolveAssistantConfiguredWorkspaceRoots();
18699
18772
  _h.label = 2;
18700
18773
  case 2:
18701
18774
  _h.trys.push([2, 7, 8, 9]);
@@ -18977,6 +19050,12 @@ function buildAssistantChangeHistoryUnavailableResponse(message, reason) {
18977
19050
  generic: true
18978
19051
  };
18979
19052
  }
19053
+ function shouldReturnAssistantChangeHistoryUnavailableFastPath() {
19054
+ var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
19055
+ var configured = normalizeOptionalBoolean(config['AI_ASSISTANT_CHANGE_HISTORY_UNAVAILABLE_FAST_PATH']
19056
+ || process.env.AI_ASSISTANT_CHANGE_HISTORY_UNAVAILABLE_FAST_PATH);
19057
+ return configured === true;
19058
+ }
18980
19059
  function resolveAssistantChangeHistoryGitRepoUrls() {
18981
19060
  var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
18982
19061
  var rawValues = [
@@ -19471,6 +19550,10 @@ function sanitizeAssistantResponse(value) {
19471
19550
  function evaluateAssistantGuardrails(message) {
19472
19551
  var e_52, _a;
19473
19552
  var normalized = String(message || '').toLowerCase();
19553
+ var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
19554
+ if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
19555
+ return identityGuardrail;
19556
+ }
19474
19557
  var patterns = [
19475
19558
  {
19476
19559
  pattern: /\b(show|share|paste|provide|dump|output)\b.*\b(code|snippet|file|function|class|script|sql)\b/i,
@@ -20339,6 +20422,10 @@ function estimateUsage(messages, responseText, model) {
20339
20422
  function evaluateGuardrails(message) {
20340
20423
  var e_56, _a;
20341
20424
  var normalized = String(message || '').toLowerCase();
20425
+ var identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(normalized);
20426
+ if (identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked) {
20427
+ return identityGuardrail;
20428
+ }
20342
20429
  var patterns = [
20343
20430
  { pattern: /\b(source\s*code|full\s*code|entire\s*code|repo\s*dump|repository|git\s*clone)\b/i, reason: 'Code access is restricted.' },
20344
20431
  { pattern: /\b(show|share|paste|provide|dump|output)\b.*\b(code|file|contents|snippet)\b/i, reason: 'Code access is restricted.' },
@@ -20368,6 +20455,34 @@ function evaluateGuardrails(message) {
20368
20455
  }
20369
20456
  return null;
20370
20457
  }
20458
+ function evaluateAssistantIdentityDisclosureGuardrail(message) {
20459
+ var normalized = String(message || '').toLowerCase();
20460
+ if (!normalized) {
20461
+ return null;
20462
+ }
20463
+ var patterns = [
20464
+ /\b(?:what|which)\s+(?:ai|model|llm)\b/i,
20465
+ /\b(?:what|which)\s+(?:model|engine|provider)\s+(?:are|is)\s+(?:you|this|it)\s+using\b/i,
20466
+ /\b(?:are\s+you|is\s+(?:this|it))\s+(?:codex|gpt|openai)\b/i,
20467
+ /\b(?:run(?:ning)?\s+locally|local(?:ly)?\s+(?:model|runtime|instance))\b/i,
20468
+ /\b(?:model|ai|assistant)\s+version\b/i,
20469
+ /\bwhat\s+version\s+are\s+you\b/i,
20470
+ /\bwhat\s+version\s+is\s+(?:this|it)\b/i,
20471
+ /\bsystem\s+prompt\b/i
20472
+ ];
20473
+ if (!patterns.some(function (pattern) { return pattern.test(normalized); })) {
20474
+ return null;
20475
+ }
20476
+ return {
20477
+ blocked: true,
20478
+ reason: 'Assistant identity/runtime details are restricted.',
20479
+ response: 'I can’t share details about the underlying AI model, provider, runtime environment, or version.'
20480
+ };
20481
+ }
20482
+ function isAssistantDebugUser(user) {
20483
+ var username = normalizeOptionalString(user === null || user === void 0 ? void 0 : user.username).toLowerCase();
20484
+ return username === 'admin';
20485
+ }
20371
20486
  function resolveIsSuperAdmin(id_user) {
20372
20487
  return __awaiter(this, void 0, void 0, function () {
20373
20488
  var user, _a;