@skillre/dsh-plugin-work-dashboard 0.9.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/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
- /** Days in one stage after which rule 12 fires. */
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. */
package/lib/store.js CHANGED
@@ -16,6 +16,8 @@
16
16
  */
17
17
  import YAML from 'yaml';
18
18
  import { daysSince, lastProgressDate, latestProgress, normalizeStage, numberOrNull, readDimensions, scanGaps, text, } from './gap.js';
19
+ import { parseRules } from './rules.js';
20
+ import { parseHealthConfig, parseSignals } from './signals.js';
19
21
  import { buildBlockerBoard } from './blockers.js';
20
22
  import { RepoError } from './repo.js';
21
23
  /** The Host-side view model builder. */
@@ -75,6 +77,16 @@ export class PocStore {
75
77
  }
76
78
  return { records, warnings };
77
79
  }
80
+ /**
81
+ * The rules in force, read from the ledger's `config/rules.yaml`.
82
+ *
83
+ * A missing file is reported through `RulesBundle.source === 'fallback'`, not
84
+ * thrown: an older cache must still render, it just must not pretend its
85
+ * thresholds are the ledger's.
86
+ */
87
+ async rules() {
88
+ return parseRules(await this.cache.readRules());
89
+ }
78
90
  /** The overview snapshot; never throws for a missing cache, it reports it. */
79
91
  async snapshot() {
80
92
  const cacheReady = await this.cache.isReady();
@@ -90,15 +102,28 @@ export class PocStore {
90
102
  gaps: [],
91
103
  analysis: emptyAnalysis(),
92
104
  blockers: buildBlockerBoard([], { now: this.options.now(), stallDays: this.options.stallDays }),
105
+ rules: {
106
+ source: 'fallback',
107
+ rulesVersion: '',
108
+ schemaVersion: '',
109
+ schemaCurrent: false,
110
+ healthSource: 'fallback',
111
+ },
93
112
  warnings: [],
94
113
  };
95
114
  }
96
115
  const { records, warnings } = await this.load();
97
116
  const now = this.options.now();
98
- const projects = records.map((record) => summarize(record, now, this.options.stallDays));
117
+ // The ledger owns the thresholds, so its rules file wins over the configured
118
+ // `stallDays`. The fallback keeps a stale cache renderable while flagging it.
119
+ const rules = await this.rules();
120
+ const health = parseHealthConfig(await this.cache.readHealth());
121
+ const signals = parseSignals(await this.cache.signalFiles());
122
+ const scanOptions = { now, stallDays: rules.thresholds.stallDays, rules };
123
+ const projects = records.map((record) => summarize(record, now, scanOptions));
99
124
  const gaps = [];
100
125
  for (const record of records) {
101
- gaps.push(...scanGaps(record, { now, stallDays: this.options.stallDays }));
126
+ gaps.push(...scanGaps(record, scanOptions));
102
127
  }
103
128
  gaps.sort(compareGaps);
104
129
  const sorted = projects.sort(compareProjects);
@@ -111,8 +136,15 @@ export class PocStore {
111
136
  stats: computeStats(sorted),
112
137
  gaps,
113
138
  analysis: analyse(sorted, gaps),
114
- blockers: buildBlockerBoard(records, { now, stallDays: this.options.stallDays }),
115
- warnings,
139
+ blockers: buildBlockerBoard(records, scanOptions),
140
+ rules: {
141
+ source: rules.source,
142
+ rulesVersion: rules.rulesVersion,
143
+ schemaVersion: schemaVersionOf(records),
144
+ schemaCurrent: records.some((record) => text(record.schema_version) === '3.1'),
145
+ healthSource: health.source,
146
+ },
147
+ warnings: [...warnings, ...rules.warnings, ...health.warnings, ...signals.warnings],
116
148
  };
117
149
  }
118
150
  /** One project's full record; `null` when no file declares that id. */
