@takagaki/cortex-decisions-viewer 0.12.270 → 0.12.278
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/dist/build.js +151 -31
- package/dist/forward-reads.js +98 -0
- package/dist/intake-code-lines.js +19 -0
- package/dist/intake-scope.js +2 -1
- package/dist/member-page.js +235 -0
- package/dist/memory-evidence.js +33 -1
- package/dist/render.js +967 -84
- package/dist/run-history.js +435 -0
- package/package.json +1 -1
|
@@ -0,0 +1,435 @@
|
|
|
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
|
+
* 行のきっかけの語(開始の押しは「開始」・毎晩・今すぐ更新・運営)。知らない語は空文字。
|
|
106
|
+
* 表は引数で受ける(`RUN_CAUSE_WORDS`・`RUN_KIND_WORDS`・forward-reads.ts。題材の `expects.words` と突き合わせる)
|
|
107
|
+
*/
|
|
108
|
+
function runCauseWordOf(row, causes, kinds) {
|
|
109
|
+
if (!row || typeof row !== "object")
|
|
110
|
+
return "";
|
|
111
|
+
if (typeof row.kind === "string" && Object.prototype.hasOwnProperty.call(kinds, row.kind))
|
|
112
|
+
return kinds[row.kind];
|
|
113
|
+
return typeof row.cause === "string" && Object.prototype.hasOwnProperty.call(causes, row.cause) ? causes[row.cause] : "";
|
|
114
|
+
}
|
|
115
|
+
/** 行の最後の試行(`runId`・`attempt` の大きい方。並びに頼らない)。形の違う試行は飛ばす。無ければ null */
|
|
116
|
+
function runLastAttemptOf(row) {
|
|
117
|
+
const attempts = row && Array.isArray(row.attempts) ? row.attempts : [];
|
|
118
|
+
let lastA = null;
|
|
119
|
+
for (const a of attempts) {
|
|
120
|
+
if (!a || !(Number.isSafeInteger(a.runId) && a.runId > 0) || !(Number.isSafeInteger(a.attempt) && a.attempt > 0))
|
|
121
|
+
continue;
|
|
122
|
+
if (!lastA || a.runId > lastA.runId || (a.runId === lastA.runId && a.attempt > lastA.attempt))
|
|
123
|
+
lastA = a;
|
|
124
|
+
}
|
|
125
|
+
return lastA;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 行の状態(設計 §2「報告の無い行の言い分け」)。
|
|
129
|
+
* - `not_run` … 押したが走らなかった(試行も run へのリンクも無い・開始に失敗した押し)
|
|
130
|
+
* - `done` … それ以外(開けるかは `runRowOpenRunOf` が決める)
|
|
131
|
+
* 試行の結果の語(ポータルの `attempts[].outcome`)は、どれも終わった試行の語なので語で状態を分けない(語の一覧も持たない。
|
|
132
|
+
* 走っている側の語は契約に無い。cortex-engine #2896 便 MEMBER-ONE-TRUTH 3 版・仕上げ 2・tools 仕上げ 5)。
|
|
133
|
+
* 試行が 1 つも読めず run へのリンクだけがある行(試行の欄の無い古い行・結果の語が窓口の形を外れて落ちた試行)も `done` だが、
|
|
134
|
+
* 結果の文は言い切らない(`runRowResultTextOf` はポータルの文だけを出す)
|
|
135
|
+
*/
|
|
136
|
+
function runRowStateOf(row) {
|
|
137
|
+
if (runLastAttemptOf(row))
|
|
138
|
+
return "done";
|
|
139
|
+
return row && typeof row.runUrl === "string" && row.runUrl ? "done" : "not_run";
|
|
140
|
+
}
|
|
141
|
+
/** 行から開く回(最後の試行の `<runId>-<attempt>`)。試行が無ければ null(開けない) */
|
|
142
|
+
function runRowOpenRunOf(row) {
|
|
143
|
+
const lastA = runLastAttemptOf(row);
|
|
144
|
+
return lastA ? lastA.runId + "-" + lastA.attempt : null;
|
|
145
|
+
}
|
|
146
|
+
/** 行の結果の 1 文。ポータルの文(`message`)があればそれ、無ければ空文字(試行の結果の語から文を作らない=言い切らない) */
|
|
147
|
+
function runRowResultTextOf(row) {
|
|
148
|
+
if (runRowStateOf(row) === "not_run")
|
|
149
|
+
return "走りませんでした";
|
|
150
|
+
return row && typeof row.message === "string" && row.message.trim() ? row.message.trim() : "";
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 窓口の答え(一覧・1 回の中身)が 200 でないときの 1 文と、名乗り券を読み直すか。
|
|
154
|
+
* 入口の門の断り(券・参加)と、口がまだ無い一覧の 404 は共通の表(`INTAKE_CODE_LINES`・引数 `lines`)の 1 行と一手
|
|
155
|
+
* (cortex-engine #2896 便 MEMBER-ONE-TRUTH 3 版・リーダーの決め 1)。ほかの 403 は見る権限が無い・1 回のページの 404 は見つからない・
|
|
156
|
+
* 大きすぎる控えは言い分ける・ほか(届かない・5xx・打ち切り)は待ってから開き直す。
|
|
157
|
+
* `page` は `"list"`(一覧)か `"run"`(1 回のページ)。1 回のページの 404 は「見えない回・無い回」(運営の回が在るかを漏らさないので分けない)。
|
|
158
|
+
* 一覧(ポータルの memory-history の答え)の 400・403 で、この画面の表(`RUN_LIST_CODE_LINES`・引数 `codes`・forward-reads.ts)に在る語は、その 1 行。
|
|
159
|
+
* **クロージャを持たない純関数に保つこと**(`.toString()` でクライアントへ渡す)
|
|
160
|
+
*/
|
|
161
|
+
function runFailTextOf(status, body, lines, page, codes) {
|
|
162
|
+
const code = body && typeof body === "object" ? body.code : undefined;
|
|
163
|
+
const refused = status === 400 || status === 403;
|
|
164
|
+
const gate = refused && typeof code === "string" && Object.prototype.hasOwnProperty.call(lines, code) ? lines[code] : null;
|
|
165
|
+
if (gate)
|
|
166
|
+
return { text: gate.text, reopen: gate.forgetTicket };
|
|
167
|
+
if (page === "list" && refused && typeof code === "string" && Object.prototype.hasOwnProperty.call(codes, code))
|
|
168
|
+
return { text: codes[code], reopen: false };
|
|
169
|
+
if (status === 403)
|
|
170
|
+
return { text: "この案件の更新の記録を見る権限がありません", reopen: false };
|
|
171
|
+
if (status === 404 && page === "list")
|
|
172
|
+
return { text: lines.NOT_FOUND.text, reopen: false };
|
|
173
|
+
if (status === 404 || status === 400)
|
|
174
|
+
return { text: "この回は見つかりません(見られない回か、古い回です)", reopen: false };
|
|
175
|
+
if (status === 503 && code === "TOO_LARGE")
|
|
176
|
+
return { text: "この回の中身は大きすぎて、ここには出せません", reopen: false };
|
|
177
|
+
return { text: "更新の記録を読めませんでした。少し待ってから開き直してください", reopen: false };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 一覧の `status`(ok 以外)の 1 文。ok は null(行を並べる)。語ごとの文は表(`RUN_HISTORY_STATUS_LINES`・forward-reads.ts)から引く。
|
|
181
|
+
* 表に無い語は「読めませんでした」
|
|
182
|
+
*/
|
|
183
|
+
function runHistoryStatusTextOf(status, lines) {
|
|
184
|
+
if (status === "ok")
|
|
185
|
+
return null;
|
|
186
|
+
if (typeof status === "string" && Object.prototype.hasOwnProperty.call(lines, status))
|
|
187
|
+
return lines[status];
|
|
188
|
+
return "更新の記録を読めませんでした。少し待ってから開き直してください";
|
|
189
|
+
}
|
|
190
|
+
/** 回の結果の語(報告の `outcome`)。知らない語は空文字 */
|
|
191
|
+
function runOutcomeTextOf(outcome) {
|
|
192
|
+
const words = {
|
|
193
|
+
landed: "記憶に入りました",
|
|
194
|
+
partial: "一部だけ記憶に入りました",
|
|
195
|
+
lost: "記憶に入りませんでした",
|
|
196
|
+
no_diff: "新しく記憶にする物はありませんでした",
|
|
197
|
+
unverified: "記憶に入ったか確かめられませんでした",
|
|
198
|
+
failed: "途中で失敗しました",
|
|
199
|
+
};
|
|
200
|
+
return Object.prototype.hasOwnProperty.call(words, outcome) ? words[outcome] : "";
|
|
201
|
+
}
|
|
202
|
+
/** 回の種類の語(きっかけと開始の何回目か)。報告の `cause`・`phase` から */
|
|
203
|
+
function runKindTextOf(cause, phase) {
|
|
204
|
+
if (phase === "first")
|
|
205
|
+
return "開始の 1 回目";
|
|
206
|
+
if (phase === "second")
|
|
207
|
+
return "開始の 2 回目";
|
|
208
|
+
if (phase === "again")
|
|
209
|
+
return "開始のやり直し";
|
|
210
|
+
const words = { schedule: "毎晩の更新", manual: "今すぐ更新", operator: "運営の更新" };
|
|
211
|
+
return Object.prototype.hasOwnProperty.call(words, cause) ? words[cause] : "";
|
|
212
|
+
}
|
|
213
|
+
/** 材料は日ごとにも畳むか(最初の回=開始の回と範囲の回は日数が多い・設計 §2「量」) */
|
|
214
|
+
function runFoldByDayOf(report) {
|
|
215
|
+
if (!report || typeof report !== "object")
|
|
216
|
+
return false;
|
|
217
|
+
if (report.phase === "first" || report.phase === "again")
|
|
218
|
+
return true;
|
|
219
|
+
return typeof report.route === "string" && report.route.indexOf("range.") === 0;
|
|
220
|
+
}
|
|
221
|
+
/** 区画の名前(記憶のタブの名前と同じ) */
|
|
222
|
+
function runSectionLabelOf(section) {
|
|
223
|
+
const words = { decisions: "決定事項", glossary: "用語集", members: "関係者", rules: "ルール", stories: "ストーリー" };
|
|
224
|
+
return Object.prototype.hasOwnProperty.call(words, section) ? words[section] : "";
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 区画ごとの数(新しく・更新・消した)。並びは記憶のタブの順。どれも 0 の区画は出さない
|
|
228
|
+
* @returns `[{ section, label, new, updated, removed }]`
|
|
229
|
+
*/
|
|
230
|
+
function runSectionCountsOf(bySection) {
|
|
231
|
+
const order = ["decisions", "glossary", "members", "rules", "stories"];
|
|
232
|
+
const out = [];
|
|
233
|
+
const src = bySection && typeof bySection === "object" ? bySection : {};
|
|
234
|
+
for (const s of order) {
|
|
235
|
+
const c = src[s];
|
|
236
|
+
if (!c || typeof c !== "object")
|
|
237
|
+
continue;
|
|
238
|
+
const n = (v) => (Number.isSafeInteger(v) && v > 0 ? v : 0);
|
|
239
|
+
const row = { section: s, label: runSectionLabelOf(s), new: n(c.new), updated: n(c.updated), removed: n(c.removed) };
|
|
240
|
+
if (row.new + row.updated + row.removed > 0)
|
|
241
|
+
out.push(row);
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
/** 区画の数の 1 文(「新しく 1 件・更新 2 件」)。0 の語は出さない */
|
|
246
|
+
function runCountsTextOf(c) {
|
|
247
|
+
const parts = [];
|
|
248
|
+
if (c && c.new > 0)
|
|
249
|
+
parts.push("新しく " + c.new + " 件");
|
|
250
|
+
if (c && c.updated > 0)
|
|
251
|
+
parts.push("更新 " + c.updated + " 件");
|
|
252
|
+
if (c && c.removed > 0)
|
|
253
|
+
parts.push("消した " + c.removed + " 件");
|
|
254
|
+
return parts.join("・");
|
|
255
|
+
}
|
|
256
|
+
/** 記録の変わり方の語 */
|
|
257
|
+
function runRecordChangeWordOf(change) {
|
|
258
|
+
const words = { new: "新しく", updated: "更新", removed: "消した", renamed: "名前を変えた" };
|
|
259
|
+
return Object.prototype.hasOwnProperty.call(words, change) ? words[change] : "";
|
|
260
|
+
}
|
|
261
|
+
/** 材料の変わり方の語 */
|
|
262
|
+
function runItemChangeWordOf(change) {
|
|
263
|
+
const words = { new: "新しく", changed: "変わった", gone: "消えた" };
|
|
264
|
+
return Object.prototype.hasOwnProperty.call(words, change) ? words[change] : "";
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* ツールの名前。名前は直書きせず、つなぎ先の行(データソース一覧)と同じ出どころ
|
|
268
|
+
* (`SOURCE_ROW_TOOLS`=接続先の表の写し。鍵か `tool` が一致する行の `toolName`)から受け取る。表に無い名前はそのまま出す
|
|
269
|
+
* (ここには「種類の言葉」〈会議・資料〉だけを持つ。ツールの名前は持たない)
|
|
270
|
+
* @param table `{ 種類: { tool, toolName } }`(接続先の表)
|
|
271
|
+
*/
|
|
272
|
+
function runToolWordOf(tool, table) {
|
|
273
|
+
const name = String(tool || "");
|
|
274
|
+
const has = (o, k) => !!o && typeof o === "object" && Object.prototype.hasOwnProperty.call(o, k);
|
|
275
|
+
if (table && typeof table === "object") {
|
|
276
|
+
if (has(table, name) && typeof table[name].toolName === "string")
|
|
277
|
+
return table[name].toolName;
|
|
278
|
+
for (const k of Object.keys(table)) {
|
|
279
|
+
if (table[k] && table[k].tool === name && typeof table[k].toolName === "string")
|
|
280
|
+
return table[k].toolName;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const kinds = { meeting: "会議", materials: "資料", file: "資料" };
|
|
284
|
+
return has(kinds, name) ? kinds[name] : name;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* 会話の場の名前。報告に焼いた `venueName` が正、無ければ案件の接続先の一覧(`externalSources`・Slack はチャンネル ID と
|
|
288
|
+
* ワークスペース)から引く。どちらも無ければ Slack は「Slack のチャンネル」、Google Chat・Teams は「スペース」(設計 §2「名前」)
|
|
289
|
+
*/
|
|
290
|
+
function runVenueNameOf(item, sources) {
|
|
291
|
+
const v = item && item.venue && typeof item.venue === "object" ? item.venue : {};
|
|
292
|
+
const tool = typeof v.tool === "string" ? v.tool : "";
|
|
293
|
+
const hash = (s) => (tool === "slack" ? "#" + s.replace(/^#+/, "") : s);
|
|
294
|
+
if (item && typeof item.venueName === "string" && item.venueName.trim())
|
|
295
|
+
return hash(item.venueName.trim());
|
|
296
|
+
if (typeof v.ref === "string" && v.ref) {
|
|
297
|
+
for (const s of Array.isArray(sources) ? sources : []) {
|
|
298
|
+
if (!s || s.ref !== v.ref || typeof s.name !== "string" || !s.name.trim() || s.name.indexOf("(名前未取得") === 0)
|
|
299
|
+
continue;
|
|
300
|
+
if (tool === "slack" && s.type !== "slack")
|
|
301
|
+
continue;
|
|
302
|
+
if (tool === "slack" && s.workspace && v.ws && s.workspace !== v.ws)
|
|
303
|
+
continue;
|
|
304
|
+
return hash(s.name.trim());
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return tool === "slack" ? "Slack のチャンネル" : "スペース";
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* 材料 1 つの名前(設計 §3「本文は出さない」の線)。
|
|
311
|
+
* - 題の有る物は `label`(engine の `evidenceLabelOf` の名前)か題
|
|
312
|
+
* - 会話(Slack・Google Chat・Teams・`message.*`): 「<場> · 11/14 18:05 のスレッド(返信 N 件)」「…の発言」「…のスレッドへの返信」
|
|
313
|
+
* - コメント: 「<親の題> へのコメント」(親の題が分からなければ「コメント」)。題の無いコメントは label より先に見る
|
|
314
|
+
* - GitHub の題の無い PR・Issue・コミット: 「<リポ> の PR #N」「<リポ> の Issue #N」「<リポ> のコミット 1a2b3c4」
|
|
315
|
+
* - 消えた物(題を持たない): 「(消えた材料)」・ほかの題の無い物は「(題を伏せています)」(秘密らしい題)
|
|
316
|
+
* @param ctx `{ sources: externalSources, titles: { 鍵: 題 } }`(親の題を引く)
|
|
317
|
+
*/
|
|
318
|
+
function runMaterialNameOf(item, ctx) {
|
|
319
|
+
if (!item || typeof item !== "object")
|
|
320
|
+
return "";
|
|
321
|
+
const label = typeof item.label === "string" && item.label.trim() ? item.label.trim() : "";
|
|
322
|
+
const title = typeof item.title === "string" && item.title.trim() ? item.title.trim() : "";
|
|
323
|
+
const c = ctx && typeof ctx === "object" ? ctx : {};
|
|
324
|
+
const v = item.venue && typeof item.venue === "object" ? item.venue : {};
|
|
325
|
+
const tool = typeof v.tool === "string" ? v.tool : "";
|
|
326
|
+
const kind = typeof item.kind === "string" ? item.kind : "";
|
|
327
|
+
// 🔴 コメントは label より先に見る(engine の evidenceLabelOf は題の無いコメントに親の題を付けるので、label のままだと親と同じ名前で並ぶ)
|
|
328
|
+
if (!title && kind.indexOf("comment") >= 0) {
|
|
329
|
+
const titles = c.titles && typeof c.titles === "object" ? c.titles : {};
|
|
330
|
+
const pt = typeof item.parent === "string" && typeof titles[item.parent] === "string" ? titles[item.parent] : label;
|
|
331
|
+
return pt ? pt + " へのコメント" : "コメント";
|
|
332
|
+
}
|
|
333
|
+
if (label || title)
|
|
334
|
+
return label || title;
|
|
335
|
+
if (tool === "slack" || tool === "google-chat" || tool === "teams" || kind.indexOf("message.") === 0) {
|
|
336
|
+
const at = runJstText(item.at);
|
|
337
|
+
const head = runVenueNameOf(item, c.sources) + (at ? " · " + at : "");
|
|
338
|
+
if (typeof item.parent === "string" && item.parent)
|
|
339
|
+
return head + " のスレッドへの返信";
|
|
340
|
+
if (Number.isSafeInteger(item.replies) && item.replies > 0)
|
|
341
|
+
return head + " のスレッド(返信 " + item.replies + " 件)";
|
|
342
|
+
return head + " の発言";
|
|
343
|
+
}
|
|
344
|
+
if (item.change === "gone")
|
|
345
|
+
return "(消えた材料)";
|
|
346
|
+
// GitHub の題の無い PR・Issue・コミットは「<リポ> の PR #N」(鍵の最後の 2 段・設計 §3)
|
|
347
|
+
if (tool === "github" && typeof item.key === "string") {
|
|
348
|
+
const segs = item.key.split(":");
|
|
349
|
+
const dec = (x) => { try {
|
|
350
|
+
return decodeURIComponent(x);
|
|
351
|
+
}
|
|
352
|
+
catch (e) {
|
|
353
|
+
return "";
|
|
354
|
+
} };
|
|
355
|
+
const repo = dec(String(typeof v.ref === "string" && v.ref !== "-" ? v.ref : segs[segs.length - 3] || ""));
|
|
356
|
+
const type = segs[segs.length - 2];
|
|
357
|
+
const id = dec(segs[segs.length - 1] || "");
|
|
358
|
+
if (repo && /^[0-9]{1,9}$/.test(id) && (type === "pr" || type === "pull"))
|
|
359
|
+
return repo + " の PR #" + id;
|
|
360
|
+
if (repo && /^[0-9]{1,9}$/.test(id) && type === "issue")
|
|
361
|
+
return repo + " の Issue #" + id;
|
|
362
|
+
if (repo && /^[0-9a-f]{7,40}$/i.test(id) && type === "commit")
|
|
363
|
+
return repo + " のコミット " + id.slice(0, 7);
|
|
364
|
+
}
|
|
365
|
+
return "(題を伏せています)";
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* 「この回に入った材料」を、ツールごと(最初の回は日ごとにも)に畳む形に組む。
|
|
369
|
+
* スレッドの返信は、親が同じツールの中に並ぶときは親の 1 行にまとめる(親の行が「返信 N 件」を言う)。
|
|
370
|
+
* 項目の数(`count`)が並べた数より多い所は `more`(数だけ出す分)を持つ。
|
|
371
|
+
* @returns `[{ tool, count, more, days: [{ day, count, more, items }] }]`(ツールの並びは数の多い順・同数は名前順。日は新しい順)
|
|
372
|
+
*/
|
|
373
|
+
function runMaterialFoldOf(materials) {
|
|
374
|
+
const groups = materials && Array.isArray(materials.groups) ? materials.groups : [];
|
|
375
|
+
const byTool = {};
|
|
376
|
+
const order = [];
|
|
377
|
+
for (const g of groups) {
|
|
378
|
+
if (!g || typeof g.tool !== "string" || typeof g.day !== "string")
|
|
379
|
+
continue;
|
|
380
|
+
if (!byTool[g.tool]) {
|
|
381
|
+
byTool[g.tool] = { tool: g.tool, count: 0, more: 0, days: [] };
|
|
382
|
+
order.push(g.tool);
|
|
383
|
+
}
|
|
384
|
+
const items = Array.isArray(g.items) ? g.items.filter((x) => x && typeof x.key === "string") : [];
|
|
385
|
+
const count = Number.isSafeInteger(g.count) && g.count >= items.length ? g.count : items.length;
|
|
386
|
+
byTool[g.tool].days.push({ day: g.day, count, more: count - items.length, items });
|
|
387
|
+
byTool[g.tool].count += count;
|
|
388
|
+
byTool[g.tool].more += count - items.length;
|
|
389
|
+
}
|
|
390
|
+
const out = [];
|
|
391
|
+
for (const t of order) {
|
|
392
|
+
const entry = byTool[t];
|
|
393
|
+
const keys = {};
|
|
394
|
+
for (const d of entry.days)
|
|
395
|
+
for (const it of d.items)
|
|
396
|
+
keys[it.key] = true;
|
|
397
|
+
for (const d of entry.days)
|
|
398
|
+
d.items = d.items.filter((it) => !(typeof it.parent === "string" && keys[it.parent]));
|
|
399
|
+
// 日は新しい順・「日付の分からない物」(unknown)は最後
|
|
400
|
+
entry.days.sort((a, b) => (a.day === b.day ? 0 : a.day === "unknown" ? 1 : b.day === "unknown" ? -1 : a.day < b.day ? 1 : -1));
|
|
401
|
+
out.push(entry);
|
|
402
|
+
}
|
|
403
|
+
out.sort((a, b) => b.count - a.count || (a.tool < b.tool ? -1 : a.tool > b.tool ? 1 : 0));
|
|
404
|
+
return out;
|
|
405
|
+
}
|
|
406
|
+
/** 材料の数の 1 文(「4 件(Slack 2・Backlog 1・会議 1)」)。数の多い順 */
|
|
407
|
+
function runMaterialSummaryOf(materials, table) {
|
|
408
|
+
const m = materials && typeof materials === "object" ? materials : {};
|
|
409
|
+
const total = Number.isSafeInteger(m.total) && m.total >= 0 ? m.total : 0;
|
|
410
|
+
const by = m.byTool && typeof m.byTool === "object" ? m.byTool : {};
|
|
411
|
+
const parts = Object.keys(by)
|
|
412
|
+
.filter((k) => Number.isSafeInteger(by[k]) && by[k] > 0)
|
|
413
|
+
.sort((a, b) => by[b] - by[a] || (a < b ? -1 : a > b ? 1 : 0))
|
|
414
|
+
.map((k) => runToolWordOf(k, table) + " " + by[k]);
|
|
415
|
+
return total + " 件" + (parts.length ? "(" + parts.join("・") + ")" : "");
|
|
416
|
+
}
|
|
417
|
+
/** 元のツールへのリンクにしてよい URL か(https だけ・窓口も絞るが画面でも絞る=二重の守り)。だめなら null */
|
|
418
|
+
function runSafeUrlOf(url) {
|
|
419
|
+
return typeof url === "string" && url.length <= 2048 && url.indexOf("https://") === 0 ? url : null;
|
|
420
|
+
}
|
|
421
|
+
/** 材料の鍵 → 題(記録ごとの材料・コメントの親の題を引く)。この回の材料と前の回の材料(`memory.refs`)から */
|
|
422
|
+
function runMaterialIndexOf(report) {
|
|
423
|
+
const out = {};
|
|
424
|
+
const r = report && typeof report === "object" ? report : {};
|
|
425
|
+
const groups = r.materials && Array.isArray(r.materials.groups) ? r.materials.groups : [];
|
|
426
|
+
for (const g of groups)
|
|
427
|
+
for (const it of g && Array.isArray(g.items) ? g.items : [])
|
|
428
|
+
if (it && typeof it.key === "string")
|
|
429
|
+
out[it.key] = it;
|
|
430
|
+
const refs = r.memory && Array.isArray(r.memory.refs) ? r.memory.refs : [];
|
|
431
|
+
for (const it of refs)
|
|
432
|
+
if (it && typeof it.key === "string" && !out[it.key])
|
|
433
|
+
out[it.key] = it;
|
|
434
|
+
return out;
|
|
435
|
+
}
|
package/package.json
CHANGED