@resolveio/server-lib 22.1.6 → 22.1.7

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.
@@ -131,7 +131,9 @@ exports.resolveAssistantAvailableCrossCollectionFallbacksFromNames = resolveAssi
131
131
  exports.collectUserViewPermissions = collectUserViewPermissions;
132
132
  exports.userHasInvoiceAccess = userHasInvoiceAccess;
133
133
  exports.resolveAssistantUserAccessTier = resolveAssistantUserAccessTier;
134
+ exports.resolveCodexThoughtLevel = resolveCodexThoughtLevel;
134
135
  exports.classifyAssistantRequestType = classifyAssistantRequestType;
136
+ exports.shouldRunAssistantPlanner = shouldRunAssistantPlanner;
135
137
  exports.collectAssistantAllowedRoutesForUser = collectAssistantAllowedRoutesForUser;
136
138
  exports.rankAssistantNavigationRoutes = rankAssistantNavigationRoutes;
137
139
  exports.shouldUseAssistantNavigationFastPath = shouldUseAssistantNavigationFastPath;
@@ -246,6 +248,9 @@ var AI_ASSISTANT_DATE_EXPANSION_SCHEMA_MAX_FIELDS = 12;
246
248
  var execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
247
249
  var AI_ASSISTANT_CHANGE_HISTORY_DEFAULT_LIMIT = 10;
248
250
  var AI_ASSISTANT_CHANGE_HISTORY_MAX_LIMIT = 40;
251
+ var AI_ASSISTANT_CHANGE_HISTORY_MIN_DEPTH = 80;
252
+ var AI_ASSISTANT_CHANGE_HISTORY_MAX_DEPTH = 240;
253
+ var AI_ASSISTANT_CHANGE_HISTORY_DURATION_MAX_DEPTH = 1200;
249
254
  var AI_ASSISTANT_GIT_COMMAND_TIMEOUT_MS = 15000;
