dsh-qianchuan-toolkit 1.0.18 → 1.0.21

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,20 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.0.21
4
+
5
+ - **`copy.mjs` 落盘根目录可配置(修硬编码作者路径)**:原第 11 行写死 `const W = 'C:/Users/admin/Documents/deepseek-harness/default-workspace'`,确认单(`qc/confirm/<计划ID>.json`)与删除前截图(`qc/confirm-<计划ID>.png`)只能写到这台机器这个目录 —— 换会话/换工作区就必然跨沙箱,每次 confirm/delete 弹一次授权;对 npm 用户则是「往不存在的 `C:\Users\admin` 写文件」。现改为 `const W = process.env.QC_WORKDIR || process.cwd()`:默认落在当前工作目录,需要固定位置时用 `QC_WORKDIR` 指定。**confirm 与 delete 必须在同一 QC_WORKDIR 下运行**,否则按「没有确认单」安全拒绝。
6
+ - **文档**:`SKILL.md` 第 6 节补登 `scripts/readmat.mjs`(1.0.20 新增但未登记),并新增「落盘位置」说明。
7
+ - 说明:1.0.19(素材滚动补选、修 `Page.navigate` 漏传 `aavid` 导致发布后空转 40s+)与 1.0.20(发布后 2s 轮询按名搜新计划)此前只提交未发版,本次随 1.0.21 一并发布。
8
+ ## 1.0.20
9
+
10
+ - copy.mjs all:发布成功后不再固定 sleep(10000),改为延迟 0.8s 就打开列表按计划名搜索;未出现则 2s 后重搜,最多 12 次(首次等 8s、后续 5s),新计划一出现立刻进详情加素材。用户 2026-11-25:越快越好,等待只用于扛网络/加载延迟。
11
+
12
+ ## 1.0.19
13
+
14
+ - pick-all.mjs:素材勾选补全。旧版每张卡只取一次坐标,取不到(弹窗第二屏/横向滚动区外的卡)就直接记 skipped 跳过——14 个抖音号主页共 135 张卡,实际只勾到 110。新版改成多轮:点完视口内的卡 → 把素材弹窗的滚动容器往前推一屏 → 再点新露出来的卡,最多 10 轮,直到没有待点卡;仍点不到的会带 chainInfo 记进 skipped 并如实汇报。根因是「没有滚动/翻页这一步」,不是选择逻辑本身。
15
+ - copy.mjs:创编后立刻找新计划。旧版 Page.navigate { url: listUrl } 漏传 aavid,URL 成了函数对象,CDP 每次都回 -32602 Invalid parameters,然后 sleep(8000),5 次循环空转 40s+(用户看到的「发布后停很久」)。新版修正为 listUrl(aavid) 并改为:发布成功 → 等 10s → 打开列表 → 按计划名搜索(命中唯一一行且含计划名)→ 从该行读 ID → 直接进详情加素材;搜索最多 3 次,失败才退回列表首行。all 子命令看门狗上限同时放宽到 900s(素材阶段本身约 90s)。
16
+ - 验证:node --check 两个文件通过;materials 重跑后逐号 delta 之和需等于页面「共N个视频」。
17
+
3
18
  ## 1.0.18
4
19
 
5
20
  - **修 `pick-all.mjs` 补点 = 取消勾选(真缺陷)**:旧版选卡只等 260ms 读「已选择 N/200」,计数没涨就再点一次同一张卡——而卡片是**开关式复选框**,二次点击等于**取消勾选**,于是出现「勾好了又取消」。新版新增单卡状态探针 `isSel(id)`(1=已选中 / 0=明确未选中 / -1=判断不出):点前已选中的直接跳过(`already`),点完只对**明确仍未选中**的补一次,判断不出的记进 `unknown[]`、**不再盲点**;每号日志新增 `clicked/already/unknown` 三项,出问题能一眼看出是哪张卡没勾上。
@@ -46,8 +46,9 @@
46
46
 
47
47
  ## 附:已知脚本缺陷(技术备忘,非守则)
48
48
 
