Compare commits

...

2 Commits

Author SHA1 Message Date
wuyang 5e7cae0bee Show waiting tasks accurately in operations views 2026-11-05 11:02:42 +08:00
wuyang f882c9a831 Use active work queue for weekly priorities 2026-11-04 17:42:20 +08:00
5 changed files with 45 additions and 7 deletions
+3 -3
View File
@@ -122,7 +122,7 @@ async function openOverview() {
const works = el('section', undefined, 'report-section'); works.append(el('h2', '已发布作品'), el('p', `采样时间:${market.observed_at ? dateTime(market.observed_at) : '暂无'};播放量不是曝光或完播率。`, 'muted')); const works = el('section', undefined, 'report-section'); works.append(el('h2', '已发布作品'), el('p', `采样时间:${market.observed_at ? dateTime(market.observed_at) : '暂无'};播放量不是曝光或完播率。`, 'muted'));
for (const v of market.account_videos || []) { const p = el('p'); if (v.bvid) { const a = el('a', v.title); a.href = `https://www.bilibili.com/video/${v.bvid}/`; a.target = '_blank'; a.rel = 'noopener noreferrer'; p.append(a); } else p.append(el('span', v.title)); p.append(document.createTextNode(` · 播放 ${v.views ?? '未知'} · 点赞 ${v.likes ?? '未知'} · 评论 ${v.comments ?? '未知'}`)); works.append(p); } host.append(works); for (const v of market.account_videos || []) { const p = el('p'); if (v.bvid) { const a = el('a', v.title); a.href = `https://www.bilibili.com/video/${v.bvid}/`; a.target = '_blank'; a.rel = 'noopener noreferrer'; p.append(a); } else p.append(el('span', v.title)); p.append(document.createTextNode(` · 播放 ${v.views ?? '未知'} · 点赞 ${v.likes ?? '未知'} · 评论 ${v.comments ?? '未知'}`)); works.append(p); } host.append(works);
const budget = el('section', undefined, 'report-section'); budget.append(el('h2', '计划投入'), el('p', (strategy.budget || []).map(x => `${x.name} ${x.percent}%`).join(' · ')), el('p', strategy.budget_note || '', 'muted')); host.append(budget); const budget = el('section', undefined, 'report-section'); budget.append(el('h2', '计划投入'), el('p', (strategy.budget || []).map(x => `${x.name} ${x.percent}%`).join(' · ')), el('p', strategy.budget_note || '', 'muted')); host.append(budget);
const work = el('section', undefined, 'report-section'); work.append(el('h2', '持续工作')); const cats = {content:'内容',engineering:'工程',research:'研究',community:'社区',management:'管理'}, status = {pending:'待继续',running:'进行中',done:'已完成',blocked:'需要处理'}, list = el('ul'); for (const t of queue.tasks || []) if (t.status !== 'done') list.append(el('li', `${cats[t.category] || '管理'} · ${t.title} · ${status[t.status] || t.status}`)); work.append(list); host.append(work); const work = el('section', undefined, 'report-section'); work.append(el('h2', '持续工作')); const cats = {content:'内容',engineering:'工程',research:'研究',community:'社区',management:'管理'}, status = {pending:'待执行',running:'进行中',waiting:'等待触发条件',done:'已完成',blocked:'需要处理'}, list = el('ul'); for (const t of queue.tasks || []) if (t.status !== 'done') list.append(el('li', `${cats[t.category] || '管理'} · ${t.title} · ${status[t.status] || t.status}`)); work.append(list); host.append(work);
const trends = el('section', undefined, 'report-section'); trends.append(el('h2', 'B 站公开榜单快照'), el('p', '单时点观察,基于标题和公开数据,不能代表趋势或保证效果。', 'muted')); const ul = el('ul'); for (const v of market.ranking || []) { const li = el('li'); if (v.bvid) { const a = el('a', v.title); a.href = `https://www.bilibili.com/video/${v.bvid}/`; a.target = '_blank'; a.rel = 'noopener noreferrer'; li.append(a); } else li.append(el('span', v.title)); li.append(document.createTextNode(` · ${v.owner} · ${v.views ?? '未知'} 播放`)); ul.append(li); } trends.append(ul); host.append(trends); const trends = el('section', undefined, 'report-section'); trends.append(el('h2', 'B 站公开榜单快照'), el('p', '单时点观察,基于标题和公开数据,不能代表趋势或保证效果。', 'muted')); const ul = el('ul'); for (const v of market.ranking || []) { const li = el('li'); if (v.bvid) { const a = el('a', v.title); a.href = `https://www.bilibili.com/video/${v.bvid}/`; a.target = '_blank'; a.rel = 'noopener noreferrer'; li.append(a); } else li.append(el('span', v.title)); li.append(document.createTextNode(` · ${v.owner} · ${v.views ?? '未知'} 播放`)); ul.append(li); } trends.append(ul); host.append(trends);
} catch (error) { host.replaceChildren(el('p', error.message, 'error')); } } catch (error) { host.replaceChildren(el('p', error.message, 'error')); }
} }
@@ -144,7 +144,7 @@ async function openExecution(updateHistory = true) {
} }
const schedules = el('section', undefined, 'report-section'); schedules.append(el('h2', '服务与计划'), el('p', '有待执行任务且运行条件满足时,守护程序约每两分钟尝试启动;下方为额外的固定时刻。', 'muted')); const list = el('ul'); const schedules = el('section', undefined, 'report-section'); schedules.append(el('h2', '服务与计划'), el('p', '有待执行任务且运行条件满足时,守护程序约每两分钟尝试启动;下方为额外的固定时刻。', 'muted')); const list = el('ul');
for (const u of data.units || []) list.append(el('li', `${u.label} · ${u.state === 'activating' || u.state === 'active' ? '正在运行' : u.state === 'inactive' ? '当前空闲' : u.state || '未知'} · 定时器${u.timer_state === 'active' ? '已启用' : u.timer_state || '未知'} · 下次固定时刻 ${u.next_run || '未知'} · 上次结果 ${u.result || '暂无'}`)); schedules.append(list); host.append(schedules); for (const u of data.units || []) list.append(el('li', `${u.label} · ${u.state === 'activating' || u.state === 'active' ? '正在运行' : u.state === 'inactive' ? '当前空闲' : u.state || '未知'} · 定时器${u.timer_state === 'active' ? '已启用' : u.timer_state || '未知'} · 下次固定时刻 ${u.next_run || '未知'} · 上次结果 ${u.result || '暂无'}`)); schedules.append(list); host.append(schedules);
const tasks = el('section', undefined, 'report-section'); tasks.append(el('h2', '任务列表')); const status = {pending:'待执行或等待退避',running:'已领取',done:'已完成',blocked:'已阻塞'}; const ul = el('ul'); for (const t of queue.tasks || []) ul.append(el('li', `${t.title} · ${status[t.status] || t.status} · 尝试 ${t.attempts} 次 · ${t.updated_at ? dateTime(t.updated_at) : '时间未知'}`)); tasks.append(ul); host.append(tasks); const tasks = el('section', undefined, 'report-section'); tasks.append(el('h2', '任务列表')); const status = {pending:'待执行',running:'已领取',waiting:'等待触发条件',done:'已完成',blocked:'已阻塞'}; const ul = el('ul'); for (const t of queue.tasks || []) ul.append(el('li', `${t.title} · ${status[t.status] || t.status} · 尝试 ${t.attempts} 次 · ${t.updated_at ? dateTime(t.updated_at) : '时间未知'}`)); tasks.append(ul); host.append(tasks);
const past = el('section', undefined, 'report-section'); past.append(el('h2', '主运营执行历史'), el('p', '记录来自每轮执行汇总;进程成功不代表整个任务已经完成。详细产出和复盘见每日计划与复盘。', 'muted')); const past = el('section', undefined, 'report-section'); past.append(el('h2', '主运营执行历史'), el('p', '记录来自每轮执行汇总;进程成功不代表整个任务已经完成。详细产出和复盘见每日计划与复盘。', 'muted'));
const results = {complete:'进程成功',failed:'失败',timeout:'超时',incomplete:'未记录进度',preflight_failed:'前置检查失败',unknown:'状态未知'}; const rows = el('ul'); for (const x of data.history || []) rows.append(el('li', `${dateTime(x.started_at)} · ${x.title} · ${results[x.status] || '未知'}${x.elapsed_seconds === null ? '' : ` · ${x.elapsed_seconds} 秒`}`)); if (!(data.history || []).length) rows.append(el('li', '暂无执行汇总')); past.append(rows); host.append(past); const results = {complete:'进程成功',failed:'失败',timeout:'超时',incomplete:'未记录进度',preflight_failed:'前置检查失败',unknown:'状态未知'}; const rows = el('ul'); for (const x of data.history || []) rows.append(el('li', `${dateTime(x.started_at)} · ${x.title} · ${results[x.status] || '未知'}${x.elapsed_seconds === null ? '' : ` · ${x.elapsed_seconds} 秒`}`)); if (!(data.history || []).length) rows.append(el('li', '暂无执行汇总')); past.append(rows); host.append(past);
} catch (error) { host.replaceChildren(el('p', error.message, 'error')); } } catch (error) { host.replaceChildren(el('p', error.message, 'error')); }
@@ -160,7 +160,7 @@ async function openDaily() {
const queue = await api('/api/workqueue'); const queue = await api('/api/workqueue');
const work = el('section', undefined, 'report-section'); const work = el('section', undefined, 'report-section');
work.append(el('h2', '持续工作')); work.append(el('h2', '持续工作'));
const status = { pending: '待继续', running: '进行中', done: '已完成', blocked: '需要处理' }; const status = { pending: '待执行', running: '进行中', waiting: '等待触发条件', done: '已完成', blocked: '需要处理' };
const tasks = Array.isArray(queue.tasks) ? queue.tasks : []; const tasks = Array.isArray(queue.tasks) ? queue.tasks : [];
if (!tasks.length) work.append(el('p', '暂无任务。', 'muted')); if (!tasks.length) work.append(el('p', '暂无任务。', 'muted'));
else { const list = el('ul'); for (const task of tasks) list.append(el('li', `${task.title} · ${status[task.status] || task.status} · ${task.updated_at ? dateTime(task.updated_at) : '时间待确认'}`)); work.append(list); } else { const list = el('ul'); for (const task of tasks) list.append(el('li', `${task.title} · ${status[task.status] || task.status} · ${task.updated_at ? dateTime(task.updated_at) : '时间待确认'}`)); work.append(list); }
+2 -2
View File
@@ -164,10 +164,10 @@ export function createApp(options = process.env) {
if (req.method === 'GET' && route === '/api/workqueue') { if (req.method === 'GET' && route === '/api/workqueue') {
const value = await jsonFile('workqueue.json', { schema: 1, tasks: [] }); const value = await jsonFile('workqueue.json', { schema: 1, tasks: [] });
if (value?.schema !== 1 || !Array.isArray(value.tasks)) return json(res, 500, { error: '工作队列格式无效' }); if (value?.schema !== 1 || !Array.isArray(value.tasks)) return json(res, 500, { error: '工作队列格式无效' });
const valid = new Set(['pending', 'running', 'done', 'blocked']); const valid = new Set(['pending', 'running', 'waiting', 'done', 'blocked']);
const categories = new Set(['content', 'engineering', 'research', 'community', 'management']); const categories = new Set(['content', 'engineering', 'research', 'community', 'management']);
const tasks = value.tasks.filter(t => t && typeof t.id === 'string' && typeof t.title === 'string' && valid.has(t.status)) const tasks = value.tasks.filter(t => t && typeof t.id === 'string' && typeof t.title === 'string' && valid.has(t.status))
.map(t => ({ title: t.id.startsWith('interaction-') ? '核查新互动' : t.title.slice(0, 100), status: t.status, .map(t => ({ title: t.id.startsWith('interaction-') ? '核查新互动' : t.title.slice(0, 100), status: t.status === 'pending' && t.dispatch_ready !== true ? 'waiting' : t.status,
category: categories.has(t.category) ? t.category : 'management', attempts: Number.isInteger(t.attempts) ? t.attempts : 0, updated_at: typeof t.updated_at === 'string' ? t.updated_at : null })); category: categories.has(t.category) ? t.category : 'management', attempts: Number.isInteger(t.attempts) ? t.attempts : 0, updated_at: typeof t.updated_at === 'string' ? t.updated_at : null }));
return json(res, 200, { tasks }); return json(res, 200, { tasks });
} }
+16
View File
@@ -194,3 +194,19 @@ test('execution status is private and absent data degrades safely', async t => {
const data = await (await request('/api/execution', { headers:{cookie} })).json(); const data = await (await request('/api/execution', { headers:{cookie} })).json();
assert.equal(data.history[0].title, '任务'); assert.equal(data.history[0].status, 'complete'); assert.equal(data.history[0].title, '任务'); assert.equal(data.history[0].status, 'complete');
}); });
test('waiting queue tasks remain visible to the owner', async t => {
const { directory, request, login } = await fixture(t);
await writeFile(path.join(directory, 'workqueue.json'), JSON.stringify({schema:1,tasks:[{id:'idea',title:'等待素材',status:'waiting'}]}));
const cookie=(await login()).headers.get('set-cookie').split(';')[0];
const result=await (await request('/api/workqueue',{headers:{cookie}})).json();
assert.equal(result.tasks[0].status,'waiting');
});
test('legacy pending tasks are not presented as ready to dispatch', async t => {
const { directory, request, login } = await fixture(t);
await writeFile(path.join(directory,'workqueue.json'),JSON.stringify({schema:1,tasks:[{id:'old',title:'旧任务',status:'pending'}]}));
const cookie=(await login()).headers.get('set-cookie').split(';')[0];
const value=await (await request('/api/workqueue',{headers:{cookie}})).json();
assert.equal(value.tasks[0].status,'waiting');
});
+12 -2
View File
@@ -193,6 +193,7 @@ def build_report(data_dir, snapshot=False, now=None):
ledger = read_json(data_dir / 'ledger.json', {'entries': []}) ledger = read_json(data_dir / 'ledger.json', {'entries': []})
content = read_json(data_dir / 'content.json', {'items': []}) content = read_json(data_dir / 'content.json', {'items': []})
tasks = read_json(data_dir / 'tasks.json', {'items': []}) tasks = read_json(data_dir / 'tasks.json', {'items': []})
queue = read_json(data_dir / 'workqueue.json', None)
findings = read_json(data_dir / 'findings.json', {}) findings = read_json(data_dir / 'findings.json', {})
api = read_json(data_dir / 'deepseek-usage.json', {}) api = read_json(data_dir / 'deepseek-usage.json', {})
entries = [] entries = []
@@ -230,6 +231,15 @@ def build_report(data_dir, snapshot=False, now=None):
if not observed_this_period(findings.get('checked_at')): if not observed_this_period(findings.get('checked_at')):
risks.append('基础验收记录未在本周期更新,历史成果未重复计作本周完成。') risks.append('基础验收记录未在本周期更新,历史成果未重复计作本周完成。')
current = next((i for i in tasks.get('items', []) if i.get('status') == 'in_progress'), None) current = next((i for i in tasks.get('items', []) if i.get('status') == 'in_progress'), None)
next_actions = [i['title'] for i in tasks.get('items', []) if i.get('status') in ('todo', 'in_progress')][:8]
# A task queue is a current snapshot; it does not reconstruct the past reporting period.
if isinstance(queue, dict) and queue.get('schema') == 1 and isinstance(queue.get('tasks'), list):
safe = [i for i in queue['tasks'] if isinstance(i, dict) and i.get('status') in ('pending', 'running', 'waiting', 'blocked') and isinstance(i.get('title'), str) and isinstance(i.get('id'), str)]
safe = [{**i, 'status': 'waiting' if i['status'] == 'pending' and i.get('dispatch_ready') is not True else i['status']} for i in safe]
safe.sort(key=lambda i: (0 if i['status'] == 'running' else 1 if i['status'] == 'pending' else 2 if i['status'] == 'waiting' else 3, i.get('updated_at') or ''))
next_actions = [('核查新互动' if i['id'].startswith('interaction-') else i['title'][:100]) + ('(已阻塞)' if i['status'] == 'blocked' else '(等待触发条件)' if i['status'] == 'waiting' else '') for i in safe[:8]]
current = next(({'title': '核查新互动' if i['id'].startswith('interaction-') else i['title'][:100]} for i in safe if i['status'] == 'running'), None)
identifier = end.strftime('%G-W%V') + ('-snapshot-' + now.strftime('%Y%m%dT%H%M%S') if snapshot else '') identifier = end.strftime('%G-W%V') + ('-snapshot-' + now.strftime('%Y%m%dT%H%M%S') if snapshot else '')
report = { report = {
'id': identifier, 'id': identifier,
@@ -239,7 +249,7 @@ def build_report(data_dir, snapshot=False, now=None):
'summary': ('当前推进:' + current['title']) if current else '根据已归档的项目记录汇总;缺失数据保留待核算。', 'summary': ('当前推进:' + current['title']) if current else '根据已归档的项目记录汇总;缺失数据保留待核算。',
'highlights': highlights, 'highlights': highlights,
'risks': risks, 'risks': risks,
'next_actions': [i['title'] for i in tasks.get('items', []) if i.get('status') in ('todo', 'in_progress')][:8], 'next_actions': next_actions,
'decisions': findings.get('decisions', []), 'decisions': findings.get('decisions', []),
'metrics': { 'metrics': {
'published_project_videos': len(published), 'published_project_videos': len(published),
@@ -260,7 +270,7 @@ def build_report(data_dir, snapshot=False, now=None):
}, },
'revenue': {'settled_cny': round(sum(e['amount'] for e in incomes), 2) if incomes else None, 'estimated_cny': None, 'revenue': {'settled_cny': round(sum(e['amount'] for e in incomes), 2) if incomes else None, 'estimated_cny': None,
'notes': ['播放量不是结算收入,自有产品推广稿件是否纳入激励需单独验证。', '未结算或未归因到PawPlay的收益不算项目收入。']}, 'notes': ['播放量不是结算收入,自有产品推广稿件是否纳入激励需单独验证。', '未结算或未归因到PawPlay的收益不算项目收入。']},
'sources': {'findings_checked_at': findings.get('checked_at'), 'ledger_entries_in_period': len(entries), 'content_ledger': 'content.json', 'usage_source': '本机会话计数(只保存汇总,不发布对话)'}, 'sources': {'findings_checked_at': findings.get('checked_at'), 'ledger_entries_in_period': len(entries), 'content_ledger': 'content.json', 'next_actions_source': 'workqueue.json:报告生成时的任务快照' if isinstance(queue, dict) and queue.get('schema') == 1 and isinstance(queue.get('tasks'), list) else 'tasks.json:静态任务清单', 'usage_source': '本机会话计数(只保存汇总,不发布对话)'},
} }
repo = collector.get('repository') repo = collector.get('repository')
if repo: if repo:
+12
View File
@@ -76,5 +76,17 @@ class AccountingTests(unittest.TestCase):
self.assertIsNone(value['cash_settlement_usd']) self.assertIsNone(value['cash_settlement_usd'])
def test_report_uses_current_queue_and_redacts_interaction_titles(self):
import json
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / 'tasks.json').write_text(json.dumps({'items':[{'title':'旧计划','status':'todo'}]}))
(root / 'workqueue.json').write_text(json.dumps({'schema':1,'tasks':[{'id':'interaction-private','title':'私人消息内容','status':'running'}, {'id':'video','title':'制作挑战视频','status':'pending','dispatch_ready':True}, {'id':'wait','title':'等待反馈','status':'waiting'}, {'id':'done','title':'已完成','status':'done'}]}))
path,_ = report.build_report(root, now=dt.datetime(2026,11,6,20,tzinfo=report.TZ))
value=report.read_json(path)
self.assertEqual(value['next_actions'],['核查新互动','制作挑战视频','等待反馈(等待触发条件)'])
self.assertNotIn('私人消息内容',json.dumps(value,ensure_ascii=False))
self.assertIn('workqueue.json',value['sources']['next_actions_source'])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()