dsh-ai-collab 0.5.0 → 0.7.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/AGENTS.global.template.md +1 -1
- package/AGENTS.template.md +6 -2
- package/CHANGELOG.md +45 -0
- package/README.md +38 -28
- package/docs/DETAIL.md +29 -11
- package/docs/DISCLAIMER.md +2 -2
- package/docs/MARKET.md +13 -4
- package/docs/index.html +24 -19
- package/index.js +132 -11
- package/lib/dashboard.js +187 -0
- package/lib/handoff.js +2 -2
- package/lib/plan.js +336 -0
- package/lib/tasks.js +27 -25
- package/package.json +4 -4
- package/template/.ai/llm.ps1 +4 -3
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 插件异常会影响 Host 启动,所以首次安装请用 --patch 隔离验证,见 README。
|
|
11
11
|
*/
|
|
12
12
|
import { existsSync, mkdirSync, appendFileSync, readFileSync, readdirSync, renameSync, statSync, rmSync, writeFileSync } from 'node:fs'
|
|
13
|
-
import { join, dirname } from 'node:path'
|
|
13
|
+
import { join, dirname, basename } from 'node:path'
|
|
14
14
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
15
15
|
import { homedir } from 'node:os'
|
|
16
16
|
import { spawn } from 'node:child_process'
|
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
renderGlobalFile, renderProjectSection, setGlobalEnabled, ID_RE,
|
|
25
25
|
} from './lib/disciplines.js'
|
|
26
26
|
import { buildHandoff, inheritPrompt, writeSessionBoot } from './lib/handoff.js'
|
|
27
|
+
import { activeRiskTitles, doneChecklistItem, PLAN_STATUSES, CHECKLIST_STATUSES, readPlan, setBlock, writePlan } from './lib/plan.js'
|
|
28
|
+
import { writeDashboard } from './lib/dashboard.js'
|
|
27
29
|
|
|
28
30
|
export const name = 'ai-collab'
|
|
29
31
|
// Only `tools` is required. `workingDirectory` is used when present
|
|
@@ -209,6 +211,16 @@ function appendRecord(root, input) {
|
|
|
209
211
|
const list = Array.isArray(st.blockers) ? st.blockers : []
|
|
210
212
|
st.blockers = [...new Set([rec.issue, ...list].filter(Boolean))]
|
|
211
213
|
}
|
|
214
|
+
// 将 plan.json 的 active 风险标题合并进 blockers(轻联动,去重)
|
|
215
|
+
try {
|
|
216
|
+
const titles = activeRiskTitles(readPlan(root))
|
|
217
|
+
if (titles.length > 0) {
|
|
218
|
+
const current = new Set((Array.isArray(st.blockers) ? st.blockers : []).filter((b) => !titles.includes(b)))
|
|
219
|
+
for (const t of titles) current.add(t)
|
|
220
|
+
const merged = [...current]
|
|
221
|
+
if (JSON.stringify(merged) !== JSON.stringify(st.blockers)) st.blockers = merged
|
|
222
|
+
}
|
|
223
|
+
} catch { /* plan.json 不可读时不阻塞状态更新 */ }
|
|
212
224
|
writeFileAtomic(statusPath(root), JSON.stringify(st, null, 2) + '\n')
|
|
213
225
|
}
|
|
214
226
|
return rec
|
|
@@ -266,30 +278,58 @@ function recentlyRefreshed(root, key, windowMs) {
|
|
|
266
278
|
return false
|
|
267
279
|
}
|
|
268
280
|
|
|
269
|
-
//
|
|
281
|
+
// 写日志后顺带刷新看板 + 仪表盘(仅当上级目录已有 .ai\board.md;走包内 ai-ensure,不执行工作区脚本)
|
|
270
282
|
function maybeRefreshBoard(root) {
|
|
271
283
|
try {
|
|
272
284
|
if (!existsSync(join(dirname(root), '.ai', 'board.md'))) return
|
|
273
285
|
if (recentlyRefreshed(root, 'board', 3000)) return
|
|
274
286
|
spawnEnsure(root, {}, ['-NoAgents'])
|
|
287
|
+
// 仪表盘与看板同频刷新(3s 节流,不阻塞记录写入)
|
|
288
|
+
try { writeDashboard(root) } catch (e) { appendLog('ai-collab-dashboard.log', `root=${root} throw ${e?.message || e}`) }
|
|
275
289
|
} catch { /* 看板刷新失败不影响记录 */ }
|
|
276
290
|
}
|
|
277
291
|
|
|
278
292
|
/**
|
|
279
|
-
*
|
|
293
|
+
* 写日志后刷新任务清单(.ai/TASKS.md + 根 TASKS.html + .ai/PLAN.md)。
|
|
294
|
+
* 首次触发时自动创建 .ai\tasks-enabled(不再需要手动开)。
|
|
280
295
|
* 进程内渲染:不执行工作区自带的 .ai/llm.ps1,避免仓库脚本被插件执行。
|
|
281
296
|
*/
|
|
282
297
|
function refreshTasks(root) {
|
|
283
298
|
try {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
299
|
+
const marker = join(root, '.ai', 'tasks-enabled')
|
|
300
|
+
if (!existsSync(marker)) mkdirSync(marker, { recursive: true })
|
|
301
|
+
const st = readJson(statusPath(root))
|
|
302
|
+
const projectName = (st && st.project) || basename(root)
|
|
303
|
+
const result = withLock(join(root, '.ai', '.tasks.lock'), () => writeTasks(root, nowIso(), projectName))
|
|
304
|
+
if (!result.written) return
|
|
305
|
+
if (result.count === 0) appendLog('ai-collab-tasks.log', `root=${root} count=0`)
|
|
288
306
|
} catch (error) {
|
|
289
307
|
appendLog('ai-collab-tasks.log', `root=${root} throw ${error?.message || error}`)
|
|
290
308
|
}
|
|
291
309
|
}
|
|
292
310
|
|
|
311
|
+
/**
|
|
312
|
+
* 重新生成所有可视化产物(`.ai/TASKS.md` + 根 `TASKS.html` + `.ai/PLAN.md`
|
|
313
|
+
* + 父目录 `.ai/dashboard.html`)。工具调用与会话活动都会走这里,
|
|
314
|
+
* 保证「插件刚装好/刚重启」时文件也能自动出现,不需要用户手动 log 一次。
|
|
315
|
+
*
|
|
316
|
+
* 8s 内同一项目只渲染一次(会话事件很密,避免重复写盘);`force` 跳过节流。
|
|
317
|
+
*/
|
|
318
|
+
function syncArtifacts(root, { force = false } = {}) {
|
|
319
|
+
try {
|
|
320
|
+
if (!root || !existsSync(join(root, '.ai'))) return false
|
|
321
|
+
if (!force && recentlyRefreshed(root, 'artifacts', 8000)) return false
|
|
322
|
+
refreshTasks(root)
|
|
323
|
+
try { writeDashboard(root) } catch (error) {
|
|
324
|
+
appendLog('ai-collab-dashboard.log', `sync root=${root} throw ${error?.message || error}`)
|
|
325
|
+
}
|
|
326
|
+
return true
|
|
327
|
+
} catch (error) {
|
|
328
|
+
appendLog('ai-collab-artifacts.log', `sync root=${root} throw ${error?.message || error}`)
|
|
329
|
+
return false
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
293
333
|
/**
|
|
294
334
|
* Rebuild `.ai\SESSION_BOOT.md` after every record. It is derived data
|
|
295
335
|
* (status + last N records), so a stale boot file is worse than a small write.
|
|
@@ -342,6 +382,8 @@ export function apply(ctx, config = {}) {
|
|
|
342
382
|
try { writeSessionBoot(root, { maxTail: opts.maxTail }) } catch (error) {
|
|
343
383
|
appendLog('ai-collab-handoff.log', `autoInit root=${root} throw ${error?.message || error}`)
|
|
344
384
|
}
|
|
385
|
+
// 会话一建立就补齐可视化产物(TASKS.html / dashboard.html),避免重启后文件不存在
|
|
386
|
+
syncArtifacts(root, { force: true })
|
|
345
387
|
}
|
|
346
388
|
ctx.logger?.info?.('ai-collab autoInit', { root, ok: finished.ok, parsed: parseEnsureOutput(finished.out) })
|
|
347
389
|
}
|
|
@@ -362,6 +404,28 @@ export function apply(ctx, config = {}) {
|
|
|
362
404
|
}
|
|
363
405
|
})
|
|
364
406
|
|
|
407
|
+
// 1b) 会话活动兜底:`session/created` 只覆盖新建会话,重启后恢复的旧会话不会触发;
|
|
408
|
+
// 而 `session/event` 在每个 turn/step 都会发一次,用它把「恢复会话」也纳入自动渲染。
|
|
409
|
+
// 走 syncArtifacts 的 8s 节流,密集事件不会重复写盘。
|
|
410
|
+
ctx.effect(() => {
|
|
411
|
+
const handler = (session) => {
|
|
412
|
+
try {
|
|
413
|
+
const root = session?.cwd || session?.workspace
|
|
414
|
+
if (!root) return
|
|
415
|
+
syncArtifacts(root)
|
|
416
|
+
} catch (error) {
|
|
417
|
+
appendLog('ai-collab-artifacts.log', `session-event throw ${error?.message || error}`)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
const off = ctx.on('session/event', handler, { global: true })
|
|
422
|
+
return typeof off === 'function' ? off : () => {}
|
|
423
|
+
} catch (error) {
|
|
424
|
+
ctx.logger?.warn?.('ai-collab: session/event hook unavailable', error)
|
|
425
|
+
return () => {}
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
|
|
365
429
|
// 2) 工具:加载 dsh-tools 后注册;失败要落盘,不能只留一条 warn
|
|
366
430
|
ctx.effect(() => {
|
|
367
431
|
let disposed = false
|
|
@@ -440,6 +504,8 @@ function registerTools(ctx, opts, defineTool, spec) {
|
|
|
440
504
|
output,
|
|
441
505
|
async execute(args, exec) {
|
|
442
506
|
const r = await rootOf(exec)
|
|
507
|
+
// 开工第一步就把可视化产物补齐(重启/新装/恢复会话后第一次 ai_status 即可见)
|
|
508
|
+
syncArtifacts(r)
|
|
443
509
|
const st = readJson(statusPath(r))
|
|
444
510
|
const lines = readLines(logPath(r))
|
|
445
511
|
return {
|
|
@@ -470,7 +536,7 @@ function registerTools(ctx, opts, defineTool, spec) {
|
|
|
470
536
|
async execute(args, exec) {
|
|
471
537
|
const r = await rootOf(exec)
|
|
472
538
|
const rec = appendRecord(r, args)
|
|
473
|
-
|
|
539
|
+
syncArtifacts(r)
|
|
474
540
|
refreshSessionBoot(r)
|
|
475
541
|
maybeRefreshBoard(r)
|
|
476
542
|
return rec
|
|
@@ -517,7 +583,8 @@ function registerTools(ctx, opts, defineTool, spec) {
|
|
|
517
583
|
parameters: {},
|
|
518
584
|
output,
|
|
519
585
|
async execute(args, exec) {
|
|
520
|
-
const
|
|
586
|
+
const root = await rootOf(exec)
|
|
587
|
+
const parent = dirname(root)
|
|
521
588
|
const rows = []
|
|
522
589
|
for (const entry of readdirSafe(parent)) {
|
|
523
590
|
if (entry.startsWith('.') || entry.startsWith('_')) continue
|
|
@@ -533,7 +600,10 @@ function registerTools(ctx, opts, defineTool, spec) {
|
|
|
533
600
|
updated_at: st.updated_at || ''
|
|
534
601
|
})
|
|
535
602
|
}
|
|
536
|
-
|
|
603
|
+
const projects = rows.sort((a, b) => String(b.updated_at).localeCompare(String(a.updated_at)))
|
|
604
|
+
// 仪表盘与本工具同频刷新(board.md 由 ai-ensure 维护,这里只写 dashboard.html + TASKS.html)
|
|
605
|
+
syncArtifacts(root, { force: true })
|
|
606
|
+
return { scanned: parent, projects }
|
|
537
607
|
}
|
|
538
608
|
}))
|
|
539
609
|
|
|
@@ -567,6 +637,8 @@ function registerTools(ctx, opts, defineTool, spec) {
|
|
|
567
637
|
try { payload.boot = writeSessionBoot(target, { maxTail: opts.maxTail }) } catch (error) {
|
|
568
638
|
payload.boot = { ok: false, error: String(error?.message || error) }
|
|
569
639
|
}
|
|
640
|
+
// 接入/同步完成后补齐可视化产物(TASKS.html / dashboard.html)
|
|
641
|
+
payload.artifacts = syncArtifacts(target, { force: true })
|
|
570
642
|
}
|
|
571
643
|
return payload
|
|
572
644
|
}
|
|
@@ -701,8 +773,57 @@ function registerTools(ctx, opts, defineTool, spec) {
|
|
|
701
773
|
}
|
|
702
774
|
}))
|
|
703
775
|
|
|
776
|
+
registered.push('ai_plan')
|
|
777
|
+
ctx.tools.register(defineTool({
|
|
778
|
+
name: 'ai_plan',
|
|
779
|
+
description: '管理执行计划、检查清单与风险应对:数据存 .ai\\plan.json,渲染产物 .ai\\PLAN.md + .ai\\TASKS.md + 根 TASKS.html。show / set <plan|checklist|risks> / done <checklist-id>。',
|
|
780
|
+
parameters: {
|
|
781
|
+
action: { type: 'string', required: true, enum: ['show', 'set', 'done'], description: 'show 返回当前计划;set 覆盖 plan/checklist/risks 其中一块(传 key+items);done 勾选一条清单项' },
|
|
782
|
+
key: { type: 'string', description: 'set 时必填:plan / checklist / risks' },
|
|
783
|
+
items: { type: 'array', items: { type: 'json' }, description: 'set 时的项数组(JSON 对象列表)' },
|
|
784
|
+
id: { type: 'string', description: 'done 时的清单项 id' },
|
|
785
|
+
root: { type: 'string', description: '目标工作区,缺省为会话 cwd' },
|
|
786
|
+
},
|
|
787
|
+
output,
|
|
788
|
+
async execute(args, exec) {
|
|
789
|
+
const r = args?.root ? String(args.root) : await rootOf(exec)
|
|
790
|
+
const action = String(args?.action || 'show')
|
|
791
|
+
const now = nowIso()
|
|
792
|
+
|
|
793
|
+
if (action === 'show') {
|
|
794
|
+
const plan = readPlan(r)
|
|
795
|
+
return { root: r, plan, hasPlan: plan.plan.length > 0 || plan.checklist.length > 0 || plan.risks.length > 0 }
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (action === 'set') {
|
|
799
|
+
const key = String(args?.key || '')
|
|
800
|
+
const items = Array.isArray(args?.items) ? args.items : []
|
|
801
|
+
const result = setBlock(r, key, items, now)
|
|
802
|
+
syncArtifacts(r, { force: true })
|
|
803
|
+
maybeRefreshBoard(r)
|
|
804
|
+
return { root: r, ok: true, key, count: (result[key] || []).length, updated_at: result.updated_at }
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
if (action === 'done') {
|
|
808
|
+
const id = String(args?.id || '')
|
|
809
|
+
const { plan, item } = doneChecklistItem(r, id, now)
|
|
810
|
+
const rec = appendRecord(r, {
|
|
811
|
+
tool: 'ai_plan', action: 'task_done', status: 'ok',
|
|
812
|
+
summary: `清单项完成: ${item.item}`,
|
|
813
|
+
tags: ['plan', 'checklist'],
|
|
814
|
+
})
|
|
815
|
+
syncArtifacts(r, { force: true })
|
|
816
|
+
refreshSessionBoot(r)
|
|
817
|
+
maybeRefreshBoard(r)
|
|
818
|
+
return { root: r, ok: true, id, item, record: rec.id, plan: { ...plan, plan: undefined, checklist: undefined, risks: undefined } }
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
throw new Error(`未知 action: ${action}`)
|
|
822
|
+
}
|
|
823
|
+
}))
|
|
824
|
+
|
|
704
825
|
logToolRegistration(registered, spec)
|
|
705
826
|
}
|
|
706
827
|
|
|
707
828
|
// 仅供测试与调试:不要在插件内部依赖这些内部函数。
|
|
708
|
-
export const __internals = { recordErrors, appendRecord, readLines, nowIso, newId, refreshTasks, SCAFFOLD_SUPPORTED }
|
|
829
|
+
export const __internals = { recordErrors, appendRecord, readLines, nowIso, newId, refreshTasks, syncArtifacts, SCAFFOLD_SUPPORTED }
|
package/lib/dashboard.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跨项目仪表盘渲染:读取父目录下各项目 status.json + log.jsonl 行数,
|
|
3
|
+
* 生成 `board.md` 同级目录的 `dashboard.html`(自包含单文件,同 TASKS.html 风格)。
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readdirSync } from 'node:fs'
|
|
6
|
+
import { join, dirname } from 'node:path'
|
|
7
|
+
import { readText, writeFileAtomic } from './atomic.js'
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------- helpers
|
|
10
|
+
|
|
11
|
+
export function readdirSafe(dir) {
|
|
12
|
+
try { return readdirSync(dir) } catch { return [] }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function htmlEsc(s) {
|
|
16
|
+
return String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readJsonFile(path) {
|
|
20
|
+
try { return JSON.parse(readText(path)) } catch { return null }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 读 `<root>/.ai/log.jsonl` 非空行数。 */
|
|
24
|
+
function logLineCount(root) {
|
|
25
|
+
try {
|
|
26
|
+
const raw = readText(join(root, '.ai', 'log.jsonl'))
|
|
27
|
+
return raw.split('\n').filter((l) => l.trim().length > 0).length
|
|
28
|
+
} catch { return 0 }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function phaseLabel(phase) {
|
|
32
|
+
const map = { init: '初始化', build: '构建', feature: '特性开发', 'attitude-validation': '姿态验证',
|
|
33
|
+
diagnosis: '诊断', maintain: '维护', deliver: '交付' }
|
|
34
|
+
return map[phase] || phase || '—'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------- scan
|
|
38
|
+
|
|
39
|
+
export function scanProjects(parent) {
|
|
40
|
+
const rows = []
|
|
41
|
+
for (const entry of readdirSafe(parent)) {
|
|
42
|
+
if (entry.startsWith('.') || entry.startsWith('_')) continue
|
|
43
|
+
const st = readJsonFile(join(parent, entry, '.ai', 'status.json'))
|
|
44
|
+
if (!st) continue
|
|
45
|
+
rows.push({
|
|
46
|
+
project: st.project || entry,
|
|
47
|
+
dir: entry,
|
|
48
|
+
phase: st.phase || '',
|
|
49
|
+
focus: st.focus || '',
|
|
50
|
+
blockers: st.blockers || [],
|
|
51
|
+
next: st.next || [],
|
|
52
|
+
updated_at: st.updated_at || '',
|
|
53
|
+
logCount: logLineCount(join(parent, entry)),
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
return rows.sort((a, b) => String(b.updated_at).localeCompare(String(a.updated_at)))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ---------------------------------------------------------------- render: dashboard.html
|
|
60
|
+
|
|
61
|
+
export function renderDashboard(rows, parent, now) {
|
|
62
|
+
const dir = htmlEsc(parent)
|
|
63
|
+
const totalProjects = rows.length
|
|
64
|
+
const totalRecords = rows.reduce((s, r) => s + r.logCount, 0)
|
|
65
|
+
const blocking = rows.filter((r) => r.blockers.length > 0)
|
|
66
|
+
const maxLog = Math.max(1, ...rows.map((r) => r.logCount))
|
|
67
|
+
|
|
68
|
+
let tableHtml = ''
|
|
69
|
+
for (const r of rows) {
|
|
70
|
+
const hasBlock = r.blockers.length > 0
|
|
71
|
+
const blockText = hasBlock ? r.blockers.map((b) => htmlEsc(b)).join('; ') : '—'
|
|
72
|
+
const trClass = hasBlock ? ' style="background:#fff5f5"' : ''
|
|
73
|
+
tableHtml += `<tr${trClass}>
|
|
74
|
+
<td>${hasBlock ? '<span class="badge blocked">阻塞</span>' : ''}</td>
|
|
75
|
+
<td><strong>${htmlEsc(r.project)}</strong></td>
|
|
76
|
+
<td>${phaseLabel(r.phase)}</td>
|
|
77
|
+
<td>${htmlEsc(r.focus)}</td>
|
|
78
|
+
<td>${blockText}</td>
|
|
79
|
+
<td><a href="../${encodeURIComponent(r.dir)}/TASKS.html" title="任务清单">${r.logCount} 条</a></td>
|
|
80
|
+
<td class="muted">${htmlEsc(r.updated_at)}</td>
|
|
81
|
+
</tr>`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let barHtml = ''
|
|
85
|
+
for (const r of rows) {
|
|
86
|
+
const pct = Math.round((r.logCount / maxLog) * 100)
|
|
87
|
+
const color = r.logCount >= 40 ? '#198754' : r.logCount >= 20 ? '#0d6efd' : '#6c757d'
|
|
88
|
+
barHtml += `<div class="bar-row">
|
|
89
|
+
<span class="bar-label">${htmlEsc(r.project)}</span>
|
|
90
|
+
<span class="bar-track"><span class="bar-fill" style="width:${pct}%;background:${color}"></span></span>
|
|
91
|
+
<span class="bar-count">${r.logCount}</span>
|
|
92
|
+
</div>`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let blockHtml = ''
|
|
96
|
+
if (blocking.length > 0) {
|
|
97
|
+
blockHtml = '<section class="blocking"><h2>🚨 当前阻塞</h2><ul>'
|
|
98
|
+
for (const r of blocking) {
|
|
99
|
+
for (const b of r.blockers) {
|
|
100
|
+
blockHtml += `<li><strong>${htmlEsc(r.project)}</strong>:${htmlEsc(b)}</li>`
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
blockHtml += '</ul></section>'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return `<!DOCTYPE html>
|
|
107
|
+
<html lang="zh-CN">
|
|
108
|
+
<head>
|
|
109
|
+
<meta charset="UTF-8">
|
|
110
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
111
|
+
<title>跨项目仪表盘</title>
|
|
112
|
+
<style>
|
|
113
|
+
:root { --bg:#f8f9fa; --card:#fff; --text:#212529; --muted:#6c757d; --border:#dee2e6; font-family:system-ui,-apple-system,sans-serif; }
|
|
114
|
+
body { background:var(--bg); color:var(--text); margin:0; padding:16px; }
|
|
115
|
+
.container { max-width:1100px; margin:0 auto; }
|
|
116
|
+
header { background:var(--card); border:1px solid var(--border); border-radius:8px; padding:16px 24px; margin-bottom:16px; display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px; }
|
|
117
|
+
header h1 { margin:0; font-size:20px; }
|
|
118
|
+
header .stats { display:flex; gap:16px; }
|
|
119
|
+
header .stat { text-align:center; }
|
|
120
|
+
header .stat .num { font-size:22px; font-weight:700; }
|
|
121
|
+
header .stat .label { font-size:11px; color:var(--muted); }
|
|
122
|
+
section { background:var(--card); border:1px solid var(--border); border-radius:8px; padding:16px 24px; margin-bottom:16px; }
|
|
123
|
+
section h2 { margin:0 0 12px; font-size:16px; }
|
|
124
|
+
section.blocking { border-color:#dc3545; }
|
|
125
|
+
section.blocking ul { margin:0; padding-left:20px; color:#dc3545; }
|
|
126
|
+
section.blocking li { margin-bottom:4px; }
|
|
127
|
+
section.blocking strong { color:var(--text); }
|
|
128
|
+
table { width:100%; border-collapse:collapse; font-size:13px; }
|
|
129
|
+
th, td { text-align:left; padding:6px 8px; border-bottom:1px solid var(--border); vertical-align:top; }
|
|
130
|
+
th { background:#f1f3f5; font-weight:600; white-space:nowrap; }
|
|
131
|
+
tr:hover { background:#f8f9fa; }
|
|
132
|
+
.muted { color:var(--muted); font-size:12px; }
|
|
133
|
+
.badge { display:inline-block; padding:2px 6px; border-radius:3px; font-size:11px; font-weight:600; }
|
|
134
|
+
.badge.blocked { background:#dc3545; color:#fff; }
|
|
135
|
+
a { color:#0d6efd; text-decoration:none; }
|
|
136
|
+
a:hover { text-decoration:underline; }
|
|
137
|
+
.bar-row { display:flex; align-items:center; gap:8px; margin-bottom:6px; font-size:13px; }
|
|
138
|
+
.bar-label { min-width:80px; text-align:right; font-weight:500; }
|
|
139
|
+
.bar-track { flex:1; height:18px; background:#e9ecef; border-radius:4px; overflow:hidden; }
|
|
140
|
+
.bar-fill { height:100%; border-radius:4px; transition:width .3s; }
|
|
141
|
+
.bar-count { min-width:30px; font-variant-numeric:tabular-nums; color:var(--muted); }
|
|
142
|
+
footer { text-align:center; color:var(--muted); font-size:12px; padding:12px; }
|
|
143
|
+
</style>
|
|
144
|
+
</head>
|
|
145
|
+
<body>
|
|
146
|
+
<div class="container">
|
|
147
|
+
<header>
|
|
148
|
+
<div><h1>📊 跨项目仪表盘</h1><div class="muted">扫描:${dir} · 共 ${totalProjects} 个项目 · ${now}</div></div>
|
|
149
|
+
<div class="stats">
|
|
150
|
+
<div class="stat"><div class="num">${totalProjects}</div><div class="label">项目</div></div>
|
|
151
|
+
<div class="stat"><div class="num">${totalRecords}</div><div class="label">记录</div></div>
|
|
152
|
+
<div class="stat"><div class="num" style="color:#dc3545">${blocking.length}</div><div class="label">阻塞</div></div>
|
|
153
|
+
</div>
|
|
154
|
+
</header>
|
|
155
|
+
${blockHtml}
|
|
156
|
+
<section><h2>记录趋势</h2>${barHtml}</section>
|
|
157
|
+
<section><h2>项目总览</h2>
|
|
158
|
+
<table>
|
|
159
|
+
<tr><th></th><th>项目</th><th>阶段</th><th>焦点</th><th>阻塞</th><th>记录</th><th class="muted">最后更新</th></tr>
|
|
160
|
+
${tableHtml}
|
|
161
|
+
</table>
|
|
162
|
+
</section>
|
|
163
|
+
<footer>自动生成 · 来源各项目 .ai/status.json + .ai/log.jsonl · 勿手动编辑</footer>
|
|
164
|
+
</div>
|
|
165
|
+
</body>
|
|
166
|
+
</html>
|
|
167
|
+
`
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ---------------------------------------------------------------- write
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 读父目录 `board.md` 的位置来确定仪表盘输出路径。
|
|
174
|
+
* 目标:`<board.md 所在目录>\dashboard.html`。
|
|
175
|
+
* 当父目录没有 board.md 时返回 null。
|
|
176
|
+
*/
|
|
177
|
+
export function writeDashboard(root) {
|
|
178
|
+
const parent = dirname(root)
|
|
179
|
+
const boardPath = join(parent, '.ai', 'board.md')
|
|
180
|
+
if (!existsSync(boardPath)) return null
|
|
181
|
+
const rows = scanProjects(parent)
|
|
182
|
+
const now = new Date().toISOString()
|
|
183
|
+
const outPath = join(parent, '.ai', 'dashboard.html')
|
|
184
|
+
mkdirSync(join(parent, '.ai'), { recursive: true })
|
|
185
|
+
writeFileAtomic(outPath, renderDashboard(rows, parent, now))
|
|
186
|
+
return { path: outPath, rows: rows.length, written: true }
|
|
187
|
+
}
|
package/lib/handoff.js
CHANGED
|
@@ -79,7 +79,7 @@ export function buildHandoff(root, { maxTail = 10 } = {}) {
|
|
|
79
79
|
agents: join(root, 'AGENTS.md'),
|
|
80
80
|
status: join(root, '.ai', 'status.json'),
|
|
81
81
|
log: join(root, '.ai', 'log.jsonl'),
|
|
82
|
-
tasks: join(root, 'TASKS.md'),
|
|
82
|
+
tasks: join(root, '.ai', 'TASKS.md'),
|
|
83
83
|
boot: join(root, '.ai', 'SESSION_BOOT.md'),
|
|
84
84
|
disciplines: join(root, '.ai', 'disciplines', 'disciplines.json'),
|
|
85
85
|
},
|
|
@@ -102,7 +102,7 @@ export function renderSessionBoot(packet) {
|
|
|
102
102
|
'2. `AGENTS.md`:§1 项目事实、§3 权限表、§8 纪律清单;',
|
|
103
103
|
'3. `.ai/status.json`:当前状态快照;',
|
|
104
104
|
`4. \`.ai/log.jsonl\` 最近 ${packet.recent.length} 条(§3 已摘录,需要细节再回读);`,
|
|
105
|
-
'5. `TASKS.
|
|
105
|
+
'5. `.ai/TASKS.md`(存在时):任务记录清单;根目录 `TASKS.html` 是它的可视化版;',
|
|
106
106
|
'6. `.ai/disciplines/disciplines.json` 与启用规则(存在时)。',
|
|
107
107
|
'',
|
|
108
108
|
'## 2. 当前状态',
|