250
255
  var AI_ASSISTANT_BLOCKED_COLLECTIONS = new Set([
251
256
  'user-groups',
@@ -1623,7 +1628,7 @@ function executeAiAssistantCodexRun(payload, context) {
1623
1628
  insertResult = _e.sent();
1624
1629
  assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
1625
1630
  enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
1626
- var runStart, steps, recordStep, progressTracker, streamProgress, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerEnabled, plannerUsed, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, _a, routeHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, shouldRunPlanner, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, cleanedResponseText, effectiveDirective, toolRequest, toolStart, toolResponse, _h, toolPayload, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload;
1631
+ var runStart, steps, recordStep, progressTracker, streamProgress, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerEnabled, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, _a, routeHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, cleanedResponseText, effectiveDirective, toolRequest, toolStart, toolResponse, _h, toolPayload, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload;
1627
1632
  var _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
1628
1633
  return __generator(this, function (_13) {
1629
1634
  switch (_13.label) {
@@ -1678,6 +1683,7 @@ function executeAiAssistantCodexRun(payload, context) {
1678
1683
  collectionNames = [];
1679
1684
  plannerEnabled = resolveAssistantPlannerEnabled();
1680
1685
  plannerUsed = false;
1686
+ plannerSkipReason = '';
1681
1687
  plannerOutput = null;
1682
1688
  plannerRaw = '';
1683
1689
  timingBreakdown = {
@@ -1713,7 +1719,7 @@ function executeAiAssistantCodexRun(payload, context) {
1713
1719
  });
1714
1720
  _13.label = 1;
1715
1721
  case 1:
1716
- _13.trys.push([1, 49, 50, 51]);
1722
+ _13.trys.push([1, 51, 52, 53]);
1717
1723
  hintSeed = [message, contextRoute].filter(Boolean).join(' ');
1718
1724
  termExpansion = expandAssistantTermSynonyms(hintSeed);
1719
1725
  hintText = termExpansion.expanded || hintSeed;
@@ -1811,7 +1817,8 @@ function executeAiAssistantCodexRun(payload, context) {
1811
1817
  skipGitRepoCheck: true,
1812
1818
  modelReasoningEffort: resolveCodexThoughtLevel({
1813
1819
  message: message,
1814
- attachmentText: attachmentData.promptText
1820
+ attachmentText: attachmentData.promptText,
1821
+ requestType: requestClassification.type
1815
1822
  }),
1816
1823
  networkAccessEnabled: false,
1817
1824
  webSearchMode: 'disabled',
@@ -1819,10 +1826,13 @@ function executeAiAssistantCodexRun(payload, context) {
1819
1826
  approvalPolicy: 'never'
1820
1827
  }
1821
1828
  };
1822
- shouldRunPlanner = plannerEnabled
1823
- && !(requestClassification.type === 'navigation' && !dataQuestion)
1824
- && !hasDeterministicHeuristicFastPath;
1825
- if (!shouldRunPlanner) return [3 /*break*/, 10];
1829
+ plannerRunOptions = __assign(__assign({}, runOptions), { threadOptions: __assign(__assign({}, (runOptions.threadOptions || {})), { modelReasoningEffort: 'minimal' }) });
1830
+ shouldRunPlanner = shouldRunAssistantPlanner({
1831
+ plannerEnabled: plannerEnabled,
1832
+ requestClassification: requestClassification,
1833
+ hasDeterministicHeuristicFastPath: hasDeterministicHeuristicFastPath
1834
+ });
1835
+ if (!shouldRunPlanner) return [3 /*break*/, 11];
1826
1836
  plannerUsed = true;
1827
1837
  recordStep('Planning: planner prompt');
1828
1838
  plannerPrompt = buildAssistantPlannerPrompt({
@@ -1839,7 +1849,7 @@ function executeAiAssistantCodexRun(payload, context) {
1839
1849
  case 7:
1840
1850
  _13.trys.push([7, 9, , 10]);
1841
1851
  plannerStart = Date.now();
1842
- return [4 /*yield*/, runCodexInWorkerThread(plannerPrompt, runOptions, codexConfig, streamProgress)];
1852
+ return [4 /*yield*/, runCodexInWorkerThread(plannerPrompt, plannerRunOptions, codexConfig, streamProgress)];
1843
1853
  case 8:
1844
1854
  plannerRaw = _13.sent();
1845
1855
  accumulateCodexUsage(plannerPrompt, plannerRaw);
@@ -1851,7 +1861,22 @@ function executeAiAssistantCodexRun(payload, context) {
1851
1861
  _b = _13.sent();
1852
1862
  recordStep('Planning: planner result', { parsed: false });
1853
1863
  return [3 /*break*/, 10];
1854
- case 10:
1864
+ case 10: return [3 /*break*/, 12];
1865
+ case 11:
1866
+ if (plannerEnabled) {
1867
+ if (hasDeterministicHeuristicFastPath) {
1868
+ plannerSkipReason = 'heuristic_directive_fast_path';
1869
+ }
1870
+ else if (!requestClassification.dataQuestion) {
1871
+ plannerSkipReason = "non_data_".concat(requestClassification.type || 'unknown');
1872
+ }
1873
+ else {
1874
+ plannerSkipReason = 'policy';
1875
+ }
1876
+ recordStep('Planning: planner skipped', { reason: plannerSkipReason });
1877
+ }
1878
+ _13.label = 12;
1879
+ case 12:
1855
1880
  requestClassification = classifyAssistantRequestType(message, plannerOutput || undefined);
1856
1881
  dataQuestion = requestClassification.dataQuestion;
1857
1882
  requestedTimeGrain = resolveAssistantRequestedTimeGrain(message, plannerOutput || undefined);
@@ -1902,15 +1927,15 @@ function executeAiAssistantCodexRun(payload, context) {
1902
1927
  timeGrain: requestedTimeGrain || undefined
1903
1928
  });
1904
1929
  }
1905
- if (!(dataQuestion && !directive)) return [3 /*break*/, 14];
1930
+ if (!(dataQuestion && !directive)) return [3 /*break*/, 16];
1906
1931
  recordStep('Directive: determine tool', { type: 'data-question' });
1907
1932
  directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode);
1908
- _13.label = 11;
1909
- case 11:
1910
- _13.trys.push([11, 13, , 14]);
1933
+ _13.label = 13;
1934
+ case 13:
1935
+ _13.trys.push([13, 15, , 16]);
1911
1936
  directiveStart = Date.now();
1912
1937
  return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, runOptions, codexConfig, streamProgress)];
1913
- case 12:
1938
+ case 14:
1914
1939
  directiveText = _13.sent();
1915
1940
  accumulateCodexUsage(directivePrompt, directiveText);
1916
1941
  timingBreakdown.directiveMs = Date.now() - directiveStart;
@@ -1927,19 +1952,19 @@ function executeAiAssistantCodexRun(payload, context) {
1927
1952
  permissionView: normalizeOptionalString((_t = directive.payload) === null || _t === void 0 ? void 0 : _t.permissionView) || undefined
1928
1953
  });
1929
1954
  }
1930
- return [3 /*break*/, 14];
1931
- case 13:
1955
+ return [3 /*break*/, 16];
1956
+ case 15:
1932
1957
  _c = _13.sent();
1933
- return [3 /*break*/, 14];
1934
- case 14:
1935
- if (!(!directive && !dataQuestion)) return [3 /*break*/, 18];
1958
+ return [3 /*break*/, 16];
1959
+ case 16:
1960
+ if (!(!directive && !dataQuestion)) return [3 /*break*/, 20];
1936
1961
  recordStep('Response: draft initial answer', { mode: 'full' });
1937
- _13.label = 15;
1938
- case 15:
1939
- _13.trys.push([15, 17, , 18]);
1962
+ _13.label = 17;
1963
+ case 17:
1964
+ _13.trys.push([17, 19, , 20]);
1940
1965
  initialStart = Date.now();
1941
1966
  return [4 /*yield*/, runCodexInWorkerThread(prompt_1, runOptions, codexConfig, streamProgress)];
1942
- case 16:
1967
+ case 18:
1943
1968
  responseText = _13.sent();
1944
1969
  accumulateCodexUsage(prompt_1, responseText);
1945
1970
  timingBreakdown.initialResponseMs = Date.now() - initialStart;
@@ -1956,23 +1981,23 @@ function executeAiAssistantCodexRun(payload, context) {
1956
1981
  permissionView: normalizeOptionalString((_w = directive.payload) === null || _w === void 0 ? void 0 : _w.permissionView) || undefined
1957
1982
  });
1958
1983
  }
1959
- return [3 /*break*/, 18];
1960
- case 17:
1984
+ return [3 /*break*/, 20];
1985
+ case 19:
1961
1986
  error_2 = _13.sent();
1962
1987
  recordStep('Response: initial draft failed', {
1963
1988
  message: normalizeOptionalString(error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || 'Unknown error'
1964
1989
  });
1965
- return [3 /*break*/, 18];
1966
- case 18:
1967
- if (!(!directive && dataQuestion)) return [3 /*break*/, 22];
1990
+ return [3 /*break*/, 20];
1991
+ case 20:
1992
+ if (!(!directive && dataQuestion)) return [3 /*break*/, 24];
1968
1993
  recordStep('Directive: forced retry', { mode: 'directive-only' });
1969
1994
  directivePrompt = buildAssistantCodexDirectivePrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, directiveStyleHint, directivePromptMode);
1970
- _13.label = 19;
1971
- case 19:
1972
- _13.trys.push([19, 21, , 22]);
1995
+ _13.label = 21;
1996
+ case 21:
1997
+ _13.trys.push([21, 23, , 24]);
1973
1998
  forcedStart = Date.now();
1974
1999
  return [4 /*yield*/, runCodexInWorkerThread(directivePrompt, runOptions, codexConfig, streamProgress)];
1975
- case 20:
2000
+ case 22:
1976
2001
  directiveText = _13.sent();
1977
2002
  accumulateCodexUsage(directivePrompt, directiveText);
1978
2003
  timingBreakdown.forcedDirectiveMs = Date.now() - forcedStart;
@@ -1989,15 +2014,15 @@ function executeAiAssistantCodexRun(payload, context) {
1989
2014
  permissionView: normalizeOptionalString((_z = directive.payload) === null || _z === void 0 ? void 0 : _z.permissionView) || undefined
1990
2015
  });
1991
2016
  }
