@skillre/dsh-plugin-work-dashboard 0.0.0-stage → 0.9.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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +259 -0
  3. package/README.md +371 -2
  4. package/UNINSTALL.md +7 -0
  5. package/compatibility.json +195 -0
  6. package/cordis.patch.yml +24 -0
  7. package/docs/DESIGN-0.3.md +122 -0
  8. package/docs/DETAIL.md +1 -0
  9. package/docs/DETAIL.zh.md +1 -0
  10. package/docs/PLAN-0.7-0.9.md +230 -0
  11. package/docs/preview.svg +254 -0
  12. package/docs/preview.zh.svg +254 -0
  13. package/icon.svg +17 -0
  14. package/lib/blockers.d.ts +45 -0
  15. package/lib/blockers.js +160 -0
  16. package/lib/client/api.d.ts +42 -0
  17. package/lib/client/api.js +45 -0
  18. package/lib/client/contracts.d.ts +94 -0
  19. package/lib/client/contracts.js +21 -0
  20. package/lib/client/css/base.d.ts +31 -0
  21. package/lib/client/css/base.js +461 -0
  22. package/lib/client/css/blockers.d.ts +18 -0
  23. package/lib/client/css/blockers.js +196 -0
  24. package/lib/client/css/charts.d.ts +14 -0
  25. package/lib/client/css/charts.js +191 -0
  26. package/lib/client/css/detail.d.ts +21 -0
  27. package/lib/client/css/detail.js +423 -0
  28. package/lib/client/css/insights.d.ts +27 -0
  29. package/lib/client/css/insights.js +660 -0
  30. package/lib/client/css/overview.d.ts +23 -0
  31. package/lib/client/css/overview.js +327 -0
  32. package/lib/client/css/summary.d.ts +13 -0
  33. package/lib/client/css/summary.js +187 -0
  34. package/lib/client/format.d.ts +57 -0
  35. package/lib/client/format.js +96 -0
  36. package/lib/client/preferences.d.ts +56 -0
  37. package/lib/client/preferences.js +118 -0
  38. package/lib/client/styles.d.ts +17 -0
  39. package/lib/client/styles.js +24 -0
  40. package/lib/client/text.d.ts +32 -0
  41. package/lib/client/text.js +1112 -0
  42. package/lib/client/view-contract.d.ts +118 -0
  43. package/lib/client/view-contract.js +28 -0
  44. package/lib/client.js +6599 -0
  45. package/lib/config.d.ts +61 -0
  46. package/lib/config.js +67 -0
  47. package/lib/form.d.ts +218 -0
  48. package/lib/form.js +1075 -0
  49. package/lib/gap.d.ts +60 -0
  50. package/lib/gap.js +227 -0
  51. package/lib/index.d.ts +40 -0
  52. package/lib/index.js +159 -0
  53. package/lib/repo.d.ts +124 -0
  54. package/lib/repo.js +407 -0
  55. package/lib/risks.d.ts +24 -0
  56. package/lib/risks.js +85 -0
  57. package/lib/skill.d.ts +94 -0
  58. package/lib/skill.js +220 -0
  59. package/lib/store.d.ts +63 -0
  60. package/lib/store.js +505 -0
  61. package/lib/timeline.d.ts +23 -0
  62. package/lib/timeline.js +93 -0
  63. package/lib/transport.d.ts +67 -0
  64. package/lib/transport.js +131 -0
  65. package/lib/types.d.ts +701 -0
  66. package/lib/types.js +78 -0
  67. package/locale/en.json +7 -0
  68. package/locale/zh.json +7 -0
  69. package/package.json +117 -4
  70. package/skills/poc-export/SKILL.md +81 -0
  71. package/skills/poc-export/scripts/export-form.mjs +654 -0
  72. package/skills/poc-ledger/SKILL.md +171 -0
  73. package/skills/poc-submit/SKILL.md +186 -0
