adloop 0.38.2__tar.gz → 0.38.3__tar.gz

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 (77) hide show
  1. {adloop-0.38.2 → adloop-0.38.3}/PKG-INFO +1 -1
  2. {adloop-0.38.2 → adloop-0.38.3}/pyproject.toml +1 -1
  3. {adloop-0.38.2 → adloop-0.38.3}/pyproject.toml.orig +1 -1
  4. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/safety/approval.py +159 -41
  5. {adloop-0.38.2 → adloop-0.38.3}/README.md +0 -0
  6. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/__init__.py +0 -0
  7. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/__main__.py +0 -0
  8. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/_mcp_patches.py +0 -0
  9. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/__init__.py +0 -0
  10. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/ai_max.py +0 -0
  11. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/assets.py +0 -0
  12. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/audiences.py +0 -0
  13. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/brands.py +0 -0
  14. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/campaign_settings.py +0 -0
  15. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/client.py +0 -0
  16. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/conversion_actions.py +0 -0
  17. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/currency.py +0 -0
  18. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/custom_conversion_goals.py +0 -0
  19. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/enums.py +0 -0
  20. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/forecast.py +0 -0
  21. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/gaql.py +0 -0
  22. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/image_fetch.py +0 -0
  23. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/pmax.py +0 -0
  24. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/read.py +0 -0
  25. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/recommendation_subscriptions.py +0 -0
  26. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/recommendations.py +0 -0
  27. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/shopping.py +0 -0
  28. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/snippet_headers.py +0 -0
  29. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/validate_only.py +0 -0
  30. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ads/write.py +0 -0
  31. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/auth.py +0 -0
  32. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/cli.py +0 -0
  33. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/config.py +0 -0
  34. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/crossref.py +0 -0
  35. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/diagnostics.py +0 -0
  36. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ga4/__init__.py +0 -0
  37. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ga4/client.py +0 -0
  38. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ga4/reports.py +0 -0
  39. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ga4/tracking.py +0 -0
  40. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/ga4/write.py +0 -0
  41. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gsc/__init__.py +0 -0
  42. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gsc/client.py +0 -0
  43. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gsc/reports.py +0 -0
  44. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gtm/__init__.py +0 -0
  45. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gtm/client.py +0 -0
  46. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gtm/entities.py +0 -0
  47. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gtm/read.py +0 -0
  48. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/gtm/write.py +0 -0
  49. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/merchant/__init__.py +0 -0
  50. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/merchant/client.py +0 -0
  51. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/merchant/read.py +0 -0
  52. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/pagespeed.py +0 -0
  53. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/reddit/__init__.py +0 -0
  54. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/reddit/auth.py +0 -0
  55. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/reddit/client.py +0 -0
  56. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/reddit/read.py +0 -0
  57. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/reddit/schedule.py +0 -0
  58. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/reddit/write.py +0 -0
  59. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/__init__.py +0 -0
  60. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/adloop.md +0 -0
  61. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/commands/analyze-performance.md +0 -0
  62. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/commands/budget-plan.md +0 -0
  63. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/commands/create-ad.md +0 -0
  64. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/commands/create-campaign.md +0 -0
  65. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
  66. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules/commands/optimize-campaign.md +0 -0
  67. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/rules_install.py +0 -0
  68. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/runtime.py +0 -0
  69. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/safety/__init__.py +0 -0
  70. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/safety/approval_card.html +0 -0
  71. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/safety/audit.py +0 -0
  72. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/safety/guards.py +0 -0
  73. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/safety/preview.py +0 -0
  74. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/server.py +0 -0
  75. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/tracking.py +0 -0
  76. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/upload_card.html +0 -0
  77. {adloop-0.38.2 → adloop-0.38.3}/src/adloop/uploads.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: adloop
3
- Version: 0.38.2
3
+ Version: 0.38.3
4
4
  Summary: The AI command center for Google Ads, Reddit Ads, GA4, and tracking code.
5
5
  Keywords: mcp,google-ads,reddit-ads,google-analytics,ga4,cursor,marketing
6
6
  Author: Daniel Klose
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.38.2"
3
+ version = "0.38.3"
4
4
  description = "The AI command center for Google Ads, Reddit Ads, GA4, and tracking code."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.38.2"
