terminal-smart-cli 0.97.18 → 0.97.19

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.
Files changed (2) hide show
  1. package/lib/agent.js +16 -4
  2. package/package.json +1 -1
package/lib/agent.js CHANGED
@@ -131,6 +131,11 @@ function missionTimeCap(requested, maxIter) {
131
131
  return Math.max(DEFAULT_MISSION_TIME_MS, Math.min(scaled, 3600000));
132
132
  }
133
133
 
134
+ function modelCallWindow({ maxDurationMs, elapsedMs, capMs = 60000, minMs = 10000 } = {}) {
135
+ const remaining = Math.max(0, Number(maxDurationMs) - Number(elapsedMs));
136
+ return remaining < minMs ? 0 : Math.min(Number(capMs) || 60000, remaining);
137
+ }
138
+
134
139
  function inspectionGateDecision({ actionExpected = false, hasMutation = false, calls = 0, warnAt = 6, max = 8 } = {}) {
135
140
  if (!actionExpected || hasMutation) return 'ok';
136
141
  if (calls > max) return 'block';
@@ -945,11 +950,16 @@ async function run(task, opts = {}) {
945
950
 
946
951
  async function _callMainModel(extra = {}) {
947
952
  for (;;) {
953
+ const signalMs = modelCallWindow({ maxDurationMs, elapsedMs:Date.now() - missionStartedAt });
954
+ if (!signalMs) {
955
+ guardStopped = { kind:'time', elapsedMs:Date.now() - missionStartedAt, maxMs:maxDurationMs };
956
+ return { msg:{ content:'' }, usage:{}, model:selectedModel, billing:null };
957
+ }
948
958
  try {
949
959
  return await llm({
950
960
  baseUrl: k.baseUrl, key: k.key, messages, model: selectedModel,
951
961
  toolsOverride: mainTools, creditBudget: Math.max(1, maxCredits - charged - _visionCredits),
952
- tries: 2, ...extra,
962
+ ...extra, signalMs, tries: 1,
953
963
  });
954
964
  } catch (e) {
955
965
  const next = _modelChain[_modelIndex + 1];
@@ -979,10 +989,12 @@ async function run(task, opts = {}) {
979
989
  const candidates = (model || k.source === 'byok') ? [selectedModel] : [...contract.candidates];
980
990
  let last = null;
981
991
  for (const roleModel of candidates) {
992
+ const signalMs = modelCallWindow({ maxDurationMs, elapsedMs:Date.now() - missionStartedAt });
993
+ if (!signalMs) break;
982
994
  try {
983
995
  onStep({ name: 'agente_' + role, detail: roleModel });
984
- const r = await llm({ baseUrl: k.baseUrl, key: k.key, model: roleModel, noTools: true, signalMs: 90000,
985
- creditBudget: Math.max(1, maxCredits - charged - _visionCredits), tries: 2,
996
+ const r = await llm({ baseUrl: k.baseUrl, key: k.key, model: roleModel, noTools: true, signalMs,
997
+ creditBudget: Math.max(1, maxCredits - charged - _visionCredits), tries: 1,
986
998
  messages: [{ role: 'system', content: contract.prompt + '\n' + system }, { role: 'user', content: user }] });
987
999
  const u = r.usage || {};
988
1000
  acc.inTok += u.prompt_tokens || 0; acc.outTok += u.completion_tokens || 0;
@@ -1779,4 +1791,4 @@ async function run(task, opts = {}) {
1779
1791
  return { text: finalText, steps, credits: charged + _visionCredits, tokens: acc, model: usedModel, actions, messages, cwd, context: lastCtx, toolErrors: _toolErrs, lastToolError: _lastErr, guard: guardStopped, completion, verification: verifyReport, orchestration: { plan: _planDecision, roles: _roleTrace, inspections: _inspectionTrace }, missionCache: _missionCache.stats() };
1780
1792
  }
1781
1793
 
1782
- module.exports = { run, llm, _test: { systemPrompt, projectBrief, inspectionGateDecision, isInspectionCommand, parseStageJson, materialDecisionPreflight, actionExpectedForTask, shouldRunPlanner, commandRecoveryHint, mutationBatchConflicts, normalizePlannerDecision, normalizeInspectorDecision, winFor, estMsgsTok, COMPACT_AT, KEEP_TAIL, loopSig, isCycle, loopDecision, decideApproval, failureFingerprint, missionGuardDecision, missionBudgetSuggestion, missionTokenCap, missionTimeCap, executorFallbackChain, isTransientModelError, completionGateDecision, canCloseFromProofs, taskScopedToolDefs, validarModeloByok, scopeToolDefs, parseTextToolCalls } };
1794
+ module.exports = { run, llm, _test: { systemPrompt, projectBrief, inspectionGateDecision, isInspectionCommand, parseStageJson, materialDecisionPreflight, actionExpectedForTask, shouldRunPlanner, commandRecoveryHint, mutationBatchConflicts, normalizePlannerDecision, normalizeInspectorDecision, winFor, estMsgsTok, COMPACT_AT, KEEP_TAIL, loopSig, isCycle, loopDecision, decideApproval, failureFingerprint, missionGuardDecision, missionBudgetSuggestion, missionTokenCap, missionTimeCap, modelCallWindow, executorFallbackChain, isTransientModelError, completionGateDecision, canCloseFromProofs, taskScopedToolDefs, validarModeloByok, scopeToolDefs, parseTextToolCalls } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terminal-smart-cli",
3
- "version": "0.97.18",
3
+ "version": "0.97.19",
4
4
  "description": "Terminal Smart no seu terminal — pergunte, analise logs por pipe e orquestre agentes de IA. Comando: ts",
5
5
  "bin": {
6
6
  "ts": "bin/ts.js"