package/lib/skill.js ADDED
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Registration of the three skills that ship inside this package.
3
+ *
4
+ * The skills live in `skills/<name>/` rather than in the user's profile, so
5
+ * installing the plugin is what publishes them, and uninstalling removes them.
6
+ * That is the point of bundling them: a colleague who installs the dashboard
7
+ * gets the ledger-reading, form-exporting and PR-submitting skills in the same
8
+ * action, on the same version, with no separate install step that can drift.
9
+ *
10
+ * Every step is best-effort by design: `skills` is an optional service, and a
11
+ * profile without it — or a package whose skill file went missing — must still
12
+ * get the dashboard. Missing service, missing file and unusable frontmatter
13
+ * therefore warn and return; nothing throws out of `apply`.
14
+ *
15
+ * The skills are read from disk at registration time rather than inlined into
16
+ * the bundle, so the `scripts/` beside them ship as real files the model can
17
+ * run, and so an operator can read exactly what was published.
18
+ */
19
+ import { existsSync, readFileSync } from 'node:fs';
20
+ import { join, resolve } from 'node:path';
21
+ import { fileURLToPath } from 'node:url';
22
+ /** Names of the bundled skills, in the order they are registered. */
23
+ export const BUNDLED_SKILL_NAMES = ['poc-ledger', 'poc-export', 'poc-submit'];
24
+ /** File the skill catalog looks for inside a skill directory. */
25
+ const SKILL_FILE_NAME = 'SKILL.md';
26
+ /**
27
+ * Kebab-case rule the registry applies to a runtime skill name.
28
+ *
29
+ * Restated here on purpose: checking it ourselves turns a registry exception
30
+ * into an explanatory warning, so a typo in the shipped frontmatter reads as
31
+ * "this skill was skipped" instead of "the plugin failed to mount".
32
+ */
33
+ const SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
34
+ /** A YAML frontmatter fence line. */
35
+ const FENCE_PATTERN = /^---\s*$/;
36
+ /**
37
+ * Absolute path of the directory holding the bundled skills.
38
+ *
39
+ * `src/` and `lib/` both sit directly under the package root, so the same
40
+ * relative URL resolves whether the plugin runs from source (tests) or from the
41
+ * built package (an installed profile).
42
+ */
43
+ export function bundledSkillsDirectory() {
44
+ return resolve(fileURLToPath(new URL('../skills/', import.meta.url)));
45
+ }
46
+ /**
47
+ * Parse the single-line `key: value` frontmatter of a bundled `SKILL.md`.
48
+ *
49
+ * Deliberately not a YAML parser: these files only carry string scalars we
50
+ * control, and a plugin should not pull a YAML dependency to read its own
51
+ * resources. A value may be wrapped in one matching pair of quotes, which are
52
+ * stripped; escape sequences are left exactly as written.
53
+ */
54
+ export function parseSkillMarkdown(source) {
55
+ const lines = source.replace(/^\uFEFF/, '').split(/\r?\n/);
56
+ const first = lines[0];
57
+ if (first === undefined || !FENCE_PATTERN.test(first)) {
58
+ return { ok: false, reason: '缺少 YAML frontmatter 起始分隔行(---)' };
59
+ }
60
+ const fields = new Map();
61
+ let fence = -1;
62
+ for (let index = 1; index < lines.length; index += 1) {
63
+ const line = lines[index] ?? '';
64
+ if (FENCE_PATTERN.test(line)) {
65
+ fence = index;
66
+ break;
67
+ }
68
+ const entry = line.trim();
69
+ if (entry === '' || entry.startsWith('#'))
70
+ continue;
71
+ const colon = entry.indexOf(':');
72
+ if (colon <= 0) {
73
+ return { ok: false, reason: `frontmatter 第 ${index + 1} 行不是 key: value 形式:${entry}` };
74
+ }
75
+ fields.set(entry.slice(0, colon).trim(), unquote(entry.slice(colon + 1).trim()));
76
+ }
77
+ if (fence < 0) {
78
+ return { ok: false, reason: 'frontmatter 缺少结束分隔行(---)' };
79
+ }
80
+ const name = fields.get('name') ?? '';
81
+ if (!SKILL_NAME_PATTERN.test(name)) {
82
+ return { ok: false, reason: `name 必须是 kebab-case,当前为:${name === '' ? '(缺失)' : name}` };
83
+ }
84
+ const description = fields.get('description') ?? '';
85
+ if (description === '')
86
+ return { ok: false, reason: 'description 不能为空' };
87
+ // 正文从结束分隔行之后开始;首尾空白对模型没有意义,一并去掉。
88
+ const content = lines.slice(fence + 1).join('\n').trim();
89
+ if (content === '')
90
+ return { ok: false, reason: '正文为空' };
91
+ const whenToUse = fields.get('whenToUse') ?? '';
92
+ return {
93
+ ok: true,
94
+ skill: {
95
+ name,
96
+ description,
97
+ content,
98
+ // 空的 whenToUse 视为没写,避免把空串当成有效提示交给模型。
99
+ ...(whenToUse === '' ? {} : { whenToUse }),
100
+ },
101
+ };
102
+ }
103
+ /**
104
+ * Register the bundled skills into the running profile's skill catalog.
105
+ *
106
+ * Called from `apply`, and returns immediately: the actual registration happens
107
+ * on the injected child fiber, whenever the `skills` service exists. Nothing
108
+ * here is order-sensitive, and nothing here can fail a mount — a profile that
109
+ * never provides a skill registry simply never runs the callback.
110
+ *
111
+ * `skills` is deliberately **not** in the plugin's static `inject`: that would
112
+ * hold the whole plugin in PENDING until the registry appears, and a profile
113
+ * without one would never mount the dashboard at all.
114
+ */
115
+ export function registerBundledSkills(ctx, options = {}) {
116
+ const logger = loggerOf(ctx);
117
+ ctx.inject(['skills'], (scoped) => {
118
+ const skills = scoped.get('skills');
119
+ if (skills === undefined || skills === null || typeof skills.register !== 'function') {
120
+ logger.warn('work-dashboard: skills 服务不可用于注册,内置 skill 未注册(看板不受影响)');
121
+ return;
122
+ }
123
+ publishBundledSkills(scoped, skills, logger, options);
124
+ });
125
+ }
126
+ /**
127
+ * Read, parse and publish every bundled skill on the fiber that owns the injection.
128
+ *
129
+ * One bad skill must not take the others down: each is registered inside its
130
+ * own try/catch and its failure is a warning. A bundled skill is an addition to
131
+ * the profile, never a reason to fail a mount.
132
+ */
133
+ function publishBundledSkills(ctx, skills, logger, options) {
134
+ const root = options.dir ?? bundledSkillsDirectory();
135
+ for (const name of BUNDLED_SKILL_NAMES) {
136
+ const directory = join(root, name);
137
+ const skillFile = join(directory, SKILL_FILE_NAME);
138
+ if (!existsSync(skillFile)) {
139
+ logger.warn(`work-dashboard: 内置 skill 文件不存在(${skillFile}),已跳过 ${name}`);
140
+ continue;
141
+ }
142
+ let source;
143
+ try {
144
+ source = readFileSync(skillFile, 'utf8');
145
+ }
146
+ catch (error) {
147
+ logger.warn(`work-dashboard: 读取内置 skill 失败(${skillFile}):${messageOf(error)}`);
148
+ continue;
149
+ }
150
+ const parsed = parseSkillMarkdown(source);
151
+ if (!parsed.ok) {
152
+ logger.warn(`work-dashboard: 内置 skill 的 frontmatter 不可用(${skillFile}):${parsed.reason}`);
153
+ continue;
154
+ }
155
+ if (parsed.skill.name !== name) {
156
+ logger.warn(`work-dashboard: 内置 skill 目录名与 frontmatter name 不一致(${name} ≠ ${parsed.skill.name}),已跳过`);
157
+ continue;
158
+ }
159
+ const skill = parsed.skill;
160
+ let dispose;
161
+ try {
162
+ dispose = skills.register({
163
+ name: skill.name,
164
+ description: skill.description,
165
+ content: skill.content,
166
+ source: 'bundled',
167
+ path: skillFile,
168
+ // 模型据此把 skill 里提到的相对路径解析到 scripts/ 等资源上。
169
+ resourceBase: { kind: 'directory', path: directory },
170
+ ...(skill.whenToUse === undefined ? {} : { whenToUse: skill.whenToUse }),
171
+ });
172
+ }
173
+ catch (error) {
174
+ logger.warn(`work-dashboard: 注册内置 skill ${name} 失败:${messageOf(error)}`);
175
+ continue;
176
+ }
177
+ try {
178
+ // 绑在注入自己的 fiber 上:该 fiber 的撤销登记在父 fiber,所以插件卸载时会一并撤销;
179
+ // 服务被替换时回调重跑,也会先撤掉上一次的注册。绑定失败则立刻回滚,不留无主目录项。
180
+ ctx.effect(() => dispose, `work-dashboard: bundled skill ${skill.name}`);
181
+ }
182
+ catch (error) {
183
+ dispose();
184
+ logger.warn(`work-dashboard: 绑定内置 skill ${name} 生命周期失败:${messageOf(error)}`);
185
+ continue;
186
+ }
187
+ // The one line that proves the whole path worked at runtime: it prints only
188
+ // when the skills service was present AND the file parsed AND the registry
189
+ // accepted the payload. Integration verification greps the boot log for it.
190
+ //
191
+ // Written to stderr rather than only through `ctx.logger`: a DSH deployment
192
+ // may not route the Host logger anywhere an operator (or a test harness) can
193
+ // read, and this single lifecycle line is the only evidence that the skills
194
+ // actually reached the catalog. It is one line per skill, on mount only.
195
+ logger.info(`work-dashboard: 内置 skill 已注册(${skill.name} ← ${skillFile})`);
196
+ process.stderr.write(`[work-dashboard] skill registered: ${skill.name}\n`);
197
+ }
198
+ }
199
+ /** Strip one matching pair of single or double quotes; escapes are not interpreted. */
200
+ function unquote(value) {
201
+ if (value.length < 2)
202
+ return value;
203
+ const first = value[0];
204
+ const last = value[value.length - 1];
205
+ if ((first === '"' && last === '"') || (first === "'" && last === "'"))
206
+ return value.slice(1, -1);
207
+ return value;
208
+ }
209
+ /** Best-effort error text; a diagnostic must never be the thing that throws. */
210
+ function messageOf(error) {
211
+ return error instanceof Error ? error.message : String(error);
212
+ }
213
+ /** Best-effort logger access; a context without a logger still mounts. */
214
+ function loggerOf(ctx) {
215
+ const logger = ctx.logger;
216
+ return {
217
+ info: (message) => { logger?.info?.(message); },
218
+ warn: (message) => { logger?.warn?.(message); },
219
+ };
220
+ }
package/lib/store.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Read-only ledger store (v3).
3
+ *
4
+ * The store turns the cloned `projects/*.yaml` files into the JSON shapes the
5
+ * Client renders. It never writes: the repository is a read-only copy and the
6
+ * real data source is GitHub.
7
+ *
8
+ * v3 is **progress-centred**: a project's state is its identity + gate0 + plan +
9
+ * progress stream + outcome. The summary therefore reads `gate0` for the G0
10
+ * verdict, `plan` for focus, `progress` for activity, and `outcome` for the four
11
+ * dimensions — there is no separate `result` block to reconcile.
12
+ *
13
+ * Parsing uses `yaml`'s `parse`. One unreadable or unparsable file is reported
14
+ * as a warning and skipped: a single bad hand-edit must not blank the whole
15
+ * board.
16
+ */
17
+ import type { RepoCache } from './repo.js';
18
+ import type { GapItem, OrgRecord, PocRecord, PortfolioAnalysis, ProjectDetail, ProjectSummary, Snapshot, StageId } from './types.js';
19
+ /** Injected clock so the store stays testable and the rules stay pure. */
20
+ export interface StoreOptions {
21
+ now: () => Date;
22
+ /** Days in one stage after which rule 12 fires. */
23
+ stallDays: number;
24
+ }
25
+ /** The Host-side view model builder. */
26
+ export declare class PocStore {
27
+ private readonly cache;
28
+ private readonly options;
29
+ constructor(cache: RepoCache, options: StoreOptions);
30
+ /** Load every project file; one bad file becomes a warning, not a failure. */
31
+ load(): Promise<{
32
+ records: PocRecord[];
33
+ warnings: string[];
34
+ }>;
35
+ /** The overview snapshot; never throws for a missing cache, it reports it. */
36
+ snapshot(): Promise<Snapshot>;
37
+ /** One project's full record; `null` when no file declares that id. */
38
+ detail(pocId: string): Promise<ProjectDetail | null>;
39
+ }
40
+ /**
41
+ * Aggregate the project list into the portfolio band.
42
+ *
43
+ * This is the only place the charts get their numbers from. Everything is
44
+ * derived from `projects` (and the already-scanned `gaps`), so a chart can
45
+ * never show a figure the table contradicts. Buckets keep their full cardinality
46
+ * even when empty: a funnel with a missing column reads as a rendering bug.
47
+ */
48
+ export declare function analyse(projects: ProjectSummary[], gaps: GapItem[]): PortfolioAnalysis;
49
+ /** An empty analysis, for the cold-cache snapshot. */
50
+ export declare function emptyAnalysis(): PortfolioAnalysis;
51
+ /** Build the G0 checklist from the parsed fields. */
52
+ export declare function gate0Checklist(gate0: {
53
+ whyCustomer: string;
54
+ whyUs: string;
55
+ decisionChain: string;
56
+ postPocDecision: string;
57
+ }, techOwner: string): Array<{
58
+ field: string;
59
+ present: boolean;
60
+ value: string;
61
+ }>;
62
+ /** Re-export the org type so the Client can name it. */
63
+ export type { OrgRecord, StageId };