@@ -124,7 +156,9 @@ export class PocStore {
124
156
  if (record === undefined)
125
157
  return null;
126
158
  const now = this.options.now();
127
- const summary = summarize(record, now, this.options.stallDays);
159
+ const rules = await this.rules();
160
+ const scanOptions = { now, stallDays: rules.thresholds.stallDays, rules };
161
+ const summary = summarize(record, now, scanOptions);
128
162
  const gate0 = record.gate0 ?? {};
129
163
  const plan = record.plan ?? {};
130
164
  const outcome = record.outcome ?? {};
@@ -160,12 +194,21 @@ export class PocStore {
160
194
  customerPain: text(plan.customer_pain),
161
195
  expectedRecognition: text(plan.expected_recognition),
162
196
  criteria: (plan.criteria ?? []).map((item) => ({
197
+ id: text(item?.id),
163
198
  name: text(item?.name),
164
199
  metric: text(item?.metric),
165
200
  baseline: text(item?.baseline),
166
201
  target: text(item?.target),
202
+ status: text(item?.status),
203
+ })),
204
+ scenarios: (plan.scenarios ?? []).map((item) => ({
205
+ id: text(item?.id),
206
+ name: text(item?.name),
207
+ goal: text(item?.goal),
208
+ status: text(item?.status),
209
+ evidenceCount: numberOrNull(item?.evidence_count) ?? 0,
210
+ recognition: text(item?.recognition),
167
211
  })),
168
- scenarios: (plan.scenarios ?? []).map(text).filter((item) => item !== ''),
169
212
  ourEdge: text(plan.our_edge),
170
213
  timelineStart: text(plan.timeline?.start),
171
214
  timelineEnd: text(plan.timeline?.end),
@@ -182,8 +225,10 @@ export class PocStore {
182
225
  seq: numberOrNull(entry?.seq),
183
226
  date: text(entry?.date),
184
227
  type: text(entry?.type),
228
+ change: text(entry?.change),
185
229
  goal: text(entry?.goal),
186
- items: (entry?.items ?? []).map(text).filter((item) => item !== ''),
230
+ scenarioIds: (entry?.scenario_ids ?? []).map(text).filter((item) => item !== ''),
231
+ criteriaIds: (entry?.criteria_ids ?? []).map(text).filter((item) => item !== ''),
187
232
  actual: text(entry?.actual),
188
233
  completion: text(entry?.completion),
189
234
  evidence: (entry?.evidence ?? []).map((item) => ({
@@ -219,10 +264,35 @@ export class PocStore {
219
264
  overall: text(outcome.overall),
220
265
  reviewedAt: text(outcome.reviewed_at),
221
266
  },
222
- gaps: scanGaps(record, { now, stallDays: this.options.stallDays }),
267
+ gaps: scanGaps(record, scanOptions),
223
268
  };
224
269
  }
225
270
  }
271
+ /**
272
+ * The most common declared `schema_version` across the records.
273
+ *
274
+ * The ledger states one shape version for the whole repository, so a mixed set
275
+ * means the cache is mid-migration. Reporting the majority keeps the UI honest
276
+ * without claiming uniformity it cannot prove.
277
+ */
278
+ function schemaVersionOf(records) {
279
+ const counts = new Map();
280
+ for (const record of records) {
281
+ const version = text(record.schema_version);
282
+ if (version === '')
283
+ continue;
284
+ counts.set(version, (counts.get(version) ?? 0) + 1);
285
+ }
286
+ let best = '';
287
+ let bestCount = 0;
288
+ for (const [version, count] of counts) {
289
+ if (count > bestCount || (count === bestCount && version > best)) {
290
+ best = version;
291
+ bestCount = count;
292
+ }
293
+ }
294
+ return best;
295
+ }
226
296
  /** File name without its directory, for warning text. */
227
297
  function basename(path) {
228
298
  const index = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
@@ -246,10 +316,10 @@ function progressSummary(poc) {
246
316
  return parts.join(' · ');
247
317
  }
248
318
  /** Collapse one record into the table row the overview renders. */
249
- function summarize(record, now, stallDays) {
319
+ function summarize(record, now, scanOptions) {
250
320
  const dimensions = readDimensions(record);
251
321
  const { stage, closed } = normalizeStage(record.stage);
252
- const gaps = scanGaps(record, { now, stallDays });
322
+ const gaps = scanGaps(record, scanOptions);
253
323
  const gate0 = record.gate0 ?? {};
254
324
  const activity = lastProgressDate(record);
255
325
  const stageSince = text(record.stage_since);
package/lib/types.d.ts CHANGED
@@ -51,22 +51,73 @@ export type SortKey = (typeof SORT_KEYS)[number];
51
51
  export declare const VIEW_MODE_KEY = "work-dashboard.viewMode";
52
52
  export declare const SORT_KEY_KEY = "work-dashboard.sortKey";
53
53
  /** Every gap rule id this plugin knows. */
54
- export declare const GAP_RULES: readonly ["R1-gate0-missing", "R2-large-amount-no-g0", "R3-g0-passed-no-plan", "R4-criteria-count", "R5-scenarios-count", "R6-risks-overflow", "R7-g2-not-ready", "R8-progress-no-evidence", "R9-evidence-no-recognition", "R10-g3-1-without-g3-2", "R11-no-next-milestone", "R12-stage-stalled"];
54
+ export declare const GAP_RULES: readonly ["R1-gate0-missing", "R2-large-amount-no-g0", "R3-g0-passed-no-plan", "R4-criteria-count", "R5-scenarios-count", "R6-risks-overflow", "R7-g2-not-ready", "R8-progress-no-evidence", "R9-evidence-no-recognition", "R10-g3-1-without-g3-2", "R11-no-next-milestone", "R12-stage-stalled", "R13-scenario-no-evidence", "R14-scenario-awaiting-customer", "R15-criteria-unverified", "R16-scenario-not-started"];
55
55
  export type GapRule = (typeof GAP_RULES)[number];
56
- /** Severity a gap carries; `high` sorts first and paints red. */
57
- export type GapLevel = 'high' | 'medium';
56
+ /**
57
+ * Severity a gap carries.
58
+ *
59
+ * `high` sorts first and paints red, `medium` is amber, and `info` is the
60
+ * deliberate "this is true but not urgent" tier the ledger introduced for R14: a
61
+ * scenario waiting on the customer is a status, not a fault. Collapsing it into
62
+ * `medium` would put a normal state on the same list as missed evidence.
63
+ */
64
+ export type GapLevel = 'high' | 'medium' | 'info';
58
65
  /** One evidence artefact attached to a progress entry. */
59
66
  export interface EvidenceRecord {
60
67
  title?: string | null;
61
68
  link?: string | null;
62
69
  type?: string | null;
63
70
  }
64
- /** One success criterion (`plan.criteria[]`). */
71
+ /**
72
+ * One success criterion (`plan.criteria[]`).
73
+ *
74
+ * v3.1 gives every criterion a stable `id` and a derived `status`. The id is what
75
+ * a progress entry cites in `criteria_ids`; the status is written by the ledger's
76
+ * `tools/derive.mjs`, so it is read here, never computed.
77
+ */
65
78
  export interface CriterionRecord {
79
+ id?: string | null;
66
80
  name?: string | null;
67
81
  metric?: string | null;
68
82
  baseline?: string | number | null;
69
83
  target?: string | number | null;
84
+ /** Derived by the ledger: 已达成 / 部分达成 / 未达成 / 未验证. */
85
+ status?: string | null;
86
+ }
87
+ /**
88
+ * One test scenario (`plan.scenarios[]`).
89
+ *
90
+ * v3.1 promoted this from a bare string to an object with a stable `id`, because
91
+ * evidence is attached by id: renaming a scenario must not orphan its proof. The
92
+ * three derived fields are written by the ledger, not by this plugin.
93
+ */
94
+ export interface ScenarioRecord {
95
+ /** Stable `scn-NN`; unique within the project and never reused. */
96
+ id?: string | null;
97
+ name?: string | null;
98
+ goal?: string | null;
99
+ /** Derived by the ledger: 已证明 / 待客户确认 / 无证据 / 未开始. */
100
+ status?: string | null;
101
+ /** Derived by the ledger: total evidence items across citing progress entries. */
102
+ evidence_count?: number | null;
103
+ /** Derived by the ledger: the recognition recorded by the deciding round. */
104
+ recognition?: string | null;
105
+ }
106
+ /**
107
+ * One gate transition (`gate_decisions[]`).
108
+ *
109
+ * Without it a promotion is just `stage` becoming a different string: months
110
+ * later nobody can say who decided, or on what basis.
111
+ */
112
+ export interface GateDecisionRecord {
113
+ from?: string | null;
114
+ to?: string | null;
115
+ decided_at?: string | null;
116
+ decided_by?: string | null;
117
+ /** `human` or `agent-suggested`. */
118
+ basis?: string | null;
119
+ signals_ref?: string | null;
120
+ note?: string | null;
70
121
  }
71
122
  /** One tracked risk (`plan.risks[]`). */
72
123
  export interface RiskRecord {
@@ -74,13 +125,26 @@ export interface RiskRecord {
74
125
  level?: string | null;
75
126
  mitigation?: string | null;
76
127
  }
77
- /** One progress entry (`progress[]`) — the centre of the v3 model. */
128
+ /**
129
+ * One progress entry (`progress[]`) — the centre of the v3 model.
130
+ *
131
+ * v3.1 shape. `items` is gone: a progress entry cites scenarios and criteria by
132
+ * id, and carries a mandatory `change` naming what moved since the previous
133
+ * entry. A file still using `items` is a schema error in the ledger, not a
134
+ * variant to tolerate here — reading it as "no scenario links" would silently
135
+ * demote every scenario from 已证明 back to 未开始.
136
+ */
78
137
  export interface ProgressRecord {
79
138
  seq?: number | null;
80
139
  date?: string | null;
81
140
  type?: string | null;
141
+ /** Mandatory in v3.1: what changed compared to the previous entry. */
142
+ change?: string | null;
82
143
  goal?: string | null;
83
- items?: (string | null)[] | null;
144
+ /** `scn-NN` ids. Names are not accepted by the ledger. */
145
+ scenario_ids?: (string | null)[] | null;
146
+ /** `cri-NN` ids; independent of `scenario_ids`. */
147
+ criteria_ids?: (string | null)[] | null;
84
148
  actual?: string | null;
85
149
  completion?: string | null;
86
150
  evidence?: EvidenceRecord[] | null;
@@ -118,7 +182,8 @@ export interface PlanRecord {
118
182
  customer_pain?: string | null;
119
183
  expected_recognition?: string | null;
120
184
  criteria?: CriterionRecord[] | null;
121
- scenarios?: (string | null)[] | null;
185
+ /** v3.1: objects with stable ids, not bare strings. */
186
+ scenarios?: ScenarioRecord[] | null;
122
187
  our_edge?: string | null;
123
188
  timeline?: {
124
189
  start?: string | null;
@@ -170,6 +235,11 @@ export interface OrgRecord {
170
235
  * absence into a finding.
171
236
  */
172
237
  export interface PocRecord {
238
+ /**
239
+ * The data-shape version, fixed `"3.1"`. A file without it is a v3.0 record
240
+ * and is handled as a degraded, read-only shape.
241
+ */
242
+ schema_version?: string | null;
173
243
  poc_id?: string | null;
174
244
  name?: string | null;
175
245
  org?: OrgRecord | null;
@@ -183,6 +253,8 @@ export interface PocRecord {
183
253
  stage?: string | null;
184
254
  status?: string | null;
185
255
  stage_since?: string | null;
256
+ /** v3.1: the audit trail of every gate promotion. */
257
+ gate_decisions?: GateDecisionRecord[] | null;
186
258
  gate0?: Gate0Record | null;
187
259
  plan?: PlanRecord | null;
188
260
  progress?: ProgressRecord[] | null;
@@ -408,16 +480,44 @@ export interface Snapshot {
408
480
  * disagree after a refresh, and the Client already holds the whole snapshot.
409
481
  */
410
482
  blockers: BlockerBoard;
483
+ /**
484
+ * Which judgement the findings in this snapshot were computed under.
485
+ *
486
+ * `source: 'fallback'` means the cache carried no `config/rules.yaml`, so the
487
+ * thresholds are this plugin's built-in copy rather than the ledger's. That is
488
+ * a usable state but not a trustworthy one: the ledger may have tuned a
489
+ * threshold, and reporting "no findings" under the wrong thresholds is exactly
490
+ * the silent drift the ledger's single-source rule exists to prevent.
491
+ */
492
+ rules: RulesProvenance;
411
493
  /** Non-fatal findings: unreadable files, unparsable YAML, duplicates. */
412
494
  warnings: string[];
413
495
  }
496
+ /** Where this snapshot's thresholds and judgement came from. */
497
+ export interface RulesProvenance {
498
+ /** `ledger` when `config/rules.yaml` was read, `fallback` when it was absent. */
499
+ source: 'ledger' | 'fallback';
500
+ /** `config/rules.yaml#version`, or empty under fallback. */
501
+ rulesVersion: string;
502
+ /** The data-shape version from `config/enums`/projects, when known. */
503
+ schemaVersion: string;
504
+ /** `true` when at least one project file declares `schema_version: "3.1"`. */
505
+ schemaCurrent: boolean;
506
+ /** The staleness limits in force, from `config/health.yaml`. */
507
+ healthSource: 'ledger' | 'fallback';
508
+ }
414
509
  /** One progress entry as the detail page receives it: every field present. */
415
510
  export interface ProgressView {
416
511
  seq: number | null;
417
512
  date: string;
418
513
  type: string;
514
+ /** v3.1: what moved compared to the previous entry. */
515
+ change: string;
419
516
  goal: string;
420
- items: string[];
517
+ /** `scn-NN` ids, as written in the ledger. */
518
+ scenarioIds: string[];
519
+ /** `cri-NN` ids, independent of `scenarioIds`. */
520
+ criteriaIds: string[];
421
521
  actual: string;
422
522
  completion: string;
423
523
  evidence: Array<{
@@ -485,16 +585,30 @@ export interface Gate0View {
485
585
  checklist: Gate0CheckItem[];
486
586
  }
487
587
  /** The plan block as the detail page receives it. */
588
+ /** One criterion as the client renders it, carrying the ledger's derived status. */
589
+ export interface CriterionView {
590
+ id: string;
591
+ name: string;
592
+ metric: string;
593
+ baseline: string;
594
+ target: string;
595
+ status: string;
596
+ }
597
+ /** One scenario as the client renders it, carrying the ledger's derived state. */
598
+ export interface ScenarioView {
599
+ id: string;
600
+ name: string;
601
+ goal: string;
602
+ /** 已证明 / 待客户确认 / 无证据 / 未开始; empty when the ledger did not derive it. */
603
+ status: string;
604
+ evidenceCount: number;
605
+ recognition: string;
606
+ }
488
607
  export interface PlanView {
489
608
  customerPain: string;
490
609
  expectedRecognition: string;
491
- criteria: Array<{
492
- name: string;
493
- metric: string;
494
- baseline: string;
495
- target: string;
496
- }>;
497
- scenarios: string[];
610
+ criteria: CriterionView[];
611
+ scenarios: ScenarioView[];
498
612
  ourEdge: string;
499
613
  timelineStart: string;
500
614
  timelineEnd: string;
package/lib/types.js CHANGED
@@ -59,6 +59,11 @@ export const GAP_RULES = Object.freeze([
59
59
  'R10-g3-1-without-g3-2',
60
60
  'R11-no-next-milestone',
61
61
  'R12-stage-stalled',
62
+ // v3.1 state rules: a plan that is the right shape but unexecuted.
63
+ 'R13-scenario-no-evidence',
64
+ 'R14-scenario-awaiting-customer',
65
+ 'R15-criteria-unverified',
66
+ 'R16-scenario-not-started',
62
67
  ]);
63
68
  /**
64
69
  * Where a blocker comes from.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillre/dsh-plugin-work-dashboard",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "工作看板:多模块运营看板,POC 运营为首个模块(四维结果、阶段轨道、缺口清单、风险看板、时间线、导出表单)",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",