@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.
- package/LICENSE +21 -0
- package/README.en.md +259 -0
- package/README.md +371 -2
- package/UNINSTALL.md +7 -0
- package/compatibility.json +195 -0
- package/cordis.patch.yml +24 -0
- package/docs/DESIGN-0.3.md +122 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/PLAN-0.7-0.9.md +230 -0
- package/docs/preview.svg +254 -0
- package/docs/preview.zh.svg +254 -0
- package/icon.svg +17 -0
- package/lib/blockers.d.ts +45 -0
- package/lib/blockers.js +160 -0
- package/lib/client/api.d.ts +42 -0
- package/lib/client/api.js +45 -0
- package/lib/client/contracts.d.ts +94 -0
- package/lib/client/contracts.js +21 -0
- package/lib/client/css/base.d.ts +31 -0
- package/lib/client/css/base.js +461 -0
- package/lib/client/css/blockers.d.ts +18 -0
- package/lib/client/css/blockers.js +196 -0
- package/lib/client/css/charts.d.ts +14 -0
- package/lib/client/css/charts.js +191 -0
- package/lib/client/css/detail.d.ts +21 -0
- package/lib/client/css/detail.js +423 -0
- package/lib/client/css/insights.d.ts +27 -0
- package/lib/client/css/insights.js +660 -0
- package/lib/client/css/overview.d.ts +23 -0
- package/lib/client/css/overview.js +327 -0
- package/lib/client/css/summary.d.ts +13 -0
- package/lib/client/css/summary.js +187 -0
- package/lib/client/format.d.ts +57 -0
- package/lib/client/format.js +96 -0
- package/lib/client/preferences.d.ts +56 -0
- package/lib/client/preferences.js +118 -0
- package/lib/client/styles.d.ts +17 -0
- package/lib/client/styles.js +24 -0
- package/lib/client/text.d.ts +32 -0
- package/lib/client/text.js +1112 -0
- package/lib/client/view-contract.d.ts +118 -0
- package/lib/client/view-contract.js +28 -0
- package/lib/client.js +6599 -0
- package/lib/config.d.ts +61 -0
- package/lib/config.js +67 -0
- package/lib/form.d.ts +218 -0
- package/lib/form.js +1075 -0
- package/lib/gap.d.ts +60 -0
- package/lib/gap.js +227 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +159 -0
- package/lib/repo.d.ts +124 -0
- package/lib/repo.js +407 -0
- package/lib/risks.d.ts +24 -0
- package/lib/risks.js +85 -0
- package/lib/skill.d.ts +94 -0
- package/lib/skill.js +220 -0
- package/lib/store.d.ts +63 -0
- package/lib/store.js +505 -0
- package/lib/timeline.d.ts +23 -0
- package/lib/timeline.js +93 -0
- package/lib/transport.d.ts +67 -0
- package/lib/transport.js +131 -0
- package/lib/types.d.ts +701 -0
- package/lib/types.js +78 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +117 -4
- package/skills/poc-export/SKILL.md +81 -0
- package/skills/poc-export/scripts/export-form.mjs +654 -0
- package/skills/poc-ledger/SKILL.md +171 -0
- package/skills/poc-submit/SKILL.md +186 -0
package/lib/gap.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The twelve v3 gap rules, as pure functions.
|
|
3
|
+
*
|
|
4
|
+
* The rules are hard-coded here on purpose: they are the product's judgement,
|
|
5
|
+
* not repository data, so they must not drift with a script the data source
|
|
6
|
+
* happens to ship. Every rule is a total function of `(record, options)` —
|
|
7
|
+
* no clock, no filesystem, no locale — so `tests/gap.spec.ts` can pin each one
|
|
8
|
+
* to a fixture.
|
|
9
|
+
*
|
|
10
|
+
* The v3 model is **progress-centred**: a project is judged by its latest
|
|
11
|
+
* progress entry, not by a separately-maintained `result` block. Rules 8–10
|
|
12
|
+
* therefore read `progress[progress.length - 1]`, and rule 7 compares "has any
|
|
13
|
+
* progress" against the G2 readiness flag.
|
|
14
|
+
*/
|
|
15
|
+
import type { GapItem, GapLevel, PocRecord, StageId } from './types.js';
|
|
16
|
+
/** Normalize the free-form `stage` string onto a stage id. */
|
|
17
|
+
export declare function normalizeStage(raw: unknown): {
|
|
18
|
+
stage: StageId | null;
|
|
19
|
+
closed: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Trim a scalar to a string; absent, null and blank all collapse to `''`. */
|
|
22
|
+
export declare function text(value: unknown): string;
|
|
23
|
+
/** `true` when a value carries no content at all. */
|
|
24
|
+
export declare function blank(value: unknown): boolean;
|
|
25
|
+
/** A numeric value, or `null` when absent or not a finite number. */
|
|
26
|
+
export declare function numberOrNull(value: unknown): number | null;
|
|
27
|
+
/** Options the rule set needs from the caller, so it stays clock-free. */
|
|
28
|
+
export interface ScanOptions {
|
|
29
|
+
/** Injected clock: the rules compare against it, tests pin it. */
|
|
30
|
+
now: Date;
|
|
31
|
+
/** Days in one stage after which rule 12 fires. */
|
|
32
|
+
stallDays: number;
|
|
33
|
+
}
|
|
34
|
+
/** Rule metadata: number, severity and sort weight. */
|
|
35
|
+
export declare const RULE_META: Record<GapItem['rule'], {
|
|
36
|
+
no: number;
|
|
37
|
+
level: GapLevel;
|
|
38
|
+
priority: number;
|
|
39
|
+
}>;
|
|
40
|
+
/** The four dimensions, resolved from the v3 `outcome` block. */
|
|
41
|
+
export declare function readDimensions(poc: PocRecord): {
|
|
42
|
+
achievement: boolean;
|
|
43
|
+
evidence: boolean;
|
|
44
|
+
recognition: boolean;
|
|
45
|
+
nextMilestone: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** The newest progress entry, or `null`. */
|
|
48
|
+
export declare function latestProgress(poc: PocRecord): Record<string, unknown> | null;
|
|
49
|
+
/** The newest progress date, or `null`. */
|
|
50
|
+
export declare function lastProgressDate(poc: PocRecord): string | null;
|
|
51
|
+
/** Whole days between a `YYYY-MM-DD` date and the scan clock. */
|
|
52
|
+
export declare function daysSince(date: string | null, now: Date): number | null;
|
|
53
|
+
/**
|
|
54
|
+
* Scan one record and return every v3 gap it has.
|
|
55
|
+
*
|
|
56
|
+
* The returned list is ordered by severity then rule number; the overview page
|
|
57
|
+
* concatenates the per-project lists and re-sorts, so order here only has to be
|
|
58
|
+
* stable for tests.
|
|
59
|
+
*/
|
|
60
|
+
export declare function scanGaps(poc: PocRecord, options: ScanOptions): GapItem[];
|
package/lib/gap.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The twelve v3 gap rules, as pure functions.
|
|
3
|
+
*
|
|
4
|
+
* The rules are hard-coded here on purpose: they are the product's judgement,
|
|
5
|
+
* not repository data, so they must not drift with a script the data source
|
|
6
|
+
* happens to ship. Every rule is a total function of `(record, options)` —
|
|
7
|
+
* no clock, no filesystem, no locale — so `tests/gap.spec.ts` can pin each one
|
|
8
|
+
* to a fixture.
|
|
9
|
+
*
|
|
10
|
+
* The v3 model is **progress-centred**: a project is judged by its latest
|
|
11
|
+
* progress entry, not by a separately-maintained `result` block. Rules 8–10
|
|
12
|
+
* therefore read `progress[progress.length - 1]`, and rule 7 compares "has any
|
|
13
|
+
* progress" against the G2 readiness flag.
|
|
14
|
+
*/
|
|
15
|
+
/** Stage prefixes a raw `stage` value can normalize to, in order. */
|
|
16
|
+
const STAGE_PREFIXES = [
|
|
17
|
+
['G0', 'G0'],
|
|
18
|
+
['G1', 'G1'],
|
|
19
|
+
['G2', 'G2'],
|
|
20
|
+
['G3', 'G3'],
|
|
21
|
+
['G4', 'G4'],
|
|
22
|
+
];
|
|
23
|
+
/** Normalize the free-form `stage` string onto a stage id. */
|
|
24
|
+
export function normalizeStage(raw) {
|
|
25
|
+
const value = typeof raw === 'string' ? raw.trim() : '';
|
|
26
|
+
if (value === '')
|
|
27
|
+
return { stage: null, closed: false };
|
|
28
|
+
if (value.toLowerCase() === 'closed')
|
|
29
|
+
return { stage: null, closed: true };
|
|
30
|
+
for (const [stage, prefix] of STAGE_PREFIXES) {
|
|
31
|
+
if (value === prefix || value.startsWith(`${prefix}-`))
|
|
32
|
+
return { stage, closed: false };
|
|
33
|
+
}
|
|
34
|
+
return { stage: null, closed: false };
|
|
35
|
+
}
|
|
36
|
+
/** Trim a scalar to a string; absent, null and blank all collapse to `''`. */
|
|
37
|
+
export function text(value) {
|
|
38
|
+
if (value === null || value === undefined)
|
|
39
|
+
return '';
|
|
40
|
+
if (typeof value === 'string')
|
|
41
|
+
return value.trim();
|
|
42
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
43
|
+
return String(value);
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
/** `true` when a value carries no content at all. */
|
|
47
|
+
export function blank(value) {
|
|
48
|
+
if (Array.isArray(value))
|
|
49
|
+
return value.length === 0;
|
|
50
|
+
return text(value) === '';
|
|
51
|
+
}
|
|
52
|
+
/** A numeric value, or `null` when absent or not a finite number. */
|
|
53
|
+
export function numberOrNull(value) {
|
|
54
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
55
|
+
return value;
|
|
56
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
57
|
+
const parsed = Number(value);
|
|
58
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/** Rule metadata: number, severity and sort weight. */
|
|
63
|
+
export const RULE_META = {
|
|
64
|
+
// R1: the G0 floor. Nothing downstream is trustworthy without it.
|
|
65
|
+
'R1-gate0-missing': { no: 1, level: 'high', priority: 90 },
|
|
66
|
+
// R2: a large commitment decided before the gate was cleared.
|
|
67
|
+
'R2-large-amount-no-g0': { no: 2, level: 'high', priority: 94 },
|
|
68
|
+
// R3: cleared the gate, then never wrote down what success means.
|
|
69
|
+
'R3-g0-passed-no-plan': { no: 3, level: 'high', priority: 92 },
|
|
70
|
+
// R4–R6: focus. A pilot measuring everything measures nothing.
|
|
71
|
+
'R4-criteria-count': { no: 4, level: 'medium', priority: 50 },
|
|
72
|
+
'R5-scenarios-count': { no: 5, level: 'medium', priority: 48 },
|
|
73
|
+
'R6-risks-overflow': { no: 6, level: 'medium', priority: 46 },
|
|
74
|
+
// R7: testing before the prerequisites are ready burns team time.
|
|
75
|
+
'R7-g2-not-ready': { no: 7, level: 'high', priority: 84 },
|
|
76
|
+
// R8–R10: the proof chain, read from the newest progress entry.
|
|
77
|
+
'R8-progress-no-evidence': { no: 8, level: 'high', priority: 82 },
|
|
78
|
+
'R9-evidence-no-recognition': { no: 9, level: 'high', priority: 80 },
|
|
79
|
+
'R10-g3-1-without-g3-2': { no: 10, level: 'high', priority: 78 },
|
|
80
|
+
// R11: it worked, and nothing followed. The highest-value gap, as the
|
|
81
|
+
// original design documented: value was created and none of it was banked.
|
|
82
|
+
'R11-no-next-milestone': { no: 11, level: 'high', priority: 96 },
|
|
83
|
+
// R12: the project has not moved.
|
|
84
|
+
'R12-stage-stalled': { no: 12, level: 'medium', priority: 40 },
|
|
85
|
+
};
|
|
86
|
+
/** Build one finding, stamping the rule metadata from {@link RULE_META}. */
|
|
87
|
+
function gap(poc, rule, extra = {}) {
|
|
88
|
+
const meta = RULE_META[rule];
|
|
89
|
+
return {
|
|
90
|
+
rule,
|
|
91
|
+
ruleNo: meta.no,
|
|
92
|
+
level: meta.level,
|
|
93
|
+
priority: meta.priority,
|
|
94
|
+
pocId: text(poc.poc_id),
|
|
95
|
+
pocName: text(poc.name),
|
|
96
|
+
...extra,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** The four dimensions, resolved from the v3 `outcome` block. */
|
|
100
|
+
export function readDimensions(poc) {
|
|
101
|
+
const outcome = poc.outcome ?? {};
|
|
102
|
+
const progress = Array.isArray(poc.progress) ? poc.progress : [];
|
|
103
|
+
const last = progress.length === 0 ? null : progress[progress.length - 1];
|
|
104
|
+
// `outcome` is mostly auto-derived from the last progress entry, so a project
|
|
105
|
+
// that has progressed but not yet had its outcome summarised still counts:
|
|
106
|
+
// evidence exists when either the outcome or the newest entry carries it.
|
|
107
|
+
const lastEvidence = Array.isArray(last?.evidence) ? last.evidence : [];
|
|
108
|
+
return {
|
|
109
|
+
achievement: !blank(outcome.achievement),
|
|
110
|
+
evidence: !blank(outcome.our_proof) || lastEvidence.length > 0,
|
|
111
|
+
recognition: !blank(outcome.customer_recognition),
|
|
112
|
+
nextMilestone: !blank(outcome.business?.milestone),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** The newest progress entry, or `null`. */
|
|
116
|
+
export function latestProgress(poc) {
|
|
117
|
+
const progress = Array.isArray(poc.progress) ? poc.progress : [];
|
|
118
|
+
const last = progress.length === 0 ? null : progress[progress.length - 1];
|
|
119
|
+
return (last ?? null);
|
|
120
|
+
}
|
|
121
|
+
/** The newest progress date, or `null`. */
|
|
122
|
+
export function lastProgressDate(poc) {
|
|
123
|
+
const progress = Array.isArray(poc.progress) ? poc.progress : [];
|
|
124
|
+
let newest = null;
|
|
125
|
+
for (const entry of progress) {
|
|
126
|
+
const date = text(entry?.date);
|
|
127
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
128
|
+
continue;
|
|
129
|
+
if (Number.isNaN(Date.parse(`${date}T00:00:00Z`)))
|
|
130
|
+
continue;
|
|
131
|
+
if (newest === null || date > newest)
|
|
132
|
+
newest = date;
|
|
133
|
+
}
|
|
134
|
+
return newest;
|
|
135
|
+
}
|
|
136
|
+
/** Whole days between a `YYYY-MM-DD` date and the scan clock. */
|
|
137
|
+
export function daysSince(date, now) {
|
|
138
|
+
if (date === null)
|
|
139
|
+
return null;
|
|
140
|
+
const stamp = Date.parse(`${date}T00:00:00Z`);
|
|
141
|
+
if (Number.isNaN(stamp))
|
|
142
|
+
return null;
|
|
143
|
+
return Math.floor((now.getTime() - stamp) / 86_400_000);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Scan one record and return every v3 gap it has.
|
|
147
|
+
*
|
|
148
|
+
* The returned list is ordered by severity then rule number; the overview page
|
|
149
|
+
* concatenates the per-project lists and re-sorts, so order here only has to be
|
|
150
|
+
* stable for tests.
|
|
151
|
+
*/
|
|
152
|
+
export function scanGaps(poc, options) {
|
|
153
|
+
const gaps = [];
|
|
154
|
+
const gate0 = poc.gate0 ?? {};
|
|
155
|
+
const plan = poc.plan ?? {};
|
|
156
|
+
const outcome = poc.outcome ?? {};
|
|
157
|
+
const amountWan = numberOrNull(poc.amount_wan) ?? 0;
|
|
158
|
+
const progress = Array.isArray(poc.progress) ? poc.progress : [];
|
|
159
|
+
const last = latestProgress(poc);
|
|
160
|
+
// R1 — the five G0 prerequisites. `gate0.missing` is computed by the ledger and
|
|
161
|
+
// was verified against actual field emptiness, so it is trusted as-is.
|
|
162
|
+
const missing = Array.isArray(gate0.missing) ? gate0.missing.map(text).filter((item) => item !== '') : [];
|
|
163
|
+
if (missing.length > 0) {
|
|
164
|
+
gaps.push(gap(poc, 'R1-gate0-missing', { field: 'gate0.missing', params: { count: missing.length, missing: missing.join(',') } }));
|
|
165
|
+
}
|
|
166
|
+
// R2 — a large commitment whose G0 was never cleared.
|
|
167
|
+
const conclusion = text(gate0.review?.conclusion);
|
|
168
|
+
if (amountWan >= 300 && conclusion !== '通过') {
|
|
169
|
+
gaps.push(gap(poc, 'R2-large-amount-no-g0', { field: 'gate0.review.conclusion', params: { amountWan, conclusion: conclusion === '' ? '未评审' : conclusion } }));
|
|
170
|
+
}
|
|
171
|
+
// R3 — cleared the gate but never defined success.
|
|
172
|
+
if (conclusion === '通过' && (plan.criteria ?? []).length === 0) {
|
|
173
|
+
gaps.push(gap(poc, 'R3-g0-passed-no-plan', { field: 'plan.criteria' }));
|
|
174
|
+
}
|
|
175
|
+
// R4–R6 — focus limits. Only fires when the list is non-empty, so a project
|
|
176
|
+
// that has not planned yet is not punished twice (R3 covers that case).
|
|
177
|
+
const criteria = (plan.criteria ?? []).length;
|
|
178
|
+
if (criteria > 0 && (criteria < 2 || criteria > 3)) {
|
|
179
|
+
gaps.push(gap(poc, 'R4-criteria-count', { field: 'plan.criteria', params: { count: criteria, min: 2, max: 3 } }));
|
|
180
|
+
}
|
|
181
|
+
const scenarios = (plan.scenarios ?? []).length;
|
|
182
|
+
if (scenarios > 0 && (scenarios < 3 || scenarios > 5)) {
|
|
183
|
+
gaps.push(gap(poc, 'R5-scenarios-count', { field: 'plan.scenarios', params: { count: scenarios, min: 3, max: 5 } }));
|
|
184
|
+
}
|
|
185
|
+
const risks = (plan.risks ?? []).length;
|
|
186
|
+
if (risks > 3) {
|
|
187
|
+
gaps.push(gap(poc, 'R6-risks-overflow', { field: 'plan.risks', params: { count: risks, max: 3 } }));
|
|
188
|
+
}
|
|
189
|
+
// R7 — testing started before G2 was ready.
|
|
190
|
+
const ready = text(plan.gate2?.ready);
|
|
191
|
+
if (progress.length > 0 && ready !== 'Ready') {
|
|
192
|
+
gaps.push(gap(poc, 'R7-g2-not-ready', { field: 'plan.gate2.ready', params: { ready: ready === '' ? '未设置' : ready } }));
|
|
193
|
+
}
|
|
194
|
+
// R8–R10 — the proof chain, judged by the NEWEST progress entry only.
|
|
195
|
+
if (last !== null) {
|
|
196
|
+
const evidence = Array.isArray(last.evidence) ? last.evidence : [];
|
|
197
|
+
const actual = text(last.actual);
|
|
198
|
+
const recognition = text(last.customer?.recognition);
|
|
199
|
+
// R8: a claimed result with nothing behind it.
|
|
200
|
+
if (actual !== '' && evidence.length === 0) {
|
|
201
|
+
gaps.push(gap(poc, 'R8-progress-no-evidence', { field: 'progress.evidence', params: { seq: numberOrNull(last.seq) ?? 0 } }));
|
|
202
|
+
}
|
|
203
|
+
// R9: evidence exists, but the customer has not confirmed it.
|
|
204
|
+
if (evidence.length > 0 && (recognition === '未认可' || recognition === '待确认')) {
|
|
205
|
+
gaps.push(gap(poc, 'R9-evidence-no-recognition', { field: 'progress.customer.recognition', params: { recognition } }));
|
|
206
|
+
}
|
|
207
|
+
// R10: provable, but never confirmed.
|
|
208
|
+
if (text(last.gate3_1) === '可证明' && text(last.gate3_2) !== '已确认') {
|
|
209
|
+
gaps.push(gap(poc, 'R10-g3-1-without-g3-2', { field: 'progress.gate3_2', params: { gate3_2: text(last.gate3_2) === '' ? '未填' : text(last.gate3_2) } }));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// R11 — achieved, and no next milestone: value created, none banked.
|
|
213
|
+
if (text(outcome.achievement) === '达成' && blank(outcome.business?.milestone)) {
|
|
214
|
+
gaps.push(gap(poc, 'R11-no-next-milestone', { field: 'outcome.business.milestone' }));
|
|
215
|
+
}
|
|
216
|
+
// R12 — the project has not moved for `stallDays`.
|
|
217
|
+
// The schema says `stage_since`; a project without it cannot be judged, so it
|
|
218
|
+
// is not reported rather than assumed stale.
|
|
219
|
+
const since = text(poc.stage_since);
|
|
220
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(since)) {
|
|
221
|
+
const days = daysSince(since, options.now);
|
|
222
|
+
if (days !== null && days > options.stallDays) {
|
|
223
|
+
gaps.push(gap(poc, 'R12-stage-stalled', { field: 'stage_since', params: { days, stage: text(poc.stage), stallDays: options.stallDays } }));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return gaps.sort((left, right) => right.priority - left.priority || left.ruleNo - right.ruleNo || left.rule.localeCompare(right.rule));
|
|
227
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host entry of the work dashboard.
|
|
3
|
+
*
|
|
4
|
+
* Ownership split: this half owns the disposable git cache, the YAML parse and
|
|
5
|
+
* the gap scan, and exposes them through one Connection route; the Client half
|
|
6
|
+
* owns only view state (which page, which project, the refresh cadence).
|
|
7
|
+
*
|
|
8
|
+
* Everything registered here belongs to this plugin's Fiber, so stopping or
|
|
9
|
+
* updating the row releases the route and the cache lifetime with no residue.
|
|
10
|
+
*
|
|
11
|
+
* The cache is wiped at mount, per the specification: the repository on GitHub
|
|
12
|
+
* is the only truth, and a stale local copy must never be mistaken for it.
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
import { resolveConfig } from './config.js';
|
|
16
|
+
import type { WorkDashboardConfig } from './config.js';
|
|
17
|
+
import { RepoError } from './repo.js';
|
|
18
|
+
import type { ConsoleActions } from './transport.js';
|
|
19
|
+
export { resolveConfig };
|
|
20
|
+
export { Config } from './config.js';
|
|
21
|
+
export declare const name = "skillre-work-dashboard";
|
|
22
|
+
/**
|
|
23
|
+
* Required services. `connection` provides the authenticated Client route; it
|
|
24
|
+
* is a hard dependency so a profile without it fails loudly instead of mounting
|
|
25
|
+
* a board that can never be reached.
|
|
26
|
+
*/
|
|
27
|
+
export declare const inject: string[];
|
|
28
|
+
/** The console facade the route dispatches onto. */
|
|
29
|
+
export interface DashboardRuntime extends ConsoleActions {
|
|
30
|
+
/** Wipe the cache (mount) and resolve the store. */
|
|
31
|
+
prepare(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/** Build the runtime around one resolved configuration. */
|
|
34
|
+
export declare function createRuntime(config: WorkDashboardConfig, options?: {
|
|
35
|
+
home?: string;
|
|
36
|
+
now?: () => Date;
|
|
37
|
+
}): DashboardRuntime;
|
|
38
|
+
export declare function apply(ctx: Context, rawConfig?: Partial<WorkDashboardConfig>): void;
|
|
39
|
+
/** Re-export the error type so tests and the transport share one identity. */
|
|
40
|
+
export { RepoError };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host entry of the work dashboard.
|
|
3
|
+
*
|
|
4
|
+
* Ownership split: this half owns the disposable git cache, the YAML parse and
|
|
5
|
+
* the gap scan, and exposes them through one Connection route; the Client half
|
|
6
|
+
* owns only view state (which page, which project, the refresh cadence).
|
|
7
|
+
*
|
|
8
|
+
* Everything registered here belongs to this plugin's Fiber, so stopping or
|
|
9
|
+
* updating the row releases the route and the cache lifetime with no residue.
|
|
10
|
+
*
|
|
11
|
+
* The cache is wiped at mount, per the specification: the repository on GitHub
|
|
12
|
+
* is the only truth, and a stale local copy must never be mistaken for it.
|
|
13
|
+
*/
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import YAML from 'yaml';
|
|
16
|
+
import { resolveConfig, expandHome, remoteUrlFor } from './config.js';
|
|
17
|
+
import { PocStore } from './store.js';
|
|
18
|
+
import { RepoCache, RepoError, assertSafeCacheRoot } from './repo.js';
|
|
19
|
+
import { buildRiskBoard } from './risks.js';
|
|
20
|
+
import { buildGlobalTimeline } from './timeline.js';
|
|
21
|
+
import { text } from './gap.js';
|
|
22
|
+
import { buildFormHtml, formFileName, projectForForm } from './form.js';
|
|
23
|
+
import { registerBundledSkills } from './skill.js';
|
|
24
|
+
import { createExecuteRoute } from './transport.js';
|
|
25
|
+
export { resolveConfig };
|
|
26
|
+
export { Config } from './config.js';
|
|
27
|
+
export const name = 'skillre-work-dashboard';
|
|
28
|
+
/**
|
|
29
|
+
* Required services. `connection` provides the authenticated Client route; it
|
|
30
|
+
* is a hard dependency so a profile without it fails loudly instead of mounting
|
|
31
|
+
* a board that can never be reached.
|
|
32
|
+
*/
|
|
33
|
+
export const inject = ['connection'];
|
|
34
|
+
/** Read an optional Cordis service without declaring it required. */
|
|
35
|
+
function service(ctx, key) {
|
|
36
|
+
return ctx.get(key);
|
|
37
|
+
}
|
|
38
|
+
/** Build the runtime around one resolved configuration. */
|
|
39
|
+
export function createRuntime(config, options = {}) {
|
|
40
|
+
const home = options.home ?? homedir();
|
|
41
|
+
const cacheRoot = assertSafeCacheRoot(expandHome(config.cacheRoot, home), home);
|
|
42
|
+
const now = options.now ?? (() => new Date());
|
|
43
|
+
const remoteUrl = remoteUrlFor(config);
|
|
44
|
+
const cache = new RepoCache({
|
|
45
|
+
cacheRoot,
|
|
46
|
+
repository: config.repository,
|
|
47
|
+
branch: config.defaultBranch,
|
|
48
|
+
remoteUrl,
|
|
49
|
+
cloneTimeoutMs: config.cloneTimeoutMs,
|
|
50
|
+
fetchTimeoutMs: config.fetchTimeoutMs,
|
|
51
|
+
});
|
|
52
|
+
const store = new PocStore(cache, { now, stallDays: config.stallDays });
|
|
53
|
+
let prepared = null;
|
|
54
|
+
/**
|
|
55
|
+
* Load the records, treating a cold cache as an EMPTY ledger.
|
|
56
|
+
*
|
|
57
|
+
* The board, the risk board and the timeline are all reachable before the
|
|
58
|
+
* first Refresh; "no data yet" is the honest answer there, so a missing clone
|
|
59
|
+
* (or a repository without `projects/`) yields no records rather than an error.
|
|
60
|
+
*/
|
|
61
|
+
const loadOrEmpty = async () => {
|
|
62
|
+
try {
|
|
63
|
+
return (await store.load()).records;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof RepoError && (error.code === 'no-projects' || error.code === 'not-found'))
|
|
67
|
+
return [];
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
async prepare() {
|
|
73
|
+
prepared ??= cache.prepare();
|
|
74
|
+
return prepared;
|
|
75
|
+
},
|
|
76
|
+
async snapshot() {
|
|
77
|
+
await this.prepare();
|
|
78
|
+
return store.snapshot();
|
|
79
|
+
},
|
|
80
|
+
async refresh() {
|
|
81
|
+
await this.prepare();
|
|
82
|
+
const outcome = await cache.refresh();
|
|
83
|
+
return { snapshot: await store.snapshot(), outcome };
|
|
84
|
+
},
|
|
85
|
+
async detail(pocId) {
|
|
86
|
+
await this.prepare();
|
|
87
|
+
return store.detail(pocId);
|
|
88
|
+
},
|
|
89
|
+
async risks() {
|
|
90
|
+
await this.prepare();
|
|
91
|
+
return buildRiskBoard(await loadOrEmpty(), { now: now(), stallDays: config.stallDays });
|
|
92
|
+
},
|
|
93
|
+
async timeline() {
|
|
94
|
+
await this.prepare();
|
|
95
|
+
return buildGlobalTimeline(await loadOrEmpty(), { stallDays: config.stallDays });
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Build the collection form.
|
|
99
|
+
*
|
|
100
|
+
* `blank` is the new-project form and ignores the ids. `fill` selects the
|
|
101
|
+
* named projects; an id that matches nothing is simply absent from the form
|
|
102
|
+
* rather than an error, because a stale browser tab holding an id that was
|
|
103
|
+
* renamed in the ledger should still produce the projects it can.
|
|
104
|
+
*/
|
|
105
|
+
async exportForm(mode, pocIds) {
|
|
106
|
+
await this.prepare();
|
|
107
|
+
const stamp = now();
|
|
108
|
+
if (mode === 'blank') {
|
|
109
|
+
return {
|
|
110
|
+
html: buildFormHtml({ mode: 'blank', projects: [], now: stamp }),
|
|
111
|
+
fileName: formFileName({ mode: 'blank', pocIds: [], now: stamp }),
|
|
112
|
+
projectCount: 0,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const wanted = new Set(pocIds);
|
|
116
|
+
const records = (await loadOrEmpty()).filter((record) => wanted.has(text(record.poc_id)));
|
|
117
|
+
const projects = records.map(projectForForm);
|
|
118
|
+
return {
|
|
119
|
+
html: buildFormHtml({ mode: 'fill', projects, now: stamp }),
|
|
120
|
+
fileName: formFileName({ mode: 'fill', pocIds: records.map((record) => text(record.poc_id)), now: stamp }),
|
|
121
|
+
projectCount: projects.length,
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function apply(ctx, rawConfig = {}) {
|
|
127
|
+
const config = resolveConfig(rawConfig);
|
|
128
|
+
const connection = service(ctx, 'connection');
|
|
129
|
+
if (!connection?.fetch?.register)
|
|
130
|
+
throw new Error('work dashboard requires the current DSH Connection exact Fetch-route registry.');
|
|
131
|
+
const runtime = createRuntime(config);
|
|
132
|
+
// The three POC skills ship inside this package, so installing the dashboard
|
|
133
|
+
// is what publishes them and uninstalling is what removes them. Registration
|
|
134
|
+
// is optional-service and best-effort: a profile without a skill registry
|
|
135
|
+
// still gets the board (see src/skill.ts).
|
|
136
|
+
registerBundledSkills(ctx);
|
|
137
|
+
// The wipe runs once, on mount. It is not awaited here — a filesystem failure
|
|
138
|
+
// must not abort the Fiber — but it is logged once and then surfaces on the
|
|
139
|
+
// first request through the shared `prepared` promise.
|
|
140
|
+
runtime.prepare().catch((error) => {
|
|
141
|
+
ctx.logger?.error?.(`work-dashboard: cache preparation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
142
|
+
});
|
|
143
|
+
ctx.effect(() => () => {
|
|
144
|
+
// The cache is a plain directory that the next mount wipes anyway; the
|
|
145
|
+
// effect exists so the Fiber owns the runtime's lifetime explicitly.
|
|
146
|
+
void runtime;
|
|
147
|
+
}, 'skillre-work-dashboard cache lifetime');
|
|
148
|
+
ctx.effect(() => connection.fetch.register(createExecuteRoute(async () => runtime, {
|
|
149
|
+
onInternalError(error) {
|
|
150
|
+
const detail = error instanceof Error ? `${error.name}: ${error.message}\n${error.stack ?? ''}` : String(error);
|
|
151
|
+
ctx.logger?.error?.(`work-dashboard: request failed internally: ${detail}`);
|
|
152
|
+
// Also surface it on the Host stderr: a DSH deployment may not route
|
|
153
|
+
// `ctx.logger` to a place the operator looks at.
|
|
154
|
+
process.stderr.write(`[work-dashboard] internal error: ${detail}\n`);
|
|
155
|
+
},
|
|
156
|
+
})), 'skillre-work-dashboard client route');
|
|
157
|
+
}
|
|
158
|
+
/** Re-export the error type so tests and the transport share one identity. */
|
|
159
|
+
export { RepoError };
|
package/lib/repo.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local git cache of the POC ledger repository.
|
|
3
|
+
*
|
|
4
|
+
* Three invariants drive this module:
|
|
5
|
+
*
|
|
6
|
+
* 1. **The cache is disposable.** It is wiped at mount and rebuilt on demand,
|
|
7
|
+
* so the plugin can never corrupt the real data source: the repository on
|
|
8
|
+
* GitHub stays the only truth.
|
|
9
|
+
* 2. **The cache is only ever a fast-forward copy.** A refresh is
|
|
10
|
+
* `clone` (first time) or `fetch --depth 1` + `reset --hard origin/<branch>`.
|
|
11
|
+
* Never `pull`: a merge could block on a conflict in a directory nobody is
|
|
12
|
+
* meant to edit.
|
|
13
|
+
* 3. **A refresh is exclusive.** One lock file keeps two console instances in
|
|
14
|
+
* the same DSH home from cloning into the same directory at once.
|
|
15
|
+
*
|
|
16
|
+
* Authentication is deliberately never stored: the token is read from the
|
|
17
|
+
* already-authenticated `gh` CLI at call time and passed to git through an
|
|
18
|
+
* environment-scoped `http.extraheader`, so it never lands in `.git/config`,
|
|
19
|
+
* never appears in a process argument list, and never reaches the Client.
|
|
20
|
+
*/
|
|
21
|
+
/** Failure carrying a stable code the transport maps onto the RPC envelope. */
|
|
22
|
+
export declare class RepoError extends Error {
|
|
23
|
+
readonly code: string;
|
|
24
|
+
readonly details: Record<string, unknown>;
|
|
25
|
+
constructor(code: string, message: string, details?: Record<string, unknown>);
|
|
26
|
+
}
|
|
27
|
+
/** Largest single YAML file the store will read, in bytes. */
|
|
28
|
+
export declare const MAX_YAML_BYTES: number;
|
|
29
|
+
/** Resolved cache settings this module needs. */
|
|
30
|
+
export interface RepoOptions {
|
|
31
|
+
/** Absolute cache root; wiped at mount. */
|
|
32
|
+
cacheRoot: string;
|
|
33
|
+
/** `owner/name` on GitHub. */
|
|
34
|
+
repository: string;
|
|
35
|
+
/** Branch tracked by the clone. */
|
|
36
|
+
branch: string;
|
|
37
|
+
/** Clone URL; the canonical GitHub URL unless overridden. */
|
|
38
|
+
remoteUrl: string;
|
|
39
|
+
/** Ceiling for one clone, in milliseconds. */
|
|
40
|
+
cloneTimeoutMs: number;
|
|
41
|
+
/** Ceiling for one fetch + reset, in milliseconds. */
|
|
42
|
+
fetchTimeoutMs: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reject a cache root that is obviously not a disposable directory.
|
|
46
|
+
*
|
|
47
|
+
* The mount wipes this path, so a mistaken value (home, `/`, a parent of the
|
|
48
|
+
* DSH home) must fail at mount rather than delete real user data.
|
|
49
|
+
*/
|
|
50
|
+
export declare function assertSafeCacheRoot(cacheRoot: string, home: string): string;
|
|
51
|
+
/** Result of one successful refresh. */
|
|
52
|
+
export interface RefreshResult {
|
|
53
|
+
mode: 'clone' | 'fetch';
|
|
54
|
+
durationMs: number;
|
|
55
|
+
finishedAt: string;
|
|
56
|
+
/** Short HEAD sha the cache now points at. */
|
|
57
|
+
head: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The disposable git cache.
|
|
61
|
+
*
|
|
62
|
+
* Lifecycle: `prepare()` at mount wipes and recreates the cache root; the first
|
|
63
|
+
* `refresh()` clones, later ones fast-forward. Every method is safe to call
|
|
64
|
+
* concurrently except that refreshes serialize on a lock.
|
|
65
|
+
*/
|
|
66
|
+
export declare class RepoCache {
|
|
67
|
+
private readonly options;
|
|
68
|
+
/** Directory the ledger is read from once a clone exists. */
|
|
69
|
+
readonly repoPath: string;
|
|
70
|
+
private fetchedAt;
|
|
71
|
+
private head;
|
|
72
|
+
constructor(options: RepoOptions);
|
|
73
|
+
/**
|
|
74
|
+
* Wipe the cache and recreate it, so every DSH start begins from "no data".
|
|
75
|
+
*
|
|
76
|
+
* Only a directory this plugin created is ever removed: a pre-existing
|
|
77
|
+
* directory without the ownership marker fails loudly instead of being
|
|
78
|
+
* deleted, because a mistaken `cacheRoot` must not destroy user files.
|
|
79
|
+
*/
|
|
80
|
+
prepare(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Map a filesystem failure onto an authored, user-actionable code.
|
|
83
|
+
*
|
|
84
|
+
* The cache lives under `$DSH_HOME/cache`, which the Host process normally
|
|
85
|
+
* owns; a sandboxed or read-only deployment can deny it. Without this mapping
|
|
86
|
+
* the first request would surface as an opaque "internal error".
|
|
87
|
+
*/
|
|
88
|
+
private fsFailure;
|
|
89
|
+
private hasMarker;
|
|
90
|
+
/**
|
|
91
|
+
* An empty directory is safe to adopt: nothing can be lost by clearing it.
|
|
92
|
+
*
|
|
93
|
+
* This matters on the very first mount, when `mkdir -p` may have been run
|
|
94
|
+
* outside the plugin (a user pre-creating `~/.dsh/cache/work-dashboard`), and on
|
|
95
|
+
* a re-mount after a wipe that left the root empty.
|
|
96
|
+
*/
|
|
97
|
+
private isEmptyDirectory;
|
|
98
|
+
/** Whether a clone exists and its working tree is readable. */
|
|
99
|
+
isReady(): Promise<boolean>;
|
|
100
|
+
/** ISO timestamp of the last successful refresh in this process. */
|
|
101
|
+
get lastFetchedAt(): string | null;
|
|
102
|
+
/** The configured `owner/name` data source. */
|
|
103
|
+
get repository(): string;
|
|
104
|
+
/** The configured branch the cache tracks. */
|
|
105
|
+
get branch(): string;
|
|
106
|
+
/** Short HEAD sha after the last successful refresh, if known. */
|
|
107
|
+
get lastHead(): string | null;
|
|
108
|
+
/** Read the `gh` token at call time; absent when `gh` is not authenticated. */
|
|
109
|
+
private ghToken;
|
|
110
|
+
/**
|
|
111
|
+
* Clone or fast-forward the cache.
|
|
112
|
+
*
|
|
113
|
+
* Serialized by a lock file in the cache root: two browser tabs pressing
|
|
114
|
+
* refresh, or two DSH instances sharing a home, must not clone into the same
|
|
115
|
+
* directory concurrently.
|
|
116
|
+
*/
|
|
117
|
+
refresh(): Promise<RefreshResult>;
|
|
118
|
+
/** Take the cache lock, waiting briefly and reclaiming a stale one. */
|
|
119
|
+
private acquireLock;
|
|
120
|
+
/** Every `projects/*.yaml` file path in the cache, sorted by file name. */
|
|
121
|
+
projectFiles(): Promise<string[]>;
|
|
122
|
+
/** Read one project file, bounded so one huge file cannot stall the console. */
|
|
123
|
+
readProject(path: string): Promise<string>;
|
|
124
|
+
}
|