@takagaki/cortex-decisions-viewer 0.12.270 → 0.12.276

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.
@@ -0,0 +1,429 @@
1
+ "use strict";
2
+ /**
3
+ * 「更新の記録」のページ(左のレールの 2 つ目・cortex-engine #2894 便 RAIL-T3・設計 #2860 確定版 §2・§3)の純関数。
4
+ *
5
+ * 一覧は取り込みの窓口の `op=memory-history`(ポータルの実行履歴と同じ行+試行の並び `attempts`)、1 回の中身は
6
+ * `op=memory-report`(engine が回の終わりに置いた報告を、窓口が許す欄だけに組み直した写し)から描く。
7
+ * 🔴 **本文は出さない**(報告にも本文は無い)。題の無い会話は「#チャンネル名 · 11/14 18:05 のスレッド(返信 3 件)」のように
8
+ * 場所と時刻で並べる(オーナーの答え Q1)。名前の決まりは engine の `evidenceLabelOf`(報告の `label`)が正で、ここは
9
+ * 題の無い物の言い方だけを持つ。
10
+ *
11
+ * **どれもクロージャを持たない function 宣言に保つこと**(`render.ts` が `.toString()` で画面へ流し込む)。
12
+ * 表は関数の中に書く(`export const` は CommonJS に落ちると `exports.X` に書き換えられ、流し込んだ先で落ちる)。
13
+ * 互いを呼ぶ関数は、呼ばれる側も同じ名前で流し込む(`render.ts` の並びを崩さない)。
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.runJstText = runJstText;
17
+ exports.runDayText = runDayText;
18
+ exports.runMonthText = runMonthText;
19
+ exports.runMonthsOf = runMonthsOf;
20
+ exports.runRowsShownOf = runRowsShownOf;
21
+ exports.runCauseWordOf = runCauseWordOf;
22
+ exports.runLastAttemptOf = runLastAttemptOf;
23
+ exports.runRowStateOf = runRowStateOf;
24
+ exports.runRowOpenRunOf = runRowOpenRunOf;
25
+ exports.runRowResultTextOf = runRowResultTextOf;
26
+ exports.runFailTextOf = runFailTextOf;
27
+ exports.runHistoryStatusTextOf = runHistoryStatusTextOf;
28
+ exports.runOutcomeTextOf = runOutcomeTextOf;
29
+ exports.runKindTextOf = runKindTextOf;
30
+ exports.runFoldByDayOf = runFoldByDayOf;
31
+ exports.runSectionLabelOf = runSectionLabelOf;
32
+ exports.runSectionCountsOf = runSectionCountsOf;
33
+ exports.runCountsTextOf = runCountsTextOf;
34
+ exports.runRecordChangeWordOf = runRecordChangeWordOf;
35
+ exports.runItemChangeWordOf = runItemChangeWordOf;
36
+ exports.runToolWordOf = runToolWordOf;
37
+ exports.runVenueNameOf = runVenueNameOf;
38
+ exports.runMaterialNameOf = runMaterialNameOf;
39
+ exports.runMaterialFoldOf = runMaterialFoldOf;
40
+ exports.runMaterialSummaryOf = runMaterialSummaryOf;
41
+ exports.runSafeUrlOf = runSafeUrlOf;
42
+ exports.runMaterialIndexOf = runMaterialIndexOf;
43
+ /** 時刻(ISO)を日本時間の「11/14 18:05」に。読めなければ空文字 */
44
+ function runJstText(iso) {
45
+ const ms = typeof iso === "string" && iso ? Date.parse(iso) : NaN;
46
+ if (!Number.isFinite(ms))
47
+ return "";
48
+ const d = new Date(ms + 9 * 60 * 60 * 1000);
49
+ const p = (n) => (n < 10 ? "0" + n : String(n));
50
+ return d.getUTCMonth() + 1 + "/" + d.getUTCDate() + " " + p(d.getUTCHours()) + ":" + p(d.getUTCMinutes());
51
+ }
52
+ /** 暦の日(`YYYY-MM-DD`)を「11/14」に。`unknown`・形違いは「日付の分からない物」 */
53
+ function runDayText(day) {
54
+ const m = typeof day === "string" ? /^\d{4}-(\d{2})-(\d{2})$/.exec(day) : null;
55
+ return m ? Number(m[1]) + "/" + Number(m[2]) : "日付の分からない物";
56
+ }
57
+ /** 暦の月(`YYYY-MM`)を「2026 年 11 月」に。形違いは空文字 */
58
+ function runMonthText(month) {
59
+ const m = typeof month === "string" ? /^(\d{4})-(0[1-9]|1[0-2])$/.exec(month) : null;
60
+ return m ? m[1] + " 年 " + Number(m[2]) + " 月" : "";
61
+ }
62
+ /**
63
+ * 一覧で選べる月(日本時間・新しい順)。今の月から、`days` 日前を含む月まで(画面に出すのは 180 日分・設計 §2「残す期間」)。
64
+ * 時計は呼び手が渡す(試験は固定の時刻を渡す)
65
+ */
66
+ function runMonthsOf(nowMs, days) {
67
+ if (!Number.isFinite(nowMs) || !(days >= 0))
68
+ return [];
69
+ const JST = 9 * 60 * 60 * 1000;
70
+ const key = (ms) => {
71
+ const d = new Date(ms + JST);
72
+ const mm = d.getUTCMonth() + 1;
73
+ return d.getUTCFullYear() + "-" + (mm < 10 ? "0" + mm : String(mm));
74
+ };
75
+ const last = key(nowMs - days * 24 * 60 * 60 * 1000);
76
+ const out = [];
77
+ const d = new Date(nowMs + JST);
78
+ let y = d.getUTCFullYear();
79
+ let m = d.getUTCMonth() + 1;
80
+ for (let i = 0; i < 24; i++) {
81
+ const k = y + "-" + (m < 10 ? "0" + m : String(m));
82
+ out.push(k);
83
+ if (k === last)
84
+ break;
85
+ m -= 1;
86
+ if (m === 0) {
87
+ m = 12;
88
+ y -= 1;
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+ /** 一覧に出す行(`days` 日より前の行は出さない・時刻の読めない行も出さない)。並びは窓口の答えのまま(新しい順) */
94
+ function runRowsShownOf(rows, nowMs, days) {
95
+ const from = nowMs - days * 24 * 60 * 60 * 1000;
96
+ const out = [];
97
+ for (const r of Array.isArray(rows) ? rows : []) {
98
+ const t = r && typeof r.at === "string" ? Date.parse(r.at) : NaN;
99
+ if (Number.isFinite(t) && t >= from)
100
+ out.push(r);
101
+ }
102
+ return out;
103
+ }
104
+ /** 行のきっかけの語(開始の押しは「開始」・毎晩・今すぐ更新・運営)。知らない語は空文字 */
105
+ function runCauseWordOf(row) {
106
+ if (!row || typeof row !== "object")
107
+ return "";
108
+ if (row.kind === "start")
109
+ return "開始";
110
+ const words = { schedule: "毎晩", manual: "今すぐ更新", operator: "運営" };
111
+ return Object.prototype.hasOwnProperty.call(words, row.cause) ? words[row.cause] : "";
112
+ }
113
+ /** 行の最後の試行(`runId`・`attempt` の大きい方。並びに頼らない)。形の違う試行は飛ばす。無ければ null */
114
+ function runLastAttemptOf(row) {
115
+ const attempts = row && Array.isArray(row.attempts) ? row.attempts : [];
116
+ let lastA = null;
117
+ for (const a of attempts) {
118
+ if (!a || !(Number.isSafeInteger(a.runId) && a.runId > 0) || !(Number.isSafeInteger(a.attempt) && a.attempt > 0))
119
+ continue;
120
+ if (!lastA || a.runId > lastA.runId || (a.runId === lastA.runId && a.attempt > lastA.attempt))
121
+ lastA = a;
122
+ }
123
+ return lastA;
124
+ }
125
+ /**
126
+ * 行の状態(設計 §2「報告の無い行の言い分け」)。
127
+ * - `not_run` … 押したが走らなかった(試行も run へのリンクも無い・開始に失敗した押し)
128
+ * - `running` … 最後の試行がまだ終わっていない(結果の語が走っている側の語)
129
+ * - `done` … それ以外(開けるかは `runRowOpenRunOf` が決める)
130
+ * 試行が 1 つも読めず run へのリンクだけがある行(試行の欄の無い古い行・結果の語が窓口の形を外れて落ちた試行)は `done` だが、
131
+ * 結果の文は言い切らない(`runRowResultTextOf` はポータルの文だけを出す)
132
+ */
133
+ function runRowStateOf(row) {
134
+ const lastA = runLastAttemptOf(row);
135
+ if (!lastA)
136
+ return row && typeof row.runUrl === "string" && row.runUrl ? "done" : "not_run";
137
+ const running = ["in_progress", "queued", "requested", "waiting", "pending", "running"];
138
+ return running.indexOf(lastA.outcome) >= 0 ? "running" : "done";
139
+ }
140
+ /** 行から開く回(最後の試行の `<runId>-<attempt>`)。試行が無ければ null(開けない) */
141
+ function runRowOpenRunOf(row) {
142
+ const lastA = runLastAttemptOf(row);
143
+ return lastA ? lastA.runId + "-" + lastA.attempt : null;
144
+ }
145
+ /** 行の結果の 1 文。ポータルの文(`message`)があればそれ、無ければ最後の試行の語から(語が無い・知らない語なら空文字=言い切らない) */
146
+ function runRowResultTextOf(row) {
147
+ const state = runRowStateOf(row);
148
+ if (state === "not_run")
149
+ return "走りませんでした";
150
+ if (state === "running")
151
+ return "実行中";
152
+ if (row && typeof row.message === "string" && row.message.trim())
153
+ return row.message.trim();
154
+ const lastA = runLastAttemptOf(row);
155
+ const words = { success: "終わりました", failure: "失敗しました", cancelled: "止めました", timed_out: "時間切れで止まりました" };
156
+ return lastA && Object.prototype.hasOwnProperty.call(words, lastA.outcome) ? words[lastA.outcome] : "";
157
+ }
158
+ /**
159
+ * 窓口の答え(一覧・1 回の中身)が 200 でないときの 1 文と、名乗り券を読み直すか。
160
+ * 券の理由の 403 は開き直しの案内(次の呼びで Cookie を読み直す)・ほかの 403 は見る権限が無い・404 は見つからない・
161
+ * 大きすぎる控えは言い分ける・ほか(届かない・5xx・打ち切り)は待ってから開き直す
162
+ */
163
+ function runFailTextOf(status, body) {
164
+ const code = body && typeof body === "object" ? body.code : undefined;
165
+ if (status === 403 && ["ACTOR_INVALID", "ACTOR_REQUIRED", "ACTOR_PROJECT_MISMATCH"].indexOf(code) >= 0) {
166
+ return { text: "確かめの期限が切れました。ページを開き直してください", reopen: true };
167
+ }
168
+ if (status === 403)
169
+ return { text: "この案件の更新の記録を見る権限がありません", reopen: false };
170
+ if (status === 404 || status === 400)
171
+ return { text: "この回は見つかりません(見られない回か、古い回です)", reopen: false };
172
+ if (status === 503 && code === "TOO_LARGE")
173
+ return { text: "この回の中身は大きすぎて、ここには出せません", reopen: false };
174
+ return { text: "更新の記録を読めませんでした。少し待ってから開き直してください", reopen: false };
175
+ }
176
+ /** 一覧の `status`(ok 以外)の 1 文。ok は null */
177
+ function runHistoryStatusTextOf(status) {
178
+ if (status === "ok")
179
+ return null;
180
+ if (status === "not_configured" || status === "not_enabled")
181
+ return "まだ記憶の更新を始めていません";
182
+ return "更新の記録を読めませんでした。少し待ってから開き直してください";
183
+ }
184
+ /** 回の結果の語(報告の `outcome`)。知らない語は空文字 */
185
+ function runOutcomeTextOf(outcome) {
186
+ const words = {
187
+ landed: "記憶に入りました",
188
+ partial: "一部だけ記憶に入りました",
189
+ lost: "記憶に入りませんでした",
190
+ no_diff: "新しく記憶にする物はありませんでした",
191
+ unverified: "記憶に入ったか確かめられませんでした",
192
+ failed: "途中で失敗しました",
193
+ };
194
+ return Object.prototype.hasOwnProperty.call(words, outcome) ? words[outcome] : "";
195
+ }
196
+ /** 回の種類の語(きっかけと開始の何回目か)。報告の `cause`・`phase` から */
197
+ function runKindTextOf(cause, phase) {
198
+ if (phase === "first")
199
+ return "開始の 1 回目";
200
+ if (phase === "second")
201
+ return "開始の 2 回目";
202
+ if (phase === "again")
203
+ return "開始のやり直し";
204
+ const words = { schedule: "毎晩の更新", manual: "今すぐ更新", operator: "運営の更新" };
205
+ return Object.prototype.hasOwnProperty.call(words, cause) ? words[cause] : "";
206
+ }
207
+ /** 材料は日ごとにも畳むか(最初の回=開始の回と範囲の回は日数が多い・設計 §2「量」) */
208
+ function runFoldByDayOf(report) {
209
+ if (!report || typeof report !== "object")
210
+ return false;
211
+ if (report.phase === "first" || report.phase === "again")
212
+ return true;
213
+ return typeof report.route === "string" && report.route.indexOf("range.") === 0;
214
+ }
215
+ /** 区画の名前(記憶のタブの名前と同じ) */
216
+ function runSectionLabelOf(section) {
217
+ const words = { decisions: "決定事項", glossary: "用語集", members: "関係者", rules: "ルール", stories: "ストーリー" };
218
+ return Object.prototype.hasOwnProperty.call(words, section) ? words[section] : "";
219
+ }
220
+ /**
221
+ * 区画ごとの数(新しく・更新・消した)。並びは記憶のタブの順。どれも 0 の区画は出さない
222
+ * @returns `[{ section, label, new, updated, removed }]`
223
+ */
224
+ function runSectionCountsOf(bySection) {
225
+ const order = ["decisions", "glossary", "members", "rules", "stories"];
226
+ const out = [];
227
+ const src = bySection && typeof bySection === "object" ? bySection : {};
228
+ for (const s of order) {
229
+ const c = src[s];
230
+ if (!c || typeof c !== "object")
231
+ continue;
232
+ const n = (v) => (Number.isSafeInteger(v) && v > 0 ? v : 0);
233
+ const row = { section: s, label: runSectionLabelOf(s), new: n(c.new), updated: n(c.updated), removed: n(c.removed) };
234
+ if (row.new + row.updated + row.removed > 0)
235
+ out.push(row);
236
+ }
237
+ return out;
238
+ }
239
+ /** 区画の数の 1 文(「新しく 1 件・更新 2 件」)。0 の語は出さない */
240
+ function runCountsTextOf(c) {
241
+ const parts = [];
242
+ if (c && c.new > 0)
243
+ parts.push("新しく " + c.new + " 件");
244
+ if (c && c.updated > 0)
245
+ parts.push("更新 " + c.updated + " 件");
246
+ if (c && c.removed > 0)
247
+ parts.push("消した " + c.removed + " 件");
248
+ return parts.join("・");
249
+ }
250
+ /** 記録の変わり方の語 */
251
+ function runRecordChangeWordOf(change) {
252
+ const words = { new: "新しく", updated: "更新", removed: "消した", renamed: "名前を変えた" };
253
+ return Object.prototype.hasOwnProperty.call(words, change) ? words[change] : "";
254
+ }
255
+ /** 材料の変わり方の語 */
256
+ function runItemChangeWordOf(change) {
257
+ const words = { new: "新しく", changed: "変わった", gone: "消えた" };
258
+ return Object.prototype.hasOwnProperty.call(words, change) ? words[change] : "";
259
+ }
260
+ /**
261
+ * ツールの名前。名前は直書きせず、つなぎ先の行(データソース一覧)と同じ出どころ
262
+ * (`SOURCE_ROW_TOOLS`=接続先の表の写し。鍵か `tool` が一致する行の `toolName`)から受け取る。表に無い名前はそのまま出す
263
+ * (ここには「種類の言葉」〈会議・資料〉だけを持つ。ツールの名前は持たない)
264
+ * @param table `{ 種類: { tool, toolName } }`(接続先の表)
265
+ */
266
+ function runToolWordOf(tool, table) {
267
+ const name = String(tool || "");
268
+ const has = (o, k) => !!o && typeof o === "object" && Object.prototype.hasOwnProperty.call(o, k);
269
+ if (table && typeof table === "object") {
270
+ if (has(table, name) && typeof table[name].toolName === "string")
271
+ return table[name].toolName;
272
+ for (const k of Object.keys(table)) {
273
+ if (table[k] && table[k].tool === name && typeof table[k].toolName === "string")
274
+ return table[k].toolName;
275
+ }
276
+ }
277
+ const kinds = { meeting: "会議", materials: "資料", file: "資料" };
278
+ return has(kinds, name) ? kinds[name] : name;
279
+ }
280
+ /**
281
+ * 会話の場の名前。報告に焼いた `venueName` が正、無ければ案件の接続先の一覧(`externalSources`・Slack はチャンネル ID と
282
+ * ワークスペース)から引く。どちらも無ければ Slack は「Slack のチャンネル」、Google Chat・Teams は「スペース」(設計 §2「名前」)
283
+ */
284
+ function runVenueNameOf(item, sources) {
285
+ const v = item && item.venue && typeof item.venue === "object" ? item.venue : {};
286
+ const tool = typeof v.tool === "string" ? v.tool : "";
287
+ const hash = (s) => (tool === "slack" ? "#" + s.replace(/^#+/, "") : s);
288
+ if (item && typeof item.venueName === "string" && item.venueName.trim())
289
+ return hash(item.venueName.trim());
290
+ if (typeof v.ref === "string" && v.ref) {
291
+ for (const s of Array.isArray(sources) ? sources : []) {
292
+ if (!s || s.ref !== v.ref || typeof s.name !== "string" || !s.name.trim() || s.name.indexOf("(名前未取得") === 0)
293
+ continue;
294
+ if (tool === "slack" && s.type !== "slack")
295
+ continue;
296
+ if (tool === "slack" && s.workspace && v.ws && s.workspace !== v.ws)
297
+ continue;
298
+ return hash(s.name.trim());
299
+ }
300
+ }
301
+ return tool === "slack" ? "Slack のチャンネル" : "スペース";
302
+ }
303
+ /**
304
+ * 材料 1 つの名前(設計 §3「本文は出さない」の線)。
305
+ * - 題の有る物は `label`(engine の `evidenceLabelOf` の名前)か題
306
+ * - 会話(Slack・Google Chat・Teams・`message.*`): 「<場> · 11/14 18:05 のスレッド(返信 N 件)」「…の発言」「…のスレッドへの返信」
307
+ * - コメント: 「<親の題> へのコメント」(親の題が分からなければ「コメント」)。題の無いコメントは label より先に見る
308
+ * - GitHub の題の無い PR・Issue・コミット: 「<リポ> の PR #N」「<リポ> の Issue #N」「<リポ> のコミット 1a2b3c4」
309
+ * - 消えた物(題を持たない): 「(消えた材料)」・ほかの題の無い物は「(題を伏せています)」(秘密らしい題)
310
+ * @param ctx `{ sources: externalSources, titles: { 鍵: 題 } }`(親の題を引く)
311
+ */
312
+ function runMaterialNameOf(item, ctx) {
313
+ if (!item || typeof item !== "object")
314
+ return "";
315
+ const label = typeof item.label === "string" && item.label.trim() ? item.label.trim() : "";
316
+ const title = typeof item.title === "string" && item.title.trim() ? item.title.trim() : "";
317
+ const c = ctx && typeof ctx === "object" ? ctx : {};
318
+ const v = item.venue && typeof item.venue === "object" ? item.venue : {};
319
+ const tool = typeof v.tool === "string" ? v.tool : "";
320
+ const kind = typeof item.kind === "string" ? item.kind : "";
321
+ // 🔴 コメントは label より先に見る(engine の evidenceLabelOf は題の無いコメントに親の題を付けるので、label のままだと親と同じ名前で並ぶ)
322
+ if (!title && kind.indexOf("comment") >= 0) {
323
+ const titles = c.titles && typeof c.titles === "object" ? c.titles : {};
324
+ const pt = typeof item.parent === "string" && typeof titles[item.parent] === "string" ? titles[item.parent] : label;
325
+ return pt ? pt + " へのコメント" : "コメント";
326
+ }
327
+ if (label || title)
328
+ return label || title;
329
+ if (tool === "slack" || tool === "google-chat" || tool === "teams" || kind.indexOf("message.") === 0) {
330
+ const at = runJstText(item.at);
331
+ const head = runVenueNameOf(item, c.sources) + (at ? " · " + at : "");
332
+ if (typeof item.parent === "string" && item.parent)
333
+ return head + " のスレッドへの返信";
334
+ if (Number.isSafeInteger(item.replies) && item.replies > 0)
335
+ return head + " のスレッド(返信 " + item.replies + " 件)";
336
+ return head + " の発言";
337
+ }
338
+ if (item.change === "gone")
339
+ return "(消えた材料)";
340
+ // GitHub の題の無い PR・Issue・コミットは「<リポ> の PR #N」(鍵の最後の 2 段・設計 §3)
341
+ if (tool === "github" && typeof item.key === "string") {
342
+ const segs = item.key.split(":");
343
+ const dec = (x) => { try {
344
+ return decodeURIComponent(x);
345
+ }
346
+ catch (e) {
347
+ return "";
348
+ } };
349
+ const repo = dec(String(typeof v.ref === "string" && v.ref !== "-" ? v.ref : segs[segs.length - 3] || ""));
350
+ const type = segs[segs.length - 2];
351
+ const id = dec(segs[segs.length - 1] || "");
352
+ if (repo && /^[0-9]{1,9}$/.test(id) && (type === "pr" || type === "pull"))
353
+ return repo + " の PR #" + id;
354
+ if (repo && /^[0-9]{1,9}$/.test(id) && type === "issue")
355
+ return repo + " の Issue #" + id;
356
+ if (repo && /^[0-9a-f]{7,40}$/i.test(id) && type === "commit")
357
+ return repo + " のコミット " + id.slice(0, 7);
358
+ }
359
+ return "(題を伏せています)";
360
+ }
361
+ /**
362
+ * 「この回に入った材料」を、ツールごと(最初の回は日ごとにも)に畳む形に組む。
363
+ * スレッドの返信は、親が同じツールの中に並ぶときは親の 1 行にまとめる(親の行が「返信 N 件」を言う)。
364
+ * 項目の数(`count`)が並べた数より多い所は `more`(数だけ出す分)を持つ。
365
+ * @returns `[{ tool, count, more, days: [{ day, count, more, items }] }]`(ツールの並びは数の多い順・同数は名前順。日は新しい順)
366
+ */
367
+ function runMaterialFoldOf(materials) {
368
+ const groups = materials && Array.isArray(materials.groups) ? materials.groups : [];
369
+ const byTool = {};
370
+ const order = [];
371
+ for (const g of groups) {
372
+ if (!g || typeof g.tool !== "string" || typeof g.day !== "string")
373
+ continue;
374
+ if (!byTool[g.tool]) {
375
+ byTool[g.tool] = { tool: g.tool, count: 0, more: 0, days: [] };
376
+ order.push(g.tool);
377
+ }
378
+ const items = Array.isArray(g.items) ? g.items.filter((x) => x && typeof x.key === "string") : [];
379
+ const count = Number.isSafeInteger(g.count) && g.count >= items.length ? g.count : items.length;
380
+ byTool[g.tool].days.push({ day: g.day, count, more: count - items.length, items });
381
+ byTool[g.tool].count += count;
382
+ byTool[g.tool].more += count - items.length;
383
+ }
384
+ const out = [];
385
+ for (const t of order) {
386
+ const entry = byTool[t];
387
+ const keys = {};
388
+ for (const d of entry.days)
389
+ for (const it of d.items)
390
+ keys[it.key] = true;
391
+ for (const d of entry.days)
392
+ d.items = d.items.filter((it) => !(typeof it.parent === "string" && keys[it.parent]));
393
+ // 日は新しい順・「日付の分からない物」(unknown)は最後
394
+ entry.days.sort((a, b) => (a.day === b.day ? 0 : a.day === "unknown" ? 1 : b.day === "unknown" ? -1 : a.day < b.day ? 1 : -1));
395
+ out.push(entry);
396
+ }
397
+ out.sort((a, b) => b.count - a.count || (a.tool < b.tool ? -1 : a.tool > b.tool ? 1 : 0));
398
+ return out;
399
+ }
400
+ /** 材料の数の 1 文(「4 件(Slack 2・Backlog 1・会議 1)」)。数の多い順 */
401
+ function runMaterialSummaryOf(materials, table) {
402
+ const m = materials && typeof materials === "object" ? materials : {};
403
+ const total = Number.isSafeInteger(m.total) && m.total >= 0 ? m.total : 0;
404
+ const by = m.byTool && typeof m.byTool === "object" ? m.byTool : {};
405
+ const parts = Object.keys(by)
406
+ .filter((k) => Number.isSafeInteger(by[k]) && by[k] > 0)
407
+ .sort((a, b) => by[b] - by[a] || (a < b ? -1 : a > b ? 1 : 0))
408
+ .map((k) => runToolWordOf(k, table) + " " + by[k]);
409
+ return total + " 件" + (parts.length ? "(" + parts.join("・") + ")" : "");
410
+ }
411
+ /** 元のツールへのリンクにしてよい URL か(https だけ・窓口も絞るが画面でも絞る=二重の守り)。だめなら null */
412
+ function runSafeUrlOf(url) {
413
+ return typeof url === "string" && url.length <= 2048 && url.indexOf("https://") === 0 ? url : null;
414
+ }
415
+ /** 材料の鍵 → 題(記録ごとの材料・コメントの親の題を引く)。この回の材料と前の回の材料(`memory.refs`)から */
416
+ function runMaterialIndexOf(report) {
417
+ const out = {};
418
+ const r = report && typeof report === "object" ? report : {};
419
+ const groups = r.materials && Array.isArray(r.materials.groups) ? r.materials.groups : [];
420
+ for (const g of groups)
421
+ for (const it of g && Array.isArray(g.items) ? g.items : [])
422
+ if (it && typeof it.key === "string")
423
+ out[it.key] = it;
424
+ const refs = r.memory && Array.isArray(r.memory.refs) ? r.memory.refs : [];
425
+ for (const it of refs)
426
+ if (it && typeof it.key === "string" && !out[it.key])
427
+ out[it.key] = it;
428
+ return out;
429
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takagaki/cortex-decisions-viewer",
3
- "version": "0.12.270",
3
+ "version": "0.12.276",
4
4
  "description": "Cortexの意思決定記録(Decisions/*.md)を静的サイトにビルドして閲覧する。各レコードに「Edit on GitHub」リンクを付与する。",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,