49
- - `plan-copy/scripts/pick-all.mjs`:~~补点 = 取消勾选~~ **已在 1.0.18 修复**。旧版靠「已选择 N/200」计数补点,计数刷新慢就二次点击同一张卡(开关式复选框 → 取消勾选);现改为先读该卡自身是否已选中(`isSel`):已选中的绝不点,只对明确未选中的补一次,判断不出的只记 `unknown[]` 不再补点。
50
- - `copy.mjs materials` 在本机卡 `[75.7s] popup`,watchdog 600s 强退(exit 9);素材仍按一波流:一个弹窗、全号从上到下勾完、只点一次「确定」。
49
+ - plan-copy/scripts/pick-all.mjs:补点=取消勾选 已在 1.0.18 修复;漏勾第二屏 已在 1.0.19 修复。旧版对「视口外的卡」直接记 skipped 跳过(没有滚动这一步),14 个号只勾到 110/135。现在点完一屏后自动把素材弹窗的滚动容器推一屏再点,最多 10 轮;跑完 skipped 应为 0,不为 0 就必须带 chainInfo 如实汇报。
50
+ - copy.mjs all:创编后找新计划 ID 的 -32602 空转 已在 1.0.19 修复(Page.navigate 漏传 aavid);现在发布后固定等 10s → 按计划名搜索 → 读行内 ID → 直接进详情加素材,不再 5 次 x 8s 重试。
51
+ - copy.mjs materials 之前在本机卡在 [75.7s] popup,1.0.19 实测 90s 跑完不卡;若再次卡住按守则重开标签页重试后仍失败即报。
51
52
 
52
53
  ---
53
54
 
@@ -411,8 +412,11 @@ node scripts/pick-all.mjs "抖音号名1,抖音号名2,...,抖音号名N"
411
412
  | `scripts/capture.mjs` | 按计划 ID 抓参数(详情页抖音号/素材/ROI/预算/商品)→ 生成 `qc/params-<原ID>.json`,供 copy.mjs 直接使用 |
412
413
  | `scripts/copy.mjs` | 一条龙:`confirm`(删除前确认单+截图推送)→ `delete <TOKEN>` → `all`(新建+发布+找新ID+加素材);另有 `create/publish/materials/search/click` 子命令 |
413
414
  | `scripts/notify-media.mjs` | 确认图推送 QQ 官方机器人 + 企业微信(copy.mjs confirm 自动调用) |
415
+ | `scripts/readmat.mjs` | 读「添加视频」弹窗当前勾选状态(每号卡片数/已选数),供素材阶段核对 |
414
416
  | `scripts/start-qc.cmd` | 双击启动 Edge(9222 + 固定 profile) |
415
417
 
418
+ > **落盘位置**:确认单与删除前截图写在 `$QC_WORKDIR/qc/`(`QC_WORKDIR` 不设时用当前工作目录)。`confirm` 与 `delete` 必须在同一目录/同一 `QC_WORKDIR` 下执行,否则 delete 会以「没有确认单」拒绝;跨会话协作时两边各自指向自己的工作区即可,互不弹授权。
419
+
416
420
  用法示例:
417
421
 
