@sentropic/track 0.98.10 → 0.98.11-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -6
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +136 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/resolve.d.ts.map +1 -1
- package/dist/cli/resolve.js +9 -0
- package/dist/cli/resolve.js.map +1 -1
- package/dist/events/types.d.ts +1 -1
- package/dist/events/types.d.ts.map +1 -1
- package/dist/events/types.js +5 -0
- package/dist/events/types.js.map +1 -1
- package/dist/focus-vendor/cli/index.d.ts +1 -1
- package/dist/graph-export.d.ts +19 -0
- package/dist/graph-export.d.ts.map +1 -1
- package/dist/graph-export.js +53 -0
- package/dist/graph-export.js.map +1 -1
- package/dist/model/blocker.d.ts +2 -0
- package/dist/model/blocker.d.ts.map +1 -1
- package/dist/model/blocker.js.map +1 -1
- package/dist/model/decision.d.ts +4 -0
- package/dist/model/decision.d.ts.map +1 -1
- package/dist/model/decision.js.map +1 -1
- package/dist/model/demand.d.ts +15 -0
- package/dist/model/demand.d.ts.map +1 -1
- package/dist/model/demand.js.map +1 -1
- package/dist/model/item.d.ts +3 -1
- package/dist/model/item.d.ts.map +1 -1
- package/dist/model/item.js.map +1 -1
- package/dist/model/report-status.d.ts +124 -21
- package/dist/model/report-status.d.ts.map +1 -1
- package/dist/model/report-status.js +372 -38
- package/dist/model/report-status.js.map +1 -1
- package/dist/read/commands.d.ts +6 -0
- package/dist/read/commands.d.ts.map +1 -1
- package/dist/read/commands.js +19 -0
- package/dist/read/commands.js.map +1 -1
- package/dist/read/contract.d.ts +8 -0
- package/dist/read/contract.d.ts.map +1 -1
- package/dist/read/contract.js +21 -0
- package/dist/read/contract.js.map +1 -1
- package/dist/read/index.d.ts +2 -2
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +1 -1
- package/dist/read/index.js.map +1 -1
- package/dist/report/audit.d.ts +2 -19
- package/dist/report/audit.d.ts.map +1 -1
- package/dist/report/audit.js +9 -26
- package/dist/report/audit.js.map +1 -1
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +2 -0
- package/dist/report/index.js.map +1 -1
- package/dist/report/owner-table.d.ts +142 -0
- package/dist/report/owner-table.d.ts.map +1 -0
- package/dist/report/owner-table.js +1586 -0
- package/dist/report/owner-table.js.map +1 -0
- package/dist/report/stage-status-lexicon.d.ts.map +1 -1
- package/dist/report/stage-status-lexicon.js +61 -37
- package/dist/report/stage-status-lexicon.js.map +1 -1
- package/dist/report/stage-status.d.ts +20 -9
- package/dist/report/stage-status.d.ts.map +1 -1
- package/dist/report/stage-status.js +211 -85
- package/dist/report/stage-status.js.map +1 -1
- package/dist/report/velocity-eta.d.ts +81 -0
- package/dist/report/velocity-eta.d.ts.map +1 -0
- package/dist/report/velocity-eta.js +217 -0
- package/dist/report/velocity-eta.js.map +1 -0
- package/dist/state/fold.d.ts +11 -0
- package/dist/state/fold.d.ts.map +1 -1
- package/dist/state/fold.js +437 -7
- package/dist/state/fold.js.map +1 -1
- package/dist/track.d.ts +53 -1
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +297 -4
- package/dist/track.js.map +1 -1
- package/dist/workspace-id.d.ts.map +1 -1
- package/dist/workspace-id.js +5 -0
- package/dist/workspace-id.js.map +1 -1
- package/package.json +1 -1
- package/registry/entries.v1.json +1 -1
|
@@ -0,0 +1,1586 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { isSettled } from '../model/decision.js';
|
|
4
|
+
import { DomainError } from '../model/item.js';
|
|
5
|
+
import { isValidMeasuredVelocityProvenance, REPORT_STAGES, REPORT_STATUSES, } from '../model/report-status.js';
|
|
6
|
+
import { effectiveOpenBlockersForItem } from './blocker-status.js';
|
|
7
|
+
import { cleanDisplayText, shortDecisionSubject } from './format.js';
|
|
8
|
+
import { deriveItemStageStatus, STAGE_RANK, } from './stage-status.js';
|
|
9
|
+
import { evaluateEtaDeadline, qualifyVelocityEta, } from './velocity-eta.js';
|
|
10
|
+
export const OWNER_TABLE_HEADERS = [
|
|
11
|
+
'#',
|
|
12
|
+
'Statut',
|
|
13
|
+
'Étape',
|
|
14
|
+
'ETA (étape cible)',
|
|
15
|
+
'Ta demande',
|
|
16
|
+
'Fait',
|
|
17
|
+
'À faire (qui)',
|
|
18
|
+
'Décision',
|
|
19
|
+
];
|
|
20
|
+
const BANNED_STEMS = [
|
|
21
|
+
Buffer.from([0x68, 0x6f, 0x6e, 0x6e, 0xc3, 0xaa, 0x74]).toString('utf8'),
|
|
22
|
+
Buffer.from([0x68, 0x6f, 0x6e, 0x6e, 0x65, 0x74]).toString('utf8'),
|
|
23
|
+
Buffer.from([0x68, 0x6f, 0x6e, 0x65, 0x73, 0x74, 0x6c, 0x79]).toString('utf8'),
|
|
24
|
+
];
|
|
25
|
+
function resolveOwnerTablePolicy(options, view) {
|
|
26
|
+
const direct = options?.policy ?? view?.policy;
|
|
27
|
+
if (direct !== undefined) {
|
|
28
|
+
return { policy: direct };
|
|
29
|
+
}
|
|
30
|
+
const rawPath = options?.policyPath ??
|
|
31
|
+
view?.policyPath ??
|
|
32
|
+
process.env['TRACK_OWNER_POLICY_FILE'] ??
|
|
33
|
+
process.env['TRACK_OWNER_REPORT_POLICY'];
|
|
34
|
+
if (rawPath === undefined || rawPath.trim() === '') {
|
|
35
|
+
const defaultLocalPolicy = options?.defaultPolicyPath ?? view?.defaultPolicyPath;
|
|
36
|
+
if (defaultLocalPolicy !== undefined &&
|
|
37
|
+
defaultLocalPolicy.trim() !== '' &&
|
|
38
|
+
existsSync(defaultLocalPolicy.trim())) {
|
|
39
|
+
const parsed = JSON.parse(readFileSync(defaultLocalPolicy.trim(), 'utf8'));
|
|
40
|
+
return { policy: parsed };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
notice: 'Private-name gate skipped: no unversioned local policy file configured (set --policy <path> or TRACK_OWNER_POLICY_FILE).',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const trimmed = rawPath.trim();
|
|
47
|
+
if (!existsSync(trimmed)) {
|
|
48
|
+
return {
|
|
49
|
+
notice: `Private-name gate skipped: local policy file not found at ${trimmed}.`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const parsed = JSON.parse(readFileSync(trimmed, 'utf8'));
|
|
53
|
+
return { policy: parsed };
|
|
54
|
+
}
|
|
55
|
+
function sha256Hex(input) {
|
|
56
|
+
return createHash('sha256').update(input, 'utf8').digest('hex');
|
|
57
|
+
}
|
|
58
|
+
function matchesPrivateTermPolicy(text, policy) {
|
|
59
|
+
if (policy?.privateTermHashes === undefined || policy.privateTermHashes.length === 0) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const nfcLower = text.normalize('NFC').toLowerCase();
|
|
63
|
+
const nfdStripped = text.normalize('NFD').replace(/\p{M}+/gu, '').toLowerCase();
|
|
64
|
+
const tokens = new Set();
|
|
65
|
+
for (const variant of [nfcLower, nfdStripped]) {
|
|
66
|
+
for (const tok of variant.split(/[^\p{L}\p{N}_-]+/u)) {
|
|
67
|
+
if (tok.length > 0)
|
|
68
|
+
tokens.add(tok);
|
|
69
|
+
}
|
|
70
|
+
for (const tok of variant.split(/[^\p{L}\p{N}]+/u)) {
|
|
71
|
+
if (tok.length > 0)
|
|
72
|
+
tokens.add(tok);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (tokens.size === 0)
|
|
76
|
+
return false;
|
|
77
|
+
const defaultSalt = policy.salt ?? '';
|
|
78
|
+
for (const entry of policy.privateTermHashes) {
|
|
79
|
+
let salt = defaultSalt;
|
|
80
|
+
let targetHash;
|
|
81
|
+
if (typeof entry === 'string') {
|
|
82
|
+
const colonIdx = entry.lastIndexOf(':');
|
|
83
|
+
if (colonIdx > 0 && /^[0-9a-f]{64}$/iu.test(entry.slice(colonIdx + 1))) {
|
|
84
|
+
salt = entry.slice(0, colonIdx);
|
|
85
|
+
targetHash = entry.slice(colonIdx + 1).toLowerCase();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
targetHash = entry.toLowerCase();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
salt = entry.salt ?? defaultSalt;
|
|
93
|
+
targetHash = entry.hash.toLowerCase();
|
|
94
|
+
}
|
|
95
|
+
for (const tok of tokens) {
|
|
96
|
+
if (salt !== '') {
|
|
97
|
+
if (sha256Hex(`${salt}:${tok}`) === targetHash || sha256Hex(`${salt}${tok}`) === targetHash) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (sha256Hex(tok) === targetHash) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const COMMIT_HASH_RE = /\b(?=[0-9a-f]{7,40}\b)(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\b/iu;
|
|
109
|
+
const ULID_RE = /\b[0-9A-HJKMNP-TV-Z]{26}\b/u;
|
|
110
|
+
const JARGON_RE = /\b(?:worktrees?|subagents?|bwrap|tmux|pty-host|events\.jsonl|aggregateId|specStatus|realizedCommit|lanes?|shards?)\b|(?:^|[^\p{L}\p{N}])claude:[a-z0-9_.:-]+/iu;
|
|
111
|
+
const WP_INTERNAL_RE = /\bWP-?\d+\b/u;
|
|
112
|
+
const PRIVATE_PATH_RE = new RegExp(String.raw `(?:^|[\s(])/(?:home|Users|tmp|var/folders)/[^\s)]+`, 'iu');
|
|
113
|
+
const PRIVATE_DIGEST_RE = /\bsha256[:=][0-9a-f]{8,}\b/iu;
|
|
114
|
+
export function formatOwnerStatusCell(row) {
|
|
115
|
+
if (row.kind === 'demand-title' || row.status === undefined) {
|
|
116
|
+
return '—';
|
|
117
|
+
}
|
|
118
|
+
switch (row.status) {
|
|
119
|
+
case 'on-track':
|
|
120
|
+
return '🔵 sur la voie';
|
|
121
|
+
case 'waiting':
|
|
122
|
+
return '🟡 en attente';
|
|
123
|
+
case 'unforeseen':
|
|
124
|
+
return '🟠 dérive';
|
|
125
|
+
case 'blocked':
|
|
126
|
+
return '🔴 bloqué';
|
|
127
|
+
case 'not-started':
|
|
128
|
+
return row.pausedByOwner === true ? '⚪ en pause' : '⚪ pas commencé';
|
|
129
|
+
case 'done':
|
|
130
|
+
return '✅ fait';
|
|
131
|
+
case 'withdrawn':
|
|
132
|
+
return '⚫ retiré';
|
|
133
|
+
case 'not-qualified':
|
|
134
|
+
return '— sans témoin';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export function formatOwnerStageCell(row) {
|
|
138
|
+
if (row.stage === undefined || row.stage === '—') {
|
|
139
|
+
return '—';
|
|
140
|
+
}
|
|
141
|
+
if (row.requestedStage !== undefined && row.requestedStage === row.stage) {
|
|
142
|
+
return `${row.stage} (demandée)`;
|
|
143
|
+
}
|
|
144
|
+
return row.stage;
|
|
145
|
+
}
|
|
146
|
+
export function formatOwnerEtaEntry(eta) {
|
|
147
|
+
const target = eta.targetLabel !== undefined && eta.targetLabel.trim() !== ''
|
|
148
|
+
? `${eta.targetStage} (${eta.targetLabel.trim()})`
|
|
149
|
+
: eta.targetStage;
|
|
150
|
+
const sourceText = eta.source === 'measured'
|
|
151
|
+
? 'mesuré'
|
|
152
|
+
: eta.source === 'committed'
|
|
153
|
+
? `engagé : ${eta.by ?? ''}`
|
|
154
|
+
: 'inconnu';
|
|
155
|
+
if (eta.slip !== undefined) {
|
|
156
|
+
if (eta.when === '—' || eta.when === eta.slip.initialWhen) {
|
|
157
|
+
return `${target} → ${eta.when} (dépassé : ${eta.slip.initialWhen}, ${sourceText})`;
|
|
158
|
+
}
|
|
159
|
+
return `${target} → ${eta.when} (${sourceText}, glissement depuis ${eta.slip.initialWhen})`;
|
|
160
|
+
}
|
|
161
|
+
return `${target} → ${eta.when} (${sourceText})`;
|
|
162
|
+
}
|
|
163
|
+
export function formatOwnerEtaCell(etas) {
|
|
164
|
+
if (etas.length === 0)
|
|
165
|
+
return '—';
|
|
166
|
+
return etas.map(formatOwnerEtaEntry).join(' · ');
|
|
167
|
+
}
|
|
168
|
+
export function formatOwnerDecisionCell(row) {
|
|
169
|
+
if (row.decisionRefs.length === 0)
|
|
170
|
+
return '—';
|
|
171
|
+
if (row.status === 'withdrawn') {
|
|
172
|
+
return row.decisionRefs.map((ref) => `${ref} (décision sans objet)`).join(' · ');
|
|
173
|
+
}
|
|
174
|
+
const sansObjetSet = new Set(row.sansObjetDecisionRefs ?? []);
|
|
175
|
+
const blockingSet = row.blockingDecisionRefs !== undefined
|
|
176
|
+
? new Set(row.blockingDecisionRefs)
|
|
177
|
+
: row.decisionBlocking === true
|
|
178
|
+
? new Set(row.decisionRefs)
|
|
179
|
+
: new Set();
|
|
180
|
+
return row.decisionRefs
|
|
181
|
+
.map((ref) => {
|
|
182
|
+
if (sansObjetSet.has(ref))
|
|
183
|
+
return `${ref} (décision sans objet)`;
|
|
184
|
+
return blockingSet.has(ref) ? `🚩 ${ref} bloquante` : ref;
|
|
185
|
+
})
|
|
186
|
+
.join(' · ');
|
|
187
|
+
}
|
|
188
|
+
function checkTextGates(text, context, violations, policy) {
|
|
189
|
+
if (COMMIT_HASH_RE.test(text)) {
|
|
190
|
+
violations.push({
|
|
191
|
+
code: 'internal-jargon',
|
|
192
|
+
...(context.rowNum !== undefined ? { rowNum: context.rowNum } : {}),
|
|
193
|
+
...(context.decisionRef !== undefined ? { decisionRef: context.decisionRef } : {}),
|
|
194
|
+
message: `${context.field} contains a commit hash`,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (ULID_RE.test(text)) {
|
|
198
|
+
violations.push({
|
|
199
|
+
code: 'internal-jargon',
|
|
200
|
+
...(context.rowNum !== undefined ? { rowNum: context.rowNum } : {}),
|
|
201
|
+
...(context.decisionRef !== undefined ? { decisionRef: context.decisionRef } : {}),
|
|
202
|
+
message: `${context.field} contains an internal ULID`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const checkWpToken = context.field.includes('"Fait"') || context.field.includes('"À faire (qui)"');
|
|
206
|
+
if (JARGON_RE.test(text) || (checkWpToken && WP_INTERNAL_RE.test(text))) {
|
|
207
|
+
violations.push({
|
|
208
|
+
code: 'internal-jargon',
|
|
209
|
+
...(context.rowNum !== undefined ? { rowNum: context.rowNum } : {}),
|
|
210
|
+
...(context.decisionRef !== undefined ? { decisionRef: context.decisionRef } : {}),
|
|
211
|
+
message: `${context.field} contains internal jargon`,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
const nfcLower = text.normalize('NFC').toLowerCase();
|
|
215
|
+
const nfdStripped = text.normalize('NFD').replace(/\p{M}+/gu, '').toLowerCase();
|
|
216
|
+
const hasBannedStem = BANNED_STEMS.some((stem) => nfcLower.includes(stem) || nfdStripped.includes(stem));
|
|
217
|
+
const hasPrivateTerm = matchesPrivateTermPolicy(text, policy);
|
|
218
|
+
if (hasBannedStem || hasPrivateTerm || PRIVATE_PATH_RE.test(text) || PRIVATE_DIGEST_RE.test(text)) {
|
|
219
|
+
violations.push({
|
|
220
|
+
code: 'banned-word',
|
|
221
|
+
...(context.rowNum !== undefined ? { rowNum: context.rowNum } : {}),
|
|
222
|
+
...(context.decisionRef !== undefined ? { decisionRef: context.decisionRef } : {}),
|
|
223
|
+
message: `${context.field} contains a banned word, private term, private path, or private digest`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function isBlankOrDash(value) {
|
|
228
|
+
if (value === undefined)
|
|
229
|
+
return true;
|
|
230
|
+
const trimmed = value.trim();
|
|
231
|
+
return trimmed === '' || trimmed === '—' || trimmed === '-';
|
|
232
|
+
}
|
|
233
|
+
function auditRowEtaEntries(row, violations, policy, requireMissedSlipStatus) {
|
|
234
|
+
if (row.etas.length > 2) {
|
|
235
|
+
violations.push({
|
|
236
|
+
code: 'invalid-eta',
|
|
237
|
+
rowNum: row.num,
|
|
238
|
+
message: `row #${row.num} carries ${row.etas.length} ETAs (maximum 2 allowed)`,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
for (const eta of row.etas) {
|
|
242
|
+
if (!REPORT_STAGES.includes(eta.targetStage)) {
|
|
243
|
+
violations.push({
|
|
244
|
+
code: 'invalid-eta',
|
|
245
|
+
rowNum: row.num,
|
|
246
|
+
message: `row #${row.num} has an ETA without a valid target stage`,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (eta.source !== 'measured' && eta.source !== 'committed' && eta.source !== 'unknown') {
|
|
250
|
+
violations.push({
|
|
251
|
+
code: 'invalid-eta',
|
|
252
|
+
rowNum: row.num,
|
|
253
|
+
message: `row #${row.num} has an ETA without a valid source (measured|committed|unknown)`,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (eta.source === 'committed' && isBlankOrDash(eta.by)) {
|
|
257
|
+
violations.push({
|
|
258
|
+
code: 'invalid-eta',
|
|
259
|
+
rowNum: row.num,
|
|
260
|
+
message: `row #${row.num} has a committed ETA without naming who committed ("by")`,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (eta.source === 'unknown' && !isBlankOrDash(eta.when)) {
|
|
264
|
+
violations.push({
|
|
265
|
+
code: 'invalid-eta',
|
|
266
|
+
rowNum: row.num,
|
|
267
|
+
message: `row #${row.num} has an unknown ETA with a target date (must be "—")`,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (eta.source === 'measured') {
|
|
271
|
+
if (!isValidMeasuredVelocityProvenance(eta.measured) ||
|
|
272
|
+
STAGE_RANK[eta.targetStage] < STAGE_RANK['dev']) {
|
|
273
|
+
violations.push({
|
|
274
|
+
code: 'invalid-eta',
|
|
275
|
+
rowNum: row.num,
|
|
276
|
+
message: `row #${row.num} has a measured ETA without qualified velocity provenance (sampleCount > 0 and matching digests)`,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if ((eta.source === 'measured' || eta.source === 'committed') && isBlankOrDash(eta.when) && eta.slip === undefined) {
|
|
281
|
+
violations.push({
|
|
282
|
+
code: 'invalid-eta',
|
|
283
|
+
rowNum: row.num,
|
|
284
|
+
message: `row #${row.num} has a ${eta.source} ETA without a target date`,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
if (requireMissedSlipStatus &&
|
|
288
|
+
eta.slip !== undefined &&
|
|
289
|
+
row.pausedByOwner !== true &&
|
|
290
|
+
row.status !== 'unforeseen' &&
|
|
291
|
+
row.status !== 'blocked' &&
|
|
292
|
+
row.status !== 'withdrawn') {
|
|
293
|
+
violations.push({
|
|
294
|
+
code: 'invalid-eta',
|
|
295
|
+
rowNum: row.num,
|
|
296
|
+
message: `row #${row.num} has a missed ETA and must be 🟠 dérive (or 🔴 bloqué)`,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (eta.by !== undefined) {
|
|
300
|
+
checkTextGates(eta.by, { rowNum: row.num, field: `row #${row.num} ETA "by"` }, violations, policy);
|
|
301
|
+
}
|
|
302
|
+
if (eta.targetLabel !== undefined) {
|
|
303
|
+
checkTextGates(eta.targetLabel, { rowNum: row.num, field: `row #${row.num} ETA "targetLabel"` }, violations, policy);
|
|
304
|
+
}
|
|
305
|
+
checkTextGates(eta.when, { rowNum: row.num, field: `row #${row.num} ETA "when"` }, violations, policy);
|
|
306
|
+
if (eta.slip?.initialWhen !== undefined) {
|
|
307
|
+
checkTextGates(eta.slip.initialWhen, { rowNum: row.num, field: `row #${row.num} ETA slip "initialWhen"` }, violations, policy);
|
|
308
|
+
}
|
|
309
|
+
if (eta.slip?.reason !== undefined) {
|
|
310
|
+
checkTextGates(eta.slip.reason, { rowNum: row.num, field: `row #${row.num} ETA slip "reason"` }, violations, policy);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Blocking gates on the owner table (Owner Decisions 14/11 & 15/11).
|
|
316
|
+
* The render refuses (`ok === false`) on any violation.
|
|
317
|
+
*/
|
|
318
|
+
export function auditOwnerTable(view, options) {
|
|
319
|
+
const violations = [];
|
|
320
|
+
const { policy, notice } = resolveOwnerTablePolicy(options, view);
|
|
321
|
+
const archivedSet = new Set(view.archivedNumbers);
|
|
322
|
+
const seenNums = new Set();
|
|
323
|
+
let prevTopLevelNum = 0;
|
|
324
|
+
let activeTitleRow;
|
|
325
|
+
let lotCountForActiveTitle = 0;
|
|
326
|
+
for (const row of view.rows) {
|
|
327
|
+
const rowKind = row.kind ?? 'single';
|
|
328
|
+
if (!Number.isInteger(row.num) || row.num < 1) {
|
|
329
|
+
violations.push({
|
|
330
|
+
code: 'missing-row',
|
|
331
|
+
rowNum: row.num,
|
|
332
|
+
message: `row #${String(row.num)} must have a positive integer request number`,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (rowKind === 'lot') {
|
|
336
|
+
if (activeTitleRow === undefined ||
|
|
337
|
+
row.parentDemandId === undefined ||
|
|
338
|
+
row.parentDemandId !== activeTitleRow.id ||
|
|
339
|
+
row.num !== activeTitleRow.num) {
|
|
340
|
+
violations.push({
|
|
341
|
+
code: 'missing-row',
|
|
342
|
+
rowNum: row.num,
|
|
343
|
+
message: `lot row #${row.num} (${row.id}) must immediately follow its parent demand-title row`,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
lotCountForActiveTitle++;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
if (activeTitleRow !== undefined && lotCountForActiveTitle < 2) {
|
|
352
|
+
violations.push({
|
|
353
|
+
code: 'missing-row',
|
|
354
|
+
rowNum: activeTitleRow.num,
|
|
355
|
+
message: `demand-title row #${activeTitleRow.num} must be followed by at least 2 lot rows`,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
if (seenNums.has(row.num)) {
|
|
359
|
+
violations.push({
|
|
360
|
+
code: 'missing-row',
|
|
361
|
+
rowNum: row.num,
|
|
362
|
+
message: `duplicate request number #${row.num}`,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
if (prevTopLevelNum > 0 && row.num <= prevTopLevelNum) {
|
|
366
|
+
violations.push({
|
|
367
|
+
code: 'missing-row',
|
|
368
|
+
rowNum: row.num,
|
|
369
|
+
message: `rows must be in strictly ascending # order`,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
seenNums.add(row.num);
|
|
373
|
+
prevTopLevelNum = row.num;
|
|
374
|
+
if (rowKind === 'demand-title') {
|
|
375
|
+
activeTitleRow = row;
|
|
376
|
+
lotCountForActiveTitle = 0;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
activeTitleRow = undefined;
|
|
380
|
+
lotCountForActiveTitle = 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (activeTitleRow !== undefined && lotCountForActiveTitle < 2) {
|
|
385
|
+
violations.push({
|
|
386
|
+
code: 'missing-row',
|
|
387
|
+
rowNum: activeTitleRow.num,
|
|
388
|
+
message: `demand-title row #${activeTitleRow.num} must be followed by at least 2 lot rows`,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
for (const registered of view.registeredNumbers) {
|
|
392
|
+
if (!seenNums.has(registered) && !archivedSet.has(registered)) {
|
|
393
|
+
violations.push({
|
|
394
|
+
code: 'missing-row',
|
|
395
|
+
rowNum: registered,
|
|
396
|
+
message: `request #${registered} is missing without an owner archive event`,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const allKnownNums = new Set([...seenNums, ...archivedSet]);
|
|
401
|
+
if (allKnownNums.size > 0) {
|
|
402
|
+
const maxNum = Math.max(...allKnownNums);
|
|
403
|
+
for (let n = 1; n <= maxNum; n++) {
|
|
404
|
+
if (!allKnownNums.has(n)) {
|
|
405
|
+
violations.push({
|
|
406
|
+
code: 'missing-row',
|
|
407
|
+
rowNum: n,
|
|
408
|
+
message: `request #${n} is missing from 1..${maxNum} without an owner archive event`,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const decisionMap = new Map();
|
|
414
|
+
for (const d of view.decisions) {
|
|
415
|
+
if (decisionMap.has(d.ref)) {
|
|
416
|
+
violations.push({
|
|
417
|
+
code: 'invalid-decision',
|
|
418
|
+
decisionRef: d.ref,
|
|
419
|
+
message: `duplicate decision ref ${d.ref}`,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
decisionMap.set(d.ref, d);
|
|
423
|
+
}
|
|
424
|
+
const referencedDecisions = new Set();
|
|
425
|
+
for (const row of view.rows) {
|
|
426
|
+
const rowKind = row.kind ?? 'single';
|
|
427
|
+
if (isBlankOrDash(row.request)) {
|
|
428
|
+
violations.push({
|
|
429
|
+
code: 'missing-row',
|
|
430
|
+
rowNum: row.num,
|
|
431
|
+
message: `row #${row.num} is missing its owner request text`,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
else if (rowKind === 'lot' && !/^↳ lot \d+ — \S/u.test(row.request)) {
|
|
435
|
+
violations.push({
|
|
436
|
+
code: 'missing-row',
|
|
437
|
+
rowNum: row.num,
|
|
438
|
+
message: `lot row #${row.num} must be formatted as "↳ lot N — <title>"`,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
if (rowKind === 'demand-title') {
|
|
442
|
+
if (row.status !== undefined) {
|
|
443
|
+
violations.push({
|
|
444
|
+
code: 'missing-witness',
|
|
445
|
+
rowNum: row.num,
|
|
446
|
+
message: `demand-title row #${row.num} must not carry a status (got "${String(row.status)}")`,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (row.stage !== undefined) {
|
|
450
|
+
violations.push({
|
|
451
|
+
code: 'missing-witness',
|
|
452
|
+
rowNum: row.num,
|
|
453
|
+
message: `demand-title row #${row.num} must not carry a stage (got "${String(row.stage)}")`,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (row.done.trim() !== '—') {
|
|
457
|
+
violations.push({
|
|
458
|
+
code: 'missing-witness',
|
|
459
|
+
rowNum: row.num,
|
|
460
|
+
message: `demand-title row #${row.num} must have "—" in "Fait"`,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
if (row.todo.trim() !== '—') {
|
|
464
|
+
violations.push({
|
|
465
|
+
code: 'missing-witness',
|
|
466
|
+
rowNum: row.num,
|
|
467
|
+
message: `demand-title row #${row.num} must have "—" in "À faire (qui)"`,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
if (row.pausedByOwner === true) {
|
|
471
|
+
violations.push({
|
|
472
|
+
code: 'missing-witness',
|
|
473
|
+
rowNum: row.num,
|
|
474
|
+
message: `demand-title row #${row.num} must not carry pausedByOwner`,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (row.hasWitness === true) {
|
|
478
|
+
violations.push({
|
|
479
|
+
code: 'missing-witness',
|
|
480
|
+
rowNum: row.num,
|
|
481
|
+
message: `demand-title row #${row.num} must not carry hasWitness`,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
const expectedTitleBlocking = (row.blockingDecisionRefs?.length ?? 0) > 0 ? true : undefined;
|
|
485
|
+
const hasUnlistedBlockingRef = (row.blockingDecisionRefs ?? []).some((ref) => !row.decisionRefs.includes(ref));
|
|
486
|
+
if (row.decisionBlocking !== expectedTitleBlocking || hasUnlistedBlockingRef) {
|
|
487
|
+
violations.push({
|
|
488
|
+
code: 'invalid-decision',
|
|
489
|
+
rowNum: row.num,
|
|
490
|
+
message: `demand-title row #${row.num} has inconsistent decisionBlocking / blockingDecisionRefs`,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
auditRowEtaEntries(row, violations, policy, false);
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
if (row.status === undefined || !REPORT_STATUSES.includes(row.status)) {
|
|
497
|
+
violations.push({
|
|
498
|
+
code: 'missing-witness',
|
|
499
|
+
rowNum: row.num,
|
|
500
|
+
message: `row #${row.num} has invalid status "${String(row.status)}"`,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (row.stage !== undefined && !REPORT_STAGES.includes(row.stage)) {
|
|
504
|
+
violations.push({
|
|
505
|
+
code: 'missing-witness',
|
|
506
|
+
rowNum: row.num,
|
|
507
|
+
message: `row #${row.num} has invalid stage "${String(row.stage)}"`,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
// Gate: 🔴 without a cause in À faire
|
|
511
|
+
if (row.status === 'blocked') {
|
|
512
|
+
if (isBlankOrDash(row.todo)) {
|
|
513
|
+
violations.push({
|
|
514
|
+
code: 'blocked-without-cause',
|
|
515
|
+
rowNum: row.num,
|
|
516
|
+
message: `row #${row.num} is 🔴 bloqué without a cause in "À faire (qui)"`,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
// Gate: blocking decision must make row 🔴 bloqué with "bloqué par D#" in À faire
|
|
521
|
+
if (row.decisionBlocking === true) {
|
|
522
|
+
if (row.decisionRefs.length === 0) {
|
|
523
|
+
violations.push({
|
|
524
|
+
code: 'invalid-decision',
|
|
525
|
+
rowNum: row.num,
|
|
526
|
+
message: `row #${row.num} is marked decisionBlocking without any D#`,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
if (row.status !== 'blocked') {
|
|
530
|
+
violations.push({
|
|
531
|
+
code: 'blocked-without-cause',
|
|
532
|
+
rowNum: row.num,
|
|
533
|
+
message: `row #${row.num} has a blocking decision (🚩) and must be 🔴 bloqué`,
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
if (!/bloqué par D\d+/u.test(row.todo)) {
|
|
537
|
+
violations.push({
|
|
538
|
+
code: 'blocked-without-cause',
|
|
539
|
+
rowNum: row.num,
|
|
540
|
+
message: `row #${row.num} has a blocking decision (🚩) and must state "bloqué par D#" in "À faire (qui)"`,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// Gate: ✅ or 🔵 without a witness; merged is never ✅ fait; stage 'done' requires ✅ fait; ⚫ without reason
|
|
545
|
+
if (row.status !== 'done' && row.status !== 'withdrawn' && row.stage === 'done') {
|
|
546
|
+
violations.push({
|
|
547
|
+
code: 'missing-witness',
|
|
548
|
+
rowNum: row.num,
|
|
549
|
+
message: `row #${row.num} cannot have stage "done" while status is "${String(row.status)}" (stage "done" requires ✅ fait)`,
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
if (row.status === 'done') {
|
|
553
|
+
if (row.stage !== 'done') {
|
|
554
|
+
violations.push({
|
|
555
|
+
code: 'missing-witness',
|
|
556
|
+
rowNum: row.num,
|
|
557
|
+
message: `row #${row.num} cannot be ✅ fait at stage "${String(row.stage ?? '—')}" (requires stage "done")`,
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
if (row.hasWitness !== true || isBlankOrDash(row.done)) {
|
|
561
|
+
violations.push({
|
|
562
|
+
code: 'missing-witness',
|
|
563
|
+
rowNum: row.num,
|
|
564
|
+
message: `row #${row.num} is ✅ fait without a recorded witness in "Fait"`,
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
else if (row.status === 'on-track') {
|
|
569
|
+
if (row.stage === undefined || row.hasWitness !== true || isBlankOrDash(row.done)) {
|
|
570
|
+
violations.push({
|
|
571
|
+
code: 'missing-witness',
|
|
572
|
+
rowNum: row.num,
|
|
573
|
+
message: `row #${row.num} is 🔵 sur la voie without a conformity witness at stage "${String(row.stage ?? '—')}"`,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
else if (row.status === 'withdrawn') {
|
|
578
|
+
if (isBlankOrDash(row.done)) {
|
|
579
|
+
violations.push({
|
|
580
|
+
code: 'missing-witness',
|
|
581
|
+
rowNum: row.num,
|
|
582
|
+
message: `row #${row.num} is ⚫ retiré without a reason in "Fait"`,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
if ((row.blockingDecisionRefs?.length ?? 0) > 0) {
|
|
586
|
+
violations.push({
|
|
587
|
+
code: 'invalid-decision',
|
|
588
|
+
rowNum: row.num,
|
|
589
|
+
message: `row #${row.num} is ⚫ retiré and must not carry blocking decisions`,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
// Gate: ETA without a target stage or a source (up to 2 ETAs per row)
|
|
594
|
+
if ((row.status === 'done' || row.status === 'withdrawn') && row.etas.length > 0) {
|
|
595
|
+
violations.push({
|
|
596
|
+
code: 'invalid-eta',
|
|
597
|
+
rowNum: row.num,
|
|
598
|
+
message: `row #${row.num} is terminal (${row.status}) and must not carry active ETAs`,
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
if (row.etas.length === 0 && row.status !== 'done' && row.status !== 'withdrawn') {
|
|
602
|
+
violations.push({
|
|
603
|
+
code: 'invalid-eta',
|
|
604
|
+
rowNum: row.num,
|
|
605
|
+
message: `row #${row.num} is missing an ETA entry (target stage + source required)`,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
auditRowEtaEntries(row, violations, policy, true);
|
|
609
|
+
}
|
|
610
|
+
// Gate: row pointing to an unlisted D# or inconsistent sansObjet / withdrawn decision refs
|
|
611
|
+
const rowSansObjetSet = new Set(row.sansObjetDecisionRefs ?? []);
|
|
612
|
+
for (const ref of rowSansObjetSet) {
|
|
613
|
+
if (!row.decisionRefs.includes(ref)) {
|
|
614
|
+
violations.push({
|
|
615
|
+
code: 'invalid-decision',
|
|
616
|
+
rowNum: row.num,
|
|
617
|
+
decisionRef: ref,
|
|
618
|
+
message: `row #${row.num} lists ${ref} in sansObjetDecisionRefs without including it in decisionRefs`,
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
if ((row.blockingDecisionRefs ?? []).includes(ref)) {
|
|
622
|
+
violations.push({
|
|
623
|
+
code: 'invalid-decision',
|
|
624
|
+
rowNum: row.num,
|
|
625
|
+
decisionRef: ref,
|
|
626
|
+
message: `row #${row.num} cannot mark decision ${ref} as both sansObjet and blocking`,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
for (const ref of row.decisionRefs) {
|
|
631
|
+
referencedDecisions.add(ref);
|
|
632
|
+
const dec = decisionMap.get(ref);
|
|
633
|
+
if (dec === undefined) {
|
|
634
|
+
violations.push({
|
|
635
|
+
code: 'invalid-decision',
|
|
636
|
+
rowNum: row.num,
|
|
637
|
+
decisionRef: ref,
|
|
638
|
+
message: `row #${row.num} points to unlisted decision ${ref}`,
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
if (row.status === 'withdrawn' && dec.sansObjet !== true) {
|
|
643
|
+
violations.push({
|
|
644
|
+
code: 'invalid-decision',
|
|
645
|
+
rowNum: row.num,
|
|
646
|
+
decisionRef: ref,
|
|
647
|
+
message: `row #${row.num} is ⚫ retiré and references decision ${ref} which is not marked sansObjet`,
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
if (rowSansObjetSet.has(ref) && dec.sansObjet !== true) {
|
|
651
|
+
violations.push({
|
|
652
|
+
code: 'invalid-decision',
|
|
653
|
+
rowNum: row.num,
|
|
654
|
+
decisionRef: ref,
|
|
655
|
+
message: `row #${row.num} marks decision ${ref} in sansObjetDecisionRefs, but decision ${ref} is not sansObjet`,
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
if (dec.sansObjet === true && !rowSansObjetSet.has(ref)) {
|
|
659
|
+
violations.push({
|
|
660
|
+
code: 'invalid-decision',
|
|
661
|
+
rowNum: row.num,
|
|
662
|
+
decisionRef: ref,
|
|
663
|
+
message: `row #${row.num} references sans-objet decision ${ref} without listing it in sansObjetDecisionRefs`,
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
// Gate: commit hash, ULID, internal jargon, or banned word in owner text
|
|
669
|
+
checkTextGates(row.request, { rowNum: row.num, field: `row #${row.num} "Ta demande"` }, violations, policy);
|
|
670
|
+
checkTextGates(row.done, { rowNum: row.num, field: `row #${row.num} "Fait"` }, violations, policy);
|
|
671
|
+
checkTextGates(row.todo, { rowNum: row.num, field: `row #${row.num} "À faire (qui)"` }, violations, policy);
|
|
672
|
+
}
|
|
673
|
+
// Gate: D# without a row, or D# missing question / options / recommendation / dossierLink
|
|
674
|
+
for (const d of view.decisions) {
|
|
675
|
+
if (!referencedDecisions.has(d.ref) && d.sansObjet !== true) {
|
|
676
|
+
violations.push({
|
|
677
|
+
code: 'invalid-decision',
|
|
678
|
+
decisionRef: d.ref,
|
|
679
|
+
message: `decision ${d.ref} is not referenced by any row`,
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
if (d.sansObjet === true && d.blocking === true) {
|
|
683
|
+
violations.push({
|
|
684
|
+
code: 'invalid-decision',
|
|
685
|
+
decisionRef: d.ref,
|
|
686
|
+
message: `decision ${d.ref} is sans objet and must not be marked blocking`,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
const validRecommendedLetter = !isBlankOrDash(d.recommendedLetter) && d.options.some((o) => o.letter === d.recommendedLetter);
|
|
690
|
+
if (isBlankOrDash(d.question) ||
|
|
691
|
+
d.options.length < 2 ||
|
|
692
|
+
!validRecommendedLetter ||
|
|
693
|
+
isBlankOrDash(d.recommendation)) {
|
|
694
|
+
violations.push({
|
|
695
|
+
code: 'invalid-decision',
|
|
696
|
+
decisionRef: d.ref,
|
|
697
|
+
message: `decision ${d.ref} must carry a question, at least 2 options with consequences, and a valid recommendation`,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
if (isBlankOrDash(d.dossierLink)) {
|
|
701
|
+
violations.push({
|
|
702
|
+
code: 'invalid-decision',
|
|
703
|
+
decisionRef: d.ref,
|
|
704
|
+
message: `decision ${d.ref} is missing a dossier link`,
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
checkTextGates(d.question, { decisionRef: d.ref, field: `decision ${d.ref} question` }, violations, policy);
|
|
708
|
+
checkTextGates(d.recommendation, { decisionRef: d.ref, field: `decision ${d.ref} recommendation` }, violations, policy);
|
|
709
|
+
if (d.dossierLink !== undefined) {
|
|
710
|
+
checkTextGates(d.dossierLink, { decisionRef: d.ref, field: `decision ${d.ref} dossierLink` }, violations, policy);
|
|
711
|
+
}
|
|
712
|
+
for (const opt of d.options) {
|
|
713
|
+
checkTextGates(`${opt.label} ${opt.consequence}`, { decisionRef: d.ref, field: `decision ${d.ref} option ${opt.letter}` }, violations, policy);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (view.replyLine !== undefined && view.replyLine !== '') {
|
|
717
|
+
checkTextGates(view.replyLine, { field: 'replyLine' }, violations, policy);
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
ok: violations.length === 0,
|
|
721
|
+
violations,
|
|
722
|
+
...(notice !== undefined ? { notices: [notice] } : {}),
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
function escapePipeCell(value) {
|
|
726
|
+
return cleanDisplayText(value).replace(/\|/gu, '\\|');
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Render the owner table in Markdown (`md` / `text`) or JSON (`json`).
|
|
730
|
+
* Refuses with a `DomainError` (`REFUSED: ...`) if any blocking gate fails.
|
|
731
|
+
*/
|
|
732
|
+
export function renderOwnerTable(view, format = 'md', options) {
|
|
733
|
+
const audit = auditOwnerTable(view, options);
|
|
734
|
+
if (!audit.ok) {
|
|
735
|
+
const details = audit.violations.map((v) => `- [${v.code}] ${v.message}`).join('\n');
|
|
736
|
+
throw new DomainError(`REFUSED: owner table failed blocking gates:\n${details}`);
|
|
737
|
+
}
|
|
738
|
+
if (format === 'json') {
|
|
739
|
+
return JSON.stringify(view, null, 2) + '\n';
|
|
740
|
+
}
|
|
741
|
+
const lines = [
|
|
742
|
+
`| ${OWNER_TABLE_HEADERS.join(' | ')} |`,
|
|
743
|
+
'| ---: | --- | --- | --- | --- | --- | --- | --- |',
|
|
744
|
+
];
|
|
745
|
+
for (const row of view.rows) {
|
|
746
|
+
const cells = [
|
|
747
|
+
String(row.num),
|
|
748
|
+
formatOwnerStatusCell(row),
|
|
749
|
+
formatOwnerStageCell(row),
|
|
750
|
+
escapePipeCell(formatOwnerEtaCell(row.etas)),
|
|
751
|
+
escapePipeCell(row.request),
|
|
752
|
+
escapePipeCell(row.done),
|
|
753
|
+
escapePipeCell(row.todo),
|
|
754
|
+
escapePipeCell(formatOwnerDecisionCell(row)),
|
|
755
|
+
];
|
|
756
|
+
lines.push(`| ${cells.join(' | ')} |`);
|
|
757
|
+
}
|
|
758
|
+
lines.push('');
|
|
759
|
+
lines.push("**Décisions qui t'attendent**");
|
|
760
|
+
lines.push('');
|
|
761
|
+
if (view.decisions.length === 0) {
|
|
762
|
+
lines.push('Aucune décision en attente.');
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
for (const d of view.decisions) {
|
|
766
|
+
const refHeading = d.sansObjet === true ? `**${d.ref}** (décision sans objet)` : `**${d.ref}**`;
|
|
767
|
+
lines.push(`- ${refHeading} — ${cleanDisplayText(d.question)}`);
|
|
768
|
+
for (const opt of d.options) {
|
|
769
|
+
lines.push(` - **${opt.letter} · ${cleanDisplayText(opt.label)}** — ${cleanDisplayText(opt.consequence)}`);
|
|
770
|
+
}
|
|
771
|
+
const dossierSuffix = d.dossierLink !== undefined && d.dossierLink.trim() !== ''
|
|
772
|
+
? ` · Dossier : ${d.dossierLink.trim()}`
|
|
773
|
+
: '';
|
|
774
|
+
lines.push(` - Reco : **${d.recommendedLetter}** (${cleanDisplayText(d.recommendation)})${dossierSuffix}`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
lines.push('');
|
|
778
|
+
lines.push(`\`${view.replyLine}\``);
|
|
779
|
+
return lines.join('\n') + '\n';
|
|
780
|
+
}
|
|
781
|
+
export function optionLetter(index) {
|
|
782
|
+
let n = Math.max(0, Math.floor(index));
|
|
783
|
+
let s = '';
|
|
784
|
+
do {
|
|
785
|
+
s = String.fromCharCode(65 + (n % 26)) + s;
|
|
786
|
+
n = Math.floor(n / 26) - 1;
|
|
787
|
+
} while (n >= 0);
|
|
788
|
+
return s;
|
|
789
|
+
}
|
|
790
|
+
function defaultTargetStageFor(stage, requestedStage) {
|
|
791
|
+
if (stage === undefined) {
|
|
792
|
+
return requestedStage ?? 'spec';
|
|
793
|
+
}
|
|
794
|
+
if (requestedStage !== undefined && STAGE_RANK[requestedStage] > STAGE_RANK[stage]) {
|
|
795
|
+
return requestedStage;
|
|
796
|
+
}
|
|
797
|
+
switch (stage) {
|
|
798
|
+
case 'brainstorm':
|
|
799
|
+
return 'spec';
|
|
800
|
+
case 'spec':
|
|
801
|
+
case 'plan':
|
|
802
|
+
return 'dev';
|
|
803
|
+
case 'dev':
|
|
804
|
+
case 'test':
|
|
805
|
+
return 'pr';
|
|
806
|
+
case 'pr':
|
|
807
|
+
case 'review':
|
|
808
|
+
return 'merged';
|
|
809
|
+
case 'merged':
|
|
810
|
+
return 'published';
|
|
811
|
+
case 'published':
|
|
812
|
+
return 'preprod';
|
|
813
|
+
case 'preprod':
|
|
814
|
+
return 'prod';
|
|
815
|
+
case 'prod':
|
|
816
|
+
case 'done':
|
|
817
|
+
return 'done';
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Legacy prose helper (never applied to gated owner-table cells so blocking gates
|
|
822
|
+
* cannot be bypassed by silent text rewriting).
|
|
823
|
+
*/
|
|
824
|
+
export function normalizeLegacyOwnerProse(input) {
|
|
825
|
+
let out = input;
|
|
826
|
+
out = out.replace(PRIVATE_DIGEST_RE, 'empreinte vérifiée');
|
|
827
|
+
out = out.replace(PRIVATE_PATH_RE, ' (chemin local)');
|
|
828
|
+
out = out.replace(ULID_RE, 'réf. interne');
|
|
829
|
+
out = out.replace(/\(\s*(?=[0-9a-f]{7,40}\s*\))(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\s*\)/giu, '');
|
|
830
|
+
out = out.replace(COMMIT_HASH_RE, 'rév.');
|
|
831
|
+
out = out.replace(/\b[a-z0-9_.-]+\/[a-z0-9_.-]+#(\d+)\b/giu, '#$1');
|
|
832
|
+
out = out.replace(/\brealization=to-do\b/giu, 'non démarré');
|
|
833
|
+
out = out.replace(/\brealization=in-progress\b/giu, 'en cours');
|
|
834
|
+
out = out.replace(/\brealization=done\b/giu, 'réalisé');
|
|
835
|
+
out = out.replace(/\bspec=to-specify\b/giu, 'à spécifier');
|
|
836
|
+
out = out.replace(/\brecette=unknown\b/giu, 'recette non qualifiée');
|
|
837
|
+
out = out.replace(/\bworktrees?\b/giu, 'espace');
|
|
838
|
+
out = out.replace(/\bsubagents?\b/giu, 'agent');
|
|
839
|
+
out = out.replace(/\bbwrap\b/giu, 'bac à sable');
|
|
840
|
+
out = out.replace(/\btmux\b/giu, 'terminal');
|
|
841
|
+
out = out.replace(/\bpty-host\b/giu, 'hôte terminal');
|
|
842
|
+
out = out.replace(/\bevents\.jsonl\b/giu, 'journal');
|
|
843
|
+
out = out.replace(/\baggregateId\b/giu, 'identifiant');
|
|
844
|
+
out = out.replace(/\bspecStatus\b/giu, 'état de spec');
|
|
845
|
+
out = out.replace(/\brealizedCommit\b/giu, 'ancrage');
|
|
846
|
+
out = out.replace(/\blanes?\b/giu, 'piste');
|
|
847
|
+
out = out.replace(/\bshards?\b/giu, 'lot');
|
|
848
|
+
return cleanDisplayText(out);
|
|
849
|
+
}
|
|
850
|
+
function hasValidArchiveDecision(state, decisionId) {
|
|
851
|
+
if (decisionId === undefined || decisionId.trim() === '')
|
|
852
|
+
return false;
|
|
853
|
+
const dec = state.decisions.get(decisionId);
|
|
854
|
+
return dec !== undefined && dec.outcome === 'go';
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Project the folded `State` and event log into an `OwnerTableView`.
|
|
858
|
+
* Pure read-time projection: never invents request numbers, causes, withdrawal reasons,
|
|
859
|
+
* stages without links, or recommendations, and never rewrites gated text.
|
|
860
|
+
*/
|
|
861
|
+
export function projectOwnerTable(state, events, options = {}) {
|
|
862
|
+
const baselineCommit = options.baselineCommit ?? 'HEAD';
|
|
863
|
+
const registeredNumbers = new Set();
|
|
864
|
+
const archivedNumbers = new Set();
|
|
865
|
+
const everOwnerItemIds = new Set();
|
|
866
|
+
const historicalItemNumbers = new Map();
|
|
867
|
+
const historicalItemRequests = new Map();
|
|
868
|
+
const promotedItemIds = new Set();
|
|
869
|
+
for (const demand of state.demands.values()) {
|
|
870
|
+
for (const itemId of demand.itemIds ?? [])
|
|
871
|
+
promotedItemIds.add(itemId);
|
|
872
|
+
}
|
|
873
|
+
for (const ev of events) {
|
|
874
|
+
if (ev.type === 'demand.owner-numbered') {
|
|
875
|
+
const demand = state.demands.get(ev.aggregateId);
|
|
876
|
+
if (options.workspace !== undefined && demand !== undefined && demand.workspace !== options.workspace)
|
|
877
|
+
continue;
|
|
878
|
+
const num = ev.payload.number;
|
|
879
|
+
if (typeof num === 'number' && Number.isInteger(num) && num >= 1) {
|
|
880
|
+
registeredNumbers.add(num);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
else if (ev.type === 'item.report-updated') {
|
|
884
|
+
const item = state.items.get(ev.aggregateId);
|
|
885
|
+
if (options.workspace !== undefined && item !== undefined && item.workspace !== options.workspace)
|
|
886
|
+
continue;
|
|
887
|
+
const payload = ev.payload;
|
|
888
|
+
if (typeof payload?.ownerNumber === 'number' && Number.isInteger(payload.ownerNumber) && payload.ownerNumber >= 1) {
|
|
889
|
+
if (!promotedItemIds.has(ev.aggregateId)) {
|
|
890
|
+
registeredNumbers.add(payload.ownerNumber);
|
|
891
|
+
}
|
|
892
|
+
historicalItemNumbers.set(ev.aggregateId, payload.ownerNumber);
|
|
893
|
+
}
|
|
894
|
+
const histReq = typeof payload?.ownerSummary === 'string' && payload.ownerSummary.trim() !== ''
|
|
895
|
+
? payload.ownerSummary.trim()
|
|
896
|
+
: typeof payload?.ownerRequest === 'string' && payload.ownerRequest.trim() !== ''
|
|
897
|
+
? payload.ownerRequest.trim()
|
|
898
|
+
: undefined;
|
|
899
|
+
if (histReq !== undefined) {
|
|
900
|
+
historicalItemRequests.set(ev.aggregateId, histReq);
|
|
901
|
+
}
|
|
902
|
+
if (payload?.ownerNumber !== undefined || histReq !== undefined) {
|
|
903
|
+
everOwnerItemIds.add(ev.aggregateId);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
for (const demand of state.demands.values()) {
|
|
908
|
+
if (options.workspace !== undefined && demand.workspace !== options.workspace)
|
|
909
|
+
continue;
|
|
910
|
+
if (demand.ownerNumber !== undefined) {
|
|
911
|
+
registeredNumbers.add(demand.ownerNumber);
|
|
912
|
+
if (demand.archived !== undefined && hasValidArchiveDecision(state, demand.archived.decisionId)) {
|
|
913
|
+
archivedNumbers.add(demand.ownerNumber);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
for (const item of state.items.values()) {
|
|
918
|
+
if (options.workspace !== undefined && item.workspace !== options.workspace)
|
|
919
|
+
continue;
|
|
920
|
+
if (promotedItemIds.has(item.id))
|
|
921
|
+
continue;
|
|
922
|
+
const num = item.report?.ownerNumber ?? historicalItemNumbers.get(item.id);
|
|
923
|
+
if (item.report?.ownerNumber !== undefined) {
|
|
924
|
+
registeredNumbers.add(item.report.ownerNumber);
|
|
925
|
+
}
|
|
926
|
+
if (num !== undefined &&
|
|
927
|
+
item.report?.archived !== undefined &&
|
|
928
|
+
hasValidArchiveDecision(state, item.report.archived.decisionId)) {
|
|
929
|
+
archivedNumbers.add(num);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
const candidates = [];
|
|
933
|
+
for (const demand of state.demands.values()) {
|
|
934
|
+
if (options.workspace !== undefined && demand.workspace !== options.workspace)
|
|
935
|
+
continue;
|
|
936
|
+
if (demand.archived !== undefined && hasValidArchiveDecision(state, demand.archived.decisionId))
|
|
937
|
+
continue;
|
|
938
|
+
const promoted = (demand.itemIds ?? [])
|
|
939
|
+
.map((id) => state.items.get(id))
|
|
940
|
+
.filter((it) => it !== undefined);
|
|
941
|
+
candidates.push({
|
|
942
|
+
kind: 'demand',
|
|
943
|
+
id: demand.id,
|
|
944
|
+
...(demand.ownerNumber !== undefined ? { explicitNumber: demand.ownerNumber } : {}),
|
|
945
|
+
demand,
|
|
946
|
+
items: promoted,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
for (const item of state.items.values()) {
|
|
950
|
+
if (options.workspace !== undefined && item.workspace !== options.workspace)
|
|
951
|
+
continue;
|
|
952
|
+
if (promotedItemIds.has(item.id))
|
|
953
|
+
continue;
|
|
954
|
+
if (item.report?.archived !== undefined && hasValidArchiveDecision(state, item.report.archived.decisionId))
|
|
955
|
+
continue;
|
|
956
|
+
const resolvedItemNumber = item.report?.ownerNumber ?? historicalItemNumbers.get(item.id);
|
|
957
|
+
const hasOwnerMeta = everOwnerItemIds.has(item.id) ||
|
|
958
|
+
resolvedItemNumber !== undefined ||
|
|
959
|
+
item.report?.ownerSummary !== undefined ||
|
|
960
|
+
item.report?.ownerRequest !== undefined;
|
|
961
|
+
if (!hasOwnerMeta)
|
|
962
|
+
continue;
|
|
963
|
+
candidates.push({
|
|
964
|
+
kind: 'item',
|
|
965
|
+
id: item.id,
|
|
966
|
+
...(resolvedItemNumber !== undefined ? { explicitNumber: resolvedItemNumber } : {}),
|
|
967
|
+
items: [item],
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
const numberedCandidates = candidates.map((c) => ({
|
|
971
|
+
...c,
|
|
972
|
+
num: c.explicitNumber ?? 0,
|
|
973
|
+
}));
|
|
974
|
+
numberedCandidates.sort((a, b) => {
|
|
975
|
+
if (a.num > 0 && b.num > 0)
|
|
976
|
+
return a.num - b.num;
|
|
977
|
+
if (a.num > 0)
|
|
978
|
+
return -1;
|
|
979
|
+
if (b.num > 0)
|
|
980
|
+
return 1;
|
|
981
|
+
return 0;
|
|
982
|
+
});
|
|
983
|
+
const pauseDecisionIds = new Set();
|
|
984
|
+
for (const item of state.items.values()) {
|
|
985
|
+
if (options.workspace !== undefined && item.workspace !== options.workspace)
|
|
986
|
+
continue;
|
|
987
|
+
if (item.report?.pausedByOwner === true &&
|
|
988
|
+
item.report.pauseDecisionId !== undefined &&
|
|
989
|
+
item.report.pauseDecisionId.trim() !== '') {
|
|
990
|
+
const dec = state.decisions.get(item.report.pauseDecisionId);
|
|
991
|
+
if (dec !== undefined && (dec.outcome === 'go' || dec.outcome === 'deferred')) {
|
|
992
|
+
pauseDecisionIds.add(dec.id);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
const isTargetArchived = (targetId, seen = new Set()) => {
|
|
997
|
+
if (seen.has(targetId))
|
|
998
|
+
return false;
|
|
999
|
+
seen.add(targetId);
|
|
1000
|
+
const dem = state.demands.get(targetId);
|
|
1001
|
+
if (dem !== undefined) {
|
|
1002
|
+
return dem.archived !== undefined && hasValidArchiveDecision(state, dem.archived.decisionId);
|
|
1003
|
+
}
|
|
1004
|
+
const it = state.items.get(targetId);
|
|
1005
|
+
if (it === undefined)
|
|
1006
|
+
return false;
|
|
1007
|
+
if (it.report?.archived !== undefined && hasValidArchiveDecision(state, it.report.archived.decisionId)) {
|
|
1008
|
+
return true;
|
|
1009
|
+
}
|
|
1010
|
+
if (it.demandId !== undefined && isTargetArchived(it.demandId, seen))
|
|
1011
|
+
return true;
|
|
1012
|
+
for (const parentDem of state.demands.values()) {
|
|
1013
|
+
if (parentDem.itemIds?.includes(it.id) && isTargetArchived(parentDem.id, seen))
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
if (it.parentId !== undefined && isTargetArchived(it.parentId, seen))
|
|
1017
|
+
return true;
|
|
1018
|
+
return false;
|
|
1019
|
+
};
|
|
1020
|
+
const isTargetWithdrawnOrArchived = (targetId, seen = new Set()) => {
|
|
1021
|
+
if (isTargetArchived(targetId))
|
|
1022
|
+
return true;
|
|
1023
|
+
if (seen.has(targetId))
|
|
1024
|
+
return false;
|
|
1025
|
+
seen.add(targetId);
|
|
1026
|
+
const dem = state.demands.get(targetId);
|
|
1027
|
+
if (dem !== undefined) {
|
|
1028
|
+
if (dem.status === 'rejected' || dem.status === 'duplicate')
|
|
1029
|
+
return true;
|
|
1030
|
+
const itemIds = dem.itemIds ?? [];
|
|
1031
|
+
return itemIds.length > 0 && itemIds.every((id) => isTargetWithdrawnOrArchived(id, new Set(seen)));
|
|
1032
|
+
}
|
|
1033
|
+
const it = state.items.get(targetId);
|
|
1034
|
+
if (it === undefined)
|
|
1035
|
+
return false;
|
|
1036
|
+
if (it.realization === 'cancelled' || it.realization === 'rejected')
|
|
1037
|
+
return true;
|
|
1038
|
+
if (it.demandId !== undefined) {
|
|
1039
|
+
const parentDem = state.demands.get(it.demandId);
|
|
1040
|
+
if (parentDem !== undefined && (parentDem.status === 'rejected' || parentDem.status === 'duplicate')) {
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
for (const parentDem of state.demands.values()) {
|
|
1045
|
+
if (parentDem.itemIds?.includes(it.id) &&
|
|
1046
|
+
(parentDem.status === 'rejected' || parentDem.status === 'duplicate')) {
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (it.parentId !== undefined && isTargetWithdrawnOrArchived(it.parentId, seen))
|
|
1051
|
+
return true;
|
|
1052
|
+
return false;
|
|
1053
|
+
};
|
|
1054
|
+
// Every pending decision with options in the workspace is listed (decisions with no row or missing recommendation/link fail Gate 5)
|
|
1055
|
+
const pendingDecisions = [];
|
|
1056
|
+
for (const decision of state.decisions.values()) {
|
|
1057
|
+
if (options.workspace !== undefined && decision.workspace !== options.workspace)
|
|
1058
|
+
continue;
|
|
1059
|
+
if (isSettled(decision.outcome) ||
|
|
1060
|
+
(decision.outcome === 'deferred' && pauseDecisionIds.has(decision.id)) ||
|
|
1061
|
+
!Array.isArray(decision.dossier?.options) ||
|
|
1062
|
+
decision.dossier.options.length === 0) {
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
pendingDecisions.push(decision);
|
|
1066
|
+
}
|
|
1067
|
+
const sansObjetDecisionIds = new Set();
|
|
1068
|
+
const decisionRefById = new Map();
|
|
1069
|
+
const ownerDecisions = pendingDecisions.map((d, idx) => {
|
|
1070
|
+
const ref = `D${idx + 1}`;
|
|
1071
|
+
decisionRefById.set(d.id, ref);
|
|
1072
|
+
const sansObjet = d.targets.length > 0 && d.targets.every((targetId) => isTargetWithdrawnOrArchived(targetId));
|
|
1073
|
+
if (sansObjet) {
|
|
1074
|
+
sansObjetDecisionIds.add(d.id);
|
|
1075
|
+
}
|
|
1076
|
+
const optionsList = d.dossier.options.map((opt, optIdx) => ({
|
|
1077
|
+
letter: optionLetter(optIdx),
|
|
1078
|
+
label: cleanDisplayText(opt.title),
|
|
1079
|
+
consequence: cleanDisplayText(opt.summary),
|
|
1080
|
+
}));
|
|
1081
|
+
const recOptionId = d.dossier.recommendation?.optionId;
|
|
1082
|
+
const recRationale = d.dossier.recommendation?.rationale;
|
|
1083
|
+
const recIdx = recOptionId !== undefined ? d.dossier.options.findIndex((o) => o.id === recOptionId) : -1;
|
|
1084
|
+
const recommendedLetter = recIdx >= 0 ? optionLetter(recIdx) : '';
|
|
1085
|
+
const recommendation = recIdx >= 0 && recRationale !== undefined && recRationale.trim() !== ''
|
|
1086
|
+
? cleanDisplayText(recRationale)
|
|
1087
|
+
: '';
|
|
1088
|
+
const artifactLink = d.dossier.artifacts?.find((a) => a.kind === 'rendered-view')?.viewRef;
|
|
1089
|
+
const hasOpenBlocker = !sansObjet &&
|
|
1090
|
+
!pauseDecisionIds.has(d.id) &&
|
|
1091
|
+
[...state.blockers.values()].some((b) => b.open && b.kind === 'decision' && b.ref === d.id);
|
|
1092
|
+
return {
|
|
1093
|
+
ref,
|
|
1094
|
+
id: d.id,
|
|
1095
|
+
question: cleanDisplayText(shortDecisionSubject(d.title)),
|
|
1096
|
+
options: optionsList,
|
|
1097
|
+
recommendedLetter,
|
|
1098
|
+
recommendation,
|
|
1099
|
+
...(artifactLink !== undefined ? { dossierLink: artifactLink } : {}),
|
|
1100
|
+
blocking: hasOpenBlocker,
|
|
1101
|
+
...(sansObjet ? { sansObjet: true } : {}),
|
|
1102
|
+
};
|
|
1103
|
+
});
|
|
1104
|
+
const decisionTargetsItem = (d, item, demandIdForSingle) => {
|
|
1105
|
+
for (const targetId of d.targets) {
|
|
1106
|
+
if (demandIdForSingle !== undefined && targetId === demandIdForSingle)
|
|
1107
|
+
return true;
|
|
1108
|
+
if (item !== undefined && targetId === item.id)
|
|
1109
|
+
return true;
|
|
1110
|
+
const visited = new Set();
|
|
1111
|
+
let curr = state.items.get(targetId);
|
|
1112
|
+
while (curr !== undefined && !visited.has(curr.id)) {
|
|
1113
|
+
visited.add(curr.id);
|
|
1114
|
+
if (item !== undefined && curr.id === item.id)
|
|
1115
|
+
return true;
|
|
1116
|
+
if (demandIdForSingle !== undefined && curr.demandId === demandIdForSingle)
|
|
1117
|
+
return true;
|
|
1118
|
+
curr = curr.parentId !== undefined ? state.items.get(curr.parentId) : undefined;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return false;
|
|
1122
|
+
};
|
|
1123
|
+
const projectSingleOrLotRow = (params) => {
|
|
1124
|
+
const { rowKind, num, rowId, parentDemandId, demand, item, request, requestedStage } = params;
|
|
1125
|
+
const report = item?.report;
|
|
1126
|
+
const derived = item !== undefined ? deriveItemStageStatus(state, events, item, baselineCommit) : undefined;
|
|
1127
|
+
let stage;
|
|
1128
|
+
let status;
|
|
1129
|
+
let hasWitness = false;
|
|
1130
|
+
let pausedByOwner = false;
|
|
1131
|
+
if (item === undefined && demand !== undefined) {
|
|
1132
|
+
stage = undefined;
|
|
1133
|
+
if (demand.status === 'rejected' || demand.status === 'duplicate') {
|
|
1134
|
+
status = 'withdrawn';
|
|
1135
|
+
}
|
|
1136
|
+
else if (demand.status === 'parked') {
|
|
1137
|
+
if (demand.parkReason !== undefined && demand.parkReason.trim() !== '') {
|
|
1138
|
+
status = 'not-started';
|
|
1139
|
+
pausedByOwner = true;
|
|
1140
|
+
}
|
|
1141
|
+
else {
|
|
1142
|
+
status = 'not-qualified';
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
status = 'not-started';
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
else if (derived !== undefined) {
|
|
1150
|
+
stage = derived.linkedStage;
|
|
1151
|
+
hasWitness =
|
|
1152
|
+
stage !== undefined &&
|
|
1153
|
+
derived.qualified &&
|
|
1154
|
+
derived.linkedStageEvidence !== undefined &&
|
|
1155
|
+
derived.linkedStageEvidence.trim() !== '';
|
|
1156
|
+
pausedByOwner = derived.status === 'not-started' && derived.pausedByOwner === true;
|
|
1157
|
+
status = derived.status;
|
|
1158
|
+
if (status === 'on-track' && (!hasWitness || stage === undefined || stage === 'done')) {
|
|
1159
|
+
status = 'not-qualified';
|
|
1160
|
+
}
|
|
1161
|
+
else if (status === 'done' && (stage !== 'done' || !hasWitness)) {
|
|
1162
|
+
status = hasWitness && stage !== undefined && stage !== 'done' ? 'on-track' : 'not-qualified';
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
else {
|
|
1166
|
+
status = 'not-started';
|
|
1167
|
+
}
|
|
1168
|
+
// Decisions linked to this specific row (a lot row never reads decisions targeting the demand or sibling lots)
|
|
1169
|
+
const linkedDecisionIds = new Set();
|
|
1170
|
+
for (const d of pendingDecisions) {
|
|
1171
|
+
if (decisionTargetsItem(d, item, rowKind === 'single' ? demand?.id : undefined)) {
|
|
1172
|
+
if (status !== 'withdrawn' || sansObjetDecisionIds.has(d.id)) {
|
|
1173
|
+
linkedDecisionIds.add(d.id);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const explicitRefs = status === 'withdrawn' ? [] : (report?.decisionRefs ?? []);
|
|
1178
|
+
const rowDecisionRefs = [
|
|
1179
|
+
...explicitRefs,
|
|
1180
|
+
...[...linkedDecisionIds].map((id) => decisionRefById.get(id)).filter((r) => r !== undefined),
|
|
1181
|
+
];
|
|
1182
|
+
const uniqueDecisionRefs = [...new Set(rowDecisionRefs)];
|
|
1183
|
+
const openDecisionBlockers = item === undefined || status === 'withdrawn'
|
|
1184
|
+
? []
|
|
1185
|
+
: (() => {
|
|
1186
|
+
const itPauseId = item.report?.pausedByOwner === true && item.report.pauseDecisionId !== undefined
|
|
1187
|
+
? item.report.pauseDecisionId
|
|
1188
|
+
: undefined;
|
|
1189
|
+
const itOwnerPaused = itPauseId !== undefined && pauseDecisionIds.has(itPauseId);
|
|
1190
|
+
return effectiveOpenBlockersForItem(state, item.id, baselineCommit).filter((b) => {
|
|
1191
|
+
if (b.kind !== 'decision')
|
|
1192
|
+
return false;
|
|
1193
|
+
if (itOwnerPaused && (b.ref === undefined || b.ref === itPauseId))
|
|
1194
|
+
return false;
|
|
1195
|
+
if (b.ref !== undefined && pauseDecisionIds.has(b.ref))
|
|
1196
|
+
return false;
|
|
1197
|
+
return true;
|
|
1198
|
+
});
|
|
1199
|
+
})();
|
|
1200
|
+
const blockingDecisionRefSet = new Set();
|
|
1201
|
+
if (status !== 'withdrawn') {
|
|
1202
|
+
for (const dId of linkedDecisionIds) {
|
|
1203
|
+
const ref = decisionRefById.get(dId);
|
|
1204
|
+
if (ref === undefined)
|
|
1205
|
+
continue;
|
|
1206
|
+
const isBlockingThisRow = openDecisionBlockers.some((b) => b.ref === undefined || b.ref === dId) ||
|
|
1207
|
+
(rowKind === 'single' &&
|
|
1208
|
+
demand !== undefined &&
|
|
1209
|
+
[...state.blockers.values()].some((b) => b.open && b.kind === 'decision' && b.targetId === demand.id && b.ref === dId));
|
|
1210
|
+
if (isBlockingThisRow)
|
|
1211
|
+
blockingDecisionRefSet.add(ref);
|
|
1212
|
+
}
|
|
1213
|
+
if (!pausedByOwner && report?.decisionBlocking === true) {
|
|
1214
|
+
for (const ref of uniqueDecisionRefs)
|
|
1215
|
+
blockingDecisionRefSet.add(ref);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
// Also incorporate item.report.decisionExpectations if set and no native Decision exists
|
|
1219
|
+
if (status !== 'withdrawn' && report?.decisionExpectations !== undefined && uniqueDecisionRefs.length === 0) {
|
|
1220
|
+
const ref = `D${ownerDecisions.length + 1}`;
|
|
1221
|
+
uniqueDecisionRefs.push(ref);
|
|
1222
|
+
if (report.decisionBlocking === true || openDecisionBlockers.length > 0) {
|
|
1223
|
+
blockingDecisionRefSet.add(ref);
|
|
1224
|
+
}
|
|
1225
|
+
const opts = report.decisionExpectations.options.map((o, idx) => ({
|
|
1226
|
+
letter: optionLetter(idx),
|
|
1227
|
+
label: cleanDisplayText(o.label),
|
|
1228
|
+
consequence: cleanDisplayText(o.consequence),
|
|
1229
|
+
}));
|
|
1230
|
+
ownerDecisions.push({
|
|
1231
|
+
ref,
|
|
1232
|
+
id: `${rowId}:expectation`,
|
|
1233
|
+
question: cleanDisplayText(report.decisionExpectations.question),
|
|
1234
|
+
options: opts,
|
|
1235
|
+
recommendedLetter: '',
|
|
1236
|
+
recommendation: '',
|
|
1237
|
+
dossierLink: report.decisionExpectations.dossier,
|
|
1238
|
+
blocking: blockingDecisionRefSet.has(ref),
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
const sansObjetDecisionRefSet = new Set();
|
|
1242
|
+
for (const dId of linkedDecisionIds) {
|
|
1243
|
+
if (sansObjetDecisionIds.has(dId)) {
|
|
1244
|
+
const ref = decisionRefById.get(dId);
|
|
1245
|
+
if (ref !== undefined)
|
|
1246
|
+
sansObjetDecisionRefSet.add(ref);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
const sansObjetDecisionRefs = uniqueDecisionRefs.filter((ref) => sansObjetDecisionRefSet.has(ref));
|
|
1250
|
+
const blockingDecisionRefs = uniqueDecisionRefs.filter((ref) => blockingDecisionRefSet.has(ref));
|
|
1251
|
+
const decisionBlocking = status !== 'withdrawn' &&
|
|
1252
|
+
(blockingDecisionRefs.length > 0 || (!pausedByOwner && report?.decisionBlocking === true));
|
|
1253
|
+
if (decisionBlocking) {
|
|
1254
|
+
status = 'blocked';
|
|
1255
|
+
}
|
|
1256
|
+
const toEtaEntry = (j) => ({
|
|
1257
|
+
targetStage: j.targetStage,
|
|
1258
|
+
...(j.targetLabel !== undefined ? { targetLabel: j.targetLabel } : {}),
|
|
1259
|
+
when: j.when,
|
|
1260
|
+
source: j.source,
|
|
1261
|
+
...(j.by !== undefined ? { by: j.by } : {}),
|
|
1262
|
+
...(j.slip !== undefined ? { slip: j.slip } : {}),
|
|
1263
|
+
...(j.measured !== undefined ? { measured: j.measured } : {}),
|
|
1264
|
+
});
|
|
1265
|
+
const baseSlots = [];
|
|
1266
|
+
const itemEtas = item?.etaJournal !== undefined && item.etaJournal.length > 0
|
|
1267
|
+
? item.etaJournal.filter((j) => j.delivered !== true)
|
|
1268
|
+
: (report?.etas ?? []);
|
|
1269
|
+
for (const j of itemEtas) {
|
|
1270
|
+
baseSlots.push({ entry: toEtaEntry(j), origin: 'item' });
|
|
1271
|
+
}
|
|
1272
|
+
if (rowKind === 'single' && demand?.etaJournal !== undefined) {
|
|
1273
|
+
for (const j of demand.etaJournal.filter((entry) => entry.delivered !== true)) {
|
|
1274
|
+
baseSlots.push({ entry: toEtaEntry(j), origin: 'demand' });
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
const lookupVelocityInputs = () => {
|
|
1278
|
+
if (options.velocityBindings === undefined)
|
|
1279
|
+
return [];
|
|
1280
|
+
// A lot row reads ONLY its own item id; never the parent demand or request number
|
|
1281
|
+
const keysToTry = rowKind === 'lot'
|
|
1282
|
+
? item !== undefined
|
|
1283
|
+
? [item.id]
|
|
1284
|
+
: []
|
|
1285
|
+
: [
|
|
1286
|
+
rowId,
|
|
1287
|
+
...(item !== undefined && item.id !== rowId ? [item.id] : []),
|
|
1288
|
+
...(num > 0 ? [String(num)] : []),
|
|
1289
|
+
];
|
|
1290
|
+
const matched = [];
|
|
1291
|
+
const seenKeys = new Set();
|
|
1292
|
+
for (const k of keysToTry) {
|
|
1293
|
+
if (seenKeys.has(k))
|
|
1294
|
+
continue;
|
|
1295
|
+
seenKeys.add(k);
|
|
1296
|
+
const found = options.velocityBindings instanceof Map
|
|
1297
|
+
? options.velocityBindings.get(k)
|
|
1298
|
+
: options.velocityBindings[k];
|
|
1299
|
+
if (found !== undefined) {
|
|
1300
|
+
const list = Array.isArray(found) ? found : [found];
|
|
1301
|
+
matched.push(...list);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
return matched;
|
|
1305
|
+
};
|
|
1306
|
+
const velocityInputs = lookupVelocityInputs();
|
|
1307
|
+
const velocitySlots = velocityInputs.map((vInput) => {
|
|
1308
|
+
const priorSlot = baseSlots.find((s) => s.entry.targetStage === vInput.targetStage && s.entry.slip !== undefined) ??
|
|
1309
|
+
baseSlots.find((s) => s.entry.targetStage === vInput.targetStage);
|
|
1310
|
+
const qualified = qualifyVelocityEta({
|
|
1311
|
+
...vInput,
|
|
1312
|
+
...(vInput.slip !== undefined
|
|
1313
|
+
? { slip: vInput.slip }
|
|
1314
|
+
: priorSlot?.entry.slip !== undefined
|
|
1315
|
+
? { slip: priorSlot.entry.slip }
|
|
1316
|
+
: {}),
|
|
1317
|
+
});
|
|
1318
|
+
return {
|
|
1319
|
+
entry: qualified.eta,
|
|
1320
|
+
origin: 'velocity',
|
|
1321
|
+
};
|
|
1322
|
+
});
|
|
1323
|
+
const rawSlots = [...velocitySlots, ...baseSlots];
|
|
1324
|
+
const evaluatedSlots = rawSlots.map((slot) => ({
|
|
1325
|
+
...evaluateEtaDeadline(slot.entry, stage, {
|
|
1326
|
+
...(options.now !== undefined ? { now: options.now } : {}),
|
|
1327
|
+
pausedByOwner,
|
|
1328
|
+
}),
|
|
1329
|
+
origin: slot.origin,
|
|
1330
|
+
}));
|
|
1331
|
+
const displaySlots = evaluatedSlots.filter((ev) => stage === undefined || STAGE_RANK[stage] < STAGE_RANK[ev.eta.targetStage]);
|
|
1332
|
+
const anyEtaMissed = displaySlots.some((ev) => ev.missed);
|
|
1333
|
+
let etas;
|
|
1334
|
+
if (status === 'done' || status === 'withdrawn') {
|
|
1335
|
+
etas = [];
|
|
1336
|
+
}
|
|
1337
|
+
else if (displaySlots.length > 0) {
|
|
1338
|
+
const byStage = new Map();
|
|
1339
|
+
for (const ev of displaySlots) {
|
|
1340
|
+
const prev = byStage.get(ev.eta.targetStage);
|
|
1341
|
+
if (prev === undefined || (!prev.missed && ev.missed)) {
|
|
1342
|
+
byStage.set(ev.eta.targetStage, ev);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
const unique = [...byStage.values()];
|
|
1346
|
+
unique.sort((a, b) => (b.missed ? 1 : 0) - (a.missed ? 1 : 0) ||
|
|
1347
|
+
STAGE_RANK[a.eta.targetStage] - STAGE_RANK[b.eta.targetStage]);
|
|
1348
|
+
etas = unique.slice(0, 2).map((ev) => ev.eta);
|
|
1349
|
+
}
|
|
1350
|
+
else {
|
|
1351
|
+
etas = [
|
|
1352
|
+
{
|
|
1353
|
+
targetStage: defaultTargetStageFor(stage, requestedStage),
|
|
1354
|
+
when: '—',
|
|
1355
|
+
source: 'unknown',
|
|
1356
|
+
},
|
|
1357
|
+
];
|
|
1358
|
+
}
|
|
1359
|
+
if (anyEtaMissed && status !== 'withdrawn' && status !== 'done' && status !== 'blocked') {
|
|
1360
|
+
status = 'unforeseen';
|
|
1361
|
+
}
|
|
1362
|
+
// Done cell (`Fait`)
|
|
1363
|
+
let doneText;
|
|
1364
|
+
if (status === 'withdrawn') {
|
|
1365
|
+
const itemFacts = report?.facts?.trim() !== '' ? report?.facts?.trim() : undefined;
|
|
1366
|
+
let settledDecisionReason;
|
|
1367
|
+
if (item !== undefined) {
|
|
1368
|
+
const linkedSettled = [...state.decisions.values()]
|
|
1369
|
+
.filter((d) => d.targets.includes(item.id) && d.outcome === 'no-go')
|
|
1370
|
+
.sort((a, b) => (a.id < b.id ? -1 : 1));
|
|
1371
|
+
for (const decision of linkedSettled) {
|
|
1372
|
+
const selected = decision.dossier.options.find((o) => o.id === decision.dossier.selectedOptionId);
|
|
1373
|
+
const cand = selected?.summary?.trim() || selected?.title?.trim();
|
|
1374
|
+
if (cand !== undefined && cand !== '') {
|
|
1375
|
+
settledDecisionReason = cand;
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
const reopenReason = item?.reopenings?.at(-1)?.reason?.trim() !== '' ? item?.reopenings?.at(-1)?.reason?.trim() : undefined;
|
|
1381
|
+
const reason = (rowKind === 'single' ? demand?.rejectReason : undefined) ??
|
|
1382
|
+
itemFacts ??
|
|
1383
|
+
settledDecisionReason ??
|
|
1384
|
+
reopenReason;
|
|
1385
|
+
doneText = reason !== undefined && reason.trim() !== '' ? cleanDisplayText(reason) : '—';
|
|
1386
|
+
}
|
|
1387
|
+
else {
|
|
1388
|
+
const parts = [];
|
|
1389
|
+
if (report?.facts !== undefined && report.facts.trim() !== '') {
|
|
1390
|
+
parts.push(cleanDisplayText(report.facts));
|
|
1391
|
+
}
|
|
1392
|
+
if (parts.length === 0 &&
|
|
1393
|
+
derived?.linkedStageEvidence !== undefined &&
|
|
1394
|
+
derived.linkedStageEvidence.trim() !== '') {
|
|
1395
|
+
parts.push(`Preuve : ${cleanDisplayText(derived.linkedStageEvidence)}`);
|
|
1396
|
+
}
|
|
1397
|
+
doneText = parts.length > 0 ? parts.join(' · ') : '—';
|
|
1398
|
+
}
|
|
1399
|
+
// Todo cell (`À faire (qui)`) — never inject a fallback cause when blocked
|
|
1400
|
+
let todoText;
|
|
1401
|
+
if (status === 'withdrawn') {
|
|
1402
|
+
todoText = '—';
|
|
1403
|
+
}
|
|
1404
|
+
else {
|
|
1405
|
+
const openBlockers = item !== undefined ? effectiveOpenBlockersForItem(state, item.id, baselineCommit) : [];
|
|
1406
|
+
const blockerReasons = openBlockers
|
|
1407
|
+
.filter((b) => b.kind !== 'decision')
|
|
1408
|
+
.map((b) => cleanDisplayText(b.reason))
|
|
1409
|
+
.filter((r) => r.length > 0);
|
|
1410
|
+
const baseTodoParts = [];
|
|
1411
|
+
if (blockingDecisionRefs.length > 0) {
|
|
1412
|
+
baseTodoParts.push(`bloqué par ${blockingDecisionRefs.join(' · ')} (owner)`);
|
|
1413
|
+
}
|
|
1414
|
+
if (blockerReasons.length > 0) {
|
|
1415
|
+
baseTodoParts.push(...new Set(blockerReasons));
|
|
1416
|
+
}
|
|
1417
|
+
if (report?.waitingOn !== undefined && report.waitingOn.trim() !== '') {
|
|
1418
|
+
const w = `attente : ${cleanDisplayText(report.waitingOn)}`;
|
|
1419
|
+
if (!baseTodoParts.includes(w))
|
|
1420
|
+
baseTodoParts.push(w);
|
|
1421
|
+
}
|
|
1422
|
+
if (report?.nextAction !== undefined && report.nextAction.trim() !== '') {
|
|
1423
|
+
const na = cleanDisplayText(report.nextAction);
|
|
1424
|
+
if (!baseTodoParts.includes(na))
|
|
1425
|
+
baseTodoParts.push(na);
|
|
1426
|
+
}
|
|
1427
|
+
else if (report?.proposal !== undefined && report.proposal.trim() !== '') {
|
|
1428
|
+
const pr = cleanDisplayText(report.proposal);
|
|
1429
|
+
if (!baseTodoParts.includes(pr))
|
|
1430
|
+
baseTodoParts.push(pr);
|
|
1431
|
+
}
|
|
1432
|
+
if (baseTodoParts.length === 0 &&
|
|
1433
|
+
rowKind === 'single' &&
|
|
1434
|
+
demand !== undefined &&
|
|
1435
|
+
item === undefined &&
|
|
1436
|
+
status !== 'blocked') {
|
|
1437
|
+
if (demand.status === 'parked' && demand.parkReason !== undefined && demand.parkReason.trim() !== '') {
|
|
1438
|
+
baseTodoParts.push(`en pause (${cleanDisplayText(demand.parkReason)})`);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
todoText = baseTodoParts.length > 0 ? baseTodoParts.join(' ; ') : '—';
|
|
1442
|
+
}
|
|
1443
|
+
return {
|
|
1444
|
+
kind: rowKind,
|
|
1445
|
+
...(parentDemandId !== undefined ? { parentDemandId } : {}),
|
|
1446
|
+
num,
|
|
1447
|
+
id: rowId,
|
|
1448
|
+
status,
|
|
1449
|
+
...(pausedByOwner ? { pausedByOwner: true } : {}),
|
|
1450
|
+
...(stage !== undefined ? { stage } : {}),
|
|
1451
|
+
...(requestedStage !== undefined ? { requestedStage } : {}),
|
|
1452
|
+
etas,
|
|
1453
|
+
request,
|
|
1454
|
+
done: doneText,
|
|
1455
|
+
todo: todoText,
|
|
1456
|
+
decisionRefs: uniqueDecisionRefs,
|
|
1457
|
+
...(sansObjetDecisionRefs.length > 0 ? { sansObjetDecisionRefs } : {}),
|
|
1458
|
+
...(blockingDecisionRefs.length > 0 ? { blockingDecisionRefs } : {}),
|
|
1459
|
+
...(decisionBlocking ? { decisionBlocking: true } : {}),
|
|
1460
|
+
hasWitness,
|
|
1461
|
+
};
|
|
1462
|
+
};
|
|
1463
|
+
const rows = [];
|
|
1464
|
+
for (const c of numberedCandidates) {
|
|
1465
|
+
if (c.kind === 'demand' && c.items.length > 1) {
|
|
1466
|
+
const demand = c.demand;
|
|
1467
|
+
const rawTitleRequest = demand.ownerSummary ?? demand.raw.title ?? demand.raw.text ?? '';
|
|
1468
|
+
const titleRequest = cleanDisplayText(rawTitleRequest);
|
|
1469
|
+
// Decisions targeting the demand itself (not individual lots)
|
|
1470
|
+
const titleDecisionIds = new Set();
|
|
1471
|
+
for (const d of pendingDecisions) {
|
|
1472
|
+
if (d.targets.includes(demand.id)) {
|
|
1473
|
+
titleDecisionIds.add(d.id);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
const titleDecisionRefs = [...titleDecisionIds]
|
|
1477
|
+
.map((id) => decisionRefById.get(id))
|
|
1478
|
+
.filter((r) => r !== undefined);
|
|
1479
|
+
const titleSansObjetRefs = [...titleDecisionIds]
|
|
1480
|
+
.filter((dId) => sansObjetDecisionIds.has(dId))
|
|
1481
|
+
.map((dId) => decisionRefById.get(dId))
|
|
1482
|
+
.filter((r) => r !== undefined);
|
|
1483
|
+
const titleBlockingRefs = [...titleDecisionIds]
|
|
1484
|
+
.filter((dId) => !sansObjetDecisionIds.has(dId) &&
|
|
1485
|
+
[...state.blockers.values()].some((b) => b.open && b.kind === 'decision' && b.targetId === demand.id && b.ref === dId))
|
|
1486
|
+
.map((dId) => decisionRefById.get(dId))
|
|
1487
|
+
.filter((r) => r !== undefined);
|
|
1488
|
+
// Demand-level ETA (demand.eta-set) shows on the title row only if set, with its own slip/rebaseline logic
|
|
1489
|
+
const activeDemandEtas = (demand.etaJournal ?? []).filter((j) => j.delivered !== true);
|
|
1490
|
+
const titleEtas = activeDemandEtas.length > 0
|
|
1491
|
+
? activeDemandEtas
|
|
1492
|
+
.map((j) => evaluateEtaDeadline({
|
|
1493
|
+
targetStage: j.targetStage,
|
|
1494
|
+
...(j.targetLabel !== undefined ? { targetLabel: j.targetLabel } : {}),
|
|
1495
|
+
when: j.when,
|
|
1496
|
+
source: j.source,
|
|
1497
|
+
...(j.by !== undefined ? { by: j.by } : {}),
|
|
1498
|
+
...(j.slip !== undefined ? { slip: j.slip } : {}),
|
|
1499
|
+
...(j.measured !== undefined ? { measured: j.measured } : {}),
|
|
1500
|
+
}, undefined, {
|
|
1501
|
+
...(options.now !== undefined ? { now: options.now } : {}),
|
|
1502
|
+
}))
|
|
1503
|
+
.sort((a, b) => (b.missed ? 1 : 0) - (a.missed ? 1 : 0) ||
|
|
1504
|
+
STAGE_RANK[a.eta.targetStage] - STAGE_RANK[b.eta.targetStage])
|
|
1505
|
+
.slice(0, 2)
|
|
1506
|
+
.map((ev) => ev.eta)
|
|
1507
|
+
: [];
|
|
1508
|
+
rows.push({
|
|
1509
|
+
kind: 'demand-title',
|
|
1510
|
+
num: c.num,
|
|
1511
|
+
id: demand.id,
|
|
1512
|
+
...(demand.requestedStage !== undefined ? { requestedStage: demand.requestedStage } : {}),
|
|
1513
|
+
etas: titleEtas,
|
|
1514
|
+
request: titleRequest,
|
|
1515
|
+
done: '—',
|
|
1516
|
+
todo: '—',
|
|
1517
|
+
decisionRefs: titleDecisionRefs,
|
|
1518
|
+
...(titleSansObjetRefs.length > 0 ? { sansObjetDecisionRefs: titleSansObjetRefs } : {}),
|
|
1519
|
+
...(titleBlockingRefs.length > 0
|
|
1520
|
+
? { blockingDecisionRefs: titleBlockingRefs, decisionBlocking: true }
|
|
1521
|
+
: {}),
|
|
1522
|
+
});
|
|
1523
|
+
c.items.forEach((lotItem, idx) => {
|
|
1524
|
+
const rawLotTitle = lotItem.report?.ownerSummary ?? lotItem.report?.ownerRequest ?? lotItem.title;
|
|
1525
|
+
const cleanedLotTitle = cleanDisplayText(rawLotTitle);
|
|
1526
|
+
const lotRequest = cleanedLotTitle === ''
|
|
1527
|
+
? ''
|
|
1528
|
+
: /^↳ lot \d+ — /u.test(cleanedLotTitle)
|
|
1529
|
+
? cleanedLotTitle
|
|
1530
|
+
: `↳ lot ${idx + 1} — ${cleanedLotTitle}`;
|
|
1531
|
+
rows.push(projectSingleOrLotRow({
|
|
1532
|
+
rowKind: 'lot',
|
|
1533
|
+
num: c.num,
|
|
1534
|
+
rowId: lotItem.id,
|
|
1535
|
+
parentDemandId: demand.id,
|
|
1536
|
+
item: lotItem,
|
|
1537
|
+
request: lotRequest,
|
|
1538
|
+
...(lotItem.report?.requestedStage !== undefined
|
|
1539
|
+
? { requestedStage: lotItem.report.requestedStage }
|
|
1540
|
+
: {}),
|
|
1541
|
+
}));
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
else {
|
|
1545
|
+
const primaryItem = c.items[0];
|
|
1546
|
+
const report = primaryItem?.report;
|
|
1547
|
+
const rawRequest = c.kind === 'demand'
|
|
1548
|
+
? (c.demand?.ownerSummary ??
|
|
1549
|
+
report?.ownerSummary ??
|
|
1550
|
+
report?.ownerRequest ??
|
|
1551
|
+
c.demand?.raw.title ??
|
|
1552
|
+
c.demand?.raw.text ??
|
|
1553
|
+
'')
|
|
1554
|
+
: (report?.ownerSummary ??
|
|
1555
|
+
report?.ownerRequest ??
|
|
1556
|
+
historicalItemRequests.get(primaryItem?.id ?? c.id) ??
|
|
1557
|
+
'');
|
|
1558
|
+
const request = cleanDisplayText(rawRequest);
|
|
1559
|
+
const requestedStage = c.demand?.requestedStage ?? report?.requestedStage;
|
|
1560
|
+
rows.push(projectSingleOrLotRow({
|
|
1561
|
+
rowKind: 'single',
|
|
1562
|
+
num: c.num,
|
|
1563
|
+
rowId: c.id,
|
|
1564
|
+
...(c.demand !== undefined ? { demand: c.demand } : {}),
|
|
1565
|
+
...(primaryItem !== undefined ? { item: primaryItem } : {}),
|
|
1566
|
+
request,
|
|
1567
|
+
...(requestedStage !== undefined ? { requestedStage } : {}),
|
|
1568
|
+
}));
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
const replyLine = ownerDecisions.length === 0
|
|
1572
|
+
? 'Réponse : aucune décision en attente'
|
|
1573
|
+
: `Réponse : ${ownerDecisions.map((d) => `${d.ref} ${d.recommendedLetter}`).join(' · ')}`;
|
|
1574
|
+
return {
|
|
1575
|
+
kind: 'owner-table-report',
|
|
1576
|
+
rows,
|
|
1577
|
+
decisions: ownerDecisions,
|
|
1578
|
+
replyLine,
|
|
1579
|
+
registeredNumbers: [...registeredNumbers].sort((a, b) => a - b),
|
|
1580
|
+
archivedNumbers: [...archivedNumbers].sort((a, b) => a - b),
|
|
1581
|
+
...(options.policy !== undefined ? { policy: options.policy } : {}),
|
|
1582
|
+
...(options.policyPath !== undefined ? { policyPath: options.policyPath } : {}),
|
|
1583
|
+
...(options.defaultPolicyPath !== undefined ? { defaultPolicyPath: options.defaultPolicyPath } : {}),
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
//# sourceMappingURL=owner-table.js.map
|