@project-ava-supernova/core 0.2.150 → 0.2.152

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 (109) hide show
  1. package/dist/agent/agent.d.ts +32 -18
  2. package/dist/agent/agent.d.ts.map +1 -1
  3. package/dist/agent/agent.js +73 -24
  4. package/dist/agent/agent.js.map +1 -1
  5. package/dist/agent/repair-history.d.ts +53 -0
  6. package/dist/agent/repair-history.d.ts.map +1 -0
  7. package/dist/agent/repair-history.js +124 -0
  8. package/dist/agent/repair-history.js.map +1 -0
  9. package/dist/i18n/locales/ar.d.ts.map +1 -1
  10. package/dist/i18n/locales/ar.js +48 -0
  11. package/dist/i18n/locales/ar.js.map +1 -1
  12. package/dist/i18n/locales/de.d.ts.map +1 -1
  13. package/dist/i18n/locales/de.js +48 -0
  14. package/dist/i18n/locales/de.js.map +1 -1
  15. package/dist/i18n/locales/en.d.ts +48 -0
  16. package/dist/i18n/locales/en.d.ts.map +1 -1
  17. package/dist/i18n/locales/en.js +48 -0
  18. package/dist/i18n/locales/en.js.map +1 -1
  19. package/dist/i18n/locales/es.d.ts.map +1 -1
  20. package/dist/i18n/locales/es.js +48 -0
  21. package/dist/i18n/locales/es.js.map +1 -1
  22. package/dist/i18n/locales/fr.d.ts.map +1 -1
  23. package/dist/i18n/locales/fr.js +48 -0
  24. package/dist/i18n/locales/fr.js.map +1 -1
  25. package/dist/i18n/locales/hi.d.ts.map +1 -1
  26. package/dist/i18n/locales/hi.js +48 -0
  27. package/dist/i18n/locales/hi.js.map +1 -1
  28. package/dist/i18n/locales/id.d.ts.map +1 -1
  29. package/dist/i18n/locales/id.js +48 -0
  30. package/dist/i18n/locales/id.js.map +1 -1
  31. package/dist/i18n/locales/it.d.ts.map +1 -1
  32. package/dist/i18n/locales/it.js +48 -0
  33. package/dist/i18n/locales/it.js.map +1 -1
  34. package/dist/i18n/locales/ja.d.ts.map +1 -1
  35. package/dist/i18n/locales/ja.js +48 -0
  36. package/dist/i18n/locales/ja.js.map +1 -1
  37. package/dist/i18n/locales/ko.d.ts.map +1 -1
  38. package/dist/i18n/locales/ko.js +48 -0
  39. package/dist/i18n/locales/ko.js.map +1 -1
  40. package/dist/i18n/locales/nl.d.ts.map +1 -1
  41. package/dist/i18n/locales/nl.js +48 -0
  42. package/dist/i18n/locales/nl.js.map +1 -1
  43. package/dist/i18n/locales/pl.d.ts.map +1 -1
  44. package/dist/i18n/locales/pl.js +48 -0
  45. package/dist/i18n/locales/pl.js.map +1 -1
  46. package/dist/i18n/locales/pt.d.ts.map +1 -1
  47. package/dist/i18n/locales/pt.js +48 -0
  48. package/dist/i18n/locales/pt.js.map +1 -1
  49. package/dist/i18n/locales/ru.d.ts.map +1 -1
  50. package/dist/i18n/locales/ru.js +48 -0
  51. package/dist/i18n/locales/ru.js.map +1 -1
  52. package/dist/i18n/locales/th.d.ts.map +1 -1
  53. package/dist/i18n/locales/th.js +48 -0
  54. package/dist/i18n/locales/th.js.map +1 -1
  55. package/dist/i18n/locales/tr.d.ts.map +1 -1
  56. package/dist/i18n/locales/tr.js +48 -0
  57. package/dist/i18n/locales/tr.js.map +1 -1
  58. package/dist/i18n/locales/uk.d.ts.map +1 -1
  59. package/dist/i18n/locales/uk.js +48 -0
  60. package/dist/i18n/locales/uk.js.map +1 -1
  61. package/dist/i18n/locales/vi.d.ts.map +1 -1
  62. package/dist/i18n/locales/vi.js +48 -0
  63. package/dist/i18n/locales/vi.js.map +1 -1
  64. package/dist/i18n/locales/zh-CN.d.ts.map +1 -1
  65. package/dist/i18n/locales/zh-CN.js +48 -0
  66. package/dist/i18n/locales/zh-CN.js.map +1 -1
  67. package/dist/i18n/locales/zh-TW.d.ts.map +1 -1
  68. package/dist/i18n/locales/zh-TW.js +48 -0
  69. package/dist/i18n/locales/zh-TW.js.map +1 -1
  70. package/dist/index.d.ts +1 -0
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +1 -0
  73. package/dist/index.js.map +1 -1
  74. package/dist/memory/memory-manager.d.ts +32 -0
  75. package/dist/memory/memory-manager.d.ts.map +1 -1
  76. package/dist/memory/memory-manager.js +165 -16
  77. package/dist/memory/memory-manager.js.map +1 -1
  78. package/dist/memory/mode-recall.d.ts.map +1 -1
  79. package/dist/memory/mode-recall.js +7 -0
  80. package/dist/memory/mode-recall.js.map +1 -1
  81. package/dist/memory/project-brain.d.ts.map +1 -1
  82. package/dist/memory/project-brain.js +71 -12
  83. package/dist/memory/project-brain.js.map +1 -1
  84. package/dist/memory/types.d.ts +23 -3
  85. package/dist/memory/types.d.ts.map +1 -1
  86. package/dist/memory/types.js +2 -2
  87. package/dist/memory/types.js.map +1 -1
  88. package/dist/portability/factory-reset.d.ts +136 -0
  89. package/dist/portability/factory-reset.d.ts.map +1 -0
  90. package/dist/portability/factory-reset.js +360 -0
  91. package/dist/portability/factory-reset.js.map +1 -0
  92. package/dist/portability/index.d.ts +1 -0
  93. package/dist/portability/index.d.ts.map +1 -1
  94. package/dist/portability/index.js +2 -0
  95. package/dist/portability/index.js.map +1 -1
  96. package/dist/social/index.d.ts +16 -0
  97. package/dist/social/index.d.ts.map +1 -1
  98. package/dist/tools/memory-recall.js +2 -2
  99. package/dist/tools/memory-recall.js.map +1 -1
  100. package/dist/tools/memory-save.d.ts.map +1 -1
  101. package/dist/tools/memory-save.js +3 -1
  102. package/dist/tools/memory-save.js.map +1 -1
  103. package/dist/tools/suggest-beats.d.ts.map +1 -1
  104. package/dist/tools/suggest-beats.js +27 -2
  105. package/dist/tools/suggest-beats.js.map +1 -1
  106. package/dist/tools/write-video-post.d.ts.map +1 -1
  107. package/dist/tools/write-video-post.js +58 -2
  108. package/dist/tools/write-video-post.js.map +1 -1
  109. package/package.json +1 -1
