@caupulican/pi-adaptative 0.80.80 → 0.80.82

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 (72) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/core/agent-session.d.ts +15 -14
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +202 -9
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/cost/daily-usage.d.ts +23 -0
  7. package/dist/core/cost/daily-usage.d.ts.map +1 -0
  8. package/dist/core/cost/daily-usage.js +135 -0
  9. package/dist/core/cost/daily-usage.js.map +1 -0
  10. package/dist/core/model-router/config-diagnostics.d.ts +4 -0
  11. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -0
  12. package/dist/core/model-router/config-diagnostics.js +26 -0
  13. package/dist/core/model-router/config-diagnostics.js.map +1 -0
  14. package/dist/core/model-router/intent-classifier.d.ts +3 -0
  15. package/dist/core/model-router/intent-classifier.d.ts.map +1 -0
  16. package/dist/core/model-router/intent-classifier.js +12 -0
  17. package/dist/core/model-router/intent-classifier.js.map +1 -0
  18. package/dist/core/model-router/session-buffer.d.ts +21 -0
  19. package/dist/core/model-router/session-buffer.d.ts.map +1 -0
  20. package/dist/core/model-router/session-buffer.js +20 -0
  21. package/dist/core/model-router/session-buffer.js.map +1 -0
  22. package/dist/core/model-router/status.d.ts +18 -0
  23. package/dist/core/model-router/status.d.ts.map +1 -0
  24. package/dist/core/model-router/status.js +67 -0
  25. package/dist/core/model-router/status.js.map +1 -0
  26. package/dist/core/model-router/tool-escalation.d.ts +9 -0
  27. package/dist/core/model-router/tool-escalation.d.ts.map +1 -0
  28. package/dist/core/model-router/tool-escalation.js +97 -0
  29. package/dist/core/model-router/tool-escalation.js.map +1 -0
  30. package/dist/core/profile-registry.d.ts +2 -1
  31. package/dist/core/profile-registry.d.ts.map +1 -1
  32. package/dist/core/profile-registry.js +15 -0
  33. package/dist/core/profile-registry.js.map +1 -1
  34. package/dist/core/resource-profile-equality.d.ts +5 -0
  35. package/dist/core/resource-profile-equality.d.ts.map +1 -0
  36. package/dist/core/resource-profile-equality.js +18 -0
  37. package/dist/core/resource-profile-equality.js.map +1 -0
  38. package/dist/core/settings-manager.d.ts +16 -0
  39. package/dist/core/settings-manager.d.ts.map +1 -1
  40. package/dist/core/settings-manager.js +74 -0
  41. package/dist/core/settings-manager.js.map +1 -1
  42. package/dist/core/slash-commands.d.ts.map +1 -1
  43. package/dist/core/slash-commands.js +2 -0
  44. package/dist/core/slash-commands.js.map +1 -1
  45. package/dist/main.d.ts.map +1 -1
  46. package/dist/main.js +5 -0
  47. package/dist/main.js.map +1 -1
  48. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  49. package/dist/modes/interactive/components/config-selector.js +3 -3
  50. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  51. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  52. package/dist/modes/interactive/components/footer.js +6 -1
  53. package/dist/modes/interactive/components/footer.js.map +1 -1
  54. package/dist/modes/interactive/components/settings-selector.d.ts +4 -1
  55. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  56. package/dist/modes/interactive/components/settings-selector.js +102 -0
  57. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  58. package/dist/modes/interactive/interactive-mode.d.ts +2 -0
  59. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  60. package/dist/modes/interactive/interactive-mode.js +96 -15
  61. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  62. package/docs/resources.md +7 -1
  63. package/docs/settings.md +24 -2
  64. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  65. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  66. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  67. package/examples/extensions/sandbox/package-lock.json +2 -2
  68. package/examples/extensions/sandbox/package.json +1 -1
  69. package/examples/extensions/with-deps/package-lock.json +2 -2
  70. package/examples/extensions/with-deps/package.json +1 -1
  71. package/npm-shrinkwrap.json +12 -12
  72. package/package.json +4 -4