1992
- return [3 /*break*/, 22];
1993
- case 21:
2017
+ return [3 /*break*/, 24];
2018
+ case 23:
1994
2019
  _d = _13.sent();
1995
- return [3 /*break*/, 22];
1996
- case 22:
2020
+ return [3 /*break*/, 24];
2021
+ case 24:
1997
2022
  if (!(directive
1998
2023
  && enforceDatedDirective
1999
2024
  && !isAssistantDeterministicHeuristicDirective(directive)
2000
- && !isAssistantDirectiveDated(directive))) return [3 /*break*/, 26];
2025
+ && !isAssistantDirectiveDated(directive))) return [3 /*break*/, 28];
2001
2026
  recordStep('Directive: dated retry', {
2002
2027
  currentType: directive.type,
2003
2028
  timeGrain: requestedTimeGrain || undefined
@@ -2009,12 +2034,12 @@ function executeAiAssistantCodexRun(payload, context) {
2009
2034
  requestedBreakdowns: requestedBreakdownDimensions,
2010
2035
  strict: true
2011
2036
  }), 'aggregate_only');
2012
- _13.label = 23;
2013
- case 23:
2014
- _13.trys.push([23, 25, , 26]);
2037
+ _13.label = 25;
2038
+ case 25:
2039
+ _13.trys.push([25, 27, , 28]);
2015
2040
  strictStart = Date.now();
2016
2041
  return [4 /*yield*/, runCodexInWorkerThread(strictDirectivePrompt, runOptions, codexConfig, streamProgress)];
2017
- case 24:
2042
+ case 26:
2018
2043
  strictDirectiveText = _13.sent();
2019
2044
  accumulateCodexUsage(strictDirectivePrompt, strictDirectiveText);
2020
2045
  timingBreakdown.forcedDirectiveMs += Date.now() - strictStart;
@@ -2036,15 +2061,15 @@ function executeAiAssistantCodexRun(payload, context) {
2036
2061
  timeGrain: requestedTimeGrain || undefined
2037
2062
  });
2038
2063
  }
2039
- return [3 /*break*/, 26];
2040
- case 25:
2064
+ return [3 /*break*/, 28];
2065
+ case 27:
2041
2066
  _e = _13.sent();
2042
- return [3 /*break*/, 26];
2043
- case 26:
2067
+ return [3 /*break*/, 28];
2068
+ case 28:
2044
2069
  if (!(directive
2045
2070
  && enforceDatedDirective
2046
2071
  && !isAssistantDeterministicHeuristicDirective(directive)
2047
- && directive.type === 'read')) return [3 /*break*/, 30];
2072
+ && directive.type === 'read')) return [3 /*break*/, 32];
2048
2073
  recordStep('Directive: dated guard retry', {
2049
2074
  currentType: directive.type,
2050
2075
  timeGrain: requestedTimeGrain || undefined
@@ -2056,12 +2081,12 @@ function executeAiAssistantCodexRun(payload, context) {
2056
2081
  requestedBreakdowns: requestedBreakdownDimensions,
2057
2082
  strict: true
2058
2083
  }), 'aggregate_only');
2059
- _13.label = 27;
2060
- case 27:
2061
- _13.trys.push([27, 29, , 30]);
2084
+ _13.label = 29;
2085
+ case 29:
2086
+ _13.trys.push([29, 31, , 32]);
2062
2087
  guardStart = Date.now();
2063
2088
  return [4 /*yield*/, runCodexInWorkerThread(guardDirectivePrompt, runOptions, codexConfig, streamProgress)];
2064
- case 28:
2089
+ case 30:
2065
2090
  guardDirectiveText = _13.sent();
2066
2091
  accumulateCodexUsage(guardDirectivePrompt, guardDirectiveText);
2067
2092
  timingBreakdown.forcedDirectiveMs += Date.now() - guardStart;
@@ -2081,15 +2106,15 @@ function executeAiAssistantCodexRun(payload, context) {
2081
2106
  timeGrain: requestedTimeGrain || undefined
2082
2107
  });
2083
2108
  }
2084
- return [3 /*break*/, 30];
2085
- case 29:
2109
+ return [3 /*break*/, 32];
2110
+ case 31:
2086
2111
  _f = _13.sent();
