@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/gap.d.ts
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The sixteen v3.1 gap rules, as pure functions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Every rule is a total function of `(record, options)` — no clock, no
|
|
5
|
+
* filesystem, no locale — so `tests/gap.spec.ts` can pin each one to a fixture.
|
|
6
|
+
*
|
|
7
|
+
* Thresholds are NOT hard-coded here. They arrive through
|
|
8
|
+
* {@link ScanOptions.rules}, parsed from the ledger's `config/rules.yaml`, because
|
|
9
|
+
* the ledger treats that file as the single source ("three copied rule lists
|
|
10
|
+
* drift; one does not"). A caller that omits `rules` gets the built-in fallback,
|
|
11
|
+
* which is the same set of numbers but is labelled as a fallback in the UI.
|
|
9
12
|
*
|
|
10
13
|
* The v3 model is **progress-centred**: a project is judged by its latest
|
|
11
14
|
* progress entry, not by a separately-maintained `result` block. Rules 8–10
|
|
12
|
-
* therefore read
|
|
13
|
-
*
|
|
15
|
+
* therefore read the newest entry, and rule 7 compares "has any progress"
|
|
16
|
+
* against the G2 readiness flag.
|
|
17
|
+
*
|
|
18
|
+
* Rules 13–16 are the v3.1 additions and read the ledger's **derived**
|
|
19
|
+
* per-scenario and per-criterion state (`scenarios[].status`,
|
|
20
|
+
* `criteria[].status`) rather than re-deriving it: the ledger's `derive.mjs` is
|
|
21
|
+
* the only writer of those fields, and a second implementation here would
|
|
22
|
+
* eventually disagree with CI.
|
|
14
23
|
*/
|
|
15
24
|
import type { GapItem, GapLevel, PocRecord, StageId } from './types.js';
|
|
25
|
+
import { type RulesBundle } from './rules.js';
|
|
16
26
|
/** Normalize the free-form `stage` string onto a stage id. */
|
|
17
27
|
export declare function normalizeStage(raw: unknown): {
|
|
18
28
|
stage: StageId | null;
|
|
@@ -30,6 +40,14 @@ export interface ScanOptions {
|
|
|
30
40
|
now: Date;
|
|
31
41
|
/** Days in one stage after which rule 12 fires. */
|
|
32
42
|
stallDays: number;
|
|
43
|
+
/**
|
|
44
|
+
* The thresholds and rule metadata in force.
|
|
45
|
+
*
|
|
46
|
+
* Omitted means "use the built-in fallback": the scan still runs, but the
|
|
47
|
+
* caller should surface that its findings came from fallback numbers, not from
|
|
48
|
+
* the ledger's `config/rules.yaml`.
|
|
49
|
+
*/
|
|
50
|
+
rules?: RulesBundle;
|
|
33
51
|
}
|
|
34
52
|
/** Rule metadata: number, severity and sort weight. */
|
|
35
53
|
export declare const RULE_META: Record<GapItem['rule'], {
|
package/lib/gap.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The sixteen v3.1 gap rules, as pure functions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Every rule is a total function of `(record, options)` — no clock, no
|
|
5
|
+
* filesystem, no locale — so `tests/gap.spec.ts` can pin each one to a fixture.
|
|
6
|
+
*
|
|
7
|
+
* Thresholds are NOT hard-coded here. They arrive through
|
|
8
|
+
* {@link ScanOptions.rules}, parsed from the ledger's `config/rules.yaml`, because
|
|
9
|
+
* the ledger treats that file as the single source ("three copied rule lists
|
|
10
|
+
* drift; one does not"). A caller that omits `rules` gets the built-in fallback,
|
|
11
|
+
* which is the same set of numbers but is labelled as a fallback in the UI.
|
|
9
12
|
*
|
|
10
13
|
* The v3 model is **progress-centred**: a project is judged by its latest
|
|
11
14
|
* progress entry, not by a separately-maintained `result` block. Rules 8–10
|
|
12
|
-
* therefore read
|
|
13
|
-
*
|
|
15
|
+
* therefore read the newest entry, and rule 7 compares "has any progress"
|
|
16
|
+
* against the G2 readiness flag.
|
|
17
|
+
*
|
|
18
|
+
* Rules 13–16 are the v3.1 additions and read the ledger's **derived**
|
|
19
|
+
* per-scenario and per-criterion state (`scenarios[].status`,
|
|
20
|
+
* `criteria[].status`) rather than re-deriving it: the ledger's `derive.mjs` is
|
|
21
|
+
* the only writer of those fields, and a second implementation here would
|
|
22
|
+
* eventually disagree with CI.
|
|
14
23
|
*/
|
|
24
|
+
import { FALLBACK_RULE_META, fallbackRules } from './rules.js';
|
|
15
25
|
/** Stage prefixes a raw `stage` value can normalize to, in order. */
|
|
16
26
|
const STAGE_PREFIXES = [
|
|
17
27
|
['G0', 'G0'],
|
|
@@ -82,7 +92,18 @@ export const RULE_META = {
|
|
|
82
92
|
'R11-no-next-milestone': { no: 11, level: 'high', priority: 96 },
|
|
83
93
|
// R12: the project has not moved.
|
|
84
94
|
'R12-stage-stalled': { no: 12, level: 'medium', priority: 40 },
|
|
95
|
+
// R13–R16: the plan is the right shape but the work has not moved. A scenario
|
|
96
|
+
// with no evidence behind it is the state-level twin of R8, per item instead
|
|
97
|
+
// of per entry.
|
|
98
|
+
'R13-scenario-no-evidence': { no: 13, level: 'high', priority: 88 },
|
|
99
|
+
'R14-scenario-awaiting-customer': { no: 14, level: 'info', priority: 30 },
|
|
100
|
+
'R15-criteria-unverified': { no: 15, level: 'medium', priority: 44 },
|
|
101
|
+
'R16-scenario-not-started': { no: 16, level: 'medium', priority: 42 },
|
|
85
102
|
};
|
|
103
|
+
/** The thresholds in force, from the ledger bundle or the built-in fallback. */
|
|
104
|
+
function thresholdsOf(options) {
|
|
105
|
+
return (options.rules ?? fallbackRules()).thresholds;
|
|
106
|
+
}
|
|
86
107
|
/** Build one finding, stamping the rule metadata from {@link RULE_META}. */
|
|
87
108
|
function gap(poc, rule, extra = {}) {
|
|
88
109
|
const meta = RULE_META[rule];
|
|
@@ -151,6 +172,7 @@ export function daysSince(date, now) {
|
|
|
151
172
|
*/
|
|
152
173
|
export function scanGaps(poc, options) {
|
|
153
174
|
const gaps = [];
|
|
175
|
+
const thresholds = thresholdsOf(options);
|
|
154
176
|
const gate0 = poc.gate0 ?? {};
|
|
155
177
|
const plan = poc.plan ?? {};
|
|
156
178
|
const outcome = poc.outcome ?? {};
|
|
@@ -165,7 +187,7 @@ export function scanGaps(poc, options) {
|
|
|
165
187
|
}
|
|
166
188
|
// R2 — a large commitment whose G0 was never cleared.
|
|
167
189
|
const conclusion = text(gate0.review?.conclusion);
|
|
168
|
-
if (amountWan >=
|
|
190
|
+
if (amountWan >= thresholds.largeAmountWan && conclusion !== '通过') {
|
|
169
191
|
gaps.push(gap(poc, 'R2-large-amount-no-g0', { field: 'gate0.review.conclusion', params: { amountWan, conclusion: conclusion === '' ? '未评审' : conclusion } }));
|
|
170
192
|
}
|
|
171
193
|
// R3 — cleared the gate but never defined success.
|
|
@@ -175,16 +197,16 @@ export function scanGaps(poc, options) {
|
|
|
175
197
|
// R4–R6 — focus limits. Only fires when the list is non-empty, so a project
|
|
176
198
|
// that has not planned yet is not punished twice (R3 covers that case).
|
|
177
199
|
const criteria = (plan.criteria ?? []).length;
|
|
178
|
-
if (criteria > 0 && (criteria <
|
|
179
|
-
gaps.push(gap(poc, 'R4-criteria-count', { field: 'plan.criteria', params: { count: criteria, min:
|
|
200
|
+
if (criteria > 0 && (criteria < thresholds.criteria.min || criteria > thresholds.criteria.max)) {
|
|
201
|
+
gaps.push(gap(poc, 'R4-criteria-count', { field: 'plan.criteria', params: { count: criteria, min: thresholds.criteria.min, max: thresholds.criteria.max } }));
|
|
180
202
|
}
|
|
181
203
|
const scenarios = (plan.scenarios ?? []).length;
|
|
182
|
-
if (scenarios > 0 && (scenarios <
|
|
183
|
-
gaps.push(gap(poc, 'R5-scenarios-count', { field: 'plan.scenarios', params: { count: scenarios, min:
|
|
204
|
+
if (scenarios > 0 && (scenarios < thresholds.scenarios.min || scenarios > thresholds.scenarios.max)) {
|
|
205
|
+
gaps.push(gap(poc, 'R5-scenarios-count', { field: 'plan.scenarios', params: { count: scenarios, min: thresholds.scenarios.min, max: thresholds.scenarios.max } }));
|
|
184
206
|
}
|
|
185
207
|
const risks = (plan.risks ?? []).length;
|
|
186
|
-
if (risks >
|
|
187
|
-
gaps.push(gap(poc, 'R6-risks-overflow', { field: 'plan.risks', params: { count: risks, max:
|
|
208
|
+
if (risks > thresholds.risks.max) {
|
|
209
|
+
gaps.push(gap(poc, 'R6-risks-overflow', { field: 'plan.risks', params: { count: risks, max: thresholds.risks.max } }));
|
|
188
210
|
}
|
|
189
211
|
// R7 — testing started before G2 was ready.
|
|
190
212
|
const ready = text(plan.gate2?.ready);
|
|
@@ -219,9 +241,58 @@ export function scanGaps(poc, options) {
|
|
|
219
241
|
const since = text(poc.stage_since);
|
|
220
242
|
if (/^\d{4}-\d{2}-\d{2}$/.test(since)) {
|
|
221
243
|
const days = daysSince(since, options.now);
|
|
222
|
-
if (days !== null && days >
|
|
223
|
-
gaps.push(gap(poc, 'R12-stage-stalled', { field: 'stage_since', params: { days, stage: text(poc.stage), stallDays:
|
|
244
|
+
if (days !== null && days > thresholds.stallDays) {
|
|
245
|
+
gaps.push(gap(poc, 'R12-stage-stalled', { field: 'stage_since', params: { days, stage: text(poc.stage), stallDays: thresholds.stallDays } }));
|
|
224
246
|
}
|
|
225
247
|
}
|
|
248
|
+
// R13–R16 — the v3.1 state rules. They read the ledger's DERIVED per-item
|
|
249
|
+
// state, never a locally recomputed one: `tools/derive.mjs` is the only writer
|
|
250
|
+
// of `scenarios[].status` / `criteria[].status`, and CI rejects a file whose
|
|
251
|
+
// stored value disagrees with it. Re-deriving here would give this plugin a
|
|
252
|
+
// second opinion that the ledger would then call wrong.
|
|
253
|
+
const scenarioItems = Array.isArray(plan.scenarios) ? plan.scenarios : [];
|
|
254
|
+
const criteriaItems = Array.isArray(plan.criteria) ? plan.criteria : [];
|
|
255
|
+
const hasProgress = progress.length > 0;
|
|
256
|
+
// R13 — a scenario was claimed but nothing backs it. Guarded by
|
|
257
|
+
// `requires-progress`: before any progress exists, "no evidence" is just the
|
|
258
|
+
// project not having started, which is not a finding.
|
|
259
|
+
const unproven = scenarioItems.filter((item) => text(item?.status) === '无证据');
|
|
260
|
+
if (hasProgress && unproven.length > 0) {
|
|
261
|
+
gaps.push(gap(poc, 'R13-scenario-no-evidence', {
|
|
262
|
+
field: 'plan.scenarios',
|
|
263
|
+
params: { count: unproven.length, scenarios: unproven.map((item) => text(item?.name) || text(item?.id)).filter((name) => name !== '').join(',') },
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
// R14 — proof exists and the customer has not spoken. `info`, not `medium`:
|
|
267
|
+
// waiting on the customer is a status, not a fault of the project.
|
|
268
|
+
const awaiting = scenarioItems.filter((item) => text(item?.status) === '待客户确认');
|
|
269
|
+
if (awaiting.length > 0) {
|
|
270
|
+
gaps.push(gap(poc, 'R14-scenario-awaiting-customer', {
|
|
271
|
+
field: 'plan.scenarios',
|
|
272
|
+
params: { count: awaiting.length, scenarios: awaiting.map((item) => text(item?.name) || text(item?.id)).filter((name) => name !== '').join(',') },
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
// R15 — the plan is the right SIZE but a criterion is unverified.
|
|
276
|
+
// The guard is deliberate and comes from the ledger: R4 already reports a
|
|
277
|
+
// plan of the wrong size, so firing R15 alongside it reports the same fact
|
|
278
|
+
// twice and trains people to ignore the list. Fix the plan first.
|
|
279
|
+
const criteriaInRange = criteria >= thresholds.criteria.min && criteria <= thresholds.criteria.max;
|
|
280
|
+
const unverified = criteriaItems.filter((item) => text(item?.status) === '未验证');
|
|
281
|
+
if (criteriaInRange && unverified.length > 0) {
|
|
282
|
+
gaps.push(gap(poc, 'R15-criteria-unverified', {
|
|
283
|
+
field: 'plan.criteria',
|
|
284
|
+
params: { count: unverified.length, criteria: unverified.map((item) => text(item?.name) || text(item?.id)).filter((name) => name !== '').join(',') },
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
// R16 — the plan is the right size, work has begun, and a scenario was never
|
|
288
|
+
// reached. Same guard shape as R15, plus `requires-progress`.
|
|
289
|
+
const scenariosInRange = scenarios >= thresholds.scenarios.min && scenarios <= thresholds.scenarios.max;
|
|
290
|
+
const notStarted = scenarioItems.filter((item) => text(item?.status) === '未开始');
|
|
291
|
+
if (scenariosInRange && hasProgress && notStarted.length > 0) {
|
|
292
|
+
gaps.push(gap(poc, 'R16-scenario-not-started', {
|
|
293
|
+
field: 'plan.scenarios',
|
|
294
|
+
params: { count: notStarted.length, scenarios: notStarted.map((item) => text(item?.name) || text(item?.id)).filter((name) => name !== '').join(',') },
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
226
297
|
return gaps.sort((left, right) => right.priority - left.priority || left.ruleNo - right.ruleNo || left.rule.localeCompare(right.rule));
|
|
227
298
|
}
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,8 @@ import { PocStore } from './store.js';
|
|
|
18
18
|
import { RepoCache, RepoError, assertSafeCacheRoot } from './repo.js';
|
|
19
19
|
import { buildRiskBoard } from './risks.js';
|
|
20
20
|
import { buildGlobalTimeline } from './timeline.js';
|
|
21
|
+
import { text } from './gap.js';
|
|
22
|
+
import { buildFormHtml, formFileName, projectForForm } from './form.js';
|
|
21
23
|
import { registerBundledSkills } from './skill.js';
|
|
22
24
|
import { createExecuteRoute } from './transport.js';
|
|
23
25
|
export { resolveConfig };
|
|
@@ -92,6 +94,33 @@ export function createRuntime(config, options = {}) {
|
|
|
92
94
|
await this.prepare();
|
|
93
95
|
return buildGlobalTimeline(await loadOrEmpty(), { stallDays: config.stallDays });
|
|
94
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
|
+
},
|
|
95
124
|
};
|
|
96
125
|
}
|
|
97
126
|
export function apply(ctx, rawConfig = {}) {
|
package/lib/repo.d.ts
CHANGED
|
@@ -13,6 +13,22 @@
|
|
|
13
13
|
* 3. **A refresh is exclusive.** One lock file keeps two console instances in
|
|
14
14
|
* the same DSH home from cloning into the same directory at once.
|
|
15
15
|
*
|
|
16
|
+
* ## The ledger has three sources, not one
|
|
17
|
+
*
|
|
18
|
+
* As of schema 3.1 the repository publishes three distinct things, and they fail
|
|
19
|
+
* independently:
|
|
20
|
+
*
|
|
21
|
+
* - `projects/*.yaml` — the facts. Absence is an error: without it there is no
|
|
22
|
+
* console at all.
|
|
23
|
+
* - `config/*.yaml` — the judgement (thresholds, rule metadata, staleness
|
|
24
|
+
* limits). Absence is a **stale cache**, not a failure: the plugin falls back
|
|
25
|
+
* to its built-in numbers and says so.
|
|
26
|
+
* - `signals/*.yaml` — the agent's conclusions. Absence is normal: most projects
|
|
27
|
+
* have none, and a signal is an opinion rather than a fact.
|
|
28
|
+
*
|
|
29
|
+
* Treating all three the same would either refuse to render a perfectly usable
|
|
30
|
+
* older cache, or silently present fallback thresholds as the ledger's.
|
|
31
|
+
*
|
|
16
32
|
* Authentication is deliberately never stored: the token is read from the
|
|
17
33
|
* already-authenticated `gh` CLI at call time and passed to git through an
|
|
18
34
|
* environment-scoped `http.extraheader`, so it never lands in `.git/config`,
|
|
@@ -121,4 +137,48 @@ export declare class RepoCache {
|
|
|
121
137
|
projectFiles(): Promise<string[]>;
|
|
122
138
|
/** Read one project file, bounded so one huge file cannot stall the console. */
|
|
123
139
|
readProject(path: string): Promise<string>;
|
|
140
|
+
/**
|
|
141
|
+
* The ledger's `config/rules.yaml`, or `null` when the cache predates it.
|
|
142
|
+
*
|
|
143
|
+
* Returning `null` rather than throwing is deliberate: a cache cloned before
|
|
144
|
+
* the ledger added `config/` is a stale cache, not a broken one, and the caller
|
|
145
|
+
* falls back to the built-in thresholds while saying so.
|
|
146
|
+
*/
|
|
147
|
+
readRules(): Promise<string | null>;
|
|
148
|
+
/**
|
|
149
|
+
* The ledger's `config/derive.yaml`.
|
|
150
|
+
*
|
|
151
|
+
* Declares which derived fields the ledger stores and which are computed at
|
|
152
|
+
* read time. The plugin needs it to honour the same split: a stored value is a
|
|
153
|
+
* pure function of the record, a computed one depends on the clock and must
|
|
154
|
+
* never be shown as though it were written down.
|
|
155
|
+
*/
|
|
156
|
+
readDerive(): Promise<string | null>;
|
|
157
|
+
/**
|
|
158
|
+
* The ledger's `config/health.yaml`.
|
|
159
|
+
*
|
|
160
|
+
* Holds two separate staleness notions — facts (nothing happened) and judgment
|
|
161
|
+
* (nobody looked) — that fail for different reasons and must not be collapsed.
|
|
162
|
+
*/
|
|
163
|
+
readHealth(): Promise<string | null>;
|
|
164
|
+
/** One file from `config/`, or `null` when absent or unreasonably large. */
|
|
165
|
+
private readConfigFile;
|
|
166
|
+
/**
|
|
167
|
+
* The agent conclusions under `signals/`, keyed by `poc_id`.
|
|
168
|
+
*
|
|
169
|
+
* A signal is an opinion, not a fact: it is written only by the agent account,
|
|
170
|
+
* and the ledger's own README requires consumers to degrade gracefully when a
|
|
171
|
+
* field is missing or the directory does not exist yet. A malformed signal
|
|
172
|
+
* therefore becomes a warning and is skipped — it must never fail the page that
|
|
173
|
+
* shows the human facts.
|
|
174
|
+
*/
|
|
175
|
+
signalFiles(): Promise<Map<string, string>>;
|
|
176
|
+
/**
|
|
177
|
+
* Read a file that is allowed not to exist.
|
|
178
|
+
*
|
|
179
|
+
* `null` means "this cache does not carry it", which callers translate into a
|
|
180
|
+
* degraded-but-usable state. Only `ENOENT` is treated that way: a permission
|
|
181
|
+
* error is a real problem and must surface.
|
|
182
|
+
*/
|
|
183
|
+
private readOptionalFile;
|
|
124
184
|
}
|
package/lib/repo.js
CHANGED
|
@@ -13,6 +13,22 @@
|
|
|
13
13
|
* 3. **A refresh is exclusive.** One lock file keeps two console instances in
|
|
14
14
|
* the same DSH home from cloning into the same directory at once.
|
|
15
15
|
*
|
|
16
|
+
* ## The ledger has three sources, not one
|
|
17
|
+
*
|
|
18
|
+
* As of schema 3.1 the repository publishes three distinct things, and they fail
|
|
19
|
+
* independently:
|
|
20
|
+
*
|
|
21
|
+
* - `projects/*.yaml` — the facts. Absence is an error: without it there is no
|
|
22
|
+
* console at all.
|
|
23
|
+
* - `config/*.yaml` — the judgement (thresholds, rule metadata, staleness
|
|
24
|
+
* limits). Absence is a **stale cache**, not a failure: the plugin falls back
|
|
25
|
+
* to its built-in numbers and says so.
|
|
26
|
+
* - `signals/*.yaml` — the agent's conclusions. Absence is normal: most projects
|
|
27
|
+
* have none, and a signal is an opinion rather than a fact.
|
|
28
|
+
*
|
|
29
|
+
* Treating all three the same would either refuse to render a perfectly usable
|
|
30
|
+
* older cache, or silently present fallback thresholds as the ledger's.
|
|
31
|
+
*
|
|
16
32
|
* Authentication is deliberately never stored: the token is read from the
|
|
17
33
|
* already-authenticated `gh` CLI at call time and passed to git through an
|
|
18
34
|
* environment-scoped `http.extraheader`, so it never lands in `.git/config`,
|
|
@@ -404,4 +420,87 @@ export class RepoCache {
|
|
|
404
420
|
}
|
|
405
421
|
return readFile(path, 'utf8');
|
|
406
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* The ledger's `config/rules.yaml`, or `null` when the cache predates it.
|
|
425
|
+
*
|
|
426
|
+
* Returning `null` rather than throwing is deliberate: a cache cloned before
|
|
427
|
+
* the ledger added `config/` is a stale cache, not a broken one, and the caller
|
|
428
|
+
* falls back to the built-in thresholds while saying so.
|
|
429
|
+
*/
|
|
430
|
+
async readRules() {
|
|
431
|
+
return this.readConfigFile('rules.yaml');
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* The ledger's `config/derive.yaml`.
|
|
435
|
+
*
|
|
436
|
+
* Declares which derived fields the ledger stores and which are computed at
|
|
437
|
+
* read time. The plugin needs it to honour the same split: a stored value is a
|
|
438
|
+
* pure function of the record, a computed one depends on the clock and must
|
|
439
|
+
* never be shown as though it were written down.
|
|
440
|
+
*/
|
|
441
|
+
async readDerive() {
|
|
442
|
+
return this.readConfigFile('derive.yaml');
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* The ledger's `config/health.yaml`.
|
|
446
|
+
*
|
|
447
|
+
* Holds two separate staleness notions — facts (nothing happened) and judgment
|
|
448
|
+
* (nobody looked) — that fail for different reasons and must not be collapsed.
|
|
449
|
+
*/
|
|
450
|
+
async readHealth() {
|
|
451
|
+
return this.readConfigFile('health.yaml');
|
|
452
|
+
}
|
|
453
|
+
/** One file from `config/`, or `null` when absent or unreasonably large. */
|
|
454
|
+
async readConfigFile(name) {
|
|
455
|
+
return this.readOptionalFile(join(this.repoPath, 'config', name));
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* The agent conclusions under `signals/`, keyed by `poc_id`.
|
|
459
|
+
*
|
|
460
|
+
* A signal is an opinion, not a fact: it is written only by the agent account,
|
|
461
|
+
* and the ledger's own README requires consumers to degrade gracefully when a
|
|
462
|
+
* field is missing or the directory does not exist yet. A malformed signal
|
|
463
|
+
* therefore becomes a warning and is skipped — it must never fail the page that
|
|
464
|
+
* shows the human facts.
|
|
465
|
+
*/
|
|
466
|
+
async signalFiles() {
|
|
467
|
+
const dir = join(this.repoPath, 'signals');
|
|
468
|
+
let names;
|
|
469
|
+
try {
|
|
470
|
+
names = await readdir(dir);
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
if (error.code === 'ENOENT')
|
|
474
|
+
return new Map();
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
const found = new Map();
|
|
478
|
+
for (const name of names.filter((entry) => entry.endsWith('.yaml') || entry.endsWith('.yml')).sort()) {
|
|
479
|
+
const source = await this.readOptionalFile(join(dir, name));
|
|
480
|
+
if (source === null)
|
|
481
|
+
continue;
|
|
482
|
+
found.set(name.replace(/\.ya?ml$/, ''), source);
|
|
483
|
+
}
|
|
484
|
+
return found;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Read a file that is allowed not to exist.
|
|
488
|
+
*
|
|
489
|
+
* `null` means "this cache does not carry it", which callers translate into a
|
|
490
|
+
* degraded-but-usable state. Only `ENOENT` is treated that way: a permission
|
|
491
|
+
* error is a real problem and must surface.
|
|
492
|
+
*/
|
|
493
|
+
async readOptionalFile(path) {
|
|
494
|
+
try {
|
|
495
|
+
const info = await stat(path);
|
|
496
|
+
if (info.size > MAX_YAML_BYTES)
|
|
497
|
+
return null;
|
|
498
|
+
return await readFile(path, 'utf8');
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
if (error.code === 'ENOENT')
|
|
502
|
+
return null;
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
407
506
|
}
|
package/lib/rules.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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 type { GapRule } from './types.js';
|
|
24
|
+
/** Where the thresholds in force came from. */
|
|
25
|
+
export type RulesSource = 'ledger' | 'fallback';
|
|
26
|
+
/** Focus limits for a list field, as declared by the ledger. */
|
|
27
|
+
export interface RangeThreshold {
|
|
28
|
+
min: number;
|
|
29
|
+
max: number;
|
|
30
|
+
}
|
|
31
|
+
/** Every threshold `rules.yaml` publishes, with the built-in fallback applied. */
|
|
32
|
+
export interface RuleThresholds {
|
|
33
|
+
/** Above this amount a cleared G0 is mandatory (R2). */
|
|
34
|
+
largeAmountWan: number;
|
|
35
|
+
/** Success-criteria focus limit (R4). */
|
|
36
|
+
criteria: RangeThreshold;
|
|
37
|
+
/** Scenario focus limit (R5). */
|
|
38
|
+
scenarios: RangeThreshold;
|
|
39
|
+
/** Maximum tracked risks (R6). */
|
|
40
|
+
risks: {
|
|
41
|
+
max: number;
|
|
42
|
+
};
|
|
43
|
+
/** Days in one stage before R12 reports a stall. */
|
|
44
|
+
stallDays: number;
|
|
45
|
+
}
|
|
46
|
+
/** Priority thresholds, kept because the board sorts by the derived value. */
|
|
47
|
+
export interface PriorityThresholds {
|
|
48
|
+
strategicWan: number;
|
|
49
|
+
highWan: number;
|
|
50
|
+
strategicPocTypes: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
/** One rule's presentation metadata. */
|
|
53
|
+
export interface RuleMeta {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
level: GapLevelLike;
|
|
57
|
+
priority: number;
|
|
58
|
+
guard: string | null;
|
|
59
|
+
}
|
|
60
|
+
/** The three severities `rules.yaml` can express. */
|
|
61
|
+
export type GapLevelLike = 'high' | 'medium' | 'info';
|
|
62
|
+
/**
|
|
63
|
+
* The rule ids this plugin implements, in schema order.
|
|
64
|
+
*
|
|
65
|
+
* Kept separate from the ledger's list on purpose: the ledger may add a rule the
|
|
66
|
+
* plugin does not yet render, and that must not crash the scan. Anything in
|
|
67
|
+
* `ledgerOrder` without an entry here is simply not evaluated.
|
|
68
|
+
*/
|
|
69
|
+
export declare const KNOWN_RULES: ReadonlyArray<GapRule>;
|
|
70
|
+
/**
|
|
71
|
+
* The built-in copy of `rules.yaml`, used when the cache has no `config/`.
|
|
72
|
+
*
|
|
73
|
+
* These are the values shipped with schema 3.1 / rules 3.2. They are a **fallback,
|
|
74
|
+
* not the source of truth**: when the ledger's file is present it always wins.
|
|
75
|
+
*/
|
|
76
|
+
export declare const FALLBACK_THRESHOLDS: RuleThresholds;
|
|
77
|
+
export declare const FALLBACK_PRIORITY: PriorityThresholds;
|
|
78
|
+
/** Fallback metadata, matching `rules.yaml` rules 1–16. */
|
|
79
|
+
export declare const FALLBACK_RULE_META: Record<string, RuleMeta>;
|
|
80
|
+
/** Everything the scan needs from the ledger's declared rules. */
|
|
81
|
+
export interface RulesBundle {
|
|
82
|
+
source: RulesSource;
|
|
83
|
+
/** `config/rules.yaml#version`, or empty when the file was absent. */
|
|
84
|
+
rulesVersion: string;
|
|
85
|
+
thresholds: RuleThresholds;
|
|
86
|
+
priority: PriorityThresholds;
|
|
87
|
+
/** Metadata keyed by the ledger's rule id (`R1`..`R16`). */
|
|
88
|
+
rules: Record<string, RuleMeta>;
|
|
89
|
+
/** Non-fatal problems met while reading the file, for the UI to surface. */
|
|
90
|
+
warnings: string[];
|
|
91
|
+
}
|
|
92
|
+
/** The bundle used when no ledger file is readable. */
|
|
93
|
+
export declare function fallbackRules(warnings?: string[]): RulesBundle;
|
|
94
|
+
/**
|
|
95
|
+
* Parse `config/rules.yaml` into a {@link RulesBundle}.
|
|
96
|
+
*
|
|
97
|
+
* Returns the fallback bundle when the source is empty or unparsable, and records
|
|
98
|
+
* why in `warnings` — an unreadable rules file is a degraded cache, not a reason
|
|
99
|
+
* to refuse to scan.
|
|
100
|
+
*/
|
|
101
|
+
export declare function parseRules(source: string | null | undefined): RulesBundle;
|
|
102
|
+
/** The plugin's rule id for a ledger rule number (`R13` → `R13-scenario-no-evidence`). */
|
|
103
|
+
export declare function ruleForLedgerId(ledgerId: string): GapRule | null;
|
|
104
|
+
/** Every rule id the ledger declares in `rules.yaml`, in file order. */
|
|
105
|
+
export declare function ledgerRuleIds(bundle: RulesBundle): string[];
|