@sentropic/track 0.98.6 → 0.98.7-rc.10

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.
Files changed (163) hide show
  1. package/README.md +13 -0
  2. package/dist/cli/index.d.ts.map +1 -1
  3. package/dist/cli/index.js +95 -16
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/cli/install-skills.d.ts.map +1 -1
  6. package/dist/cli/install-skills.js +9 -3
  7. package/dist/cli/install-skills.js.map +1 -1
  8. package/dist/events/types.d.ts +1 -1
  9. package/dist/events/types.d.ts.map +1 -1
  10. package/dist/events/types.js +1 -0
  11. package/dist/events/types.js.map +1 -1
  12. package/dist/focus-vendor/editing/anchors.d.ts +20 -0
  13. package/dist/focus-vendor/editing/anchors.d.ts.map +1 -0
  14. package/dist/focus-vendor/editing/anchors.js +113 -0
  15. package/dist/focus-vendor/editing/anchors.js.map +1 -0
  16. package/dist/focus-vendor/editing/codec.d.ts +22 -0
  17. package/dist/focus-vendor/editing/codec.d.ts.map +1 -0
  18. package/dist/focus-vendor/editing/codec.js +143 -0
  19. package/dist/focus-vendor/editing/codec.js.map +1 -0
  20. package/dist/focus-vendor/editing/contract.d.ts +14 -0
  21. package/dist/focus-vendor/editing/contract.d.ts.map +1 -0
  22. package/dist/focus-vendor/editing/contract.js +76 -0
  23. package/dist/focus-vendor/editing/contract.js.map +1 -0
  24. package/dist/focus-vendor/editing/diff.d.ts +17 -0
  25. package/dist/focus-vendor/editing/diff.d.ts.map +1 -0
  26. package/dist/focus-vendor/editing/diff.js +125 -0
  27. package/dist/focus-vendor/editing/diff.js.map +1 -0
  28. package/dist/focus-vendor/editing/digest.d.ts +6 -0
  29. package/dist/focus-vendor/editing/digest.d.ts.map +1 -0
  30. package/dist/focus-vendor/editing/digest.js +56 -0
  31. package/dist/focus-vendor/editing/digest.js.map +1 -0
  32. package/dist/focus-vendor/editing/index.d.ts +7 -0
  33. package/dist/focus-vendor/editing/index.d.ts.map +1 -0
  34. package/dist/focus-vendor/editing/index.js +7 -0
  35. package/dist/focus-vendor/editing/index.js.map +1 -0
  36. package/dist/focus-vendor/editing/reconcile.d.ts +3 -0
  37. package/dist/focus-vendor/editing/reconcile.d.ts.map +1 -0
  38. package/dist/focus-vendor/editing/reconcile.js +167 -0
  39. package/dist/focus-vendor/editing/reconcile.js.map +1 -0
  40. package/dist/focus-vendor/editing/structure.d.ts +16 -0
  41. package/dist/focus-vendor/editing/structure.d.ts.map +1 -0
  42. package/dist/focus-vendor/editing/structure.js +71 -0
  43. package/dist/focus-vendor/editing/structure.js.map +1 -0
  44. package/dist/focus-vendor/index.d.ts +2 -0
  45. package/dist/focus-vendor/index.js +2 -0
  46. package/dist/focus-vendor/index.js.map +1 -1
  47. package/dist/focus-vendor/model.d.ts +1 -1
  48. package/dist/focus-vendor/model.d.ts.map +1 -1
  49. package/dist/focus-vendor/model.js +1 -1
  50. package/dist/focus-vendor/model.js.map +1 -1
  51. package/dist/focus-vendor/registry/definitions.d.ts +68 -0
  52. package/dist/focus-vendor/registry/definitions.d.ts.map +1 -0
  53. package/dist/focus-vendor/registry/definitions.js +509 -0
  54. package/dist/focus-vendor/registry/definitions.js.map +1 -0
  55. package/dist/focus-vendor/registry/entries.v1.json +140 -0
  56. package/dist/focus-vendor/render/evidence.d.ts +9 -0
  57. package/dist/focus-vendor/render/evidence.d.ts.map +1 -0
  58. package/dist/focus-vendor/render/evidence.js +37 -0
  59. package/dist/focus-vendor/render/evidence.js.map +1 -0
  60. package/dist/focus-vendor/render/html.d.ts.map +1 -1
  61. package/dist/focus-vendor/render/html.js +14 -1
  62. package/dist/focus-vendor/render/html.js.map +1 -1
  63. package/dist/focus-vendor/render/md.d.ts.map +1 -1
  64. package/dist/focus-vendor/render/md.js +15 -1
  65. package/dist/focus-vendor/render/md.js.map +1 -1
  66. package/dist/focus-vendor/render/presentation.d.ts +29 -0
  67. package/dist/focus-vendor/render/presentation.d.ts.map +1 -0
  68. package/dist/focus-vendor/render/presentation.js +25 -0
  69. package/dist/focus-vendor/render/presentation.js.map +1 -0
  70. package/dist/focus-vendor/render/terminal.d.ts.map +1 -1
  71. package/dist/focus-vendor/render/terminal.js +15 -1
  72. package/dist/focus-vendor/render/terminal.js.map +1 -1
  73. package/dist/focus-vendor/track/index.d.ts +23 -27
  74. package/dist/focus-vendor/track/index.d.ts.map +1 -1
  75. package/dist/focus-vendor/track/index.js +24 -10
  76. package/dist/focus-vendor/track/index.js.map +1 -1
  77. package/dist/focus-vendor/validation/evidence-bytes.d.ts +5 -0
  78. package/dist/focus-vendor/validation/evidence-bytes.d.ts.map +1 -0
  79. package/dist/focus-vendor/validation/evidence-bytes.js +57 -0
  80. package/dist/focus-vendor/validation/evidence-bytes.js.map +1 -0
  81. package/dist/focus-vendor/validation/evidence-shape.d.ts +11 -0
  82. package/dist/focus-vendor/validation/evidence-shape.d.ts.map +1 -0
  83. package/dist/focus-vendor/validation/evidence-shape.js +54 -0
  84. package/dist/focus-vendor/validation/evidence-shape.js.map +1 -0
  85. package/dist/focus-vendor/validation/evidence-sources.d.ts +6 -0
  86. package/dist/focus-vendor/validation/evidence-sources.d.ts.map +1 -0
  87. package/dist/focus-vendor/validation/evidence-sources.js +56 -0
  88. package/dist/focus-vendor/validation/evidence-sources.js.map +1 -0
  89. package/dist/focus-vendor/validation/evidence.d.ts +3 -0
  90. package/dist/focus-vendor/validation/evidence.d.ts.map +1 -0
  91. package/dist/focus-vendor/validation/evidence.js +131 -0
  92. package/dist/focus-vendor/validation/evidence.js.map +1 -0
  93. package/dist/focus-vendor/validation/index.d.ts +187 -0
  94. package/dist/focus-vendor/validation/index.d.ts.map +1 -0
  95. package/dist/focus-vendor/validation/index.js +500 -0
  96. package/dist/focus-vendor/validation/index.js.map +1 -0
  97. package/dist/focus-vendor/validation/readability.d.ts +22 -0
  98. package/dist/focus-vendor/validation/readability.d.ts.map +1 -0
  99. package/dist/focus-vendor/validation/readability.js +265 -0
  100. package/dist/focus-vendor/validation/readability.js.map +1 -0
  101. package/dist/model/decision.d.ts +19 -0
  102. package/dist/model/decision.d.ts.map +1 -1
  103. package/dist/model/decision.js.map +1 -1
  104. package/dist/model/index.d.ts +1 -0
  105. package/dist/model/index.d.ts.map +1 -1
  106. package/dist/model/index.js +1 -0
  107. package/dist/model/index.js.map +1 -1
  108. package/dist/model/item.d.ts +2 -0
  109. package/dist/model/item.d.ts.map +1 -1
  110. package/dist/model/item.js.map +1 -1
  111. package/dist/model/report-status.d.ts +53 -0
  112. package/dist/model/report-status.d.ts.map +1 -0
  113. package/dist/model/report-status.js +106 -0
  114. package/dist/model/report-status.js.map +1 -0
  115. package/dist/read/commands.d.ts +22 -2
  116. package/dist/read/commands.d.ts.map +1 -1
  117. package/dist/read/commands.js +134 -21
  118. package/dist/read/commands.js.map +1 -1
  119. package/dist/read/contract.d.ts.map +1 -1
  120. package/dist/read/contract.js +3 -1
  121. package/dist/read/contract.js.map +1 -1
  122. package/dist/report/audit.d.ts +68 -0
  123. package/dist/report/audit.d.ts.map +1 -1
  124. package/dist/report/audit.js +116 -0
  125. package/dist/report/audit.js.map +1 -1
  126. package/dist/report/build.d.ts +82 -1
  127. package/dist/report/build.d.ts.map +1 -1
  128. package/dist/report/build.js +85 -3
  129. package/dist/report/build.js.map +1 -1
  130. package/dist/report/directive.d.ts +5 -1
  131. package/dist/report/directive.d.ts.map +1 -1
  132. package/dist/report/directive.js +4 -0
  133. package/dist/report/directive.js.map +1 -1
  134. package/dist/report/format.d.ts +104 -3
  135. package/dist/report/format.d.ts.map +1 -1
  136. package/dist/report/format.js +251 -27
  137. package/dist/report/format.js.map +1 -1
  138. package/dist/report/index.d.ts +5 -2
  139. package/dist/report/index.d.ts.map +1 -1
  140. package/dist/report/index.js +6 -1
  141. package/dist/report/index.js.map +1 -1
  142. package/dist/report/stage-status-lexicon.d.ts +24 -0
  143. package/dist/report/stage-status-lexicon.d.ts.map +1 -0
  144. package/dist/report/stage-status-lexicon.js +96 -0
  145. package/dist/report/stage-status-lexicon.js.map +1 -0
  146. package/dist/report/stage-status.d.ts +31 -0
  147. package/dist/report/stage-status.d.ts.map +1 -0
  148. package/dist/report/stage-status.js +208 -0
  149. package/dist/report/stage-status.js.map +1 -0
  150. package/dist/state/fold.d.ts.map +1 -1
  151. package/dist/state/fold.js +11 -0
  152. package/dist/state/fold.js.map +1 -1
  153. package/dist/track.d.ts +3 -0
  154. package/dist/track.d.ts.map +1 -1
  155. package/dist/track.js +12 -1
  156. package/dist/track.js.map +1 -1
  157. package/package.json +2 -2
  158. package/skills/present-decision/SKILL.md +98 -95
  159. package/skills/present-decision/assets/dossier-template.md +35 -38
  160. package/skills/present-decision/assets/native-questions.md +18 -0
  161. package/skills/present-decision/assets/owner-criteria.template.md +11 -16
  162. package/skills/present-decision/assets/self-audit.md +26 -22
  163. package/skills/propose-workpackages/SKILL.md +20 -1