@@ -22,6 +22,7 @@ import { cliProviderAliases, defaultModelPerProvider, findExactModelReferenceMat
22
22
  import { DefaultPackageManager } from "../../core/package-manager.js";
23
23
  import { BUILT_IN_PROVIDER_DISPLAY_NAMES } from "../../core/provider-display-names.js";
24
24
  import { getPendingReloadBlockers } from "../../core/reload-blockers.js";
25
+ import { resourceProfileSettingsChangedKinds } from "../../core/resource-profile-equality.js";
25
26
  import { formatMissingSessionCwdPrompt, MissingSessionCwdError } from "../../core/session-cwd.js";
26
27
  import { isAutoLearnSessionId, SessionManager } from "../../core/session-manager.js";
27
28
  import { validateSkillName } from "../../core/skills.js";
@@ -2415,6 +2416,11 @@ export class InteractiveMode {
2415
2416
  text = text.trim();
2416
2417
  if (!text)
2417
2418
  return;
2419
+ if (text === "/quit" || text === "/exit") {
2420
+ this.editor.setText("");
2421
+ await this.shutdown();
2422
+ return;
2423
+ }
2418
2424
  // A ">>" prefix queues the message as a follow-up (delivered after the
2419
2425
  // current work finishes, starting the next round) instead of steering.
2420
2426
  // This is the chord-free alternative to app.message.followUp, which many
@@ -2509,6 +2515,11 @@ export class InteractiveMode {
2509
2515
  this.editor.setText("");
2510
2516
  return;
2511
2517
  }
2518
+ if (text === "/usage" || text === "/cost") {
2519
+ this.handleUsageCommand();
2520
+ this.editor.setText("");
2521
+ return;
2522
+ }
2512
2523
  if (text === "/changelog") {
2513
2524
  this.handleChangelogCommand();
2514
2525
  this.editor.setText("");
@@ -2609,11 +2620,6 @@ export class InteractiveMode {
2609
2620
  this.editor.setText("");
2610
2621
  return;
2611
2622
  }
2612
- if (text === "/quit") {
2613
- this.editor.setText("");
2614
- await this.shutdown();
2615
- return;
2616
- }
2617
2623
  // Handle bash command (! for normal, !! for excluded from context)
2618
2624
  if (text.startsWith("!")) {
2619
2625
  const isExcluded = text.startsWith("!!");
@@ -4253,6 +4259,9 @@ export class InteractiveMode {
4253
4259
  thinkingLevel: settings.thinkingLevel ?? preset.thinkingLevel,
4254
4260
  };
4255
4261
  }
4262
+ getCurrentAutoLearnSettings() {
4263
+ return this.getEffectiveAutoLearnSettings();
4264
+ }
4256
4265
  getAutoLearnTenantKey() {
4257
4266
  return `${this.sessionManager.getCwd()}::${this.session.sessionId}`;
4258
4267
  }
@@ -5140,6 +5149,8 @@ export class InteractiveMode {
5140
5149
  selfModificationScope: projectSettings.selfModification ? "project" : "global",
5141
5150
  autonomy: this.settingsManager.getAutonomySettings(),
5142
5151
  autonomyScope: projectSettings.autonomy ? "project" : "global",
5152
+ modelRouter: this.settingsManager.getModelRouterSettings(),
5153
+ modelRouterScope: projectSettings.modelRouter ? "project" : "global",
5143
5154
  autoLearn: this.settingsManager.getAutoLearnSettings(),
5144
5155
  autoLearnScope: projectSettings.autoLearn ? "project" : "global",
5145
5156
  autoLearnModelOptions: this.getAutoLearnModelOptions(),
@@ -5283,6 +5294,17 @@ export class InteractiveMode {
5283
5294
  this.applyAutonomyMode(settings.mode ?? "off", scope);
5284
5295
  this.showStatus(`Autonomy mode ${settings.mode ?? "off"} saved to ${scope}. Use /autonomy status.`);
5285
5296
  },
5297
+ onModelRouterChange: (settings, scope) => {
5298
+ this.settingsManager.setModelRouterSettings(settings, scope);
5299
+ for (const value of [settings.cheapModel, settings.expensiveModel, settings.learningModel]) {
5300
+ const validationMessage = this.validateAutoLearnModelValue(value);
5301
+ if (validationMessage) {
5302
+ this.showWarning(validationMessage.replace("Auto Learn model", "Model router model"));
5303
+ }
5304
+ }
5305
+ this.updateAutoLearnFooter();
5306
+ this.showStatus(`Model Router settings saved to ${scope}. Use /session or /usage to inspect routing.`);
5307
+ },
5286
5308
  onAutoLearnChange: (settings, scope) => {
5287
5309
  this.settingsManager.setAutoLearnSettings(settings, scope);
5288
5310
  const validationMessage = this.validateAutoLearnModelValue(settings.model);
@@ -5706,18 +5728,16 @@ export class InteractiveMode {
5706
5728
  }, currentScope);
5707
5729
  this.showStatus(`Saved profile "${profileName}" to ${currentScope}.`);
5708
5730
  if (isActiveProfile) {
5709
- const extensionsChanged = originalResources.extensions !== resources.extensions;
5710
- const otherResourcesChanged = originalResources.tools !== resources.tools ||
5711
- originalResources.skills !== resources.skills ||
5712
- originalResources.agents !== resources.agents ||
5713
- originalResources.prompts !== resources.prompts ||
5714
- originalResources.themes !== resources.themes;
5715
- if (extensionsChanged && !otherResourcesChanged) {
5731
+ const changedKinds = resourceProfileSettingsChangedKinds(originalResources, resources);
5732
+ if (changedKinds.size === 1 && changedKinds.has("extensions")) {
5716
5733
  void this.reconcileExtensionsAndRefreshUI(profileName);
5717
5734
  }
5718
- else {
5735
+ else if (changedKinds.size > 0) {
5719
5736
  void this.refreshAfterProfileMutation(profileName);
5720
5737
  }
5738
+ else {
5739
+ this.ui.requestRender();
5740
+ }
5721
5741
  }
5722
5742
  }
5723
5743
  catch (error) {
@@ -7257,10 +7277,71 @@ export class InteractiveMode {
7257
7277
  info += `${theme.fg("dim", "Cache Write:")} ${stats.tokens.cacheWrite.toLocaleString()}\n`;
7258
7278
  }
7259
7279
  info += `${theme.fg("dim", "Total:")} ${stats.tokens.total.toLocaleString()}\n`;
7260
- if (stats.cost > 0) {
7280
+ const dailyUsage = this.session.getDailyUsageTotals();
7281
+ if (stats.cost > 0 || dailyUsage.totalCost > 0) {
7261
7282
  info += `\n${theme.bold("Cost")}\n`;
7262
- info += `${theme.fg("dim", "Total:")} ${stats.cost.toFixed(4)}`;
7283
+ info += `${theme.fg("dim", "Total:")} $${stats.cost.toFixed(4)}\n`;
7284
+ info += `${this.session.getDailyUsageBreakdown((label) => theme.fg("dim", label))}`;
7263
7285
  }
7286
+ info += `\n\n${theme.bold("Model Router")}\n`;
7287
+ info += this.session.getModelRouterStatus((label) => theme.fg("dim", label));
7288
+ this.chatContainer.addChild(new Spacer(1));
7289
+ this.chatContainer.addChild(new Text(info, 1, 0));
7290
+ this.ui.requestRender();
7291
+ }
7292
+ handleUsageCommand() {
7293
+ const stats = this.session.getSessionStats();
7294
+ const spawned = this.session.getSpawnedUsage();
7295
+ const daily = this.session.getDailyUsageTotals();
7296
+ const context = this.session.getContextUsage();
7297
+ const autoLearn = this.getCurrentAutoLearnSettings();
7298
+ const costGuard = this.session.getLastCostGuardDecision();
7299
+ let info = `${theme.bold("Usage & Optimization")}\n\n`;
7300
+ info += `${theme.bold("Session tokens")}\n`;
7301
+ info += `${theme.fg("dim", "Input:")} ${stats.tokens.input.toLocaleString()}\n`;
7302
+ info += `${theme.fg("dim", "Output:")} ${stats.tokens.output.toLocaleString()}\n`;
7303
+ info += `${theme.fg("dim", "Cache read:")} ${stats.tokens.cacheRead.toLocaleString()}\n`;
7304
+ info += `${theme.fg("dim", "Cache write:")} ${stats.tokens.cacheWrite.toLocaleString()}\n`;
7305
+ info += `${theme.fg("dim", "Total:")} ${stats.tokens.total.toLocaleString()}\n\n`;
7306
+ info += `${theme.bold("Cost")}\n`;
7307
+ info += `${theme.fg("dim", "Session:")} $${stats.cost.toFixed(4)}\n`;
7308
+ info += `${theme.fg("dim", "Spawned/background:")} $${spawned.cost.toFixed(4)} (${spawned.reports} reports)\n`;
7309
+ info += `${theme.fg("dim", "Today:")} $${daily.totalCost.toFixed(4)}\n`;
7310
+ info += `${theme.fg("dim", "Today own:")} $${daily.ownCost.toFixed(4)}\n`;
7311
+ info += `${theme.fg("dim", "Today spawned/background:")} $${daily.spawnedCost.toFixed(4)}\n`;
7312
+ info += `${theme.fg("dim", "Today tokens:")} ${daily.totalTokens.toLocaleString()}\n\n`;
7313
+ info += `${theme.bold("Optimization state")}\n`;
7314
+ const contextPercent = context?.percent;
7315
+ const contextTokens = context?.tokens;
7316
+ if (context &&
7317
+ contextPercent !== undefined &&
7318
+ contextPercent !== null &&
7319
+ contextTokens !== undefined &&
7320
+ contextTokens !== null) {
7321
+ info += `${theme.fg("dim", "Context:")} ${contextPercent.toFixed(1)}% (${contextTokens.toLocaleString()}/${context.contextWindow.toLocaleString()})\n`;
7322
+ }
7323
+ else {
7324
+ info += `${theme.fg("dim", "Context:")} unknown until next provider usage sample\n`;
7325
+ }
7326
+ info += `${theme.fg("dim", "Auto-compaction:")} ${this.session.autoCompactionEnabled ? "enabled" : "disabled"}\n`;
7327
+ if (costGuard) {
7328
+ const status = costGuard.over ? "over" : "ok";
7329
+ info += `${theme.fg("dim", "Cost guard:")} ${status} $${costGuard.estUsd.toFixed(4)}/$${costGuard.thresholdUsd.toFixed(4)} (${costGuard.action})\n`;
7330
+ }
7331
+ else {
7332
+ info += `${theme.fg("dim", "Cost guard:")} disabled\n`;
7333
+ }
7334
+ info += `${theme.fg("dim", "Auto Learn:")} ${autoLearn.enabled ? "enabled" : "disabled"}\n`;
7335
+ info += `${theme.fg("dim", "Scavenger model:")} ${autoLearn.model || "active"}\n`;
7336
+ info += `${theme.fg("dim", "Reflection review:")} ${autoLearn.reflectionReview ? "enabled" : "disabled"} (${autoLearn.reflectionMinToolCalls} tool-call trigger)\n`;
7337
+ info += `${theme.fg("dim", "Auto Learn concurrency:")} ${autoLearn.maxConcurrentLearners} learner(s), ${autoLearn.cooldownMinutes}m cooldown\n\n`;
7338
+ info += `${theme.bold("Model Router")}\n`;
7339
+ info += `${this.session.getModelRouterStatus((label) => theme.fg("dim", label))}\n\n`;
7340
+ info += `${theme.bold("Manual controls")}\n`;
7341
+ info += `${theme.fg("dim", "/compact")}: compact the active context now\n`;
7342
+ info += `${theme.fg("dim", "/settings")}: adjust Auto Learn, cost guard, compaction, and model-router config\n`;
7343
+ info += `${theme.fg("dim", "/auto-learn status|run")}: inspect or launch background learning\n`;
7344
+ info += `${theme.fg("dim", "context_audit")}: ask the agent to inspect provider-visible context contributors\n`;
7264
7345
  this.chatContainer.addChild(new Spacer(1));
7265
7346
  this.chatContainer.addChild(new Text(info, 1, 0));
7266
7347
  this.ui.requestRender();