@google/gemini-cli-core 0.55.0-preview.0 → 0.56.0-nightly.20260807.gd5c9a97dc

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 (30) hide show
  1. package/dist/docs/changelogs/index.md +18 -0
  2. package/dist/docs/changelogs/latest.md +59 -31
  3. package/dist/docs/changelogs/preview.md +45 -3
  4. package/dist/google-gemini-cli-core-0.56.0-nightly.20260806.g761f604c1.tgz +0 -0
  5. package/dist/src/core/geminiChat.d.ts +10 -0
  6. package/dist/src/core/geminiChat.js +53 -1
  7. package/dist/src/core/geminiChat.js.map +1 -1
  8. package/dist/src/core/geminiChat.test.js +219 -0
  9. package/dist/src/core/geminiChat.test.js.map +1 -1
  10. package/dist/src/generated/git-commit.d.ts +2 -2
  11. package/dist/src/generated/git-commit.js +2 -2
  12. package/dist/src/generated/git-commit.js.map +1 -1
  13. package/dist/src/services/chatRecordingService.d.ts +6 -0
  14. package/dist/src/services/chatRecordingService.js +70 -1
  15. package/dist/src/services/chatRecordingService.js.map +1 -1
  16. package/dist/src/services/chatRecordingService.test.js +93 -0
  17. package/dist/src/services/chatRecordingService.test.js.map +1 -1
  18. package/dist/src/utils/errorParsing.test.js +8 -0
  19. package/dist/src/utils/errorParsing.test.js.map +1 -1
  20. package/dist/src/utils/googleErrors.js +68 -1
  21. package/dist/src/utils/googleErrors.js.map +1 -1
  22. package/dist/src/utils/googleErrors.test.js +90 -0
  23. package/dist/src/utils/googleErrors.test.js.map +1 -1
  24. package/dist/src/utils/googleQuotaErrors.d.ts +6 -4
  25. package/dist/src/utils/googleQuotaErrors.js +15 -0
  26. package/dist/src/utils/googleQuotaErrors.js.map +1 -1
  27. package/dist/src/utils/quotaErrorDetection.js +3 -1
  28. package/dist/src/utils/quotaErrorDetection.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +1 -1