418
422
  ```bash
@@ -8,7 +8,9 @@ import path from 'node:path';
8
8
  import { pickAllOnTarget } from './pick-all.mjs';
9
9
  import { connect, sleep, listPages, browserSend } from '../../live-control/scripts/cdp-lib.mjs';
10
10
 
11
- const W = 'C:/Users/admin/Documents/deepseek-harness/default-workspace';
11
+ // 确认单/截图落盘根目录:默认当前工作目录(可移植),需要固定位置时用 QC_WORKDIR 指定。
12
+ // confirm 与 delete 必须在同一个 QC_WORKDIR 下运行,否则找不到确认单。
13
+ const W = process.env.QC_WORKDIR || process.cwd();
12
14
 
13
15
  // ---------- 删除前确认单(硬闸门)----------
14
16
  // 规则(用户 2026-11-20 定):删除前必须把「搜索该计划 ID 后的单条计划截图」原文发给用户并等其确认;
@@ -22,7 +24,7 @@ const t0 = Date.now();
22
24
  let LAST = 'init';
23
25
  const mark = (l, e) => { LAST = l; console.log('[' + ((Date.now() - t0) / 1000).toFixed(1) + 's] ' + l + (e ? ' ' + e : '')); };
24
26
  // 看门狗:任何一步卡住都会打印最后一步并退出,避免静默长跑(默认 150s,可用 QC_WATCHDOG 覆盖)
25
- setTimeout(() => { console.log('[WATCHDOG] 卡在 ' + LAST + ',强制退出'); process.exit(9) }, Number(process.env.QC_WATCHDOG || 150000));
27
+ setTimeout(() => { console.log('[WATCHDOG] 卡在 ' + LAST + ',强制退出'); process.exit(9) }, Number(process.env.QC_WATCHDOG || (process.argv[2] === "all" ? 900000 : 150000)));
26
28
 
27
29
  // ---------- 通用自愈:关掉标签页重开 ----------
28
30
  // 用户 2026-11-21 确认:大多数异常(「添加视频」弹层跑到视口外、抽屉/搜索卡住)关闭标签页重开就能解决。
@@ -444,37 +446,48 @@ async function cmdMaterials() {
444
446
  mark('result', JSON.stringify({ totalVideos: res.totalVideos, submitted: res.submitted, picktest: process.argv.includes('--picktest') }));
445
447
  }
446
448
 
447
- // 一条龙:新建 → 发布 → 找新计划ID → 详情抽屉加素材
449
+ // 一条龙:新建 → 发布 → 等 10s → 按计划名搜到新计划 → 详情抽屉加素材
450
+ async function searchByName(page, name) {
451
+ for (let i = 1; i <= 3; i++) {
452
+ await focusAndType(page, PLAN_SEARCH, name)
453
+ await sleep(700)
454
+ await pressEnter(page)
455
+ const ok = await wait(page, '(() => { const trs=[...document.querySelectorAll("tbody tr")].filter(r=>(r.innerText||"").indexOf("ID:")>=0); return trs.length===1 && (trs[0].innerText||"").indexOf(' + JSON.stringify(name) + ')>=0 })()', i === 1 ? 8000 : 5000)
456
+ if (ok) return true
457
+ await sleep(800)
458
+ }
459
+ return false
460
+ }
461
+
448
462
  async function cmdAll() {
449
- const aavid = process.argv[3], paramsFile = process.argv[4];
450
- const argv0 = process.argv.slice(0, 2);
451
- process.argv = argv0.concat(['create', aavid, paramsFile]);
452
- await cmdCreate();
453
- process.argv = argv0.concat(['publish']);
454
- await cmdPublish();
455
- const page = await connectFor(aavid);
456
- await page.eval(INJECT);
457
- const wantName = JSON.parse(fs.readFileSync(paramsFile, 'utf8')).planName;
458
- let newId = null, topRow = '';
459
- for (let i = 0; i < 5; i++) {
460
- try {
461
- const p3 = await connectFor(aavid);
462
- await p3.send('Page.navigate', { url: listUrl }, 20000);
463
- } catch (e) { mark('list-nav-err', String(e.message).slice(0, 60)) }
464
- await sleep(8000);
465
- try {
466
- const p4 = await connectFor(aavid);
467
- newId = await newestPlanId(p4);
468
- topRow = await p4.eval('(() => { const tr = document.querySelector("tbody tr"); return tr ? (tr.innerText || "").replace(/\\s+/g, " ").trim() : "" })()');
469
- } catch (e) { newId = null; topRow = '' }
470
- if (newId && String(topRow).indexOf(wantName) >= 0) break;
471
- mark('new-plan-retry', i + ' ' + String(topRow).slice(0, 40));
463
+ const aavid = process.argv[3], paramsFile = process.argv[4]
464
+ const argv0 = process.argv.slice(0, 2)
465
+ process.argv = argv0.concat(['create', aavid, paramsFile])
466
+ await cmdCreate()
467
+ process.argv = argv0.concat(['publish'])
468
+ await cmdPublish()
469
+ const wantName = JSON.parse(fs.readFileSync(paramsFile, 'utf8')).planName
470
+ // 用户 2026-11-25 要求:发布后立刻按计划名搜新计划,没出现就 2s 后重搜(只等网络/加载延迟,不空等固定秒数)
471
+ await sleep(800)
472
+ const page = await connectFor(aavid)
473
+ await page.eval(INJECT)
474
+ await openList(page, aavid)
475
+ await dismissBubbles(page)
476
+ mark('list-ready')
477
+ let newId = null, rowText = ''
478
+ for (let i = 0; i < 12 && !newId; i++) {
479
+ const hit = await searchByName(page, wantName)
480
+ rowText = await page.eval('(() => { const trs=[...document.querySelectorAll("tbody tr")].filter(r=>(r.innerText||"").indexOf("ID:")>=0); return trs.length ? trs[0].innerText.replace(/\s+/g," ").trim() : "" })()')
481
+ const m = String(rowText).match(/ID[::]\s*(\d{10,})/)
482
+ if (hit && m) newId = m[1]
483
+ else { mark('new-plan-retry', i + ' ' + String(rowText).slice(0, 50)); await sleep(2000) }
472
484
  }
473
- if (!newId) throw new Error('发布后拿不到新计划 ID');
474
- if (String(topRow).indexOf(wantName) < 0) throw new Error('列表首行不是刚建的计划(首行=' + String(topRow).slice(0, 60) + ' 期望=' + wantName + ')');
475
- mark('new-plan', newId + ' ' + wantName);
476
- process.argv = argv0.concat(['materials', aavid, newId, paramsFile]);
477
- await cmdMaterials();
485
+ if (!newId) { try { newId = await newestPlanId(page) } catch (e) {} }
486
+ if (!newId) throw new Error('发布后拿不到新计划 ID(按名字搜也没有)')
487
+ if (String(rowText).indexOf(wantName) < 0) throw new Error('搜到的不是刚建的计划(行=' + String(rowText).slice(0, 60) + ' 期望=' + wantName + ')')
488
+ mark('new-plan', newId + ' ' + wantName)
489
+ process.argv = argv0.concat(['materials', aavid, newId, paramsFile])
490
+ await cmdMaterials()
478
491
  }
479
492
 
480
493
  async function cmdPublish() {
@@ -72,28 +72,42 @@ async function pollCards(c, maxMs) {
72
72
  }
73
73
 
74
74
  async function selectCards(c, ids) {
75
- let clicked = 0, retried = 0, skipped = 0, already = 0, why = null
75
+ // 多轮:不在可视区的卡(弹窗第二屏 / 横向滚动区外)先滚动让它进视野,下一轮再点,直到全部点完 —— 不允许静默 skipped
76
+ let clicked = 0, retried = 0, already = 0
76
77
  const unknown = []
77
- for (const id of ids) {
78
- const p = await ev(c, cardPos(id))
79
- if (!p || p.err || typeof p.x !== 'number') { skipped++; if (!why && p && p.err === 'noclick') why = JSON.stringify(await ev(c, chainInfo(id))); else why = why || (p && (p.err || 'bad')) + ' ' + JSON.stringify(p); continue }
80
- await sleep(120)
81
- // 已经勾上的卡绝不点:开关式复选框,二次点击=取消勾选(旧版靠「已选择 N/200」补点,计数刷新慢就会自己取消掉)
82
- if ((await ev(c, isSel(id))) === 1) { already++; continue }
83
- await click(c, p.x, p.y)
84
- clicked++
85
- let st = await waitSel(c, id, 1200)
86
- if (st !== 1) {
87
- if (st === 0) {
88
- const p2 = await ev(c, cardPos(id))
89
- if (p2 && typeof p2.x === 'number' && (await ev(c, isSel(id))) === 0) { await click(c, p2.x, p2.y); retried++; st = await waitSel(c, id, 1200) }
78
+ let pending = ids.slice()
79
+ for (let pass = 0; pass < 10 && pending.length; pass++) {
80
+ const next = []
81
+ for (const id of pending) {
82
+ const p = await ev(c, cardPos(id))
83
+ if (!p || p.err || typeof p.x !== 'number') { next.push(id); continue }
84
+ await sleep(120)
85
+ // 已经勾上的卡绝不点:开关式复选框,二次点击=取消勾选
86
+ if ((await ev(c, isSel(id))) === 1) { already++; continue }
87
+ await click(c, p.x, p.y)
88
+ clicked++
89
+ let st = await waitSel(c, id, 1200)
90
+ if (st !== 1) {
91
+ if (st === 0) {
92
+ const p2 = await ev(c, cardPos(id))
93
+ if (p2 && typeof p2.x === 'number' && (await ev(c, isSel(id))) === 0) { await click(c, p2.x, p2.y); retried++; st = await waitSel(c, id, 1200) }
94
+ }
95
+ if (st !== 1) unknown.push(id)
90
96
  }
91
- if (st !== 1) unknown.push(id)
92
97
  }
98
+ if (!next.length) { pending = []; break }
99
+ for (let k = 0; k < 2; k++) { await ev(c, scrollStep); await sleep(450) }
100
+ pending = next
93
101
  }
102
+ let why = null
103
+ const skipped = pending.length
104
+ if (skipped) { try { why = JSON.stringify(await ev(c, chainInfo(pending[0]))) } catch (e) { why = 'chainInfo-fail' } }
94
105
  return { clicked, retried, skipped, already, unknown, why }
95
106
  }
96
107
 
108
+ // 让素材弹窗里的滚动容器往前走一屏(横向那一排卡在第 2 屏,只点视口内的卡必然漏)
109
+ const scrollStep = '(()=>{const roots=[...document.querySelectorAll("[class*=create-material]")];const els=new Set();for(const r of roots){let a=r;for(let i=0;i<8&&a;i++,a=a.parentElement)els.add(a)}let n=0;for(const el of els){if(el===document.body||el===document.documentElement)continue;const rc=el.getBoundingClientRect();if(!rc||rc.width<10)continue;const s=getComputedStyle(el);if((s.overflowX==="auto"||s.overflowX==="scroll")&&el.scrollWidth>el.clientWidth+4){el.scrollLeft=Math.min(el.scrollLeft+Math.round(el.clientWidth*0.8),el.scrollWidth-el.clientWidth);n++}if((s.overflowY==="auto"||s.overflowY==="scroll")&&el.scrollHeight>el.clientHeight+4&&el.clientHeight>200){el.scrollTop=Math.min(el.scrollTop+Math.round(el.clientHeight*0.6),el.scrollHeight-el.clientHeight);n++}}return n})()'
110
+
97
111
  // 供 copy.mjs 复用:在已打开的「添加视频」弹窗里按名单逐个抖音号全选,返回结构化日志
98
112
  export async function pickAllOnTarget(target, names) {
99
113
  const c = await connect(target)
@@ -0,0 +1,27 @@
1
+ import { connect, sleep, listPages } from '../../live-control/scripts/cdp-lib.mjs'
2
+ const A = process.argv[2], ID = process.argv[3]
3
+ const pages = await listPages()
4
+ const hit = pages.find(p => p.type==='page' && (p.url||'').indexOf('overall-prom')>=0 && (p.url||'').indexOf(A)>=0)
5
+ if (!hit) { console.log(JSON.stringify({err:'no tab'})); process.exit(1) }
6
+ const c = await connect('overall-prom', { id: hit.id })
7
+ await c.send('Page.navigate', { url: 'https://qianchuan.jinritemai.com/overall-prom?aavid='+A+'&campaignType=1&uniTab=ad&uniVideoTab=1&overallPromViewTab=plan' }, 20000)
8
+ await sleep(6000)
9
+ const txt = await c.eval('document.body.innerText')
10
+ const box = await c.eval('(() => { const i=[...document.querySelectorAll("input")].find(x=>/回车搜索|计划名称|计划ID|计划 ID/.test(x.placeholder||"")); return i ? "ok" : "nobox" })()')
11
+ console.log(JSON.stringify({ step:'list', box, hasPlanView: String(txt).indexOf('计划视图')>=0 }))
12
+ await c.eval('(() => { const els=[...document.querySelectorAll("*")].filter(x=>x.children.length===0 && (x.innerText||"").trim()==="计划视图"); if(els.length) els[els.length-1].click(); const e2=[...document.querySelectorAll("*")].filter(x=>x.children.length===0 && (x.innerText||"").trim()==="商品自选"); if(e2.length) e2[e2.length-1].click(); return "clicked" })()')
13
+ await sleep(2500)
14
+ const set = '(() => { const i=[...document.querySelectorAll("input")].find(x=>/回车搜索|计划名称|计划ID|计划 ID/.test(x.placeholder||"")); if(!i) return "noinput"; i.focus(); const s=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value").set; s.call(i, ""); i.dispatchEvent(new Event("input",{bubbles:true})); s.call(i, ' + JSON.stringify(ID) + '); i.dispatchEvent(new Event("input",{bubbles:true})); return "typed" })()'
15
+ console.log(JSON.stringify({ typed: await c.eval(set) }))
16
+ await sleep(700)
17
+ await c.eval('(() => { const i=document.activeElement; const k={key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:true}; i.dispatchEvent(new KeyboardEvent("keydown",k)); i.dispatchEvent(new KeyboardEvent("keyup",k)); return "enter" })()')
18
+ await sleep(9000)
19
+ const rowsTxt = await c.eval('(() => { const trs=[...document.querySelectorAll("tbody tr")].filter(r=>(r.innerText||"").indexOf("ID:")>=0); return trs.map(r=>(r.innerText||"").replace(/\\s+/g," ").slice(0,60)) })()')
20
+ console.log(JSON.stringify({ rows: rowsTxt }))
21
+ const chip = await c.eval('(() => { const tr=[...document.querySelectorAll("tbody tr")].find(r=>(r.innerText||"").indexOf(' + JSON.stringify(ID) + ')>=0); if(!tr) return "norow"; const leaves=[...tr.querySelectorAll("*")].filter(e=>e.children.length===0 && (e.innerText||"").trim().length>0); const first=(tr.innerText||"").split(String.fromCharCode(10)).map(s=>s.trim()).filter(Boolean)[0]; const el=leaves.find(e=>e.innerText.trim()===first)||leaves.find(e=>e.innerText.trim()==="素材"); if(!el) return "nochip"; el.click(); return "ok" })()')
22
+ console.log(JSON.stringify({ chip }))
23
+ await sleep(4000)
24
+ const tabRes = await c.eval('(() => { const roots=[...document.querySelectorAll("*")].filter(e=>{const t=e.innerText||"";return t.indexOf("保障历史")>=0 && t.indexOf("素材")>=0 && t.length>100}); if(!roots.length) return "noroot"; roots.sort((a,b)=>a.innerText.length-b.innerText.length); const lv=[...roots[0].querySelectorAll("*")].filter(e=>e.children.length===0 && (e.innerText||"").trim()==="素材"); if(!lv.length) return "notab"; lv[0].click(); return "ok" })()')
25
+ await sleep(5000)
26
+ const total = await c.eval('(() => { const t=document.body.innerText; const m=t.match(/共\\d+个视频/); const m2=t.match(/已选\\d+\\/200/); return { total: m?m[0]:null, sel: m2?m2[0]:null } })()')
27
+ console.log(JSON.stringify({ tabRes, total }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qianchuan-toolkit",
3
- "version": "1.0.18",
3
+ "version": "1.0.21",
4
4
  "type": "module",
5
5
  "description": "DSH skill bundle for 巨量千川: 直播盯盘自动控量 (qianchuan-live-control) + 乘方计划复制 (qianchuan-plan-copy).",
6
6
  "license": "MIT",
@@ -46,4 +46,4 @@
46
46
  "CHANGELOG.md",
47
47
  "docs"
48
48
  ]
49
- }
49
+ }