@skillre/dsh-plugin-work-dashboard 0.11.0 → 0.12.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/form.d.ts CHANGED
@@ -35,7 +35,7 @@
35
35
  * commits; submission stays a human-merged PR, which is the ledger's design.
36
36
  */
37
37
  import YAML from 'yaml';
38
- import type { PocRecord } from './types.js';
38
+ import type { PocRecord, ProgressRecord } from './types.js';
39
39
  /** The four G0 prerequisites that live under `gate0` (the fifth is identity). */
40
40
  export declare const G0_FIELDS: readonly ["why_customer", "why_us", "decision_chain", "post_poc_decision"];
41
41
  /** One plan criterion, as the form edits it. */
@@ -98,6 +98,35 @@ export interface FormProgress {
98
98
  deadline: string;
99
99
  };
100
100
  }
101
+ /**
102
+ * One already-recorded progress round, as the form shows it read-only.
103
+ *
104
+ * This exists because the form used to say only "已有 3 条进展" and never showed
105
+ * them. Two concrete failures came from that:
106
+ *
107
+ * - the colleague could not see what had already been reported, so the same
108
+ * round was filed twice under different wording;
109
+ * - the reviewer opening a returned form could not see the story the new round
110
+ * was supposed to continue, so "这次什么变了" was unverifiable.
111
+ *
112
+ * Read-only by construction: v3 history is append-only, and the form's job is to
113
+ * add a round, never to rewrite one.
114
+ */
115
+ export interface FormHistoryEntry {
116
+ seq: number | null;
117
+ date: string;
118
+ type: string;
119
+ change: string;
120
+ actual: string;
121
+ completion: string;
122
+ /** Evidence titles, already flattened: the form only lists them. */
123
+ evidence: string[];
124
+ syncedWith: string;
125
+ recognition: string;
126
+ nextGoal: string;
127
+ nextOwner: string;
128
+ nextDeadline: string;
129
+ }
101
130
  /**
102
131
  * The project shape the form edits.
103
132
  *
@@ -146,6 +175,14 @@ export interface FormProject {
146
175
  progress: FormProgress;
147
176
  /** How many entries the project already has (so `seq` can continue). */
148
177
  existingProgressCount: number;
178
+ /**
179
+ * The recorded rounds, newest first, for the read-only history block.
180
+ *
181
+ * Capped by {@link HISTORY_LIMIT}: a project with forty rounds does not need
182
+ * all forty in a form whose job is to add the forty-first, and an uncapped list
183
+ * would push the fields the colleague must fill below the fold.
184
+ */
185
+ history: FormHistoryEntry[];
149
186
  /**
150
187
  * The G4 conclusion block.
151
188
  *
@@ -219,6 +256,17 @@ export interface FormOptions {
219
256
  * empty one rather than `undefined`, so the generated script never has to guard.
220
257
  */
221
258
  export declare function projectForForm(record: PocRecord): FormProject;
259
+ /** How many recorded rounds the form lists read-only. */
260
+ export declare const HISTORY_LIMIT = 5;
261
+ /**
262
+ * Flatten the recorded rounds for the read-only history block.
263
+ *
264
+ * Newest first, because the round a colleague is about to continue is the newest
265
+ * one: reading it first is what makes "这次什么变了" answerable. The order is
266
+ * reversed rather than re-sorted by date because the ledger's own array order is
267
+ * the append order, and a hand-edited `date` must not reshuffle history.
268
+ */
269
+ export declare function progressHistory(progress: readonly ProgressRecord[]): FormHistoryEntry[];
222
270
  /** One empty progress entry, with `seq` continuing the existing count. */
223
271
  export declare function blankProgress(existingCount: number): FormProgress;
224
272
  /** The blank project a `blank`-mode form edits. */
@@ -317,17 +365,50 @@ export interface FormChangeSet {
317
365
  ready: string | null;
318
366
  };
319
367
  };
368
+ /**
369
+ * The G4 conclusion block.
370
+ *
371
+ * It was missing from the change set while the form could edit it, which meant a
372
+ * G4 colleague filled in "我们证明了什么 / 客户认可了什么 / 下一步业务动作",
373
+ * downloaded the file, and every one of those answers was silently dropped. The
374
+ * form showed the block; the serializer never wrote it. A G4 form could not
375
+ * record the only thing a G4 form exists to record.
376
+ */
377
+ outcome: {
378
+ achievement: string | null;
379
+ customer_recognition: string | null;
380
+ our_proof: string | null;
381
+ remaining_risks: string | null;
382
+ conclusion: {
383
+ proved: string | null;
384
+ recognized: string | null;
385
+ next_business: string | null;
386
+ };
387
+ business: {
388
+ milestone: string | null;
389
+ owner: string | null;
390
+ deadline: string | null;
391
+ status: string | null;
392
+ };
393
+ overall: string | null;
394
+ };
320
395
  /** The rounds this form ADDS; empty when the colleague recorded none. */
321
396
  progress: Array<Record<string, unknown>>;
