@skillre/dsh-plugin-work-dashboard 0.12.0 → 0.14.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/README.en.md +3 -3
- package/README.md +8 -15
- package/docs/POC-3.2-/350/277/233/345/261/225/345/245/221/347/272/246.md +21 -0
- package/docs/Super-Agent-3.2-/350/201/224/350/260/203/346/211/213/345/206/214.md +38 -0
- package/lib/client/css/detail.d.ts +1 -1
- package/lib/client/css/detail.js +4 -0
- package/lib/client/text.js +9 -13
- package/lib/client.js +89 -48
- package/lib/form.js +118 -35
- package/lib/gap.d.ts +2 -2
- package/lib/gap.js +21 -14
- package/lib/index.js +26 -13
- package/lib/progress.d.ts +8 -0
- package/lib/progress.js +20 -0
- package/lib/report-contract.d.ts +315 -0
- package/lib/report-contract.js +119 -0
- package/lib/report-form.d.ts +25 -0
- package/lib/report-form.js +90 -0
- package/lib/report-import.d.ts +9 -0
- package/lib/report-import.js +118 -0
- package/lib/report-page.d.ts +60 -0
- package/lib/report-page.js +3217 -0
- package/lib/report-style.d.ts +18 -0
- package/lib/report-style.js +412 -0
- package/lib/store.js +8 -4
- package/lib/timeline.js +7 -6
- package/lib/types.d.ts +58 -9
- package/package.json +1 -1
- package/skills/poc-export/SKILL.md +10 -125
- package/skills/poc-export/scripts/export-form.mjs +34 -69
- package/skills/poc-ledger/SKILL.md +14 -25
- package/skills/poc-submit/SKILL.md +13 -278
- package/skills/poc-submit/prepare-return.mjs +48 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lastRound, MAX_REPORT_PROJECTS, previousPlans, projectBase, projectId, REPORT_ENUMS } from './report-contract.js';
|
|
3
|
+
import { canReportProgress } from './progress.js';
|
|
4
|
+
import { REPORT_PAGE_SCRIPT } from './report-page.js';
|
|
5
|
+
import { REPORT_STYLE } from './report-style.js';
|
|
6
|
+
const scriptJSON = (value) => JSON.stringify(value)
|
|
7
|
+
.replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
|
8
|
+
function calendarDate(now) {
|
|
9
|
+
const parts = new Intl.DateTimeFormat('en-CA', { timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(now);
|
|
10
|
+
return ['year', 'month', 'day'].map((kind) => parts.find((part) => part.type === kind)?.value).join('-');
|
|
11
|
+
}
|
|
12
|
+
export function buildReportHtml(intent, records, now = new Date()) {
|
|
13
|
+
if (records.length > MAX_REPORT_PROJECTS)
|
|
14
|
+
throw new Error(`最多可导出 ${MAX_REPORT_PROJECTS} 个项目`);
|
|
15
|
+
if (intent === 'progress') {
|
|
16
|
+
const closed = records.find((project) => !canReportProgress(project.stage, project.status));
|
|
17
|
+
if (closed)
|
|
18
|
+
throw new Error(`${closed.poc_id ?? ''} 已结束,不能导出记录进展表单`);
|
|
19
|
+
}
|
|
20
|
+
const title = intent === 'new' ? '新建项目 · POC 工作表' : '记录进展 · POC 工作表';
|
|
21
|
+
const projects = intent === 'new' ? [] : records.map((project) => ({
|
|
22
|
+
poc_id: projectId.parse(project.poc_id), name: project.name ?? '', stage: project.stage ?? '', status: project.status ?? '',
|
|
23
|
+
owner: project.owner ?? '', company: project.org?.company ?? '', base: projectBase(project),
|
|
24
|
+
previous_date: lastRound(project)?.date ?? '', round_count: project.progress?.length ?? 0,
|
|
25
|
+
previous_plans: previousPlans(project),
|
|
26
|
+
scenarios: (project.plan?.scenarios ?? []).flatMap((item) => item.id && /^scn-\d{2,3}$/.test(item.id) ? [{ id: item.id, name: item.name ?? item.id }] : []),
|
|
27
|
+
criteria: (project.plan?.criteria ?? []).flatMap((item) => item.id && /^cri-\d{2,3}$/.test(item.id) ? [{ id: item.id, name: item.name ?? item.id }] : []),
|
|
28
|
+
}));
|
|
29
|
+
return `<!doctype html>
|
|
30
|
+
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
31
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; form-action 'none'; base-uri 'none'">
|
|
32
|
+
<title>${title}</title><style>${REPORT_STYLE}</style></head><body>
|
|
33
|
+
<main id="app" class="rp-app"></main><noscript>请下载文件,用启用了 JavaScript 的浏览器打开。无需联网。</noscript>
|
|
34
|
+
<script type="application/json" id="poc-report-input">${scriptJSON({ intent, today: calendarDate(now), form_id: randomUUID(), projects, enums: REPORT_ENUMS })}</script>
|
|
35
|
+
<script id="poc-form-script">${REPORT_PAGE_SCRIPT.replace(/<\/script/gi, '<\\/script')}</script>
|
|
36
|
+
</body></html>`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One part of a download name: readable, but never path-like.
|
|
40
|
+
*
|
|
41
|
+
* The file is forwarded over 企业微信 and re-opened on machines this code has
|
|
42
|
+
* never seen, so a `/`, a `:` or a leading `.` would make it unsaveable or
|
|
43
|
+
* hidden. Chinese characters are kept: the colleague recognises the project by
|
|
44
|
+
* name, not by `POC-001`.
|
|
45
|
+
*/
|
|
46
|
+
function fileNamePart(value, fallback) {
|
|
47
|
+
const cleaned = value
|
|
48
|
+
.replace(/[\u0000-\u001f\u007f]/g, ' ')
|
|
49
|
+
.replace(/[\\/:*?"<>|]/g, ' ')
|
|
50
|
+
.replace(/\s+/g, ' ')
|
|
51
|
+
.trim()
|
|
52
|
+
.replace(/^\.+/, '')
|
|
53
|
+
.trim()
|
|
54
|
+
.slice(0, 32);
|
|
55
|
+
return cleaned === '' ? fallback : cleaned;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The suggested download name for one form file.
|
|
59
|
+
*
|
|
60
|
+
* `项目名称_负责人` is the part the recipient reads in a chat list of files, so
|
|
61
|
+
* it comes first; the intent and the date make two exports of the same project
|
|
62
|
+
* distinguishable without opening either.
|
|
63
|
+
*/
|
|
64
|
+
export function reportFileName(intent, project, now = new Date()) {
|
|
65
|
+
const date = calendarDate(now);
|
|
66
|
+
if (intent === 'new' || project === null)
|
|
67
|
+
return `新建项目_${date}.html`;
|
|
68
|
+
const name = fileNamePart(project.name ?? '', project.pocId ?? '未命名项目');
|
|
69
|
+
const owner = fileNamePart(project.owner ?? '', '未填负责人');
|
|
70
|
+
return `${name}_${owner}_记录进展_${date}.html`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One download name per project, made unique inside this batch.
|
|
74
|
+
*
|
|
75
|
+
* Two projects may legitimately share a name and an owner; without a suffix the
|
|
76
|
+
* second download would silently replace the first in the recipient's folder.
|
|
77
|
+
*/
|
|
78
|
+
export function reportFileNames(intent, projects, now = new Date()) {
|
|
79
|
+
if (intent === 'new')
|
|
80
|
+
return [reportFileName('new', null, now)];
|
|
81
|
+
const used = new Set();
|
|
82
|
+
return projects.map((project) => {
|
|
83
|
+
const base = reportFileName('progress', project, now);
|
|
84
|
+
let name = base;
|
|
85
|
+
for (let copy = 2; used.has(name); copy += 1)
|
|
86
|
+
name = base.replace(/\.html$/, `_${copy}.html`);
|
|
87
|
+
used.add(name);
|
|
88
|
+
return name;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Report } from './report-contract.js';
|
|
2
|
+
export interface PreparedCandidate {
|
|
3
|
+
pocId: string;
|
|
4
|
+
action: 'create' | 'append' | 'unchanged';
|
|
5
|
+
seq?: number;
|
|
6
|
+
yaml?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Pure, all-or-nothing planning. Do not call Git or write the user's ledger. */
|
|
9
|
+
export declare function prepareReport(input: Report, existing: ReadonlyMap<string, string>): PreparedCandidate[];
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
import { canReportProgress } from './progress.js';
|
|
3
|
+
import { canonical, LEDGER_VERSION, previousPlans, projectBase, reportSchema } from './report-contract.js';
|
|
4
|
+
function requireUnique(values, what) {
|
|
5
|
+
if (new Set(values).size !== values.length)
|
|
6
|
+
throw new Error(`${what} 不可重复`);
|
|
7
|
+
}
|
|
8
|
+
function candidateRound(project, round, notes) {
|
|
9
|
+
const plans = previousPlans(project);
|
|
10
|
+
const byId = new Map(plans.map((p) => [p.id, p]));
|
|
11
|
+
const used = round.lines.flatMap((line) => line.plan_id ? [line.plan_id] : []);
|
|
12
|
+
requireUnique(used, '上轮计划的反馈');
|
|
13
|
+
for (const line of round.lines) {
|
|
14
|
+
if (line.plan_id && byId.get(line.plan_id)?.goal !== line.title)
|
|
15
|
+
throw new Error('反馈条目不匹配上轮计划编号或标题');
|
|
16
|
+
for (const [ids, available, name] of [
|
|
17
|
+
[line.scenario_ids, project.plan?.scenarios, '场景'], [line.criteria_ids, project.plan?.criteria, '指标'],
|
|
18
|
+
]) {
|
|
19
|
+
requireUnique(ids ?? [], `${line.title} 的${name}`);
|
|
20
|
+
for (const id of ids ?? []) {
|
|
21
|
+
if (!available?.some((item) => item.id === id))
|
|
22
|
+
throw new Error(`${line.title}:${name} ${id} 不存在`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (used.length !== plans.length)
|
|
27
|
+
throw new Error('请逐项填写上轮计划,含未开始或取消的项目');
|
|
28
|
+
const oldPlanIds = (project.progress ?? []).flatMap((entry) => (entry.next_plans ?? []).map((p) => p.id));
|
|
29
|
+
requireUnique([...oldPlanIds, ...round.next_plans.map((plan) => plan.id)], '计划编号');
|
|
30
|
+
if (!round.lines.length && !round.next_plans.length && round.change !== '无实质进展') {
|
|
31
|
+
throw new Error('请填写一个进展或下一步计划;都没有时请选择「无实质进展」');
|
|
32
|
+
}
|
|
33
|
+
let max = 0;
|
|
34
|
+
for (const entry of project.progress ?? []) {
|
|
35
|
+
if (typeof entry.seq === 'number' && Number.isSafeInteger(entry.seq))
|
|
36
|
+
max = Math.max(max, entry.seq);
|
|
37
|
+
}
|
|
38
|
+
if (max >= Number.MAX_SAFE_INTEGER)
|
|
39
|
+
throw new Error('台账轮次编号超出可用范围');
|
|
40
|
+
const { lines, ...facts } = round;
|
|
41
|
+
return {
|
|
42
|
+
seq: max + 1, ...facts, ...(notes?.length ? { stage_notes: notes } : {}),
|
|
43
|
+
lines: lines.map((line) => ({
|
|
44
|
+
title: line.title, status: line.status, actual: line.actual,
|
|
45
|
+
...(line.plan_id ? { plan_id: line.plan_id } : {}),
|
|
46
|
+
...(line.evidence ? { evidence: line.evidence.map((entry) => ({ title: entry.title, link: entry.link ?? null, type: entry.type ?? null })) } : {}),
|
|
47
|
+
...(line.customer ? { customer: { ...(line.customer.synced_with ? { synced_with: line.customer.synced_with } : {}), ...(line.customer.feedback ? { feedback: line.customer.feedback } : {}) } } : {}),
|
|
48
|
+
...(line.scenario_ids ? { scenario_ids: line.scenario_ids } : {}),
|
|
49
|
+
...(line.criteria_ids ? { criteria_ids: line.criteria_ids } : {}),
|
|
50
|
+
...(line.completion ? { completion: line.completion } : {}),
|
|
51
|
+
})),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function sameSubmission(stored, round, notes) {
|
|
55
|
+
// A reviewer may have supplemented a line with a separate audit. It is not a
|
|
56
|
+
// member-submitted change and does not affect the replay comparison.
|
|
57
|
+
const { seq: _seq, stage_notes, lines, ...rest } = stored;
|
|
58
|
+
return canonical({ ...rest, lines: lines?.map(({ review: _review, evidence, ...facts }) => ({ ...facts, ...(evidence ? { evidence: evidence.map((entry) => ({ title: entry.title, ...(entry.link ? { link: entry.link } : {}), ...(entry.type ? { type: entry.type } : {}) })) } : {}) })), stage_notes: stage_notes ?? [] })
|
|
59
|
+
=== canonical({ ...round, stage_notes: notes ?? [] });
|
|
60
|
+
}
|
|
61
|
+
/** Pure, all-or-nothing planning. Do not call Git or write the user's ledger. */
|
|
62
|
+
export function prepareReport(input, existing) {
|
|
63
|
+
const report = reportSchema.parse(input);
|
|
64
|
+
requireUnique(report.changes.map((change) => change.poc_id), '项目编号');
|
|
65
|
+
requireUnique(report.changes.flatMap((change) => change.round ? [change.round.submission_id] : []), '回执编号');
|
|
66
|
+
if (report.intent === 'new') {
|
|
67
|
+
const change = report.changes[0];
|
|
68
|
+
const { poc_id: pocId, identity, gate0, round, stage_notes: notes } = change;
|
|
69
|
+
requireUnique((notes ?? []).map((note) => note.stage), '补充阶段');
|
|
70
|
+
if (notes?.length && !round)
|
|
71
|
+
throw new Error('保存阶段补充需随首轮进展记录');
|
|
72
|
+
const { company, system, department, name, owner, tech_owner, amount_wan, poc_type, sales, exec_sponsor } = identity;
|
|
73
|
+
const project = {
|
|
74
|
+
schema_version: LEDGER_VERSION, poc_id: pocId, name, owner, tech_owner,
|
|
75
|
+
amount_wan: amount_wan ?? null, poc_type: poc_type ?? null, sales: sales ?? null, exec_sponsor: exec_sponsor ?? null,
|
|
76
|
+
org: { company, system: system ?? null, department: department ?? null },
|
|
77
|
+
stage: 'G0-立项', status: '未开始',
|
|
78
|
+
gate0: { ...gate0, competitor: gate0.competitor ?? null }, plan: { scenarios: [], criteria: [], risks: [] }, progress: [], outcome: {},
|
|
79
|
+
};
|
|
80
|
+
if (existing.has(pocId))
|
|
81
|
+
throw new Error(`项目 ${pocId} 已存在,不能用新建回执覆盖`);
|
|
82
|
+
if (round)
|
|
83
|
+
project.progress.push(candidateRound(project, round, notes));
|
|
84
|
+
return [{ pocId, action: 'create', ...(round ? { seq: 1 } : {}), yaml: YAML.stringify(project) }];
|
|
85
|
+
}
|
|
86
|
+
return report.changes.map(({ poc_id: pocId, base, round, stage_notes: notes }) => {
|
|
87
|
+
requireUnique((notes ?? []).map((note) => note.stage), '补充阶段');
|
|
88
|
+
const source = existing.get(pocId);
|
|
89
|
+
if (!source)
|
|
90
|
+
throw new Error(`项目 ${pocId} 不存在,不能自动新建`);
|
|
91
|
+
const doc = YAML.parseDocument(source);
|
|
92
|
+
if (doc.errors.length)
|
|
93
|
+
throw new Error(`${pocId} 的台账 YAML 无法解析`);
|
|
94
|
+
const project = doc.toJS({ maxAliasCount: 50 });
|
|
95
|
+
if (!project || project.poc_id !== pocId)
|
|
96
|
+
throw new Error(`${pocId} 文件内编号不匹配`);
|
|
97
|
+
if (!Array.isArray(project.progress))
|
|
98
|
+
throw new Error(`${pocId} 的历史进展不是列表`);
|
|
99
|
+
if (project.schema_version !== LEDGER_VERSION)
|
|
100
|
+
throw new Error(`${pocId} 尚未迁移到台账 3.2,请先迁移再重新导出`);
|
|
101
|
+
const saved = project.progress.find((entry) => entry?.submission_id === round.submission_id);
|
|
102
|
+
if (saved) {
|
|
103
|
+
if (!sameSubmission(saved, round, notes))
|
|
104
|
+
throw new Error(`${pocId}:同一个回执编号已入账,但内容不同,不能重复提交`);
|
|
105
|
+
return { pocId, action: 'unchanged', ...(typeof saved.seq === 'number' ? { seq: saved.seq } : {}) };
|
|
106
|
+
}
|
|
107
|
+
if (projectBase(project) !== base)
|
|
108
|
+
throw new Error(`${pocId} 自导出后已有变更。请核对差异后重新导出,不能覆盖或把旧计划当成当前计划。`);
|
|
109
|
+
if (!canReportProgress(project.stage, project.status))
|
|
110
|
+
throw new Error(`${pocId} 已结束,不能追加进展`);
|
|
111
|
+
const entry = candidateRound(project, round, notes);
|
|
112
|
+
const list = doc.get('progress', true);
|
|
113
|
+
if (!YAML.isSeq(list))
|
|
114
|
+
throw new Error(`${pocId} 的进展不是可追加的 YAML 列表`);
|
|
115
|
+
list.add(doc.createNode(entry));
|
|
116
|
+
return { pocId, action: 'append', seq: entry.seq, yaml: doc.toString() };
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POC 3.2 report page: the offline form a colleague edits, plus the read-only
|
|
3
|
+
* return receipt it produces.
|
|
4
|
+
*
|
|
5
|
+
* ## Contract
|
|
6
|
+
*
|
|
7
|
+
* The Host writes the shell and the data block; this module only supplies two
|
|
8
|
+
* strings:
|
|
9
|
+
*
|
|
10
|
+
* - `REPORT_STYLE` — embedded in a `<style>` element.
|
|
11
|
+
* - `REPORT_PAGE_SCRIPT` — embedded in a `<script>` element **after** the DOM
|
|
12
|
+
* nodes `<main id="app"></main>` and
|
|
13
|
+
* a `<script type="application/json" id="poc-report-input">` data block (with its
|
|
14
|
+
* matching closing tag) that carries the page payload.
|
|
15
|
+
*
|
|
16
|
+
* Everything else is built here. The page has to work from `file://` with no
|
|
17
|
+
* network, so there are no imports, no fonts, no images and no requests.
|
|
18
|
+
*
|
|
19
|
+
* ## Why the script is a function rendered through `toString()`
|
|
20
|
+
*
|
|
21
|
+
* The script is write-once plain JavaScript that runs inside the generated HTML
|
|
22
|
+
* page. If it were a template literal it would get no TypeScript checking at
|
|
23
|
+
* all — the first symptom of a typo would be a blank page on a colleague's
|
|
24
|
+
* laptop. So the browser code lives in `reportPage()`, a normal typed function,
|
|
25
|
+
* and is serialised with `Function.prototype.toString()`. Everything it needs is
|
|
26
|
+
* declared inside it: no module scope, no Host constants, no `Node` APIs.
|
|
27
|
+
*
|
|
28
|
+
* The generated return receipt is a self-contained HTML file. It repeats the
|
|
29
|
+
* payload in `<script type="application/json" id="poc-return-data">` (escaped,
|
|
30
|
+
* never executed) and lists the same facts as readable cards for a recipient
|
|
31
|
+
* who just double-clicks the file. The receipt carries no scripts beyond that
|
|
32
|
+
* inert JSON block.
|
|
33
|
+
*
|
|
34
|
+
* ## The payload (poc-report/1, ledger_version 3.2)
|
|
35
|
+
*
|
|
36
|
+
* `changes[]` is one entry per project the colleague actually filled in:
|
|
37
|
+
*
|
|
38
|
+
* - `new`: `{ poc_id, identity, gate0, stage_notes?, round? }`
|
|
39
|
+
* - `progress`: `{ poc_id, base, stage_notes?, round }`
|
|
40
|
+
*
|
|
41
|
+
* `round` is `{ submission_id, date, type, change, lines[], next_plans[] }`.
|
|
42
|
+
* Facts only: no `seq`, no Gate verdicts, no `review`. Execution state lives on
|
|
43
|
+
* each line and is not a result. Empty optional fields are omitted rather than
|
|
44
|
+
* sent as `null`, so "not answered" stays distinguishable from "answered empty".
|
|
45
|
+
*
|
|
46
|
+
* ## Host integration
|
|
47
|
+
*
|
|
48
|
+
* Drafts are stored under `poc-report-draft:<form_id>` and are discarded when
|
|
49
|
+
* the form's per-project `base` digests change, so a draft can never be applied
|
|
50
|
+
* on top of a different baseline.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* The page script, ready to embed inside a script element.
|
|
54
|
+
*
|
|
55
|
+
* `reportPage` is serialised rather than hand-written as a string so that
|
|
56
|
+
* TypeScript checks the browser code and a typo cannot silently ship as a blank
|
|
57
|
+
* page. The wrapper is an IIFE: the embedded script gets no globals, and the
|
|
58
|
+
* function's own `'use strict'` keeps accidental globals out.
|
|
59
|
+
*/
|
|
60
|
+
export declare const REPORT_PAGE_SCRIPT: string;
|