2087
- return [3 /*break*/, 30];
2088
- case 30:
2112
+ return [3 /*break*/, 32];
2113
+ case 32:
2089
2114
  if (!(directive
2090
2115
  && enforceGroupedDirective
2091
2116
  && !isAssistantDeterministicHeuristicDirective(directive)
2092
- && !isAssistantDirectiveGrouped(directive))) return [3 /*break*/, 34];
2117
+ && !isAssistantDirectiveGrouped(directive))) return [3 /*break*/, 36];
2093
2118
  recordStep('Directive: grouped guard retry', {
2094
2119
  currentType: directive.type,
2095
2120
  breakdownDimensions: requestedBreakdownDimensions.length ? requestedBreakdownDimensions : undefined
@@ -2101,12 +2126,12 @@ function executeAiAssistantCodexRun(payload, context) {
2101
2126
  requestedBreakdowns: requestedBreakdownDimensions,
2102
2127
  strict: true
2103
2128
  }), 'aggregate_only');
2104
- _13.label = 31;
2105
- case 31:
2106
- _13.trys.push([31, 33, , 34]);
2129
+ _13.label = 33;
2130
+ case 33:
2131
+ _13.trys.push([33, 35, , 36]);
2107
2132
  groupedStart = Date.now();
2108
2133
  return [4 /*yield*/, runCodexInWorkerThread(groupedDirectivePrompt, runOptions, codexConfig, streamProgress)];
2109
- case 32:
2134
+ case 34:
2110
2135
  groupedDirectiveText = _13.sent();
2111
2136
  accumulateCodexUsage(groupedDirectivePrompt, groupedDirectiveText);
2112
2137
  timingBreakdown.forcedDirectiveMs += Date.now() - groupedStart;
@@ -2129,11 +2154,11 @@ function executeAiAssistantCodexRun(payload, context) {
2129
2154
  timeGrain: requestedTimeGrain || undefined
2130
2155
  });
2131
2156
  }
2132
- return [3 /*break*/, 34];
2133
- case 33:
2157
+ return [3 /*break*/, 36];
2158
+ case 35:
2134
2159
  _g = _13.sent();