@@ -119,6 +119,15 @@ export type AgentEvent = {
119
119
  type: 'context_truncated';
120
120
  droppedCount: number;
121
121
  }
122
+ /** The provider refused the conversation and we repaired it rather than
123
+ * ending the turn. NEVER silent: a quiet repair hides the bug that made
124
+ * it necessary, and the whole reason this exists is a fault that would
125
+ * otherwise have been absorbed invisibly. */
126
+ | {
127
+ type: 'history_repaired';
128
+ kind: string;
129
+ summary: string;
130
+ }
122
131
  /** The model was cut off at its output limit mid-reply. Never silent: a
123
132
  * truncated tool call simply never arrives, and the turn used to end as
124
133
  * though she had chosen to stop. */
@@ -627,33 +636,38 @@ export declare class Agent {
627
636
  private trimOldToolResults;
628
637
  private truncateMessages;
629
638
  /**
630
- * Detect the "first turn after Stop" pattern and strip prior conversation.
639
+ * Detect the "first turn after Stop" and tell Ava not to resume — WITHOUT
640
+ * taking the conversation away from her.
631
641
  *
632
- * When cancelRun() fires in the extension, a marker is pushed into the
633
- * conversation: `[User pressed Stop — previous task terminated...]`.
634
- * After the user's next real message, the conversation looks like:
642
+ * When cancelRun() fires, a marker goes into the conversation:
643
+ * `[User pressed Stop — previous task terminated...]`. After the user's
644
+ * next real message the history looks like:
635
645
  *
636
- * [... prior task, maybe 150K tokens ...]
646
+ * [... prior task ...]
637
647
  * [User pressed Stop — ...] (meta user message)
638
648
  * Actual new user message
639
649
  *
640
- * The prior 150K tokens are dead weight. Sending them back means the
641
- * model re-draws on the task the user told us to abandon. The fix is
642
- * to detect this pattern and return a restricted message array:
650
+ * THIS USED TO DELETE EVERYTHING ABOVE THE MARKER. The reasoning was that
651
+ * the prior tokens were dead weight and re-sending them made the model drift
652
+ * back into the abandoned task. The cost was far worse than the saving: the
653
+ * operator pressed Stop meaning "that is going wrong, let me redirect you",
654
+ * and Ava answered as though the conversation had never happened — then
655
+ * remembered it again the turn after, which is more baffling still. He
656
+ * described it as "losing massive chunks", and he was right to.
643
657
  *
644
- * [system prompt + stop directive]
645
- * [new user message]
658
+ * Stop means stop generating. It does not mean forget. Every other tool he
659
+ * uses works that way, and the marker below already carries the "do not
660
+ * resume" instruction — enforcing it with amnesia was never necessary.
646
661
  *
647
- * Detection: find the most recent stop marker. If it exists AND there
648
- * is exactly one non-meta user message after it (and the assistant
649
- * hasn't yet responded to that message), we're in the first post-stop
650
- * turn — restrict.
662
+ * So this now injects the directive into the system prompt and returns the
663
+ * history intact. Compression still applies downstream, which is the right
664
+ * place to deal with size.
651
665
  *
652
- * If more messages exist after that point (assistant replies, tool
653
- * results), we've already handled the first post-stop turn normally;
654
- * further turns see full context and operate as normal.
666
+ * Detection: the most recent stop marker, with exactly one non-meta user
667
+ * message after it and no real assistant reply yet. Later turns need no
668
+ * directive — the task is well and truly abandoned by then.
655
669
  */
656
- private maybeRestrictPostStopContext;
670
+ private applyPostStopDirective;
657
671
  /**
658
672
  * Age out old images and old tool results to cut per-turn token cost.
659
673
  *
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAqC,MAAM,uBAAuB,CAAC;AAEzF,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA8BhD,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,sBAAsB,CAAC;AA8IhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,kBAAkB,kQAarB,CAAC;AA0eX;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,IAAI,CAYzE;AAiCD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAGlF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,CAAC,MA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ool-p
8
8
  import { bridgeImagesForTextModel } from './vision-bridge.js';
9
9
  import { auditClaims } from './claims-auditor.js';
10
10
  import { parseJsonForgivingly } from '../utils/json-repair.js';
11
+ import { repairHistory, logRepair } from './repair-history.js';
11
12
  import { autoExtractAndSave } from '../memory/auto-extract.js';
12
13
  import { maybeBuildDesignReinjection, isUIFilePath as isUIFilePathLocal } from './design-reinjection.js';
13
14
  import { isStopCommand } from './stop-command.js';
@@ -1376,7 +1377,7 @@ export class Agent {
1376
1377
  // short/conversational, the intent gate will disable tools too.
1377
1378
  // Combined effect: user presses Stop → types something → Ava responds
1378
1379
  // on the user's actual terms, not the prior task's terms.
1379
- messages = this.maybeRestrictPostStopContext(messages);
1380
+ messages = this.applyPostStopDirective(messages);
1380
1381
  // ─── Classify this task for directness discipline ─────────────────────
1381
1382
  // Find the latest non-meta user message and run the lightweight
1382
1383
  // classifier. The result sets the exploration budget for this run and
@@ -1525,6 +1526,10 @@ export class Agent {
1525
1526
  // Pass signal to tool execution context so tools (esp. bash) can be cancelled
1526
1527
  const runContext = { ...this.toolContext, signal };
1527
1528
  let iterations = 0;
1529
+ // One repair per turn. If a repaired history fails again the repair did
1530
+ // not take, and retrying becomes a loop that spends an allowance going
1531
+ // nowhere. See repair-history.ts.
1532
+ let repairAttempted = false;
1528
1533
  this.pauseRequested = false; // clear any stale pause from a prior run
1529
1534
  this._inThinkTag = false;
1530
1535
  let warningInjected = false;
@@ -1941,6 +1946,36 @@ export class Agent {
1941
1946
  }
1942
1947
  catch (error) {
1943
1948
  logger.error(`[agent] streamResponse THREW: ${error instanceof Error ? error.message : String(error)}`);
1949
+ // ── Repair a refused conversation, once ───────────────────────────
1950
+ //
1951
+ // A 400 is usually a complaint about the HISTORY, not about what was
1952
+ // just typed. Before this, the error surfaced and the turn ended; the
1953
+ // next message replayed the same malformed history and failed the
1954
+ // same way, forever, and a new chat was the only escape. A DeepSeek
1955
+ // thinking-mode conversation died exactly like that on 16 Oct, under
1956
+ // an error message that said "that's ours to fix — try again".
1957
+ //
1958
+ // So when the provider names a structural fault we fix that fault and
1959
+ // send once more. Only once, and only if the repair actually changed
1960
+ // something: see repair-history.ts for why those two rules carry more
1961
+ // weight than the repairs do.
1962
+ const provErr = error;
1963
+ if (!repairAttempted && provErr?.statusCode === 400) {
1964
+ const detail = typeof provErr.responseBody === 'string'
1965
+ ? provErr.responseBody
1966
+ : JSON.stringify(provErr.responseBody ?? '');
1967
+ const repair = repairHistory(detail, messages);
1968
+ if (repair && repair.messages.length !== messages.length) {
1969
+ repairAttempted = true;
1970
+ logRepair(repair, 1);
1971
+ messages = repair.messages;
1972
+ // Said out loud on purpose. A silent repair hides the bug that
1973
+ // caused it — this very fault would have been absorbed invisibly
1974
+ // and the two files that disagreed would still disagree.
1975
+ onEvent({ type: 'history_repaired', kind: repair.kind, summary: repair.summary });
1976
+ continue;
1977
+ }
1978
+ }
1944
1979
  // Surface the error through the event system so CLI/extension handle it consistently
1945
1980
  onEvent({ type: 'error', error: error instanceof Error ? error : new Error(String(error)) });
1946
1981
  // Always emit done so UI clears isStreaming/isThinking
@@ -3781,33 +3816,38 @@ ${transcript}`;
3781
3816
  return enrichedSystem ? [enrichedSystem, ...fixed] : fixed;
3782
3817
  }
3783
3818
  /**
3784
- * Detect the "first turn after Stop" pattern and strip prior conversation.
3819
+ * Detect the "first turn after Stop" and tell Ava not to resume — WITHOUT
3820
+ * taking the conversation away from her.
3785
3821
  *
3786
- * When cancelRun() fires in the extension, a marker is pushed into the
3787
- * conversation: `[User pressed Stop — previous task terminated...]`.
3788
- * After the user's next real message, the conversation looks like:
3822
+ * When cancelRun() fires, a marker goes into the conversation:
3823
+ * `[User pressed Stop — previous task terminated...]`. After the user's
3824
+ * next real message the history looks like:
3789
3825
  *
3790
- * [... prior task, maybe 150K tokens ...]
3826
+ * [... prior task ...]
3791
3827
  * [User pressed Stop — ...] (meta user message)
3792
3828
  * Actual new user message
3793
3829
  *
3794
- * The prior 150K tokens are dead weight. Sending them back means the
3795
- * model re-draws on the task the user told us to abandon. The fix is
3796
- * to detect this pattern and return a restricted message array:
3830
+ * THIS USED TO DELETE EVERYTHING ABOVE THE MARKER. The reasoning was that
3831
+ * the prior tokens were dead weight and re-sending them made the model drift
3832
+ * back into the abandoned task. The cost was far worse than the saving: the
3833
+ * operator pressed Stop meaning "that is going wrong, let me redirect you",
3834
+ * and Ava answered as though the conversation had never happened — then
3835
+ * remembered it again the turn after, which is more baffling still. He
3836
+ * described it as "losing massive chunks", and he was right to.
3797
3837
  *
3798
- * [system prompt + stop directive]
3799
- * [new user message]
3838
+ * Stop means stop generating. It does not mean forget. Every other tool he
3839
+ * uses works that way, and the marker below already carries the "do not
3840
+ * resume" instruction — enforcing it with amnesia was never necessary.
3800
3841
  *
3801
- * Detection: find the most recent stop marker. If it exists AND there
3802
- * is exactly one non-meta user message after it (and the assistant
3803
- * hasn't yet responded to that message), we're in the first post-stop
3804
- * turn — restrict.
3842
+ * So this now injects the directive into the system prompt and returns the
3843
+ * history intact. Compression still applies downstream, which is the right
3844
+ * place to deal with size.
3805
3845
  *
3806
- * If more messages exist after that point (assistant replies, tool
3807
- * results), we've already handled the first post-stop turn normally;
3808
- * further turns see full context and operate as normal.
3846
+ * Detection: the most recent stop marker, with exactly one non-meta user
3847
+ * message after it and no real assistant reply yet. Later turns need no
3848
+ * directive — the task is well and truly abandoned by then.
3809
3849
  */
3810
- maybeRestrictPostStopContext(messages) {
3850
+ applyPostStopDirective(messages) {
3811
3851
  // Find the most recent stop marker (a user-role message starting with the marker prefix).
3812
3852
  let markerIdx = -1;
3813
3853
  for (let i = messages.length - 1; i >= 0; i--) {
@@ -3848,17 +3888,26 @@ ${transcript}`;
3848
3888
  if (nonMetaUsers.length !== 1 || hasRealAssistantResponse) {
3849
3889
  return messages;
3850
3890
  }
3851
- const newUserMessage = nonMetaUsers[0];
3891
+ // (The new user message itself needs no special handling now that the
3892
+ // history stays — it is already in `messages` where it belongs.)
3852
3893
  const systemMsg = messages.find(m => m.role === 'system');
3853
3894
  // Merge the stop directive into the system prompt so the model sees
3854
3895
  // it at the highest-authority layer, not as a floating user message
3855
3896
  // (which some providers reject when followed by another user msg).
3856
- const stopDirective = `\n\n[Post-stop context] The previous task was terminated by the user. Do not resume it. Treat the user's message below as a fresh request on its own terms. If they reference prior work ambiguously (e.g. "fix that", "continue"), ask them to be specific — you do not have the prior context and should not assume.`;
3857
- const restrictedSystem = systemMsg
3897
+ // The directive used to end with "you do not have the prior context",
3898
+ // which was true only because this function had just deleted it. Both
3899
+ // halves are gone now: the history stays, and Ava is told plainly that
3900
+ // she still has it.
3901
+ const stopDirective = `\n\n[Post-stop] The user stopped the previous task. Do NOT resume it or pick it back up on your own — answer the message below on its own terms.\n\nThe conversation above is still yours to use. If their message leans on it ("fix that instead", "same thing but…", "carry on from the bit that worked"), use it. Stopping a task does not undo the discussion that led to it.`;
3902
+ const withDirective = systemMsg
3858
3903
  ? { ...systemMsg, content: (typeof systemMsg.content === 'string' ? systemMsg.content : '') + stopDirective }
3859
3904
  : { role: 'system', content: stopDirective.trimStart() };
3860
- logger.debug(`[agent] Post-stop context restriction: dropped ${messages.length - 2} prior messages, keeping system + new user message`);
3861
- return restrictedSystem ? [restrictedSystem, newUserMessage] : [newUserMessage];
3905
+ logger.debug('[agent] Post-stop directive applied; history kept intact');
3906
+ // History intact — only the system message is swapped for its annotated
3907
+ // copy. Size is compression's job, not this function's.
3908
+ if (!withDirective)
3909
+ return messages;
3910
+ return messages.map(m => (m === systemMsg ? withDirective : m));
3862
3911
  }
3863
3912
  /**
3864
3913
  * Age out old images and old tool results to cut per-turn token cost.