@pentoshi/clai 3.8.19 → 3.8.20

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 (59) hide show
  1. package/dist/agent/compaction-summary.d.ts +1 -1
  2. package/dist/agent/compaction-summary.js +3 -2
  3. package/dist/agent/compaction-summary.js.map +1 -1
  4. package/dist/agent/context-manager.d.ts +29 -2
  5. package/dist/agent/context-manager.js +125 -17
  6. package/dist/agent/context-manager.js.map +1 -1
  7. package/dist/agent/continue-orient.d.ts +39 -0
  8. package/dist/agent/continue-orient.js +152 -0
  9. package/dist/agent/continue-orient.js.map +1 -0
  10. package/dist/agent/runner.js +46 -6
  11. package/dist/agent/runner.js.map +1 -1
  12. package/dist/agent/session-state.d.ts +2 -0
  13. package/dist/agent/session-state.js +9 -3
  14. package/dist/agent/session-state.js.map +1 -1
  15. package/dist/agent/stop-summary.d.ts +2 -2
  16. package/dist/agent/stop-summary.js +23 -4
  17. package/dist/agent/stop-summary.js.map +1 -1
  18. package/dist/agent/tool-output-formatting.js +8 -4
  19. package/dist/agent/tool-output-formatting.js.map +1 -1
  20. package/dist/app/controllers/session-compact-helper.d.ts +2 -0
  21. package/dist/app/controllers/session-compact-helper.js +14 -5
  22. package/dist/app/controllers/session-compact-helper.js.map +1 -1
  23. package/dist/app/controllers/session-controller.js +6 -1
  24. package/dist/app/controllers/session-controller.js.map +1 -1
  25. package/dist/llm/http.js +22 -12
  26. package/dist/llm/http.js.map +1 -1
  27. package/dist/prompts/embedded.js +1 -1
  28. package/dist/prompts/embedded.js.map +1 -1
  29. package/dist/prompts/system.agent.md +3 -2
  30. package/dist/tools/definitions.js +9 -2
  31. package/dist/tools/definitions.js.map +1 -1
  32. package/dist/tools/http.d.ts +2 -0
  33. package/dist/tools/http.js +208 -57
  34. package/dist/tools/http.js.map +1 -1
  35. package/dist/tools/registry.js +1 -0
  36. package/dist/tools/registry.js.map +1 -1
  37. package/dist/tui-v2/app/App.js +39 -1
  38. package/dist/tui-v2/app/App.js.map +1 -1
  39. package/dist/tui-v2/app/commands/picker-commands.js +7 -7
  40. package/dist/tui-v2/app/commands/picker-commands.js.map +1 -1
  41. package/dist/tui-v2/bootstrap/start-tui-v2.js +10 -4
  42. package/dist/tui-v2/bootstrap/start-tui-v2.js.map +1 -1
  43. package/dist/tui-v2/components/modal/secret-modal.d.ts +3 -1
  44. package/dist/tui-v2/components/modal/secret-modal.js +110 -18
  45. package/dist/tui-v2/components/modal/secret-modal.js.map +1 -1
  46. package/dist/tui-v2/components/toast/toast-anim.d.ts +5 -4
  47. package/dist/tui-v2/components/toast/toast-anim.js +10 -7
  48. package/dist/tui-v2/components/toast/toast-anim.js.map +1 -1
  49. package/dist/tui-v2/components/toast/toast-host.d.ts +9 -3
  50. package/dist/tui-v2/components/toast/toast-host.js +124 -26
  51. package/dist/tui-v2/components/toast/toast-host.js.map +1 -1
  52. package/dist/tui-v2/controllers/overlay-controller.d.ts +6 -0
  53. package/dist/tui-v2/controllers/overlay-controller.js +25 -0
  54. package/dist/tui-v2/controllers/overlay-controller.js.map +1 -1
  55. package/dist/tui-v2/state/transcript-reducer.js +70 -30
  56. package/dist/tui-v2/state/transcript-reducer.js.map +1 -1
  57. package/dist/version.generated.d.ts +2 -2
  58. package/dist/version.generated.js +2 -2
  59. package/package.json +1 -1
@@ -14,7 +14,7 @@ import { availableToolNames, normalizeToolCall, runToolCall, BATCH_SAFE_TOOLS, }
14
14
  import { getToolDefinitions, getCompactToolDefinitions, PLAN_TOOL_NAMES, } from "../tools/definitions.js";
