@infodb/p3 0.10.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 +6 -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-DGaoQoIa.js → RequestStatus-RG-OVQYY.js} +1 -1
- package/dist/web/assets/{Tabs-D16MqQxu.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-ChFzBoL2.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 +392 -3
- package/docs/development.md +1 -1
- package/docs/how-to-use.md +261 -5
- package/docs/installation.md +5 -5
- package/lib/cli/args.js +45 -0
- package/lib/cli/help.js +43 -1
- package/lib/cli/main.js +42 -4
- 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 +219 -14
- 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 +7 -1
- package/lib/core/milestoneReview/code.js +129 -0
- package/lib/core/milestoneReview/material.js +148 -0
- package/lib/core/milestoneReview/mockReviewer.js +28 -0
- package/lib/core/milestoneReview/review.js +325 -0
- package/lib/core/milestoneReview/service.js +214 -0
- package/lib/core/milestoneReview/store.js +176 -0
- package/lib/core/ops.js +9 -2
- package/lib/core/preflight/carryover.js +1 -1
- package/lib/core/preflight/codexEngine.js +20 -6
- 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 +101 -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 +43 -2
- package/lib/core/store/preflightStore.js +9 -1
- package/lib/core/store/projectFile.js +18 -1
- package/lib/core/store/workspace.js +122 -14
- 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 +74 -5
- package/lib/server/api/milestoneReviewRoutes.js +70 -0
- package/lib/server/api/routes.js +164 -20
- 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/milestoneGoals.js +57 -0
- package/lib/shared/milestoneReview.js +27 -0
- 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-B4Tr7JzU.js +0 -1
- package/dist/web/assets/TagInput-pSYxm4bz.js +0 -1
- package/dist/web/assets/TaskDrawer-1Ev3RpRV.js +0 -3
- package/dist/web/assets/_requestId-BKhn019m.js +0 -1
- package/dist/web/assets/_requestId-Btpvuu7-.js +0 -30
- package/dist/web/assets/appCtx-D_Iaoh2e.js +0 -1
- package/dist/web/assets/board-DeHdxbN4.js +0 -1
- package/dist/web/assets/done-BFaHGt03.js +0 -1
- package/dist/web/assets/index-BF1xMdJo.css +0 -2
- package/dist/web/assets/index-CDWcKy1L.js +0 -12
- package/dist/web/assets/preload-helper-hSId95YD.js +0 -1
- package/dist/web/assets/release-notes-BWNDFDkH.js +0 -3
- package/dist/web/assets/requestData-B_320uxL.js +0 -1
- package/dist/web/assets/routes-BBD464IS.js +0 -3
- package/dist/web/assets/settings-D7PPrGjT.js +0 -1
- package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
4
|
+
import { REQUEST_ID, TASK_ID } from "../../shared/refs.js";
|
|
5
|
+
import { TASK_REVIEW_STATUSES, } from "../../shared/taskReview.js";
|
|
6
|
+
import { dirs, finishRunFile, readJson, ReviewStoreError, runStamp, updateRunFile, writeJson } from "../reviewRuns.js";
|
|
7
|
+
import { withFileLock } from "../store/fsutil.js";
|
|
8
|
+
import { safeRelPath } from "./paths.js";
|
|
9
|
+
/**
|
|
10
|
+
* タスクの AI レビューの履歴(要望のフォルダの中。要望をアーカイブすれば一緒に動き、タスクをアーカイブしても残る)。
|
|
11
|
+
*
|
|
12
|
+
* requests/<要望ID>/task-reviews/<タスクID>/<run>/input.json 固定した材料(作ったら変えない)
|
|
13
|
+
* requests/<要望ID>/task-reviews/<タスクID>/<run>/material/ 材料のファイル(差分・前後のコード。作ったら変えない)
|
|
14
|
+
* requests/<要望ID>/task-reviews/<タスクID>/<run>/run.json 実行の記録
|
|
15
|
+
* requests/<要望ID>/task-reviews/<タスクID>/<run>/review.json 結果(completed のときだけ。書き終えてから completed にする)
|
|
16
|
+
* requests/<要望ID>/task-reviews/.locks/<タスクID>.lock 状態を変えるときのロック(プロセス間。タスクごと)
|
|
17
|
+
*
|
|
18
|
+
* - キーは "<要望ID>/<タスクID>"。ID の形を確かめ、保存先の外を指すものは断る。同じ run は作り直さない
|
|
19
|
+
* - 保存・終わり・取消の規則はマイルストーンレビューと共通(reviewRuns.ts)
|
|
20
|
+
* - 結果はタスクのファイル(本文・証拠)には書かない。同じ OS の権限でファイルを直接書き換えることは防がない
|
|
21
|
+
*/
|
|
22
|
+
export const TASK_REVIEWS_DIR = "task-reviews";
|
|
23
|
+
const RUN_ID = /^TR-\d{8}-\d{6}-[0-9a-f]{4}$/;
|
|
24
|
+
export function newTaskReviewRunId(now = new Date()) {
|
|
25
|
+
return `TR-${runStamp(now)}-${randomBytes(2).toString("hex")}`;
|
|
26
|
+
}
|
|
27
|
+
export function checkTaskReviewRunId(id) {
|
|
28
|
+
if (!RUN_ID.test(id))
|
|
29
|
+
throw new ReviewStoreError("bad_id", `タスクのレビューの run の ID ではありません: ${JSON.stringify(id)}(TR-YYYYMMDD-HHMMSS-xxxx)`);
|
|
30
|
+
}
|
|
31
|
+
/** キー(<要望ID>/<タスクID>)を分けて確かめる */
|
|
32
|
+
export function parseTaskReviewKey(key) {
|
|
33
|
+
const [rid, tid, extra] = key.split("/");
|
|
34
|
+
if (extra !== undefined || !rid || !tid || !REQUEST_ID.test(rid) || !TASK_ID.test(tid))
|
|
35
|
+
throw new ReviewStoreError("bad_id", `タスクの参照に使えません: ${JSON.stringify(key)}(<要望ID>/T001)`);
|
|
36
|
+
return { rid, tid };
|
|
37
|
+
}
|
|
38
|
+
export class TaskReviewStore {
|
|
39
|
+
requestsDir;
|
|
40
|
+
/** requestsDir: <data>/requests */
|
|
41
|
+
constructor(requestsDir) {
|
|
42
|
+
this.requestsDir = requestsDir;
|
|
43
|
+
}
|
|
44
|
+
within(...parts) {
|
|
45
|
+
const root = resolve(this.requestsDir);
|
|
46
|
+
const p = resolve(root, ...parts);
|
|
47
|
+
if (!p.startsWith(root + sep))
|
|
48
|
+
throw new ReviewStoreError("bad_id", `保存先の外を指します: ${parts.join("/")}`);
|
|
49
|
+
return p;
|
|
50
|
+
}
|
|
51
|
+
reviewsDir(rid) {
|
|
52
|
+
parseTaskReviewKey(`${rid}/T001`);
|
|
53
|
+
return this.within(rid, TASK_REVIEWS_DIR);
|
|
54
|
+
}
|
|
55
|
+
taskDir(key) {
|
|
56
|
+
const { rid, tid } = parseTaskReviewKey(key);
|
|
57
|
+
return this.within(rid, TASK_REVIEWS_DIR, tid);
|
|
58
|
+
}
|
|
59
|
+
runDir(key, run) {
|
|
60
|
+
checkTaskReviewRunId(run);
|
|
61
|
+
return join(this.taskDir(key), run);
|
|
62
|
+
}
|
|
63
|
+
materialDir(key, run) {
|
|
64
|
+
return join(this.runDir(key, run), "material");
|
|
65
|
+
}
|
|
66
|
+
/** タスクの状態を変えるときのロック(ほかのプロセスの開始・終わり・取消と1つずつにする。別のタスクは独立) */
|
|
67
|
+
withLock(key, fn) {
|
|
68
|
+
const { rid, tid } = parseTaskReviewKey(key);
|
|
69
|
+
return withFileLock(join(this.reviewsDir(rid), ".locks", `${tid}.lock`), fn, {
|
|
70
|
+
busyMessage: `${key} のレビューの記録を変えられませんでした(別のプロセスが使っています。少し待ってやり直してください)`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** run の ID(新しい順) */
|
|
74
|
+
async runIds(key) {
|
|
75
|
+
return (await dirs(this.taskDir(key))).filter((r) => RUN_ID.test(r)).sort().reverse();
|
|
76
|
+
}
|
|
77
|
+
async hasHistory(key) {
|
|
78
|
+
return (await this.runIds(key)).length > 0;
|
|
79
|
+
}
|
|
80
|
+
/** 履歴のあるタスク(アーカイブしたタスクも含む) */
|
|
81
|
+
async tasksWithHistory(rid) {
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const d of await dirs(this.reviewsDir(rid)))
|
|
84
|
+
if (TASK_ID.test(d) && (await this.hasHistory(`${rid}/${d}`)))
|
|
85
|
+
out.push(d);
|
|
86
|
+
return out.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 新しい run を作る(材料のファイル・input.json・running の run.json)。同じ ID が既にあれば exists で断る(上書きしない)。
|
|
90
|
+
* 呼ぶ側がロックの中で呼ぶ(同じタスクで実行中の run を2つ作らないため)
|
|
91
|
+
*/
|
|
92
|
+
async create(input, files, run) {
|
|
93
|
+
const key = `${run.request}/${run.task}`;
|
|
94
|
+
const dir = this.runDir(key, run.id);
|
|
95
|
+
const material = join(dir, "material");
|
|
96
|
+
// 書く前に全部のパスを確かめる(途中で断って作りかけを残さない)
|
|
97
|
+
const targets = [...files].map(([rel, data]) => {
|
|
98
|
+
const path = resolve(material, rel);
|
|
99
|
+
if (!safeRelPath(rel) || !path.startsWith(resolve(material) + sep))
|
|
100
|
+
throw new ReviewStoreError("bad_id", `材料のファイルのパスに使えません: ${JSON.stringify(rel)}`);
|
|
101
|
+
return { path, data };
|
|
102
|
+
});
|
|
103
|
+
await mkdir(this.taskDir(key), { recursive: true });
|
|
104
|
+
try {
|
|
105
|
+
await mkdir(dir);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (e.code === "EEXIST")
|
|
109
|
+
throw new ReviewStoreError("exists", `既にある run です: ${key}/${run.id}`);
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
for (const { path, data } of targets) {
|
|
114
|
+
await mkdir(dirname(path), { recursive: true });
|
|
115
|
+
// 作ったばかりのフォルダの中だけに書く(途中がシンボリックリンクなら断る。新しいファイルとしてだけ作る)
|
|
116
|
+
await assertNoLinks(material, path);
|
|
117
|
+
await writeFile(path, data, { flag: "wx" });
|
|
118
|
+
}
|
|
119
|
+
await writeJson(join(dir, "input.json"), input);
|
|
120
|
+
await writeJson(join(dir, "run.json"), run);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
// 作りかけの run は残さない(一覧に壊れた記録として出さない)
|
|
124
|
+
await rm(dir, { recursive: true, force: true });
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async readRun(key, run) {
|
|
129
|
+
return readJson(join(this.runDir(key, run), "run.json"), `${key}/${run}`, checkRunShape);
|
|
130
|
+
}
|
|
131
|
+
async readInput(key, run) {
|
|
132
|
+
return readJson(join(this.runDir(key, run), "input.json"), `${key}/${run} の input.json`, (x) => {
|
|
133
|
+
const i = x;
|
|
134
|
+
if (!i.task || !Array.isArray(i.items) || !Array.isArray(i.targets) || typeof i.hash !== "string")
|
|
135
|
+
throw new Error("形が違います");
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async readResult(key, run) {
|
|
139
|
+
return readJson(join(this.runDir(key, run), "review.json"), `${key}/${run} の review.json`, (x) => {
|
|
140
|
+
const r = x;
|
|
141
|
+
if (typeof r.overall !== "string" || !Array.isArray(r.items))
|
|
142
|
+
throw new Error("形が違います");
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** 1回分(無ければ not_found、どれかが読めなければ broken) */
|
|
146
|
+
async get(key, run) {
|
|
147
|
+
const r = await this.readRun(key, run);
|
|
148
|
+
const input = await this.readInput(key, run);
|
|
149
|
+
const result = r.status === "completed" ? await this.readResult(key, run) : undefined;
|
|
150
|
+
return { run: r, input, ...(result ? { result } : {}) };
|
|
151
|
+
}
|
|
152
|
+
/** 一覧(新しい順)。読めない記録も broken として出す(隠さない) */
|
|
153
|
+
async list(key) {
|
|
154
|
+
const out = [];
|
|
155
|
+
for (const id of await this.runIds(key)) {
|
|
156
|
+
try {
|
|
157
|
+
const rec = await this.get(key, id);
|
|
158
|
+
const verdicts = {};
|
|
159
|
+
for (const i of rec.result?.items ?? [])
|
|
160
|
+
verdicts[i.verdict] = (verdicts[i.verdict] ?? 0) + 1;
|
|
161
|
+
out.push({ state: "ok", run: rec.run, inputHash: rec.input.hash, items: rec.input.items.length, ...(rec.result ? { verdicts } : {}) });
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
out.push({ state: "broken", id, error: e.message });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const at = (x) => (x.state === "ok" ? x.run.startedAt.replace(/[-:]/g, "").replace("T", "-") : x.id.slice(3, 18));
|
|
168
|
+
return out.sort((a, b) => (at(a) < at(b) ? 1 : at(a) > at(b) ? -1 : 0));
|
|
169
|
+
}
|
|
170
|
+
async updateRunning(key, run, fn) {
|
|
171
|
+
return updateRunFile(`${key}/${run}`, await this.readRun(key, run), fn, (r) => writeJson(join(this.runDir(key, run), "run.json"), r));
|
|
172
|
+
}
|
|
173
|
+
async finish(key, run, patch, result) {
|
|
174
|
+
const dir = this.runDir(key, run);
|
|
175
|
+
return finishRunFile(`${key}/${run}`, await this.readRun(key, run), patch, result, {
|
|
176
|
+
writeRun: (r) => writeJson(join(dir, "run.json"), r),
|
|
177
|
+
writeResult: (r) => writeJson(join(dir, "review.json"), r),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/** 材料のファイルの一覧(材料のフォルダからの相対パス。シンボリックリンクは含めない) */
|
|
181
|
+
async materialFiles(key, run) {
|
|
182
|
+
const root = this.materialDir(key, run);
|
|
183
|
+
const out = [];
|
|
184
|
+
const walk = async (d, rel) => {
|
|
185
|
+
for (const e of await readdir(d, { withFileTypes: true }).catch(() => [])) {
|
|
186
|
+
const r = rel ? `${rel}/${e.name}` : e.name;
|
|
187
|
+
if (e.isDirectory())
|
|
188
|
+
await walk(join(d, e.name), r);
|
|
189
|
+
else if (e.isFile())
|
|
190
|
+
out.push(r);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
await walk(root, "");
|
|
194
|
+
return out.sort();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** root から path までの途中(root を除く)にシンボリックリンクが無いこと */
|
|
198
|
+
async function assertNoLinks(root, path) {
|
|
199
|
+
const parts = path.slice(resolve(root).length + 1).split(sep);
|
|
200
|
+
let cur = resolve(root);
|
|
201
|
+
for (const p of parts.slice(0, -1)) {
|
|
202
|
+
cur = join(cur, p);
|
|
203
|
+
if ((await lstat(cur)).isSymbolicLink())
|
|
204
|
+
throw new ReviewStoreError("bad_id", `材料のフォルダの中にシンボリックリンクがあります: ${cur}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function checkRunShape(x) {
|
|
208
|
+
const r = x;
|
|
209
|
+
if (typeof r.id !== "string" || typeof r.request !== "string" || typeof r.task !== "string" || !TASK_REVIEW_STATUSES.includes(r.status) || typeof r.startedAt !== "string") {
|
|
210
|
+
throw new Error("形が違います");
|
|
211
|
+
}
|
|
212
|
+
if (!Array.isArray(r.log))
|
|
213
|
+
throw new Error("log がありません");
|
|
214
|
+
}
|
|
@@ -22,7 +22,39 @@ export const AI_MANIFEST = {
|
|
|
22
22
|
"ここに無い API は /api/projects/:project/... の下に置く(通常の serve の /api/... と同じ)。変える操作には x-p3-project-generation が要る(無ければ 428、違えば 409 code: changed)。" +
|
|
23
23
|
"プロジェクトを書かないデータの API は 404 code: project_required。/api/chatgpt(engine は null)・/api/user-theme・/api/events(一覧・テーマ・接続の変更)はプロジェクトを選ばずに使える",
|
|
24
24
|
},
|
|
25
|
-
{
|
|
25
|
+
{
|
|
26
|
+
method: "GET|POST",
|
|
27
|
+
path: "/api/quality",
|
|
28
|
+
desc: "品質基準(project.yaml の quality)。GET は {quality: {state: unset | set | invalid, ...}, version, diffs(採用したテンプレートの改版の差分), templates}。" +
|
|
29
|
+
"POST {ops: [{op: init | adopt | upgrade | add | replace | edit | remove | exempt | unexempt, ...}], version?} で操作を順に当てて quality だけを書く(version が違えば 409 quality_conflict、" +
|
|
30
|
+
"規則に合わなければ 400 quality_invalid、読めない設定は 400 quality_unreadable。設定の保存 PUT /api/project は quality を書かない)。コマンドは実行しない",
|
|
31
|
+
},
|
|
32
|
+
{ method: "GET", path: "/api/requests/:rid/tasks/:tid/quality-diff", desc: "タスクの受け入れ基準と今の品質基準の差分 {quality, version, diff: [{kind: add | change | remove | exempt | edited, quality, criterion?, text?, reason?}]}(読むだけ)" },
|
|
33
|
+
{
|
|
34
|
+
method: "POST",
|
|
35
|
+
path: "/api/requests/:rid/tasks/:tid/quality-import",
|
|
36
|
+
desc: "差分を明示して受け入れ基準に取り込む {keys?: [\"<kind>:<品質 ID>\"], rev?}(add は足す、change は文と出典を直す(証拠は再確認が必要になる)、remove・exempt は消す)。POST tasks の quality: auto | none | [ID] で作るときにも取り込む",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
method: "POST",
|
|
40
|
+
path: "/api/quality/improvements/preview",
|
|
41
|
+
desc: "品質の不足の診断と改善要望の原稿 {source: {type: project} | {type: task-review, request, task, run} | {type: milestone-review, milestone, run}, keys?}。" +
|
|
42
|
+
"{findings: [{key, kind: unset | invalid | violated | undetermined | exempt, ...}], hash, registered, picked, draft?}(読むだけ。除外は既定で選ばない)",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
method: "POST",
|
|
46
|
+
path: "/api/quality/improvements",
|
|
47
|
+
desc: "改善要望を明示して登録する {source, keys, title, body, hash, reopenClosed?}(201 {request, keys})。診断が変わっていれば 409 diagnosis_changed、開いている登録先があれば 409 existing(existing.request)、" +
|
|
48
|
+
"閉じた要望で扱った不足は reopenClosed が無ければ 409 closed_existing。不足ごとの登録先は quality-improvements.json に残す",
|
|
49
|
+
},
|
|
50
|
+
{ method: "GET", path: "/api/quality/templates/:id[?version=]", desc: "同梱の品質基準のテンプレートの中身(版つきの例。業界の標準への認証ではない)" },
|
|
51
|
+
{ method: "GET", path: "/api/project", desc: "プロジェクト設定と milestonesVersion(マイルストーンの版)" },
|
|
52
|
+
{
|
|
53
|
+
method: "PUT",
|
|
54
|
+
path: "/api/project",
|
|
55
|
+
desc: "プロジェクト設定を項目ごとに保存する。milestones の各項目は purpose(目的)・goals(予定機能 {id, text})を持てる(キーを省くと今の値を残す。null・空で消す)。" +
|
|
56
|
+
"milestonesVersion を付けると最新の版と照らし、違えば 409 code: milestones_conflict で何も書かない",
|
|
57
|
+
},
|
|
26
58
|
{
|
|
27
59
|
method: "POST",
|
|
28
60
|
path: "/api/reload",
|
|
@@ -35,7 +67,7 @@ export const AI_MANIFEST = {
|
|
|
35
67
|
desc: "参照先(共有の定義)。GET は読めたかの状態と、ローカルの画面にだけこのマシンのパス。POST {name, role?, readFirst?, writable?, map?, path?}",
|
|
36
68
|
},
|
|
37
69
|
{ method: "PUT|DELETE", path: "/api/repos/:name/path", desc: "参照先のこのマシンのパス(個人設定)。このマシンのローカルの画面(Origin)からだけ" },
|
|
38
|
-
{ method: "GET", path: "/api/requests[?parent=<要望ID>]", desc: "要望の一覧と進捗(更新の新しい順。parent
|
|
70
|
+
{ method: "GET", path: "/api/requests[?parent=<要望ID>]", desc: "要望の一覧と進捗(更新の新しい順。parent で直下の子だけを親の表示順に)。止まっている自分のタスクの数 blocked と配下の数 subtree.blocked(作業中にも数える)、タスクの印に停止の今の値 block" },
|
|
39
71
|
{ method: "POST", path: "/api/requests", desc: "要望の作成(parent で子の要望にする。省いた期限・マイルストーン・タグは親から写す)" },
|
|
40
72
|
{
|
|
41
73
|
method: "GET",
|
|
@@ -56,8 +88,18 @@ export const AI_MANIFEST = {
|
|
|
56
88
|
"重複・無い要望・直下の子でない・足りないは 409 code: child_order_invalid(reason・ids・今の並び children。子が変わっていれば読み直す)、rev が違えば 409 code: rev_conflict。" +
|
|
57
89
|
"表示の順で、実行の順・着手できるかは表さない",
|
|
58
90
|
},
|
|
59
|
-
{ method: "GET|POST", path: "/api/requests/:rid/tasks", desc: "
|
|
60
|
-
{ method: "GET|PATCH|DELETE", path: "/api/requests/:rid/tasks/:tid", desc: "タスク(GET は置き換えの印 superseded
|
|
91
|
+
{ method: "GET|POST", path: "/api/requests/:rid/tasks", desc: "要望のタスク(GET の ?blocked=true で止まっているものだけ(status・area・q と AND)。POST の criteria: [文] で受け入れ基準を付ける(ID は p3 が振る)。対応済の要望に未完了のタスクを足すと進行中に戻し reopened を返す。対応済の祖先も戻して reopenedAncestors、完了済の祖先は warnings の ancestor_done)" },
|
|
92
|
+
{ method: "GET|PATCH|DELETE", path: "/api/requests/:rid/tasks/:tid", desc: "タスク(GET は置き換えの印 superseded と受け入れ基準の状態 acceptance(不足 shortfalls。基準なしは null)も返す。PATCH は rev で楽観ロック、null で項目を消す。置き換えられたタスクを作業中にすると warnings を添える。" +
|
|
93
|
+
"受け入れ基準・証拠は PATCH の acceptance: [{op: add|edit|remove|order|record|unrecord, ...}] で順に当て、規則に合わなければ何も書かず 400 code: acceptance_invalid。" +
|
|
94
|
+
"済みのタスクの基準・証拠の中身が変わると済みを外し checkCleared を返す。" +
|
|
95
|
+
"止まっている理由(停止)は PATCH の blockOp: {op: set, reason, decision?}(作業中だけ。内容を直しても since は変えない)/ {op: clear, resolution}(解除。状態は変えない)で変え、" +
|
|
96
|
+
"日時・履歴は受け付けない。規則に合わなければ 400 block_invalid / block_not_doing、止まったまま未着手・完了へ動かすと 409 blocked(解除と移動を同じ PATCH に書けば一緒に保存する))" },
|
|
97
|
+
{
|
|
98
|
+
method: "GET",
|
|
99
|
+
path: "/api/requests/:rid/archived-tasks[/:tid]",
|
|
100
|
+
desc: "アーカイブしたタスク(読むだけ。各タスクに archived: true)。一覧は {request, tasks, errors}(ID の数値順。壊れたファイルは errors)、" +
|
|
101
|
+
"1件は {task}。無い → 404、読めない → 500 code: archive_unreadable。通常の tasks・進捗・対応済の判定には入らない。DELETE /tasks/:tid がアーカイブする",
|
|
102
|
+
},
|
|
61
103
|
{ method: "POST", path: "/api/requests/:rid/preflight", desc: "Preflight の実行 {engine?: codex|mock, note?: メモ}。前回の結果とまだ渡していないメモを引き継ぐ" },
|
|
62
104
|
{ method: "GET|POST", path: "/api/requests/:rid/notes", desc: "Preflight へのメモ(GET は渡し済みか・次に引き継ぐ前回の run も返す。POST {body})" },
|
|
63
105
|
{
|
|
@@ -97,7 +139,9 @@ export const AI_MANIFEST = {
|
|
|
97
139
|
{
|
|
98
140
|
method: "PATCH",
|
|
99
141
|
path: "/api/requests/:rid/preflight/:run/drafts/:key",
|
|
100
|
-
desc: "タスク案を直す {title?, description?, include?, repo?, expectedTitle?}。
|
|
142
|
+
desc: "タスク案を直す {title?, description?, include?, repo?, acceptanceCriteria?, expectedTitle?, expectedCriteria?}。" +
|
|
143
|
+
"acceptanceCriteria は受け入れ基準の並び全体 [{id?, text}](id は残し、無い項目に振る。空で基準なし)で、expectedCriteria(編集を始めたときの基準)が要る。違えば 409 rev_conflict。" +
|
|
144
|
+
"expectedTitle(編集を始めたときの題。制御用で案には書かない)を渡すと、" +
|
|
101
145
|
"案のファイルを読み直した今の題と比べ、違えば 409 code: rev_conflict(current に今の案)で書かない。画面から題を変えるときは必ず渡す",
|
|
102
146
|
},
|
|
103
147
|
{
|
|
@@ -147,6 +191,31 @@ export const AI_MANIFEST = {
|
|
|
147
191
|
path: "/api/release-generations/:id[/cancel]",
|
|
148
192
|
desc: "生成1件 {status: running|completed|failed|cancelled, failure?, items(文と出典), markdown(本文の案), warnings, materialChanged, log} / 取り消し",
|
|
149
193
|
},
|
|
194
|
+
{
|
|
195
|
+
method: "POST",
|
|
196
|
+
path: "/api/requests/:rid/tasks/:tid/review-preview",
|
|
197
|
+
desc: "タスクの AI レビューの今の材料の要約と hash {targets?, viewpoint?}(比較項目・作業した側の証拠の状態・比較対象・観点の出典・注意・engineRequired。何も書かない)",
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
method: "GET|POST",
|
|
201
|
+
path: "/api/requests/:rid/tasks/:tid/reviews",
|
|
202
|
+
desc: "タスクの AI レビューの履歴(新しい順。読めない記録も broken)/ 始める(202。{targets?, viewpoint?, engine?, expectedHash?}。完了したタスクだけ。" +
|
|
203
|
+
"材料が変わっていれば 409 material_changed、実行中なら 409 running、Preflight の担当が agent で engine を明示していなければ 400 engine_required)。結果はタスクの状態・済み・基準・証拠を変えない",
|
|
204
|
+
},
|
|
205
|
+
{ method: "GET", path: "/api/requests/:rid/tasks/:tid/reviews/:run", desc: "タスクの AI レビューの1回分(固定した材料・結果。実行中は所有者の状態 owner)。結果を直す口は無い" },
|
|
206
|
+
{ method: "POST", path: "/api/requests/:rid/tasks/:tid/reviews/:run/cancel", desc: "タスクの AI レビューを取り消す {acknowledgeStopped?}(マイルストーンレビューと同じ規則)" },
|
|
207
|
+
{ method: "GET", path: "/api/milestone-reviews", desc: "レビューの履歴のあるマイルストーン {milestones}(project.yaml に無い孤立も。履歴のあるマイルストーンは消せず ID も変えられない)" },
|
|
208
|
+
{ method: "GET", path: "/api/milestones/:mid/review-preview", desc: "マイルストーンレビューの今の材料(比較単位・目的・要望の件数と状態・参照先のコード・範囲・警告・hash)。何も書かない" },
|
|
209
|
+
{
|
|
210
|
+
method: "GET|POST",
|
|
211
|
+
path: "/api/milestones/:mid/reviews",
|
|
212
|
+
desc: "レビューの履歴 {items}(新しい順。読めない記録は state: broken)/ 実行を始める {engine?: codex|mock}(202。目的も予定機能も無ければ 400 no_goals、実行中は 409 running)",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
method: "GET|POST",
|
|
216
|
+
path: "/api/milestones/:mid/reviews/:run[/cancel]",
|
|
217
|
+
desc: "1回分 {run, input, result, owner?} / 取消 {acknowledgeStopped?}(ほかのプロセスの run は要求を残す。終わっている・所有者が動いていれば 409)。結果は参考で、要望・ノート・リリース済みを変えない",
|
|
218
|
+
},
|
|
150
219
|
{ method: "GET", path: "/api/resolve?q=&request=", desc: "参照・タイトルから対象を特定" },
|
|
151
220
|
{ method: "GET", path: "/api/chatgpt", desc: "ChatGPT プランの接続の状態(トークンは返さない)。このマシンからだけ" },
|
|
152
221
|
{ method: "POST", path: "/api/chatgpt/login|cancel|paste|logout", desc: "サインインの開始・取消・コールバックの URL の貼り付け・解除。このマシンのローカルの画面(Origin)からだけ" },
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { extractReviewInput } from "../../core/milestoneReview/material.js";
|
|
4
|
+
import { ReviewCancelRefused, ReviewRejected } from "../../core/milestoneReview/service.js";
|
|
5
|
+
import { checkReviewMilestoneId, ReviewStoreError } from "../../core/milestoneReview/store.js";
|
|
6
|
+
/**
|
|
7
|
+
* マイルストーンレビュー(画面のため)。規則と保存は core/milestoneReview(CLI の p3 milestone review と同じ)。
|
|
8
|
+
*
|
|
9
|
+
* GET /milestone-reviews 履歴のあるマイルストーン(project.yaml に無い孤立も)
|
|
10
|
+
* GET /milestones/:mid/review-preview 今の材料(比較単位・目的・要望の件数と状態・参照先のコード・範囲・警告・hash)。何も書かない
|
|
11
|
+
* GET /milestones/:mid/reviews 履歴(新しい順。読めない記録も broken で出す)
|
|
12
|
+
* POST /milestones/:mid/reviews 実行を始める(202。目的も予定機能も無ければ 400 no_goals、実行中なら 409 running)
|
|
13
|
+
* GET /milestones/:mid/reviews/:run 1回分(固定した材料・結果。実行中は所有者の状態 owner)
|
|
14
|
+
* POST /milestones/:mid/reviews/:run/cancel 取り消す(ほかのプロセスの run は要求を残す)。{ acknowledgeStopped: true } は
|
|
15
|
+
* 所有者の分からない run を人が明示して中断する(ほかの環境のプロセスを止めたとは限らない)
|
|
16
|
+
*/
|
|
17
|
+
const actorOf = (c) => c.req.header("x-p3-actor") ?? "human:web";
|
|
18
|
+
export function milestoneReviewRoutes(ctx) {
|
|
19
|
+
const app = new Hono();
|
|
20
|
+
const svc = () => ctx.milestoneReview;
|
|
21
|
+
app.onError((err, c) => {
|
|
22
|
+
if (err instanceof ReviewStoreError) {
|
|
23
|
+
const status = err.code === "not_found" ? 404 : err.code === "bad_id" ? 400 : err.code === "broken" ? 422 : 409;
|
|
24
|
+
return c.json({ error: err.message, code: err.code }, status);
|
|
25
|
+
}
|
|
26
|
+
if (err instanceof ReviewRejected) {
|
|
27
|
+
const status = err.code === "running" || err.code === "material_changed" ? 409 : err.code === "unknown_milestone" ? 404 : 400;
|
|
28
|
+
return c.json({ error: err.message, code: err.code, ...(err.running ? { run: err.running } : {}) }, status);
|
|
29
|
+
}
|
|
30
|
+
if (err instanceof ReviewCancelRefused)
|
|
31
|
+
return c.json({ error: err.message, code: err.code }, 409);
|
|
32
|
+
if (err instanceof z.ZodError)
|
|
33
|
+
return c.json({ error: "invalid input", issues: err.issues }, 400);
|
|
34
|
+
console.error(err);
|
|
35
|
+
return c.json({ error: err.message }, 400);
|
|
36
|
+
});
|
|
37
|
+
app.get("/milestone-reviews", async (c) => c.json({ milestones: await ctx.ws.milestoneReviews.milestones() }));
|
|
38
|
+
app.get("/milestones/:mid/review-preview", async (c) => {
|
|
39
|
+
const mid = c.req.param("mid");
|
|
40
|
+
checkReviewMilestoneId(mid);
|
|
41
|
+
const i = await extractReviewInput(ctx.ws.dataDir, mid, ctx.ws.refs());
|
|
42
|
+
const statuses = {};
|
|
43
|
+
for (const r of i.requests)
|
|
44
|
+
statuses[r.status] = (statuses[r.status] ?? 0) + 1;
|
|
45
|
+
return c.json({
|
|
46
|
+
milestone: i.milestone,
|
|
47
|
+
units: i.units,
|
|
48
|
+
requests: i.requests.length,
|
|
49
|
+
statuses,
|
|
50
|
+
context: i.context.length,
|
|
51
|
+
code: i.code ?? [],
|
|
52
|
+
warnings: i.warnings,
|
|
53
|
+
...(i.quality ? { quality: { state: i.quality.state, version: i.quality.version, standards: (i.quality.standards ?? []).map((q) => ({ id: q.id, text: q.text, exempt: q.exempt?.reason })) } } : {}),
|
|
54
|
+
scope: i.scope,
|
|
55
|
+
hash: i.hash,
|
|
56
|
+
extractedAt: i.extractedAt,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
app.get("/milestones/:mid/reviews", async (c) => c.json({ items: await svc().list(c.req.param("mid")) }));
|
|
60
|
+
app.post("/milestones/:mid/reviews", async (c) => {
|
|
61
|
+
const { engine, expectedHash } = z.object({ engine: z.enum(["codex", "mock"]).optional(), expectedHash: z.string().optional() }).parse(await c.req.json().catch(() => ({})));
|
|
62
|
+
return c.json(await svc().start(c.req.param("mid"), actorOf(c), engine, { expectedHash }), 202);
|
|
63
|
+
});
|
|
64
|
+
app.get("/milestones/:mid/reviews/:run", async (c) => c.json(await svc().get(c.req.param("mid"), c.req.param("run"))));
|
|
65
|
+
app.post("/milestones/:mid/reviews/:run/cancel", async (c) => {
|
|
66
|
+
const { acknowledgeStopped } = z.object({ acknowledgeStopped: z.boolean().optional() }).parse(await c.req.json().catch(() => ({})));
|
|
67
|
+
return c.json(await svc().cancel(c.req.param("mid"), c.req.param("run"), actorOf(c), { acknowledgeStopped }));
|
|
68
|
+
});
|
|
69
|
+
return app;
|
|
70
|
+
}
|