@infodb/p3 0.8.0 → 0.9.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 +1 -0
- package/docs/architecture.md +24 -2
- package/docs/development.md +6 -0
- package/docs/how-to-use.md +50 -1
- package/docs/installation.md +9 -7
- package/lib/cli/args.js +3 -0
- package/lib/cli/help.js +4 -0
- package/lib/cli/preflightCommands.js +74 -2
- package/lib/cli/project.js +1 -0
- package/lib/core/context.js +1 -1
- package/lib/core/preflight/codexEngine.js +8 -209
- package/lib/core/preflight/instructions.js +263 -0
- package/lib/core/preflight/service.js +297 -84
- package/lib/core/preflight/uiRender.js +1 -1
- package/lib/shared/scopeView.js +3 -2
- package/package.json +1 -1
- package/skills/p3/SKILL.md +29 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
1
|
+
import { lstat, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { isAbsolute, join, relative } from "node:path";
|
|
4
4
|
import { createHash, randomBytes } from "node:crypto";
|
|
5
5
|
import {} from "../../shared/types.js";
|
|
6
6
|
import { normalizeTaskId, REQUEST_ID } from "../../shared/refs.js";
|
|
7
|
-
import { newRequestId, nowIso, writeFileAtomic } from "../store/fsutil.js";
|
|
7
|
+
import { newRequestId, nowIso, withFileLock, writeFileAtomic } from "../store/fsutil.js";
|
|
8
8
|
import { ConflictError, NotFoundError } from "../store/collection.js";
|
|
9
9
|
import { supersedeCandidates } from "../supersede.js";
|
|
10
10
|
import { hierarchyNow, reopenAncestors } from "../requestStatus.js";
|
|
@@ -12,6 +12,9 @@ import { archivedRequestIds, inheritFrom, withHierarchyLock } from "../hierarchy
|
|
|
12
12
|
import { childBody, childrenVersion, draftProblems, parseSplit, splitMarker } from "./split.js";
|
|
13
13
|
import { redact } from "../redact.js";
|
|
14
14
|
import { renderCarryover, selectCarryover } from "./carryover.js";
|
|
15
|
+
import { LOCAL_INSTRUCTIONS_FILE, LOCAL_OUTPUTS, localInstructions } from "./instructions.js";
|
|
16
|
+
import { renderManuscripts } from "./uiRender.js";
|
|
17
|
+
import { repoTargetProblem } from "../../shared/workTarget.js";
|
|
15
18
|
import { refScope } from "../repoRefs.js";
|
|
16
19
|
import { checkRepoTarget, planWorkstreams, workstreamPatch } from "../workTargets.js";
|
|
17
20
|
import { hideConfigPath } from "../userConfig.js";
|
|
@@ -58,15 +61,19 @@ export class PulseInputError extends Error {
|
|
|
58
61
|
export class PreflightService {
|
|
59
62
|
ws;
|
|
60
63
|
engines;
|
|
64
|
+
renderOpts;
|
|
61
65
|
active = new Map();
|
|
62
66
|
/** 最後に分かった既定のエンジン */
|
|
63
67
|
lastDefault;
|
|
64
68
|
/**
|
|
65
69
|
* defaultEngine: 決まった名前か、読むたびに今の既定を返す関数(serve: 個人設定の preflight.engine を Preflight を始めるたびに読む)
|
|
66
70
|
*/
|
|
67
|
-
constructor(ws, engines, defaultEngine
|
|
71
|
+
constructor(ws, engines, defaultEngine,
|
|
72
|
+
/** 手元のエージェントの取り込みで画面イメージを描くとき: パスの対応(codex.pathMap)と、テスト用の描画の差し替え */
|
|
73
|
+
renderOpts = { pathMap: async () => [] }) {
|
|
68
74
|
this.ws = ws;
|
|
69
75
|
this.engines = engines;
|
|
76
|
+
this.renderOpts = renderOpts;
|
|
70
77
|
if (typeof defaultEngine === "string") {
|
|
71
78
|
this.lastDefault = defaultEngine;
|
|
72
79
|
this.loadDefault = async () => defaultEngine;
|
|
@@ -120,6 +127,144 @@ export class PreflightService {
|
|
|
120
127
|
return note;
|
|
121
128
|
}
|
|
122
129
|
async start(requestId, opts = {}) {
|
|
130
|
+
return this.locked(requestId, async () => {
|
|
131
|
+
const fixed = await this.fix(requestId);
|
|
132
|
+
// 既定のエンジンは始めるたびに個人設定から決める。読めなければ、この run を設定のエラーとして失敗にする
|
|
133
|
+
// (古い設定や Mock に落とさない。serve とほかの操作は続ける)
|
|
134
|
+
let engine;
|
|
135
|
+
if (opts.engine)
|
|
136
|
+
engine = this.engines[opts.engine];
|
|
137
|
+
else {
|
|
138
|
+
try {
|
|
139
|
+
engine = this.engines[await this.currentDefault()];
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
const message = `個人設定を読めないので Preflight を始めません(Docker は起動していません): ${hideConfigPath(e)}`;
|
|
143
|
+
engine = failing(this.lastDefault, message);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!engine)
|
|
147
|
+
throw new Error(`engine ${opts.engine} は利用できません`);
|
|
148
|
+
// 始めるときの設定に決める(この run の間は個人設定が変わっても使い続ける)
|
|
149
|
+
if (engine.snapshot) {
|
|
150
|
+
const from = engine;
|
|
151
|
+
engine = await from.snapshot().catch((e) => failing(from.name, e.message));
|
|
152
|
+
}
|
|
153
|
+
const opened = await this.open(fixed, engine.name, opts.actor);
|
|
154
|
+
const abort = new AbortController();
|
|
155
|
+
const done = this.execute(engine, opened, abort.signal);
|
|
156
|
+
this.active.set(opened.run.id, { run: opened.run, abort, done });
|
|
157
|
+
return opened.run;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 手元の対話エージェント(Claude Code など)に評価を頼む準備: 評価対象・参照先・親子・添付・メモ・前回の結果を通常の Preflight と
|
|
162
|
+
* 同じ方法で固定し、指示のファイル(instructions.md)を run のフォルダに書いて、評価を待つ run(engine: local・running)を残して返す。
|
|
163
|
+
* モデル・Codex・Docker は使わない。取り込みは complete、やめるのは cancelLocal(別のプロセスからでもよい)
|
|
164
|
+
*/
|
|
165
|
+
async prepare(requestId, opts = {}) {
|
|
166
|
+
return this.locked(requestId, async () => {
|
|
167
|
+
const opened = await this.open(await this.fix(requestId), "local", opts.actor);
|
|
168
|
+
const { run, runDir } = opened;
|
|
169
|
+
run.local = { before: opened.before };
|
|
170
|
+
await this.extractAttachments(run, runDir);
|
|
171
|
+
const instructions = join(runDir, LOCAL_INSTRUCTIONS_FILE);
|
|
172
|
+
await writeFileAtomic(instructions, localInstructions(this.job(opened)));
|
|
173
|
+
this.log(run, { kind: "info", text: `手元のエージェントの評価を待っています(指示: ${LOCAL_INSTRUCTIONS_FILE}。取り込みは p3 preflight ${requestId} --complete --run ${run.id})` });
|
|
174
|
+
await this.ws.preflight.save(run);
|
|
175
|
+
this.ws.emit({ type: "changed", kind: "preflight", request: requestId });
|
|
176
|
+
return { run, runDir, instructions, outputs: LOCAL_OUTPUTS.map((o) => join(runDir, o)) };
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 手元のエージェントが書いた結果を取り込む。指定した run(engine: local で評価を待っているもの)の成果物だけを確かめ、通常の Preflight と
|
|
181
|
+
* 同じ取り込み(評価・案・分割・根拠・画面資料)で完了にする。成果物に問題があれば何も確定せず LocalResultError(直して同じ run で
|
|
182
|
+
* やり直せる)。取り込み済みなら何もせずに返す(already)
|
|
183
|
+
*/
|
|
184
|
+
async complete(requestId, runId) {
|
|
185
|
+
return this.locked(requestId, async () => {
|
|
186
|
+
const run = await this.localRun(requestId, runId);
|
|
187
|
+
if (run.status === "completed")
|
|
188
|
+
return { run, already: true };
|
|
189
|
+
if (run.status !== "running") {
|
|
190
|
+
throw new LocalRunError(`${runId} は${run.error === PREFLIGHT_CANCELLED ? "取り消し済み" : "失敗した run"}です。評価し直すなら p3 preflight ${requestId} --prepare から`);
|
|
191
|
+
}
|
|
192
|
+
const runDir = this.ws.preflight.runDir(requestId, runId);
|
|
193
|
+
const refs = this.ws.refs();
|
|
194
|
+
const problems = await localProblems(this.ws, run, runDir);
|
|
195
|
+
if (problems.length) {
|
|
196
|
+
run.local = { ...run.local, rejected: (run.local?.rejected ?? 0) + 1 };
|
|
197
|
+
for (const p of problems)
|
|
198
|
+
this.log(run, { kind: "error", text: `取り込めません: ${p}` });
|
|
199
|
+
await this.ws.preflight.save(run);
|
|
200
|
+
throw new LocalResultError(problems);
|
|
201
|
+
}
|
|
202
|
+
// 画面イメージ: 原稿があるときだけ描画のコンテナを使う。描けなくても評価は残す(取り込みで不足として扱う)
|
|
203
|
+
await renderManuscripts(runDir, { pathMap: await this.renderOpts.pathMap().catch(() => []), log: (e) => this.log(run, e), render: this.renderOpts.render });
|
|
204
|
+
await this.ingest(run, runDir, refs);
|
|
205
|
+
run.status = "completed";
|
|
206
|
+
await this.finish(run, run.local.before);
|
|
207
|
+
return { run, already: false };
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/** 手元のエージェントの評価を待つ run をやめる(取り込まない。成果物のファイルは残す)。取り消し済みなら何もしない */
|
|
211
|
+
async cancelLocal(requestId, runId) {
|
|
212
|
+
return this.locked(requestId, async () => {
|
|
213
|
+
const run = await this.localRun(requestId, runId);
|
|
214
|
+
if (run.status === "completed")
|
|
215
|
+
throw new LocalRunError(`${runId} は取り込み済みです(取り消せません)`);
|
|
216
|
+
if (run.status === "failed")
|
|
217
|
+
return { run, already: true };
|
|
218
|
+
run.status = "failed";
|
|
219
|
+
run.error = PREFLIGHT_CANCELLED;
|
|
220
|
+
run.ui = withCurrent({ status: "missing", reason: "評価が終わらなかったので、画面資料を取り込んでいません", targets: [], items: [], problems: [] }, run);
|
|
221
|
+
this.log(run, { kind: "error", text: run.error });
|
|
222
|
+
await this.finish(run, run.local.before);
|
|
223
|
+
return { run, already: false };
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async localRun(requestId, runId) {
|
|
227
|
+
if (!/^PF-[\w-]+$/.test(runId))
|
|
228
|
+
throw new NotFoundError(runId);
|
|
229
|
+
this.ws.requests.require(requestId);
|
|
230
|
+
const run = await this.ws.preflight.get(requestId, runId);
|
|
231
|
+
if (!run)
|
|
232
|
+
throw new NotFoundError(`${requestId}/${runId}`);
|
|
233
|
+
if (run.engine !== "local" || !run.local)
|
|
234
|
+
throw new LocalRunError(`${runId} は手元のエージェントの run ではありません(engine: ${run.engine})`);
|
|
235
|
+
return run;
|
|
236
|
+
}
|
|
237
|
+
/** 同じ要望の Preflight の開始・準備・取り込み・取消を、プロセスを跨いで1つずつにする */
|
|
238
|
+
locked(requestId, fn) {
|
|
239
|
+
if (!REQUEST_ID.test(requestId))
|
|
240
|
+
throw new NotFoundError(requestId);
|
|
241
|
+
return withFileLock(join(this.ws.requestsDir, `.preflight-${requestId}.lock`), fn, {
|
|
242
|
+
timeoutMs: 10_000,
|
|
243
|
+
busyMessage: `${requestId} の Preflight を別の操作が変えています。少し待ってからやり直してください`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* 同じ要望の Preflight が動いているか。このプロセスで実行中、手元のエージェントの評価を待っている、ほかのプロセス(serve・CLI)で
|
|
248
|
+
* 実行中(開始から STALE_RUNNING_MS まで。それより古いものは落ちたプロセスのものとして扱う)なら、その理由
|
|
249
|
+
*/
|
|
250
|
+
async busy(requestId) {
|
|
251
|
+
if ([...this.active.values()].some((a) => a.run.requestId === requestId))
|
|
252
|
+
return `${requestId} の preflight は実行中です`;
|
|
253
|
+
const last = this.ws.requests.get(requestId)?.lastPreflight;
|
|
254
|
+
if (!last)
|
|
255
|
+
return undefined;
|
|
256
|
+
const run = await this.ws.preflight.get(requestId, last);
|
|
257
|
+
if (run?.status !== "running")
|
|
258
|
+
return undefined;
|
|
259
|
+
if (run.engine === "local") {
|
|
260
|
+
return `${requestId} の preflight ${last} は手元のエージェントの評価を待っています(取り込む: p3 preflight ${requestId} --complete --run ${last} / やめる: p3 preflight ${requestId} --cancel --run ${last})`;
|
|
261
|
+
}
|
|
262
|
+
if (Date.now() - Date.parse(run.startedAt) < STALE_RUNNING_MS)
|
|
263
|
+
return `${requestId} の preflight ${last} が別のプロセスで実行中です`;
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
/** 評価対象を固定する(ディスクから読み直す)。同じ要望の Preflight が動いていれば PreflightBusyError */
|
|
267
|
+
async fix(requestId) {
|
|
123
268
|
// 評価対象はディスクから読み直して固定する(監視していない外部の編集も取り込む)。この後に変わっても、この run は固定した内容で評価する
|
|
124
269
|
await this.ws.requests.reload(requestId);
|
|
125
270
|
const current = this.ws.requests.require(requestId);
|
|
@@ -133,30 +278,15 @@ export class PreflightService {
|
|
|
133
278
|
...(parent ? { parent: { id: parent.id, hash: inputHash(parent) } } : {}),
|
|
134
279
|
children: kids.map((c) => ({ id: c.id, hash: inputHash(c) })),
|
|
135
280
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
engine = this.engines[await this.currentDefault()];
|
|
147
|
-
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
const message = `個人設定を読めないので Preflight を始めません(Docker は起動していません): ${hideConfigPath(e)}`;
|
|
150
|
-
engine = failing(this.lastDefault, message);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (!engine)
|
|
154
|
-
throw new Error(`engine ${opts.engine} は利用できません`);
|
|
155
|
-
// 始めるときの設定に決める(この run の間は個人設定が変わっても使い続ける)
|
|
156
|
-
if (engine.snapshot) {
|
|
157
|
-
const from = engine;
|
|
158
|
-
engine = await from.snapshot().catch((e) => failing(from.name, e.message));
|
|
159
|
-
}
|
|
281
|
+
const busy = await this.busy(requestId);
|
|
282
|
+
if (busy)
|
|
283
|
+
throw new PreflightBusyError(busy);
|
|
284
|
+
return { request, input, parent, kids };
|
|
285
|
+
}
|
|
286
|
+
/** run を作る: 前回の結果とメモ・参照先・添付を固定し、要望を評価中にする(エンジンによらず同じ) */
|
|
287
|
+
async open(fixed, engine, actor) {
|
|
288
|
+
const { request, input, parent, kids } = fixed;
|
|
289
|
+
const requestId = request.id;
|
|
160
290
|
const stamp = nowIso().replace(/[-:]/g, "").replace("T", "-").slice(0, 15);
|
|
161
291
|
const id = `PF-${stamp}-${randomBytes(2).toString("hex")}`;
|
|
162
292
|
// 前回の結果とその後のメモ。開始の時点で選んで固定する(実行中に足されたメモは次回に回る)
|
|
@@ -167,10 +297,10 @@ export class PreflightService {
|
|
|
167
297
|
const run = {
|
|
168
298
|
id,
|
|
169
299
|
requestId,
|
|
170
|
-
engine
|
|
300
|
+
engine,
|
|
171
301
|
status: "running",
|
|
172
302
|
startedAt: nowIso(),
|
|
173
|
-
startedBy:
|
|
303
|
+
startedBy: actor,
|
|
174
304
|
previous: carry.previous?.id,
|
|
175
305
|
notes: carry.notes.length ? carry.notes.map((n) => n.id) : undefined,
|
|
176
306
|
log: [],
|
|
@@ -182,9 +312,9 @@ export class PreflightService {
|
|
|
182
312
|
const runDir = this.ws.preflight.runDir(requestId, id);
|
|
183
313
|
// 添付は始める時点のものを run の中にコピーして固定する。途中で変わったら始めない(原本は残るので、そのまま再試行できる)
|
|
184
314
|
try {
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
187
|
-
run.attachments =
|
|
315
|
+
const fixedAttachments = await this.ws.attachments.snapshot(requestId, runDir);
|
|
316
|
+
if (fixedAttachments.length)
|
|
317
|
+
run.attachments = fixedAttachments;
|
|
188
318
|
}
|
|
189
319
|
catch (e) {
|
|
190
320
|
await rm(runDir, { recursive: true, force: true });
|
|
@@ -223,18 +353,27 @@ export class PreflightService {
|
|
|
223
353
|
await writeFileAtomic(join(runDir, "request.md"), renderRequestSnapshot(request.id, input));
|
|
224
354
|
// ステータスを動かすのはタスク化する前の要望だけ。進行中・完了の要望で再評価しても状態は変えない
|
|
225
355
|
const before = request.status;
|
|
226
|
-
|
|
227
|
-
await this.ws.requests.update(requestId, early ? { status: "preflight", lastPreflight: id } : { lastPreflight: id }, { actor: opts.actor });
|
|
356
|
+
await this.ws.requests.update(requestId, isEarly(before) ? { status: "preflight", lastPreflight: id } : { lastPreflight: id }, { actor });
|
|
228
357
|
this.ws.emit({ type: "changed", kind: "request", request: requestId });
|
|
229
|
-
const abort = new AbortController();
|
|
230
|
-
const after = (ok) => (early ? (ok ? "reviewed" : before === "reviewed" ? "reviewed" : "draft") : before);
|
|
231
358
|
const family = {
|
|
232
359
|
...(parent ? { parent: { id: parent.id, title: parent.title, body: parent.body } } : {}),
|
|
233
360
|
...(kids.length ? { children: kids.map((c) => ({ id: c.id, title: c.title, status: c.status })) } : {}),
|
|
234
361
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
362
|
+
return { run, request, runDir, carried, refs, family, before };
|
|
363
|
+
}
|
|
364
|
+
/** エンジンに渡す仕事(始めたときに固定したもの) */
|
|
365
|
+
job(o) {
|
|
366
|
+
return {
|
|
367
|
+
project: this.ws.project,
|
|
368
|
+
// 始めたときに固定した要望(実行中に本文が変わっても、request.md・run.input と同じものを渡す)
|
|
369
|
+
request: o.request,
|
|
370
|
+
refs: o.refs,
|
|
371
|
+
dataDir: this.ws.dataDir,
|
|
372
|
+
runDir: o.runDir,
|
|
373
|
+
carryover: o.carried,
|
|
374
|
+
attachments: o.run.attachments ?? [],
|
|
375
|
+
...o.family,
|
|
376
|
+
};
|
|
238
377
|
}
|
|
239
378
|
/** 実行中の run の完了を待つ(CLI 用)。完了後の run を返す */
|
|
240
379
|
async wait(requestId, runId) {
|
|
@@ -278,45 +417,16 @@ export class PreflightService {
|
|
|
278
417
|
return `data:${data}`;
|
|
279
418
|
return p.startsWith("/workspace") ? p : "(参照先の外)";
|
|
280
419
|
}
|
|
281
|
-
async execute(engine,
|
|
420
|
+
async execute(engine, opened, signal) {
|
|
421
|
+
const { run, runDir, refs } = opened;
|
|
282
422
|
try {
|
|
283
423
|
await this.extractAttachments(run, runDir);
|
|
284
|
-
const outcome = await engine.run(
|
|
285
|
-
project: this.ws.project,
|
|
286
|
-
// 始めたときに固定した要望(実行中に本文が変わっても、request.md・run.input と同じものを渡す)
|
|
287
|
-
request,
|
|
288
|
-
refs,
|
|
289
|
-
dataDir: this.ws.dataDir,
|
|
290
|
-
runDir,
|
|
291
|
-
carryover,
|
|
292
|
-
attachments: run.attachments ?? [],
|
|
293
|
-
...family,
|
|
294
|
-
}, (e) => this.log(run, e), signal);
|
|
424
|
+
const outcome = await engine.run(this.job(opened), (e) => this.log(run, e), signal);
|
|
295
425
|
// 書いてよい範囲の外が変更されていないか確かめる
|
|
296
426
|
const stray = outcome.changed.filter((p) => !p.startsWith(`${runDir}/`));
|
|
297
427
|
for (const p of stray)
|
|
298
428
|
this.log(run, { kind: "error", text: `想定外の変更: ${this.shownPath(p, refs)}(確認して必要なら元に戻してください)` });
|
|
299
|
-
|
|
300
|
-
run.drafts = await this.ws.preflight.loadDrafts(run.requestId, run.id);
|
|
301
|
-
// 子の案(分割の run): 確かめて、問題があれば残す(採用しない)
|
|
302
|
-
const children = await this.ws.preflight.loadChildren(run.requestId, run.id);
|
|
303
|
-
if (children) {
|
|
304
|
-
run.children = children;
|
|
305
|
-
const problems = draftProblems(run, this.ws.tasksOf(run.requestId).list().map((t) => t.id));
|
|
306
|
-
if (problems.length)
|
|
307
|
-
run.draftProblems = problems;
|
|
308
|
-
for (const p of problems)
|
|
309
|
-
this.log(run, { kind: "error", text: `子の案の問題: ${p}` });
|
|
310
|
-
}
|
|
311
|
-
// 画面資料: 確かめて取り込む。不正なものは除いて理由を残す(評価は消さない)。必要な画面イメージが足りなければ go を clarify に
|
|
312
|
-
run.ui = applyUiShortage(run.assessment, await loadUiMaterials(runDir, run.id, [...run.drafts, ...(run.children ?? [])].map((d) => d.key)));
|
|
313
|
-
for (const p of run.ui.problems)
|
|
314
|
-
this.log(run, { kind: "error", text: `画面資料を取り込めません: ${p}` });
|
|
315
|
-
if (run.ui.status === "missing")
|
|
316
|
-
this.log(run, { kind: "info", text: `画面資料が足りません: ${run.ui.reason}` });
|
|
317
|
-
run.ui = withCurrent(run.ui, run);
|
|
318
|
-
if (run.ui.verdictAdjusted)
|
|
319
|
-
this.log(run, { kind: "info", text: "必要な画面イメージが足りないので、判定を go から clarify にしました" });
|
|
429
|
+
await this.ingest(run, runDir, refs);
|
|
320
430
|
run.status = "completed";
|
|
321
431
|
}
|
|
322
432
|
catch (e) {
|
|
@@ -327,20 +437,48 @@ export class PreflightService {
|
|
|
327
437
|
this.log(run, { kind: "error", text: run.error });
|
|
328
438
|
}
|
|
329
439
|
finally {
|
|
330
|
-
run.
|
|
331
|
-
await this.ws.preflight.save(run);
|
|
332
|
-
// 評価中にした要望だけ、終わったら評価済み(失敗なら元)へ戻す。実行中に人や AI が変えたステータス
|
|
333
|
-
// (進行中に戻した・完了済にしたなど)や、評価中にしていない要望(進行中・対応済など)は上書きしない
|
|
334
|
-
const status = after(run.status === "completed");
|
|
335
|
-
if (this.ws.requests.get(run.requestId)?.status === "preflight" && status !== "preflight") {
|
|
336
|
-
await this.ws.requests.update(run.requestId, { status });
|
|
337
|
-
}
|
|
338
|
-
// 保存が終わってから実行中の一覧から外す(先に外すと wait() が保存前のファイルを読む)
|
|
339
|
-
this.active.delete(run.id);
|
|
340
|
-
this.ws.emit({ type: "preflight-status", runId: run.id, status: run.status });
|
|
341
|
-
this.ws.emit({ type: "changed", kind: "request", request: run.requestId });
|
|
440
|
+
await this.finish(run, opened.before);
|
|
342
441
|
}
|
|
343
442
|
}
|
|
443
|
+
/** run のフォルダの成果物(評価・案・子の案・画面資料)を取り込む。評価が読めなければ例外 */
|
|
444
|
+
async ingest(run, runDir, refs) {
|
|
445
|
+
run.assessment = parseAssessment(await readFile(join(runDir, "assessment.json"), "utf8"), refs);
|
|
446
|
+
run.drafts = await this.ws.preflight.loadDrafts(run.requestId, run.id);
|
|
447
|
+
// 子の案(分割の run): 確かめて、問題があれば残す(採用しない)
|
|
448
|
+
const children = await this.ws.preflight.loadChildren(run.requestId, run.id);
|
|
449
|
+
if (children) {
|
|
450
|
+
run.children = children;
|
|
451
|
+
const problems = draftProblems(run, this.ws.tasksOf(run.requestId).list().map((t) => t.id));
|
|
452
|
+
if (problems.length)
|
|
453
|
+
run.draftProblems = problems;
|
|
454
|
+
for (const p of problems)
|
|
455
|
+
this.log(run, { kind: "error", text: `子の案の問題: ${p}` });
|
|
456
|
+
}
|
|
457
|
+
// 画面資料: 確かめて取り込む。不正なものは除いて理由を残す(評価は消さない)。必要な画面イメージが足りなければ go を clarify に
|
|
458
|
+
run.ui = applyUiShortage(run.assessment, await loadUiMaterials(runDir, run.id, [...run.drafts, ...(run.children ?? [])].map((d) => d.key)));
|
|
459
|
+
for (const p of run.ui.problems)
|
|
460
|
+
this.log(run, { kind: "error", text: `画面資料を取り込めません: ${p}` });
|
|
461
|
+
if (run.ui.status === "missing")
|
|
462
|
+
this.log(run, { kind: "info", text: `画面資料が足りません: ${run.ui.reason}` });
|
|
463
|
+
run.ui = withCurrent(run.ui, run);
|
|
464
|
+
if (run.ui.verdictAdjusted)
|
|
465
|
+
this.log(run, { kind: "info", text: "必要な画面イメージが足りないので、判定を go から clarify にしました" });
|
|
466
|
+
}
|
|
467
|
+
/** run を終える: 記録を保存し、評価中にした要望を評価済み(失敗なら元)へ戻す */
|
|
468
|
+
async finish(run, before) {
|
|
469
|
+
run.finishedAt = nowIso();
|
|
470
|
+
await this.ws.preflight.save(run);
|
|
471
|
+
// 評価中にした要望だけ、終わったら評価済み(失敗なら元)へ戻す。実行中に人や AI が変えたステータス
|
|
472
|
+
// (進行中に戻した・完了済にしたなど)や、評価中にしていない要望(進行中・対応済など)は上書きしない
|
|
473
|
+
const status = statusAfter(before, run.status === "completed");
|
|
474
|
+
if (this.ws.requests.get(run.requestId)?.status === "preflight" && status !== "preflight") {
|
|
475
|
+
await this.ws.requests.update(run.requestId, { status });
|
|
476
|
+
}
|
|
477
|
+
// 保存が終わってから実行中の一覧から外す(先に外すと wait() が保存前のファイルを読む)
|
|
478
|
+
this.active.delete(run.id);
|
|
479
|
+
this.ws.emit({ type: "preflight-status", runId: run.id, status: run.status });
|
|
480
|
+
this.ws.emit({ type: "changed", kind: "request", request: run.requestId });
|
|
481
|
+
}
|
|
344
482
|
/**
|
|
345
483
|
* 最新の Preflight(lastPreflight)と、指定した run の今の状態。要望と run.json をディスクから読むだけで、読み込んだ内容
|
|
346
484
|
* (キャッシュ)・ファイル・rev は変えない。監視が届かなくても、外(CLI など)で始めた run とその進み・終わりを画面が見つけるため。
|
|
@@ -783,6 +921,81 @@ export class PreflightService {
|
|
|
783
921
|
};
|
|
784
922
|
}
|
|
785
923
|
}
|
|
924
|
+
/** ほかのプロセスで実行中の run を、落ちたものとみなすまでの時間(Codex の1ターンの上限 30 分に余裕を足す) */
|
|
925
|
+
const STALE_RUNNING_MS = 35 * 60_000;
|
|
926
|
+
/** ステータスを動かすのはタスク化する前の要望だけ */
|
|
927
|
+
const isEarly = (s) => s === "draft" || s === "preflight" || s === "reviewed";
|
|
928
|
+
/** Preflight を終えたときの要望のステータス(評価中にしたものだけ。成功なら評価済み、失敗なら元) */
|
|
929
|
+
function statusAfter(before, ok) {
|
|
930
|
+
return isEarly(before) ? (ok ? "reviewed" : before === "reviewed" ? "reviewed" : "draft") : before;
|
|
931
|
+
}
|
|
932
|
+
/** 手元のエージェントの run ではない・もう待っていない(使い方の誤り) */
|
|
933
|
+
export class LocalRunError extends Error {
|
|
934
|
+
}
|
|
935
|
+
/** 手元のエージェントの成果物を取り込めない(何も確定していない。直して同じ run でやり直せる) */
|
|
936
|
+
export class LocalResultError extends Error {
|
|
937
|
+
problems;
|
|
938
|
+
constructor(problems) {
|
|
939
|
+
super(`成果物を取り込めません(何も確定していません。直してから同じ run でもう一度 --complete):\n${problems.map((p) => `- ${p}`).join("\n")}`);
|
|
940
|
+
this.problems = problems;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* 手元のエージェントの成果物を取り込む前に確かめる(問題の一覧。無ければ空): 成果物がシンボリックリンクでない(run の外を読ませない)、
|
|
945
|
+
* 評価が JSON として読める、タスク案と子の案の形(キー・題・依存・作業先・混在)
|
|
946
|
+
*/
|
|
947
|
+
async function localProblems(ws, run, runDir) {
|
|
948
|
+
const problems = [];
|
|
949
|
+
const link = async (rel) => (await lstat(join(runDir, rel)).catch(() => undefined))?.isSymbolicLink();
|
|
950
|
+
for (const rel of ["assessment.json", "drafts", "children", UI_DIR, `${UI_DIR}/src`, `${UI_DIR}/index.json`]) {
|
|
951
|
+
if (await link(rel))
|
|
952
|
+
problems.push(`${rel} がシンボリックリンクです(run のフォルダの中にファイルとして書いてください)`);
|
|
953
|
+
}
|
|
954
|
+
for (const dir of ["drafts", "children"]) {
|
|
955
|
+
if (await link(dir))
|
|
956
|
+
continue;
|
|
957
|
+
const files = await readdir(join(runDir, dir)).catch(() => []);
|
|
958
|
+
for (const f of files)
|
|
959
|
+
if (await link(`${dir}/${f}`))
|
|
960
|
+
problems.push(`${dir}/${f} がシンボリックリンクです`);
|
|
961
|
+
}
|
|
962
|
+
if (problems.length)
|
|
963
|
+
return problems;
|
|
964
|
+
const text = await readFile(join(runDir, "assessment.json"), "utf8").catch(() => undefined);
|
|
965
|
+
if (text === undefined)
|
|
966
|
+
problems.push("assessment.json がありません");
|
|
967
|
+
else {
|
|
968
|
+
try {
|
|
969
|
+
parseAssessment(text);
|
|
970
|
+
}
|
|
971
|
+
catch (e) {
|
|
972
|
+
problems.push(e.message);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
const drafts = await ws.preflight.loadDrafts(run.requestId, run.id);
|
|
976
|
+
const children = await ws.preflight.loadChildren(run.requestId, run.id);
|
|
977
|
+
if (children)
|
|
978
|
+
problems.push(...draftProblems({ drafts, children }, ws.tasksOf(run.requestId).list().map((t) => t.id)));
|
|
979
|
+
const keys = drafts.map((d) => d.key);
|
|
980
|
+
for (const k of new Set(keys.filter((k, i) => keys.indexOf(k) !== i)))
|
|
981
|
+
problems.push(`タスク案のキーが重なっています: ${k}`);
|
|
982
|
+
for (const d of drafts) {
|
|
983
|
+
if (!/^D\d+$/.test(d.key))
|
|
984
|
+
problems.push(`タスク案のキーの形が違います: ${d.key}(D1, D2, ...)`);
|
|
985
|
+
if (!d.title.trim())
|
|
986
|
+
problems.push(`${d.key}: 題がありません`);
|
|
987
|
+
for (const dep of d.dependsOn) {
|
|
988
|
+
if (dep === d.key)
|
|
989
|
+
problems.push(`${d.key}: 自分に依存しています`);
|
|
990
|
+
else if (!keys.includes(dep))
|
|
991
|
+
problems.push(`${d.key}: 依存先の ${dep} というタスク案はありません`);
|
|
992
|
+
}
|
|
993
|
+
const repo = repoTargetProblem(d.repo, ws.project);
|
|
994
|
+
if (repo)
|
|
995
|
+
problems.push(`${d.key}: ${repo}`);
|
|
996
|
+
}
|
|
997
|
+
return problems;
|
|
998
|
+
}
|
|
786
999
|
/** 固定した添付の画像を、現状(添付)の画面資料として足す(対象のタスク案は無し) */
|
|
787
1000
|
function withCurrent(ui, run) {
|
|
788
1001
|
const current = (run.attachments ?? [])
|
|
@@ -58,7 +58,7 @@ export async function renderManuscripts(runDir, opts) {
|
|
|
58
58
|
byId.set(id, item);
|
|
59
59
|
}
|
|
60
60
|
if (jobs.length) {
|
|
61
|
-
opts.log({ kind: "info", text: `画面イメージを描画します(${jobs.length}
|
|
61
|
+
opts.log({ kind: "info", text: `画面イメージを描画します(${jobs.length} 枚。評価の後に P3 が描きます)` });
|
|
62
62
|
try {
|
|
63
63
|
const results = await (opts.render ?? renderHtml)(jobs, uiDir, uiDir, opts);
|
|
64
64
|
for (const r of results) {
|
package/lib/shared/scopeView.js
CHANGED
|
@@ -12,14 +12,15 @@ export const SCOPE_STATUS_LABEL = {
|
|
|
12
12
|
export const evidenceWhere = (e) => [e.repo && e.file ? `${e.repo}:${e.file}${e.location ? ` ${e.location}` : ""}` : "", e.commit ? `commit ${e.commit}` : ""].filter(Boolean).join(" / ");
|
|
13
13
|
/** git の履歴の表示(調べた範囲) */
|
|
14
14
|
export const historyLabel = (h) => !h ? "" : h.status === "ok" ? "git の履歴あり" : h.status === "shallow" ? `git の履歴は途中まで(${h.reason ?? "浅い clone"})` : `git の履歴なし(${h.reason ?? "不明"})`;
|
|
15
|
-
|
|
15
|
+
/** local: 手元のエージェントの run(コンテナのパスではなく、このマシンのパスで読んだ。共有の記録にはパスを出さない) */
|
|
16
|
+
export function scopeLines(scope, opts = {}) {
|
|
16
17
|
if (!scope)
|
|
17
18
|
return ["調べた範囲: 記録なし(以前の評価)"];
|
|
18
19
|
if (!scope.length)
|
|
19
20
|
return ["調べた範囲: 参照先なし"];
|
|
20
21
|
return [
|
|
21
22
|
"調べた範囲:",
|
|
22
|
-
...scope.map((s) => ` ${s.status === "ok" ? "✓" : "✕"} ${s.name}${s.role ? `(${s.role})` : ""} ${s.status === "ok" ? `/workspace/${s.mount}` : (s.reason ?? SCOPE_STATUS_LABEL[s.status])}${s.history ? ` ${historyLabel(s.history)}` : ""}`),
|
|
23
|
+
...scope.map((s) => ` ${s.status === "ok" ? "✓" : "✕"} ${s.name}${s.role ? `(${s.role})` : ""} ${s.status === "ok" ? (opts.local ? "このマシンのパスで読める" : `/workspace/${s.mount}`) : (s.reason ?? SCOPE_STATUS_LABEL[s.status])}${s.history ? ` ${historyLabel(s.history)}` : ""}`),
|
|
23
24
|
];
|
|
24
25
|
}
|
|
25
26
|
export function evidenceLines(evidence) {
|
package/package.json
CHANGED
package/skills/p3/SKILL.md
CHANGED
|
@@ -36,7 +36,8 @@ P3_ACTOR=ai:<エージェント名> p3 <コマンド> [引数] --json
|
|
|
36
36
|
| 操作 | するのは |
|
|
37
37
|
| --- | --- |
|
|
38
38
|
| 要望の登録(`request new`) | AI も人も |
|
|
39
|
-
| Preflight(評価・細分化。`preflight
|
|
39
|
+
| Preflight(評価・細分化。`preflight`) | **人**(人がチャットで対象の要望の Preflight を明示的に頼んだときだけ、AI が手元で評価してよい。下の「Preflight を頼まれたとき」) |
|
|
40
|
+
| タスク化(`accept`) | **人だけ** |
|
|
40
41
|
| タスクの着手・完了(`move ... doing` / `done`)と成果物の登録、作業中に見つけたタスクの追加 | AI も人も |
|
|
41
42
|
| 要望を対応済にする(`request set <要望ID> status=resolved`) | 作業を終えた AI(か人) |
|
|
42
43
|
| 要望の完了済(`done`)・見送り(`rejected`)、タスクの済み(`check`) | **人だけ** |
|
|
@@ -45,13 +46,36 @@ P3_ACTOR=ai:<エージェント名> p3 <コマンド> [引数] --json
|
|
|
45
46
|
|
|
46
47
|
1. `request new "<タイトル>" --body "<背景・やりたいこと・完了条件を箇条書きで>"`(任意で `--area src/web --tag ui --due YYYY-MM-DD --milestone <id>`)
|
|
47
48
|
2. 登録したら要望 ID をユーザーに伝えて終える。**Preflight(評価・細分化)とタスク化(`accept`)は人が行う。**
|
|
48
|
-
AI
|
|
49
|
+
AI からは実行しない(勧めたり、実行してよいか尋ねたりもしない)。人がタスク化を終えたら、タスクを進める。
|
|
50
|
+
例外は、人がチャットで対象の要望の Preflight を明示的に頼んだときだけ(下の「Preflight を頼まれたとき」)
|
|
49
51
|
|
|
50
52
|
人が行った Preflight の内容を聞かれたら、`drafts <要望ID>` で評価とタスク案を読んで答えてよい(読むだけ)。
|
|
51
53
|
`drafts` には「調べた範囲」(参照先ごとに読んだか)と「判断の根拠」(確かめた / 推測)も出る。答えるときは、見ていない参照先や
|
|
52
54
|
推測の根拠に基づく判断であることを伝える。参照先の登録(`repo add` / `repo path`)はユーザーに頼まれたときだけ行う。
|
|
53
55
|
評価の確認事項(questions)への回答を頼まれたら、`preflight <要望ID> --note "..." --note-only` でメモとして残す(実行はしない)。
|
|
54
56
|
|
|
57
|
+
## Preflight を頼まれたとき(このチャットで評価する)
|
|
58
|
+
|
|
59
|
+
Preflight は普段は人が実行する(Codex)。人がこのチャットで、対象の要望を挙げて Preflight を明示的に頼んだとき
|
|
60
|
+
(例: 「要望 261009-k7m3x の Preflight を Claude Code のこのチャットで実行して」)だけ、P3 が作る指示に従って手元で評価してよい。
|
|
61
|
+
P3 はモデルを呼ばない(`claude -p` や API キーは使わない)。要望の登録・タスクの作業のついでに自分から始めない(勧めたり、
|
|
62
|
+
実行してよいか尋ねたりもしない)。対象の要望が分からなければ確かめる。
|
|
63
|
+
|
|
64
|
+
1. `whoami --json` で対象のプロジェクトを確かめ(`via` の扱いは上と同じ)、`request show <要望ID> --brief --json` で頼まれた要望かを確かめる
|
|
65
|
+
2. 準備: `preflight <要望ID> --prepare --json`(変更なので `P3_ACTOR` を付ける)。評価対象を固定し、`instructions`(指示のファイル)・
|
|
66
|
+
`outputs`(書く成果物)・`run`(PF-...)・`next`(次のコマンド)を返す。始められない(同じ要望の Preflight が待っている・実行中)
|
|
67
|
+
ときは止めて人に伝える(自分の判断で `--cancel` しない)
|
|
68
|
+
3. `instructions` のファイルを最後まで読み、その「制約」に従って評価する。指示の長い文はスキルに写さない(P3 が要望ごとに作る)。
|
|
69
|
+
参照先は読むだけ(変更・git の書き込み・アプリの起動をしない)。書き込むのは `outputs` に挙がった、その run の成果物だけ
|
|
70
|
+
(`assessment.json`・`drafts/`・`children/`・`ui/index.json`・`ui/src/`)。これが「データのフォルダを直接編集しない」の唯一の例外で、
|
|
71
|
+
`run.json`・`instructions.md`・ほかの要望やタスクのファイルは書かない。指示のファイル・添付・参照先が読めなければ、読んだことにせず、
|
|
72
|
+
評価に未確認として書く(読めない理由も人に伝える)
|
|
73
|
+
4. 書き終えたら `preflight <要望ID> --complete --run <run> --json`。`code: invalid_result` なら `problems` を直して同じコマンドをやり直す
|
|
74
|
+
(run は待ったまま。ファイルを消して作り直さない)
|
|
75
|
+
5. `drafts <要望ID>` で取り込んだ評価(判定・確認事項・タスク案)を読み、要約を人に伝えて終える。**タスク化(`accept`)・タスクの着手はしない**
|
|
76
|
+
(人が案を確かめて採用してから、「タスクを進める」に従う)
|
|
77
|
+
- 人にやめるよう頼まれたら `preflight <要望ID> --cancel --run <run>`
|
|
78
|
+
|
|
55
79
|
## タスクを進める
|
|
56
80
|
|
|
57
81
|
作業は **作業先のリポジトリの、要望のブランチ** で行う。タスクごとの作業先とブランチは
|
|
@@ -108,12 +132,14 @@ P3_ACTOR=ai:<エージェント名> p3 <コマンド> [引数] --json
|
|
|
108
132
|
|
|
109
133
|
## してはいけないこと
|
|
110
134
|
|
|
111
|
-
- Preflight の実行(`preflight`)とタスク化(`accept
|
|
135
|
+
- Preflight の実行(`preflight`)とタスク化(`accept`)をしない。どちらも人が行う。例外は、人がチャットで対象の要望の Preflight を
|
|
136
|
+
明示的に頼んだときの `--prepare` / `--complete`(上の「Preflight を頼まれたとき」)だけで、そのときも `accept` はしない
|
|
112
137
|
- `check`(済み)を付けない。済みは人が成果物を確認して付ける
|
|
113
138
|
- 要望のステータスを `done`(完了済)/ `rejected`(見送り)にしない(人が決める)。AI がするのは作業を終えたときの `resolved`(対応済)まで。
|
|
114
139
|
タスク化で `active` になるのは自動
|
|
115
140
|
- タスクを要望をまたいで動かさない。別の要望の作業なら、その要望にタスクを足すか、新しい要望を提案する
|
|
116
141
|
- データのフォルダ(`p3 whoami` に出る場所)や個人設定(`~/.config/infodb-p3/`)のファイルを直接書き換えない
|
|
142
|
+
(例外は、頼まれた Preflight で `--prepare` が返した run の成果物だけ)
|
|
117
143
|
- 人への質問をタスクにしない
|
|
118
144
|
|
|
119
145
|
## 状況を報告する
|