15
15
  import { appendAssistantWithTools, appendToolResult, assertValidToolProtocol, fillMissingToolResults, } from "./tool-history.js";
16
16
  import { formatViewportHint, registerViewport } from "../ui/output-pane.js";
17
- import { compactMessagesWithSummary, estimateMessagesTokens, AUTO_COMPACT_TOKEN_BUDGET, COMPACTION_MEMORY_PREFIX, PLAN_IMPLEMENT_MEMORY_PREFIX, isCompactionMemoryMessage, } from "./context-manager.js";
17
+ import { compactMessagesWithSummary, estimateMessagesTokens, AUTO_COMPACT_TOKEN_BUDGET, shouldApplyAutoCompact, COMPACTION_MEMORY_PREFIX, PLAN_IMPLEMENT_MEMORY_PREFIX, isCompactionMemoryMessage, } from "./context-manager.js";
18
18
  import { auditLog } from "../store/logs.js";
19
19
  import { loadProjectContext } from "../store/project.js";
20
20
  import { loadScope, isScopeActive } from "../store/scope.js";
@@ -37,6 +37,7 @@ import { saveToolOutput, summarizeOutput, formatToolContext, } from "./tool-outp
37
37
  import { renderPlanForTerminal, planContextMessage, handlePlanTool, resolvePlanTaskId, } from "./plan-tool.js";
38
38
  import { absorbLooseWorkIntoLedger, applyDestinationCwd, canMarkTaskDone, hasLocalRuntimeProof, hasRemoteWorkProof, isDevServerCall, isEvidenceWorkTool, isFeatureImplementationCall, isPackageInstallCommand, isPlanPreflightTool, isPortListeningOutput, isReadOnlyReconTool, isRemoteActiveTestCall, isRemoteObservationTask, isRemoteReconToolCall, isRuntimeObservationTask, isScaffoldCreateCommand, isServerReadyOutput, ledgerFromTaskEvidence, pickPendingTaskForToolCall, recordTaskWorkSuccess, resolveUserDestinationHint, taskEvidenceFromLedger, TOOL_ABORT_GRACE_MS, toolHardBudgetMs, toolStallBudgetMs, userAskedForFeatureApp, } from "./task-evidence.js";
39
39
  import { buildSessionStateBlock, inferNextHint, upsertSessionStateMessage, } from "./session-state.js";
40
+ import { buildContinueOrientation } from "./continue-orient.js";
40
41
  import { detectPackageManager } from "./workspace-orient.js";
41
42
  import { budgetRemaining, consumeBudget, createRecoveryBudgets, freestyleClaimsAppReady, looksLikeShallowPentestReport, recoveryForErrorDiagnosis, recoveryForFailedProbe, recoveryForFreshness, recoveryForMissingFeature, recoveryForMissingPlan, recoveryForNarration, recoveryForPrematureComplete, recoveryForRuntimeVerify, recoveryForShallowPentest, } from "./must-continue.js";
42
43
  import { scopeContextMessage } from "./scope-context.js";
