dsh-qianchuan-toolkit 1.0.0 → 1.0.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.0.2
4
+
5
+ - 新增**小时消耗门槛**:本小时消耗必须**超过** `minCost`(默认 200 元,等于 200 也不控)才进入净成交 ROI 判定;花得少的时候控量只是白占一次控量窗口。三层覆盖照旧可改。
6
+ - 修复**分时数据漏计划**:`statQuery` 不传 `ad_id` 条件时,每天每小时只回一行主计划,其余计划被合并进 `ad_id: null` 的汇总行(值为 0),导致同一账号另一条产品线的计划被误判成「本小时 0 消耗、没花钱」。现在按该账号下目标的 adId 显式过滤(`ad_id IN (...)`),一条计划一行。
7
+ - 修复**投放状态误判**:已暂停的行常同时带「有效投放中」这类诊断字样,原来会被当成在投;改为命中「投放中」且不含「已暂停 / 未开播 / 审核中 / 预算不足 / 已结束」。
8
+ - 跨账号同名抖音号不再默认拦截:按用户指定的「一个直播间同一时间只在一个账号投放」处理,仅在该抖音号同时出现在多个账号时提示,不阻断。
9
+ - 文档与默认配置同步(`config.rules.json`、`references/01`、`references/04`、`SKILL.md`、`README`、`docs/DETAIL.md`)。
10
+
11
+ ## 1.0.1
12
+
13
+ - 修复:埋点写入失败(例如数据目录无写权限)会抛出异常并中断 `--watch` 巡航,现在只告警、不打断本轮与后续轮次。
14
+
3
15
  ## 1.0.0
4
16
 
5
17
  首次以 `dsh-qianchuan-toolkit` 发布:把原先的两个独立插件合成一个包,注册两个技能。
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  | 技能 | 干什么 |
6
6
  |---|---|
7
- | `qianchuan-live-control` | 直播盯盘 + 一键控量:在自然小时的 :15/:30/:45/:55 读分时数据,净成交 ROI 低于阈值且已经在花钱,就给该抖音号提交一键控量(默认 200 元 / 0.5 小时),提交后回读计划日志核对。 |
7
+ | `qianchuan-live-control` | 直播盯盘 + 一键控量:在自然小时的 :15/:30/:45/:55 读分时数据,当前小时消耗**超过 200 元**且净成交 ROI 低于阈值,就给该抖音号提交一键控量(默认 200 元 / 0.5 小时),提交后回读计划日志核对。 |
8
8
  | `qianchuan-plan-copy` | 乘方「推商品」计划复制:搜原计划 → 抓参数 → 确认 → 删除 → 按参数重建 → 逐抖音号全选主页素材 → 核对。 |
9
9
 
10
10
  两个技能的脚本各自独立(都在自己的 `assets/*/scripts/` 下),只依赖 Node 18+ 内置模块和一个带调试端口的浏览器。
@@ -21,7 +21,7 @@
21
21
  | 判定节点 | 每小时 **:15 / :30 / :45 / :55** | `:55` 读的是刚结束的那个小时 |
22
22
  | 数据源 | 分时报表 `statQuery` | 直接拿「这个小时」的消耗与净成交,不做差量 |
23
23
  | 判定字段 | 当前小时**净成交 ROI** | 净成交金额 ÷ 消耗 |
24
- | 触发 | ROI **< 2.40** 且该小时**已有消耗** | 消耗为 0 不控(没花钱,控了只是给空跑计划加预算) |
24
+ | 触发 | 该小时消耗 **> 200 元** 且净成交 ROI **< 2.40** | 消耗未超过 200 元不控(等于 200 也不控);没花钱更不控 |
25
25
  | 动作 | **一键控量** | 预算默认 **200 元** |
26
26
  | 时长 | **0.5 小时(平台固定,改不了)** | 弹窗里不可编辑 |
27
27
  | 轮空 | 该行已有控量在跑 | 平台不允许叠加,轮空并记住结束时间,结束后 +1 分钟加插一轮 |
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "controlHoursFixed": 0.5,
19
19
  "extraRoundAfterEndMinutes": 1,
