@infodb/p3 0.11.0 → 0.13.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 -33
- package/dist/web/assets/CompletionReview-gZKZrDu_.js +1 -0
- package/dist/web/assets/ImprovementDialog-Dno6dPnG.js +1 -0
- package/dist/web/assets/Outputs-BgHalMGb.js +1 -0
- package/dist/web/assets/RequestStatus-hZcBUUIu.js +1 -0
- package/dist/web/assets/Tabs-C3NmwCc3.js +1 -0
- package/dist/web/assets/TagInput-B2b862qn.js +1 -0
- package/dist/web/assets/TaskDrawer-4BQBELXa.js +6 -0
- package/dist/web/assets/_requestId-BMAG1t3o.js +1 -0
- package/dist/web/assets/_requestId-tbg2pA2S.js +1 -0
- package/dist/web/assets/archive-DMl6WyOe.js +1 -0
- package/dist/web/assets/board-BMTcHKyt.js +1 -0
- package/dist/web/assets/done-CL6Nlsua.js +1 -0
- package/dist/web/assets/draft-BvGxfD7v.js +2 -0
- package/dist/web/assets/index-Dp7Fc4VI.css +2 -0
- package/dist/web/assets/index-KdlgMitg.js +12 -0
- package/dist/web/assets/metrics-Cu7gJ7Rk.js +1 -0
- package/dist/web/assets/new-DTXWHuFO.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-oLCrNCwz.js +1 -0
- package/dist/web/assets/quality-RFd-7k3r.js +1 -0
- package/dist/web/assets/release-notes-Bpdi6RdY.js +5 -0
- package/dist/web/assets/requestData-CbFxwW5w.js +1 -0
- package/dist/web/assets/routes-BIt8bExF.js +6 -0
- package/dist/web/assets/settings-CsCqF_1B.js +1 -0
- package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
- package/dist/web/assets/ui-BGK72r3u.js +1 -0
- package/dist/web/assets/workTarget-CySfKyfB.js +30 -0
- package/dist/web/index.html +4 -4
- package/docs/architecture.md +610 -33
- package/docs/development.md +61 -17
- package/docs/how-to-use.md +554 -17
- package/docs/installation.md +235 -144
- package/docs/publishing.md +1 -1
- package/lib/cli/agentsStatus.js +197 -0
- package/lib/cli/args.js +111 -2
- package/lib/cli/guide.js +27 -0
- package/lib/cli/guide.md +214 -0
- package/lib/cli/help.js +74 -1
- package/lib/cli/main.js +97 -17
- package/lib/cli/metricsCommands.js +77 -0
- package/lib/cli/output.js +19 -1
- package/lib/cli/preflightCommands.js +7 -1
- package/lib/cli/project.js +13 -24
- package/lib/cli/qualityCommands.js +188 -0
- package/lib/cli/readOnly.js +17 -0
- package/lib/cli/requestCommands.js +33 -4
- package/lib/cli/requirementCommands.js +288 -0
- package/lib/cli/retroCommands.js +106 -0
- package/lib/cli/revisitCommands.js +73 -0
- package/lib/cli/showView.js +183 -4
- package/lib/cli/taskCommands.js +341 -20
- package/lib/cli/taskReviewCommands.js +178 -0
- package/lib/cli/userConfig.js +47 -0
- package/lib/core/completionRefs.js +46 -0
- package/lib/core/context.js +4 -1
- package/lib/core/metrics/definitions.js +434 -0
- package/lib/core/metrics/index.js +88 -0
- package/lib/core/metrics/manual.js +180 -0
- 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 +23 -3
- package/lib/core/preflight/carryover.js +6 -2
- package/lib/core/preflight/codexEngine.js +34 -17
- package/lib/core/preflight/diagnose.js +4 -9
- package/lib/core/preflight/engine.js +15 -0
- package/lib/core/preflight/hostPaths.js +260 -0
- package/lib/core/preflight/input.js +33 -5
- package/lib/core/preflight/instructions.js +36 -2
- package/lib/core/preflight/mockEngine.js +24 -2
- package/lib/core/preflight/render.js +22 -3
- package/lib/core/preflight/service.js +99 -8
- package/lib/core/preflight/uiRender.js +3 -0
- 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 +294 -11
- package/lib/core/retrospective.js +208 -0
- package/lib/core/reviewCandidates.js +56 -0
- package/lib/core/reviewRuns.js +205 -0
- package/lib/core/store/archivedTasks.js +74 -0
- package/lib/core/store/collection.js +32 -3
- package/lib/core/store/normalize.js +35 -2
- package/lib/core/store/preflightStore.js +23 -1
- package/lib/core/store/projectFile.js +10 -0
- package/lib/core/store/workspace.js +49 -3
- package/lib/core/taskReview/material.js +459 -0
- package/lib/core/taskReview/mockReviewer.js +30 -0
- package/lib/core/taskReview/paths.js +15 -0
- package/lib/core/taskReview/review.js +312 -0
- package/lib/core/taskReview/service.js +187 -0
- package/lib/core/taskReview/store.js +214 -0
- package/lib/server/api/manifest.js +104 -5
- package/lib/server/api/milestoneReviewRoutes.js +4 -3
- package/lib/server/api/routes.js +265 -17
- package/lib/server/api/taskReviewRoutes.js +66 -0
- package/lib/server/server.js +2 -2
- package/lib/shared/acceptance.js +618 -0
- package/lib/shared/completionRecord.js +327 -0
- package/lib/shared/metrics.js +42 -0
- package/lib/shared/milestoneReview.js +2 -1
- package/lib/shared/preflightInput.js +1 -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/requirementSource.js +635 -0
- package/lib/shared/retrospective.js +286 -0
- package/lib/shared/reviewCandidate.js +308 -0
- package/lib/shared/reworkHistory.js +81 -0
- package/lib/shared/taskBlock.js +142 -0
- package/lib/shared/taskReview.js +56 -0
- package/package.json +3 -2
- package/skills/p3/SKILL.md +9 -152
- package/dist/web/assets/Outputs-ddwte0jj.js +0 -1
- package/dist/web/assets/RequestStatus-Bg1OLbRc.js +0 -1
- package/dist/web/assets/Tabs-DTmggzgg.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/draft-CfJeyLOl.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/new-9TKiNT4O.js +0 -1
- package/dist/web/assets/preflightInput-BAeEJYUK.js +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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { mkdir
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
3
|
import { join, resolve, sep } from "node:path";
|
|
4
4
|
import { REVIEW_STATUSES, REVIEW_VERDICTS, } from "../../shared/milestoneReview.js";
|
|
5
|
-
import {
|
|
5
|
+
import { dirs, finishRunFile, readJson, ReviewStoreError, runStamp, updateRunFile, writeJson } from "../reviewRuns.js";
|
|
6
|
+
import { withFileLock } from "../store/fsutil.js";
|
|
7
|
+
export { ReviewStoreError };
|
|
6
8
|
/**
|
|
7
9
|
* マイルストーンレビューの履歴。
|
|
8
10
|
*
|
|
@@ -19,14 +21,6 @@ import { withFileLock, writeFileAtomic } from "../store/fsutil.js";
|
|
|
19
21
|
export const MILESTONE_REVIEWS_DIR = "milestone-reviews";
|
|
20
22
|
const MILESTONE_ID = /^[A-Za-z0-9._-]+$/;
|
|
21
23
|
const RUN_ID = /^MR-\d{8}-\d{6}-[0-9a-f]{4}$/;
|
|
22
|
-
/** 履歴の操作の失敗。not_found: 無い / broken: 読めない / bad_id: ID が使えない / exists: 既にある / finished: 終わった run */
|
|
23
|
-
export class ReviewStoreError extends Error {
|
|
24
|
-
code;
|
|
25
|
-
constructor(code, message) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.code = code;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
24
|
export function checkReviewMilestoneId(id) {
|
|
31
25
|
if (!MILESTONE_ID.test(id) || id === "." || id === "..")
|
|
32
26
|
throw new ReviewStoreError("bad_id", `マイルストーンの ID に使えません: ${JSON.stringify(id)}(英数字と . _ -)`);
|
|
@@ -36,10 +30,9 @@ export function checkRunId(id) {
|
|
|
36
30
|
throw new ReviewStoreError("bad_id", `レビューの run の ID ではありません: ${JSON.stringify(id)}(MR-YYYYMMDD-HHMMSS-xxxx)`);
|
|
37
31
|
}
|
|
38
32
|
export function newReviewRunId(now = new Date()) {
|
|
39
|
-
|
|
40
|
-
return `MR-${s}-${randomBytes(2).toString("hex")}`;
|
|
33
|
+
return `MR-${runStamp(now)}-${randomBytes(2).toString("hex")}`;
|
|
41
34
|
}
|
|
42
|
-
|
|
35
|
+
/** 保存と実行中の run の規則は reviewRuns.ts と共通(キーはマイルストーンの ID) */
|
|
43
36
|
export class MilestoneReviewStore {
|
|
44
37
|
dataDir;
|
|
45
38
|
constructor(dataDir) {
|
|
@@ -158,29 +151,18 @@ export class MilestoneReviewStore {
|
|
|
158
151
|
}
|
|
159
152
|
/** run.json を書き換える(呼ぶ側がロックの中で呼ぶ)。終わった run は finished で断る */
|
|
160
153
|
async updateRunning(mid, run, fn) {
|
|
161
|
-
|
|
162
|
-
if (isTerminal(cur))
|
|
163
|
-
throw new ReviewStoreError("finished", `${mid}/${run} は既に終わっています(${cur.status})`);
|
|
164
|
-
const next = fn(cur);
|
|
165
|
-
await writeJson(join(this.runDir(mid, run), "run.json"), next);
|
|
166
|
-
return next;
|
|
154
|
+
return updateRunFile(`${mid}/${run}`, await this.readRun(mid, run), fn, (r) => writeJson(join(this.runDir(mid, run), "run.json"), r));
|
|
167
155
|
}
|
|
168
156
|
/**
|
|
169
157
|
* 終わりにする(呼ぶ側がロックの中で呼ぶ)。completed は結果を書き終えてから run.json を completed にする。
|
|
170
158
|
* 既に終わっていれば finished で断り、何も書かない
|
|
171
159
|
*/
|
|
172
160
|
async finish(mid, run, patch, result) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
throw new Error("completed には結果が要ります");
|
|
179
|
-
await writeJson(join(this.runDir(mid, run), "review.json"), result);
|
|
180
|
-
}
|
|
181
|
-
const next = { ...cur, ...patch, finishedAt: patch.finishedAt ?? new Date().toISOString() };
|
|
182
|
-
await writeJson(join(this.runDir(mid, run), "run.json"), next);
|
|
183
|
-
return next;
|
|
161
|
+
const dir = this.runDir(mid, run);
|
|
162
|
+
return finishRunFile(`${mid}/${run}`, await this.readRun(mid, run), patch, result, {
|
|
163
|
+
writeRun: (r) => writeJson(join(dir, "run.json"), r),
|
|
164
|
+
writeResult: (r) => writeJson(join(dir, "review.json"), r),
|
|
165
|
+
});
|
|
184
166
|
}
|
|
185
167
|
}
|
|
186
168
|
function checkRunShape(x) {
|
|
@@ -192,35 +174,3 @@ function checkRunShape(x) {
|
|
|
192
174
|
}
|
|
193
175
|
/** 判定の区分か */
|
|
194
176
|
export const isVerdict = (v) => REVIEW_VERDICTS.includes(v);
|
|
195
|
-
async function dirs(path) {
|
|
196
|
-
try {
|
|
197
|
-
return (await readdir(path, { withFileTypes: true })).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
198
|
-
}
|
|
199
|
-
catch (e) {
|
|
200
|
-
if (e.code === "ENOENT")
|
|
201
|
-
return [];
|
|
202
|
-
throw e;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async function writeJson(path, v) {
|
|
206
|
-
await writeFileAtomic(path, `${JSON.stringify(v, null, 2)}\n`);
|
|
207
|
-
}
|
|
208
|
-
async function readJson(path, label, check) {
|
|
209
|
-
let text;
|
|
210
|
-
try {
|
|
211
|
-
text = await readFile(path, "utf8");
|
|
212
|
-
}
|
|
213
|
-
catch (e) {
|
|
214
|
-
if (e.code === "ENOENT")
|
|
215
|
-
throw new ReviewStoreError("not_found", `レビューの記録がありません: ${label}`);
|
|
216
|
-
throw e;
|
|
217
|
-
}
|
|
218
|
-
try {
|
|
219
|
-
const v = JSON.parse(text);
|
|
220
|
-
check(v);
|
|
221
|
-
return v;
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
throw new ReviewStoreError("broken", `レビューの記録を読めません: ${label}(${e.message})`);
|
|
225
|
-
}
|
|
226
|
-
}
|
package/lib/core/ops.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { evidenceSummary } from "../shared/acceptance.js";
|
|
1
2
|
import { normalizeTaskId } from "../shared/refs.js";
|
|
2
3
|
import { REQUEST_STATUSES, TASK_STATUSES } from "../shared/types.js";
|
|
3
4
|
import { hierarchyNow } from "./requestStatus.js";
|
|
4
|
-
|
|
5
|
+
import { requestReviewCounts, taskReview } from "./reviewCandidates.js";
|
|
6
|
+
export function listTasks(ctx, f = {}) {
|
|
7
|
+
const { ws } = ctx;
|
|
5
8
|
let tasks = f.request ? ws.tasksOf(f.request).list() : ws.allTasks();
|
|
6
9
|
if (f.status?.length)
|
|
7
10
|
tasks = tasks.filter((t) => f.status.includes(t.status));
|
|
@@ -10,6 +13,10 @@ export function listTasks({ ws }, f = {}) {
|
|
|
10
13
|
// 作業先で絞る(none は作業先なし)
|
|
11
14
|
if (f.repo !== undefined)
|
|
12
15
|
tasks = tasks.filter((t) => (t.repo ?? null) === (f.repo === "none" ? null : f.repo));
|
|
16
|
+
if (f.blocked)
|
|
17
|
+
tasks = tasks.filter((t) => !!t.block);
|
|
18
|
+
if (f.review)
|
|
19
|
+
tasks = tasks.filter((t) => taskReview(ctx, t)?.state === "candidate");
|
|
13
20
|
if (f.q) {
|
|
14
21
|
const q = f.q.toLowerCase();
|
|
15
22
|
tasks = tasks.filter((t) => `${t.ref} ${t.title} ${t.body}`.toLowerCase().includes(q));
|
|
@@ -84,9 +91,11 @@ export function progress(ctx) {
|
|
|
84
91
|
for (const t of tasks)
|
|
85
92
|
counts[t.status]++;
|
|
86
93
|
const done = tasks.filter((t) => t.status === "done");
|
|
94
|
+
// 止まっているタスク(作業中にも数える。完了率・完了の判定は変えない)
|
|
95
|
+
const blocked = tasks.filter((t) => !!t.block).length;
|
|
87
96
|
// 配下: 自分と子孫(循環しても1回ずつ)
|
|
88
97
|
const below = h.descendants(request.id);
|
|
89
|
-
const sub = { counts: zero(), total: 0, done: 0, requests: Object.fromEntries(REQUEST_STATUSES.map((s) => [s, 0])) };
|
|
98
|
+
const sub = { counts: zero(), total: 0, done: 0, blocked: 0, requests: Object.fromEntries(REQUEST_STATUSES.map((s) => [s, 0])) };
|
|
90
99
|
const stamps = [request.updatedAt, ...tasks.map((t) => t.updatedAt)];
|
|
91
100
|
for (const r of [request, ...below]) {
|
|
92
101
|
if (r !== request) {
|
|
@@ -98,20 +107,31 @@ export function progress(ctx) {
|
|
|
98
107
|
sub.total++;
|
|
99
108
|
if (t.status === "done")
|
|
100
109
|
sub.done++;
|
|
110
|
+
if (t.block)
|
|
111
|
+
sub.blocked++;
|
|
101
112
|
if (r !== request)
|
|
102
113
|
stamps.push(t.updatedAt);
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
return {
|
|
106
117
|
request,
|
|
107
|
-
tasks: tasks.map((
|
|
118
|
+
tasks: tasks.map((t) => {
|
|
119
|
+
const { id, ref, title, status, createdAt, startedAt, doneAt, checkedAt, block } = t;
|
|
120
|
+
// 証拠の小さな概要(本文は載せない。規則は shared/acceptance.ts)
|
|
121
|
+
const evidence = evidenceSummary(t);
|
|
122
|
+
// 完了したタスクの見直しの診断の状態(理由は詳細で読む)
|
|
123
|
+
const review = taskReview(ctx, t)?.state;
|
|
124
|
+
return { id, ref, title, status, createdAt, startedAt, doneAt, checkedAt, ...(block ? { block } : {}), ...(evidence ? { evidence } : {}), ...(review ? { review } : {}) };
|
|
125
|
+
}),
|
|
108
126
|
counts,
|
|
109
127
|
total: tasks.length,
|
|
110
128
|
done: done.length,
|
|
129
|
+
blocked,
|
|
111
130
|
updatedAt: stamps.sort().at(-1),
|
|
112
131
|
children: h.children(request.id).map((c) => c.id),
|
|
113
132
|
subtree: sub,
|
|
114
133
|
hierarchyIssues: h.issuesAround(request.id),
|
|
134
|
+
review: requestReviewCounts(ctx, request, h),
|
|
115
135
|
};
|
|
116
136
|
})
|
|
117
137
|
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt) || byId(a.request.id, b.request.id));
|
|
@@ -82,12 +82,16 @@ export function renderCarryover(c) {
|
|
|
82
82
|
const list = (xs) => (xs.length ? xs.map((x) => `- ${x}`).join("\n") : "(なし)");
|
|
83
83
|
if (c.requestChange)
|
|
84
84
|
out.push(requestChangeSection(c.requestChange, p.id));
|
|
85
|
-
out.push(`## 前回の評価(${p.id})`, `判定: ${a.verdict} / 妥当性 ${a.validity.score} / 実現可能性 ${a.feasibility.score}`, a.summary, `### 確認事項\n${list(a.questions)}`,
|
|
85
|
+
out.push(`## 前回の評価(${p.id})`, `判定: ${a.verdict} / 妥当性 ${a.validity.score} / 実現可能性 ${a.feasibility.score}`, a.summary, `### 確認事項\n${list(a.questions)}`, ...(a.clarifications?.length
|
|
86
|
+
? [
|
|
87
|
+
`### 構造化した確認事項(回答は要望の「要求の出典と確認」に元の組のまま載せています)\n${list(a.clarifications.map((q) => `${p.id}/${q.id}: ${q.question}(確認先: ${q.ask} / 対象: ${q.target}${q.needed ? ` / 必要な根拠: ${q.needed}` : ""})`))}`,
|
|
88
|
+
]
|
|
89
|
+
: []), `### リスク\n${list(a.risks)}`,
|
|
86
90
|
// 前回の根拠は前回の時点のもの。今回の確かめた根拠としてそのまま写させない
|
|
87
91
|
`### 前回の根拠(前回の時点のもの。使うなら今回あらためて確かめ、確かめていなければ assumed にする)\n${a.evidence === undefined
|
|
88
92
|
? "(記録なし)"
|
|
89
93
|
: list(a.evidence.map((e) => `${e.kind === "verified" ? "確かめた" : "推測"}: ${e.claim}${e.repo && e.file ? `(${e.repo}:${e.file}${e.location ? ` ${e.location}` : ""})` : ""}`))}`, `## 前回のタスク案(人の編集と採否を含む)`, ...(p.drafts.length
|
|
90
|
-
? p.drafts.map((d) => `### ${d.key} ${d.title}(${d.include ? "採用" : "不採用"}${d.dependsOn.length ? ` / 依存: ${d.dependsOn.join(", ")}` : ""}${d.repo !== undefined ? ` / 作業先: ${d.repo ?? "なし"}` : ""})\n${d.description}`)
|
|
94
|
+
? p.drafts.map((d) => `### ${d.key} ${d.title}(${d.include ? "採用" : "不採用"}${d.dependsOn.length ? ` / 依存: ${d.dependsOn.join(", ")}` : ""}${d.repo !== undefined ? ` / 作業先: ${d.repo ?? "なし"}` : ""})\n${d.description}${d.acceptanceCriteria?.length ? `\n\n受け入れ基準(人の編集を含む):\n${d.acceptanceCriteria.map((c) => `- ${c.text}`).join("\n")}` : ""}`)
|
|
91
95
|
: [p.children ? "(なし。前回は子の要望に分ける案でした)" : "(なし)"]), ...(p.children
|
|
92
96
|
? [
|
|
93
97
|
`## 前回の子の要望の案(人の編集と採否を含む)${p.adoption?.done ? `。採用済み: ${Object.values(p.adoption.reserved).join(", ")}` : ""}`,
|
|
@@ -60,7 +60,8 @@ import { redact } from "../redact.js";
|
|
|
60
60
|
import { ensureCodexImage } from "./codexImage.js";
|
|
61
61
|
import { CONTAINER_LABEL, containerName, DOCKER_LIMITS, DockerAbortError, removeContainer, removeLog, withContainerName } from "./docker.js";
|
|
62
62
|
import { renderManuscripts } from "./uiRender.js";
|
|
63
|
-
import { describeMapping, diagnoseLaunch
|
|
63
|
+
import { describeMapping, diagnoseLaunch } from "./diagnose.js";
|
|
64
|
+
import { resolveHostPaths, unresolvedMessage } from "./hostPaths.js";
|
|
64
65
|
import { prepareLaunch } from "./launch.js";
|
|
65
66
|
import { hideConfigPath } from "../userConfig.js";
|
|
66
67
|
import { CONTAINER_DATA, containerEnv, developerInstructions, entryMissing, preflightPrompt } from "./instructions.js";
|
|
@@ -124,6 +125,27 @@ function localPath(job, p) {
|
|
|
124
125
|
}
|
|
125
126
|
return abs;
|
|
126
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* マウントするパスを Docker のホストのパスに決める(hostPaths.ts)。1つでも決まらなければ、コンテナを起こさずに理由と次にすることで投げる。
|
|
130
|
+
* 実際のパスはエラーに書かない(共有の記録に残る)
|
|
131
|
+
*/
|
|
132
|
+
async function mountPaths(cfg, targets, what, signal) {
|
|
133
|
+
let r;
|
|
134
|
+
try {
|
|
135
|
+
r = await resolveHostPaths(targets.map((t) => t.local), { pathMap: cfg.pathMap, signal, probe: cfg.hostProbe });
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
if (e instanceof DockerAbortError)
|
|
139
|
+
throw new Error("中止しました", { cause: e });
|
|
140
|
+
throw e;
|
|
141
|
+
}
|
|
142
|
+
if (!r.ok)
|
|
143
|
+
throw new Error(unresolvedMessage(what, targets.map((t, i) => ({ label: t.label, result: r.paths[i] }))));
|
|
144
|
+
return targets.map((t, i) => {
|
|
145
|
+
const p = r.paths[i];
|
|
146
|
+
return { label: t.label, local: t.local, host: p.host, rule: p.rule, container: t.container, resolved: p };
|
|
147
|
+
});
|
|
148
|
+
}
|
|
127
149
|
/**
|
|
128
150
|
* llmcs の codex-workspace(TypeScript 版。npm の @infodb/codex-workspace)で、Docker コンテナ内の
|
|
129
151
|
* codex app-server に preflight を頼む。
|
|
@@ -244,9 +266,6 @@ export class CodexWorkspaceEngine {
|
|
|
244
266
|
this.checked = { at: Date.now(), key, status };
|
|
245
267
|
return status;
|
|
246
268
|
}
|
|
247
|
-
hostPath(local) {
|
|
248
|
-
return mapPath(this.cfg.pathMap, local).host;
|
|
249
|
-
}
|
|
250
269
|
async run(job, log, signal) {
|
|
251
270
|
return this.authorized("Preflight", log, (a) => this.runWith(a.cfg, job, a.auth, a.env, a.log, signal));
|
|
252
271
|
}
|
|
@@ -259,15 +278,12 @@ export class CodexWorkspaceEngine {
|
|
|
259
278
|
async ask(input, log, signal) {
|
|
260
279
|
return this.authorized(input.label, log, async ({ cfg, auth, env, log }) => {
|
|
261
280
|
const readable = (input.refs ?? []).filter((r) => r.status === "ok" && r.local);
|
|
262
|
-
const mappings = readable.
|
|
263
|
-
label: `参照先 ${r.name}`,
|
|
264
|
-
|
|
265
|
-
...mapPath(cfg.pathMap, r.local),
|
|
266
|
-
container: `${CONTAINER_WORKSPACE}/${r.mount}`,
|
|
267
|
-
}));
|
|
281
|
+
const mappings = readable.length
|
|
282
|
+
? await mountPaths(cfg, readable.map((r) => ({ label: `参照先 ${r.name}`, local: r.local, container: `${CONTAINER_WORKSPACE}/${r.mount}` })), input.label, signal)
|
|
283
|
+
: [];
|
|
268
284
|
const repos = readable.map((r, i) => ({ name: r.name, host: mappings[i].host, container: mappings[i].container }));
|
|
269
285
|
if (mappings.length) {
|
|
270
|
-
log({ kind: "info", text: "
|
|
286
|
+
log({ kind: "info", text: "パスの対応(Docker のホストから見たパス。読むだけでマウントします):" });
|
|
271
287
|
for (const m of mappings)
|
|
272
288
|
log({ kind: "info", text: ` ${describeMapping(m, cfg.pathMap.length)}` });
|
|
273
289
|
}
|
|
@@ -392,13 +408,14 @@ export class CodexWorkspaceEngine {
|
|
|
392
408
|
}
|
|
393
409
|
async runWith(cfg, job, auth, env, log, signal) {
|
|
394
410
|
const readable = job.refs.filter((r) => r.status === "ok" && r.local);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
{ label:
|
|
398
|
-
|
|
411
|
+
// 全部の参照先とデータを、Codex のコンテナを起こす前にまとめて決める(1つでも決まらなければ起こさない)
|
|
412
|
+
const mappings = await mountPaths(cfg, [
|
|
413
|
+
...readable.map((r) => ({ label: `参照先 ${r.name}`, local: r.local, container: `${CONTAINER_WORKSPACE}/${r.mount}` })),
|
|
414
|
+
{ label: "データ", local: job.dataDir, container: CONTAINER_DATA },
|
|
415
|
+
], "Preflight", signal);
|
|
399
416
|
const repos = readable.map((r, i) => ({ name: r.name, host: mappings[i].host, container: mappings[i].container }));
|
|
400
417
|
const data = mappings.at(-1).host;
|
|
401
|
-
log({ kind: "info", text: "
|
|
418
|
+
log({ kind: "info", text: "パスの対応(Docker のホストから見たパス):" });
|
|
402
419
|
for (const m of mappings)
|
|
403
420
|
log({ kind: "info", text: ` ${describeMapping(m, cfg.pathMap.length)}` });
|
|
404
421
|
for (const r of readable)
|
|
@@ -411,7 +428,7 @@ export class CodexWorkspaceEngine {
|
|
|
411
428
|
const outcome = await this.launched("preflight", cfg, command, mappings, log, signal, (launch, onError) => this.session(cfg, launch, env, log, onError, (session) => this.turn(session, job, auth, log, signal)));
|
|
412
429
|
// 画面イメージ: Codex が書いた原稿を、Codex の後に P3 が描画のコンテナで PNG にする(Codex のコンテナに Docker は渡さない)。
|
|
413
430
|
// 描けなくても評価は残す(取り込みで不足として扱う)
|
|
414
|
-
await renderManuscripts(job.runDir, { pathMap: cfg.pathMap, signal, log, render: cfg.render });
|
|
431
|
+
await renderManuscripts(job.runDir, { pathMap: cfg.pathMap, signal, log, render: cfg.render, hostProbe: cfg.hostProbe });
|
|
415
432
|
return outcome;
|
|
416
433
|
}
|
|
417
434
|
/** 起こして、work(スレッドを立てて頼む)を行う。失敗は onError で診断をつけてから投げる */
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
for (const rule of pathMap) {
|
|
4
|
-
const [from, to] = rule;
|
|
5
|
-
if (local === from || local.startsWith(`${from}/`))
|
|
6
|
-
return { host: to + local.slice(from.length), rule };
|
|
7
|
-
}
|
|
8
|
-
return { host: local };
|
|
9
|
-
}
|
|
1
|
+
import { originText } from "./hostPaths.js";
|
|
2
|
+
export { mapPath } from "./hostPaths.js";
|
|
10
3
|
/**
|
|
11
4
|
* パスの対応の説明。共有の記録(run.json)に残るので、このマシンのパスと Docker のホストのパスは出さず、
|
|
12
5
|
* 参照先の名前・コンテナの中のパス・codex.pathMap の対応が当たったかだけを書く
|
|
13
6
|
*/
|
|
14
7
|
export function describeMapping(m, rules) {
|
|
8
|
+
if (m.resolved)
|
|
9
|
+
return `${m.label} → コンテナ ${m.container}(${originText(m.resolved, rules)})`;
|
|
15
10
|
const how = m.rule
|
|
16
11
|
? m.rule[0] === m.rule[1]
|
|
17
12
|
? "codex.pathMap の対応あり(パスは変わらない)"
|
|
@@ -5,6 +5,10 @@ export const ASSESSMENT_SPEC = `{
|
|
|
5
5
|
"feasibility": { "score": 0-100, "reasons": ["実現可能か: 既存コード・技術的制約・規模"] },
|
|
6
6
|
"risks": ["..."],
|
|
7
7
|
"questions": ["要望者に確認すべき事項"],
|
|
8
|
+
"clarifications": [
|
|
9
|
+
{ "id": "Q1", "target": "確かめたい要望の前提の文、または D1/A2 のような案と基準", "ask": "確認先(役割名。分からなければ「要望者に確認先を特定してもらう」)",
|
|
10
|
+
"question": "質問", "needed": "答えに要る根拠(業務の担当が承認した計算例・規則や契約の該当箇所など)", "impact": "判断への影響(答えでタスク案・基準がどう変わるか)" }
|
|
11
|
+
],
|
|
8
12
|
"areas": ["影響するコード領域やコンポーネント(リポジトリ相対パス推奨)"],
|
|
9
13
|
"split": { "decision": "split" | "keep", "estimatedTasks": 想定するタスクの数(概算), "reasons": ["分割する・しない理由"] },
|
|
10
14
|
"evidence": [
|
|
@@ -14,6 +18,11 @@ export const ASSESSMENT_SPEC = `{
|
|
|
14
18
|
]
|
|
15
19
|
}
|
|
16
20
|
|
|
21
|
+
clarifications は questions のうち、誰かに確かめないと決まらないものを構造化したものです(questions にも同じ趣旨を文で残す)。
|
|
22
|
+
業務上の正解(計算式・規則・契約など)がコードや履歴から分からず、判定やタスク案に影響するときは verdict を clarify にし、
|
|
23
|
+
足りない根拠と確認先を clarifications に書いてください。確認先が分からなければ ask は「要望者に確認先を特定してもらう」とし、
|
|
24
|
+
誰かに確かめたように書かないでください。要望に出典や根拠の記録が無いというだけの理由で clarify にしないでください。
|
|
25
|
+
|
|
17
26
|
evidence には、判断に使ったファイル・箇所を書いてください。実際に読んで確かめたものは verified(repo・file を必ず書く)、
|
|
18
27
|
読まずに推測した判断も消さずに assumed として書いてください(推測で書いた部分が分かるように)。`;
|
|
19
28
|
/** 分割の基準(SPLIT_HINT_TASKS と同じ数を書く) */
|
|
@@ -48,9 +57,15 @@ repo: <作業先> # 作業するリポジトリ・フォルダ(「作
|
|
|
48
57
|
areas: [src/foo] # 触る領域
|
|
49
58
|
dependsOn: [D1] # 同じ preflight 内で先に終わっている必要があるタスク案の key
|
|
50
59
|
supersedes: [T003] # この案が置き換える、同じ要望の既存タスク(再評価で古いタスクを置き換えるときだけ。無ければ省略)
|
|
60
|
+
acceptanceCriteria: # 受け入れ基準: 完了したと外から確かめられる条件を1件1文で(3〜7件ほど。ID は P3 が振る)
|
|
61
|
+
- 設定を保存して再読み込みしても値が残る
|
|
62
|
+
- 幅 375 の画面で横にはみ出さない
|
|
51
63
|
include: true
|
|
52
64
|
---
|
|
53
65
|
|
|
66
|
+
受け入れ基準は、作業した人が完了するときにテスト・コマンドの結果・画面の確認などの証拠を添えられる、観測できる文にしてください
|
|
67
|
+
(「きれいにする」「適切に扱う」のような確かめようのない文や、作業の手順は書かない。証拠はここでは書かず、作業するときに残す)。
|
|
68
|
+
|
|
54
69
|
作業内容・完了条件を Markdown で。最後に次の2つの見出しを付けてください:
|
|
55
70
|
## 判断の根拠
|
|
56
71
|
- この作業範囲にした根拠(<参照先>:<ファイル> の箇所。確かめていなければ「推測」と書く)
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { hostname as osHostname } from "node:os";
|
|
3
|
+
import { basename, dirname, join } from "node:path";
|
|
4
|
+
import { DOCKER_LIMITS, DockerAbortError, DockerCommandError, dockerExec } from "./docker.js";
|
|
5
|
+
const read = (p) => {
|
|
6
|
+
try {
|
|
7
|
+
return readFileSync(p, "utf8");
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/** あるところまで realpath し、無い残りを足す */
|
|
14
|
+
function realpathLoose(p) {
|
|
15
|
+
const rest = [];
|
|
16
|
+
let cur = p;
|
|
17
|
+
for (;;) {
|
|
18
|
+
try {
|
|
19
|
+
return join(realpathSync(cur), ...rest.toReversed());
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
const up = dirname(cur);
|
|
23
|
+
if (up === cur)
|
|
24
|
+
return p;
|
|
25
|
+
rest.push(basename(cur));
|
|
26
|
+
cur = up;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** 手で書いた対応: 前から順に、境界(/)が合う最初の対応を使う(当たらなければ元のパス) */
|
|
31
|
+
export function mapPath(pathMap, local) {
|
|
32
|
+
for (const rule of pathMap) {
|
|
33
|
+
const [from, to] = rule;
|
|
34
|
+
if (local === from || local.startsWith(`${from}/`))
|
|
35
|
+
return { host: to + local.slice(from.length), rule };
|
|
36
|
+
}
|
|
37
|
+
return { host: local };
|
|
38
|
+
}
|
|
39
|
+
/** コンテナの外として振る舞う(P3_HOST_PATHS=direct のとき) */
|
|
40
|
+
export const DIRECT_PROBE = {
|
|
41
|
+
mountinfo: () => null,
|
|
42
|
+
cgroup: () => null,
|
|
43
|
+
dockerenv: () => false,
|
|
44
|
+
hostname: () => "",
|
|
45
|
+
realpath: (p) => p,
|
|
46
|
+
inspect: async () => null,
|
|
47
|
+
};
|
|
48
|
+
/** 実際の OS と docker の CLI(接続先は docker の CLI が環境変数と context から決める) */
|
|
49
|
+
export function systemProbe(docker = "docker", timeoutMs = DOCKER_LIMITS.inspectMs) {
|
|
50
|
+
return {
|
|
51
|
+
mountinfo: () => read("/proc/self/mountinfo"),
|
|
52
|
+
cgroup: () => read("/proc/self/cgroup"),
|
|
53
|
+
dockerenv: () => existsSync("/.dockerenv"),
|
|
54
|
+
hostname: () => osHostname(),
|
|
55
|
+
realpath: realpathLoose,
|
|
56
|
+
inspect: async (id, signal) => {
|
|
57
|
+
try {
|
|
58
|
+
const { stdout } = await dockerExec(docker, ["inspect", "--type", "container", "--format", "{{json .}}", id], {
|
|
59
|
+
stage: "自分のコンテナの確認(docker inspect)",
|
|
60
|
+
timeoutMs,
|
|
61
|
+
signal,
|
|
62
|
+
});
|
|
63
|
+
return JSON.parse(stdout);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (e instanceof DockerCommandError && /no such (container|object)/i.test(e.stderr))
|
|
67
|
+
return null;
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** mountinfo の \040 などのエスケープを戻す */
|
|
74
|
+
const unescape = (s) => s.replace(/\\([0-7]{3})/g, (_, o) => String.fromCharCode(Number.parseInt(o, 8)));
|
|
75
|
+
export function parseMountinfo(text) {
|
|
76
|
+
const out = [];
|
|
77
|
+
for (const line of text.split("\n")) {
|
|
78
|
+
const f = line.trim().split(" ");
|
|
79
|
+
const sep = f.indexOf("-");
|
|
80
|
+
if (f.length < 7 || sep < 6)
|
|
81
|
+
continue;
|
|
82
|
+
out.push({ root: unescape(f[3]), mountPoint: unescape(f[4]), fsType: f[sep + 1] ?? "" });
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
const ID = /(?:^|\/)(?:containers|overlay-containers)\/([0-9a-f]{64})(?:\/|$)/;
|
|
87
|
+
/** Docker(と Podman)がコンテナごとに置くファイル */
|
|
88
|
+
const PER_CONTAINER = new Set(["/etc/hostname", "/etc/hosts", "/etc/resolv.conf"]);
|
|
89
|
+
/** 自分のコンテナの ID の候補(mountinfo の /etc/hostname などの元の場所、cgroup v1 の docker の行) */
|
|
90
|
+
export function containerIdCandidates(mountinfo, cgroup) {
|
|
91
|
+
const ids = new Set();
|
|
92
|
+
for (const m of mountinfo ? parseMountinfo(mountinfo) : []) {
|
|
93
|
+
if (!PER_CONTAINER.has(m.mountPoint))
|
|
94
|
+
continue;
|
|
95
|
+
const id = ID.exec(m.root)?.[1];
|
|
96
|
+
if (id)
|
|
97
|
+
ids.add(id);
|
|
98
|
+
}
|
|
99
|
+
for (const line of cgroup?.split("\n") ?? []) {
|
|
100
|
+
const id = /\/docker[/-]([0-9a-f]{64})(?:\.scope)?$/.exec(line.trim())?.[1];
|
|
101
|
+
if (id)
|
|
102
|
+
ids.add(id);
|
|
103
|
+
}
|
|
104
|
+
return [...ids];
|
|
105
|
+
}
|
|
106
|
+
/** 境界(/)が合うか */
|
|
107
|
+
const under = (p, base) => base === "/" || p === base || p.startsWith(`${base}/`);
|
|
108
|
+
const trimSlash = (p) => (p.length > 1 ? p.replace(/\/+$/, "") : p);
|
|
109
|
+
/** p を含む一番深いマウントの場所(同じ場所に重なっていれば後のもの) */
|
|
110
|
+
export function deepestMount(mounts, p) {
|
|
111
|
+
let best;
|
|
112
|
+
for (const m of mounts)
|
|
113
|
+
if (under(p, m.mountPoint) && (!best || m.mountPoint.length >= best.mountPoint.length))
|
|
114
|
+
best = m;
|
|
115
|
+
return best;
|
|
116
|
+
}
|
|
117
|
+
const MANUAL_HINT = "p3 user-config set codex.pathMap+=<このマシンのパス>=<Docker のホストから見たパス>";
|
|
118
|
+
/** 自分のコンテナを確かめる */
|
|
119
|
+
async function identify(probe, signal) {
|
|
120
|
+
const mountinfo = probe.mountinfo();
|
|
121
|
+
const candidates = containerIdCandidates(mountinfo, probe.cgroup());
|
|
122
|
+
if (!candidates.length) {
|
|
123
|
+
if (probe.dockerenv())
|
|
124
|
+
return { env: { kind: "container-unknown", reason: "self-unknown", detail: "コンテナの中で動いているようですが、自分のコンテナの ID が分かりません" } };
|
|
125
|
+
return { env: { kind: "direct" } };
|
|
126
|
+
}
|
|
127
|
+
const found = [];
|
|
128
|
+
for (const id of candidates) {
|
|
129
|
+
let c;
|
|
130
|
+
try {
|
|
131
|
+
c = await probe.inspect(id, signal);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
if (e instanceof DockerAbortError && e.reason === "aborted")
|
|
135
|
+
throw e;
|
|
136
|
+
const why = e.code === "ENOENT" ? "docker コマンドがありません" : e.message.split("\n")[0];
|
|
137
|
+
return { env: { kind: "container-unknown", reason: "inspect-failed", detail: `自分のコンテナを Docker に問い合わせられません(${why})` } };
|
|
138
|
+
}
|
|
139
|
+
if (c && c.Id === id)
|
|
140
|
+
found.push(c);
|
|
141
|
+
}
|
|
142
|
+
if (!found.length)
|
|
143
|
+
return {
|
|
144
|
+
env: {
|
|
145
|
+
kind: "container-unknown",
|
|
146
|
+
reason: "self-not-found",
|
|
147
|
+
detail: "接続先の Docker のデーモンに、p3 が動いているコンテナがありません(リモートの Docker・別のデーモンに繋がっている)",
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
if (found.length > 1)
|
|
151
|
+
return { env: { kind: "container-unknown", reason: "self-ambiguous", detail: `自分のコンテナの候補が ${found.length} つあり、1つに決まりません` } };
|
|
152
|
+
const c = found[0];
|
|
153
|
+
const host = c.Config?.Hostname;
|
|
154
|
+
if (host && host !== probe.hostname())
|
|
155
|
+
return {
|
|
156
|
+
env: { kind: "container-unknown", reason: "self-mismatch", detail: "docker inspect で見つけたコンテナのホスト名が、このマシンのホスト名と合いません" },
|
|
157
|
+
};
|
|
158
|
+
return { env: { kind: "container", containerId: c.Id }, container: c };
|
|
159
|
+
}
|
|
160
|
+
/** 自分のコンテナのマウントから1つのパスを求める */
|
|
161
|
+
function fromMounts(local, mounts, c, probe) {
|
|
162
|
+
const real = probe.realpath(local);
|
|
163
|
+
const m = deepestMount(mounts, real);
|
|
164
|
+
if (!m || m.mountPoint === "/")
|
|
165
|
+
return { ok: false, reason: "container-layer", detail: "このフォルダはホストのフォルダ(bind マウント)の下にありません(コンテナの中だけにある)" };
|
|
166
|
+
const mount = (c.Mounts ?? []).find((x) => x.Destination && trimSlash(x.Destination) === m.mountPoint);
|
|
167
|
+
if (!mount)
|
|
168
|
+
return {
|
|
169
|
+
ok: false,
|
|
170
|
+
reason: "not-bind",
|
|
171
|
+
detail: `このフォルダは Docker が付けたマウントではない場所(${m.fsType})の下にあります`,
|
|
172
|
+
};
|
|
173
|
+
if (mount.Type !== "bind")
|
|
174
|
+
return { ok: false, reason: "not-bind", detail: `このフォルダはホストのフォルダではないマウント(${mount.Type ?? "不明"})の下にあります` };
|
|
175
|
+
const src = mount.Source ?? "";
|
|
176
|
+
if (!src.startsWith("/"))
|
|
177
|
+
return { ok: false, reason: "unsupported-source", detail: "このフォルダのマウントの元が、そのまま渡せる形(/ で始まるパス)ではありません" };
|
|
178
|
+
return { ok: true, host: trimSlash(src) + real.slice(m.mountPoint.length), destination: m.mountPoint };
|
|
179
|
+
}
|
|
180
|
+
/** 止める理由ごとの次にすること(1つ) */
|
|
181
|
+
export function nextStep(reason) {
|
|
182
|
+
switch (reason) {
|
|
183
|
+
case "not-bind":
|
|
184
|
+
case "container-layer":
|
|
185
|
+
return "このフォルダを、ホストのフォルダをマウント(bind)した場所の下へ移してください";
|
|
186
|
+
case "conflict":
|
|
187
|
+
return "手で書いた対応を直すか外してください(p3 user-config set codex.pathMap-=<このマシンのパス>。外せば自動で決めます)";
|
|
188
|
+
case "inspect-failed":
|
|
189
|
+
return "docker version で Docker に繋がるか確かめてください";
|
|
190
|
+
default:
|
|
191
|
+
return `ホストから見たパスを手で書いてください: ${MANUAL_HINT}`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 対象のパスごとに、Docker のデーモンから見たパスを決める。1つでも決まらなければ ok: false(呼ぶ側はコンテナを起こさない)
|
|
196
|
+
*/
|
|
197
|
+
export async function resolveHostPaths(locals, opts) {
|
|
198
|
+
// P3_HOST_PATHS=direct: 自動で決めず、コンテナの外と同じに扱う(手で書いた対応だけ。テストと切り分け用)
|
|
199
|
+
const probe = opts.probe ?? (process.env.P3_HOST_PATHS === "direct" ? DIRECT_PROBE : systemProbe(opts.docker, opts.timeoutMs));
|
|
200
|
+
const manual = (local) => {
|
|
201
|
+
const m = mapPath(opts.pathMap, local);
|
|
202
|
+
return m.rule ? m : undefined;
|
|
203
|
+
};
|
|
204
|
+
const self = await identify(probe, opts.signal);
|
|
205
|
+
const mounts = self.container ? parseMountinfo(probe.mountinfo() ?? "") : [];
|
|
206
|
+
const paths = locals.map((local) => {
|
|
207
|
+
const hand = manual(local);
|
|
208
|
+
if (self.env.kind === "direct")
|
|
209
|
+
return hand ? { ok: true, local, host: hand.host, origin: "manual", rule: hand.rule, verified: false } : { ok: true, local, host: local, origin: "direct" };
|
|
210
|
+
if (self.env.kind === "container-unknown") {
|
|
211
|
+
if (hand)
|
|
212
|
+
return { ok: true, local, host: hand.host, origin: "manual", rule: hand.rule, verified: false };
|
|
213
|
+
return { ok: false, local, reason: self.env.reason, detail: self.env.detail, next: nextStep(self.env.reason) };
|
|
214
|
+
}
|
|
215
|
+
const auto = fromMounts(local, mounts, self.container, probe);
|
|
216
|
+
if (hand) {
|
|
217
|
+
if (auto.ok && trimSlash(auto.host) !== trimSlash(hand.host))
|
|
218
|
+
return {
|
|
219
|
+
ok: false,
|
|
220
|
+
local,
|
|
221
|
+
reason: "conflict",
|
|
222
|
+
detail: "手で書いた対応(codex.pathMap)と、p3 が自分のコンテナのマウントから求めたホストのパスが違います",
|
|
223
|
+
next: nextStep("conflict"),
|
|
224
|
+
};
|
|
225
|
+
return { ok: true, local, host: hand.host, origin: "manual", rule: hand.rule, verified: auto.ok };
|
|
226
|
+
}
|
|
227
|
+
if (!auto.ok)
|
|
228
|
+
return { ok: false, local, reason: auto.reason, detail: auto.detail, next: nextStep(auto.reason) };
|
|
229
|
+
return { ok: true, local, host: auto.host, origin: "auto", destination: auto.destination };
|
|
230
|
+
});
|
|
231
|
+
return { ok: paths.every((p) => p.ok), environment: self.env, paths };
|
|
232
|
+
}
|
|
233
|
+
/** ローカルで確かめるコマンド(実際のパスはこの CLI の出力だけに出す) */
|
|
234
|
+
export const PATHS_CHECK = "p3 user-config paths <このマシンのパス>";
|
|
235
|
+
/**
|
|
236
|
+
* 決まらなかったときのエラーの文。共有の記録(run.json・ログ)に残るので、このマシンのパス・ホストのパス・コンテナの ID は書かず、
|
|
237
|
+
* 対象の名前・理由・次にすること・確かめ方だけにする
|
|
238
|
+
*/
|
|
239
|
+
export function unresolvedMessage(what, items) {
|
|
240
|
+
const ng = items.filter((i) => !i.result.ok);
|
|
241
|
+
const nexts = [...new Set(ng.map((i) => i.result.next))];
|
|
242
|
+
return [
|
|
243
|
+
`${what}でマウントするフォルダが Docker のホストのどこにあるか決められないので、コンテナを起こしません(どのフォルダもマウントしていません)`,
|
|
244
|
+
...ng.map((i) => ` ${i.label}: ${i.result.detail}`),
|
|
245
|
+
...nexts.map((n) => `次にすること: ${n}`),
|
|
246
|
+
`確かめる: このマシンで ${PATHS_CHECK}(実際のパスと決め方が出ます)`,
|
|
247
|
+
].join("\n");
|
|
248
|
+
}
|
|
249
|
+
/** 決め方の説明(共有の記録に残してよい言葉だけ) */
|
|
250
|
+
export function originText(r, rules) {
|
|
251
|
+
if (r.origin === "auto")
|
|
252
|
+
return "自動(p3 が動いているコンテナのマウントから)";
|
|
253
|
+
if (r.origin === "manual")
|
|
254
|
+
return r.rule && r.rule[0] === r.rule[1]
|
|
255
|
+
? `codex.pathMap の対応あり(パスは変わらない)${r.verified ? "。コンテナのマウントとも一致" : ""}`
|
|
256
|
+
: `codex.pathMap の対応あり${r.verified ? "。コンテナのマウントとも一致" : ""}`;
|
|
257
|
+
return rules
|
|
258
|
+
? `codex.pathMap の対応なし(${rules} 件のどれにも当たらない。このマシンのパスのまま渡す)`
|
|
259
|
+
: "codex.pathMap の対応なし(このマシンのパスのまま渡す)";
|
|
260
|
+
}
|