322
397
  }
323
398
  /**
324
399
  * Build one project's change set from the form state.
325
400
  *
326
- * Every field the form can edit appears, so `poc-submit` can apply the whole
327
- * object with `setIfPresent` semantics: a blank field means "I did not change
328
- * this", which the merge step must not read as "delete it".
401
+ * Blocks outside the intent's scope are emitted as `null` (or an empty list), which
402
+ * `poc-submit` treats as "not changed" and skips. A blank field inside a block that
403
+ * IS in scope means the same thing: the colleague did not touch it.
404
+ *
405
+ * @param project the form's own view of the project
406
+ * @param intent what the colleague was asked to do; defaults to `supplement`, the
407
+ * widest scope, so an older caller keeps its previous behaviour
408
+ * @param baseline the project's values when the form was generated. When given,
409
+ * a field equal to its seed is emitted as `null` — "I did not touch this".
329
410
  */
330
- export declare function projectToChangeSet(project: FormProject): FormChangeSet;
411
+ export declare function projectToChangeSet(project: FormProject, intent?: FormIntent, baseline?: FormProject): FormChangeSet;
331
412
  /** The whole download: one change set per project, plus provenance. */
332
413
  export interface FormChangeDocument {
333
414
  schemaVersion: string;
@@ -341,6 +422,15 @@ export declare function buildChangeDocument(options: {
341
422
  projects: readonly FormProject[];
342
423
  intent: FormIntent;
343
424
  now?: Date;
425
+ /**
426
+ * The values each project had when the form was GENERATED.
427
+ *
428
+ * When supplied, only fields that differ from their seed are emitted — so a
429
+ * colleague who opened a form, changed one field and sent it back cannot revert
430
+ * the other twenty to the day the form was exported. See
431
+ * {@link projectToChangeSet}.
432
+ */
433
+ baseline?: readonly FormProject[];
344
434
  }): FormChangeDocument;
345
435
  /** The enums, mirrored from `schemas/enums.yaml`. */
346
436
  declare const ENUMS: {
@@ -391,6 +481,14 @@ export interface FormPayload {
391
481
  generatedAt: string;
392
482
  today: string;
393
483
  projects: FormProject[];
484
+ /**
485
+ * Each project's values at generation time, index-aligned with `projects`.
486
+ *
487
+ * The page compares against this before emitting a change set, so a field the
488
+ * colleague never touched is sent as "unchanged" rather than as its stale
489
+ * pre-filled value.
490
+ */
491
+ baseline: FormProject[];
394
492
  /**
395
493
  * Per-project section resolution, index-aligned with `projects`.
396
494
  *
@@ -411,6 +509,15 @@ export interface FormPayload {
411
509
  label: string;
412
510
  hint: string;
413
511
  }>;
512
+ /**
513
+ * The returned page's stylesheet.
514
+ *
515
+ * It is shipped in the payload rather than referenced from the page script
516
+ * because the page script is generated code with no module scope: it cannot see
517
+ * a Host constant, and a first attempt that assumed otherwise threw
518
+ * "RETURN_CSS is not defined" at the moment a colleague clicked the button.
519
+ */
520
+ returnCss: string;
414
521
  }
415
522
  /**
416
523
  * Generate the complete HTML form.
@@ -456,3 +563,35 @@ export interface FormCompatibility {
456
563
  * point is to inspect a document whose shape may be from an older generation.
457
564
  */
458
565
  export declare function checkFormCompatibility(payload: unknown): FormCompatibility;
566
+ /** The element id the returned page carries its change set in. */
567
+ export declare const RETURN_DATA_ID = "poc-return-data";
568
+ /** What reading a returned file produced. */
569
+ export interface ReturnReadResult {
570
+ /** The change document, or `null` when the file could not be read. */
571
+ document: FormChangeDocument | null;
572
+ /** A message safe to show the person who sent the file back. */
573
+ reason: string;
574
+ }
575
+ /**
576
+ * Read a returned form — either the `.html` this generator emits or a `.json`
577
+ * change set — back into a change document.
578
+ *
579
+ * ## Why both formats, and why HTML is the default
580
+ *
581
+ * The documented workflow is "colleague fills it in and sends the HTML back on
582
+ * WeChat". That only works if the returned HTML actually carries the answers, so
583
+ * {@link buildFormHtml}'s page writes a `RETURN_DATA_ID` script block holding the
584
+ * exact change set. The same page is also readable by a human: it renders the
585
+ * answers as formatted HTML, so the person who receives it can see what was
586
+ * submitted before handing it to DSH.
587
+ *
588
+ * The `.json` path is kept because it is stricter and smaller, and because forms
589
+ * already in circulation emit it.
590
+ *
591
+ * ## Safety
592
+ *
593
+ * The HTML is never executed and never given to a DOM parser: the block is found
594
+ * with a string search and the slice is handed to `JSON.parse`. Nothing in the
595
+ * returned file can run.
596
+ */
597
+ export declare function readReturnDocument(input: string): ReturnReadResult;