@infodb/p3 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -35
- package/bin/p3.mjs +3 -2
- package/dist/web/assets/CompletionReview-BD7d6Yzt.js +1 -0
- package/dist/web/assets/ImprovementDialog-BoAZN1KR.js +1 -0
- package/dist/web/assets/Outputs-D-ZouoxF.js +1 -0
- package/dist/web/assets/RequestStatus-Bl3fdSbM.js +1 -0
- package/dist/web/assets/Tabs-CxeceOL-.js +1 -0
- package/dist/web/assets/TagInput-CeAbmGRR.js +1 -0
- package/dist/web/assets/TaskDrawer-BCriSnhe.js +6 -0
- package/dist/web/assets/_requestId-CZKMe_mC.js +1 -0
- package/dist/web/assets/_requestId-Fx4lLkFo.js +1 -0
- package/dist/web/assets/appCtx-BdxbkSZa.js +1 -0
- package/dist/web/assets/archive-D5IIxcSV.js +1 -0
- package/dist/web/assets/board-p6R9KMqd.js +1 -0
- package/dist/web/assets/done-BTOF188x.js +1 -0
- package/dist/web/assets/draft-BWYpm3PD.js +2 -0
- package/dist/web/assets/index-DFbY8NAR.css +2 -0
- package/dist/web/assets/index-Dpqi2dcC.js +12 -0
- package/dist/web/assets/link-D481whDt.js +1 -0
- package/dist/web/assets/metrics-CAzP6V8I.js +1 -0
- package/dist/web/assets/new-C65IJJg3.js +1 -0
- package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
- package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
- package/dist/web/assets/preload-helper-_dAYMct_.js +1 -0
- package/dist/web/assets/{quality-Pu6EISAM.js → quality-RFd-7k3r.js} +1 -1
- package/dist/web/assets/release-notes-Dtif8xsQ.js +5 -0
- package/dist/web/assets/requestData-SPc36t8Q.js +1 -0
- package/dist/web/assets/routes-DJj8CWuk.js +6 -0
- package/dist/web/assets/settings-DKJd7CLe.js +1 -0
- package/dist/web/assets/ui-CbEOnPnF.js +1 -0
- package/dist/web/assets/workTarget-DavxMs-c.js +30 -0
- package/dist/web/index.html +6 -4
- package/docs/architecture.md +430 -72
- package/docs/chatgpt-sign-in.md +2 -2
- package/docs/development.md +141 -64
- package/docs/feature-inventory.md +139 -0
- package/docs/how-to-use.md +389 -31
- package/docs/installation.md +261 -147
- package/docs/publishing.md +33 -14
- package/docs/refactoring.md +332 -0
- package/lib/cli/agentsStatus.js +198 -0
- package/lib/cli/guide.js +27 -0
- package/lib/cli/guide.md +217 -0
- package/lib/cli/help.js +45 -7
- package/lib/cli/main.js +58 -207
- package/lib/cli/project.js +34 -294
- package/lib/core/projectRegistry.js +2 -2
- package/lib/kit/appInfo.js +13 -0
- package/lib/kit/usage.js +27 -0
- package/lib/server/api/projectsRoutes.js +5 -5
- package/lib/server/server.js +7 -4
- package/lib/{cli → tasks/cli}/args.js +73 -9
- package/lib/{cli → tasks/cli}/chatgpt.js +1 -1
- package/lib/{cli → tasks/cli}/codex.js +1 -1
- package/lib/{cli → tasks/cli}/output.js +12 -2
- package/lib/{cli → tasks/cli}/preflightCommands.js +1 -1
- package/lib/tasks/cli/readOnly.js +75 -0
- package/lib/{cli → tasks/cli}/render.js +1 -1
- package/lib/{cli → tasks/cli}/requestCommands.js +24 -7
- package/lib/tasks/cli/showView.js +279 -0
- package/lib/{cli → tasks/cli}/taskCommands.js +55 -21
- package/lib/tasks/cli/tasksCli.js +149 -0
- package/lib/{core → tasks/core}/context.js +6 -9
- package/lib/tasks/core/errorOutcome.js +125 -0
- package/lib/{core → tasks/core}/hierarchy.js +1 -1
- package/lib/{core → tasks/core}/ops.js +17 -2
- package/lib/{core → tasks/core}/preflight/carryover.js +5 -1
- package/lib/{core → tasks/core}/preflight/codexEngine.js +36 -28
- package/lib/{core → tasks/core}/preflight/diagnose.js +4 -9
- package/lib/{core → tasks/core}/preflight/engine.js +9 -0
- package/lib/tasks/core/preflight/hostPaths.js +299 -0
- package/lib/{core → tasks/core}/preflight/input.js +33 -5
- package/lib/{core → tasks/core}/preflight/instructions.js +19 -2
- package/lib/{core → tasks/core}/preflight/mockEngine.js +27 -8
- package/lib/{core → tasks/core}/preflight/render.js +22 -3
- package/lib/{core → tasks/core}/preflight/service.js +86 -11
- package/lib/{core → tasks/core}/preflight/uiRender.js +5 -2
- package/lib/{core → tasks/core}/requestOps.js +214 -17
- package/lib/{core → tasks/core}/reviewRuns.js +127 -22
- package/lib/{core → tasks/core}/store/attachments.js +3 -2
- package/lib/{core → tasks/core}/store/collection.js +21 -2
- package/lib/tasks/core/store/fieldGroups.js +30 -0
- package/lib/tasks/core/store/jsonRecord.js +30 -0
- package/lib/{core → tasks/core}/store/normalize.js +15 -10
- package/lib/{core → tasks/core}/store/noteStore.js +2 -2
- package/lib/{core → tasks/core}/store/preflightStore.js +59 -22
- package/lib/{core → tasks/core}/store/projectFile.js +1 -1
- package/lib/{core → tasks/core}/store/workspace.js +28 -6
- package/lib/{core → tasks/core}/userConfig.js +1 -1
- package/lib/{core → tasks/core}/workTargets.js +1 -1
- package/lib/tasks/features/metrics/cli/metricsCommands.js +77 -0
- package/lib/tasks/features/metrics/core/definitions.js +445 -0
- package/lib/tasks/features/metrics/core/index.js +112 -0
- package/lib/tasks/features/metrics/core/manual.js +179 -0
- package/lib/tasks/features/metrics/server/metricsRoutes.js +8 -0
- package/lib/tasks/features/metrics/shared/metrics.js +42 -0
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/code.js +2 -11
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/material.js +5 -6
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/review.js +2 -2
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/service.js +38 -100
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/store.js +3 -3
- package/lib/{server/api → tasks/features/milestoneReview/server}/milestoneReviewRoutes.js +7 -13
- package/lib/{cli → tasks/features/quality/cli}/qualityCommands.js +36 -11
- package/lib/{core → tasks/features/quality/core}/qualityImprovement.js +16 -15
- package/lib/tasks/features/records/cli/revisitCommands.js +73 -0
- package/lib/tasks/features/records/core/completionRefs.js +46 -0
- package/lib/tasks/features/records/core/reviewCandidates.js +76 -0
- package/lib/tasks/features/records/shared/completionRecord.js +329 -0
- package/lib/tasks/features/records/shared/reviewCandidate.js +313 -0
- package/lib/tasks/features/records/shared/reworkHistory.js +86 -0
- package/lib/{cli → tasks/features/releaseNotes/cli}/releaseNotesCommands.js +7 -7
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/completeRequests.js +5 -6
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/generate.js +3 -14
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/material.js +3 -4
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/service.js +1 -1
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/store.js +2 -2
- package/lib/{server/api → tasks/features/releaseNotes/server}/releaseNoteRoutes.js +11 -20
- package/lib/tasks/features/requirements/cli/requirementCommands.js +289 -0
- package/lib/{shared → tasks/features/requirements/shared}/acceptance.js +292 -18
- package/lib/tasks/features/requirements/shared/requirementSource.js +635 -0
- package/lib/tasks/features/retro/cli/retroCommands.js +106 -0
- package/lib/tasks/features/retro/core/retrospective.js +197 -0
- package/lib/tasks/features/retro/shared/retrospective.js +286 -0
- package/lib/tasks/features/settings/cli/projectSettings.js +245 -0
- package/lib/{cli → tasks/features/settings/cli}/userConfig.js +50 -3
- package/lib/{core → tasks/features/settings/core}/machineSettingsEdit.js +2 -2
- package/lib/{core → tasks/features/settings/core}/repoAdmin.js +3 -3
- package/lib/{core → tasks/features/settings/core}/userTheme.js +2 -2
- package/lib/{server/api → tasks/features/settings/server}/repoRoutes.js +2 -2
- package/lib/{server/api → tasks/features/settings/server}/userThemeRoutes.js +3 -3
- package/lib/{cli → tasks/features/taskReview/cli}/taskReviewCommands.js +5 -5
- package/lib/{core/taskReview → tasks/features/taskReview/core}/material.js +13 -7
- package/lib/{core/taskReview → tasks/features/taskReview/core}/review.js +10 -3
- package/lib/{core/taskReview → tasks/features/taskReview/core}/service.js +24 -85
- package/lib/{core/taskReview → tasks/features/taskReview/core}/store.js +4 -4
- package/lib/{server/api → tasks/features/taskReview/server}/taskReviewRoutes.js +7 -14
- package/lib/{server → tasks/server}/api/manifest.js +51 -3
- package/lib/{server → tasks/server}/api/routes.js +134 -65
- package/lib/tasks/shared/commitRefs.js +10 -0
- package/lib/{shared → tasks/shared}/preflightInput.js +1 -1
- package/package.json +1 -43
- package/skills/p3/SKILL.md +9 -181
- package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +0 -1
- package/dist/web/assets/Outputs-_nU_p3nu.js +0 -1
- package/dist/web/assets/RequestStatus-RG-OVQYY.js +0 -1
- package/dist/web/assets/Tabs-ew9i5SKX.js +0 -1
- package/dist/web/assets/TagInput-BtlJTF7i.js +0 -1
- package/dist/web/assets/TaskDrawer-DW8GyJqI.js +0 -6
- package/dist/web/assets/_requestId-6Nb727dD.js +0 -1
- package/dist/web/assets/_requestId-BykTgPax.js +0 -1
- package/dist/web/assets/appCtx-CxDdXABS.js +0 -1
- package/dist/web/assets/archive-Ckh295Xe.js +0 -1
- package/dist/web/assets/board-BVAIjK-Y.js +0 -1
- package/dist/web/assets/done-BGfA-3MA.js +0 -1
- package/dist/web/assets/draft-CfJeyLOl.js +0 -1
- package/dist/web/assets/index-CgRU744I.css +0 -2
- package/dist/web/assets/index-DacQ0yl4.js +0 -12
- package/dist/web/assets/new-DVygWvVc.js +0 -1
- package/dist/web/assets/outputs-B6xDsLZf.js +0 -1
- package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
- package/dist/web/assets/preload-helper-DyCqp21K.js +0 -1
- package/dist/web/assets/release-notes-CCpzyiNf.js +0 -5
- package/dist/web/assets/requestData-D5vBnuMh.js +0 -1
- package/dist/web/assets/routes-Q91zvNc0.js +0 -4
- package/dist/web/assets/settings-BzRgcmUm.js +0 -1
- package/dist/web/assets/workTarget-C9c57JAO.js +0 -30
- package/lib/cli/readOnly.js +0 -38
- package/lib/cli/showView.js +0 -166
- /package/lib/{core/store → kit}/frontmatter.js +0 -0
- /package/lib/{core/store → kit}/fsutil.js +0 -0
- /package/lib/{cli → tasks/cli}/format.js +0 -0
- /package/lib/{core → tasks/core}/chatgpt.js +0 -0
- /package/lib/{core → tasks/core}/machineSettings.js +0 -0
- /package/lib/{core → tasks/core}/preflight/codexImage.js +0 -0
- /package/lib/{core → tasks/core}/preflight/docker.js +0 -0
- /package/lib/{core → tasks/core}/preflight/launch.js +0 -0
- /package/lib/{core → tasks/core}/preflight/launcher.mjs +0 -0
- /package/lib/{core → tasks/core}/preflight/mock-ui.html +0 -0
- /package/lib/{core → tasks/core}/preflight/mock-ui.png +0 -0
- /package/lib/{core → tasks/core}/preflight/owner.js +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/Dockerfile +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/fonts-ja.conf +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/render.mjs +0 -0
- /package/lib/{core → tasks/core}/preflight/split.js +0 -0
- /package/lib/{core → tasks/core}/preflight/uiMaterials.js +0 -0
- /package/lib/{core → tasks/core}/preflight/wireframe.js +0 -0
- /package/lib/{core → tasks/core}/preflight/xlsx.js +0 -0
- /package/lib/{core → tasks/core}/redact.js +0 -0
- /package/lib/{core → tasks/core}/repoRefs.js +0 -0
- /package/lib/{core → tasks/core}/requestStatus.js +0 -0
- /package/lib/{core → tasks/core}/store/archivedTasks.js +0 -0
- /package/lib/{core → tasks/core}/store/dataWatcher.js +0 -0
- /package/lib/{core → tasks/core}/store/locate.js +0 -0
- /package/lib/{core → tasks/core}/supersede.js +0 -0
- /package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/mockReviewer.js +0 -0
- /package/lib/{shared → tasks/features/milestoneReview/shared}/milestoneReview.js +0 -0
- /package/lib/{core → tasks/features/quality/core}/quality.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/quality.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/qualityImprovement.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/qualityTemplates.js +0 -0
- /package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/mockSummarizer.js +0 -0
- /package/lib/{core/taskReview → tasks/features/taskReview/core}/mockReviewer.js +0 -0
- /package/lib/{core/taskReview → tasks/features/taskReview/core}/paths.js +0 -0
- /package/lib/{shared → tasks/features/taskReview/shared}/taskReview.js +0 -0
- /package/lib/{server → tasks/server}/api/chatgptRoutes.js +0 -0
- /package/lib/{server → tasks/server}/api/local.js +0 -0
- /package/lib/{shared → tasks/shared}/dates.js +0 -0
- /package/lib/{shared → tasks/shared}/directTask.js +0 -0
- /package/lib/{shared → tasks/shared}/hierarchy.js +0 -0
- /package/lib/{shared → tasks/shared}/milestoneGoals.js +0 -0
- /package/lib/{shared → tasks/shared}/milestoneOrder.js +0 -0
- /package/lib/{shared → tasks/shared}/preflightRunner.js +0 -0
- /package/lib/{shared → tasks/shared}/refs.js +0 -0
- /package/lib/{shared → tasks/shared}/repos.js +0 -0
- /package/lib/{shared → tasks/shared}/scopeView.js +0 -0
- /package/lib/{shared → tasks/shared}/tags.js +0 -0
- /package/lib/{shared → tasks/shared}/taskBlock.js +0 -0
- /package/lib/{shared → tasks/shared}/types.js +0 -0
- /package/lib/{shared → tasks/shared}/workTarget.js +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { readAcceptance } from "../../requirements/shared/acceptance.js";
|
|
2
|
+
import { qualityPlain, readQuality, standardsFor } from "../../quality/shared/quality.js";
|
|
3
|
+
import { readRequirement, requestSubject } from "../../requirements/shared/requirementSource.js";
|
|
4
|
+
/**
|
|
5
|
+
* 完了の記録(完了・人の済み・対応済・完了済にしたときの条件の写し)の規則。CLI・API・画面で同じものを使う
|
|
6
|
+
* (保存は core/requestOps.ts の createTask / updateTask / updateRequest がこれで作る)。
|
|
7
|
+
*
|
|
8
|
+
* - タスク(task.md の completionRecords)と要望(request.md の completionRecords)に追記だけで持つ。状態と同じ rev の更新で書くので、
|
|
9
|
+
* 片方だけが保存されることはない。再開・済みの解除でも消さず、再完了・再確認で新しい記録を足す。同じ状態の再保存・成果物の追記では足さない
|
|
10
|
+
* - 契機は、タスクの完了(task_done)・人の済み(task_checked。人の最終確認で、AI の承認ではない)・要望の対応済(request_resolved)・
|
|
11
|
+
* 要望の完了済(request_done)。日時・保存した主体(by。アクターの名前)・書いた後の rev と状態を持つ
|
|
12
|
+
* - 写すもの: タスクは受け入れ基準(取り込んだ品質基準の版を含む)・証拠と根拠の種類・基準ごとの要求の根拠、要望の要求の根拠と確認履歴、
|
|
13
|
+
* 品質の状態・版・作業先に当てはまる項目と除外(完了したときの最新の値。取り込んだときの版は基準の quality に残る)。要望は題・本文の hash・
|
|
14
|
+
* 要求の根拠・品質の状態と版、完了の判定に使ったタスクと子の要望(ID・rev・状態・その時点の最新の記録 ID)
|
|
15
|
+
* - 参照先: 登録された参照先ごとに、取得した時点の HEAD のコミット・未コミットの変更の有無・取得時刻、取れなければ取れない理由
|
|
16
|
+
* (git でない・このマシンのパスなし・パスが無い・取得に失敗)。このマシンのパスは残さない。過去の Preflight の評価から推測して埋めない
|
|
17
|
+
* - 読めない条件(品質の設定・基準・根拠が壊れている)は problems として写し、完了は拒まない。記録の無い古いデータは補わず「記録なし」と読む
|
|
18
|
+
* - 複数のファイル(project.yaml・要望・タスク・参照先)を同じ瞬間に固定するものではない(それぞれ書く直前に読んだ値と取得時刻)
|
|
19
|
+
* - 直接編集で壊れた記録は黙って消さず completionProblems にし、関係のない更新ではファイルの元の値のまま書き戻す(keepRaw)。
|
|
20
|
+
* 壊れている間は新しい記録を足さない(完了は拒まず、足せなかったことを知らせる)
|
|
21
|
+
*/
|
|
22
|
+
export const COMPLETION_TRIGGERS = ["task_done", "task_checked", "request_resolved", "request_done"];
|
|
23
|
+
const isTrigger = (v) => typeof v === "string" && COMPLETION_TRIGGERS.includes(v);
|
|
24
|
+
export const COMPLETION_TRIGGER_LABEL = {
|
|
25
|
+
task_done: "タスクの完了",
|
|
26
|
+
task_checked: "人の済み(人の最終確認)",
|
|
27
|
+
request_resolved: "要望の対応済",
|
|
28
|
+
request_done: "要望の完了済",
|
|
29
|
+
};
|
|
30
|
+
/** 参照先を取得した結果。ok: 取得できた / not_git: git のリポジトリでない / unregistered: このマシンのパスなし / missing: パスが無い / notdir: フォルダでない / failed: git の実行に失敗 */
|
|
31
|
+
export const REF_CAPTURE_STATES = ["ok", "not_git", "unregistered", "missing", "notdir", "failed"];
|
|
32
|
+
const isRefState = (v) => typeof v === "string" && REF_CAPTURE_STATES.includes(v);
|
|
33
|
+
export const REF_CAPTURE_LABEL = {
|
|
34
|
+
ok: "取得",
|
|
35
|
+
not_git: "git でない",
|
|
36
|
+
unregistered: "このマシンのパスなし",
|
|
37
|
+
missing: "パスが無い",
|
|
38
|
+
notdir: "フォルダでない",
|
|
39
|
+
failed: "取得に失敗",
|
|
40
|
+
};
|
|
41
|
+
/** ファイルに書く項目(壊れていたら元の値のまま書き戻す) */
|
|
42
|
+
export const COMPLETION_KEYS = ["completionRecords"];
|
|
43
|
+
export const COMPLETION_ID_RE = /^C\d+$/;
|
|
44
|
+
// --- 読む ---------------------------------------------------------------------
|
|
45
|
+
const str = (v) => (typeof v === "string" && v ? v : undefined);
|
|
46
|
+
const iso = (v) => (v instanceof Date ? v.toISOString() : str(v));
|
|
47
|
+
const int = (v) => (Number.isInteger(v) && v >= 0 ? v : undefined);
|
|
48
|
+
const obj = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : undefined);
|
|
49
|
+
const strList = (v) => (Array.isArray(v) && v.every((x) => typeof x === "string") ? v : undefined);
|
|
50
|
+
function readQualityCondition(v) {
|
|
51
|
+
const o = obj(v);
|
|
52
|
+
if (!o)
|
|
53
|
+
return "quality が読めません";
|
|
54
|
+
const state = o.state;
|
|
55
|
+
if (state !== "unset" && state !== "set" && state !== "invalid")
|
|
56
|
+
return "quality.state が読めません(unset / set / invalid)";
|
|
57
|
+
const version = typeof o.version === "string" ? o.version : undefined;
|
|
58
|
+
if (version === undefined)
|
|
59
|
+
return "quality.version がありません";
|
|
60
|
+
const out = { state, version };
|
|
61
|
+
if ("repo" in o)
|
|
62
|
+
out.repo = typeof o.repo === "string" && o.repo ? o.repo : null;
|
|
63
|
+
if (o.standards !== undefined) {
|
|
64
|
+
const q = readQuality({ standards: o.standards });
|
|
65
|
+
if (q.state !== "set")
|
|
66
|
+
return `quality.standards が読めません: ${q.state === "invalid" ? q.problems.join(" / ") : ""}`;
|
|
67
|
+
out.standards = q.config.standards;
|
|
68
|
+
}
|
|
69
|
+
if (o.problems !== undefined) {
|
|
70
|
+
const p = strList(o.problems);
|
|
71
|
+
if (!p)
|
|
72
|
+
return "quality.problems が読めません";
|
|
73
|
+
out.problems = p;
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
function readAcceptanceCondition(v) {
|
|
78
|
+
const o = obj(v);
|
|
79
|
+
if (!o)
|
|
80
|
+
return "acceptance が読めません";
|
|
81
|
+
if (o.problems !== undefined) {
|
|
82
|
+
const p = strList(o.problems);
|
|
83
|
+
return p ? { problems: p } : "acceptance.problems が読めません";
|
|
84
|
+
}
|
|
85
|
+
const a = readAcceptance({ acceptanceCriteria: o.criteria, acceptanceEvidence: o.evidence, acceptanceSources: o.sources });
|
|
86
|
+
if (a.acceptanceProblems?.length)
|
|
87
|
+
return `acceptance が読めません: ${a.acceptanceProblems.join(" / ")}`;
|
|
88
|
+
return {
|
|
89
|
+
...(a.acceptanceCriteria?.length ? { criteria: a.acceptanceCriteria } : {}),
|
|
90
|
+
...(a.acceptanceEvidence?.length ? { evidence: a.acceptanceEvidence } : {}),
|
|
91
|
+
...(a.acceptanceSources?.length ? { sources: a.acceptanceSources } : {}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function readRequirementCondition(v) {
|
|
95
|
+
const o = obj(v);
|
|
96
|
+
if (!o)
|
|
97
|
+
return "requirement が読めません";
|
|
98
|
+
if (o.problems !== undefined) {
|
|
99
|
+
const p = strList(o.problems);
|
|
100
|
+
return p ? { problems: p } : "requirement.problems が読めません";
|
|
101
|
+
}
|
|
102
|
+
const r = readRequirement({ requirementSources: o.sources });
|
|
103
|
+
if (r.requirementProblems?.length)
|
|
104
|
+
return `requirement が読めません: ${r.requirementProblems.join(" / ")}`;
|
|
105
|
+
return r.requirementSources?.length ? { sources: r.requirementSources } : {};
|
|
106
|
+
}
|
|
107
|
+
function readRefs(v) {
|
|
108
|
+
if (!Array.isArray(v))
|
|
109
|
+
return "refs が並びになっていません";
|
|
110
|
+
const out = [];
|
|
111
|
+
for (const raw of v) {
|
|
112
|
+
const o = obj(raw);
|
|
113
|
+
const name = str(o?.name);
|
|
114
|
+
const at = iso(o?.at);
|
|
115
|
+
if (!o || !name || !at || !isRefState(o.state))
|
|
116
|
+
return "refs の項目が読めません(name・state・at が要ります)";
|
|
117
|
+
if (o.commit !== undefined && !/^[0-9a-f]{7,64}$/.test(String(o.commit)))
|
|
118
|
+
return `refs の ${name} の commit が読めません`;
|
|
119
|
+
if (o.dirty !== undefined && typeof o.dirty !== "boolean")
|
|
120
|
+
return `refs の ${name} の dirty が読めません`;
|
|
121
|
+
out.push({ name, state: o.state, ...(o.commit !== undefined ? { commit: String(o.commit) } : {}), ...(typeof o.dirty === "boolean" ? { dirty: o.dirty } : {}), at, ...(str(o.reason) ? { reason: str(o.reason) } : {}) });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
function readParts(v, key) {
|
|
126
|
+
if (!Array.isArray(v))
|
|
127
|
+
return `${key} が並びになっていません`;
|
|
128
|
+
const out = [];
|
|
129
|
+
for (const raw of v) {
|
|
130
|
+
const o = obj(raw);
|
|
131
|
+
const id = str(o?.id);
|
|
132
|
+
const rev = int(o?.rev);
|
|
133
|
+
const status = str(o?.status);
|
|
134
|
+
if (!o || !id || rev === undefined || !status)
|
|
135
|
+
return `${key} の項目が読めません(id・rev・status が要ります)`;
|
|
136
|
+
if (o.record !== undefined && !COMPLETION_ID_RE.test(String(o.record)))
|
|
137
|
+
return `${key} の ${id} の record が読めません`;
|
|
138
|
+
out.push({ id, rev, status, ...(typeof o.checked === "boolean" ? { checked: o.checked } : {}), ...(o.record !== undefined ? { record: String(o.record) } : {}) });
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function readRecord(raw, at) {
|
|
143
|
+
const o = obj(raw);
|
|
144
|
+
if (!o)
|
|
145
|
+
return `${at} が読めません`;
|
|
146
|
+
const id = str(o.id) ?? "";
|
|
147
|
+
const label = `${at}${id ? `(${id})` : ""}`;
|
|
148
|
+
if (!COMPLETION_ID_RE.test(id))
|
|
149
|
+
return `${label} の id が読めません(C1, C2, ...)`;
|
|
150
|
+
if (!isTrigger(o.trigger))
|
|
151
|
+
return `${label} の trigger が読めません(${COMPLETION_TRIGGERS.join(" / ")})`;
|
|
152
|
+
const when = iso(o.at);
|
|
153
|
+
if (!when)
|
|
154
|
+
return `${label} の at がありません`;
|
|
155
|
+
const rev = int(o.rev);
|
|
156
|
+
if (rev === undefined)
|
|
157
|
+
return `${label} の rev が読めません`;
|
|
158
|
+
const status = str(o.status);
|
|
159
|
+
if (!status)
|
|
160
|
+
return `${label} の status がありません`;
|
|
161
|
+
const quality = readQualityCondition(o.quality);
|
|
162
|
+
if (typeof quality === "string")
|
|
163
|
+
return `${label}: ${quality}`;
|
|
164
|
+
const rec = { id, trigger: o.trigger, at: when, ...(str(o.by) ? { by: str(o.by) } : {}), rev, status, ...(typeof o.checked === "boolean" ? { checked: o.checked } : {}), quality };
|
|
165
|
+
if (o.requirement !== undefined) {
|
|
166
|
+
const r = readRequirementCondition(o.requirement);
|
|
167
|
+
if (typeof r === "string")
|
|
168
|
+
return `${label}: ${r}`;
|
|
169
|
+
rec.requirement = r;
|
|
170
|
+
}
|
|
171
|
+
if (o.acceptance !== undefined) {
|
|
172
|
+
const a = readAcceptanceCondition(o.acceptance);
|
|
173
|
+
if (typeof a === "string")
|
|
174
|
+
return `${label}: ${a}`;
|
|
175
|
+
rec.acceptance = a;
|
|
176
|
+
}
|
|
177
|
+
if (o.title !== undefined)
|
|
178
|
+
rec.title = String(o.title);
|
|
179
|
+
if (o.subject !== undefined)
|
|
180
|
+
rec.subject = String(o.subject);
|
|
181
|
+
for (const key of ["tasks", "children"]) {
|
|
182
|
+
if (o[key] === undefined)
|
|
183
|
+
continue;
|
|
184
|
+
const p = readParts(o[key], key);
|
|
185
|
+
if (typeof p === "string")
|
|
186
|
+
return `${label}: ${p}`;
|
|
187
|
+
rec[key] = p;
|
|
188
|
+
}
|
|
189
|
+
if (o.refs !== undefined) {
|
|
190
|
+
const r = readRefs(o.refs);
|
|
191
|
+
if (typeof r === "string")
|
|
192
|
+
return `${label}: ${r}`;
|
|
193
|
+
rec.refs = r;
|
|
194
|
+
}
|
|
195
|
+
return rec;
|
|
196
|
+
}
|
|
197
|
+
/** frontmatter の completionRecords を読む。無ければ何も足さない(記録の無い古いデータはそのまま「記録なし」) */
|
|
198
|
+
export function readCompletion(d) {
|
|
199
|
+
if (d.completionRecords === undefined || d.completionRecords === null)
|
|
200
|
+
return {};
|
|
201
|
+
if (!Array.isArray(d.completionRecords))
|
|
202
|
+
return { completionProblems: ["completionRecords が並びになっていません"] };
|
|
203
|
+
const problems = [];
|
|
204
|
+
const list = [];
|
|
205
|
+
for (const [i, raw] of d.completionRecords.entries()) {
|
|
206
|
+
const r = readRecord(raw, `完了の記録 ${i + 1} 件目`);
|
|
207
|
+
if (typeof r === "string")
|
|
208
|
+
problems.push(r);
|
|
209
|
+
else if (list.some((x) => x.id === r.id))
|
|
210
|
+
problems.push(`完了の記録の id が重複しています: ${r.id}`);
|
|
211
|
+
else
|
|
212
|
+
list.push(r);
|
|
213
|
+
}
|
|
214
|
+
return { ...(list.length ? { completionRecords: list } : {}), ...(problems.length ? { completionProblems: problems } : {}) };
|
|
215
|
+
}
|
|
216
|
+
// --- 作る ---------------------------------------------------------------------
|
|
217
|
+
/** 次の記録の ID(消さないので最大の番号の次) */
|
|
218
|
+
export function nextCompletionId(list) {
|
|
219
|
+
const max = Math.max(0, ...(list ?? []).map((r) => Number(r.id.slice(1))));
|
|
220
|
+
return `C${max + 1}`;
|
|
221
|
+
}
|
|
222
|
+
/** 最新の記録(無ければ undefined) */
|
|
223
|
+
/** 契機ごとの最初の記録(開発の指標の到達の時点など。無ければ undefined) */
|
|
224
|
+
export const firstCompletion = (records, trigger) => (records ?? []).find((c) => c.trigger === trigger);
|
|
225
|
+
export const latestCompletion = (list) => list?.at(-1);
|
|
226
|
+
/**
|
|
227
|
+
* タスクの書く前(prev。作るときは無い)と書いた後(next)から、足す記録の契機を決める。
|
|
228
|
+
* acceptanceChanged: この更新で基準・証拠・基準の根拠の中身が変わった(済みのまま中身を変えて済みを付け直したら、新しい人の済みの記録にする)
|
|
229
|
+
*/
|
|
230
|
+
export function taskTriggers(prev, next, acceptanceChanged) {
|
|
231
|
+
if (next.status !== "done")
|
|
232
|
+
return [];
|
|
233
|
+
const out = [];
|
|
234
|
+
const wasDone = prev?.status === "done";
|
|
235
|
+
if (!wasDone)
|
|
236
|
+
out.push("task_done");
|
|
237
|
+
if (next.checkedAt && (!wasDone || !prev?.checkedAt || acceptanceChanged))
|
|
238
|
+
out.push("task_checked");
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
/** 要望の状態の変化から、足す記録の契機を決める */
|
|
242
|
+
export function requestTriggers(prev, next) {
|
|
243
|
+
if (prev === next)
|
|
244
|
+
return [];
|
|
245
|
+
if (next === "resolved")
|
|
246
|
+
return ["request_resolved"];
|
|
247
|
+
if (next === "done")
|
|
248
|
+
return ["request_done"];
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
/** 品質の条件(タスクなら作業先に当てはまる項目と除外を写す) */
|
|
252
|
+
export function qualityCondition(state, version, task) {
|
|
253
|
+
const st = state ?? { state: "unset" };
|
|
254
|
+
const base = { state: st.state, version: version ?? "", ...(task ? { repo: task.repo } : {}) };
|
|
255
|
+
if (st.state === "invalid")
|
|
256
|
+
return { ...base, problems: [...st.problems] };
|
|
257
|
+
if (st.state !== "set" || !task)
|
|
258
|
+
return base;
|
|
259
|
+
const { applies, exempt } = standardsFor(st.config, task.repo);
|
|
260
|
+
const hit = st.config.standards.filter((s) => applies.includes(s) || exempt.includes(s));
|
|
261
|
+
// 書く形(qualityPlain)にそろえて写す(読み直しても同じ値になる)
|
|
262
|
+
return { ...base, standards: qualityPlain({ standards: hit }).standards.map((s) => structuredClone(s)) };
|
|
263
|
+
}
|
|
264
|
+
const requirementOf = (r) => {
|
|
265
|
+
if (!r)
|
|
266
|
+
return undefined;
|
|
267
|
+
if (r.requirementProblems?.length)
|
|
268
|
+
return { problems: [...r.requirementProblems] };
|
|
269
|
+
return r.requirementSources?.length ? { sources: structuredClone(r.requirementSources) } : undefined;
|
|
270
|
+
};
|
|
271
|
+
/** タスクの記録(task は書いた後の値。rev は書いた後の rev) */
|
|
272
|
+
export function taskCompletionRecord(id, trigger, task, rev, request, ctx) {
|
|
273
|
+
let acceptance;
|
|
274
|
+
if (task.acceptanceProblems?.length)
|
|
275
|
+
acceptance = { problems: [...task.acceptanceProblems] };
|
|
276
|
+
else if (task.acceptanceCriteria?.length || task.acceptanceEvidence?.length || task.acceptanceSources?.length) {
|
|
277
|
+
acceptance = {
|
|
278
|
+
...(task.acceptanceCriteria?.length ? { criteria: structuredClone(task.acceptanceCriteria) } : {}),
|
|
279
|
+
...(task.acceptanceEvidence?.length ? { evidence: structuredClone(task.acceptanceEvidence) } : {}),
|
|
280
|
+
...(task.acceptanceSources?.length ? { sources: structuredClone(task.acceptanceSources) } : {}),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const requirement = requirementOf(request);
|
|
284
|
+
return {
|
|
285
|
+
id,
|
|
286
|
+
trigger,
|
|
287
|
+
at: ctx.at,
|
|
288
|
+
...(ctx.by ? { by: ctx.by } : {}),
|
|
289
|
+
rev,
|
|
290
|
+
status: task.status,
|
|
291
|
+
checked: !!task.checkedAt,
|
|
292
|
+
quality: qualityCondition(ctx.quality, ctx.qualityVersion, task),
|
|
293
|
+
...(requirement ? { requirement } : {}),
|
|
294
|
+
...(acceptance ? { acceptance } : {}),
|
|
295
|
+
...(ctx.refs ? { refs: structuredClone(ctx.refs) } : {}),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/** 要望の記録(request は書いた後の値。tasks・children は判定に使った配下) */
|
|
299
|
+
export function requestCompletionRecord(id, trigger, request, rev, parts, ctx) {
|
|
300
|
+
const requirement = requirementOf(request);
|
|
301
|
+
const part = (x) => {
|
|
302
|
+
const rec = latestCompletion(x.completionRecords);
|
|
303
|
+
return { id: x.id, rev: x.rev, status: x.status, ...(rec ? { record: rec.id } : {}) };
|
|
304
|
+
};
|
|
305
|
+
return {
|
|
306
|
+
id,
|
|
307
|
+
trigger,
|
|
308
|
+
at: ctx.at,
|
|
309
|
+
...(ctx.by ? { by: ctx.by } : {}),
|
|
310
|
+
rev,
|
|
311
|
+
status: request.status,
|
|
312
|
+
quality: qualityCondition(ctx.quality, ctx.qualityVersion),
|
|
313
|
+
...(requirement ? { requirement } : {}),
|
|
314
|
+
title: request.title,
|
|
315
|
+
subject: requestSubject(request),
|
|
316
|
+
tasks: parts.tasks.map((t) => ({ ...part(t), checked: !!t.checkedAt })),
|
|
317
|
+
children: parts.children.map(part),
|
|
318
|
+
...(ctx.refs ? { refs: structuredClone(ctx.refs) } : {}),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/** 記録を足した値(壊れた記録があれば足さずに undefined) */
|
|
322
|
+
export function appendCompletion(cur, make) {
|
|
323
|
+
if (cur.completionProblems?.length)
|
|
324
|
+
return undefined;
|
|
325
|
+
const list = cur.completionRecords ?? [];
|
|
326
|
+
return [...list, make(nextCompletionId(list))];
|
|
327
|
+
}
|
|
328
|
+
/** 壊れた記録のため記録を足せなかったときの知らせ */
|
|
329
|
+
export const COMPLETION_SKIPPED = "完了の記録が読めないため、今回の記録は残していません(状態は変えました)。ファイルの completionRecords を直してください";
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { latestCompletion } from "./completionRecord.js";
|
|
2
|
+
import { checkLine, standardHash, standardsFor } from "../../quality/shared/quality.js";
|
|
3
|
+
import { criterionSubject, requestSubject, sourceState } from "../../requirements/shared/requirementSource.js";
|
|
4
|
+
export const REVIEW_STATE_LABEL = {
|
|
5
|
+
no_record: "記録なし",
|
|
6
|
+
unreadable: "比較不能",
|
|
7
|
+
none: "差分なし",
|
|
8
|
+
candidate: "見直しが必要(候補)",
|
|
9
|
+
};
|
|
10
|
+
export const REVIEW_STATE_HINT = {
|
|
11
|
+
no_record: "完了したときの条件の記録がありません(この機能より前・直接編集で完了したもの)。比べる基点がないので、必要なら人がもう一度確かめて済みにしてください",
|
|
12
|
+
unreadable: "完了の記録が読めないため比べられません。ファイルの completionRecords を直してください",
|
|
13
|
+
none: "完了したときの条件と今の条件に、見直しにつながる差はありません",
|
|
14
|
+
candidate: "完了したときの条件から変わったものがあります。過去の判断が誤りという意味ではありません。確かめて、必要ならもう一度済みにしてください",
|
|
15
|
+
};
|
|
16
|
+
export const REVIEW_CODES = [
|
|
17
|
+
"quality_added",
|
|
18
|
+
"quality_changed",
|
|
19
|
+
"quality_removed",
|
|
20
|
+
"quality_exempted",
|
|
21
|
+
"quality_state",
|
|
22
|
+
"criterion_added",
|
|
23
|
+
"criterion_changed",
|
|
24
|
+
"criterion_removed",
|
|
25
|
+
"source_changed",
|
|
26
|
+
"source_removed",
|
|
27
|
+
"source_unconfirmed",
|
|
28
|
+
"premise_changed",
|
|
29
|
+
];
|
|
30
|
+
export const REVIEW_CODE_LABEL = {
|
|
31
|
+
quality_added: "品質基準が新たに当てはまる",
|
|
32
|
+
quality_changed: "品質基準が変わった",
|
|
33
|
+
quality_removed: "品質基準が消えた・当てはまらなくなった",
|
|
34
|
+
quality_exempted: "品質基準が除外になった",
|
|
35
|
+
quality_state: "品質基準の設定の状態が変わった",
|
|
36
|
+
criterion_added: "受け入れ基準が増えた",
|
|
37
|
+
criterion_changed: "受け入れ基準の文が変わった",
|
|
38
|
+
criterion_removed: "受け入れ基準が消えた",
|
|
39
|
+
source_changed: "要求の根拠の内容が変わった",
|
|
40
|
+
source_removed: "要求の根拠が消えた",
|
|
41
|
+
source_unconfirmed: "要求の根拠の確認が効かなくなった",
|
|
42
|
+
premise_changed: "前提の変更が記録された",
|
|
43
|
+
};
|
|
44
|
+
export const PREMISE_LIMITS = { changes: 200, targets: 50, reason: 2000, condition: 1000, acks: 200 };
|
|
45
|
+
export const PREMISE_KEYS = ["premiseChanges"];
|
|
46
|
+
export const PREMISE_ID_RE = /^P\d+$/;
|
|
47
|
+
/** 入力が規則に合わない(何も書いていない)。CLI は使い方の誤り、API は 400 */
|
|
48
|
+
export class PremiseInputError extends Error {
|
|
49
|
+
code = "premise_invalid";
|
|
50
|
+
}
|
|
51
|
+
const str = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
52
|
+
const iso = (v) => (v instanceof Date ? v.toISOString() : str(v));
|
|
53
|
+
function readAck(v) {
|
|
54
|
+
const o = v && typeof v === "object" ? v : undefined;
|
|
55
|
+
const target = str(o?.target);
|
|
56
|
+
const condition = str(o?.condition);
|
|
57
|
+
const at = iso(o?.at);
|
|
58
|
+
if (!target || !condition || !at)
|
|
59
|
+
return undefined;
|
|
60
|
+
return { target, condition, at, ...(str(o?.by) ? { by: str(o?.by) } : {}) };
|
|
61
|
+
}
|
|
62
|
+
/** 要望の premiseChanges を読む(無ければ何も足さない) */
|
|
63
|
+
export function readPremises(d) {
|
|
64
|
+
if (d.premiseChanges === undefined || d.premiseChanges === null)
|
|
65
|
+
return {};
|
|
66
|
+
if (!Array.isArray(d.premiseChanges))
|
|
67
|
+
return { premiseProblems: ["premiseChanges が並びになっていません"] };
|
|
68
|
+
const list = [];
|
|
69
|
+
const problems = [];
|
|
70
|
+
for (const [i, raw] of d.premiseChanges.entries()) {
|
|
71
|
+
const o = raw && typeof raw === "object" ? raw : {};
|
|
72
|
+
const id = str(o.id) ?? "";
|
|
73
|
+
const at = `前提の変更 ${i + 1} 件目${id ? `(${id})` : ""}`;
|
|
74
|
+
const targets = Array.isArray(o.targets) ? o.targets.map(str).filter((x) => !!x) : [];
|
|
75
|
+
const acks = Array.isArray(o.acks) ? o.acks.map(readAck) : [];
|
|
76
|
+
if (!PREMISE_ID_RE.test(id))
|
|
77
|
+
problems.push(`${at} の id が読めません(P1, P2, ...)`);
|
|
78
|
+
else if (list.some((x) => x.id === id))
|
|
79
|
+
problems.push(`前提の変更の id が重複しています: ${id}`);
|
|
80
|
+
else if (!targets.length)
|
|
81
|
+
problems.push(`${at} の targets がありません`);
|
|
82
|
+
else if (!str(o.reason) || !str(o.condition) || !iso(o.at))
|
|
83
|
+
problems.push(`${at} には reason・condition・at が要ります`);
|
|
84
|
+
else if (acks.some((a) => !a))
|
|
85
|
+
problems.push(`${at} の acks の項目が読めません(target・condition・at が要ります)`);
|
|
86
|
+
else
|
|
87
|
+
list.push({
|
|
88
|
+
id,
|
|
89
|
+
targets,
|
|
90
|
+
reason: str(o.reason),
|
|
91
|
+
condition: str(o.condition),
|
|
92
|
+
at: iso(o.at),
|
|
93
|
+
...(str(o.by) ? { by: str(o.by) } : {}),
|
|
94
|
+
...(acks.length ? { acks: acks } : {}),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return { ...(list.length ? { premiseChanges: list } : {}), ...(problems.length ? { premiseProblems: problems } : {}) };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 前提の変更への操作を当てる(足す・確認を記録する)。exists: 対象が今あるか(要望 ID・タスク ID・要望の根拠の ID)。
|
|
101
|
+
* 規則に合わなければ PremiseInputError(何も当てない)
|
|
102
|
+
*/
|
|
103
|
+
export function applyPremiseOp(list, op, ctx) {
|
|
104
|
+
const condition = str(op.condition);
|
|
105
|
+
if (!condition)
|
|
106
|
+
throw new PremiseInputError("新しい条件・版(condition)を書いてください");
|
|
107
|
+
if (condition.length > PREMISE_LIMITS.condition)
|
|
108
|
+
throw new PremiseInputError(`条件は ${PREMISE_LIMITS.condition} 文字までです`);
|
|
109
|
+
if (op.op === "add") {
|
|
110
|
+
const reason = str(op.reason);
|
|
111
|
+
if (!reason)
|
|
112
|
+
throw new PremiseInputError("変更の理由(reason)を書いてください");
|
|
113
|
+
if (reason.length > PREMISE_LIMITS.reason)
|
|
114
|
+
throw new PremiseInputError(`理由は ${PREMISE_LIMITS.reason} 文字までです`);
|
|
115
|
+
const targets = [...new Set((op.targets ?? []).map((t) => t.trim()).filter(Boolean))];
|
|
116
|
+
if (!targets.length)
|
|
117
|
+
throw new PremiseInputError("対象(要望 ID・タスク ID・要望の根拠の ID)を1つ以上指定してください");
|
|
118
|
+
if (targets.length > PREMISE_LIMITS.targets)
|
|
119
|
+
throw new PremiseInputError(`対象は ${PREMISE_LIMITS.targets} 件までです`);
|
|
120
|
+
const missing = targets.filter((t) => !ctx.exists(t));
|
|
121
|
+
if (missing.length)
|
|
122
|
+
throw new PremiseInputError(`対象がありません: ${missing.join(", ")}(要望 ID・この要望のタスク ID・要望の根拠の ID)`);
|
|
123
|
+
if (list.length >= PREMISE_LIMITS.changes)
|
|
124
|
+
throw new PremiseInputError(`前提の変更は ${PREMISE_LIMITS.changes} 件までです`);
|
|
125
|
+
const n = Math.max(0, ...list.map((c) => Number(c.id.slice(1)))) + 1;
|
|
126
|
+
return [...list, { id: `P${n}`, targets, reason, condition, at: ctx.now, ...(ctx.actor ? { by: ctx.actor } : {}) }];
|
|
127
|
+
}
|
|
128
|
+
const cur = list.find((c) => c.id === op.id);
|
|
129
|
+
if (!cur)
|
|
130
|
+
throw new PremiseInputError(`前提の変更 ${op.id} はありません`);
|
|
131
|
+
const target = str(op.target);
|
|
132
|
+
if (!target || !cur.targets.includes(target))
|
|
133
|
+
throw new PremiseInputError(`${op.id} の対象ではありません: ${op.target}(対象: ${cur.targets.join(", ")})`);
|
|
134
|
+
if ((cur.acks?.length ?? 0) >= PREMISE_LIMITS.acks)
|
|
135
|
+
throw new PremiseInputError(`確認の記録は ${PREMISE_LIMITS.acks} 件までです`);
|
|
136
|
+
const ack = { target, condition, at: ctx.now, ...(ctx.actor ? { by: ctx.actor } : {}) };
|
|
137
|
+
return list.map((c) => (c === cur ? { ...c, acks: [...(c.acks ?? []), ack] } : c));
|
|
138
|
+
}
|
|
139
|
+
// --- 診断 ---------------------------------------------------------------------
|
|
140
|
+
const short = (s, n = 200) => (s === undefined ? undefined : s.length > n ? `${s.slice(0, n)}…` : s);
|
|
141
|
+
const stdLine = (s) => `${s.text}(${checkLine(s.check)})${s.repos?.length ? `(対象: ${s.repos.join(", ")})` : ""}${s.exempt ? `(除外: ${s.exempt.reason})` : ""}`;
|
|
142
|
+
const sourceLine = (s) => [s.target, s.source, s.basis].filter(Boolean).join(" / ");
|
|
143
|
+
const sourceKey = (s) => JSON.stringify([s.target ?? "", s.source ?? "", s.basis ?? ""]);
|
|
144
|
+
/**
|
|
145
|
+
* 品質の理由。subject は診断の対象: タスク(task。作業先 repo に当てはまる項目を比べる)か要望自身(request。状態だけを比べる)。
|
|
146
|
+
* 要望の記録は品質の項目を写さないので、要望自身は「設定済 → 未設定・読めない」の変化だけを理由にし、未設定 → 設定(初回設定)では
|
|
147
|
+
* 候補にしない(後から品質基準を導入しただけで、過去の要望が一括して候補になるのを避ける)。タスクは未設定の記録でも項目なしとして比べる
|
|
148
|
+
*/
|
|
149
|
+
function qualityReasons(rec, now, subject, out, unreadable) {
|
|
150
|
+
const q = rec.quality;
|
|
151
|
+
const st = now ?? { state: "unset" };
|
|
152
|
+
if (q.state === "invalid") {
|
|
153
|
+
unreadable.push("完了したときの品質基準が読めなかったため、品質は比べられません");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (st.state === "invalid") {
|
|
157
|
+
out.push({ code: "quality_state", target: "quality", was: q.state === "set" ? "設定済" : "未設定", now: "読めない" });
|
|
158
|
+
unreadable.push("今の品質基準が読めないため、項目は比べられません");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (q.state === "set" && st.state === "unset") {
|
|
162
|
+
out.push({ code: "quality_state", target: "quality", was: "設定済", now: "未設定" });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// 要望自身は項目を比べない(状態だけ)。未設定 → 設定も候補にしない
|
|
166
|
+
if (subject.kind === "request")
|
|
167
|
+
return;
|
|
168
|
+
if (st.state !== "set")
|
|
169
|
+
return;
|
|
170
|
+
const then = q.standards ?? [];
|
|
171
|
+
const { applies, exempt } = standardsFor(st.config, subject.repo);
|
|
172
|
+
for (const s of applies) {
|
|
173
|
+
const was = then.find((x) => x.id === s.id);
|
|
174
|
+
if (!was || was.exempt)
|
|
175
|
+
out.push({ code: "quality_added", target: s.id, ...(was ? { was: stdLine(was) } : {}), now: stdLine(s) });
|
|
176
|
+
else if (standardHash(was) !== standardHash(s))
|
|
177
|
+
out.push({ code: "quality_changed", target: s.id, was: stdLine(was), now: stdLine(s) });
|
|
178
|
+
}
|
|
179
|
+
for (const was of then.filter((x) => !x.exempt)) {
|
|
180
|
+
if (applies.some((s) => s.id === was.id))
|
|
181
|
+
continue;
|
|
182
|
+
const ex = exempt.find((s) => s.id === was.id);
|
|
183
|
+
if (ex)
|
|
184
|
+
out.push({ code: "quality_exempted", target: was.id, was: stdLine(was), now: stdLine(ex) });
|
|
185
|
+
else
|
|
186
|
+
out.push({ code: "quality_removed", target: was.id, was: stdLine(was), now: st.config.standards.some((s) => s.id === was.id) ? "作業先に当てはまらない" : undefined });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function sourceReasons(then, now, nowState, label, out, related) {
|
|
190
|
+
for (const was of then) {
|
|
191
|
+
const cur = now.find((s) => label(s) === label(was));
|
|
192
|
+
const rel = related?.(was);
|
|
193
|
+
const extra = rel?.length ? { related: rel } : {};
|
|
194
|
+
if (!cur)
|
|
195
|
+
out.push({ code: "source_removed", target: label(was), was: short(sourceLine(was)), ...extra });
|
|
196
|
+
else if (sourceKey(cur) !== sourceKey(was))
|
|
197
|
+
out.push({ code: "source_changed", target: label(was), was: short(sourceLine(was)), now: short(sourceLine(cur)), ...extra });
|
|
198
|
+
else if (was.confirmed && nowState(cur) !== "confirmed")
|
|
199
|
+
out.push({ code: "source_unconfirmed", target: label(was), was: `確認記録あり(${was.confirmed.by}・${was.confirmed.on})`, now: nowState(cur) === "reconfirm" ? "再確認が必要" : "未確認", ...extra });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function premiseReasons(changes, since, keys, out) {
|
|
203
|
+
for (const c of changes ?? []) {
|
|
204
|
+
if (c.at <= since)
|
|
205
|
+
continue;
|
|
206
|
+
const hit = c.targets.filter((t) => keys.includes(t) && !c.acks?.some((a) => a.target === t && a.at >= c.at));
|
|
207
|
+
if (hit.length)
|
|
208
|
+
out.push({ code: "premise_changed", target: c.id, now: short(`${c.reason}(新しい条件: ${c.condition})`), related: hit });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/** 同じ理由(理由と対象)を1件にする */
|
|
212
|
+
const dedupe = (list) => list.filter((r, i) => list.findIndex((x) => x.code === r.code && x.target === r.target) === i);
|
|
213
|
+
function finish(target, rec, reasons, unreadable, qualityVersion) {
|
|
214
|
+
const rs = dedupe(reasons);
|
|
215
|
+
return {
|
|
216
|
+
target,
|
|
217
|
+
state: rs.length ? "candidate" : "none",
|
|
218
|
+
record: rec.id,
|
|
219
|
+
...(qualityVersion !== undefined ? { qualityVersion } : {}),
|
|
220
|
+
reasons: rs,
|
|
221
|
+
...(unreadable.length ? { unreadable } : {}),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/** 完了したタスクか(診断の対象) */
|
|
225
|
+
export const isReviewTarget = (t) => t.status === "done";
|
|
226
|
+
/** 対応済・完了済の要望か(自身の条件の差を診断する対象) */
|
|
227
|
+
export const isReviewRequest = (r) => r.status === "resolved" || r.status === "done";
|
|
228
|
+
/** タスクの診断(完了していないタスクは undefined) */
|
|
229
|
+
export function diagnoseTask(task, request, now) {
|
|
230
|
+
if (!isReviewTarget(task))
|
|
231
|
+
return undefined;
|
|
232
|
+
if (task.completionProblems?.length)
|
|
233
|
+
return { target: task.ref, state: "unreadable", reasons: [], unreadable: [...task.completionProblems] };
|
|
234
|
+
const rec = latestCompletion(task.completionRecords);
|
|
235
|
+
if (!rec)
|
|
236
|
+
return { target: task.ref, state: "no_record", reasons: [] };
|
|
237
|
+
const reasons = [];
|
|
238
|
+
const unreadable = [];
|
|
239
|
+
qualityReasons(rec, now.quality, { kind: "task", repo: task.repo }, reasons, unreadable);
|
|
240
|
+
// 基準
|
|
241
|
+
if (rec.acceptance?.problems)
|
|
242
|
+
unreadable.push("完了したときの受け入れ基準が読めなかったため、基準は比べられません");
|
|
243
|
+
else if (task.acceptanceProblems?.length)
|
|
244
|
+
unreadable.push("今の受け入れ基準が読めないため、基準は比べられません");
|
|
245
|
+
else {
|
|
246
|
+
const then = rec.acceptance?.criteria ?? [];
|
|
247
|
+
const cur = task.acceptanceCriteria ?? [];
|
|
248
|
+
for (const c of cur) {
|
|
249
|
+
const was = then.find((x) => x.id === c.id);
|
|
250
|
+
if (!was)
|
|
251
|
+
reasons.push({ code: "criterion_added", target: c.id, now: short(c.text) });
|
|
252
|
+
else if (was.text !== c.text)
|
|
253
|
+
reasons.push({ code: "criterion_changed", target: c.id, was: short(was.text), now: short(c.text) });
|
|
254
|
+
}
|
|
255
|
+
for (const was of then)
|
|
256
|
+
if (!cur.some((c) => c.id === was.id))
|
|
257
|
+
reasons.push({ code: "criterion_removed", target: was.id, was: short(was.text) });
|
|
258
|
+
// 基準ごとの根拠(基準 ID / 記録 ID)
|
|
259
|
+
const textOf = (id) => cur.find((c) => c.id === id)?.text;
|
|
260
|
+
const label = (s) => `${s.criterionId}/${s.id}`;
|
|
261
|
+
sourceReasons(rec.acceptance?.sources ?? [], task.acceptanceSources ?? [], (s) => {
|
|
262
|
+
const t = textOf(s.criterionId);
|
|
263
|
+
return t === undefined ? "unlinked" : sourceState(s, criterionSubject(t));
|
|
264
|
+
}, label, reasons);
|
|
265
|
+
// 写した元の要望の根拠(当時の元と今の元)
|
|
266
|
+
const fromIds = [...new Set((rec.acceptance?.sources ?? []).flatMap((s) => (s.from ? [s.from] : [])))];
|
|
267
|
+
if (fromIds.length) {
|
|
268
|
+
if (rec.requirement?.problems)
|
|
269
|
+
unreadable.push("完了したときの要望の根拠が読めなかったため、写した元は比べられません");
|
|
270
|
+
else if (request?.requirementProblems?.length)
|
|
271
|
+
unreadable.push("今の要望の根拠が読めないため、写した元は比べられません");
|
|
272
|
+
else if (request) {
|
|
273
|
+
const thenReq = (rec.requirement?.sources ?? []).filter((s) => fromIds.includes(s.id));
|
|
274
|
+
const subject = requestSubject(request);
|
|
275
|
+
const users = (id) => (rec.acceptance?.sources ?? []).filter((s) => s.from === id).map(label);
|
|
276
|
+
sourceReasons(thenReq, request.requirementSources ?? [], (s) => sourceState(s, subject), (s) => s.id, reasons, (s) => users(s.id));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 前提の変更(タスク ID か、基準の根拠が写した要望の根拠の ID を対象にしたもの)
|
|
281
|
+
if (request?.premiseProblems?.length)
|
|
282
|
+
unreadable.push("前提の変更の記録が読めないため、前提の変更は比べられません");
|
|
283
|
+
const keys = [task.id, ...new Set((task.acceptanceSources ?? []).flatMap((s) => (s.from ? [s.from] : [])))];
|
|
284
|
+
premiseReasons(request?.premiseChanges, rec.at, keys, reasons);
|
|
285
|
+
return finish(task.ref, rec, reasons, unreadable, now.qualityVersion);
|
|
286
|
+
}
|
|
287
|
+
/** 要望自身の診断(対応済・完了済でなければ undefined)。配下の件数は含めない */
|
|
288
|
+
export function diagnoseRequest(request, now) {
|
|
289
|
+
if (!isReviewRequest(request))
|
|
290
|
+
return undefined;
|
|
291
|
+
if (request.completionProblems?.length)
|
|
292
|
+
return { target: request.id, state: "unreadable", reasons: [], unreadable: [...request.completionProblems] };
|
|
293
|
+
const rec = latestCompletion(request.completionRecords);
|
|
294
|
+
if (!rec)
|
|
295
|
+
return { target: request.id, state: "no_record", reasons: [] };
|
|
296
|
+
const reasons = [];
|
|
297
|
+
const unreadable = [];
|
|
298
|
+
qualityReasons(rec, now.quality, { kind: "request" }, reasons, unreadable);
|
|
299
|
+
if (rec.requirement?.problems)
|
|
300
|
+
unreadable.push("完了したときの要望の根拠が読めなかったため、根拠は比べられません");
|
|
301
|
+
else if (request.requirementProblems?.length)
|
|
302
|
+
unreadable.push("今の要望の根拠が読めないため、根拠は比べられません");
|
|
303
|
+
else {
|
|
304
|
+
const subject = requestSubject(request);
|
|
305
|
+
sourceReasons(rec.requirement?.sources ?? [], request.requirementSources ?? [], (s) => sourceState(s, subject), (s) => s.id, reasons);
|
|
306
|
+
}
|
|
307
|
+
if (request.premiseProblems?.length)
|
|
308
|
+
unreadable.push("前提の変更の記録が読めないため、前提の変更は比べられません");
|
|
309
|
+
// 前提の変更(要望 ID か、要望の根拠の ID を対象にしたもの)
|
|
310
|
+
premiseReasons(request.premiseChanges, rec.at, [request.id, ...(request.requirementSources ?? []).map((s) => s.id), ...(rec.requirement?.sources ?? []).map((s) => s.id)], reasons);
|
|
311
|
+
return finish(request.id, rec, reasons, unreadable, now.qualityVersion);
|
|
312
|
+
}
|
|
313
|
+
export const reviewSummary = (d) => ({ state: d.state, ...(d.record ? { record: d.record } : {}), reasons: d.reasons.length, codes: [...new Set(d.reasons.map((r) => r.code))] });
|