2135
- return [3 /*break*/, 34];
2136
- case 34:
2160
+ return [3 /*break*/, 36];
2161
+ case 36:
2137
2162
  if (!directive && dataQuestion) {
2138
2163
  heuristicDirective = buildAssistantHeuristicDirective(message, collectionHints);
2139
2164
  if (isAssistantExecutableDirective(heuristicDirective)) {
@@ -2172,7 +2197,7 @@ function executeAiAssistantCodexRun(payload, context) {
2172
2197
  if (cleanedResponseText) {
2173
2198
  assistantContent = sanitizeAssistantResponse(cleanedResponseText);
2174
2199
  }
2175
- if (!((directive === null || directive === void 0 ? void 0 : directive.payload) && AI_ASSISTANT_TOOL_MAX_STEPS > 0)) return [3 /*break*/, 47];
2200
+ if (!((directive === null || directive === void 0 ? void 0 : directive.payload) && AI_ASSISTANT_TOOL_MAX_STEPS > 0)) return [3 /*break*/, 49];
2176
2201
  effectiveDirective = collectionOverride
2177
2202
  ? __assign(__assign({}, directive), { payload: __assign(__assign({}, (directive.payload || {})), { collection: collectionOverride.to }) }) : directive;
2178
2203
  toolRequest = buildAssistantToolRequest(effectiveDirective, input);
@@ -2182,20 +2207,20 @@ function executeAiAssistantCodexRun(payload, context) {
2182
2207
  collection: normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.collection) || undefined,
2183
2208
  permissionView: normalizeOptionalString(toolRequest === null || toolRequest === void 0 ? void 0 : toolRequest.permissionView) || undefined
2184
2209
  });
2185
- _13.label = 35;
2186
- case 35:
2187
- _13.trys.push([35, 45, , 46]);
2210
+ _13.label = 37;
2211
+ case 37:
2212
+ _13.trys.push([37, 47, , 48]);
2188
2213
  toolStart = Date.now();
2189
- if (!(effectiveDirective.type === 'aggregate')) return [3 /*break*/, 37];
2214
+ if (!(effectiveDirective.type === 'aggregate')) return [3 /*break*/, 39];
2190
2215
  return [4 /*yield*/, executeAiAssistantReportBuilderAggregate(toolRequest, context)];
2191
- case 36:
2192
- _h = _13.sent();
2193
- return [3 /*break*/, 39];
2194
- case 37: return [4 /*yield*/, executeAiAssistantReportBuilderRead(toolRequest, context)];
2195
2216
  case 38:
2196
2217
  _h = _13.sent();
2197
- _13.label = 39;
2198
- case 39:
2218
+ return [3 /*break*/, 41];
2219
+ case 39: return [4 /*yield*/, executeAiAssistantReportBuilderRead(toolRequest, context)];
2220
+ case 40:
2221
+ _h = _13.sent();
2222
+ _13.label = 41;
2223
+ case 41:
2199
2224
  toolResponse = _h;
2200
2225
  timingBreakdown.toolMs = Date.now() - toolStart;
2201
2226
  toolResponseDebug = (toolResponse === null || toolResponse === void 0 ? void 0 : toolResponse.debug) && typeof toolResponse.debug === 'object'
@@ -2211,53 +2236,53 @@ function executeAiAssistantCodexRun(payload, context) {
2211
2236
  progressTracker.push('Drafting response');
2212
2237
  skipFollowupCodex = usedDeterministicHeuristicFastPath
2213
2238
  || isAssistantDeterministicHeuristicDirective(effectiveDirective);
2214
- if (!skipFollowupCodex) return [3 /*break*/, 40];
2239
+ if (!skipFollowupCodex) return [3 /*break*/, 42];
2215
2240
  recordStep('Drafting response: deterministic summary', {
2216
2241
  reason: normalizeOptionalString(effectiveDirective.rawLine) || 'deterministic_heuristic'
2217
2242
  });
2218
2243
  assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
2219
2244
  assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
2220
- return [3 /*break*/, 44];
2221
- case 40:
2245
+ return [3 /*break*/, 46];
2246
+ case 42:
2222
2247
  recordStep('Drafting response');
2223
2248
  followupPrompt = buildAssistantCodexToolFollowupPrompt(message, attachmentData.promptText, historyLines.join('\n'), assistantContext, toolPayload.prompt);
2224
- _13.label = 41;
2225
- case 41:
2226
- _13.trys.push([41, 43, , 44]);
2249
+ _13.label = 43;
2250
+ case 43:
2251
+ _13.trys.push([43, 45, , 46]);
2227
2252
  followupStart = Date.now();
2228
2253
  return [4 /*yield*/, runCodexInWorkerThread(followupPrompt, runOptions, codexConfig, streamProgress)];
2229
- case 42:
2254
+ case 44:
2230
2255
  followupText = _13.sent();
2231
2256
  accumulateCodexUsage(followupPrompt, followupText);
2232
2257
  timingBreakdown.followupMs = Date.now() - followupStart;
2233
2258
  assistantContent = sanitizeAssistantResponse(followupText);
2234
2259
  assistantContent = applyAssistantDisplayTableToResponse(assistantContent, toolPayload.result.output.display);
2235
- return [3 /*break*/, 44];
2236
- case 43:
2260
+ return [3 /*break*/, 46];
2261
+ case 45:
2237
2262
  _j = _13.sent();
2238
2263
  assistantContent = buildAssistantToolFallbackResponse(toolPayload.result);
2239
- return [3 /*break*/, 44];
2240
- case 44: return [3 /*break*/, 46];
2241
- case 45:
2242
- error_3 = _13.sent();
2243
- assistantContent = buildAssistantToolErrorMessage(error_3);
2244
- toolError = error_3;
2245
2264
  return [3 /*break*/, 46];
2246
2265
  case 46: return [3 /*break*/, 48];
2247
2266
  case 47:
2267
+ error_3 = _13.sent();
2268
+ assistantContent = buildAssistantToolErrorMessage(error_3);
2269
+ toolError = error_3;
2270
+ return [3 /*break*/, 48];
2271
+ case 48: return [3 /*break*/, 50];
2272
+ case 49:
2248
2273
  progressTracker.push('Drafting response');
2249
2274
  recordStep('Drafting response');
2250
- _13.label = 48;
2251
- case 48: return [3 /*break*/, 51];
2252
- case 49:
2275
+ _13.label = 50;
2276
+ case 50: return [3 /*break*/, 53];
2277
+ case 51:
2253
2278
  error_4 = _13.sent();
2254
2279
  assistantContent = buildAssistantCodexErrorMessage(error_4);
2255
2280
  recordStep('Error', { message: normalizeOptionalString(error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || 'Unknown error' });
2256
- return [3 /*break*/, 51];
2257
- case 50:
2281
+ return [3 /*break*/, 53];
2282
+ case 52:
2258
2283
  progressTracker.stop();
2259
2284
  return [7 /*endfinally*/];
2260
- case 51:
2285
+ case 53:
2261
2286
  if (!assistantContent) {
2262
2287
  assistantContent = buildAssistantCodexErrorMessage(null);
2263
2288
  }
@@ -2327,7 +2352,7 @@ function executeAiAssistantCodexRun(payload, context) {
2327
2352
  : undefined
2328
2353
  } : (plannerEnabled ? {
2329
2354
  enabled: false,
2330
- reason: 'skipped_for_navigation'
2355
+ reason: plannerSkipReason || 'skipped_by_policy'
2331
2356
  } : undefined)
2332
2357
  },
2333
2358
  timings: {
@@ -2353,14 +2378,14 @@ function executeAiAssistantCodexRun(payload, context) {
2353
2378
  output_tokens: codexUsage.output_tokens,
2354
2379
  total_tokens: codexUsage.total_tokens
2355
2380
  } : null;
2356
- if (!finalUsage) return [3 /*break*/, 56];
2381
+ if (!finalUsage) return [3 /*break*/, 58];
2357
2382
  return [4 /*yield*/, resolveClientId(conversation, input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
2358
- case 52:
2383
+ case 54:
2359
2384
  usageClientId = _13.sent();
2360
- if (!usageClientId) return [3 /*break*/, 56];
2361
- _13.label = 53;
2362
- case 53:
2363
- _13.trys.push([53, 55, , 56]);
2385
+ if (!usageClientId) return [3 /*break*/, 58];
2386
+ _13.label = 55;
2387
+ case 55:
2388
+ _13.trys.push([55, 57, , 58]);
2364
2389
  return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)({
2365
2390
  id_client: usageClientId,
2366
2391
  model: finalUsage.model,
@@ -2371,16 +2396,16 @@ function executeAiAssistantCodexRun(payload, context) {
2371
2396
  id_request: requestId || undefined,
2372
2397
  id_conversation: conversation._id
2373
2398
  })];
2374
- case 54:
2399
+ case 56:
2375
2400
  _13.sent();
2376
- return [3 /*break*/, 56];
2377
- case 55:
2401
+ return [3 /*break*/, 58];
2402
+ case 57:
2378
2403
  usageError_1 = _13.sent();
2379
2404
  console.error(new Date(), 'Failed to record codex usage', usageError_1);
2380
- return [3 /*break*/, 56];
2381
- case 56:
2405
+ return [3 /*break*/, 58];
2406
+ case 58:
2382
2407
  finalAssistantDoc = __assign(__assign(__assign(__assign({}, assistantDoc), { _id: assistantMessageId, content: assistantContent, metadata: finalMetadata }), (finalUsage ? { usage: finalUsage } : {})), { updatedAt: finalNow });
2383
- if (!assistantMessageId) return [3 /*break*/, 58];
2408
+ if (!assistantMessageId) return [3 /*break*/, 60];
2384
2409
  setPayload = {
2385
2410
  content: assistantContent,
2386
2411
  metadata: finalMetadata,
@@ -2390,18 +2415,18 @@ function executeAiAssistantCodexRun(payload, context) {
2390
2415
  setPayload.usage = finalUsage;
2391
2416
  }
2392
2417
  return [4 /*yield*/, updateAssistantMessageWithFallback(assistantMessageId, setPayload)];
2393
- case 57:
2394
- _13.sent();
2395
- _13.label = 58;
2396
- case 58: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
2397
2418
  case 59:
2398
2419
  _13.sent();
2399
- if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 61];
2420
+ _13.label = 60;
2421
+ case 60: return [4 /*yield*/, touchConversation(conversation._id, finalNow, assistantMessageId ? String(assistantMessageId) : undefined)];
2422
+ case 61:
2423
+ _13.sent();
2424
+ if (!(input.delete_files_after_run !== false)) return [3 /*break*/, 63];
2400
2425
  return [4 /*yield*/, cleanupAttachments(attachmentData.attachments)];
2401
- case 60:
2426
+ case 62:
2402
2427
  _13.sent();
2403
- _13.label = 61;
2404
- case 61: return [2 /*return*/, finalAssistantDoc];
2428
+ _13.label = 63;
2429
+ case 63: return [2 /*return*/, finalAssistantDoc];
2405
2430
  }
2406
2431
  });
2407
2432
  }); });
