@skillre/dsh-plugin-work-dashboard 0.13.0 → 0.15.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.
Files changed (38) hide show
  1. package/README.en.md +6 -9
  2. package/README.md +9 -12
  3. package/lib/client/api.d.ts +3 -3
  4. package/lib/client/api.js +1 -3
  5. package/lib/client/text.js +5 -5
  6. package/lib/client.js +37 -30
  7. package/lib/index.js +56 -8
  8. package/lib/report-contract.d.ts +132 -2
  9. package/lib/report-contract.js +127 -1
  10. package/lib/report-form.d.ts +33 -2
  11. package/lib/report-form.js +79 -6
  12. package/lib/report-page.js +2093 -1481
  13. package/lib/report-style.d.ts +24 -12
  14. package/lib/report-style.js +368 -447
  15. package/lib/transport.d.ts +5 -5
  16. package/lib/transport.js +4 -3
  17. package/lib/types.d.ts +25 -10
  18. package/package.json +9 -16
  19. package/skills/poc-export/SKILL.md +3 -3
  20. package/skills/poc-export/scripts/export-form.mjs +24 -5
  21. package/skills/poc-submit/SKILL.md +2 -2
  22. package/compatibility.json +0 -240
  23. package/docs/DESIGN-0.3.md +0 -122
  24. package/docs/DESIGN-1.0-/344/274/230/345/214/226/346/226/271/346/241/210.md +0 -212
  25. package/docs/DESIGN-/344/274/232/350/257/235/344/272/214-SuperAgent/344/270/216/344/273/223/345/272/223/346/224/271/351/200/240.md +0 -275
  26. package/docs/DESIGN-/345/257/274/345/207/272/350/241/250/345/215/225/351/207/215/350/256/276/350/256/241.md +0 -330
  27. package/docs/DESIGN-/346/217/220/351/206/222/344/270/216Gate/350/257/204/345/256/241.md +0 -518
  28. package/docs/DESIGN-/346/226/207/346/234/254/346/210/252/346/226/255.md +0 -565
  29. package/docs/DESIGN-/350/241/250/345/215/225/345/210/206/351/230/266/346/256/265.md +0 -420
  30. package/docs/LEDGER-REQUIREMENTS-v3.1.md +0 -367
  31. package/docs/PLAN-0.7-0.9.md +0 -230
  32. package/docs/PLAN-v3.1-adaptation.md +0 -237
  33. package/docs/POC-3.2-/350/277/233/345/261/225/345/245/221/347/272/246.md +0 -21
  34. package/docs/Super-Agent-3.2-/350/201/224/350/260/203/346/211/213/345/206/214.md +0 -38
  35. package/docs/TARGET-/345/217/260/350/264/246/344/273/223/345/272/223v3.1.md +0 -500
  36. package/docs//350/200/201Mac-SuperAgent/346/224/271/351/200/240/350/256/260/345/275/225-/347/254/254/344/272/214/346/255/245.md +0 -233
  37. package/lib/form.d.ts +0 -597
  38. package/lib/form.js +0 -3211
@@ -66,7 +66,7 @@ export function readReport(input) {
66
66
  // No DOM, no evaluation, no file paths or operations from the attachment.
67
67
  const blocks = [...source.matchAll(/<script\s+type="application\/json"\s+id="poc-return-data"\s*>([^<]*)<\/script\s*>/gi)];
68
68
  if (blocks.length !== 1)
69
- throw new Error('未找到唯一的回传数据。请发送填写后「生成回传文件」下载的新版 HTML,不能发原始空白表单。');
69
+ throw new Error('未找到唯一的回传数据。请发送组员点「保存」后得到的表单文件,不能发原始空白表单。');
70
70
  json = blocks[0][1];
71
71
  }
72
72
  let data;