@@ -1,4 +1,6 @@
1
1
  import { BUCKETS } from './buckets.js';
2
+ import { resolveStageStatusLabels } from './stage-status-lexicon.js';
3
+ import { STATUS_HEALTH } from './stage-status.js';
2
4
  import { buildDirectives, decisionNeedsFocus, dispatchQueueOf, keystoneOf, } from './directive.js';
3
5
  // Unified report presentation (spec 2026-07-11) — the SINGLE enum→French lexicon the cockpit shares, so
4
6
  // the two surfaces can never re-word apart. The terminal composes its own `<nature> (<actor>): <clause>`
@@ -104,10 +106,12 @@ function rowLine(r, format) {
104
106
  * readable, but only a dossier that satisfies the native validator is actionable.
105
107
  */
106
108
  function classifyDecisions(decisions) {
109
+ // Amendment D12 — `deferred` is pending, not settled, in every renderer.
110
+ const answerable = (decision) => decision.outcome === 'pending' || decision.outcome === 'deferred';
107
111
  return {
108
112
  structured: decisions.filter((decision) => decision.structured === true),
109
- legacyPending: decisions.filter((decision) => decision.structured !== true && decision.outcome === 'pending'),
110
- legacySettled: decisions.filter((decision) => decision.structured !== true && decision.outcome !== 'pending'),
113
+ legacyPending: decisions.filter((decision) => decision.structured !== true && answerable(decision)),
114
+ legacySettled: decisions.filter((decision) => decision.structured !== true && !answerable(decision)),
111
115
  };
112
116
  }
113
117
  function legacyRevisionAction(decision) {
@@ -291,7 +295,7 @@ export function formatActionReport(report, format) {
291
295
  const dropped = report.buckets.DROPPED;
292
296
  const allDecisions = report.decisions ?? [];
293
297
  const { structured, legacyPending, legacySettled } = classifyDecisions(allDecisions);
294
- const pendingDecisions = structured.filter((d) => d.outcome === 'pending');
298
+ const pendingDecisions = structured.filter((d) => d.outcome === 'pending' || d.outcome === 'deferred');
295
299
  lines.push(h('SYNTHÈSE'));
296
300
  lines.push(...table(['fait', 'à-faire', 'attendus', 'dropped', 'décisions pending'], [[String(done.length), String(todo.length), String(awaited.length), String(dropped.length), String(pendingDecisions.length)]]));
297
301
  lines.push('');
@@ -657,12 +661,13 @@ const ULID = /[0-9A-HJKMNP-TV-Z]{26}/gu;
657
661
  function redactOwnerText(value) {
658
662
  return value.replace(ULID, 'référence interne');
659
663
  }
660
- function redactOwnerTable(table) {
664
+ export function redactOwnerTable(table) {
661
665
  const ownerColumns = new Set(table.columns.map((column) => column.id));
662
666
  return {
663
667
  ...table,
664
668
  rows: table.rows.map((row) => Object.fromEntries(Object.entries(row).map(([key, value]) => [key, ownerColumns.has(key) ? redactOwnerText(value) : value]))),
665
669
  ...(table.lines === undefined ? {} : { lines: table.lines.map(redactOwnerText) }),
670
+ ...(table.links === undefined ? {} : { links: table.links.map(link => ({ ...link, label: redactOwnerText(link.label) })) }),
666
671
  };
667
672
  }
668
673
  /** `undefined` for an absent/blank body — a bare title is then the HONEST render, not a gap to fill. */
@@ -688,19 +693,44 @@ export const DETERMINISTIC_NEXT_ACTIONS = [
688
693
  *
689
694
  * The renderer's own markers are counted as `uninstructed`, never as violations: they are the honest
690
695
  * statement that the work is still owed, which is exactly what the report must say until it is done.
696
+ * An `investigated` row without action text AND origin is uncertified — neither a plain string nor
697
+ * missing audit metadata can certify an investigated action — so it still counts as owed.
691
698
  */
692
- export function auditNextActions(values, gateClauses) {
693
- const marker = new Set(DETERMINISTIC_NEXT_ACTIONS);
694
- const substantive = values.filter((value) => !marker.has(value));
699
+ export function auditNextActions(descriptors) {
700
+ const certified = descriptors.filter((descriptor) => descriptor.instruction === 'investigated' &&
701
+ descriptor.action !== undefined &&
702
+ descriptor.actionOrigin !== undefined);
695
703
  const counts = new Map();
696
- for (const value of substantive)
697
- counts.set(value, (counts.get(value) ?? 0) + 1);
704
+ for (const descriptor of certified)
705
+ counts.set(descriptor.action, (counts.get(descriptor.action) ?? 0) + 1);
698
706
  const repeated = [...counts.entries()].filter(([, n]) => n > 2).map(([value]) => value);
699
- const bare = (value) => value.replace(/^(?:action|engagement|décision) \([^)]*\)\s*:\s*/u, '');
700
- const gates = new Set(gateClauses);
701
- const hits = substantive.filter((value) => gates.has(bare(value)));
702
- const uninstructed = values.filter((value) => value === NEXT_ACTION_TO_INSTRUCT).length;
703
- return { uninstructed, repeated, gateClauses: [...new Set(hits)], ok: repeated.length === 0 && hits.length === 0 };
707
+ const hits = certified.filter((descriptor) => descriptor.actionOrigin === 'gate-class');
708
+ const uninstructed = descriptors.length - certified.length - descriptors.filter((descriptor) => descriptor.instruction === 'not-instructed' ||
709
+ descriptor.instruction === 'structure-dossier' ||
710
+ descriptor.instruction === 'none-owed').length;
711
+ return { uninstructed, repeated, gateClauses: [...new Set(hits.map((descriptor) => descriptor.action))], ok: repeated.length === 0 && hits.length === 0 };
712
+ }
713
+ /**
714
+ * Amendment D10 — describe rendered À-FAIRE rows as audit descriptors. The
715
+ * serving layer supplies instruction/origin metadata. Missing metadata owes
716
+ * investigation regardless of the text's language; no prose is classified.
717
+ */
718
+ export function describeRowNextActions(rows) {
719
+ return rows.map((row) => {
720
+ const focus = row['focus'] === 'true';
721
+ const next = row['nextAction'] ?? '';
722
+ const value = row['instruction'];
723
+ const instruction = value === 'investigated' || value === 'not-instructed' || value === 'structure-dossier' || value === 'none-owed'
724
+ ? value : 'to-instruct';
725
+ const origin = row['actionOrigin'];
726
+ return {
727
+ focus,
728
+ instruction,
729
+ ...(instruction === 'investigated' ? { action: next } : {}),
730
+ ...(origin === 'investigated' || origin === 'gate-class' ? { actionOrigin: origin } : {}),
731
+ ...(row['gateSteps'] !== undefined ? { gateSteps: row['gateSteps'].split(',').filter(Boolean) } : {}),
732
+ };
733
+ });
704
734
  }
705
735
  /** `2026-07-29T11:02:03.000Z` → `2026-07-29`. UTC, so the header is TZ-independent and reproducible. */
706
736
  function isoDate(value) {
@@ -713,6 +743,18 @@ function isoDate(value) {
713
743
  export function reportPeriod(meta) {
714
744
  if (meta.periodWindow !== undefined) {
715
745
  const period = meta.periodWindow;
746
+ // Amendment D4 — rolling windows are instant bounds: resolved AND printed
747
+ // with time and offset (no calendar rounding). Calendar selectors keep
748
+ // their pinned date labels.
749
+ if (period.requested === 'last-week' || period.requested === 'last-day') {
750
+ const span = period.requested === 'last-week' ? '7 derniers jours glissants' : '24 dernières heures glissantes';
751
+ const from = isoDate(period.from);
752
+ const to = isoDate(period.to);
753
+ const label = period.from === undefined || period.to === undefined
754
+ ? 'période : journal vide (aucun événement enregistré)'
755
+ : `période : ${period.from} → ${period.to} (${span} ; ${period.eventsInWindow}/${period.eventsTotal} événements)`;
756
+ return { ...(from !== undefined ? { from } : {}), ...(to !== undefined ? { to } : {}), toSource: 'unknown', label };
757
+ }
716
758
  const from = isoDate(period.from);
717
759
  const to = isoDate(period.to);
718
760
  if (period.requested === null) {
@@ -788,6 +830,48 @@ function compactRefs(refs) {
788
830
  function shellArgument(value) {
789
831
  return /^[A-Za-z0-9_./:-]+$/u.test(value) ? value : `'${value.replace(/'/gu, "'\"'\"'")}'`;
790
832
  }
833
+ /** Named period selectors rebindable with a single `--period` flag. */
834
+ const NAMED_PERIODS = ['today', 'week', 'month', 'all', 'last-week', 'last-day'];
835
+ /**
836
+ * Amendment D4/D13 — the resolution command bound to the exact rendering
837
+ * context: scope, period and sub-WP expansion travel with the handle, so a
838
+ * reply quoting a handle without its context is refused rather than
839
+ * mis-resolved. No context ⇒ the established bare command, byte-identical.
840
+ */
841
+ export function handleCommandFor(meta) {
842
+ const parts = ['track report'];
843
+ if (meta.scopeProjection !== undefined)
844
+ parts.push(`--scope ${shellArgument(meta.scopeProjection.selector)}`);
845
+ const requested = meta.periodWindow?.requested ?? null;
846
+ if (requested !== null) {
847
+ if (NAMED_PERIODS.includes(requested)) {
848
+ parts.push(`--period ${requested}`);
849
+ }
850
+ else {
851
+ const [since, until] = requested.split('..');
852
+ // Freeze symbolic commit bounds so moving HEAD cannot reassign a handle.
853
+ parts.push(`--since ${shellArgument(meta.periodWindow.fromRef ?? since)}`);
854
+ if (until !== undefined)
855
+ parts.push(`--until ${shellArgument(meta.periodWindow.toRef ?? until)}`);
856
+ }
857
+ }
858
+ if (meta.subWp === true)
859
+ parts.push('--sub-wp');
860
+ const clock = meta.now ?? meta.periodWindow?.to ?? meta.logTo;
861
+ if (clock !== undefined)
862
+ parts.push(`--now ${shellArgument(clock)}`);
863
+ if (meta.baselineCommit !== undefined)
864
+ parts.push(`--commit ${shellArgument(meta.baselineCommit)}`);
865
+ if (meta.requireAccepted === true)
866
+ parts.push('--require-accepted');
867
+ if (meta.journalRevision !== undefined) {
868
+ parts.push(`--expect-events ${meta.journalRevision.events}`);
869
+ if (meta.journalRevision.head !== null)
870
+ parts.push(`--expect-head ${shellArgument(meta.journalRevision.head)}`);
871
+ }
872
+ parts.push('--resolve <handle>');
873
+ return parts.join(' ');
874
+ }
791
875
  export function buildWpConductorView(tree, decisions = [], outsideRollup = [], totalScope = 'global', meta = {}) {
792
876
  assertOrderedPeriodWindow(meta);
793
877
  const wpName = (n) => `${n.label} · ${clean(stripWpPrefix(n.title))}`;
@@ -833,12 +917,17 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
833
917
  // cell, or FAIT if it produced something). It leaves the report and is counted among omissions.
834
918
  // 24 — a pending dossier with no stored options cannot be answered either. It is not dressed up as a
835
919
  // choice: it appears in À-FAIRE as the work of making it answerable.
836
- const structuredPending = structuredDecisions.filter((d) => d.outcome === 'pending');
837
- const settledDecisions = decisions.filter((d) => d.outcome !== 'pending');
920
+ // Amendment D12 — a `deferred` dossier is NOT settled: it stays answerable
921
+ // (numbered, listed, resolvable) and states explicitly that its answer is
922
+ // postponed. The withdrawn view's private deferred→pending mapping is gone
923
+ // with that view; the validated path answers the same journal the same way.
924
+ const isAnswerable = (d) => d.outcome === 'pending' || d.outcome === 'deferred';
925
+ const structuredPending = structuredDecisions.filter(isAnswerable);
926
+ const settledDecisions = decisions.filter((d) => !isAnswerable(d));
838
927
  const decisionRef = new Map();
839
928
  structuredPending.forEach((d, i) => decisionRef.set(d.id, `D${i + 1}`));
840
929
  legacyPending.forEach((d, i) => decisionRef.set(d.id, `Q${i + 1}`));
841
- const isPending = new Set(decisions.filter((d) => d.outcome === 'pending').map((d) => d.id));
930
+ const isPending = new Set(decisions.filter(isAnswerable).map((d) => d.id));
842
931
  // ---- handles (criteria 10b/10c) -----------------------------------------------------------------
843
932
  // Handles are POSITIONAL WITHIN THIS REPORT (`[row.item]`), assigned AFTER À-FAIRE is ordered. Leg A
844
933
  // established that no content-derived handle can be stable across runs — ordering, titles and WP
@@ -898,6 +987,7 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
898
987
  attached.push(directive);
899
988
  }
900
989
  const urgencyIndex = new Map(directives.map((d, i) => [d.id, i]));
990
+ const stepByDirectiveId = new Map(directives.map(d => [d.id, d.step.code]));
901
991
  /**
902
992
  * Criterion 7 + 19 — `bloqué` names the ANSWER that unblocks (a D-number) when the gate is a dossier,
903
993
  * and a short gate token otherwise. It renders `—` ONLY when no gate is recorded at all.
@@ -933,6 +1023,31 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
933
1023
  // Machine-only audit properties (NOT declared columns, so no renderer ever prints them): the precise
934
1024
  // gate phrase the short `bloqué` token compacts, kept so nothing is lost from the projection.
935
1025
  const gateDetail = (attached) => [...new Set(attached.map((d) => gatePhraseFr(d.gate)).filter((p) => p !== undefined))].join(' / ');
1026
+ // Amendment D3/D11 — per-item stage/status + strict-WP facts for the two
1027
+ // new columns, through the existing lexicon (the validated renderer stays
1028
+ // French). Codes stay the identity; only the owner-facing cells are
1029
+ // labelled. Without journal context the cells honestly state `—`.
1030
+ const frLabels = resolveStageStatusLabels(meta.lang ?? 'fr').labels;
1031
+ const stageCell = (id, handle) => {
1032
+ const facts = meta.itemFacts?.[id];
1033
+ if (facts === undefined)
1034
+ return `[${handle}] —`;
1035
+ return `[${handle}] ${frLabels.stage[facts.stage]}`;
1036
+ };
1037
+ const statusCell = (id, handle) => {
1038
+ const facts = meta.itemFacts?.[id];
1039
+ if (facts === undefined)
1040
+ return `[${handle}] —`;
1041
+ const health = STATUS_HEALTH[facts.status];
1042
+ const label = frLabels.status[facts.status];
1043
+ return `[${handle}] ${health === undefined ? '—' : health} ${label}`;
1044
+ };
1045
+ // An item with no strict WP root renders the visible machine flag
1046
+ // `outside-wp` — but only when facts are present (unknown ≠ outside).
1047
+ const isOutsideWp = (id) => {
1048
+ const facts = meta.itemFacts?.[id];
1049
+ return facts !== undefined && facts.wpStrictRootId === undefined;
1050
+ };
936
1051
  const wpTodoDrafts = rowNodes
937
1052
  .filter((n) => openLeaves(n).length > 0 || branchOf(n).some((b) => directivesByWpId.has(b.id)))
938
1053
  .map((n) => {
@@ -965,6 +1080,7 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
965
1080
  return {
966
1081
  wp: wpName(n),
967
1082
  progress: pctStr(n.pct),
1083
+ nodeIds: branchOf(n).map((b) => b.id),
968
1084
  items,
969
1085
  blocked: blockedCell(attached),
970
1086
  gatedOnDecision: gated,
@@ -989,6 +1105,7 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
989
1105
  horsWpDrafts.push({
990
1106
  wp: 'hors WP · dossiers à structurer',
991
1107
  progress: 'n/a',
1108
+ nodeIds: [],
992
1109
  // A dossier with no stored options says nothing by its title alone. Its prose context is recorded:
993
1110
  // show it as an EXCERPT — never as options, which is what `unstructured` forbids (criterion 16).
994
1111
  items: toStructure.map((d) => {
@@ -1015,6 +1132,7 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1015
1132
  horsWpDrafts.push({
1016
1133
  wp: 'hors WP · items',
1017
1134
  progress: 'n/a',
1135
+ nodeIds: [],
1018
1136
  items: outsideOpen.map((r) => ({
1019
1137
  id: r.id,
1020
1138
  title: clean(r.title),
@@ -1028,10 +1146,73 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1028
1146
  order: '09998',
1029
1147
  });
1030
1148
  }
1031
- const orderedDrafts = [...wpTodoDrafts, ...horsWpDrafts].sort((a, b) => a.order === b.order ? a.wp.localeCompare(b.wp) : a.order.localeCompare(b.order));
1149
+ // Amendment D9 — withdrawal notices join À-FAIRE as identifiable items
1150
+ // under their actual container/WP. An item already rendered (an AWAITED
1151
+ // withdrawal with a live gate) is NOT duplicated: its status comes from
1152
+ // the shared derivation. Notices never touch legacy bucket/tally rules and
1153
+ // are never counted a second time in active/delivered totals.
1154
+ const containerLabel = (containerId) => {
1155
+ const walk = (nodes) => {
1156
+ for (const node of nodes) {
1157
+ if (node.id === containerId)
1158
+ return node;
1159
+ const found = walk(node.children);
1160
+ if (found !== undefined)
1161
+ return found;
1162
+ }
1163
+ return undefined;
1164
+ };
1165
+ const node = walk(tree);
1166
+ return node === undefined ? undefined : wpName(node);
1167
+ };
1168
+ const noticeDrafts = [];
1169
+ for (const notice of meta.withdrawnNotices ?? []) {
1170
+ const existing = [...wpTodoDrafts, ...horsWpDrafts, ...noticeDrafts].flatMap(draft => draft.items).filter(item => item.id === notice.id);
1171
+ const reason = notice.reason === undefined ? 'retiré — motif non enregistré' : `retiré : ${notice.reason}`;
1172
+ if (existing.length > 0) {
1173
+ for (const item of existing)
1174
+ item.excerpt = reason;
1175
+ continue;
1176
+ }
1177
+ const item = {
1178
+ id: notice.id,
1179
+ title: clean(notice.title),
1180
+ excerpt: reason,
1181
+ };
1182
+ const host = [...wpTodoDrafts, ...horsWpDrafts, ...noticeDrafts].find((draft) => notice.containerId !== undefined && draft.nodeIds.includes(notice.containerId));
1183
+ if (host !== undefined) {
1184
+ host.items.push(item);
1185
+ }
1186
+ else {
1187
+ const refs = notice.dossierIds
1188
+ .map((dossierId) => decisionRef.get(dossierId))
1189
+ .filter((ref) => ref !== undefined);
1190
+ noticeDrafts.push({
1191
+ wp: (notice.containerId !== undefined ? containerLabel(notice.containerId) : undefined) ?? 'hors WP · retraits',
1192
+ progress: 'n/a',
1193
+ nodeIds: [],
1194
+ items: [item],
1195
+ // Criterion 19 — a recorded answerable dossier is a reference, never `—`.
1196
+ blocked: refs.length > 0 ? compactRefs(refs) : NO_GATE,
1197
+ // D9 — no action is owed on a withdrawal; stating so must not imply open work.
1198
+ fixedNextAction: NO_ACTION,
1199
+ gatedOnDecision: false,
1200
+ directiveIds: '',
1201
+ gateDetail: '',
1202
+ gateStep: '',
1203
+ order: '09997',
1204
+ });
1205
+ }
1206
+ }
1207
+ const orderedDrafts = [...wpTodoDrafts, ...horsWpDrafts, ...noticeDrafts].sort((a, b) => a.order === b.order ? a.wp.localeCompare(b.wp) : a.order.localeCompare(b.order));
1032
1208
  // Handles are assigned HERE, once the order is final: `[row.item]`, both 1-based (criterion 10b/10c).
1033
1209
  // `prochaine action` is decided here too, because whether a row is FOCUS depends on that same order
1034
1210
  // (criterion 20: the per-row investigation is bounded to the five rows the ordering line names).
1211
+ // Amendment D3/D11 — the two new columns annotate identifiable tracked
1212
+ // items: one stage/status line per item, handle-prefixed like the `à faire`
1213
+ // lines so the mapping survives wrapping; `outside-wp` flags strict
1214
+ // non-attachment in the item line itself.
1215
+ const outsideIds = new Set();
1035
1216
  const orderedTodo = orderedDrafts.map((draft, rowIndex) => {
1036
1217
  const cells = draft.items.map((item, itemIndex) => {
1037
1218
  const handle = `${rowIndex + 1}.${itemIndex + 1}`;
@@ -1043,24 +1224,38 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1043
1224
  // Criterion 27 — one idea per line: the item on its line, and its recorded excerpt as a
1044
1225
  // SUBORDINATE clause on its own, never a paragraph appended to the title.
1045
1226
  const note = item.note === undefined ? '' : ` (${item.note})`;
1227
+ const outside = isOutsideWp(item.id) ? ' (outside-wp)' : '';
1228
+ if (outside !== '')
1229
+ outsideIds.add(item.id);
1046
1230
  const excerpt = item.excerpt === undefined ? '' : `\n↳ extrait : ${item.excerpt}`;
1047
- return `[${handle}] ${item.title}${note}${excerpt}`;
1231
+ const source = meta.itemFacts?.[item.id]?.requestSource;
1232
+ const request = source?.provenance === 'demand-raw' ? `\n↳ source (demand-raw): ${source.text}` : '';
1233
+ return `[${handle}] ${item.title}${note}${outside}${excerpt}${request}`;
1048
1234
  });
1235
+ const stageLines = draft.items.map((item, itemIndex) => stageCell(item.id, `${rowIndex + 1}.${itemIndex + 1}`));
1236
+ const statusLines = draft.items.map((item, itemIndex) => statusCell(item.id, `${rowIndex + 1}.${itemIndex + 1}`));
1049
1237
  const nextAction = draft.fixedNextAction ??
1050
1238
  (draft.items.length === 0
1051
1239
  ? NO_ACTION
1052
1240
  : rowIndex < FOCUS_ROWS
1053
1241
  ? NEXT_ACTION_TO_INSTRUCT
1054
1242
  : NEXT_ACTION_NOT_INSTRUCTED);
1243
+ const instruction = draft.fixedNextAction !== undefined
1244
+ ? (draft.gatedOnDecision || draft.items.length === 0 || draft.fixedNextAction === NO_ACTION ? 'none-owed' : 'structure-dossier')
1245
+ : draft.items.length === 0 ? 'none-owed' : rowIndex < FOCUS_ROWS ? 'to-instruct' : 'not-instructed';
1055
1246
  return {
1056
1247
  wp: draft.wp,
1057
1248
  progress: draft.progress,
1249
+ stage: stageLines.join('\n'),
1250
+ status: statusLines.join('\n'),
1058
1251
  todo: cells.join('\n'),
1059
1252
  blocked: draft.blocked,
1060
1253
  nextAction,
1254
+ instruction,
1061
1255
  directiveIds: draft.directiveIds,
1062
1256
  gateDetail: draft.gateDetail,
1063
1257
  gateStep: draft.gateStep,
1258
+ gateSteps: [...new Set(draft.directiveIds.split(',').flatMap(id => stepByDirectiveId.get(id) ?? []))].join(','),
1064
1259
  focus: rowIndex < FOCUS_ROWS ? 'true' : 'false',
1065
1260
  };
1066
1261
  });
@@ -1069,7 +1264,7 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1069
1264
  }
1070
1265
  const todoRows = orderedTodo.length > 0
1071
1266
  ? orderedTodo
1072
- : [{ wp: '—', progress: 'n/a', todo: 'aucun WP ouvert', blocked: NO_GATE, nextAction: NO_ACTION, directiveIds: '' }];
1267
+ : [{ wp: '—', progress: 'n/a', stage: '—', status: '—', todo: 'aucun WP ouvert', blocked: NO_GATE, nextAction: NO_ACTION, instruction: 'none-owed', directiveIds: '' }];
1073
1268
  // ---- DÉCISIONS ----------------------------------------------------------------------------------
1074
1269
  // Criterion 23 — pending, answerable dossiers ONLY. Nothing else.
1075
1270
  const decisionRows = [];
@@ -1098,7 +1293,9 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1098
1293
  let preco = precoLines.join('\n');
1099
1294
  if (preco.trim() === '')
1100
1295
  preco = '—';
1101
- decisionRows.push({ n: ref, subject: shortDecisionSubject(d.title), alternatives, preco });
1296
+ // Amendment D12 — whether an answer is needed now is stated explicitly.
1297
+ const deferredMark = d.outcome === 'deferred' ? ' (reporté — réponse ajournée, pas abandonnée)' : '';
1298
+ decisionRows.push({ n: ref, subject: `${shortDecisionSubject(d.title)}${deferredMark}`, alternatives, preco });
1102
1299
  }
1103
1300
  if (decisionRows.length === 0) {
1104
1301
  decisionRows.push({
@@ -1161,6 +1358,8 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1161
1358
  label: shortDecisionSubject(d.title),
1162
1359
  reason: 'décision déjà tranchée (visible dans bloqué ou FAIT, plus rien à y répondre)',
1163
1360
  })),
1361
+ // Amendment D9 — withdrawals left out of the served tables stay declared, each with its reason.
1362
+ ...(meta.withdrawnOmitted ?? []),
1164
1363
  ];
1165
1364
  // ---- coverage (criteria 17/18) --------------------------------------------------------------------
1166
1365
  // 17 — the report STATES both counts, so omission is a declared act rather than a silent one. Both
@@ -1170,12 +1369,17 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1170
1369
  // structurally in the rendered lists above, whatever the compression ratio.
1171
1370
  // An unscoped directive always TARGETS a dossier already counted in `decisions`, so counting it again
1172
1371
  // would inflate the denominator against itself.
1173
- const projectedRows = wpNodes.length + outsideRollup.length + decisions.length;
1372
+ // Amendment D9/D11 — the explicit additions live INSIDE the legacy
1373
+ // equation (`rendered = projected − omitted` stays true: notice rows are
1374
+ // rendered, withdrawal omissions are omissions) and stay separately visible
1375
+ // in the line (`hors WP` count, per-reason omission detail).
1376
+ const projectedRows = wpNodes.length + outsideRollup.length + decisions.length + noticeDrafts.length + (meta.withdrawnOmitted ?? []).length;
1174
1377
  const coverage = {
1175
1378
  projected: projectedRows,
1176
1379
  rendered: projectedRows - omitted.length,
1177
1380
  omitted,
1178
1381
  aggregated,
1382
+ ...(outsideIds.size > 0 ? { outsideWp: outsideIds.size } : {}),
1179
1383
  };
1180
1384
  const header = {
1181
1385
  scope: totalScope,
@@ -1197,9 +1401,7 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1197
1401
  ]),
1198
1402
  ],
1199
1403
  coverage,
1200
- handleCommand: meta.scopeProjection === undefined
1201
- ? 'track report --resolve <handle>'
1202
- : `track report --scope ${shellArgument(meta.scopeProjection.selector)} --resolve <handle>`,
1404
+ handleCommand: handleCommandFor(meta),
1203
1405
  };
1204
1406
  const tables = [
1205
1407
  {
@@ -1218,6 +1420,8 @@ export function buildWpConductorView(tree, decisions = [], outsideRollup = [], t
1218
1420
  columns: [
1219
1421
  { id: 'wp', label: 'WP' },
1220
1422
  { id: 'progress', label: 'av.' },
1423
+ { id: 'stage', label: 'étape' },
1424
+ { id: 'status', label: 'statut' },
1221
1425
  { id: 'todo', label: 'à faire' },
1222
1426
  { id: 'blocked', label: 'bloqué' },
1223
1427
  { id: 'nextAction', label: 'prochaine action' },
@@ -1276,7 +1480,9 @@ export function coverageLine(coverage) {
1276
1480
  const merged = coverage.aggregated.length > 0
1277
1481
  ? ` · ${coverage.aggregated.length} sous-WP agrégés dans leur parent`
1278
1482
  : '';
1279
- const head = `couverture : ${coverage.projected} lignes projetées · ${coverage.rendered} rendues${merged}`;
1483
+ // Amendment D11 — strict-WP orphans are counted in the header coverage line.
1484
+ const outside = (coverage.outsideWp ?? 0) > 0 ? ` · ${coverage.outsideWp} hors WP (outside-wp)` : '';
1485
+ const head = `couverture : ${coverage.projected} lignes projetées · ${coverage.rendered} rendues${merged}${outside}`;
1280
1486
  if (coverage.omitted.length === 0)
1281
1487
  return `${head} · aucune omission`;
1282
1488
  const byReason = new Map();
@@ -1321,7 +1527,7 @@ export function resolutionLines(view) {
1321
1527
  lines.push('(aucun handle émis)');
1322
1528
  return lines;
1323
1529
  }
1324
- function renderReportView(view, format) {
1530
+ export function renderReportView(view, format) {
1325
1531
  assertReportFormat(format);
1326
1532
  if (format === 'json')
1327
1533
  return JSON.stringify(view, null, 2) + '\n';
@@ -1337,6 +1543,14 @@ function renderReportView(view, format) {
1337
1543
  // never a raw user title, so there is nothing to escape and nothing to inject.
1338
1544
  lines.push(...(section.lines ?? []));
1339
1545
  }
1546
+ else if (section.render === 'pipe') {
1547
+ lines.push(...(section.lines ?? []), '', `| ${section.columns.map(c => c.label).join(' | ')} |`, `| ${section.columns.map(() => '---').join(' | ')} |`, ...section.rows.map((row, index) => `| ${section.columns.map(c => {
1548
+ const text = esc(row[c.id] ?? '').replace(/\n/gu, ' ');
1549
+ const links = (section.links ?? []).filter(link => link.row === index && link.column === c.id).map(link => reportCellLink(link.label, link.destination, format));
1550
+ const cell = [text, ...links].join(' ');
1551
+ return format === 'md' ? cell : cell.replace(/\|/gu, '\\|');
1552
+ }).join(' | ')} |`));
1553
+ }
1340
1554
  else if (section.render === 'drawn') {
1341
1555
  // The box-drawn table is emitted verbatim; `md` fences it so the alignment survives.
1342
1556
  const drawn = drawTable(section.columns.map((c) => c.label), section.rows.map((row) => section.columns.map((c) => clean0(row[c.id] ?? ''))), DECISION_CAPS, [false, false, false, true]);
@@ -1363,6 +1577,16 @@ function renderReportView(view, format) {
1363
1577
  lines.push(resolutionFence);
1364
1578
  return lines.join('\n').trimEnd() + '\n';
1365
1579
  }
1580
+ function reportCellLink(label, ref, format) {
1581
+ const trimmed = ref.trim();
1582
+ if (format !== 'md' || /^(?!https?:)[a-z][a-z\d+.-]*:/iu.test(trimmed)) {
1583
+ return `${displayCell(label, format)} : ${displayCell(redactOwnerText(cleanDisplayText(trimmed)), format)}`;
1584
+ }
1585
+ // Preserve valid percent escapes, encoding raw bytes and Markdown destination delimiters once.
1586
+ const destination = trimmed.split(/(%[a-f\d]{2})/giu).map((part, index) => index % 2 === 1 ? part : encodeURI(part))
1587
+ .join('').replace(/[<>()|\\]/gu, c => `%${c.charCodeAt(0).toString(16)}`);
1588
+ return `[${displayCell(label, format)}](${destination})`;
1589
+ }
1366
1590
  /**
1367
1591
  * A fence long enough to contain `lines` (CommonMark: an opening fence must be longer than any backtick
1368
1592
  * run inside it). Without this, a single item title carrying ``` would close the fence early and let the