3
+ version = "0.38.3"
4
4
  description = "The AI command center for Google Ads, Reddit Ads, GA4, and tracking code."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -28,14 +28,16 @@ import contextvars
28
28
  import hashlib
29
29
  import hmac
30
30
  import json
31
+ import re
31
32
  import secrets
32
- from dataclasses import dataclass
33
33
  from collections.abc import Iterator
34
34
  from contextlib import contextmanager
35
35
  from functools import lru_cache
36
36
  from importlib import resources
37
37
  from typing import TYPE_CHECKING, Any
38
38
 
39
+ from pydantic import BaseModel, Field
40
+
39
41
  if TYPE_CHECKING:
40
42
  from adloop.safety.preview import ChangePlan
41
43
 
@@ -242,15 +244,20 @@ DIALOG_KEY = "adloop_confirm"
242
244
  _MAX_DIALOG_FIELDS = 10
243
245
 
244
246
 
245
- @dataclass
246
- class ApplyConfirmation:
247
- apply: bool = False
247
+ # The tick stays even though the dialog has an Accept button: without a field,
248
+ # apps put the cursor on Accept, and one reflexive Enter would apply. The titles
249
+ # are what the dialog shows next to each box.
250
+ _APPLY_TITLE = "Yes, apply this change"
251
+ _UNDO_TITLE = "I understand it cannot be undone"
252
+
248
253
 
254
+ class ApplyConfirmation(BaseModel):
255
+ apply: bool = Field(False, title=_APPLY_TITLE)
249
256
 
250
- @dataclass
251
- class IrreversibleConfirmation:
252
- apply: bool = False
253
- cannot_be_undone: bool = False
257
+
258
+ class IrreversibleConfirmation(BaseModel):
259
+ apply: bool = Field(False, title=_APPLY_TITLE)
260
+ cannot_be_undone: bool = Field(False, title=_UNDO_TITLE)
254
261
 
255
262
 
256
263
  def _confirmation_type(plan: ChangePlan) -> type:
@@ -274,43 +281,137 @@ def client_can_elicit() -> bool:
274
281
  return form is not None or url is None
275
282
 
276
283
 
284
+ _PLATFORM_LABELS = {
285
+ "google": "Google Ads",
286
+ "reddit": "Reddit Ads",
287
+ "gtm": "Google Tag Manager",
288
+ "ga4": "Google Analytics",
289
+ "microsoft": "Microsoft Advertising",
290
+ "chatgpt": "ChatGPT Ads",
291
+ }
292
+ _OPERATION_PREFIX = re.compile(r"^(?:%s)_" % "|".join(p for p in _PLATFORM_LABELS if p != "google"))
293
+ # Where a plan keeps the name of what it changes, most specific first.
294
+ _NAME_KEYS = ("entity_name", "name", "campaign_name", "ad_group_name", "list_name",
295
+ "tag_name", "trigger_name", "variable_name")
296
+ # Shown in the dialog's first two lines already, or noise in a summary.
297
+ _HEADER_KEYS = frozenset({*_NAME_KEYS, "account", "account_name", "customer_id",
298
+ "current_status", "target_status", "status_on_create"})
299
+ _SUMMARY_SKIP = frozenset({"currency", "time_zone", "fingerprint", "warnings"})
300
+ _MAX_SUMMARY_FACTS = 3
301
+
302
+
277
303
  def _platform_label(plan: ChangePlan) -> str:
304
+ if plan.platform in _PLATFORM_LABELS:
305
+ return _PLATFORM_LABELS[plan.platform]
278
306
  op = plan.operation
279
- if op.startswith("reddit_"):
280
- return "Reddit Ads"
281
- if op.startswith("gtm_"):
282
- return "Google Tag Manager"
307
+ for prefix, label in _PLATFORM_LABELS.items():
308
+ if op.startswith(prefix + "_"):
309
+ return label
283
310
  if "key_event" in op:
284
311
  return "Google Analytics"
285
312
  return "Google Ads"
286
313
 
287
314
 
