Merge branch 'main' of github.com:Aider-AI/aider

This commit is contained in:
Paul Gauthier 2025-06-25 11:51:28 -07:00
commit 8fe52d7b0d
6 changed files with 57 additions and 21 deletions

View file

@ -70,9 +70,17 @@ class Analytics:
# ephemeral
logfile = None
def __init__(self, logfile=None, permanently_disable=False):
def __init__(
self,
logfile=None,
permanently_disable=False,
posthog_host=None,
posthog_project_api_key=None
):
self.logfile = logfile
self.get_or_create_uuid()
self.custom_posthog_host = posthog_host
self.custom_posthog_project_api_key = posthog_project_api_key
if self.permanently_disable or permanently_disable or not self.asked_opt_in:
self.disable(permanently_disable)
@ -92,8 +100,8 @@ class Analytics:
# self.mp = Mixpanel(mixpanel_project_token)
self.ph = Posthog(
project_api_key=posthog_project_api_key,
host=posthog_host,
project_api_key=self.custom_posthog_project_api_key or posthog_project_api_key,
host=self.custom_posthog_host or posthog_host,
on_error=self.posthog_error,
enable_exception_autocapture=True,
super_properties=self.get_system_info(), # Add system info to all events

View file

@ -582,6 +582,16 @@ def get_parser(default_config_files, git_root):
help="Permanently disable analytics",
default=False,
)
group.add_argument(
"--analytics-posthog-host",
metavar="ANALYTICS_POSTHOG_HOST",
help="Send analytics to custom PostHog instance",
)
group.add_argument(
"--analytics-posthog-project-api-key",
metavar="ANALYTICS_POSTHOG_PROJECT_API_KEY",
help="Send analytics to custom PostHog project"
)
#########
group = parser.add_argument_group("Upgrading")

View file

@ -63,37 +63,38 @@ class ChatSummary:
if split_index <= min_split:
return self.summarize_all(messages)
# Split head and tail
head = messages[:split_index]
tail = messages[split_index:]
sized = sized[:split_index]
head.reverse()
sized.reverse()
# Only size the head once
sized_head = sized[:split_index]
# Precompute token limit (fallback to 4096 if undefined)
model_max_input_tokens = self.models[0].info.get("max_input_tokens") or 4096
model_max_input_tokens -= 512 # reserve buffer for safety
keep = []
total = 0
# These sometimes come set with value = None
model_max_input_tokens = self.models[0].info.get("max_input_tokens") or 4096
model_max_input_tokens -= 512
for i in range(split_index):
total += sized[i][0]
# Iterate in original order, summing tokens until limit
for tokens, msg in sized_head:
total += tokens
if total > model_max_input_tokens:
break
keep.append(head[i])
keep.reverse()
keep.append(msg)
# No need to reverse lists back and forth
summary = self.summarize_all(keep)
tail_tokens = sum(tokens for tokens, msg in sized[split_index:])
# If the combined summary and tail still fits, return directly
summary_tokens = self.token_count(summary)
result = summary + tail
tail_tokens = sum(tokens for tokens, _ in sized[split_index:])
if summary_tokens + tail_tokens < self.max_tokens:
return result
return summary + tail
return self.summarize_real(result, depth + 1)
# Otherwise recurse with increased depth
return self.summarize_real(summary + tail, depth + 1)
def summarize_all(self, messages):
content = ""

View file

@ -633,7 +633,12 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
)
os.environ["OPENAI_ORGANIZATION"] = args.openai_organization_id
analytics = Analytics(logfile=args.analytics_log, permanently_disable=args.analytics_disable)
analytics = Analytics(
logfile=args.analytics_log,
permanently_disable=args.analytics_disable,
posthog_host=args.analytics_posthog_host,
posthog_project_api_key=args.analytics_posthog_project_api_key
)
if args.analytics is not False:
if analytics.need_to_ask(args.analytics):
io.tool_output(

View file

@ -298,6 +298,12 @@
## Permanently disable analytics
#analytics-disable: false
## PostHog host (default: https://us.i.posthog.com)
#analytics-posthog-host: xxx
## PostHog project api key (default: phc_99T7muzafUMMZX15H8XePbMSreEUzahHbtWjy3l5Qbv)
#analytics-posthog-project-api-key: xxx
############
# Upgrading:

View file

@ -105,6 +105,12 @@ If you want to just log analytics without reporting them, you can do:
aider --analytics-log filename.jsonl --no-analytics
```
### Sending analytics to custom PostHog project or installation
Aider uses PostHog for analytics collection. You can configure aider to send analytics to your own PostHog project or a custom PostHog installation using these parameters:
- `--analytics-posthog-project-api-key KEY` - Set a custom PostHog project API key
- `--analytics-posthog-host HOST` - Set a custom PostHog host (default is app.posthog.com)
## Reporting issues