mpt-workflow 0.4.0 → 0.5.0
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 +18 -1
- package/README.md +41 -24
- package/README.zh-CN.md +11 -10
- package/dist/cli.js +23 -0
- package/dist/cli.js.map +1 -1
- package/dist/core/demo.js +50 -0
- package/dist/core/demo.js.map +1 -0
- package/dist/core/init.js +25 -5
- package/dist/core/init.js.map +1 -1
- package/dist/core/messages.js +9 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/workflow.js +7 -0
- package/dist/core/workflow.js.map +1 -1
- package/dist/version.js +1 -1
- package/dist/web/public/index.html +397 -48
- package/dist/web/server.js +2 -1
- package/dist/web/server.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<title>workflow · 开发看板</title>
|
|
6
|
+
<title>mpt-workflow · 开发看板</title>
|
|
7
7
|
<style>
|
|
8
8
|
/* Palette: dataviz reference. State colours are paired with a symbol AND a text
|
|
9
9
|
label everywhere, so colour never carries meaning alone. */
|
|
@@ -114,6 +114,7 @@ header.top {
|
|
|
114
114
|
padding: 3px 10px; font-size: 12px; color: var(--ink-2); background: var(--card);
|
|
115
115
|
}
|
|
116
116
|
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
|
|
117
|
+
.pill[hidden] { display: none; }
|
|
117
118
|
.pill.active .dot { background: var(--good); }
|
|
118
119
|
.btn {
|
|
119
120
|
border: 1px solid var(--ring); background: var(--card); color: var(--ink);
|
|
@@ -266,8 +267,63 @@ details.ms-detail[open] summary::before { content: "▾"; }
|
|
|
266
267
|
.lv.WARN { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--ink); }
|
|
267
268
|
.lv.OK { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-text); }
|
|
268
269
|
.empty { padding: 16px; color: var(--muted); font-size: 12.5px; }
|
|
270
|
+
.empty b { color: var(--ink); }
|
|
271
|
+
.empty pre {
|
|
272
|
+
background: var(--surface-1); border: 1px solid var(--ring); border-radius: 6px;
|
|
273
|
+
padding: 7px 9px; margin: 6px 0; overflow: auto; font-size: 11.5px; color: var(--ink);
|
|
274
|
+
}
|
|
269
275
|
.footer { color: var(--muted); font-size: 11.5px; margin-top: 24px; display: flex; gap: 14px; flex-wrap: wrap; }
|
|
270
276
|
|
|
277
|
+
/* feedback and controls */
|
|
278
|
+
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
|
|
279
|
+
.banner {
|
|
280
|
+
display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
|
|
281
|
+
background: color-mix(in srgb, var(--critical) 9%, var(--card));
|
|
282
|
+
border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
|
|
283
|
+
color: var(--ink); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px;
|
|
284
|
+
}
|
|
285
|
+
.banner[hidden] { display: none; }
|
|
286
|
+
.banner .grow { flex: 1; min-width: 200px; }
|
|
287
|
+
.pill input[type="checkbox"] { margin: 0; }
|
|
288
|
+
.msg-filters { display: flex; gap: 6px; padding: 9px 16px; border-bottom: 1px solid var(--grid); flex-wrap: wrap; }
|
|
289
|
+
.msg-help {
|
|
290
|
+
padding: 9px 16px; border-bottom: 1px solid var(--grid);
|
|
291
|
+
color: var(--muted); font-size: 11.5px; line-height: 1.55;
|
|
292
|
+
}
|
|
293
|
+
.msg-help b { color: var(--ink-2); }
|
|
294
|
+
.chip {
|
|
295
|
+
border: 1px solid var(--ring); background: var(--card); color: var(--ink-2);
|
|
296
|
+
border-radius: 999px; padding: 3px 10px; font-size: 11.5px; cursor: pointer;
|
|
297
|
+
}
|
|
298
|
+
.chip:hover { border-color: var(--line); }
|
|
299
|
+
.chip.active { background: var(--track); color: var(--ink); border-color: var(--line); font-weight: 600; }
|
|
300
|
+
|
|
301
|
+
/* diff modal */
|
|
302
|
+
.modal {
|
|
303
|
+
position: fixed; inset: 0; z-index: 50; padding: 20px;
|
|
304
|
+
background: rgba(0, 0, 0, .45); display: grid; place-items: center;
|
|
305
|
+
}
|
|
306
|
+
.modal[hidden] { display: none; }
|
|
307
|
+
.modal-card {
|
|
308
|
+
background: var(--card); color: var(--ink); border: 1px solid var(--ring);
|
|
309
|
+
border-radius: 12px; width: min(1040px, 100%); max-height: 88vh;
|
|
310
|
+
display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 18px 60px rgba(0,0,0,.25);
|
|
311
|
+
}
|
|
312
|
+
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--grid); }
|
|
313
|
+
.modal-head h2 { font-size: 14px; margin: 0; }
|
|
314
|
+
.modal-head .btn { margin-left: auto; }
|
|
315
|
+
.modal-body { padding: 14px 16px; overflow: auto; }
|
|
316
|
+
.diff {
|
|
317
|
+
background: var(--surface-1); border: 1px solid var(--ring); border-radius: 8px;
|
|
318
|
+
padding: 10px; overflow: auto; max-height: 52vh; margin: 0;
|
|
319
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; line-height: 1.55;
|
|
320
|
+
}
|
|
321
|
+
.diff .dline { display: block; white-space: pre; }
|
|
322
|
+
.dline.add { color: var(--good-text); background: color-mix(in srgb, var(--good) 9%, transparent); }
|
|
323
|
+
.dline.rem { color: var(--critical); background: color-mix(in srgb, var(--critical) 9%, transparent); }
|
|
324
|
+
.dline.hunk { color: var(--blue); }
|
|
325
|
+
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
|
|
326
|
+
|
|
271
327
|
@media (max-width: 1000px) {
|
|
272
328
|
.grid { grid-template-columns: 1fr; }
|
|
273
329
|
.tiles { grid-template-columns: repeat(2, 1fr); }
|
|
@@ -284,9 +340,9 @@ details.ms-detail[open] summary::before { content: "▾"; }
|
|
|
284
340
|
<div class="wrap">
|
|
285
341
|
<header class="top">
|
|
286
342
|
<div class="brand">
|
|
287
|
-
<div class="mark">
|
|
343
|
+
<div class="mark">mpt</div>
|
|
288
344
|
<div>
|
|
289
|
-
<h1 id="program-name">workflow</h1>
|
|
345
|
+
<h1 id="program-name">mpt-workflow</h1>
|
|
290
346
|
<div class="sub" id="root-path">正在加载…</div>
|
|
291
347
|
</div>
|
|
292
348
|
</div>
|
|
@@ -296,12 +352,21 @@ details.ms-detail[open] summary::before { content: "▾"; }
|
|
|
296
352
|
<span class="lbl">个里程碑已验收</span>
|
|
297
353
|
</div>
|
|
298
354
|
<div class="top-tools">
|
|
355
|
+
<span class="pill" id="version" hidden></span>
|
|
299
356
|
<span class="pill" id="active-repo"><span class="dot"></span><span>无 active repo</span></span>
|
|
357
|
+
<label class="pill" title="自动刷新不会在你输入或查看详情时打断">
|
|
358
|
+
<input type="checkbox" id="autorefresh" checked /> 自动刷新
|
|
359
|
+
</label>
|
|
300
360
|
<button class="btn ghost" id="refresh">刷新</button>
|
|
301
361
|
<button class="btn ghost" id="theme">切换主题</button>
|
|
302
362
|
</div>
|
|
303
363
|
</header>
|
|
304
364
|
|
|
365
|
+
<div id="error" class="banner" role="alert" hidden>
|
|
366
|
+
<span class="grow" id="error-msg"></span>
|
|
367
|
+
<button class="btn" id="retry">重试</button>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
305
370
|
<div class="tiles" id="tiles"></div>
|
|
306
371
|
|
|
307
372
|
<div class="grid">
|
|
@@ -331,7 +396,13 @@ details.ms-detail[open] summary::before { content: "▾"; }
|
|
|
331
396
|
|
|
332
397
|
<aside class="col">
|
|
333
398
|
<section class="card">
|
|
334
|
-
<div class="card-head"><h2
|
|
399
|
+
<div class="card-head"><h2>消息 · 发给 user</h2><span class="count" id="message-count"></span></div>
|
|
400
|
+
<div class="msg-filters" id="message-filters"></div>
|
|
401
|
+
<div class="msg-help">
|
|
402
|
+
发给 <b>user</b> 的消息是给你看的。<b>仅标记已读</b> 只改变未读状态;
|
|
403
|
+
<b>确认已处理</b>(ack)才会解除 blocking。审批请求的详情和操作在右侧
|
|
404
|
+
「待批准提交」,批准后会自动 ack 这条通知。
|
|
405
|
+
</div>
|
|
335
406
|
<div class="list" id="messages"></div>
|
|
336
407
|
</section>
|
|
337
408
|
|
|
@@ -358,9 +429,20 @@ details.ms-detail[open] summary::before { content: "▾"; }
|
|
|
358
429
|
</div>
|
|
359
430
|
|
|
360
431
|
<div class="footer">
|
|
361
|
-
<span
|
|
432
|
+
<span>本地看板(仅 127.0.0.1)· 写操作:回答/关闭问题、批准提交、ack 消息、切换 active repo</span>
|
|
362
433
|
<span>数据源:Markdown + .workflow/runtime</span>
|
|
363
|
-
<span id="
|
|
434
|
+
<span id="auto-state" aria-live="polite"></span>
|
|
435
|
+
<span id="generated" aria-live="polite"></span>
|
|
436
|
+
</div>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
<div id="modal" class="modal" hidden>
|
|
440
|
+
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
441
|
+
<div class="modal-head">
|
|
442
|
+
<h2 id="modal-title">提交详情</h2>
|
|
443
|
+
<button class="btn ghost" id="modal-close">关闭</button>
|
|
444
|
+
</div>
|
|
445
|
+
<div class="modal-body" id="modal-body"></div>
|
|
364
446
|
</div>
|
|
365
447
|
</div>
|
|
366
448
|
|
|
@@ -383,6 +465,14 @@ const QSTATUS = { open: '待回答', answered: '已回答', applied: '已应用'
|
|
|
383
465
|
let data = null;
|
|
384
466
|
let showClosed = false;
|
|
385
467
|
let messagesData = { unread: 0, blocking: [], messages: [] };
|
|
468
|
+
let messageFilter = 'unread';
|
|
469
|
+
let autoRefresh = localStorage.getItem('wf-auto') !== 'off';
|
|
470
|
+
let openDetail = null;
|
|
471
|
+
let modalOpen = false;
|
|
472
|
+
let lastFocus = null;
|
|
473
|
+
let loading = false;
|
|
474
|
+
const drafts = new Map();
|
|
475
|
+
const openForms = new Set();
|
|
386
476
|
|
|
387
477
|
async function get(path) {
|
|
388
478
|
const r = await fetch(path);
|
|
@@ -406,6 +496,57 @@ function ago(ts) {
|
|
|
406
496
|
return Math.floor(s / 86400) + 'd';
|
|
407
497
|
}
|
|
408
498
|
|
|
499
|
+
function isEditing() {
|
|
500
|
+
const a = document.activeElement;
|
|
501
|
+
if (a && /^(INPUT|TEXTAREA|SELECT)$/.test(a.tagName)) return true;
|
|
502
|
+
return !!document.querySelector('.q-form.open');
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function updateAutoState() {
|
|
506
|
+
const box = $('#auto-state');
|
|
507
|
+
if (!box) return;
|
|
508
|
+
if (!autoRefresh) box.textContent = '自动刷新已关闭';
|
|
509
|
+
else if (document.visibilityState === 'hidden') box.textContent = '自动刷新暂停(页面隐藏)';
|
|
510
|
+
else if (isEditing()) box.textContent = '自动刷新暂停(正在编辑)';
|
|
511
|
+
else box.textContent = '自动刷新 15s';
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function showError(msg) {
|
|
515
|
+
$('#error-msg').textContent = msg;
|
|
516
|
+
$('#error').hidden = false;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function hideError() {
|
|
520
|
+
$('#error').hidden = true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
async function copyText(text, btn) {
|
|
524
|
+
const old = btn ? btn.textContent : '';
|
|
525
|
+
try {
|
|
526
|
+
await navigator.clipboard.writeText(text);
|
|
527
|
+
if (btn) btn.textContent = '已复制';
|
|
528
|
+
} catch {
|
|
529
|
+
window.prompt('复制以下内容', text);
|
|
530
|
+
}
|
|
531
|
+
if (btn) setTimeout(() => { btn.textContent = old; }, 1500);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function openModal(title, html) {
|
|
535
|
+
lastFocus = document.activeElement;
|
|
536
|
+
$('#modal-title').textContent = title;
|
|
537
|
+
$('#modal-body').innerHTML = html;
|
|
538
|
+
$('#modal').hidden = false;
|
|
539
|
+
modalOpen = true;
|
|
540
|
+
$('#modal-close').focus();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function closeModal() {
|
|
544
|
+
if (!modalOpen) return;
|
|
545
|
+
modalOpen = false;
|
|
546
|
+
$('#modal').hidden = true;
|
|
547
|
+
if (lastFocus && lastFocus.focus) lastFocus.focus();
|
|
548
|
+
}
|
|
549
|
+
|
|
409
550
|
function renderTiles(st) {
|
|
410
551
|
const milestones = st.repos.flatMap(r => r.milestones);
|
|
411
552
|
const accepted = milestones.filter(m => m.status === 'accepted' || m.status === 'committed').length;
|
|
@@ -413,6 +554,9 @@ function renderTiles(st) {
|
|
|
413
554
|
$('#hero-of').textContent = '/ ' + milestones.length;
|
|
414
555
|
$('#program-name').textContent = st.program;
|
|
415
556
|
$('#root-path').textContent = st.root;
|
|
557
|
+
const ver = $('#version');
|
|
558
|
+
if (st.version) { ver.hidden = false; ver.textContent = 'v' + st.version; }
|
|
559
|
+
else ver.hidden = true;
|
|
416
560
|
|
|
417
561
|
const active = $('#active-repo');
|
|
418
562
|
active.classList.toggle('active', !!st.activeRepo);
|
|
@@ -445,6 +589,16 @@ function renderRepos(st) {
|
|
|
445
589
|
const box = $('#repos');
|
|
446
590
|
box.innerHTML = '';
|
|
447
591
|
$('#repo-count').textContent = st.repos.length + ' 个仓库';
|
|
592
|
+
if (!st.repos.length) {
|
|
593
|
+
box.innerHTML = `<div class="empty onboarding">
|
|
594
|
+
<b>还没有仓库</b>
|
|
595
|
+
<p>在工作区根目录运行:</p>
|
|
596
|
+
<pre>mpt-workflow init --root "${esc(st.root)}" --adopt</pre>
|
|
597
|
+
<pre>mpt-workflow init --root "${esc(st.root)}" --install-hooks</pre>
|
|
598
|
+
<p>然后用角色启动 agent:<code>WF_ROLE=plan WF_REPO=<repo> claude</code></p>
|
|
599
|
+
</div>`;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
448
602
|
for (const r of st.repos) {
|
|
449
603
|
const total = r.milestones.length;
|
|
450
604
|
const done = r.milestones.filter(m => ['accepted', 'committed'].includes(m.status)).length;
|
|
@@ -471,6 +625,7 @@ function renderRepos(st) {
|
|
|
471
625
|
const b = el('button', 'ms ' + m.status);
|
|
472
626
|
b.innerHTML = `<span class="sy">${s.sym}</span><span class="id">${esc(m.id)}</span><span>${s.label}</span>`;
|
|
473
627
|
b.title = m.title + (m.sha ? ' · ' + m.sha : '');
|
|
628
|
+
b.setAttribute('aria-label', `${m.id} ${m.title} · ${s.label}`);
|
|
474
629
|
b.onclick = () => toggleDetail(wrap, r, m, b);
|
|
475
630
|
track.appendChild(b);
|
|
476
631
|
}
|
|
@@ -488,17 +643,21 @@ function renderRepos(st) {
|
|
|
488
643
|
p.innerHTML = r.problems.map(x => '<span style="color:var(--serious)">! ' + esc(x) + '</span>').join(' · ');
|
|
489
644
|
wrap.appendChild(p);
|
|
490
645
|
}
|
|
646
|
+
if (total === 0) {
|
|
647
|
+
const hint = el('div', 'repo-meta');
|
|
648
|
+
hint.style.marginTop = '6px';
|
|
649
|
+
hint.innerHTML = '先写 PLAN.md 的里程碑表或 TODO-M1.md,然后点刷新。';
|
|
650
|
+
wrap.appendChild(hint);
|
|
651
|
+
}
|
|
652
|
+
if (openDetail && openDetail.repo === r.id) {
|
|
653
|
+
const m = r.milestones.find(x => x.id === openDetail.ms);
|
|
654
|
+
if (m) appendDetail(wrap, r, m);
|
|
655
|
+
}
|
|
491
656
|
box.appendChild(wrap);
|
|
492
657
|
}
|
|
493
658
|
}
|
|
494
659
|
|
|
495
|
-
function
|
|
496
|
-
const existing = wrap.querySelector('details.ms-detail');
|
|
497
|
-
if (existing) {
|
|
498
|
-
const same = existing.dataset.ms === m.id;
|
|
499
|
-
existing.remove();
|
|
500
|
-
if (same) return;
|
|
501
|
-
}
|
|
660
|
+
function appendDetail(wrap, repo, m) {
|
|
502
661
|
const d = el('details', 'ms-detail');
|
|
503
662
|
d.dataset.ms = m.id;
|
|
504
663
|
d.open = true;
|
|
@@ -524,16 +683,50 @@ function toggleDetail(wrap, repo, m, btn) {
|
|
|
524
683
|
wrap.appendChild(d);
|
|
525
684
|
}
|
|
526
685
|
|
|
686
|
+
function toggleDetail(wrap, repo, m) {
|
|
687
|
+
const existing = wrap.querySelector('details.ms-detail');
|
|
688
|
+
const same = existing && existing.dataset.ms === m.id;
|
|
689
|
+
if (existing) existing.remove();
|
|
690
|
+
if (same) {
|
|
691
|
+
openDetail = null;
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
openDetail = { repo: repo.id, ms: m.id };
|
|
695
|
+
appendDetail(wrap, repo, m);
|
|
696
|
+
}
|
|
697
|
+
|
|
527
698
|
function renderQuestions(st) {
|
|
528
699
|
const box = $('#questions');
|
|
700
|
+
// Preserve half-written answers across refreshes.
|
|
701
|
+
box.querySelectorAll('.q').forEach(qn => {
|
|
702
|
+
const id = qn.dataset.qid;
|
|
703
|
+
if (!id) return;
|
|
704
|
+
const ta = qn.querySelector('textarea');
|
|
705
|
+
const input = qn.querySelector('input');
|
|
706
|
+
if (ta) drafts.set(id, { answer: ta.value, resolution: input ? input.value : '' });
|
|
707
|
+
});
|
|
529
708
|
box.innerHTML = '';
|
|
530
709
|
const all = st.questions;
|
|
531
|
-
const list = all
|
|
710
|
+
const list = all
|
|
711
|
+
.filter(q => showClosed ? true : (q.status !== 'closed' && q.status !== 'canceled'))
|
|
712
|
+
.sort((a, b) => {
|
|
713
|
+
const rank = q => (q.blocking && q.status === 'open' ? 0 : q.status === 'open' ? 1 : q.status === 'answered' ? 2 : 3);
|
|
714
|
+
return rank(a) - rank(b);
|
|
715
|
+
});
|
|
532
716
|
$('#question-count').textContent = `${list.length} 条 · ${all.filter(q => q.blocking && q.status === 'open').length} 阻塞`;
|
|
533
|
-
if (!list.length) {
|
|
717
|
+
if (!list.length) {
|
|
718
|
+
box.appendChild(el('div', 'empty', '没有需要处理的问题。agent 调用 <code>ask</code> 后会出现在这里。'));
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
534
721
|
for (const q of list) {
|
|
722
|
+
if (q.status === 'closed' || q.status === 'canceled') {
|
|
723
|
+
openForms.delete(q.id);
|
|
724
|
+
drafts.delete(q.id);
|
|
725
|
+
}
|
|
535
726
|
const n = el('div', 'q');
|
|
727
|
+
n.dataset.qid = q.id;
|
|
536
728
|
const opts = q.options.map(o => `<div class="q-opt"><b>${esc(o.id)}</b><span>${esc(o.text)}</span></div>`).join('');
|
|
729
|
+
const draft = drafts.get(q.id) || { answer: '', resolution: '' };
|
|
537
730
|
n.innerHTML = `
|
|
538
731
|
<div class="q-head">
|
|
539
732
|
<span class="q-id">${esc(q.id)}</span>
|
|
@@ -541,41 +734,66 @@ function renderQuestions(st) {
|
|
|
541
734
|
${q.blocking ? '<span class="tag bad">blocking</span>' : ''}
|
|
542
735
|
<span class="q-flow">${esc(q.from)} → ${esc(q.to)} · ${esc(q.repo || 'root')}</span>
|
|
543
736
|
</div>
|
|
544
|
-
<div class="q-context clamp">${esc(q.context)}</div>
|
|
737
|
+
<div class="q-context clamp" data-context>${esc(q.context)}</div>
|
|
545
738
|
${opts ? '<div class="q-opts">' + opts + '</div>' : ''}
|
|
546
739
|
${q.recommendation ? '<div class="q-rec">建议:' + esc(q.recommendation) + '</div>' : ''}
|
|
547
740
|
${q.answer ? '<div class="q-rec" style="border-color:var(--good)">回答:' + esc(q.answer) + '</div>' : ''}
|
|
548
741
|
<div class="q-actions">
|
|
549
742
|
${q.status !== 'closed' ? '<button class="btn primary" data-act="answer">回答</button>' : ''}
|
|
743
|
+
${q.recommendation && q.status !== 'closed' ? '<button class="btn" data-act="rec">采纳建议</button>' : ''}
|
|
550
744
|
${q.status !== 'closed' ? '<button class="btn" data-act="close">关闭</button>' : ''}
|
|
745
|
+
<button class="btn ghost" data-act="expand">展开/收起</button>
|
|
551
746
|
<button class="btn ghost" data-act="relay">复制转发文本</button>
|
|
552
747
|
</div>
|
|
553
|
-
<div class="q-form">
|
|
554
|
-
<textarea placeholder="写下决定(会写入 docs/agent-questions.md 的 answer 字段)"
|
|
555
|
-
<input placeholder="resolution(回写 PLAN/TODO/decisions 的位置,可选)" />
|
|
748
|
+
<div class="q-form${openForms.has(q.id) ? ' open' : ''}">
|
|
749
|
+
<textarea placeholder="写下决定(会写入 docs/agent-questions.md 的 answer 字段)">${esc(draft.answer)}</textarea>
|
|
750
|
+
<input placeholder="resolution(回写 PLAN/TODO/decisions 的位置,可选)" value="${esc(draft.resolution)}" />
|
|
556
751
|
<div class="row"><button class="btn primary" data-act="submit">提交回答</button><span class="repo-meta" data-msg></span></div>
|
|
557
752
|
</div>`;
|
|
558
753
|
const form = n.querySelector('.q-form');
|
|
559
754
|
const msg = n.querySelector('[data-msg]');
|
|
755
|
+
const ta = form.querySelector('textarea');
|
|
756
|
+
const input = form.querySelector('input');
|
|
757
|
+
const sync = () => drafts.set(q.id, { answer: ta.value, resolution: input.value });
|
|
758
|
+
ta.addEventListener('input', sync);
|
|
759
|
+
input.addEventListener('input', sync);
|
|
560
760
|
n.querySelectorAll('[data-act]').forEach(b => {
|
|
561
761
|
b.onclick = async () => {
|
|
562
762
|
const act = b.dataset.act;
|
|
563
|
-
if (act === '
|
|
763
|
+
if (act === 'expand') {
|
|
764
|
+
n.querySelector('[data-context]').classList.toggle('clamp');
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
564
767
|
if (act === 'relay') {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
768
|
+
await copyText(relayText(q), b);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if (act === 'answer') {
|
|
772
|
+
const opening = !form.classList.contains('open');
|
|
773
|
+
form.classList.toggle('open', opening);
|
|
774
|
+
if (opening) { openForms.add(q.id); ta.focus(); }
|
|
775
|
+
else openForms.delete(q.id);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if (act === 'rec') {
|
|
779
|
+
openForms.add(q.id);
|
|
780
|
+
form.classList.add('open');
|
|
781
|
+
ta.value = q.recommendation || '';
|
|
782
|
+
sync();
|
|
783
|
+
ta.focus();
|
|
568
784
|
return;
|
|
569
785
|
}
|
|
570
786
|
try {
|
|
571
787
|
if (act === 'close') {
|
|
572
788
|
await post(`/api/question/${encodeURIComponent(q.id)}/close`, {});
|
|
573
789
|
} else {
|
|
574
|
-
const answer =
|
|
575
|
-
const resolution =
|
|
576
|
-
if (!answer) { msg.textContent = '先写回答'; return; }
|
|
790
|
+
const answer = ta.value.trim();
|
|
791
|
+
const resolution = input.value.trim();
|
|
792
|
+
if (!answer) { msg.textContent = '先写回答'; ta.focus(); return; }
|
|
577
793
|
await post(`/api/question/${encodeURIComponent(q.id)}/answer`, { answer, resolution });
|
|
578
794
|
}
|
|
795
|
+
drafts.delete(q.id);
|
|
796
|
+
openForms.delete(q.id);
|
|
579
797
|
await load();
|
|
580
798
|
} catch (e) { msg.textContent = '失败:' + e.message; }
|
|
581
799
|
};
|
|
@@ -597,39 +815,75 @@ function relayText(q) {
|
|
|
597
815
|
return lines.join('\n');
|
|
598
816
|
}
|
|
599
817
|
|
|
818
|
+
function renderMessageFilters() {
|
|
819
|
+
const box = $('#message-filters');
|
|
820
|
+
const defs = [['unread', '未读'], ['blocking', 'blocking'], ['all', '全部']];
|
|
821
|
+
box.innerHTML = defs
|
|
822
|
+
.map(([k, label]) => `<button class="chip${messageFilter === k ? ' active' : ''}" data-filter="${k}">${label}</button>`)
|
|
823
|
+
.join('');
|
|
824
|
+
box.querySelectorAll('[data-filter]').forEach(b => {
|
|
825
|
+
b.onclick = () => { messageFilter = b.dataset.filter; renderMessages(); };
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
|
|
600
829
|
function renderMessages() {
|
|
830
|
+
renderMessageFilters();
|
|
601
831
|
const box = $('#messages');
|
|
602
832
|
box.innerHTML = '';
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
833
|
+
const all = messagesData.messages || [];
|
|
834
|
+
const list = all.filter(m => {
|
|
835
|
+
if (messageFilter === 'all') return true;
|
|
836
|
+
if (messageFilter === 'blocking') return m.blocking && !['acked', 'expired'].includes(m.status);
|
|
837
|
+
return m.status === 'queued' || m.status === 'unread';
|
|
838
|
+
});
|
|
839
|
+
$('#message-count').textContent = `${messagesData.unread} 未读` +
|
|
840
|
+
(messagesData.blocking.length ? ` · ${messagesData.blocking.length} blocking` : '') +
|
|
841
|
+
` · 显示 ${list.length}`;
|
|
842
|
+
if (!list.length) {
|
|
843
|
+
const empty = messageFilter === 'all' ? '还没有消息。' : messageFilter === 'blocking' ? '没有 blocking 消息。' : '没有未读消息。';
|
|
844
|
+
box.appendChild(el('div', 'empty', empty));
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
for (const m of list) {
|
|
607
848
|
const r = el('div', 'row-item');
|
|
608
|
-
const
|
|
849
|
+
const isApproval = m.kind === 'approval_request';
|
|
850
|
+
const refs = Object.entries(m.refs || {})
|
|
851
|
+
.filter(([k, v]) => (!isApproval || k === 'repo' || k === 'approval_id') && v && (!Array.isArray(v) || v.length));
|
|
852
|
+
const approvalId = String((m.refs && m.refs.approval_id) || '');
|
|
853
|
+
const done = m.status === 'acked';
|
|
609
854
|
r.innerHTML = `
|
|
610
855
|
<div class="v" style="flex:1">
|
|
611
856
|
<div>
|
|
612
857
|
${m.blocking ? '<span class="tag bad">blocking</span> ' : ''}
|
|
858
|
+
<span class="tag">${esc(m.status)}</span>
|
|
613
859
|
<b>${esc(m.subject)}</b>
|
|
614
860
|
</div>
|
|
615
861
|
<div class="repo-meta">${esc(m.kind)} · ${esc(m.from.role)}${m.from.repo ? '@' + esc(m.from.repo) : ''} → ${esc(m.to.role)}${m.to.repo ? '@' + esc(m.to.repo) : ''} · ${esc(ago(m.created_at))}</div>
|
|
616
|
-
${m.body ? '<div class="q-context clamp" style="margin:5px 0;font-size:12.5px">' + esc(m.body) + '</div>' : ''}
|
|
862
|
+
${!isApproval && m.body ? '<div class="q-context clamp" style="margin:5px 0;font-size:12.5px">' + esc(m.body) + '</div>' : ''}
|
|
863
|
+
${isApproval ? '<div class="repo-meta" style="margin:5px 0">审批详情和操作在右侧「待批准提交」;批准后会自动 ack 这条通知。</div>' : ''}
|
|
617
864
|
${refs.length ? '<div class="repo-meta">' + refs.map(([k, v]) => esc(k) + '=' + esc(Array.isArray(v) ? v.join(',') : v)).join(' · ') + '</div>' : ''}
|
|
618
|
-
<div style="margin-top:6px">
|
|
619
|
-
|
|
620
|
-
${
|
|
865
|
+
<div style="margin-top:6px;display:flex;gap:8px;flex-wrap:wrap;align-items:center">
|
|
866
|
+
${approvalId ? `<button class="btn" data-approval="${esc(approvalId)}">查看待批准提交</button>` : ''}
|
|
867
|
+
${done ? '<span class="tag ok">已处理</span>' : (!isApproval ? `<button class="btn" data-ack="${esc(m.id)}" title="ack 后才会解除 blocking,并记录处理时间">确认已处理</button>` : '')}
|
|
868
|
+
${m.status === 'unread' || m.status === 'queued' ? `<button class="btn ghost" data-read="${esc(m.id)}" title="只改变未读状态;不会解除 blocking,也不会批准提交">仅标记已读</button>` : ''}
|
|
621
869
|
</div>
|
|
622
870
|
</div>`;
|
|
871
|
+
const ap = r.querySelector('[data-approval]');
|
|
872
|
+
if (ap) ap.onclick = () => {
|
|
873
|
+
const a = (window.__approvals || []).find(x => x.id === ap.dataset.approval);
|
|
874
|
+
if (a) openDiff(a);
|
|
875
|
+
else showError(`审批 ${ap.dataset.approval} 不存在或已使用`);
|
|
876
|
+
};
|
|
623
877
|
const ack = r.querySelector('[data-ack]');
|
|
624
878
|
if (ack) ack.onclick = async () => {
|
|
625
879
|
ack.disabled = true;
|
|
626
880
|
try { await post(`/api/message/${encodeURIComponent(m.id)}/ack`, {}); await load(); }
|
|
627
|
-
catch (e) {
|
|
881
|
+
catch (e) { showError(e.message); ack.disabled = false; }
|
|
628
882
|
};
|
|
629
883
|
const rd = r.querySelector('[data-read]');
|
|
630
884
|
if (rd) rd.onclick = async () => {
|
|
631
885
|
try { await post(`/api/message/${encodeURIComponent(m.id)}/read`, {}); await load(); }
|
|
632
|
-
catch (e) {
|
|
886
|
+
catch (e) { showError(e.message); }
|
|
633
887
|
};
|
|
634
888
|
box.appendChild(r);
|
|
635
889
|
}
|
|
@@ -639,38 +893,103 @@ function renderNext(st) {
|
|
|
639
893
|
const box = $('#next');
|
|
640
894
|
box.innerHTML = '';
|
|
641
895
|
$('#next-count').textContent = st.next.length ? st.next.length + ' 项' : '';
|
|
642
|
-
if (!st.next.length) {
|
|
896
|
+
if (!st.next.length) {
|
|
897
|
+
box.appendChild(el('div', 'empty', '没有识别到待办。运行 <code>mpt-workflow doctor</code> 检查配置。'));
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
643
900
|
for (const n of st.next) {
|
|
901
|
+
const cmd = n.actor === 'user'
|
|
902
|
+
? `mpt-workflow web --root ${JSON.stringify(st.root)}`
|
|
903
|
+
: `WF_ROLE=${n.actor}${n.repo ? ` WF_REPO=${n.repo}` : ''} claude`;
|
|
644
904
|
const r = el('div', 'row-item');
|
|
645
905
|
r.innerHTML = `
|
|
646
906
|
<span class="next-actor">${esc(n.actor)}</span>
|
|
647
|
-
<div class="v">
|
|
907
|
+
<div class="v" style="flex:1">
|
|
648
908
|
<div style="color:var(--ink);font-weight:600">${esc(n.action)}${n.repo ? ' <span class="repo-meta">' + esc(n.repo) + (n.milestone ? '/' + esc(n.milestone) : '') + '</span>' : ''}</div>
|
|
649
909
|
<div>${esc(n.detail)}</div>
|
|
910
|
+
<div class="repo-meta" style="margin-top:5px;display:flex;gap:6px;align-items:center;flex-wrap:wrap">
|
|
911
|
+
<code>${esc(cmd)}</code>
|
|
912
|
+
<button class="btn ghost" data-copy="${esc(cmd)}">复制</button>
|
|
913
|
+
</div>
|
|
650
914
|
</div>`;
|
|
915
|
+
r.querySelector('[data-copy]').onclick = (e) => copyText(e.currentTarget.dataset.copy, e.currentTarget);
|
|
651
916
|
box.appendChild(r);
|
|
652
917
|
}
|
|
653
918
|
}
|
|
654
919
|
|
|
920
|
+
function diffLines(diff) {
|
|
921
|
+
if (!diff) return '<span class="dline">(no diff)</span>';
|
|
922
|
+
return diff.slice(0, 200000).split('\n').map(line => {
|
|
923
|
+
let cls = '';
|
|
924
|
+
if (line.startsWith('@@')) cls = 'hunk';
|
|
925
|
+
else if (line.startsWith('+') && !line.startsWith('+++')) cls = 'add';
|
|
926
|
+
else if (line.startsWith('-') && !line.startsWith('---')) cls = 'rem';
|
|
927
|
+
return `<span class="dline ${cls}">${esc(line) || ' '}</span>`;
|
|
928
|
+
}).join('');
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
async function openDiff(a) {
|
|
932
|
+
openModal(`提交 ${a.id}`, '<div class="empty">正在加载 diff…</div>');
|
|
933
|
+
try {
|
|
934
|
+
const d = await get(`/api/diff?repo=${encodeURIComponent(a.repo)}`);
|
|
935
|
+
const files = (a.files || []).map(f => `<li><code>${esc(f)}</code></li>`).join('');
|
|
936
|
+
const log = (d.log || []).map(x => `<div class="repo-meta">${esc(x)}</div>`).join('');
|
|
937
|
+
$('#modal-body').innerHTML = `
|
|
938
|
+
<div class="repo-meta">${esc(a.repo)} · ${esc(a.message)}</div>
|
|
939
|
+
<div class="repo-meta">tree <code>${esc(a.tree_hash)}</code> · ${(a.files || []).length} 个文件</div>
|
|
940
|
+
<div class="modal-actions">
|
|
941
|
+
${a.approved_at ? '<span class="tag ok">已批准</span>' : '<button class="btn primary" id="modal-approve">批准这个提交</button>'}
|
|
942
|
+
<span class="repo-meta">批准绑定当前工作区 hash;批准后 agent 才能 commit。</span>
|
|
943
|
+
</div>
|
|
944
|
+
<h3 style="font-size:12px;margin:14px 0 6px">改动文件</h3>
|
|
945
|
+
<ul style="margin:0;padding-left:18px;font-size:12px">${files}</ul>
|
|
946
|
+
<h3 style="font-size:12px;margin:14px 0 6px">diff 摘要</h3>
|
|
947
|
+
<pre class="diff">${esc(d.stat || '(no stat)')}</pre>
|
|
948
|
+
<h3 style="font-size:12px;margin:14px 0 6px">diff</h3>
|
|
949
|
+
<pre class="diff">${diffLines(d.diff || '')}</pre>
|
|
950
|
+
${log ? '<h3 style="font-size:12px;margin:14px 0 6px">最近提交</h3>' + log : ''}`;
|
|
951
|
+
const btn = $('#modal-approve');
|
|
952
|
+
if (btn) btn.onclick = async () => {
|
|
953
|
+
btn.disabled = true;
|
|
954
|
+
btn.textContent = '批准中…';
|
|
955
|
+
try { await post('/api/approve', { id: a.id }); closeModal(); await load(); }
|
|
956
|
+
catch (e) { btn.disabled = false; btn.textContent = '批准提交'; showError(e.message); }
|
|
957
|
+
};
|
|
958
|
+
} catch (e) {
|
|
959
|
+
$('#modal-body').innerHTML = '<div class="empty">加载 diff 失败:' + esc(e.message) + '</div>';
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
655
963
|
function renderApprovals() {
|
|
656
964
|
const box = $('#approvals');
|
|
657
965
|
const list = (window.__approvals || []).filter(a => !a.used_at);
|
|
658
966
|
box.innerHTML = '';
|
|
659
967
|
if (!list.length) { box.appendChild(el('div', 'empty', '没有待批准的提交。')); return; }
|
|
660
968
|
for (const a of list) {
|
|
969
|
+
const files = (a.files || []).map(f => `<li><code>${esc(f)}</code></li>`).join('');
|
|
661
970
|
const r = el('div', 'row-item');
|
|
662
971
|
r.innerHTML = `
|
|
663
972
|
<div class="v" style="flex:1">
|
|
664
|
-
<div><code>${esc(a.id)}</code> · ${esc(a.repo)}</div>
|
|
973
|
+
<div><code>${esc(a.id)}</code> · ${esc(a.repo)} ${a.approved_at ? '<span class="tag ok">已批准</span>' : '<span class="tag">待批准</span>'}</div>
|
|
665
974
|
<div style="color:var(--ink-2)">${esc(a.message)}</div>
|
|
666
|
-
<div class="repo-meta">${a.files.length} 个文件 · tree ${esc(a.tree_hash)}
|
|
667
|
-
<
|
|
975
|
+
<div class="repo-meta">${(a.files || []).length} 个文件 · tree ${esc(a.tree_hash)}</div>
|
|
976
|
+
<details class="repo-meta" style="margin-top:4px">
|
|
977
|
+
<summary>查看文件列表</summary>
|
|
978
|
+
<ul style="margin:4px 0 0;padding-left:18px">${files}</ul>
|
|
979
|
+
</details>
|
|
980
|
+
<div style="margin-top:6px;display:flex;gap:8px;flex-wrap:wrap">
|
|
981
|
+
<button class="btn" data-diff="${esc(a.id)}">查看 diff</button>
|
|
982
|
+
${a.approved_at ? '' : `<button class="btn primary" data-approve="${esc(a.id)}">批准提交</button>`}
|
|
983
|
+
</div>
|
|
668
984
|
</div>`;
|
|
985
|
+
const diffBtn = r.querySelector('[data-diff]');
|
|
986
|
+
if (diffBtn) diffBtn.onclick = () => openDiff(a);
|
|
669
987
|
const b = r.querySelector('[data-approve]');
|
|
670
988
|
if (b) b.onclick = async () => {
|
|
671
989
|
b.disabled = true;
|
|
990
|
+
b.textContent = '批准中…';
|
|
672
991
|
try { await post('/api/approve', { id: a.id }); await load(); }
|
|
673
|
-
catch (e) {
|
|
992
|
+
catch (e) { showError(e.message); b.disabled = false; b.textContent = '批准提交'; }
|
|
674
993
|
};
|
|
675
994
|
box.appendChild(r);
|
|
676
995
|
}
|
|
@@ -704,11 +1023,14 @@ function renderTimeline(events) {
|
|
|
704
1023
|
}
|
|
705
1024
|
}
|
|
706
1025
|
|
|
707
|
-
async function load() {
|
|
1026
|
+
async function load(opts = {}) {
|
|
1027
|
+
if (loading) return;
|
|
1028
|
+
loading = true;
|
|
1029
|
+
const y = window.scrollY;
|
|
708
1030
|
try {
|
|
709
1031
|
const [st, approvals, events, doctor, messages] = await Promise.all([
|
|
710
1032
|
get('/api/status'), get('/api/approvals'), get('/api/events?limit=120'), get('/api/doctor'),
|
|
711
|
-
get('/api/messages?role=user'),
|
|
1033
|
+
get('/api/messages?role=user&all=1&limit=100'),
|
|
712
1034
|
]);
|
|
713
1035
|
data = st;
|
|
714
1036
|
window.__approvals = approvals;
|
|
@@ -721,13 +1043,27 @@ async function load() {
|
|
|
721
1043
|
renderApprovals();
|
|
722
1044
|
renderDoctor(doctor);
|
|
723
1045
|
renderTimeline(events);
|
|
1046
|
+
hideError();
|
|
724
1047
|
$('#generated').textContent = '更新于 ' + new Date(st.generatedAt).toLocaleTimeString();
|
|
1048
|
+
if (!opts.silent && y > 0) { try { window.scrollTo(0, y); } catch { /* jsdom/no-op */ } }
|
|
725
1049
|
} catch (e) {
|
|
726
|
-
|
|
1050
|
+
showError('加载失败:' + e.message);
|
|
1051
|
+
} finally {
|
|
1052
|
+
loading = false;
|
|
1053
|
+
updateAutoState();
|
|
727
1054
|
}
|
|
728
1055
|
}
|
|
729
1056
|
|
|
730
|
-
$('#
|
|
1057
|
+
const autoBox = $('#autorefresh');
|
|
1058
|
+
autoBox.checked = autoRefresh;
|
|
1059
|
+
autoBox.onchange = () => {
|
|
1060
|
+
autoRefresh = autoBox.checked;
|
|
1061
|
+
localStorage.setItem('wf-auto', autoRefresh ? 'on' : 'off');
|
|
1062
|
+
updateAutoState();
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
$('#refresh').onclick = () => load();
|
|
1066
|
+
$('#retry').onclick = () => load();
|
|
731
1067
|
$('#show-closed').onchange = (e) => { showClosed = e.target.checked; if (data) renderQuestions(data); };
|
|
732
1068
|
$('#theme').onclick = () => {
|
|
733
1069
|
const cur = document.documentElement.getAttribute('data-theme');
|
|
@@ -735,11 +1071,24 @@ $('#theme').onclick = () => {
|
|
|
735
1071
|
document.documentElement.setAttribute('data-theme', next);
|
|
736
1072
|
localStorage.setItem('wf-theme', next);
|
|
737
1073
|
};
|
|
1074
|
+
$('#modal-close').onclick = closeModal;
|
|
1075
|
+
$('#modal').addEventListener('click', (e) => { if (e.target === $('#modal')) closeModal(); });
|
|
1076
|
+
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeModal(); });
|
|
1077
|
+
document.addEventListener('visibilitychange', () => {
|
|
1078
|
+
updateAutoState();
|
|
1079
|
+
if (document.visibilityState === 'visible' && autoRefresh && !isEditing() && !modalOpen) load({ silent: true });
|
|
1080
|
+
});
|
|
738
1081
|
const saved = localStorage.getItem('wf-theme');
|
|
739
1082
|
if (saved) document.documentElement.setAttribute('data-theme', saved);
|
|
740
1083
|
|
|
741
1084
|
load();
|
|
742
|
-
setInterval(
|
|
1085
|
+
setInterval(() => {
|
|
1086
|
+
if (!autoRefresh || document.visibilityState === 'hidden' || isEditing() || modalOpen) {
|
|
1087
|
+
updateAutoState();
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
load({ silent: true });
|
|
1091
|
+
}, 15000);
|
|
743
1092
|
</script>
|
|
744
1093
|
</body>
|
|
745
1094
|
</html>
|