20
- "minCost": 1,
20
+ "minCost": 200,
21
21
  "extraMetrics": []
22
22
  },
23
23
  "accounts": []
@@ -41,7 +41,7 @@
41
41
  | 8 | 净成交 ROI < `roiFloor`(默认 2.40) | **control**(预算 `budget`) | 失败才通知 |
42
42
  | 9 | 其余 | skip `roi-ok` | 否 |
43
43
 
44
- `minCost`(默认 1 元)是第 6 步的补充门槛:本小时消耗低于它同样视为「还没花钱」。
44
+ `minCost`(默认 200 元)是第 6 步的补充门槛:本小时消耗**未超过** 200 元(≤ 200)一律不控——花得少的时候控量没有意义,只会白白占用一次控量窗口。
45
45
 
46
46
  ## 4. 三层覆盖
47
47
 
@@ -22,7 +22,7 @@
22
22
  ```json
23
23
  {
24
24
  "version": 1,
25
- "defaults": { "hourly": { "nodes": [15,30,45,55], "roiFloor": 2.4, "minCost": 1, "budget": 200, "controlHours": 0.5 } },
25
+ "defaults": { "hourly": { "nodes": [15,30,45,55], "roiFloor": 2.4, "minCost": 200, "budget": 200, "controlHours": 0.5 } },
26
26
  "accounts": [
27
27
  { "key": "A", "aavid": "1860000000000001", "name": "我的全域账户", "entry": "uniprom" },
28
28
  { "key": "B", "aavid": "1860000000000002", "name": "我的乘方账户", "entry": "square" }
@@ -77,7 +77,7 @@ node scripts/targets.mjs primary A/shesiyahufu7 # 改回主力
77
77
  targets[].rules.hourly > accounts[].rules.hourly > defaults.hourly
78
78
  ```
79
79
 
80
- 可覆盖字段:`nodes`(判定的分钟节点)、`roiFloor`(净成交 ROI 低于它就控)、`minCost`(消耗低于它不控)、`budget`(控量预算)、`controlHours`。
80
+ 可覆盖字段:`nodes`(判定的分钟节点)、`roiFloor`(净成交 ROI 低于它就控)、`minCost`(小时消耗未超过它不控,默认 200 元)、`budget`(控量预算)、`controlHours`。
81
81
  例:只想给某个抖音号设 ROI 2.0、预算 300 → 在它的 `rules.hourly` 里写 `{"roiFloor":2,"budget":300}`。
82
82
 
83
83
  ## 4. CLI