@@ -117,3 +117,129 @@ export function previousPlans(project) {
117
117
  export function structuredSummary(roundRecord) {
118
118
  return (roundRecord.lines ?? []).map((item) => `${item.title}(${item.status}):${item.actual}`).join('\n');
119
119
  }
120
+ const one = (value) => (typeof value === 'string' ? value.trim() : '');
121
+ /** Join the parts of a round that a reader can use, skipping the empties. */
122
+ function roundCustomer(entry) {
123
+ const synced = one(entry.customer?.synced_with);
124
+ const feedback = one(entry.customer?.feedback);
125
+ const recognition = one(entry.customer?.recognition);
126
+ if (!synced && !feedback && !recognition)
127
+ return '';
128
+ const who = synced ? `已同步 ${synced}` : '已同步';
129
+ const said = feedback || recognition;
130
+ return said ? `${who} · ${said}` : who;
131
+ }
132
+ function roundIds(entry) {
133
+ const list = [...(entry.scenario_ids ?? []), ...(entry.criteria_ids ?? [])].map(one).filter((id) => id !== '');
134
+ return list.join(' · ');
135
+ }
136
+ /** Flatten one round for the dossier list. */
137
+ export function dossierRound(entry) {
138
+ const seq = Number.isSafeInteger(entry.seq) && (entry.seq ?? 0) > 0 ? String(entry.seq) : '';
139
+ const lines = (entry.lines ?? []).map((line) => ({
140
+ title: one(line.title),
141
+ status: one(line.status),
142
+ actual: one(line.actual),
143
+ }));
144
+ return {
145
+ seq,
146
+ date: one(entry.date),
147
+ type: one(entry.type),
148
+ change: one(entry.change),
149
+ actual: structuredSummary(entry) || one(entry.actual),
150
+ lines,
151
+ completion: one(entry.completion),
152
+ evidenceCount: Array.isArray(entry.evidence) ? entry.evidence.length : 0,
153
+ ids: roundIds(entry),
154
+ customer: roundCustomer(entry),
155
+ };
156
+ }
157
+ /**
158
+ * Build the read-only dossier embedded in every progress form.
159
+ *
160
+ * `recentRounds` is the caller's cap. Two is the default the user chose: enough
161
+ * to see what was promised and what happened, few enough that a project with
162
+ * forty rounds still opens instantly.
163
+ */
164
+ export function buildDossier(project, summary, recentRounds = 2) {
165
+ const org = project.org ?? {};
166
+ const gate0 = project.gate0 ?? {};
167
+ const plan = project.plan ?? {};
168
+ const outcome = project.outcome ?? {};
169
+ const progress = Array.isArray(project.progress) ? project.progress : [];
170
+ const criteria = (plan.criteria ?? []).map((item) => ({
171
+ id: one(item?.id),
172
+ name: one(item?.name),
173
+ metric: [one(item?.metric), one(item?.target) ? `目标 ${one(item?.target)}` : ''].filter((part) => part !== '').join(' · '),
174
+ status: one(item?.status),
175
+ }));
176
+ const scenarios = (plan.scenarios ?? []).map((item) => ({
177
+ id: one(item?.id),
178
+ name: one(item?.name),
179
+ goal: one(item?.goal),
180
+ status: one(item?.status),
181
+ evidenceCount: typeof item?.evidence_count === 'number' ? item.evidence_count : 0,
182
+ }));
183
+ const missing = (Array.isArray(gate0.missing) ? gate0.missing : [])
184
+ .map(one)
185
+ .filter((field) => field !== '');
186
+ const nextPlans = previousPlans(project);
187
+ const rounds = progress.slice(-recentRounds).reverse().map(dossierRound);
188
+ return {
189
+ pocId: one(project.poc_id),
190
+ name: one(project.name),
191
+ stage: one(project.stage),
192
+ status: one(project.status),
193
+ owner: one(project.owner),
194
+ company: one(org.company),
195
+ department: one(org.department),
196
+ system: one(org.system),
197
+ sales: one(project.sales),
198
+ techOwner: one(project.tech_owner),
199
+ execSponsor: one(project.exec_sponsor),
200
+ amountWan: typeof project.amount_wan === 'number' && Number.isFinite(project.amount_wan) ? String(project.amount_wan) : '',
201
+ pocType: one(project.poc_type),
202
+ daysInStage: summary.daysInStage,
203
+ stageSince: summary.stageSince,
204
+ g0Conclusion: summary.g0Conclusion,
205
+ g0Complete: summary.g0Complete,
206
+ gate0: {
207
+ whyCustomer: one(gate0.why_customer),
208
+ whyUs: one(gate0.why_us),
209
+ decisionChain: one(gate0.decision_chain),
210
+ postPocDecision: one(gate0.post_poc_decision),
211
+ competitor: one(gate0.competitor),
212
+ missing,
213
+ },
214
+ plan: {
215
+ customerPain: one(plan.customer_pain),
216
+ expectedRecognition: one(plan.expected_recognition),
217
+ ourEdge: one(plan.our_edge),
218
+ timelineStart: one(plan.timeline?.start),
219
+ timelineEnd: one(plan.timeline?.end),
220
+ criteria,
221
+ scenarios,
222
+ risks: (plan.risks ?? []).map((item) => ({
223
+ name: one(item?.name),
224
+ level: one(item?.level),
225
+ mitigation: one(item?.mitigation),
226
+ })),
227
+ },
228
+ rounds,
229
+ roundTotal: progress.length,
230
+ outcome: {
231
+ achievement: one(outcome.achievement),
232
+ proved: one(outcome.conclusion?.proved),
233
+ recognized: one(outcome.conclusion?.recognized),
234
+ nextBusiness: one(outcome.conclusion?.next_business),
235
+ overall: one(outcome.overall),
236
+ },
237
+ gaps: {
238
+ stalled: summary.daysInStage !== null && summary.daysInStage > 14,
239
+ stalledDays: summary.daysInStage,
240
+ unverifiedCriteria: summary.unverifiedCriteria,
241
+ g0Missing: missing.length,
242
+ pendingPlans: nextPlans.length,
243
+ },
244
+ };
245
+ }
@@ -1,3 +1,34 @@
1
+ import type { DossierProject } from './report-contract.js';
1
2
  import type { PocRecord } from './types.js';
2
- export declare function buildReportHtml(intent: 'new' | 'progress', records: readonly PocRecord[], now?: Date): string;
3
- export declare function reportFileName(intent: 'new' | 'progress', ids: readonly string[], now?: Date): string;
3
+ /**
4
+ * Build one collection form.
5
+ *
6
+ * `dossier` is the project's read-only second page. It is optional because the
7
+ * two callers differ: the Host always has the ledger and passes it, while a
8
+ * blank new-project form has no project to describe. A `null` dossier is also
9
+ * legal — the page then shows "档案暂不可用" rather than a half-rendered one.
10
+ */
11
+ export declare function buildReportHtml(intent: 'new' | 'progress', records: readonly PocRecord[], now?: Date, dossier?: DossierProject | null): string;
12
+ /**
13
+ * The suggested download name for one form file.
14
+ *
15
+ * `项目名称_负责人` is the part the recipient reads in a chat list of files, so
16
+ * it comes first; the intent and the date make two exports of the same project
17
+ * distinguishable without opening either.
18
+ */
19
+ export declare function reportFileName(intent: 'new' | 'progress', project: {
20
+ name?: string;
21
+ owner?: string;
22
+ pocId?: string;
23
+ } | null, now?: Date): string;
24
+ /**
25
+ * One download name per project, made unique inside this batch.
26
+ *
27
+ * Two projects may legitimately share a name and an owner; without a suffix the
28
+ * second download would silently replace the first in the recipient's folder.
29
+ */
30
+ export declare function reportFileNames(intent: 'new' | 'progress', projects: readonly {
31
+ name?: string;
32
+ owner?: string;
33
+ pocId?: string;
34
+ }[], now?: Date): string[];
@@ -9,7 +9,15 @@ function calendarDate(now) {
9
9
  const parts = new Intl.DateTimeFormat('en-CA', { timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(now);
10
10
  return ['year', 'month', 'day'].map((kind) => parts.find((part) => part.type === kind)?.value).join('-');
11
11
  }
12
- export function buildReportHtml(intent, records, now = new Date()) {
12
+ /**
13
+ * Build one collection form.
14
+ *
15
+ * `dossier` is the project's read-only second page. It is optional because the
16
+ * two callers differ: the Host always has the ledger and passes it, while a
17
+ * blank new-project form has no project to describe. A `null` dossier is also
18
+ * legal — the page then shows "档案暂不可用" rather than a half-rendered one.
19
+ */
20
+ export function buildReportHtml(intent, records, now = new Date(), dossier = null) {
13
21
  if (records.length > MAX_REPORT_PROJECTS)
14
22
  throw new Error(`最多可导出 ${MAX_REPORT_PROJECTS} 个项目`);
15
23
  if (intent === 'progress') {
@@ -26,16 +34,81 @@ export function buildReportHtml(intent, records, now = new Date()) {
26
34
  scenarios: (project.plan?.scenarios ?? []).flatMap((item) => item.id && /^scn-\d{2,3}$/.test(item.id) ? [{ id: item.id, name: item.name ?? item.id }] : []),
27
35
  criteria: (project.plan?.criteria ?? []).flatMap((item) => item.id && /^cri-\d{2,3}$/.test(item.id) ? [{ id: item.id, name: item.name ?? item.id }] : []),
28
36
  }));
37
+ const today = calendarDate(now);
29
38
  return `<!doctype html>
30
39
  <html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
31
40
  <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
41
  <title>${title}</title><style>${REPORT_STYLE}</style></head><body>
33
42
  <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>${REPORT_PAGE_SCRIPT.replace(/<\/script/gi, '<\\/script')}</script>
43
+ <script type="application/json" id="poc-report-input">${scriptJSON({ intent, today, form_id: randomUUID(), exported_at: exportedAt(now), projects, dossier, enums: REPORT_ENUMS })}</script>
44
+ <script id="poc-form-script">${REPORT_PAGE_SCRIPT.replace(/<\/script/gi, '<\\/script')}</script>
36
45
  </body></html>`;
37
46
  }
38
- export function reportFileName(intent, ids, now = new Date()) {
39
- const subject = intent === 'new' ? '新建项目' : ids.length === 1 && projectId.safeParse(ids[0]).success ? ids[0] : `${ids.length}个项目`;
40
- return `poc-${intent}-${subject}-${calendarDate(now)}.html`;
47
+ /**
48
+ * The moment the snapshot was taken, printed on both pages.
49
+ *
50
+ * The dossier is a snapshot, so it has to say when it was taken — otherwise a
51
+ * form re-opened a month later presents stale facts as current. Rendered in
52
+ * Asia/Shanghai because every project in this ledger is reported from there.
53
+ */
54
+ function exportedAt(now) {
55
+ const parts = new Intl.DateTimeFormat('zh-CN', {
56
+ timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit',
57
+ hour: '2-digit', minute: '2-digit', hour12: false,
58
+ }).formatToParts(now);
59
+ const get = (kind) => parts.find((part) => part.type === kind)?.value ?? '';
60
+ return `${get('year')}-${get('month')}-${get('day')} ${get('hour')}:${get('minute')}`;
61
+ }
62
+ /**
63
+ * One part of a download name: readable, but never path-like.
64
+ *
65
+ * The file is forwarded over 企业微信 and re-opened on machines this code has
66
+ * never seen, so a `/`, a `:` or a leading `.` would make it unsaveable or
67
+ * hidden. Chinese characters are kept: the colleague recognises the project by
68
+ * name, not by `POC-001`.
69
+ */
70
+ function fileNamePart(value, fallback) {
71
+ const cleaned = value
72
+ .replace(/[\u0000-\u001f\u007f]/g, ' ')
73
+ .replace(/[\\/:*?"<>|]/g, ' ')
74
+ .replace(/\s+/g, ' ')
75
+ .trim()
76
+ .replace(/^\.+/, '')
77
+ .trim()
78
+ .slice(0, 32);
79
+ return cleaned === '' ? fallback : cleaned;
80
+ }
81
+ /**
82
+ * The suggested download name for one form file.
83
+ *
84
+ * `项目名称_负责人` is the part the recipient reads in a chat list of files, so
85
+ * it comes first; the intent and the date make two exports of the same project
86
+ * distinguishable without opening either.
87
+ */
88
+ export function reportFileName(intent, project, now = new Date()) {
89
+ const date = calendarDate(now);
90
+ if (intent === 'new' || project === null)
91
+ return `新建项目_${date}.html`;
92
+ const name = fileNamePart(project.name ?? '', project.pocId ?? '未命名项目');
93
+ const owner = fileNamePart(project.owner ?? '', '未填负责人');
94
+ return `${name}_${owner}_记录进展_${date}.html`;
95
+ }
96
+ /**
97
+ * One download name per project, made unique inside this batch.
98
+ *
99
+ * Two projects may legitimately share a name and an owner; without a suffix the
100
+ * second download would silently replace the first in the recipient's folder.
101
+ */
102
+ export function reportFileNames(intent, projects, now = new Date()) {
103
+ if (intent === 'new')
104
+ return [reportFileName('new', null, now)];
105
+ const used = new Set();
106
+ return projects.map((project) => {
107
+ const base = reportFileName('progress', project, now);
108
+ let name = base;
109
+ for (let copy = 2; used.has(name); copy += 1)
110
+ name = base.replace(/\.html$/, `_${copy}.html`);
111
+ used.add(name);
112
+ return name;
113
+ });
41
114
  }