@infodb/p3 0.11.0 → 0.12.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 +4 -1
- package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +1 -0
- package/dist/web/assets/Outputs-_nU_p3nu.js +1 -0
- package/dist/web/assets/{RequestStatus-Bg1OLbRc.js → RequestStatus-RG-OVQYY.js} +1 -1
- package/dist/web/assets/{Tabs-DTmggzgg.js → Tabs-ew9i5SKX.js} +1 -1
- package/dist/web/assets/TagInput-BtlJTF7i.js +1 -0
- package/dist/web/assets/TaskDrawer-DW8GyJqI.js +6 -0
- package/dist/web/assets/_requestId-6Nb727dD.js +1 -0
- package/dist/web/assets/_requestId-BykTgPax.js +1 -0
- package/dist/web/assets/appCtx-CxDdXABS.js +1 -0
- package/dist/web/assets/archive-Ckh295Xe.js +1 -0
- package/dist/web/assets/board-BVAIjK-Y.js +1 -0
- package/dist/web/assets/done-BGfA-3MA.js +1 -0
- package/dist/web/assets/index-CgRU744I.css +2 -0
- package/dist/web/assets/index-DacQ0yl4.js +12 -0
- package/dist/web/assets/{new-9TKiNT4O.js → new-DVygWvVc.js} +1 -1
- package/dist/web/assets/outputs-B6xDsLZf.js +1 -0
- package/dist/web/assets/preload-helper-DyCqp21K.js +1 -0
- package/dist/web/assets/quality-Pu6EISAM.js +1 -0
- package/dist/web/assets/release-notes-CCpzyiNf.js +5 -0
- package/dist/web/assets/requestData-D5vBnuMh.js +1 -0
- package/dist/web/assets/routes-Q91zvNc0.js +4 -0
- package/dist/web/assets/settings-BzRgcmUm.js +1 -0
- package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
- package/dist/web/assets/workTarget-C9c57JAO.js +30 -0
- package/dist/web/index.html +4 -4
- package/docs/architecture.md +315 -2
- package/docs/development.md +1 -1
- package/docs/how-to-use.md +184 -0
- package/docs/installation.md +5 -5
- package/lib/cli/args.js +45 -0
- package/lib/cli/help.js +36 -1
- package/lib/cli/main.js +27 -3
- package/lib/cli/output.js +9 -1
- package/lib/cli/preflightCommands.js +7 -1
- package/lib/cli/project.js +3 -0
- package/lib/cli/qualityCommands.js +163 -0
- package/lib/cli/readOnly.js +2 -0
- package/lib/cli/requestCommands.js +12 -0
- package/lib/cli/showView.js +69 -3
- package/lib/cli/taskCommands.js +312 -17
- package/lib/cli/taskReviewCommands.js +178 -0
- package/lib/core/context.js +4 -1
- package/lib/core/milestoneReview/material.js +11 -1
- package/lib/core/milestoneReview/mockReviewer.js +1 -0
- package/lib/core/milestoneReview/review.js +70 -6
- package/lib/core/milestoneReview/service.js +29 -93
- package/lib/core/milestoneReview/store.js +12 -62
- package/lib/core/ops.js +9 -2
- package/lib/core/preflight/carryover.js +1 -1
- package/lib/core/preflight/engine.js +6 -0
- package/lib/core/preflight/instructions.js +18 -1
- package/lib/core/preflight/mockEngine.js +4 -0
- package/lib/core/preflight/service.js +45 -4
- package/lib/core/projectRegistry.js +3 -3
- package/lib/core/quality.js +21 -0
- package/lib/core/qualityImprovement.js +221 -0
- package/lib/core/requestOps.js +97 -6
- package/lib/core/reviewRuns.js +205 -0
- package/lib/core/store/archivedTasks.js +74 -0
- package/lib/core/store/collection.js +12 -2
- package/lib/core/store/normalize.js +16 -1
- package/lib/core/store/preflightStore.js +9 -1
- package/lib/core/store/projectFile.js +10 -0
- package/lib/core/store/workspace.js +33 -3
- package/lib/core/taskReview/material.js +452 -0
- package/lib/core/taskReview/mockReviewer.js +30 -0
- package/lib/core/taskReview/paths.js +15 -0
- package/lib/core/taskReview/review.js +305 -0
- package/lib/core/taskReview/service.js +187 -0
- package/lib/core/taskReview/store.js +214 -0
- package/lib/server/api/manifest.js +55 -4
- package/lib/server/api/milestoneReviewRoutes.js +4 -3
- package/lib/server/api/routes.js +145 -17
- package/lib/server/api/taskReviewRoutes.js +66 -0
- package/lib/server/server.js +2 -2
- package/lib/shared/acceptance.js +378 -0
- package/lib/shared/milestoneReview.js +2 -1
- package/lib/shared/quality.js +391 -0
- package/lib/shared/qualityImprovement.js +1 -0
- package/lib/shared/qualityTemplates.js +31 -0
- package/lib/shared/taskBlock.js +142 -0
- package/lib/shared/taskReview.js +56 -0
- package/package.json +1 -1
- package/skills/p3/SKILL.md +31 -2
- package/dist/web/assets/Outputs-ddwte0jj.js +0 -1
- package/dist/web/assets/TagInput-BHAgjLP7.js +0 -1
- package/dist/web/assets/TaskDrawer-Dz_5c2NH.js +0 -3
- package/dist/web/assets/_requestId-D9-gtIcG.js +0 -1
- package/dist/web/assets/_requestId-DzCNYvqf.js +0 -30
- package/dist/web/assets/appCtx-Cm24VpAf.js +0 -1
- package/dist/web/assets/board-MCHcZ-PU.js +0 -1
- package/dist/web/assets/done-zq10Bt08.js +0 -1
- package/dist/web/assets/index-Ce0ndpne.js +0 -12
- package/dist/web/assets/index-D68mkSnw.css +0 -2
- package/dist/web/assets/preload-helper-FBLw7u7x.js +0 -1
- package/dist/web/assets/release-notes-hK5XezLW.js +0 -5
- package/dist/web/assets/requestData-BnN7mctX.js +0 -1
- package/dist/web/assets/routes-usHwrrA0.js +0 -3
- package/dist/web/assets/settings-BVZDnL6O.js +0 -1
- package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import YAML from "yaml";
|
|
6
|
+
import { acceptanceStatus } from "../../shared/acceptance.js";
|
|
7
|
+
import { qualitySnapshot, standardsFor, taskQualityDiff } from "../../shared/quality.js";
|
|
8
|
+
import { commitsInOutput } from "../milestoneReview/code.js";
|
|
9
|
+
import { NotFoundError } from "../store/collection.js";
|
|
10
|
+
import { Workspace } from "../store/workspace.js";
|
|
11
|
+
import { safeRelPath } from "./paths.js";
|
|
12
|
+
export { safeRelPath };
|
|
13
|
+
/**
|
|
14
|
+
* タスクの AI レビューの材料を固定する(何も書かない。取り出したファイルの中身は files で返し、保存は store.ts)。
|
|
15
|
+
*
|
|
16
|
+
* - 対象は保存してある完了したタスク(済みも再実行できる)。無い・未完了・アーカイブしたタスクは断る(過去の履歴は読める)
|
|
17
|
+
* - タスクの本文・受け入れ基準・作業した側の証拠(失効・読めない値も含む)・変更の記録・成果物・要望の文脈を写す。
|
|
18
|
+
* 証拠は判定に変えない。基準が無ければ本文から比較項目を取り出し、元の段落を残す
|
|
19
|
+
* - 比較対象(コミット・範囲・PR の参照)を参照先ごとに正規化し、完全な SHA に固定する。単一のコミットは親との差分(ルートは
|
|
20
|
+
* 空の tree)、複数は各親との差分、範囲は merge-base からの差分。マージのコミット・参照先の候補が複数なら人に指定を求める。
|
|
21
|
+
* PR の URL は出典として残し、中身は取りに行かない(fetch・checkout・認証はしない)
|
|
22
|
+
* - 差分・変更の一覧・変わったファイルの前後の中身を、固定した SHA の git のオブジェクトから取り出す(作業ツリーの未コミットの
|
|
23
|
+
* 変更・今のブランチは混ざらない)。submodule・シンボリックリンクの先は追わない。コードは実行しない
|
|
24
|
+
* - 観点は人が明示したものだけ(参照先の固定した SHA のファイルか、project.yaml の taskReview.viewpoints)。作業ブランチの
|
|
25
|
+
* ファイルで差し替えない。選んだ文面・出典・SHA・hash を残す
|
|
26
|
+
* - 上限を超えるファイルは切り詰めずに取り出さず、注意(omitted)として未確認の範囲にする。差分の合計が上限を超えたら断る
|
|
27
|
+
* - hash は抽出の日時を含めない(同じ文面・基準・証拠・対象の SHA・観点・取り出した中身なら同じ)
|
|
28
|
+
*/
|
|
29
|
+
export const TASK_REVIEW_LIMITS = {
|
|
30
|
+
/** 差分の本文の合計 */
|
|
31
|
+
patchBytes: 1_000_000,
|
|
32
|
+
/** 取り出すファイル1件 */
|
|
33
|
+
fileBytes: 200_000,
|
|
34
|
+
/** 取り出すファイルの合計 */
|
|
35
|
+
totalBytes: 4_000_000,
|
|
36
|
+
/** 比較対象のコミットの数 */
|
|
37
|
+
commits: 50,
|
|
38
|
+
/** 観点の文字数 */
|
|
39
|
+
viewpoint: 20_000,
|
|
40
|
+
};
|
|
41
|
+
/** 始められない(理由つき。何も書いていない) */
|
|
42
|
+
export class TaskReviewRejected extends Error {
|
|
43
|
+
code;
|
|
44
|
+
running;
|
|
45
|
+
constructor(code, message, running) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.running = running;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
52
|
+
const FULL_SHA = /^[0-9a-f]{40}$/;
|
|
53
|
+
const TASK_REF_RE = /\b\d{6}-[a-z0-9]{5}\/T\d{3,}\b/g;
|
|
54
|
+
const PR_RE = /^https?:\/\/\S+\/(?:pull|pulls|merge_requests)\/\d+/i;
|
|
55
|
+
function gitBuf(local, args, maxBuffer = 64 * 1024 * 1024) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
execFile("git", ["-c", "core.quotepath=off", "-C", local, ...args], { encoding: "buffer", timeout: 30_000, maxBuffer }, (err, stdout) => (err ? reject(err instanceof Error ? err : new Error(String(err))) : resolve(stdout)));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const git = async (local, args) => (await gitBuf(local, args)).toString("utf8");
|
|
61
|
+
const tryGit = (local, args) => git(local, args).then((s) => s.trim(), () => undefined);
|
|
62
|
+
/** 本文から比較項目を取り出す: 「完了条件」の見出しの下の箇条書き → 箇条書き全部 → 段落 */
|
|
63
|
+
export function bodyItems(body) {
|
|
64
|
+
const text = body.replace(/\r\n/g, "\n").replace(/\n> preflight: .*$/m, "");
|
|
65
|
+
const bullets = (s) => s
|
|
66
|
+
.split("\n")
|
|
67
|
+
.map((l) => /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+)$/.exec(l)?.[1]?.trim())
|
|
68
|
+
.filter((x) => !!x);
|
|
69
|
+
const section = /^#{1,6}\s*完了条件\s*$([\s\S]*?)(?=^#{1,6}\s|$(?![\s\S]))/m.exec(text)?.[1] ?? "";
|
|
70
|
+
let list = bullets(section);
|
|
71
|
+
if (!list.length)
|
|
72
|
+
list = bullets(text.replace(/^#{1,6}\s*(判断の根拠|未確認)\s*$[\s\S]*?(?=^#{1,6}\s|$(?![\s\S]))/gm, ""));
|
|
73
|
+
if (!list.length)
|
|
74
|
+
list = text.split(/\n{2,}/).map((p) => p.replace(/^#{1,6}\s.*$/gm, "").trim()).filter(Boolean);
|
|
75
|
+
return list.slice(0, 50).map((t, i) => ({ id: `B${i + 1}`, kind: "body", text: t.length > 1000 ? `${t.slice(0, 1000)}…` : t, source: t }));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 材料を取り出す。dataDir のファイルをディスクから読み直した別の Workspace で読む(画面・CLI のキャッシュに左右されない)。
|
|
79
|
+
* refs: 参照先(このマシンのパス)
|
|
80
|
+
*/
|
|
81
|
+
export async function extractTaskReview(dataDir, rid, tid, refs, opts = {}) {
|
|
82
|
+
const extractedAt = new Date().toISOString();
|
|
83
|
+
const snap = new Workspace(dataDir);
|
|
84
|
+
await snap.load();
|
|
85
|
+
const request = snap.requests.get(rid);
|
|
86
|
+
if (!request)
|
|
87
|
+
throw new NotFoundError(rid);
|
|
88
|
+
const task = snap.tasksOf(rid).get(tid);
|
|
89
|
+
if (!task) {
|
|
90
|
+
const archived = await readFile(join(snap.requestsDir, rid, "tasks", ".archive", `${tid}.md`)).then(() => true, () => false);
|
|
91
|
+
if (archived)
|
|
92
|
+
throw new TaskReviewRejected("archived", `${rid}/${tid} はアーカイブしたタスクです。新しいレビューは始められません(過去のレビューの履歴は読めます)`);
|
|
93
|
+
throw new NotFoundError(`${rid}/${tid}`);
|
|
94
|
+
}
|
|
95
|
+
if (task.status !== "done")
|
|
96
|
+
throw new TaskReviewRejected("not_done", `${task.ref} はまだ完了していません(${task.status})。レビューは完了したタスクだけです`);
|
|
97
|
+
const notes = [];
|
|
98
|
+
const files = new Map();
|
|
99
|
+
const acc = acceptanceStatus(task);
|
|
100
|
+
const items = task.acceptanceCriteria?.length ? task.acceptanceCriteria.map((c) => ({ id: c.id, kind: "criterion", text: c.text })) : bodyItems(task.body);
|
|
101
|
+
if (!task.acceptanceCriteria?.length)
|
|
102
|
+
notes.push({ code: "no_criteria", target: task.ref, message: "受け入れ基準がありません。本文から取り出した項目で比べます(元の段落を残します)" });
|
|
103
|
+
if (task.acceptanceProblems?.length)
|
|
104
|
+
notes.push({ code: "broken_acceptance", target: task.ref, message: `受け入れ基準・証拠に読めない値があります: ${task.acceptanceProblems.join(" / ")}` });
|
|
105
|
+
for (const i of acc?.items ?? []) {
|
|
106
|
+
if (i.state === "stale")
|
|
107
|
+
notes.push({ code: "stale_evidence", target: `${task.ref}#${i.id}`, message: `${i.id} の証拠は基準を変える前のものです` });
|
|
108
|
+
if (i.state === "missing")
|
|
109
|
+
notes.push({ code: "no_evidence", target: `${task.ref}#${i.id}`, message: `${i.id} に作業した側の証拠がありません` });
|
|
110
|
+
}
|
|
111
|
+
for (const e of acc?.orphans ?? [])
|
|
112
|
+
notes.push({ code: "orphan_evidence", target: `${task.ref}#${e.criterionId}`, message: `${e.criterionId} の証拠は消された基準のものです` });
|
|
113
|
+
if (!task.record?.trim())
|
|
114
|
+
notes.push({ code: "no_record", target: task.ref, message: "変更の記録がありません" });
|
|
115
|
+
const outputs = [...task.outputs, ...(task.repoOutputs ?? []).map((o) => `${o.repo}: ${o.output}`)];
|
|
116
|
+
if (!outputs.length)
|
|
117
|
+
notes.push({ code: "no_outputs", target: task.ref, message: "成果物がありません" });
|
|
118
|
+
const targets = await resolveTargets(task, outputs, refs, opts.targets, notes);
|
|
119
|
+
let patchBytes = 0;
|
|
120
|
+
let totalBytes = 0;
|
|
121
|
+
const put = (path, data) => {
|
|
122
|
+
files.set(path, data);
|
|
123
|
+
totalBytes += data.length;
|
|
124
|
+
};
|
|
125
|
+
for (const t of targets) {
|
|
126
|
+
const local = refs.find((r) => r.name === t.repo).local;
|
|
127
|
+
for (const [i, d] of t.diffs.entries()) {
|
|
128
|
+
const patch = await gitBuf(local, ["diff", "--no-color", "--no-ext-diff", "--no-textconv", "--find-renames", "--unified=3", d.base, d.head, "--"]);
|
|
129
|
+
patchBytes += patch.length;
|
|
130
|
+
if (patchBytes > TASK_REVIEW_LIMITS.patchBytes) {
|
|
131
|
+
throw new TaskReviewRejected("too_large", `差分が上限を超えています(${patchBytes} バイト / 上限 ${TASK_REVIEW_LIMITS.patchBytes})。切り詰めずに断ります。比較対象を絞ってください(--target)`);
|
|
132
|
+
}
|
|
133
|
+
d.patchFile = `diff/${t.repo}/${i + 1}.patch`;
|
|
134
|
+
put(d.patchFile, patch);
|
|
135
|
+
d.changes = await changesOf(local, d.base, d.head);
|
|
136
|
+
for (const c of d.changes) {
|
|
137
|
+
if (c.submodule || c.symlink || c.binary) {
|
|
138
|
+
notes.push({ code: "omitted", target: `${t.repo}:${c.path}`, message: `${c.path} は${c.submodule ? " submodule" : c.symlink ? "シンボリックリンク" : "バイナリ"}なので中身を取り出していません(差分の一覧だけ)` });
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
for (const [side, sha, path] of [
|
|
142
|
+
["base", d.base, c.oldPath ?? c.path],
|
|
143
|
+
["head", d.head, c.path],
|
|
144
|
+
]) {
|
|
145
|
+
if ((side === "base" && c.status === "A") || (side === "head" && c.status === "D") || sha === EMPTY_TREE)
|
|
146
|
+
continue;
|
|
147
|
+
if (!safeRelPath(path)) {
|
|
148
|
+
notes.push({ code: "omitted", target: `${t.repo}:${path}`, message: `${JSON.stringify(path)} は材料のフォルダに置けないパスなので中身を取り出していません` });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const rel = `code/${t.repo}/${sha}/${path}`;
|
|
152
|
+
if (files.has(rel)) {
|
|
153
|
+
if (side === "base")
|
|
154
|
+
c.baseFile = rel;
|
|
155
|
+
else
|
|
156
|
+
c.headFile = rel;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const size = Number(await tryGit(local, ["cat-file", "-s", `${sha}:${path}`]));
|
|
160
|
+
if (!Number.isFinite(size))
|
|
161
|
+
continue;
|
|
162
|
+
if (size > TASK_REVIEW_LIMITS.fileBytes || totalBytes + size > TASK_REVIEW_LIMITS.totalBytes) {
|
|
163
|
+
notes.push({
|
|
164
|
+
code: "omitted",
|
|
165
|
+
target: `${t.repo}@${sha.slice(0, 12)}:${path}`,
|
|
166
|
+
message: `${path}(${side === "base" ? "前" : "後"}・${size} バイト)は上限を超えるので取り出していません(未確認の範囲。差分は材料にあります)`,
|
|
167
|
+
});
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
put(rel, await gitBuf(local, ["cat-file", "blob", `${sha}:${path}`]));
|
|
171
|
+
if (side === "base")
|
|
172
|
+
c.baseFile = rel;
|
|
173
|
+
else
|
|
174
|
+
c.headFile = rel;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const viewpoint = await readViewpoint(dataDir, refs, opts.viewpoint);
|
|
180
|
+
// 品質: レビューを始めたときの最新の品質基準と、タスクに取り込んだ版(観点を替えても、この比較は外さない)
|
|
181
|
+
const latest = qualitySnapshot(snap.project.quality, snap.project.qualityVersion);
|
|
182
|
+
const cfg = { standards: latest.standards ?? [] };
|
|
183
|
+
const { applies, exempt } = latest.state === "set" ? standardsFor(cfg, task.repo) : { applies: [], exempt: [] };
|
|
184
|
+
const quality = {
|
|
185
|
+
latest,
|
|
186
|
+
applies,
|
|
187
|
+
exempt,
|
|
188
|
+
imported: (task.acceptanceCriteria ?? []).flatMap((c) => (c.quality ? [{ criterion: c.id, quality: c.quality.id, hash: c.quality.hash, version: c.quality.version }] : [])),
|
|
189
|
+
diff: taskQualityDiff(task.acceptanceCriteria ?? [], snap.project.quality, task.repo),
|
|
190
|
+
};
|
|
191
|
+
if (latest.state === "unset")
|
|
192
|
+
notes.push({ code: "quality_unset", target: "project.yaml", message: "プロジェクトの品質基準は未設定です(品質は評価しません。p3 quality で設定できます)" });
|
|
193
|
+
if (latest.state === "invalid")
|
|
194
|
+
notes.push({ code: "quality_invalid", target: "project.yaml", message: `プロジェクトの品質基準が読めません(品質は評価しません): ${(latest.problems ?? []).join(" / ")}` });
|
|
195
|
+
if (quality.diff.some((d) => d.kind !== "edited"))
|
|
196
|
+
notes.push({ code: "quality_changed", target: task.ref, message: `タスクに取り込んだ品質基準と最新の品質基準に差があります(${quality.diff.filter((d) => d.kind !== "edited").map((d) => `${d.kind}:${d.quality}`).join(", ")})。基準の改定による不足とコードの逸脱を分けて読んでください` });
|
|
197
|
+
const fileList = [...files.entries()].sort(([a], [b]) => (a < b ? -1 : 1)).map(([path, data]) => ({ path, bytes: data.length, sha256: createHash("sha256").update(data).digest("hex") }));
|
|
198
|
+
const body = {
|
|
199
|
+
version: 1,
|
|
200
|
+
quality,
|
|
201
|
+
request: { id: request.id, title: request.title, status: request.status, body: request.body.trim() },
|
|
202
|
+
task: {
|
|
203
|
+
id: task.id,
|
|
204
|
+
ref: task.ref,
|
|
205
|
+
title: task.title,
|
|
206
|
+
status: task.status,
|
|
207
|
+
body: task.body.trim(),
|
|
208
|
+
...(task.record?.trim() ? { record: task.record.trim() } : {}),
|
|
209
|
+
outputs,
|
|
210
|
+
...(task.acceptanceCriteria?.length ? { criteria: task.acceptanceCriteria } : {}),
|
|
211
|
+
...(task.acceptanceEvidence?.length ? { evidence: task.acceptanceEvidence } : {}),
|
|
212
|
+
...(acc?.items.length ? { evidenceStates: acc.items.map((i) => ({ id: i.id, state: i.state })) } : {}),
|
|
213
|
+
...(task.acceptanceProblems?.length ? { acceptanceProblems: task.acceptanceProblems } : {}),
|
|
214
|
+
},
|
|
215
|
+
items,
|
|
216
|
+
targets,
|
|
217
|
+
viewpoint,
|
|
218
|
+
notes,
|
|
219
|
+
files: fileList,
|
|
220
|
+
};
|
|
221
|
+
return { input: { ...body, extractedAt, hash: taskReviewInputHash(body) }, files };
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 材料の識別子(抽出の日時は入れない)。比較対象の出典(成果物の文字列か、指定した文字列か)も入れない
|
|
225
|
+
* (同じ SHA を比べていれば、指定の仕方によらず同じ材料)
|
|
226
|
+
*/
|
|
227
|
+
export function taskReviewInputHash(i) {
|
|
228
|
+
const targets = i.targets.map(({ sources: _s, ...t }) => t);
|
|
229
|
+
const notes = i.notes.filter((n) => n.code !== "pr_unresolved");
|
|
230
|
+
return createHash("sha256").update(JSON.stringify([i.version, i.request, i.task, i.items, targets, i.viewpoint, notes, i.files, ...(i.quality ? [i.quality] : [])])).digest("hex");
|
|
231
|
+
}
|
|
232
|
+
function parseSpec(raw, names) {
|
|
233
|
+
const s = raw.trim();
|
|
234
|
+
if (PR_RE.test(s))
|
|
235
|
+
return { spec: s, source: s };
|
|
236
|
+
const m = /^([^:\s]+):(.+)$/.exec(s);
|
|
237
|
+
if (m && names.has(m[1]))
|
|
238
|
+
return { repo: m[1], spec: m[2].trim(), source: s };
|
|
239
|
+
return { spec: s, source: s };
|
|
240
|
+
}
|
|
241
|
+
async function resolveTargets(task, outputs, refs, specs, notes) {
|
|
242
|
+
const names = new Set(refs.map((r) => r.name));
|
|
243
|
+
let parsed;
|
|
244
|
+
if (specs?.length)
|
|
245
|
+
parsed = specs.map((s) => parseSpec(s, names));
|
|
246
|
+
else {
|
|
247
|
+
// 成果物のコミット("<参照先>: <成果物>" はその参照先)と PR の URL
|
|
248
|
+
parsed = [];
|
|
249
|
+
for (const o of outputs) {
|
|
250
|
+
const m = /^([^:\s]+): (.*)$/s.exec(o);
|
|
251
|
+
const repo = m && names.has(m[1]) ? m[1] : undefined;
|
|
252
|
+
const text = repo ? m[2] : o;
|
|
253
|
+
for (const sha of commitsInOutput(text))
|
|
254
|
+
parsed.push({ repo, spec: sha, source: o });
|
|
255
|
+
if (PR_RE.test(text.trim()))
|
|
256
|
+
parsed.push({ repo, spec: text.trim(), source: o });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const prs = parsed.filter((p) => PR_RE.test(p.spec));
|
|
260
|
+
for (const p of prs)
|
|
261
|
+
notes.push({ code: "pr_unresolved", target: p.source, message: `${p.spec} は出典として残します。P3 は PR の中身を取りに行きません(比較するなら取得済みの base..head を --target で指定してください)` });
|
|
262
|
+
const usable = parsed.filter((p) => !PR_RE.test(p.spec));
|
|
263
|
+
if (!usable.length) {
|
|
264
|
+
throw new TaskReviewRejected(prs.length ? "pr_unresolved" : "no_target", prs.length
|
|
265
|
+
? `比較対象が PR の URL だけです(${prs.map((p) => p.spec).join(", ")})。取得済みのブランチ・コミットを --target <参照先>:<base>..<head> で指定してください`
|
|
266
|
+
: `${task.ref} の成果物に比較できるコミットがありません。--target <参照先>:<コミット>(複数はカンマ区切り)か <参照先>:<base>..<head> で指定してください`);
|
|
267
|
+
}
|
|
268
|
+
const out = [];
|
|
269
|
+
for (const p of usable) {
|
|
270
|
+
const range = /^(.+?)\.\.(.+)$/.exec(p.spec);
|
|
271
|
+
const shas = range ? [] : p.spec.split(",").map((x) => x.trim()).filter(Boolean);
|
|
272
|
+
if (!range && !shas.every((x) => /^[0-9a-f]{4,40}$/i.test(x)))
|
|
273
|
+
throw new TaskReviewRejected("bad_target", `比較対象の形が違います: ${p.source}(<参照先>:<コミット>[,<コミット>] / <参照先>:<base>..<head>)`);
|
|
274
|
+
const repo = await chooseRepo(task, p, refs, range ? [range[2]] : shas);
|
|
275
|
+
const local = refs.find((r) => r.name === repo).local;
|
|
276
|
+
let t = out.find((x) => x.repo === repo && x.kind === (range ? "range" : "commits"));
|
|
277
|
+
if (range) {
|
|
278
|
+
const base = await revParse(local, range[1], p.source);
|
|
279
|
+
const head = await revParse(local, range[2], p.source);
|
|
280
|
+
const mergeBase = await tryGit(local, ["merge-base", base, head]);
|
|
281
|
+
if (!mergeBase)
|
|
282
|
+
throw new TaskReviewRejected("shallow", `${p.source}: ${range[1]} と ${range[2]} の共通の祖先が見つかりません(浅い履歴・無関係の履歴)。範囲を指定し直してください`);
|
|
283
|
+
const list = (await git(local, ["rev-list", "--reverse", `${mergeBase}..${head}`])).split("\n").filter(Boolean);
|
|
284
|
+
if (list.length > TASK_REVIEW_LIMITS.commits)
|
|
285
|
+
throw new TaskReviewRejected("too_large", `${p.source} のコミットが多すぎます(${list.length} 件 / 上限 ${TASK_REVIEW_LIMITS.commits})`);
|
|
286
|
+
t = { repo, kind: "range", sources: [p.source], commits: [], range: { base, head, mergeBase, baseSpec: range[1], headSpec: range[2] }, diffs: [{ base: mergeBase, head, patchFile: "", changes: [] }] };
|
|
287
|
+
for (const sha of list)
|
|
288
|
+
t.commits.push(await commitOf(local, sha, task.ref));
|
|
289
|
+
out.push(t);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (!t) {
|
|
293
|
+
t = { repo, kind: "commits", sources: [], commits: [], diffs: [] };
|
|
294
|
+
out.push(t);
|
|
295
|
+
}
|
|
296
|
+
t.sources.push(p.source);
|
|
297
|
+
for (const s of shas) {
|
|
298
|
+
const sha = await revParse(local, s, p.source);
|
|
299
|
+
if (t.commits.some((c) => c.sha === sha))
|
|
300
|
+
continue;
|
|
301
|
+
const c = await commitOf(local, sha, task.ref);
|
|
302
|
+
if (c.parents.length > 1) {
|
|
303
|
+
throw new TaskReviewRejected("merge_commit", `${sha.slice(0, 12)} はマージのコミットです(親が ${c.parents.length} つ)。どちらの親と比べるかを --target ${repo}:<親>..${sha.slice(0, 12)} で指定してください`);
|
|
304
|
+
}
|
|
305
|
+
if (c.parents.length === 0 && (await tryGit(local, ["rev-parse", "--is-shallow-repository"])) === "true" && (await isShallowBoundary(local, sha))) {
|
|
306
|
+
throw new TaskReviewRejected("shallow", `${sha.slice(0, 12)} の親が浅い履歴のため読めません。親まで取得するか、--target ${repo}:<base>..<head> で指定してください`);
|
|
307
|
+
}
|
|
308
|
+
t.commits.push(c);
|
|
309
|
+
t.diffs.push({ base: c.parents[0] ?? EMPTY_TREE, head: sha, patchFile: "", changes: [] });
|
|
310
|
+
if (t.commits.length > TASK_REVIEW_LIMITS.commits)
|
|
311
|
+
throw new TaskReviewRejected("too_large", `比較対象のコミットが多すぎます(上限 ${TASK_REVIEW_LIMITS.commits})`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const t of out) {
|
|
315
|
+
const others = [...new Set(t.commits.flatMap((c) => c.otherTasks))];
|
|
316
|
+
if (others.length)
|
|
317
|
+
notes.push({ code: "other_tasks", target: t.repo, message: `比較対象に他のタスク(${others.join(", ")})のコミットが含まれます。このタスクの範囲と分けて読んでください` });
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
321
|
+
async function isShallowBoundary(local, sha) {
|
|
322
|
+
const gitDir = await tryGit(local, ["rev-parse", "--absolute-git-dir"]);
|
|
323
|
+
if (!gitDir)
|
|
324
|
+
return false;
|
|
325
|
+
const text = await readFile(join(gitDir, "shallow"), "utf8").catch(() => "");
|
|
326
|
+
return text.split("\n").includes(sha);
|
|
327
|
+
}
|
|
328
|
+
/** 参照先を決める: 指定 → タスクの作業先 → コミットが見つかる読める参照先が1つ */
|
|
329
|
+
async function chooseRepo(task, p, refs, probe) {
|
|
330
|
+
const ok = (r) => r.status === "ok" && !!r.local;
|
|
331
|
+
const check = async (name) => {
|
|
332
|
+
const r = refs.find((x) => x.name === name);
|
|
333
|
+
if (!r || !ok(r))
|
|
334
|
+
throw new TaskReviewRejected("repo_unavailable", `参照先 ${name} を読めません(${r?.reason ?? "登録されていません"})。p3 repo path ${name} <パス> で登録してください`);
|
|
335
|
+
if ((await tryGit(r.local, ["rev-parse", "--git-dir"])) === undefined)
|
|
336
|
+
throw new TaskReviewRejected("repo_unavailable", `参照先 ${name} は git のリポジトリではありません`);
|
|
337
|
+
return name;
|
|
338
|
+
};
|
|
339
|
+
if (p.repo)
|
|
340
|
+
return check(p.repo);
|
|
341
|
+
if (task.repo && refs.some((r) => r.name === task.repo && ok(r)))
|
|
342
|
+
return check(task.repo);
|
|
343
|
+
const found = [];
|
|
344
|
+
for (const r of refs.filter(ok)) {
|
|
345
|
+
let all = true;
|
|
346
|
+
for (const s of probe)
|
|
347
|
+
if (!(await tryGit(r.local, ["rev-parse", "--verify", "-q", `${s}^{commit}`])))
|
|
348
|
+
all = false;
|
|
349
|
+
if (all)
|
|
350
|
+
found.push(r.name);
|
|
351
|
+
}
|
|
352
|
+
if (found.length === 1)
|
|
353
|
+
return check(found[0]);
|
|
354
|
+
if (!found.length)
|
|
355
|
+
throw new TaskReviewRejected("unknown_commit", `${p.source} が読める参照先の履歴に見つかりません(取得済みか確かめ、--target <参照先>:<コミット> で指定してください)`);
|
|
356
|
+
throw new TaskReviewRejected("ambiguous_repo", `${p.source} が複数の参照先(${found.join(", ")})にあります。--target <参照先>:${p.spec} で指定してください`);
|
|
357
|
+
}
|
|
358
|
+
async function revParse(local, spec, source) {
|
|
359
|
+
if (spec.startsWith("-"))
|
|
360
|
+
throw new TaskReviewRejected("bad_target", `比較対象の形が違います: ${source}`);
|
|
361
|
+
const sha = await tryGit(local, ["rev-parse", "--verify", "-q", `${spec}^{commit}`]);
|
|
362
|
+
if (!sha || !FULL_SHA.test(sha))
|
|
363
|
+
throw new TaskReviewRejected("unknown_commit", `${spec} が参照先の履歴にありません(${source})`);
|
|
364
|
+
return sha;
|
|
365
|
+
}
|
|
366
|
+
async function commitOf(local, sha, ownRef) {
|
|
367
|
+
const raw = await git(local, ["show", "-s", "--format=%P%x00%s%x00%B", sha]);
|
|
368
|
+
const [parents, subject, message] = raw.split("\0");
|
|
369
|
+
const otherTasks = [...new Set([...(message ?? "").matchAll(TASK_REF_RE)].map((m) => m[0]))].filter((r) => r !== ownRef);
|
|
370
|
+
return { sha, parents: parents.trim().split(/\s+/).filter(Boolean), subject: subject.trim(), otherTasks };
|
|
371
|
+
}
|
|
372
|
+
/** 変更の一覧(名前の変更を含む)。submodule(160000)・シンボリックリンク(120000)・バイナリの印を付ける */
|
|
373
|
+
async function changesOf(local, base, head) {
|
|
374
|
+
const raw = await git(local, ["diff", "--raw", "-z", "--no-abbrev", "--find-renames", base, head, "--"]);
|
|
375
|
+
const num = await git(local, ["diff", "--numstat", "-z", "--find-renames", base, head, "--"]);
|
|
376
|
+
const binary = new Set();
|
|
377
|
+
const parts = num.split("\0");
|
|
378
|
+
for (let i = 0; i < parts.length; i++) {
|
|
379
|
+
const m = /^(-|\d+)\t(-|\d+)\t(.*)$/s.exec(parts[i]);
|
|
380
|
+
if (!m)
|
|
381
|
+
continue;
|
|
382
|
+
// 名前の変更は "a\tb\t" の後に古い名前・新しい名前が続く
|
|
383
|
+
const path = m[3] === "" ? parts[i + 2] : m[3];
|
|
384
|
+
if (m[3] === "")
|
|
385
|
+
i += 2;
|
|
386
|
+
if (m[1] === "-")
|
|
387
|
+
binary.add(path);
|
|
388
|
+
}
|
|
389
|
+
const out = [];
|
|
390
|
+
const f = raw.split("\0");
|
|
391
|
+
for (let i = 0; i < f.length - 1;) {
|
|
392
|
+
const meta = /^:(\d{6}) (\d{6}) [0-9a-f]+ [0-9a-f]+ ([AMDRCT])\d*$/.exec(f[i]);
|
|
393
|
+
if (!meta) {
|
|
394
|
+
i++;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const [, oldMode, newMode, st] = meta;
|
|
398
|
+
const renamed = st === "R" || st === "C";
|
|
399
|
+
const oldPath = renamed ? f[i + 1] : undefined;
|
|
400
|
+
const path = renamed ? f[i + 2] : f[i + 1];
|
|
401
|
+
i += renamed ? 3 : 2;
|
|
402
|
+
const mode = st === "D" ? oldMode : newMode;
|
|
403
|
+
out.push({
|
|
404
|
+
status: st,
|
|
405
|
+
path,
|
|
406
|
+
...(oldPath ? { oldPath } : {}),
|
|
407
|
+
...(mode === "160000" || oldMode === "160000" ? { submodule: true } : {}),
|
|
408
|
+
...(mode === "120000" || oldMode === "120000" ? { symlink: true } : {}),
|
|
409
|
+
...(binary.has(path) ? { binary: true } : {}),
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
// --- 観点 -------------------------------------------------------------------------
|
|
415
|
+
/** 既定の観点(どのレビューにも付ける) */
|
|
416
|
+
export const BUILTIN_VIEWPOINT = "受け入れ基準・本文の要件が、比較対象の変更で満たされているかを確かめる。依頼に無い変更・既存の動作を変える変更は意図しない変更の候補に挙げる。" +
|
|
417
|
+
"基準どうしや本文との矛盾は直さず、人が確かめる点に残す。";
|
|
418
|
+
async function readViewpoint(dataDir, refs, spec) {
|
|
419
|
+
const hash = (t) => createHash("sha256").update(t).digest("hex");
|
|
420
|
+
const s = spec?.trim();
|
|
421
|
+
if (!s || s === "builtin")
|
|
422
|
+
return { source: "builtin", text: BUILTIN_VIEWPOINT, hash: hash(BUILTIN_VIEWPOINT) };
|
|
423
|
+
if (s === "project") {
|
|
424
|
+
// 共有のプロジェクトの設定(project.yaml の taskReview.viewpoints)。作業ブランチのファイルは読まない
|
|
425
|
+
const doc = YAML.parse(await readFile(join(dataDir, "project.yaml"), "utf8").catch(() => ""));
|
|
426
|
+
const text = typeof doc?.taskReview?.viewpoints === "string" ? doc.taskReview.viewpoints.trim() : "";
|
|
427
|
+
if (!text)
|
|
428
|
+
throw new TaskReviewRejected("bad_viewpoint", "project.yaml に taskReview.viewpoints がありません(観点を書くか、--viewpoint <参照先>@<SHA>:<パス> で指定してください)");
|
|
429
|
+
if (text.length > TASK_REVIEW_LIMITS.viewpoint)
|
|
430
|
+
throw new TaskReviewRejected("bad_viewpoint", `観点が長すぎます(上限 ${TASK_REVIEW_LIMITS.viewpoint} 文字)`);
|
|
431
|
+
return { source: "project", text, hash: hash(text) };
|
|
432
|
+
}
|
|
433
|
+
const m = /^([^@\s]+)@([0-9a-f]{40}|[^:\s]+):(.+)$/.exec(s);
|
|
434
|
+
if (!m)
|
|
435
|
+
throw new TaskReviewRejected("bad_viewpoint", `観点の指定が違います: ${s}(builtin / project / <参照先>@<SHA>:<パス>)`);
|
|
436
|
+
const [, repo, rev, path] = m;
|
|
437
|
+
const r = refs.find((x) => x.name === repo);
|
|
438
|
+
if (!r || r.status !== "ok" || !r.local)
|
|
439
|
+
throw new TaskReviewRejected("repo_unavailable", `観点の参照先 ${repo} を読めません`);
|
|
440
|
+
if (!safeRelPath(path))
|
|
441
|
+
throw new TaskReviewRejected("bad_viewpoint", `観点のパスが使えません: ${path}`);
|
|
442
|
+
const sha = await tryGit(r.local, ["rev-parse", "--verify", "-q", `${rev}^{commit}`]);
|
|
443
|
+
if (!sha)
|
|
444
|
+
throw new TaskReviewRejected("bad_viewpoint", `観点の ${rev} が ${repo} の履歴にありません`);
|
|
445
|
+
const type = await tryGit(r.local, ["cat-file", "-t", `${sha}:${path}`]);
|
|
446
|
+
if (type !== "blob")
|
|
447
|
+
throw new TaskReviewRejected("bad_viewpoint", `観点のファイル ${repo}@${sha.slice(0, 12)}:${path} がありません`);
|
|
448
|
+
const text = (await git(r.local, ["cat-file", "blob", `${sha}:${path}`])).trim();
|
|
449
|
+
if (text.length > TASK_REVIEW_LIMITS.viewpoint)
|
|
450
|
+
throw new TaskReviewRejected("bad_viewpoint", `観点が長すぎます(上限 ${TASK_REVIEW_LIMITS.viewpoint} 文字)`);
|
|
451
|
+
return { source: "file", text, repo, sha, path, hash: hash(text) };
|
|
452
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex を使わずにタスクのレビューの契約(最後の応答の JSON)を再現する(オフライン開発・デモ・テスト用)。評価はせず、
|
|
3
|
+
* どの比較項目も「判断できない」にする。--engine mock か個人設定の preflight.engine: mock で明示したときだけ使う
|
|
4
|
+
*/
|
|
5
|
+
export class MockTaskReviewer {
|
|
6
|
+
opts;
|
|
7
|
+
constructor(opts = {}) {
|
|
8
|
+
this.opts = opts;
|
|
9
|
+
}
|
|
10
|
+
async ask(input, log, signal) {
|
|
11
|
+
log({ kind: "info", text: "Mock でレビューします(評価はせず、どの比較項目も判断できないにします)" });
|
|
12
|
+
await new Promise((res, rej) => {
|
|
13
|
+
const t = setTimeout(res, this.opts.delayMs ?? 1500);
|
|
14
|
+
signal.addEventListener("abort", () => (clearTimeout(t), rej(new Error("aborted"))), { once: true });
|
|
15
|
+
});
|
|
16
|
+
const json = /<material>\n([\s\S]*?)\n<\/material>/.exec(input.prompt)?.[1];
|
|
17
|
+
const material = JSON.parse(json ?? "{}");
|
|
18
|
+
return {
|
|
19
|
+
message: JSON.stringify({
|
|
20
|
+
overall: "(Mock)評価していません",
|
|
21
|
+
items: (material.items ?? []).map((i) => ({ item: i.id, verdict: "undetermined", reason: "(Mock)評価していません", evidence: [], gaps: ["Codex で実行すると評価します"] })),
|
|
22
|
+
unplanned: [],
|
|
23
|
+
checks: [],
|
|
24
|
+
coverage: { read: "(Mock)読んでいません", unread: "材料の全部" },
|
|
25
|
+
...(material.quality?.state === "set" ? { quality: material.quality.standards.map((q) => ({ standard: q.id, verdict: "undetermined", reason: "(Mock)評価していません", evidence: [] })) } : {}),
|
|
26
|
+
}),
|
|
27
|
+
seconds: 0,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 材料のフォルダのパスの規則(保存と抽出で共有する。Workspace に依存しない) */
|
|
2
|
+
function hasControl(p) {
|
|
3
|
+
for (let i = 0; i < p.length; i++) {
|
|
4
|
+
const c = p.charCodeAt(i);
|
|
5
|
+
if (c < 0x20 || c === 0x7f)
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
/** 材料のフォルダの中に置けるパスか(参照先の中の相対パス。.. ・絶対パス・制御文字は使わない) */
|
|
11
|
+
export function safeRelPath(p) {
|
|
12
|
+
if (!p || p.startsWith("/") || /^[A-Za-z]:/.test(p) || p.includes("\\") || hasControl(p))
|
|
13
|
+
return false;
|
|
14
|
+
return !p.split("/").some((s) => s === ".." || s === "." || s === "");
|
|
15
|
+
}
|