@@ -380,6 +381,22 @@ export async function runAgentTurn(prompt, options = {}) {
380
381
  if (activePlan) {
381
382
  systemSections.push(planContextMessage(activePlan, session.planApproved.value));
382
383
  }
384
+ // Soft mid-work recovery (any domain): re-attach to jobs / open tasks /
385
+ // last tools after interrupt or "continue" — not a hard gate.
386
+ if (!informationalQuery && !idleOrSocialPrompt) {
387
+ const continueBrief = buildContinueOrientation({
388
+ prompt,
389
+ history: options.history,
390
+ plan: activePlan,
391
+ runningJobs: jobManager.getRunningJobs(),
392
+ recentJobs: jobManager.getRecentJobs(12),
393
+ informationalQuery,
394
+ idleOrSocial: idleOrSocialPrompt,
395
+ });
396
+ if (continueBrief) {
397
+ systemSections.push(continueBrief);
398
+ }
399
+ }
383
400
  if (isPlanMode) {
384
401
  systemSections.push(planModeDirective());
385
402
  }
@@ -699,9 +716,14 @@ export async function runAgentTurn(prompt, options = {}) {
699
716
  refreshSessionState = (plan) => {
700
717
  if (idleOrSocialPrompt || informationalQuery)
701
718
  return;
702
- if (!buildLikeTurn && !pentestLikeTurn && !plan && !activePlan)
703
- return;
719
+ const runningJobs = jobManager.getRunningJobs();
704
720
  const p = plan ?? activePlan;
721
+ if (!buildLikeTurn &&
722
+ !pentestLikeTurn &&
723
+ !p &&
724
+ runningJobs.length === 0) {
725
+ return;
726
+ }
705
727
  const root = getActiveProjectRoot() ?? p?.meta?.projectRoot;
706
728
  const pm = p?.meta?.packageManager ??
707
729
  (root ? detectPackageManager(root) : undefined);
@@ -712,6 +734,10 @@ export async function runAgentTurn(prompt, options = {}) {
712
734
  const done = p?.tasks
713
735
  .filter((t) => t.state === "done" || t.state === "skipped")
714
736
  .map((t) => t.id);
737
+ const jobBits = runningJobs.slice(0, 4).map((j) => {
738
+ const cmd = (j.commandDisplay || j.command).replace(/\s+/g, " ").trim();
739
+ return `${j.id} ${j.status} ${cmd.slice(0, 40)}`;
740
+ });
715
741
  const snap = {
716
742
  goal: p?.goal ?? prompt.slice(0, 160),
717
743
  projectRoot: root,
@@ -728,6 +754,9 @@ export async function runAgentTurn(prompt, options = {}) {
728
754
  serverProbedOk: sawLocalHttpProbe,
729
755
  lastProbeFailed: sawFailedLocalHttpProbe,
730
756
  lastOkTool: taskWorkLedger?.lastOkTool,
757
+ backgroundJobs: jobBits.length > 0
758
+ ? `${runningJobs.length} running: ${jobBits.join("; ")}`
759
+ : undefined,
731
760
  engagementNote: pentestSession
732
761
  ? "remote/security engagement — no local dev server as completion"
733
762
  : undefined,
@@ -1879,7 +1908,8 @@ export async function runAgentTurn(prompt, options = {}) {
1879
1908
  }
1880
1909
  return { ok: result.ok, call, result, contextOutput };
1881
1910
  }
1882
- const AUTO_COMPACT_KEEP_RECENT = 6;
1911
+ // Align with /compact default: small recency + dense memory (not keepRecent=6 fat tails).
1912
+ const AUTO_COMPACT_KEEP_RECENT = 2;
1883
1913
  let lastCompactionMsgCount = 0;
1884
1914
  const summarizeForCompaction = async (summaryPrompt) => {
1885
1915
  const response = await completeWithProvider({
@@ -1890,7 +1920,8 @@ export async function runAgentTurn(prompt, options = {}) {
1890
1920
  { role: "user", content: summaryPrompt },
1891
1921
  ],
1892
1922
  temperature: 0.1,
1893
- maxTokens: 4_096,
1923
+ // Prefer dense memory; enough room for findings without forcing a tiny stub.
1924
+ maxTokens: 2_048,
1894
1925
  signal: options.signal,
1895
1926
  });
1896
1927
  return response.text;
@@ -1907,8 +1938,17 @@ export async function runAgentTurn(prompt, options = {}) {
1907
1938
  return;
1908
1939
  try {
1909
1940
  const result = await compactMessagesWithSummary(messages, summarizeForCompaction, { budgetTokens: 0, keepRecent: AUTO_COMPACT_KEEP_RECENT });
1910
- if (!result.summarized || result.afterTokens >= beforeTokens)
1941
+ const summaryBody = result.messages.find((m) => isCompactionMemoryMessage(m))?.content ??
1942
+ "";
1943
+ if (!shouldApplyAutoCompact({
1944
+ summarized: result.summarized,
1945
+ summaryBody,
1946
+ beforeTokens: result.beforeTokens,
1947
+ afterTokens: result.afterTokens,
1948
+ afterMessages: result.messages,
1949
+ })) {
1911
1950
  return;
1951
+ }
1912
1952
  messages.splice(0, messages.length, ...result.messages);
1913
1953
  loopGuard.resetReadOnly();
1914
1954
  // Token stats BEFORE plan re-injection so the reduction is accurate.