288
- def confirmation_message(plan: ChangePlan) -> str:
289
- """The dialog text: what changes, where, and what confirming does."""
290
- title = plan.operation.replace("reddit_", "").replace("gtm_", "").replace("_", " ")
291
- target = " ".join(
292
- part for part in (plan.entity_type.replace("_", " "), plan.entity_id) if part
315
+ def _clip(text: str, limit: int) -> str:
316
+ return text if len(text) <= limit else text[: limit - 1] + "…"
317
+
318
+
319
+ def _headline(plan: ChangePlan) -> str:
320
+ """'create campaign "Spring sale"', 'pause campaign 123': the action and its target."""
321
+ action = _OPERATION_PREFIX.sub("", plan.operation).replace("_", " ")
322
+ noun = plan.entity_type.replace("_", " ")
323
+ if noun and action.endswith(" entity"):
324
+ action = action[: -len("entity")] + noun
325
+ name = next(
326
+ (v.strip() for k in _NAME_KEYS
327
+ if isinstance(v := plan.changes.get(k), str) and v.strip()),
328
+ "",
293
329
  )
294
- lines = [f"AdLoop: apply this change in {_platform_label(plan)}?", ""]
295
- lines.append(title.capitalize() + (f" ({target})" if target else ""))
296
- for key, value in list(plan.changes.items())[:_MAX_DIALOG_FIELDS]:
330
+ if name:
331
+ return f'{action} "{_clip(name, 60)}"'
332
+ if plan.entity_id:
333
+ return f"{action} {plan.entity_id}" if action.endswith(noun) else f"{action} ({noun} {plan.entity_id})"
334
+ return action
335
+
336
+
337
+ def _fact(key: str, value: Any) -> str:
338
+ """One short 'key: value' for the summary line, or '' when it isn't one."""
339
+ if isinstance(value, dict) and len(value) == 1:
340
+ value = next(iter(value.values()))
341
+ if isinstance(value, list) and 0 < len(value) <= 3 and all(
342
+ isinstance(v, (str, int, float)) for v in value
343
+ ):
344
+ value = ", ".join(str(v) for v in value)
345
+ if isinstance(value, bool) or value in (None, "", []) or not isinstance(value, (str, int, float)):
346
+ return ""
347
+ text = str(value)
348
+ return f"{key.replace('_', ' ')}: {text}" if len(text) <= 40 else ""
349
+
350
+
351
+ def _summary(plan: ChangePlan) -> str:
352
+ """The dialog's second line: account, status change and the first few facts.
353
+
354
+ Apps such as Claude Code show only the first lines of the message and fold
355
+ the rest, so this line has to carry what the person is approving.
356
+ """
357
+ changes = plan.changes
358
+ parts = []
359
+ account = next(
360
+ (a for a in (changes.get("account"), changes.get("account_name"), plan.customer_id)
361
+ if isinstance(a, (str, int)) and not isinstance(a, bool) and str(a).strip()),
362
+ "",
363
+ )
364
+ if account:
365
+ parts.append(f"account {account}")
366
+ current, target = changes.get("current_status"), changes.get("target_status")
367
+ if target:
368
+ parts.append(f"{current} → {target}" if current else f"→ {target}")
369
+ elif created := changes.get("status_on_create"):
370
+ parts.append(f"created {str(created).lower()}")
371
+ facts = 0
372
+ for key, value in changes.items():
373
+ if facts == _MAX_SUMMARY_FACTS:
374
+ break
375
+ if key in _HEADER_KEYS or key in _SUMMARY_SKIP or key.endswith(("_id", "_ids")):
376
+ continue
377
+ if fact := _fact(key, value):
378
+ parts.append(fact)
379
+ facts += 1
380
+ return _clip(" · ".join(parts), 160)
381
+
382
+
383
+ def confirmation_message(plan: ChangePlan) -> str:
384
+ """The dialog text: the question and a one-line summary first, then the details.
385
+
386
+ Some apps show only the first two lines until the person expands the
387
+ dialog, so those two lines name the change, the platform, the account and
388
+ the key values on their own.
389
+ """
390
+ lines = [f"AdLoop: {_headline(plan)} in {_platform_label(plan)}?"]
391
+ if summary := _summary(plan):
392
+ lines.append(summary[0].upper() + summary[1:])
393
+ details = [(k, v) for k, v in plan.changes.items() if k not in _HEADER_KEYS]
394
+ if details:
395
+ lines.append("")
396
+ for key, value in details[:_MAX_DIALOG_FIELDS]:
297
397
  text = value if isinstance(value, str) else json.dumps(value, default=str)
298
- if len(text) > 160:
299
- text = text[:157] + "..."
300
- lines.append(f"- {key.replace('_', ' ')}: {text}")
301
- if len(plan.changes) > _MAX_DIALOG_FIELDS:
302
- lines.append(f"- ... {len(plan.changes) - _MAX_DIALOG_FIELDS} more fields in the preview")
398
+ lines.append(f"- {key.replace('_', ' ')}: {_clip(text, 160)}")
399
+ if (more := len(details) - _MAX_DIALOG_FIELDS) > 0:
400
+ lines.append(f"- … {more} more field{'s' if more > 1 else ''} in the preview")
303
401
  lines.append("")
304
402
  if plan.requires_double_confirm:
305
- lines.append("This cannot be undone. Tick both boxes to apply it for real.")
403
+ lines.append(
404
+ f'This cannot be undone. Tick "{_APPLY_TITLE}" and "{_UNDO_TITLE}", then Accept.'
405
+ )
306
406
  else:
307
- lines.append("Tick the box to apply it for real. Declining changes nothing.")
407
+ lines.append(f'Tick "{_APPLY_TITLE}", then Accept. Decline changes nothing.')
308
408
  return "\n".join(lines)
309
409
 
310
410
 
311
- def _accepted(plan: ChangePlan, action: str | None, content: Any) -> bool:
411
+ def _refusal(plan: ChangePlan, action: str | None, content: Any) -> str:
412
+ """Why the dialog's answer does not allow the apply; "" when it does."""
312
413
  if action != "accept":
313
- return False
414
+ return "declined"
314
415
  if content is None:
315
416
  data: dict = {}
316
417
  elif isinstance(content, dict):
@@ -318,20 +419,37 @@ def _accepted(plan: ChangePlan, action: str | None, content: Any) -> bool:
318
419
  else:
319
420
  data = vars(content)
320
421
  if not data.get("apply"):
321
- return False
322
- return not plan.requires_double_confirm or bool(data.get("cannot_be_undone"))
323
-
324
-
325
- def _not_confirmed(plan: ChangePlan) -> dict:
422
+ return "apply_not_ticked"
423
+ if plan.requires_double_confirm and not data.get("cannot_be_undone"):
424
+ return "undo_not_ticked"
425
+ return ""
426
+
427
+
428
+ def _not_confirmed(plan: ChangePlan, reason: str = "declined") -> dict:
429
+ if reason == "apply_not_ticked":
430
+ message = (
431
+ f'The user chose Accept in the confirmation dialog without ticking "{_APPLY_TITLE}", '
432
+ "so nothing was changed. Tell them the box has to be ticked, and ask whether "
433
+ "to try again. The preview stays pending."
434
+ )
435
+ elif reason == "undo_not_ticked":
436
+ message = (
437
+ f'The user chose Accept without ticking "{_UNDO_TITLE}", which this irreversible '
438
+ "change requires, so nothing was changed. Tell them both boxes have to be "
439
+ "ticked, and ask whether to try again. The preview stays pending."
440
+ )
441
+ else:
442
+ message = (
443
+ "The user did not confirm the change in the confirmation dialog, so "
444
+ "nothing was changed. Do not retry on your own; ask the user what "
445
+ "they want to do. The preview stays pending."
446
+ )
326
447
  return {
327
448
  "status": "NOT_CONFIRMED",
449
+ "reason": reason,
328
450
  "plan_id": plan.plan_id,
329
451
  "operation": plan.operation,
330
- "message": (
331
- "The user did not confirm the change in the confirmation dialog, so "
332
- "nothing was changed. Do not retry on your own; ask the user what "
333
- "they want to do. The preview stays pending."
334
- ),
452
+ "message": message,
335
453
  }
336
454
 
337
455
 
@@ -479,6 +597,6 @@ async def confirm_in_dialog(context: Any, plan_id: str) -> Any | None:
479
597
  action = getattr(answer, "action", None)
480
598
  content = getattr(answer, "data", None)
481
599
 
482
- if _accepted(plan, action, content):
600
+ if not (reason := _refusal(plan, action, content)):
483
601
  return None
484
- return ToolResult(structured_content=_not_confirmed(plan))
602
+ return ToolResult(structured_content=_not_confirmed(plan, reason))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes