@skillre/dsh-plugin-work-dashboard 0.9.0 → 0.10.1
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/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-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/client/css/detail.d.ts +1 -1
- package/lib/client/css/detail.js +273 -22
- package/lib/client/text.js +90 -6
- package/lib/client.js +3040 -519
- package/lib/form.d.ts +62 -2
- package/lib/form.js +88 -10
- package/lib/gap.d.ts +26 -8
- package/lib/gap.js +88 -17
- 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 +80 -10
- package/lib/types.d.ts +129 -15
- package/lib/types.js +5 -0
- package/package.json +1 -1
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[];
|
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;
|