Repository: TabbyML/tabby
File: clients/vscode/src/chat/webview.ts (TypeScript)

Code before:
            for (const diff of diffs) {
              const diffChars = diff.length;

              if (currentTokenCount + diffChars > charLimit) {
                break;
              }

              res.push({
                content: diff,
                staged: staged,
              } as ChangeItem);

              currentTokenCount += diffChars;
            }

            if (currentTokenCount >= maxChars) {
              break;
            }
          }

          return res;
        };

        const stagedChanges: ChangeItem[] = await getRepoChanges(repositories, true, remainingChars);

        const stagedTokenCount = stagedChanges.reduce((count, item) => count + Math.ceil(item.content.length / 4), 0);
        remainingChars = maxChars - stagedTokenCount;

        const unstagedChanges: ChangeItem[] = await getRepoChanges(repositories, false, remainingChars);

        const res = [...stagedChanges, ...unstagedChanges];

        this.logger.info(`Found ${res.length} changed files.`);

        // return the result order from stage to unstaged
        return res;
      },
    });
  }

  private checkStatusAndLoadContent() {
    const statusInfo = this.lspClient.status.current;
    const error = this.checkStatusInfo(statusInfo);
    if (error) {
      this.currentConfig = undefined;
      this.loadErrorPage(error);
      return;
    }
    const config = this.lspClient.agentConfig.current;
    if (!config) {
      this.currentConfig = undefined;

Review comment (suggestion):
```suggestion
        const stagedCharCount = stagedChanges.reduce((count, item) => count + item.content.length, 0);
```

Code after:

            for (const diff of diffs) {
              const diffChars = diff.length;

              if (charLimit !== undefined && currentCharCount + diffChars > charLimit) {
                break;
              }

              res.push({
                content: diff,
                staged: staged,
              } as ChangeItem);

              currentCharCount += diffChars;
            }

            if (charLimit !== undefined && currentCharCount >= charLimit) {
              break;
            }
          }

          return res;
        };

        const stagedChanges: ChangeItem[] = await getRepoChanges(repositories, true, remainingChars);

        const stagedCharCount = stagedChanges.reduce((count, item) => count + item.content.length, 0);

        remainingChars = maxChars !== undefined ? maxChars - stagedCharCount : undefined;

        const unstagedChanges: ChangeItem[] = await getRepoChanges(repositories, false, remainingChars);

        const res = [...stagedChanges, ...unstagedChanges];

        this.logger.info(`Found ${res.length} changed files.`);

        return res;
      },

      runCommand: async (command: string) => {
        const terminal = window.createTerminal("Tabby");
        terminal.show();
        terminal.sendText(command);
      },
    });
  }

  private checkStatusAndLoadContent() {
    const statusInfo = this.lspClient.status.current;
    const error = this.checkStatusInfo(statusInfo);
    if (error) {