@@ -68,9 +68,11 @@ async function openEntry(page, acct, say) {
68
68
  export async function ensureTabFor(acct, say = () => {}) {
69
69
  const t0 = Date.now()
70
70
  const pages = await listPages()
71
+ // 同一账号可能同时有全域与乘方两条产品线 → 标签页要按 entry 区分,否则会抢同一个标签
72
+ const wantPath = acct.entry === 'square' ? /\/overall-prom/ : /\/uni-prom/
71
73
  const hit = pages.find((p) => p.type === 'page'
72
74
  && (p.url || '').includes('aavid=' + acct.aavid)
73
- && /(uni-prom|overall-prom)/.test(p.url || '')
75
+ && wantPath.test(p.url || '')
74
76
  && !/\/detail/.test(p.url || ''))
75
77
  let page
76
78
  if (hit) {
@@ -82,7 +84,7 @@ export async function ensureTabFor(acct, say = () => {}) {
82
84
  for (let i = 0; i < 40 && !found; i++) {
83
85
  await sleep(150)
84
86
  const now = await listPages()
85
- found = now.find((p) => p.id === id || ((p.type === 'page') && (p.url || '').includes('aavid=' + acct.aavid)))
87
+ found = now.find((p) => p.id === id || ((p.type === 'page') && (p.url || '').includes('aavid=' + acct.aavid) && wantPath.test(p.url || '')))
86
88
  }
87
89
  if (!found) throw new Error('新建标签页失败(' + acct.key + ')')
88
90
  page = await connect('jinritemai', { id: found.id })
@@ -3,6 +3,18 @@
3
3
  const now = new Date()
4
4
  const day = now.getFullYear() + '-' + pad(now.getMonth() + 1) + '-' + pad(now.getDate())
5
5
  const end = day + ' ' + pad(now.getHours()) + ':' + pad(now.getMinutes()) + ':59'
6
+ // 关键:必须显式按 ad_id 过滤。不带 ad_id 条件时平台每天每小时只回一行(其余计划被合并成 ad_id=null 的汇总行),
7
+ // 乘方计划会因为不是「当小时主计划」而整行消失,导致误判成 0 消耗。
8
+ const ads = {{ADS}}
9
+ const conds = [
10
+ { Field: 'advertiser_id', Operator: 7, Values: ['{{ADV}}'] },
11
+ { Field: 'pricing_category', Operator: 7, Values: ['2'] },
12
+ { Field: 'marketing_goal', Operator: 7, Values: ['2'] },
13
+ { Field: 'ecp_app_id', Operator: 7, Values: ['1'] },
14
+ { Field: 'campaign_type', Operator: 7, Values: ['1'] },
15
+ { Field: 'adlab_mode', Operator: 7, Values: ['1'] },
16
+ ]
17
+ if (ads.length) conds.push({ Field: 'ad_id', Operator: 7, Values: ads })
6
18
  const body = {
7
19
  Dimensions: ['stat_time_hour', 'ad_id'],
8
20
  StartTime: day + ' 00:00:00',
@@ -10,13 +22,7 @@
10
22
  OrderBy: [{ Type: 1, Field: 'stat_time_hour' }],
11
23
  DataSetKey: 'site_promotion_post_overview',
12
24
  Metrics: ['stat_cost', 'total_prepay_and_pay_settle_roi2_1h', 'total_order_settle_amount_for_roi2_1h', 'total_order_settle_count_for_roi2_1h'],
13
- Filters: { ConditionRelationshipType: 1, Conditions: [
14
- { Field: 'advertiser_id', Operator: 7, Values: ['{{ADV}}'] },
15
- { Field: 'pricing_category', Operator: 7, Values: ['2'] },
16
- { Field: 'marketing_goal', Operator: 7, Values: ['2'] },
17
- { Field: 'ecp_app_id', Operator: 7, Values: ['1'] },
18
- { Field: 'campaign_type', Operator: 7, Values: ['1'] },
19
- { Field: 'adlab_mode', Operator: 7, Values: ['1'] }] },
25
+ Filters: { ConditionRelationshipType: 1, Conditions: conds },
20
26
  refer: '', FilterParams: {}
21
27
  }
22
28
  const t0 = Date.now()
@@ -22,7 +22,8 @@
22
22
  return {
23
23
  aweme: c(td[iAweme] && td[iAweme].innerText).slice(0, 26),
24
24
  status: c(td[iStatus] && td[iStatus].innerText).slice(0, 26),
25
- live: /投放中/.test(c(td[iStatus] && td[iStatus].innerText)) && !/未开播/.test(c(td[iStatus] && td[iStatus].innerText)),
25
+ // 「已暂停」行常附带「有效投放中」这类诊断字样,必须用否定词兜住,否则会把暂停行当成在投
26
+ live: (() => { const s = c(td[iStatus] && td[iStatus].innerText); return /投放中/.test(s) && !/已暂停|未开播|审核中|预算不足|已结束/.test(s) })(),
26
27
  hasPause: names.includes('iconPauseFilled'),
27
28
  hasPlus: names.includes('oc-icon-plus'),
28
29
  tools: groupsOf(toolCell).map(labelOf),
@@ -155,7 +155,8 @@ async function gatherAccount(group) {
155
155
 
156
156
  log(' [' + acct.key + '] 查分时数据…')
157
157
  t = Date.now()
158
- const data = JSON.parse(await page.eval(expr('hourly-data.js', { '{{ADV}}': acct.aavid })))
158
+ const groupAds = [...new Set(group.targets.flatMap((x) => x.ads || []).map(String).filter((id) => /^\d{6,}$/.test(id)))]
159
+ const data = JSON.parse(await page.eval(expr('hourly-data.js', { '{{ADV}}': acct.aavid, '{{ADS}}': JSON.stringify(groupAds) })))
159
160
  stage.queryMs = Date.now() - t
160
161
  if (!data.rows) { out.err = 'no-data'; stage.totalMs = Date.now() - t0; return out }
161
162
  out.day = data.day
@@ -30,18 +30,20 @@ eq('resolveRule 目标层 + 节点排序', [rT.nodes, rT.roiFloor, rT.budget], [
30
30
  eq('resolveRule 非法节点被过滤', resolveRule(CFG, { account: 'A', rules: { hourly: { nodes: [0, 60, 15, '30'] } } }).nodes, [15, 30])
31
31
 
32
32
  /* ---------- 2. judgeHourly:自然小时判定 ---------- */
33
- const R = { roiFloor: 2.4, minCost: 1, budget: 200, controlHours: 0.5 }
33
+ const R = { roiFloor: 2.4, minCost: 200, budget: 200, controlHours: 0.5 }
34
34
  const H = (rows) => ({ hour: '2026-11-19 09:00', rows })
35
35
  eq('没花钱 -> no-spend', judgeHourly({}, H([{ cost: 0, gmv: 0, orders: 0 }]), R).reason, 'no-spend')
36
36
  eq('没数据行 -> no-data', judgeHourly({}, H([]), R).reason, 'no-data')
37
- eq('ROI 1.08 < 2.4 -> 控 200', judgeHourly({}, H([{ cost: 129.46, gmv: 109, orders: 1 }]), R),
38
- { cost: 129.46, gmv: 109, orders: 1, roi: 0.84, action: 'control', budget: 200, hours: 0.5 })
39
- eq('ROI 恰好 2.4 -> 不控', judgeHourly({}, H([{ cost: 100, gmv: 240, orders: 1 }]), R).action, 'skip')
40
- eq('ROI 3.40 -> 不控', judgeHourly({}, H([{ cost: 169.34, gmv: 575.76, orders: 3 }]), R).reason, 'roi-ok')
41
- eq('消耗低于 minCost -> 不控', judgeHourly({}, H([{ cost: 0.5, gmv: 0, orders: 0 }]), { ...R, minCost: 1 }).reason, 'below-min-cost')
42
- eq('多计划汇总成抖音号', judgeHourly({}, H([{ cost: 100, gmv: 100, orders: 1 }, { cost: 100, gmv: 300, orders: 2 }]), R),
43
- { cost: 200, gmv: 400, orders: 3, roi: 2, action: 'control', budget: 200, hours: 0.5 })
44
- eq('预算跟随目标覆盖值', judgeHourly({}, H([{ cost: 50, gmv: 10, orders: 1 }]), { ...R, budget: 300 }).budget, 300)
37
+ eq('ROI 0.50 且消耗 500 -> 控 200', judgeHourly({}, H([{ cost: 500, gmv: 250, orders: 2 }]), R),
38
+ { cost: 500, gmv: 250, orders: 2, roi: 0.5, action: 'control', budget: 200, hours: 0.5 })
39
+ eq('ROI 恰好 2.4 -> 不控', judgeHourly({}, H([{ cost: 500, gmv: 1200, orders: 4 }]), R).action, 'skip')
40
+ eq('ROI 3.40 -> 不控', judgeHourly({}, H([{ cost: 500, gmv: 1700, orders: 5 }]), R).reason, 'roi-ok')
41
+ eq('消耗 150 低于 minCost 200 -> 不控', judgeHourly({}, H([{ cost: 150, gmv: 100, orders: 1 }]), R).reason, 'below-min-cost')
42
+ eq('消耗恰好 200 -> 不控(要严格超过 200)', judgeHourly({}, H([{ cost: 200, gmv: 100, orders: 1 }]), R).reason, 'below-min-cost')
43
+ eq('消耗 200.01 -> 进入 ROI 判定', judgeHourly({}, H([{ cost: 200.01, gmv: 100, orders: 1 }]), R).action, 'control')
44
+ eq('多计划汇总成抖音号', judgeHourly({}, H([{ cost: 150, gmv: 150, orders: 1 }, { cost: 150, gmv: 450, orders: 2 }]), R),
45
+ { cost: 300, gmv: 600, orders: 3, roi: 2, action: 'control', budget: 200, hours: 0.5 })
46
+ eq('预算跟随目标覆盖值', judgeHourly({}, H([{ cost: 300, gmv: 10, orders: 1 }]), { ...R, budget: 300 }).budget, 300)
45
47
 
46
48
  /* ---------- 3. deliveringAccount / standby:同名抖音号谁在投 ---------- */
47
49
  eq('主力无备用 -> null', deliveringAccount(CFG, CFG.targets[0]), null)
File without changes
@@ -29,7 +29,7 @@ export const paths = () => {
29
29
  }
30
30
  }
31
31
 
32
- const DEFAULT_HOURLY = { nodes: [15, 30, 45, 55], roiFloor: 2.4, minCost: 1, budget: 200, controlHours: 0.5, extraRoundAfterEndMinutes: 1 }
32
+ const DEFAULT_HOURLY = { nodes: [15, 30, 45, 55], roiFloor: 2.4, minCost: 200, budget: 200, controlHours: 0.5, extraRoundAfterEndMinutes: 1 }
33
33
 
34
34
  function readJson(p, dflt) {
35
35
  try { return JSON.parse(fs.readFileSync(p, 'utf8')) } catch (e) { return dflt }
@@ -124,8 +124,13 @@ export function groupByAccount(cfg) {
124
124
  }
125
125
 
126
126
  export function appendJsonl(file, obj) {
127
- fs.mkdirSync(path.dirname(file), { recursive: true })
128
- fs.appendFileSync(file, JSON.stringify(obj) + '\n')
127
+ // 埋点写失败不能打断巡航:只告警,不抛出
128
+ try {
129
+ fs.mkdirSync(path.dirname(file), { recursive: true })
130
+ fs.appendFileSync(file, JSON.stringify(obj) + '\n')
131
+ } catch (e) {
132
+ console.error('埋点写入失败(已忽略):' + file + ' — ' + e.message)
133
+ }
129
134
  }
130
135
 
131
136
  /** 判定:一个抖音号当前小时的聚合 */
@@ -138,7 +143,8 @@ export function judgeHourly(target, hour, rule) {
138
143
  const roi = cost > 0 ? gmv / cost : 0
139
144
  const base = { cost: round2(cost), gmv: round2(gmv), orders, roi: round2(roi) }
140
145
  if (cost <= 0) return { ...base, action: 'skip', reason: 'no-spend' }
141
- if (cost < rule.minCost) return { ...base, action: 'skip', reason: 'below-min-cost' }
146
+ // 小时消耗必须「超过」minCost 才做 ROI 判定(等于不算,避免边界抖动)
147
+ if (cost <= rule.minCost) return { ...base, action: 'skip', reason: 'below-min-cost' }
142
148
  if (roi < rule.roiFloor) return { ...base, action: 'control', budget: rule.budget, hours: rule.controlHours }
143
149
  return { ...base, action: 'skip', reason: 'roi-ok' }
144
150
  }
File without changes
package/docs/DETAIL.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  每个自然小时的 :15 / :30 / :45 / :55 各跑一次;`:55` 读刚结束的那个小时。命中顺序:备用账号 → 找不到行 → 已有控量 → 未投放 → 无 ad → 本小时没消耗 → 跨账号歧义 → ROI 低于阈值(控)→ 其余跳过。
23
23
 
24
- 「消耗为 0 不控」是硬规则:没花钱的时候控量只会给没跑起来的计划追加预算。
24
+ 「消耗为 0 不控」是硬规则;更进一步,本小时消耗**未超过 `minCost`(默认 200 元,等于 200 也不控)**时同样跳过——花得少的时候控量只会白占一次控量窗口,还可能给空跑计划追加预算。
25
25
 
26
26
  ## 执行与核对
27
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qianchuan-toolkit",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "DSH skill bundle for 巨量千川: 直播盯盘自动控量 (qianchuan-live-control) + 乘方计划复制 (qianchuan-plan-copy).",
6
6
  "license": "MIT",