投放优化运行机制How the ad-ops loop runs
多个广告渠道共用的一套循环。四条保证全部由文件与脚本承担,不依赖 AI「记得」。图中为示意,不含任何真实账户与数据。为什么这样拆,见「上下文结构」。One loop shared by every ad channel. All four guarantees are carried by files and scripts, not by the AI remembering. Diagrams are illustrative; no real accounts or data. For the reasoning, see "Context structure".
01一次「看下广告」实际发生什么What "check the ads" actually does
你提问 → hook 先把状态塞进上下文 → AI 只读两份短规则 → 跑脚本出表 → 解释。操作流水不在路径上。You ask → a hook injects the state first → the AI reads two short rule files → runs a script → explains. The operations log is not on the path.
sequenceDiagram
autonumber
participant U as 你
participant H as hook<br/>context_brief
participant C as AI agent
participant S as state.json<br/>todo / outcomes
participant B as daily_review<br/>(后端数据)
participant G as 广告平台 API
U->>H: 「看下昨天的广告」
H->>S: 读快照 / 待办 / 上次效果
H-->>C: 注入 ≤40 行简报
Note over C: 只加载两份规则文件<br/>合计约 140 行
C->>B: --campaign … --days 14 --mark 改动日
B-->>C: 分日表(双口径·成熟标注)
C->>G: 展示/点击/CTR/CPC 按组
C-->>U: 分日表 → 趋势 → 结论 → 建议动作(不执行)
Note over C,S: 不回写操作记录;<br/>到期待办顺手给结论
02文件层:谁写、谁读、常驻还是按需File layers: who writes, who reads, always-on or on demand
flowchart LR
subgraph always[每次会话自动加载]
R[根规则<br/>≈90 行]
A[投放通用规则<br/>≈60 行]
M[渠道规则<br/>≤90 行]
end
subgraph inject[hook 按需注入 ≤40 行]
ST[state.json<br/>在管快照·旋钮现值·最近改动]
TD[todo.jsonl<br/>待办·到期]
OC[outcomes.jsonl<br/>同旋钮上次效果]
end
subgraph ondemand[按需读]
W[wiki/<br/>API 坑·版位·案例·研究存档]
KB[跨渠道结论]
OP[ops.jsonl · 操作记录<br/>流水,只在追因果时翻]
BI[口径唯一真相源]
end
REC[record.py<br/>唯一写入口] -- 追加 --> OP
REC -- 覆盖 --> ST
REC -- 自动生成复盘待办 --> TD
OUT[outcome.py] -- 算前后 7 天 --> OC
OUT -- 标 done --> TD
DR[daily_review.py] -. 实现 .-> BI
style REC fill:#E8804A,color:#15191C,stroke:none
style OUT fill:#E8804A,color:#15191C,stroke:none
03动作 → 效果 → 下次决策Action → outcome → next decision
每个动作在写入时就预约了自己的复盘;复盘由脚本算;结果在下次要动同一旋钮时自动出现。Every action books its own review when logged; the review is computed by script; the result surfaces the next time the same knob is touched.
flowchart TB
D0[你确认动作] --> X[执行脚本<br/>读回验证]
X --> R[record.py]
R --> O1[ops.jsonl<br/>id · 字段 · 旧→新 · 原因]
R --> T1[todo:+7 天效果复盘]
T1 -- 到期 / lint 催 --> OC[outcome.py]
OC -- 前后 7 天<br/>+ 同期大盘对照 --> O2[outcomes.jsonl<br/>成本·量·付费率·回收]
O2 -- 同窗口多动作<br/>自动标不可拆 --> O2
O2 -- 下次提问 --> H[hook 简报:<br/>「上次这样改:<br/>成本 −x%,回收在掉」]
H --> D1[下一次决策]
O2 -. 月度蒸馏 .-> KB[动作效果账本]
style OC fill:#E8804A,color:#15191C,stroke:none
style H fill:#5BC08F,color:#15191C,stroke:none
04四条保证各靠什么What enforces each guarantee
读Reads hook提问命中投放关键词就注入快照。跳不过。Any ads question injects the snapshot. Cannot be skipped.
UserPromptSubmit → context_brief.py
UserPromptSubmit → context_brief.py
写Records 代码账户改动必经 record.py;该记什么由代码决定。Every change goes through record.py; what gets recorded is decided by code.
ops.jsonl + 操作记录 + state.json
ops.jsonl + 操作记录 + state.json
学Learns 代码 + hook效果由 outcome.py 算,下次动同旋钮前自动出现。Outcomes are computed by outcome.py and surface before the same knob is touched again.
outcomes.jsonl → 简报
outcomes.jsonl → 简报
一致Consistent lint快照落后流水、待办过期、未复盘、超行数、明文凭证。Snapshot behind log, overdue todos, unreviewed actions, oversized rules, plaintext secrets.
晨检末尾自动跑runs at the end of every daily check
晨检末尾自动跑runs at the end of every daily check
05上下文负担前后Context cost, before and after
| 一次日常检查起手Starting one daily check | 重构前Before | 现在Now |
|---|---|---|
| 自动加载的规则Rules loaded per session | 约 1,200 行,三个文件~1,200 lines, three files | 230 行lines |
| 标的与最近改动What's live, what changed | 读 300 行操作流水,脑内合并Read a 300-line log, merge mentally | hook 注入 ≤40 行≤40 lines injected |
| 分日表Daily table | 每次重写查询Query rewritten each time | daily_review.py 一条命令one command |
| 上次动作的效果Effect of the last action | 不存在Didn't exist | outcomes.jsonl,自动注入auto-injected |
| 口径规则副本Copies of metric rules | ≥6 份copies | 1 份 + 代码+ code |
| 估算 tokenEstimated tokens | ~50k | ~10k |
06目录Directory layout
投放/ ├── CLAUDE.md 通用循环 · 四条保证 · 渠道入口 ├── _kb/ 跨渠道结论 ├── google/ CLAUDE.md + wiki/ │ ├── dg/ CLAUDE.md · state.json · todo.jsonl · ops.jsonl · outcomes.jsonl · 操作记录.md · wiki/ │ ├── search/ CLAUDE.md · state.json · todo.jsonl · keyword_操作记录.json · wiki/ ├── bing/ yandex/ affiliates/ 各自 CLAUDE.md · state.json · todo.jsonl utils/bi/ CLAUDE.md(口径真相源)· daily_review.py utils/ops/ context_brief.py · record.py · outcome.py · lint.py .claude/ settings.json(hook)· skills/morning-*(各 ≤17 行)