@@ -14000,38 +14025,6 @@ function resolveConfiguredCodexAutoThoughtLevel(kind) {
14000
14025
  || process.env["AI_DASHBOARD_CODEX_".concat(levelKey, "_THOUGHT_LEVEL")]);
14001
14026
  return configured || fallbackLevel;
14002
14027
  }
14003
- function resolveAutoCodexThoughtLevel(params) {
14004
- var combinedText = [
14005
- normalizeOptionalString(params === null || params === void 0 ? void 0 : params.message),
14006
- normalizeOptionalString(params === null || params === void 0 ? void 0 : params.attachmentText)
14007
- ].filter(Boolean).join('\n').toLowerCase();
14008
- var simpleLevel = resolveConfiguredCodexAutoThoughtLevel('simple');
14009
- var complexLevel = resolveConfiguredCodexAutoThoughtLevel('complex');
14010
- if (!combinedText) {
14011
- return simpleLevel;
14012
- }
14013
- var bugOrIssuePatterns = [
14014
- /\bbug\b/i,
14015
- /\bissue\b/i,
14016
- /\berror\b/i,
14017
- /\bexception\b/i,
14018
- /\bfail(?:ed|ing|ure)?\b/i,
14019
- /\bbroken\b/i,
14020
- /\bnot\s+working\b/i,
14021
- /\bdoesn['’]t\s+work\b/i,
14022
- /\bwhy\s+is\s+this\s+happening\b/i,
14023
- /\broot\s+cause\b/i,
14024
- /\bregression\b/i,
14025
- /\bdebug\b/i,
14026
- /\binvestigat(?:e|ion)\b/i,
14027
- /\bfix\b/i,
14028
- /\bcrash(?:ed|ing)?\b/i,
14029
- /\btimeout\b/i,
14030
- /\bwrong\b/i,
14031
- /\bincorrect\b/i
14032
- ];
14033
- return bugOrIssuePatterns.some(function (pattern) { return pattern.test(combinedText); }) ? complexLevel : simpleLevel;
14034
- }
14035
14028
  function resolveCodexThoughtLevel(params) {
14036
14029
  var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
14037
14030
  var raw = normalizeOptionalString(config['AI_ASSISTANT_CODEX_THOUGHT_LEVEL']
@@ -14042,13 +14035,17 @@ function resolveCodexThoughtLevel(params) {
14042
14035
  || process.env.AI_DASHBOARD_CODEX_THOUGHT_LEVEL);
14043
14036
  var normalized = (raw || '').trim().toLowerCase();
14044
14037
  var explicitLevel = normalizeCodexThoughtLevel(normalized);
14038
+ var isBugIssueRequest = (params === null || params === void 0 ? void 0 : params.requestType) === 'bug_issue';
14039
+ if (!isBugIssueRequest) {
14040
+ return 'medium';
14041
+ }
14045
14042
  if (explicitLevel) {
14046
14043
  return explicitLevel;
14047
14044
  }
14048
14045
  if (normalized === 'auto' || !normalized) {
14049
- return resolveAutoCodexThoughtLevel(params);
14046
+ return resolveConfiguredCodexAutoThoughtLevel('complex');
14050
14047
  }
14051
- return 'medium';
14048
+ return 'high';
14052
14049
  }
14053
14050
  function resolveCodexSettings(options) {
14054
14051
  var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
@@ -14729,6 +14726,20 @@ function classifyAssistantRequestType(message, plannerOutput) {
14729
14726
  plannerIntentType: plannerIntentRaw || undefined
14730
14727
  };
14731
14728
  }
14729
+ function shouldRunAssistantPlanner(params) {
14730
+ if (!(params === null || params === void 0 ? void 0 : params.plannerEnabled)) {
14731
+ return false;
14732
+ }
14733
+ if (params === null || params === void 0 ? void 0 : params.hasDeterministicHeuristicFastPath) {
14734
+ return false;
14735
+ }
14736
+ var requestClassification = params === null || params === void 0 ? void 0 : params.requestClassification;
14737
+ if (requestClassification === null || requestClassification === void 0 ? void 0 : requestClassification.dataQuestion) {
14738
+ return true;
14739
+ }
14740
+ var type = (requestClassification === null || requestClassification === void 0 ? void 0 : requestClassification.type) || 'unknown';
14741
+ return type === 'unknown' || type === 'mixed';
14742
+ }
14732
14743
  function resolveAssistantRequestedTimeGrain(message, plannerOutput) {
14733
14744
  var _a, _b;
14734
14745
  var plannerGrain = normalizeOptionalString((_b = (_a = plannerOutput === null || plannerOutput === void 0 ? void 0 : plannerOutput.dataPlan) === null || _a === void 0 ? void 0 : _a.timeRange) === null || _b === void 0 ? void 0 : _b.grain).toLowerCase();
@@ -15701,13 +15712,88 @@ var AI_ASSISTANT_CHANGE_HISTORY_PATTERNS = [
15701
15712
  /\bwhat\s+did\s+(?:the\s+)?last\s+(?:system\s+)?update\s+(?:just\s+)?do\b/i,
15702
15713
  /\blast\s+system\s+update\b[\s\S]{0,40}\bdo\b/i,
15703
15714
  /\bhow\s+long\b.*\bbeen\s+(this|that)\s+way\b/i,
15715
+ /\bhow\s+long\b[\s\S]{0,80}\bbeen\s+around\b/i,
15704
15716
  /\bsince\s+when\b/i,
15717
+ /\bwhen\s+was\b[\s\S]{0,80}\bintroduced\b/i,
15705
15718
  /\bchangelog\b/i,
15706
15719
  /\brelease\s+notes?\b/i,
15707
15720
  /\bgithub\b/i,
15708
15721
  /\bcommits?\b/i,
15709
15722
  /\bupdate\s+history\b/i
15710
15723
  ];
15724
+ var AI_ASSISTANT_CHANGE_HISTORY_TOKEN_STOPWORDS = new Set([
15725
+ 'the',
15726
+ 'a',
15727
+ 'an',
15728
+ 'to',
15729
+ 'for',
15730
+ 'of',
15731
+ 'in',
15732
+ 'on',
15733
+ 'at',
15734
+ 'and',
15735
+ 'or',
15736
+ 'i',
15737
+ 'me',
15738
+ 'my',
15739
+ 'we',
15740
+ 'us',
15741
+ 'you',
15742
+ 'our',
15743
+ 'is',
15744
+ 'are',
15745
+ 'do',
15746
+ 'did',
15747
+ 'does',
15748
+ 'can',
15749
+ 'could',
15750
+ 'would',
15751
+ 'should',
15752
+ 'what',
15753
+ 'when',
15754
+ 'where',
15755
+ 'which',
15756
+ 'why',
15757
+ 'how',
15758
+ 'long',
15759
+ 'has',
15760
+ 'have',
15761
+ 'had',
15762
+ 'been',
15763
+ 'this',
15764
+ 'that',
15765
+ 'these',
15766
+ 'those',
15767
+ 'it',
15768
+ 'new',
15769
+ 'changed',
15770
+ 'change',
15771
+ 'recent',
15772
+ 'recently',
15773
+ 'latest',
15774
+ 'last',
15775
+ 'time',
15776
+ 'updated',
15777
+ 'update',
15778
+ 'updates',
15779
+ 'added',
15780
+ 'around',
15781
+ 'page',
15782
+ 'screen',
15783
+ 'feature',
15784
+ 'features',
15785
+ 'history',
15786
+ 'list',
15787
+ 'dashboard',
15788
+ 'server',
15789
+ 'management',
15790
+ 'system',
15791
+ 'release',
15792
+ 'notes',
15793
+ 'github',
15794
+ 'commits',
15795
+ 'commit'
15796
+ ]);
15711
15797
  function isAssistantChangeHistoryQuestion(message) {
15712
15798
  var text = normalizeOptionalString(message).toLowerCase();
15713
15799
  if (!text) {
@@ -15739,6 +15825,13 @@ function resolveAssistantChangeHistoryLimit(message) {
15739
15825
  }
15740
15826
  return AI_ASSISTANT_CHANGE_HISTORY_DEFAULT_LIMIT;
15741
15827
  }
15828
+ function resolveAssistantChangeHistoryDepth(message, limit) {
15829
+ var normalizedLimit = Math.min(Math.max((0, common_1.round)(limit || 0), 1), AI_ASSISTANT_CHANGE_HISTORY_MAX_LIMIT);
15830
+ if (isAssistantChangeDurationQuestion(message)) {
15831
+ return Math.min(Math.max(normalizedLimit * 40, AI_ASSISTANT_CHANGE_HISTORY_MAX_DEPTH), AI_ASSISTANT_CHANGE_HISTORY_DURATION_MAX_DEPTH);
15832
+ }
15833
+ return Math.min(Math.max(normalizedLimit * 8, AI_ASSISTANT_CHANGE_HISTORY_MIN_DEPTH), AI_ASSISTANT_CHANGE_HISTORY_MAX_DEPTH);
15834
+ }
15742
15835
  function resolveAssistantChangeHistoryFetchEnabled() {
15743
15836
  var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
15744
15837
  var normalized = normalizeOptionalBoolean(config['AI_ASSISTANT_GIT_FETCH_ENABLED']
@@ -15754,6 +15847,43 @@ function shouldAssistantFetchGitRemote(message) {
15754
15847
  }
15755
15848
  return /\b(github|latest|newest|up to date|up-to-date|pull|remote)\b/i.test(text);
15756
15849
  }
15850
+ function resolveAssistantChangeHistoryKeywords(message) {
15851
+ var rawTokens = normalizeOptionalString(message)
15852
+ .toLowerCase()
15853
+ .split(/[^a-z0-9]+/g)
15854
+ .map(function (token) { return token.trim(); })
15855
+ .filter(Boolean);
15856
+ var keywords = [];
15857
+ rawTokens.forEach(function (token) {
15858
+ normalizeCollectionToken(token).forEach(function (normalized) {
15859
+ if (!normalized || normalized.length < 4 || AI_ASSISTANT_CHANGE_HISTORY_TOKEN_STOPWORDS.has(normalized)) {
15860
+ return;
15861
+ }
15862
+ keywords.push(normalized);
15863
+ });
15864
+ });
15865
+ return Array.from(new Set(keywords));
15866
+ }
15867
+ function scoreAssistantChangeHistoryCommitByKeywords(commit, keywords) {
15868
+ if (!Array.isArray(keywords) || !keywords.length) {
15869
+ return 0;
15870
+ }
15871
+ var subject = normalizeOptionalString(commit === null || commit === void 0 ? void 0 : commit.subject).toLowerCase();
15872
+ var files = Array.isArray(commit === null || commit === void 0 ? void 0 : commit.files)
15873
+ ? commit.files.map(function (file) { return normalizeOptionalString(file).toLowerCase(); }).filter(Boolean).join(' ')
15874
+ : '';
15875
+ var haystack = "".concat(subject, " ").concat(files).trim();
15876
+ if (!haystack) {
15877
+ return 0;
15878
+ }
15879
+ var score = 0;
15880
+ keywords.forEach(function (keyword) {
15881
+ if (keyword && haystack.includes(keyword)) {
15882
+ score += keyword.length >= 8 ? 2 : 1;
15883
+ }
15884
+ });
15885
+ return score;
15886
+ }
15757
15887
  function resolveAssistantChangeModulesFromText(message) {
15758
15888
  var text = normalizeOptionalString(message).toLowerCase();
15759
15889
  if (!text) {
@@ -16058,9 +16188,22 @@ function buildAssistantChangeHistorySummaryFromCommits(params) {
16058
16188
  }
16059
16189
  return __assign({ response: lines_3.join('\n'), reason: 'generic', commitCount: 0, generic: true }, (branch ? { branch: branch } : {}));
16060
16190
  }
16061
- var themes = summarizeAssistantChangeThemes(permittedCommits);
16191
+ var featureKeywords = resolveAssistantChangeHistoryKeywords(message);
16192
+ var keywordScopedCommits = featureKeywords.length
16193
+ ? permittedCommits
16194
+ .map(function (commit, index) { return ({
16195
+ commit: commit,
16196
+ index: index,
16197
+ score: scoreAssistantChangeHistoryCommitByKeywords(commit, featureKeywords)
16198
+ }); })
16199
+ .filter(function (entry) { return entry.score > 0; })
16200
+ .sort(function (a, b) { return (b.score - a.score) || (a.index - b.index); })
16201
+ .map(function (entry) { return entry.commit; })
16202
+ : [];
16203
+ var relevantCommits = keywordScopedCommits.length ? keywordScopedCommits : permittedCommits;
16204
+ var themes = summarizeAssistantChangeThemes(relevantCommits);
16062
16205
  var limit = resolveAssistantChangeHistoryLimit(message);
16063
- var topCommits = permittedCommits.slice(0, Math.max(limit, 1));
16206
+ var topCommits = relevantCommits.slice(0, Math.max(limit, 1));
16064
16207
  var lines = [title];
16065
16208
  if (themes.length) {
16066
16209
  lines.push("- Themes: ".concat(themes.join(', '), "."));
@@ -16070,7 +16213,10 @@ function buildAssistantChangeHistorySummaryFromCommits(params) {
16070
16213
  lines.push("- ".concat(dateText, ": ").concat(sanitizeAssistantChangeSubject(commit.subject), "."));
16071
16214
  });
16072
16215
  if (asksDuration) {
16073
- var datedCommits = permittedCommits
16216
+ if (featureKeywords.length && !keywordScopedCommits.length) {
16217
+ lines.push('- I could not find exact feature-term matches in recent commits, so this estimate uses the closest available history.');
16218
+ }
16219
+ var datedCommits = relevantCommits
16074
16220
  .map(function (commit) { return ({ commit: commit, date: new Date(commit.date) }); })
16075
16221
  .filter(function (entry) { return !Number.isNaN(entry.date.getTime()); });
16076
16222
  if (datedCommits.length) {
@@ -16159,7 +16305,7 @@ function resolveAssistantChangeHistoryFastPathResponse(params) {
16159
16305
  return [3 /*break*/, 14];
16160
16306
  case 14:
16161
16307
  limit = resolveAssistantChangeHistoryLimit(params.message);
16162
- historyDepth = Math.min(Math.max(limit * 8, 80), 240);
16308
+ historyDepth = resolveAssistantChangeHistoryDepth(params.message, limit);
16163
16309
  return [4 /*yield*/, runAssistantGitCommand(gitRoot, [
16164
16310
  'log',
16165
16311
  '-n',