@skillre/dsh-plugin-work-dashboard 0.6.0 → 0.10.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 +12 -6
- package/README.md +32 -8
- package/compatibility.json +44 -4
- package/docs/DESIGN-1.0-/344/274/230/345/214/226/346/226/271/346/241/210.md +212 -0
- 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 +275 -0
- package/docs/LEDGER-REQUIREMENTS-v3.1.md +367 -0
- package/docs/PLAN-0.7-0.9.md +230 -0
- package/docs/PLAN-v3.1-adaptation.md +237 -0
- package/docs/TARGET-/345/217/260/350/264/246/344/273/223/345/272/223v3.1.md +500 -0
- 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 +233 -0
- package/lib/blockers.d.ts +45 -0
- package/lib/blockers.js +160 -0
- package/lib/client/api.d.ts +8 -1
- package/lib/client/api.js +1 -0
- package/lib/client/css/base.d.ts +1 -1
- package/lib/client/css/base.js +39 -0
- package/lib/client/css/blockers.d.ts +18 -0
- package/lib/client/css/blockers.js +196 -0
- package/lib/client/css/detail.d.ts +1 -1
- package/lib/client/css/detail.js +107 -4
- package/lib/client/css/overview.d.ts +5 -4
- package/lib/client/css/overview.js +23 -34
- 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/styles.js +3 -1
- package/lib/client/text.js +284 -44
- package/lib/client/view-contract.d.ts +9 -1
- package/lib/client.js +4836 -968
- package/lib/form.d.ts +278 -0
- package/lib/form.js +1153 -0
- package/lib/gap.d.ts +26 -8
- package/lib/gap.js +88 -17
- package/lib/index.js +29 -0
- package/lib/repo.d.ts +60 -0
- package/lib/repo.js +99 -0
- package/lib/rules.d.ts +105 -0
- package/lib/rules.js +227 -0
- package/lib/signals.d.ts +126 -0
- package/lib/signals.js +238 -0
- package/lib/store.d.ts +16 -1
- package/lib/store.js +92 -11
- package/lib/transport.d.ts +7 -1
- package/lib/transport.js +10 -0
- package/lib/types.d.ts +218 -15
- package/lib/types.js +21 -0
- package/package.json +1 -1
package/lib/rules.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules and thresholds the ledger declares, parsed into typed constants.
|
|
3
|
+
*
|
|
4
|
+
* Why this file exists at all: the ledger's `config/rules.yaml` says, in as many
|
|
5
|
+
* words, that "three copied rule lists drift; one does not". Those thresholds
|
|
6
|
+
* decide what counts as a finding, and they belong to the data source, not to
|
|
7
|
+
* this plugin. Hard-coding `300`, `2–3`, `3–5` and `45` here would make the plugin
|
|
8
|
+
* and the ledger disagree the first time either one is tuned — and the plugin
|
|
9
|
+
* would keep reporting findings the ledger no longer makes.
|
|
10
|
+
*
|
|
11
|
+
* Two versions are in play and they are NOT the same thing:
|
|
12
|
+
*
|
|
13
|
+
* - `schema_version` is the **shape** of the data (`schemas/enums.yaml`).
|
|
14
|
+
* - `rulesVersion` here is the **judgement** applied to that shape.
|
|
15
|
+
*
|
|
16
|
+
* A project can be schema-current while its findings are computed by older rules.
|
|
17
|
+
*
|
|
18
|
+
* When the file is missing — an older cache, or a cache that has not been
|
|
19
|
+
* refreshed since the ledger added `config/` — the built-in defaults below are
|
|
20
|
+
* used and {@link RulesBundle.source} says so. Falling back silently would let a
|
|
21
|
+
* stale cache look like a healthy one; the caller renders the difference.
|
|
22
|
+
*/
|
|
23
|
+
import YAML from 'yaml';
|
|
24
|
+
/**
|
|
25
|
+
* The rule ids this plugin implements, in schema order.
|
|
26
|
+
*
|
|
27
|
+
* Kept separate from the ledger's list on purpose: the ledger may add a rule the
|
|
28
|
+
* plugin does not yet render, and that must not crash the scan. Anything in
|
|
29
|
+
* `ledgerOrder` without an entry here is simply not evaluated.
|
|
30
|
+
*/
|
|
31
|
+
export const KNOWN_RULES = Object.freeze([
|
|
32
|
+
'R1-gate0-missing',
|
|
33
|
+
'R2-large-amount-no-g0',
|
|
34
|
+
'R3-g0-passed-no-plan',
|
|
35
|
+
'R4-criteria-count',
|
|
36
|
+
'R5-scenarios-count',
|
|
37
|
+
'R6-risks-overflow',
|
|
38
|
+
'R7-g2-not-ready',
|
|
39
|
+
'R8-progress-no-evidence',
|
|
40
|
+
'R9-evidence-no-recognition',
|
|
41
|
+
'R10-g3-1-without-g3-2',
|
|
42
|
+
'R11-no-next-milestone',
|
|
43
|
+
'R12-stage-stalled',
|
|
44
|
+
'R13-scenario-no-evidence',
|
|
45
|
+
'R14-scenario-awaiting-customer',
|
|
46
|
+
'R15-criteria-unverified',
|
|
47
|
+
'R16-scenario-not-started',
|
|
48
|
+
]);
|
|
49
|
+
/**
|
|
50
|
+
* The ledger's rule numbers mapped onto this plugin's rule ids.
|
|
51
|
+
*
|
|
52
|
+
* The ledger numbers rules `R1..R16`; the plugin needs a stable identifier per
|
|
53
|
+
* rule because the Client renders copy keyed on it. The mapping is the only place
|
|
54
|
+
* the ledger's numbering enters the code.
|
|
55
|
+
*/
|
|
56
|
+
const LEDGER_NUMBER_TO_RULE = {
|
|
57
|
+
R1: 'R1-gate0-missing',
|
|
58
|
+
R2: 'R2-large-amount-no-g0',
|
|
59
|
+
R3: 'R3-g0-passed-no-plan',
|
|
60
|
+
R4: 'R4-criteria-count',
|
|
61
|
+
R5: 'R5-scenarios-count',
|
|
62
|
+
R6: 'R6-risks-overflow',
|
|
63
|
+
R7: 'R7-g2-not-ready',
|
|
64
|
+
R8: 'R8-progress-no-evidence',
|
|
65
|
+
R9: 'R9-evidence-no-recognition',
|
|
66
|
+
R10: 'R10-g3-1-without-g3-2',
|
|
67
|
+
R11: 'R11-no-next-milestone',
|
|
68
|
+
R12: 'R12-stage-stalled',
|
|
69
|
+
R13: 'R13-scenario-no-evidence',
|
|
70
|
+
R14: 'R14-scenario-awaiting-customer',
|
|
71
|
+
R15: 'R15-criteria-unverified',
|
|
72
|
+
R16: 'R16-scenario-not-started',
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The built-in copy of `rules.yaml`, used when the cache has no `config/`.
|
|
76
|
+
*
|
|
77
|
+
* These are the values shipped with schema 3.1 / rules 3.2. They are a **fallback,
|
|
78
|
+
* not the source of truth**: when the ledger's file is present it always wins.
|
|
79
|
+
*/
|
|
80
|
+
export const FALLBACK_THRESHOLDS = Object.freeze({
|
|
81
|
+
largeAmountWan: 300,
|
|
82
|
+
criteria: { min: 2, max: 3 },
|
|
83
|
+
scenarios: { min: 3, max: 5 },
|
|
84
|
+
risks: { max: 3 },
|
|
85
|
+
stallDays: 45,
|
|
86
|
+
});
|
|
87
|
+
export const FALLBACK_PRIORITY = Object.freeze({
|
|
88
|
+
strategicWan: 1000,
|
|
89
|
+
highWan: 300,
|
|
90
|
+
strategicPocTypes: ['大体量项目'],
|
|
91
|
+
});
|
|
92
|
+
/** Fallback metadata, matching `rules.yaml` rules 1–16. */
|
|
93
|
+
export const FALLBACK_RULE_META = Object.freeze({
|
|
94
|
+
R1: { id: 'R1', name: 'G0 五必填缺失', level: 'high', priority: 90, guard: null },
|
|
95
|
+
R2: { id: 'R2', name: '大金额未过 G0', level: 'high', priority: 94, guard: null },
|
|
96
|
+
R3: { id: 'R3', name: 'G0 通过无计划', level: 'high', priority: 92, guard: null },
|
|
97
|
+
R4: { id: 'R4', name: '成功标准不聚焦', level: 'medium', priority: 50, guard: null },
|
|
98
|
+
R5: { id: 'R5', name: '场景不聚焦', level: 'medium', priority: 48, guard: null },
|
|
99
|
+
R6: { id: 'R6', name: '风险超限', level: 'medium', priority: 46, guard: null },
|
|
100
|
+
R7: { id: 'R7', name: 'G2 未就绪已开测', level: 'high', priority: 84, guard: null },
|
|
101
|
+
R8: { id: 'R8', name: '进展无证据', level: 'high', priority: 82, guard: null },
|
|
102
|
+
R9: { id: 'R9', name: '有证据无认可', level: 'high', priority: 80, guard: null },
|
|
103
|
+
R10: { id: 'R10', name: 'G3-1 无 G3-2', level: 'high', priority: 78, guard: null },
|
|
104
|
+
R11: { id: 'R11', name: '达成无下一步', level: 'high', priority: 96, guard: null },
|
|
105
|
+
R12: { id: 'R12', name: '阶段停滞', level: 'medium', priority: 40, guard: null },
|
|
106
|
+
R13: { id: 'R13', name: '场景无证据', level: 'high', priority: 88, guard: 'requires-progress' },
|
|
107
|
+
R14: { id: 'R14', name: '场景待客户确认', level: 'info', priority: 30, guard: null },
|
|
108
|
+
R15: { id: 'R15', name: '指标未验证', level: 'medium', priority: 44, guard: 'criteria-count-in-range' },
|
|
109
|
+
R16: { id: 'R16', name: '场景未开始', level: 'medium', priority: 42, guard: 'scenarios-count-in-range-and-progress' },
|
|
110
|
+
});
|
|
111
|
+
/** The bundle used when no ledger file is readable. */
|
|
112
|
+
export function fallbackRules(warnings = []) {
|
|
113
|
+
return {
|
|
114
|
+
source: 'fallback',
|
|
115
|
+
rulesVersion: '',
|
|
116
|
+
thresholds: FALLBACK_THRESHOLDS,
|
|
117
|
+
priority: FALLBACK_PRIORITY,
|
|
118
|
+
rules: { ...FALLBACK_RULE_META },
|
|
119
|
+
warnings,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function asNumber(value, fallback) {
|
|
123
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
124
|
+
return value;
|
|
125
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
126
|
+
const parsed = Number(value);
|
|
127
|
+
if (Number.isFinite(parsed))
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
return fallback;
|
|
131
|
+
}
|
|
132
|
+
function asRange(value, fallback) {
|
|
133
|
+
if (typeof value !== 'object' || value === null)
|
|
134
|
+
return fallback;
|
|
135
|
+
const record = value;
|
|
136
|
+
const min = asNumber(record.min, fallback.min);
|
|
137
|
+
const max = asNumber(record.max, fallback.max);
|
|
138
|
+
// A crossed range would make every project fail R4/R5 forever. Refusing it is
|
|
139
|
+
// safer than shipping a rule that can never be satisfied.
|
|
140
|
+
if (min > max)
|
|
141
|
+
return fallback;
|
|
142
|
+
return { min, max };
|
|
143
|
+
}
|
|
144
|
+
function asStringArray(value, fallback) {
|
|
145
|
+
if (!Array.isArray(value))
|
|
146
|
+
return fallback;
|
|
147
|
+
const items = value.map((item) => (typeof item === 'string' ? item.trim() : '')).filter((item) => item !== '');
|
|
148
|
+
return items.length === 0 ? fallback : items;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Parse `config/rules.yaml` into a {@link RulesBundle}.
|
|
152
|
+
*
|
|
153
|
+
* Returns the fallback bundle when the source is empty or unparsable, and records
|
|
154
|
+
* why in `warnings` — an unreadable rules file is a degraded cache, not a reason
|
|
155
|
+
* to refuse to scan.
|
|
156
|
+
*/
|
|
157
|
+
export function parseRules(source) {
|
|
158
|
+
if (typeof source !== 'string' || source.trim() === '') {
|
|
159
|
+
return fallbackRules(['config/rules.yaml 不可读,阈值回落到内置默认值']);
|
|
160
|
+
}
|
|
161
|
+
let document;
|
|
162
|
+
try {
|
|
163
|
+
document = YAML.parse(source);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
const detail = error instanceof Error ? error.message.split('\n')[0] : 'invalid YAML';
|
|
167
|
+
return fallbackRules([`config/rules.yaml 解析失败(${detail}),阈值回落到内置默认值`]);
|
|
168
|
+
}
|
|
169
|
+
if (typeof document !== 'object' || document === null) {
|
|
170
|
+
return fallbackRules(['config/rules.yaml 不是 YAML 映射,阈值回落到内置默认值']);
|
|
171
|
+
}
|
|
172
|
+
const root = document;
|
|
173
|
+
const thresholdsRaw = (root.thresholds ?? {});
|
|
174
|
+
const priorityRaw = (root.priority ?? {});
|
|
175
|
+
const thresholds = {
|
|
176
|
+
largeAmountWan: asNumber(thresholdsRaw.large_amount_wan, FALLBACK_THRESHOLDS.largeAmountWan),
|
|
177
|
+
criteria: asRange(thresholdsRaw.criteria, FALLBACK_THRESHOLDS.criteria),
|
|
178
|
+
scenarios: asRange(thresholdsRaw.scenarios, FALLBACK_THRESHOLDS.scenarios),
|
|
179
|
+
risks: { max: asNumber(thresholdsRaw.risks?.max, FALLBACK_THRESHOLDS.risks.max) },
|
|
180
|
+
stallDays: asNumber(thresholdsRaw.stall_days, FALLBACK_THRESHOLDS.stallDays),
|
|
181
|
+
};
|
|
182
|
+
const priority = {
|
|
183
|
+
strategicWan: asNumber(priorityRaw.strategic_wan, FALLBACK_PRIORITY.strategicWan),
|
|
184
|
+
highWan: asNumber(priorityRaw.high_wan, FALLBACK_PRIORITY.highWan),
|
|
185
|
+
strategicPocTypes: asStringArray(priorityRaw.strategic_poc_types, FALLBACK_PRIORITY.strategicPocTypes),
|
|
186
|
+
};
|
|
187
|
+
const rules = { ...FALLBACK_RULE_META };
|
|
188
|
+
const warnings = [];
|
|
189
|
+
if (Array.isArray(root.rules)) {
|
|
190
|
+
for (const entry of root.rules) {
|
|
191
|
+
if (typeof entry !== 'object' || entry === null)
|
|
192
|
+
continue;
|
|
193
|
+
const record = entry;
|
|
194
|
+
const id = typeof record.id === 'string' ? record.id.trim() : '';
|
|
195
|
+
if (id === '')
|
|
196
|
+
continue;
|
|
197
|
+
const fallback = FALLBACK_RULE_META[id];
|
|
198
|
+
const level = record.level;
|
|
199
|
+
rules[id] = {
|
|
200
|
+
id,
|
|
201
|
+
name: typeof record.name === 'string' && record.name.trim() !== '' ? record.name.trim() : (fallback?.name ?? id),
|
|
202
|
+
level: level === 'high' || level === 'medium' || level === 'info' ? level : (fallback?.level ?? 'medium'),
|
|
203
|
+
priority: asNumber(record.priority, fallback?.priority ?? 50),
|
|
204
|
+
guard: typeof record.guard === 'string' && record.guard.trim() !== '' ? record.guard.trim() : null,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
warnings.push('config/rules.yaml 缺少 rules 列表,规则元数据回落到内置默认值');
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
source: 'ledger',
|
|
213
|
+
rulesVersion: typeof root.version === 'string' ? root.version.trim() : '',
|
|
214
|
+
thresholds,
|
|
215
|
+
priority,
|
|
216
|
+
rules,
|
|
217
|
+
warnings,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/** The plugin's rule id for a ledger rule number (`R13` → `R13-scenario-no-evidence`). */
|
|
221
|
+
export function ruleForLedgerId(ledgerId) {
|
|
222
|
+
return LEDGER_NUMBER_TO_RULE[ledgerId] ?? null;
|
|
223
|
+
}
|
|
224
|
+
/** Every rule id the ledger declares in `rules.yaml`, in file order. */
|
|
225
|
+
export function ledgerRuleIds(bundle) {
|
|
226
|
+
return Object.keys(bundle.rules);
|
|
227
|
+
}
|
package/lib/signals.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent's conclusions (`signals/<poc_id>.yaml`) and the staleness limits
|
|
3
|
+
* (`config/health.yaml`).
|
|
4
|
+
*
|
|
5
|
+
* ## Why this is a separate module from `rules.ts`
|
|
6
|
+
*
|
|
7
|
+
* The ledger draws a hard line between two kinds of machine output:
|
|
8
|
+
*
|
|
9
|
+
* - `projects/*.yaml` derived fields (`scenarios[].status`, …) are
|
|
10
|
+
* **deterministic calculations** over one record, written by `tools/derive.mjs`.
|
|
11
|
+
* CI rejects a stored value that disagrees with the script.
|
|
12
|
+
* - `signals/*.yaml` are **judgements that need cross-record reasoning** ("can this
|
|
13
|
+
* upgrade?", "who should be chased?"). They are written only by the agent
|
|
14
|
+
* account, never by hand, and they are an opinion rather than a fact.
|
|
15
|
+
*
|
|
16
|
+
* Keeping them apart is the whole point of the directory: if the two were mixed,
|
|
17
|
+
* a human edit could overwrite a machine conclusion and nobody could tell who
|
|
18
|
+
* said what.
|
|
19
|
+
*
|
|
20
|
+
* ## The contract this module honours
|
|
21
|
+
*
|
|
22
|
+
* The ledger's `signals/README.md` states one rule for consumers: **degrade
|
|
23
|
+
* gracefully on missing fields.** A signal is optional, its schema may evolve,
|
|
24
|
+
* and most projects have none at all. So every field here is optional and every
|
|
25
|
+
* parse failure becomes a warning — a bad signal must never blank out the page
|
|
26
|
+
* that displays the human facts.
|
|
27
|
+
*/
|
|
28
|
+
/** What the agent concluded about a possible gate promotion. */
|
|
29
|
+
export interface GateUpgradeSignal {
|
|
30
|
+
eligible: boolean;
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
33
|
+
missing: string[];
|
|
34
|
+
basis: string[];
|
|
35
|
+
note: string;
|
|
36
|
+
}
|
|
37
|
+
/** The agent's health read for one project. */
|
|
38
|
+
export interface HealthSignal {
|
|
39
|
+
/** `ok` | `warn` | `bad`; empty when the agent did not judge. */
|
|
40
|
+
level: string;
|
|
41
|
+
/** Days since the newest progress round; `null` when there is no progress. */
|
|
42
|
+
factsStaleDays: number | null;
|
|
43
|
+
/** Days since anybody looked at the plan or the G0 review. */
|
|
44
|
+
judgmentStaleDays: number | null;
|
|
45
|
+
reasons: string[];
|
|
46
|
+
nextAction: {
|
|
47
|
+
text: string;
|
|
48
|
+
owner: string;
|
|
49
|
+
due: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A signal risk's severity.
|
|
54
|
+
*
|
|
55
|
+
* Deliberately NOT `GapLevel`: a gap is a rule violation that the ledger defines,
|
|
56
|
+
* while a signal risk is the agent's opinion. They share the word "level" and
|
|
57
|
+
* nothing else — `info` would be meaningless here, and `low` would be meaningless
|
|
58
|
+
* there. Reusing one type would force a cast and hide exactly the mismatch this
|
|
59
|
+
* distinction exists to keep visible.
|
|
60
|
+
*/
|
|
61
|
+
export type SignalRiskLevel = 'high' | 'medium' | 'low';
|
|
62
|
+
/** One risk the agent raised, distinct from the human `plan.risks[]`. */
|
|
63
|
+
export interface SignalRisk {
|
|
64
|
+
id: string;
|
|
65
|
+
level: SignalRiskLevel;
|
|
66
|
+
text: string;
|
|
67
|
+
source: string;
|
|
68
|
+
}
|
|
69
|
+
/** One project's machine judgement. */
|
|
70
|
+
export interface ProjectSignal {
|
|
71
|
+
pocId: string;
|
|
72
|
+
schemaVersion: string;
|
|
73
|
+
generatedAt: string;
|
|
74
|
+
generatedBy: string;
|
|
75
|
+
rulesVersion: string;
|
|
76
|
+
/** The `projects/` blob sha the judgement was computed from. */
|
|
77
|
+
projectSha: string;
|
|
78
|
+
gateUpgrade: GateUpgradeSignal | null;
|
|
79
|
+
health: HealthSignal | null;
|
|
80
|
+
risks: SignalRisk[];
|
|
81
|
+
}
|
|
82
|
+
/** Every signal in the cache, plus the problems met while reading them. */
|
|
83
|
+
export interface SignalBundle {
|
|
84
|
+
/** Whether the cache carries a `signals/` directory at all. */
|
|
85
|
+
present: boolean;
|
|
86
|
+
byPocId: Map<string, ProjectSignal>;
|
|
87
|
+
warnings: string[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Parse one `signals/<poc_id>.yaml`.
|
|
91
|
+
*
|
|
92
|
+
* Returns `null` for a document that is not a mapping, so the caller records a
|
|
93
|
+
* warning. Missing inner fields are normal and produce empty values.
|
|
94
|
+
*/
|
|
95
|
+
export declare function parseSignal(pocId: string, source: string): ProjectSignal | null;
|
|
96
|
+
/**
|
|
97
|
+
* Parse the whole `signals/` directory.
|
|
98
|
+
*
|
|
99
|
+
* One unreadable signal is skipped with a warning, never escalated: the ledger's
|
|
100
|
+
* consumer contract is explicit that a signal directory may be absent or partial.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseSignals(files: Map<string, string>): SignalBundle;
|
|
103
|
+
/** The bundle used when the cache has no `signals/` directory. */
|
|
104
|
+
export declare function emptySignals(): SignalBundle;
|
|
105
|
+
/** The two independent staleness notions the ledger defines. */
|
|
106
|
+
export interface HealthThresholds {
|
|
107
|
+
stallDays: number;
|
|
108
|
+
/** Facts go stale when nothing has happened. */
|
|
109
|
+
progressStaleDays: number;
|
|
110
|
+
changeStaleDays: number;
|
|
111
|
+
/** Judgment goes stale when nobody has looked. */
|
|
112
|
+
g0ReviewStaleDays: number;
|
|
113
|
+
planStaleDays: number;
|
|
114
|
+
/** Which checks apply at each stage, as declared. */
|
|
115
|
+
byStage: Record<string, string[]>;
|
|
116
|
+
source: 'ledger' | 'fallback';
|
|
117
|
+
warnings: string[];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Built-in copy of `config/health.yaml` at rules 3.2.
|
|
121
|
+
*
|
|
122
|
+
* A fallback, not the source of truth: when the file is readable it always wins.
|
|
123
|
+
*/
|
|
124
|
+
export declare const FALLBACK_HEALTH: Omit<HealthThresholds, 'source' | 'warnings'>;
|
|
125
|
+
/** Parse `config/health.yaml`, falling back to the built-in limits. */
|
|
126
|
+
export declare function parseHealthConfig(source: string | null | undefined): HealthThresholds;
|
package/lib/signals.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent's conclusions (`signals/<poc_id>.yaml`) and the staleness limits
|
|
3
|
+
* (`config/health.yaml`).
|
|
4
|
+
*
|
|
5
|
+
* ## Why this is a separate module from `rules.ts`
|
|
6
|
+
*
|
|
7
|
+
* The ledger draws a hard line between two kinds of machine output:
|
|
8
|
+
*
|
|
9
|
+
* - `projects/*.yaml` derived fields (`scenarios[].status`, …) are
|
|
10
|
+
* **deterministic calculations** over one record, written by `tools/derive.mjs`.
|
|
11
|
+
* CI rejects a stored value that disagrees with the script.
|
|
12
|
+
* - `signals/*.yaml` are **judgements that need cross-record reasoning** ("can this
|
|
13
|
+
* upgrade?", "who should be chased?"). They are written only by the agent
|
|
14
|
+
* account, never by hand, and they are an opinion rather than a fact.
|
|
15
|
+
*
|
|
16
|
+
* Keeping them apart is the whole point of the directory: if the two were mixed,
|
|
17
|
+
* a human edit could overwrite a machine conclusion and nobody could tell who
|
|
18
|
+
* said what.
|
|
19
|
+
*
|
|
20
|
+
* ## The contract this module honours
|
|
21
|
+
*
|
|
22
|
+
* The ledger's `signals/README.md` states one rule for consumers: **degrade
|
|
23
|
+
* gracefully on missing fields.** A signal is optional, its schema may evolve,
|
|
24
|
+
* and most projects have none at all. So every field here is optional and every
|
|
25
|
+
* parse failure becomes a warning — a bad signal must never blank out the page
|
|
26
|
+
* that displays the human facts.
|
|
27
|
+
*/
|
|
28
|
+
import YAML from 'yaml';
|
|
29
|
+
function text(value) {
|
|
30
|
+
if (value === null || value === undefined)
|
|
31
|
+
return '';
|
|
32
|
+
if (typeof value === 'string')
|
|
33
|
+
return value.trim();
|
|
34
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
35
|
+
return String(value);
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
function numberOrNull(value) {
|
|
39
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
40
|
+
return value;
|
|
41
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
42
|
+
const parsed = Number(value);
|
|
43
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function stringList(value) {
|
|
48
|
+
if (!Array.isArray(value))
|
|
49
|
+
return [];
|
|
50
|
+
return value.map(text).filter((item) => item !== '');
|
|
51
|
+
}
|
|
52
|
+
function asRecord(value) {
|
|
53
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
54
|
+
? value
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
/** A risk level the ledger can express, collapsed onto this plugin's three. */
|
|
58
|
+
function riskLevel(value) {
|
|
59
|
+
const raw = text(value).toLowerCase();
|
|
60
|
+
if (raw === 'high')
|
|
61
|
+
return 'high';
|
|
62
|
+
if (raw === 'low')
|
|
63
|
+
return 'low';
|
|
64
|
+
if (raw === 'medium' || raw === 'mid')
|
|
65
|
+
return 'medium';
|
|
66
|
+
// An unknown level must not silently become `high`: that would promote a
|
|
67
|
+
// machine opinion to the top of the board. `medium` keeps it visible without
|
|
68
|
+
// letting a typo shout.
|
|
69
|
+
return 'medium';
|
|
70
|
+
}
|
|
71
|
+
function parseGateUpgrade(value) {
|
|
72
|
+
const record = asRecord(value);
|
|
73
|
+
if (record === null)
|
|
74
|
+
return null;
|
|
75
|
+
return {
|
|
76
|
+
eligible: record.eligible === true,
|
|
77
|
+
from: text(record.from),
|
|
78
|
+
to: text(record.to),
|
|
79
|
+
missing: stringList(record.missing),
|
|
80
|
+
basis: stringList(record.basis),
|
|
81
|
+
note: text(record.note),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function parseHealth(value) {
|
|
85
|
+
const record = asRecord(value);
|
|
86
|
+
if (record === null)
|
|
87
|
+
return null;
|
|
88
|
+
const action = asRecord(record.next_action);
|
|
89
|
+
return {
|
|
90
|
+
level: text(record.level),
|
|
91
|
+
factsStaleDays: numberOrNull(record.facts_stale_days),
|
|
92
|
+
judgmentStaleDays: numberOrNull(record.judgment_stale_days),
|
|
93
|
+
reasons: stringList(record.reasons),
|
|
94
|
+
nextAction: {
|
|
95
|
+
text: text(action?.text),
|
|
96
|
+
owner: text(action?.owner),
|
|
97
|
+
due: text(action?.due),
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function parseRisks(value) {
|
|
102
|
+
if (!Array.isArray(value))
|
|
103
|
+
return [];
|
|
104
|
+
const risks = [];
|
|
105
|
+
value.forEach((entry, index) => {
|
|
106
|
+
const record = asRecord(entry);
|
|
107
|
+
if (record === null)
|
|
108
|
+
return;
|
|
109
|
+
const body = text(record.text);
|
|
110
|
+
// A risk with no text says nothing; keeping it would render an empty row.
|
|
111
|
+
if (body === '')
|
|
112
|
+
return;
|
|
113
|
+
risks.push({
|
|
114
|
+
id: text(record.id) || `signal-risk-${index + 1}`,
|
|
115
|
+
level: riskLevel(record.level),
|
|
116
|
+
text: body,
|
|
117
|
+
source: text(record.source),
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
return risks;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse one `signals/<poc_id>.yaml`.
|
|
124
|
+
*
|
|
125
|
+
* Returns `null` for a document that is not a mapping, so the caller records a
|
|
126
|
+
* warning. Missing inner fields are normal and produce empty values.
|
|
127
|
+
*/
|
|
128
|
+
export function parseSignal(pocId, source) {
|
|
129
|
+
let document;
|
|
130
|
+
try {
|
|
131
|
+
document = YAML.parse(source);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const record = asRecord(document);
|
|
137
|
+
if (record === null)
|
|
138
|
+
return null;
|
|
139
|
+
return {
|
|
140
|
+
pocId: text(record.poc_id) || pocId,
|
|
141
|
+
schemaVersion: text(record.schema_version),
|
|
142
|
+
generatedAt: text(record.generated_at),
|
|
143
|
+
generatedBy: text(record.generated_by),
|
|
144
|
+
rulesVersion: text(record.rules_version),
|
|
145
|
+
projectSha: text(asRecord(record.inputs)?.project_sha),
|
|
146
|
+
gateUpgrade: parseGateUpgrade(record.gate_upgrade),
|
|
147
|
+
health: parseHealth(record.health),
|
|
148
|
+
risks: parseRisks(record.risks),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Parse the whole `signals/` directory.
|
|
153
|
+
*
|
|
154
|
+
* One unreadable signal is skipped with a warning, never escalated: the ledger's
|
|
155
|
+
* consumer contract is explicit that a signal directory may be absent or partial.
|
|
156
|
+
*/
|
|
157
|
+
export function parseSignals(files) {
|
|
158
|
+
const byPocId = new Map();
|
|
159
|
+
const warnings = [];
|
|
160
|
+
for (const [filePocId, source] of files) {
|
|
161
|
+
const parsed = parseSignal(filePocId, source);
|
|
162
|
+
if (parsed === null) {
|
|
163
|
+
warnings.push(`signals/${filePocId}.yaml: 不是可解析的 YAML 映射,已跳过`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
byPocId.set(parsed.pocId, parsed);
|
|
167
|
+
}
|
|
168
|
+
return { present: files.size > 0, byPocId, warnings };
|
|
169
|
+
}
|
|
170
|
+
/** The bundle used when the cache has no `signals/` directory. */
|
|
171
|
+
export function emptySignals() {
|
|
172
|
+
return { present: false, byPocId: new Map(), warnings: [] };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Built-in copy of `config/health.yaml` at rules 3.2.
|
|
176
|
+
*
|
|
177
|
+
* A fallback, not the source of truth: when the file is readable it always wins.
|
|
178
|
+
*/
|
|
179
|
+
export const FALLBACK_HEALTH = Object.freeze({
|
|
180
|
+
stallDays: 45,
|
|
181
|
+
progressStaleDays: 7,
|
|
182
|
+
changeStaleDays: 14,
|
|
183
|
+
g0ReviewStaleDays: 30,
|
|
184
|
+
planStaleDays: 30,
|
|
185
|
+
byStage: {
|
|
186
|
+
G0: ['change_stale_days', 'g0_review_stale_days'],
|
|
187
|
+
G1: ['change_stale_days', 'plan_stale_days'],
|
|
188
|
+
G2: ['change_stale_days', 'progress_stale_days'],
|
|
189
|
+
G3: ['change_stale_days', 'progress_stale_days'],
|
|
190
|
+
G4: ['change_stale_days', 'progress_stale_days'],
|
|
191
|
+
closed: ['change_stale_days'],
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
function asNumber(value, fallback) {
|
|
195
|
+
const parsed = numberOrNull(value);
|
|
196
|
+
return parsed === null ? fallback : parsed;
|
|
197
|
+
}
|
|
198
|
+
/** Parse `config/health.yaml`, falling back to the built-in limits. */
|
|
199
|
+
export function parseHealthConfig(source) {
|
|
200
|
+
const fallback = (warnings) => ({
|
|
201
|
+
...FALLBACK_HEALTH,
|
|
202
|
+
source: 'fallback',
|
|
203
|
+
warnings,
|
|
204
|
+
});
|
|
205
|
+
if (typeof source !== 'string' || source.trim() === '') {
|
|
206
|
+
return fallback(['config/health.yaml 不可读,陈旧度阈值回落到内置默认值']);
|
|
207
|
+
}
|
|
208
|
+
let document;
|
|
209
|
+
try {
|
|
210
|
+
document = YAML.parse(source);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const detail = error instanceof Error ? error.message.split('\n')[0] : 'invalid YAML';
|
|
214
|
+
return fallback([`config/health.yaml 解析失败(${detail}),陈旧度阈值回落到内置默认值`]);
|
|
215
|
+
}
|
|
216
|
+
const root = asRecord(document);
|
|
217
|
+
if (root === null)
|
|
218
|
+
return fallback(['config/health.yaml 不是 YAML 映射,陈旧度阈值回落到内置默认值']);
|
|
219
|
+
const facts = asRecord(root.facts) ?? {};
|
|
220
|
+
const judgment = asRecord(root.judgment) ?? {};
|
|
221
|
+
const byStageRaw = asRecord(root.by_stage) ?? {};
|
|
222
|
+
const byStage = { ...FALLBACK_HEALTH.byStage };
|
|
223
|
+
for (const [stage, checks] of Object.entries(byStageRaw)) {
|
|
224
|
+
const list = stringList(checks);
|
|
225
|
+
if (list.length > 0)
|
|
226
|
+
byStage[stage] = list;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
stallDays: asNumber(root.stall_days, FALLBACK_HEALTH.stallDays),
|
|
230
|
+
progressStaleDays: asNumber(facts.progress_stale_days, FALLBACK_HEALTH.progressStaleDays),
|
|
231
|
+
changeStaleDays: asNumber(facts.change_stale_days, FALLBACK_HEALTH.changeStaleDays),
|
|
232
|
+
g0ReviewStaleDays: asNumber(judgment.g0_review_stale_days, FALLBACK_HEALTH.g0ReviewStaleDays),
|
|
233
|
+
planStaleDays: asNumber(judgment.plan_stale_days, FALLBACK_HEALTH.planStaleDays),
|
|
234
|
+
byStage,
|
|
235
|
+
source: 'ledger',
|
|
236
|
+
warnings: [],
|
|
237
|
+
};
|
|
238
|
+
}
|
package/lib/store.d.ts
CHANGED
|
@@ -14,12 +14,19 @@
|
|
|
14
14
|
* as a warning and skipped: a single bad hand-edit must not blank the whole
|
|
15
15
|
* board.
|
|
16
16
|
*/
|
|
17
|
+
import type { RulesBundle } from './rules.js';
|
|
17
18
|
import type { RepoCache } from './repo.js';
|
|
18
19
|
import type { GapItem, OrgRecord, PocRecord, PortfolioAnalysis, ProjectDetail, ProjectSummary, Snapshot, StageId } from './types.js';
|
|
19
20
|
/** Injected clock so the store stays testable and the rules stay pure. */
|
|
20
21
|
export interface StoreOptions {
|
|
21
22
|
now: () => Date;
|
|
22
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Days in one stage after which rule 12 fires.
|
|
25
|
+
*
|
|
26
|
+
* Retained as an explicit override for tests and for the plugin config; when a
|
|
27
|
+
* rules bundle is available its `stallDays` wins, because the ledger owns the
|
|
28
|
+
* threshold and the plugin must not disagree with CI.
|
|
29
|
+
*/
|
|
23
30
|
stallDays: number;
|
|
24
31
|
}
|
|
25
32
|
/** The Host-side view model builder. */
|
|
@@ -32,6 +39,14 @@ export declare class PocStore {
|
|
|
32
39
|
records: PocRecord[];
|
|
33
40
|
warnings: string[];
|
|
34
41
|
}>;
|
|
42
|
+
/**
|
|
43
|
+
* The rules in force, read from the ledger's `config/rules.yaml`.
|
|
44
|
+
*
|
|
45
|
+
* A missing file is reported through `RulesBundle.source === 'fallback'`, not
|
|
46
|
+
* thrown: an older cache must still render, it just must not pretend its
|
|
47
|
+
* thresholds are the ledger's.
|
|
48
|
+
*/
|
|
49
|
+
rules(): Promise<RulesBundle>;
|
|
35
50
|
/** The overview snapshot; never throws for a missing cache, it reports it. */
|
|
36
51
|
snapshot(): Promise<Snapshot>;
|
|
37
52
|
/** One project's full record; `null` when no file declares that id. */
|