@@ -183,6 +183,14 @@ describe('GeminiChat', () => {
183
183
  mockConfig.getMessageBus = vi.fn().mockReturnValue(mockMessageBus);
184
184
  // Disable 429 simulation for tests
185
185
  setSimulate429(false);
186
+ // The mid-stream retry loop sleeps on a real timer (1s + 2s + 4s) between
187
+ // attempts, which exceeds the default 5s test timeout and silently killed
188
+ // every InvalidStreamError test before it reached its assertions. Run those
189
+ // delays instantly.
190
+ vi.spyOn(globalThis, 'setTimeout').mockImplementation(((fn) => {
191
+ fn();
192
+ return 0;
193
+ }));
186
194
  // Reset history for each test by creating a new instance
187
195
  chat = new GeminiChat(mockConfig);
188
196
  mockConfig.getHookSystem = vi.fn().mockReturnValue(undefined);
@@ -756,6 +764,162 @@ describe('GeminiChat', () => {
756
764
  const lastTurn = chat.agentHistory.get()[chat.agentHistory.length - 1];
757
765
  expect(lastTurn.content.parts?.[0]?.functionResponse).toBeDefined();
758
766
  });
767
+ it('should not fuse the next user message into a preserved tool-response turn', async () => {
768
+ // Regression: when a stream fails mid tool-loop the tool response is
769
+ // deliberately preserved (see the test above), which leaves history
770
+ // ending on a user turn. The user's next message was then coalesced into
771
+ // that same turn as [functionResponse, text]. The model reads the
772
+ // trailing text as a continuation of the tool result and completes the
773
+ // sentence instead of answering it.
774
+ chat.agentHistory.push({
775
+ id: 'model-turn-1',
776
+ content: {
777
+ role: 'model',
778
+ parts: [{ functionCall: { name: 'test_tool', args: {} } }],
779
+ },
780
+ });
781
+ // 1. Tool response goes back, model returns nothing -> InvalidStreamError.
782
+ vi.mocked(mockContentGenerator.generateContentStream).mockResolvedValue((async function* () {
783
+ yield {
784
+ candidates: [
785
+ { content: { role: 'model', parts: [] }, finishReason: 'STOP' },
786
+ ],
787
+ };
788
+ })());
789
+ const failingStream = await chat.sendMessageStream({ model: 'gemini-2.0-flash' }, [
790
+ {
791
+ functionResponse: {
792
+ name: 'test_tool',
793
+ response: { success: true },
794
+ },
795
+ },
796
+ ], 'prompt-id-fusion-setup', new AbortController().signal, LlmRole.MAIN);
797
+ await expect((async () => {
798
+ for await (const _ of failingStream) {
799
+ // consume
800
+ }
801
+ })()).rejects.toThrow(InvalidStreamError);
802
+ // 2. The user types a brand new instruction.
803
+ let capturedContents = [];
804
+ vi.mocked(mockContentGenerator.generateContentStream).mockImplementation(async (req) => {
805
+ capturedContents = req.contents;
806
+ return (async function* () {
807
+ yield {
808
+ candidates: [
809
+ {
810
+ content: { role: 'model', parts: [{ text: 'ok' }] },
811
+ finishReason: 'STOP',
812
+ },
813
+ ],
814
+ };
815
+ })();
816
+ });
817
+ const stream = await chat.sendMessageStream({ model: 'gemini-2.0-flash' }, 'are you done?', 'prompt-id-fusion-check', new AbortController().signal, LlmRole.MAIN);
818
+ for await (const _ of stream) {
819
+ // consume
820
+ }
821
+ const fusedTurn = capturedContents.find((c) => c.role === 'user' &&
822
+ !!c.parts?.some((p) => !!p.functionResponse) &&
823
+ !!c.parts?.some((p) => p.text?.includes('are you done?')));
824
+ expect(fusedTurn).toBeUndefined();
825
+ });
826
+ it('should not fuse the next user message into a cancelled tool response', async () => {
827
+ // Same defect reached by a different trigger: cancelling a tool call
828
+ // records its response via addHistory then returns without submitting,
829
+ // leaving history on an unanswered user turn just like a stream failure.
830
+ chat.agentHistory.push({
831
+ id: 'model-turn-cancel',
832
+ content: {
833
+ role: 'model',
834
+ parts: [
835
+ { functionCall: { id: 'c1', name: 'run_shell_command', args: {} } },
836
+ ],
837
+ },
838
+ });
839
+ chat.addHistory({
840
+ role: 'user',
841
+ parts: [
842
+ {
843
+ functionResponse: {
844
+ id: 'c1',
845
+ name: 'run_shell_command',
846
+ response: { error: '[Operation Cancelled]' },
847
+ },
848
+ },
849
+ ],
850
+ });
851
+ let capturedContents = [];
852
+ vi.mocked(mockContentGenerator.generateContentStream).mockImplementation(async (req) => {
853
+ capturedContents = req.contents;
854
+ return (async function* () {
855
+ yield {
856
+ candidates: [
857
+ {
858
+ content: { role: 'model', parts: [{ text: 'ok' }] },
859
+ finishReason: 'STOP',
860
+ },
861
+ ],
862
+ };
863
+ })();
864
+ });
865
+ const stream = await chat.sendMessageStream({ model: 'gemini-2.0-flash' }, "you're querying local database, I meant nprd", 'prompt-id-cancel-fusion', new AbortController().signal, LlmRole.MAIN);
866
+ for await (const _ of stream) {
867
+ // consume
868
+ }
869
+ const fusedCancelTurn = capturedContents.find((c) => c.role === 'user' &&
870
+ !!c.parts?.some((p) => !!p.functionResponse) &&
871
+ !!c.parts?.some((p) => p.text?.includes('I meant nprd')));
872
+ expect(fusedCancelTurn).toBeUndefined();
873
+ });
874
+ it('should close a dangling tool response restored from a resumed session', async () => {
875
+ // The guard runs when a new user message arrives rather than when the
876
+ // turn fails, so it does not depend on a placeholder having been
877
+ // persisted. A session resumed from disk that ends on an unanswered tool
878
+ // response is repaired on the next message just the same.
879
+ chat.setHistory([
880
+ { role: 'user', parts: [{ text: 'run the tests' }] },
881
+ {
882
+ role: 'model',
883
+ parts: [
884
+ { functionCall: { id: 'c1', name: 'run_shell_command', args: {} } },
885
+ ],
886
+ },
887
+ {
888
+ role: 'user',
889
+ parts: [
890
+ {
891
+ functionResponse: {
892
+ id: 'c1',
893
+ name: 'run_shell_command',
894
+ response: { output: 'ok' },
895
+ },
896
+ },
897
+ ],
898
+ },
899
+ ]);
900
+ let capturedContents = [];
901
+ vi.mocked(mockContentGenerator.generateContentStream).mockImplementation(async (req) => {
902
+ capturedContents = req.contents;
903
+ return (async function* () {
904
+ yield {
905
+ candidates: [
906
+ {
907
+ content: { role: 'model', parts: [{ text: 'ok' }] },
908
+ finishReason: 'STOP',
909
+ },
910
+ ],
911
+ };
912
+ })();
913
+ });
914
+ const stream = await chat.sendMessageStream({ model: 'gemini-2.0-flash' }, 'are you done?', 'prompt-id-resumed-fusion', new AbortController().signal, LlmRole.MAIN);
915
+ for await (const _ of stream) {
916
+ // consume
917
+ }
918
+ const fusedResumedTurn = capturedContents.find((c) => c.role === 'user' &&
919
+ !!c.parts?.some((p) => !!p.functionResponse) &&
920
+ !!c.parts?.some((p) => p.text?.includes('are you done?')));
921
+ expect(fusedResumedTurn).toBeUndefined();
922
+ });
759
923
  it('should preserve mixed multimodal function responses during rollback when InvalidStreamError is thrown (regression)', async () => {
760
924
  // 1. Setup history ending with a model turn containing functionCall
761
925
  chat.agentHistory.push({
@@ -2285,6 +2449,61 @@ describe('GeminiChat', () => {
2285
2449
  expect(turns[0].content.parts[0].text).toBe('Question 1');
2286
2450
  expect(turns[0].content.parts[1].text).toBe('Question 2');
2287
2451
  });
2452
+ it('should inject a synthetic thoughtSignature onto a functionCall left signature-less after stripping a thought part that carried it (regression test for #28604)', () => {
2453
+ vi.mocked(mockConfig.isContextManagementEnabled).mockReturnValue(false);
2454
+ vi.mocked(mockConfig.getModel).mockReturnValue('gemini-2.5-pro');
2455
+ chat.setHistory([
2456
+ { role: 'user', parts: [{ text: 'activate the skill' }] },
2457
+ {
2458
+ role: 'model',
2459
+ parts: [
2460
+ {
2461
+ text: 'internal monologue',
2462
+ thought: true,
2463
+ thoughtSignature: 'real-sig-from-api',
2464
+ },
2465
+ {
2466
+ functionCall: { name: 'activate_skill', args: {} },
2467
+ },
2468
+ ],
2469
+ },
2470
+ {
2471
+ role: 'user',
2472
+ parts: [
2473
+ { functionResponse: { name: 'activate_skill', response: {} } },
2474
+ ],
2475
+ },
2476
+ ]);
2477
+ const turns = chat.getHistoryTurns(true);
2478
+ const modelTurn = turns[1];
2479
+ expect(modelTurn.content.parts).toHaveLength(1);
2480
+ expect(modelTurn.content.parts[0].functionCall?.name).toBe('activate_skill');
2481
+ expect(modelTurn.content.parts[0].thoughtSignature).toBe(SYNTHETIC_THOUGHT_SIGNATURE);
2482
+ });
2483
+ it('should leave an existing thoughtSignature on a functionCall untouched when stripping thoughts', () => {
2484
+ vi.mocked(mockConfig.isContextManagementEnabled).mockReturnValue(false);
2485
+ vi.mocked(mockConfig.getModel).mockReturnValue('gemini-2.5-pro');
2486
+ chat.setHistory([
2487
+ { role: 'user', parts: [{ text: 'activate the skill' }] },
2488
+ {
2489
+ role: 'model',
2490
+ parts: [
2491
+ {
2492
+ text: 'internal monologue',
2493
+ thought: true,
2494
+ thoughtSignature: 'real-sig-from-api',
2495
+ },
2496
+ {
2497
+ functionCall: { name: 'activate_skill', args: {} },
2498
+ thoughtSignature: 'existing-sig-on-call',
2499
+ },
2500
+ ],
2501
+ },
2502
+ ]);
2503
+ const turns = chat.getHistoryTurns(true);
2504
+ const modelTurn = turns[1];
2505
+ expect(modelTurn.content.parts[0].thoughtSignature).toBe('existing-sig-on-call');
2506
+ });
2288
2507
  });
2289
2508
  describe('ensureActiveLoopHasThoughtSignatures', () => {
2290
2509
  it('should add thoughtSignature to the first functionCall in each model turn of the active loop', () => {