@infodb/p3 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -35
- package/bin/p3.mjs +3 -2
- package/dist/web/assets/CompletionReview-BD7d6Yzt.js +1 -0
- package/dist/web/assets/ImprovementDialog-BoAZN1KR.js +1 -0
- package/dist/web/assets/Outputs-D-ZouoxF.js +1 -0
- package/dist/web/assets/RequestStatus-Bl3fdSbM.js +1 -0
- package/dist/web/assets/Tabs-CxeceOL-.js +1 -0
- package/dist/web/assets/TagInput-CeAbmGRR.js +1 -0
- package/dist/web/assets/TaskDrawer-BCriSnhe.js +6 -0
- package/dist/web/assets/_requestId-CZKMe_mC.js +1 -0
- package/dist/web/assets/_requestId-Fx4lLkFo.js +1 -0
- package/dist/web/assets/appCtx-BdxbkSZa.js +1 -0
- package/dist/web/assets/archive-D5IIxcSV.js +1 -0
- package/dist/web/assets/board-p6R9KMqd.js +1 -0
- package/dist/web/assets/done-BTOF188x.js +1 -0
- package/dist/web/assets/draft-BWYpm3PD.js +2 -0
- package/dist/web/assets/index-DFbY8NAR.css +2 -0
- package/dist/web/assets/index-Dpqi2dcC.js +12 -0
- package/dist/web/assets/link-D481whDt.js +1 -0
- package/dist/web/assets/metrics-CAzP6V8I.js +1 -0
- package/dist/web/assets/new-C65IJJg3.js +1 -0
- package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
- package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
- package/dist/web/assets/preload-helper-_dAYMct_.js +1 -0
- package/dist/web/assets/{quality-Pu6EISAM.js → quality-RFd-7k3r.js} +1 -1
- package/dist/web/assets/release-notes-Dtif8xsQ.js +5 -0
- package/dist/web/assets/requestData-SPc36t8Q.js +1 -0
- package/dist/web/assets/routes-DJj8CWuk.js +6 -0
- package/dist/web/assets/settings-DKJd7CLe.js +1 -0
- package/dist/web/assets/ui-CbEOnPnF.js +1 -0
- package/dist/web/assets/workTarget-DavxMs-c.js +30 -0
- package/dist/web/index.html +6 -4
- package/docs/architecture.md +430 -72
- package/docs/chatgpt-sign-in.md +2 -2
- package/docs/development.md +141 -64
- package/docs/feature-inventory.md +139 -0
- package/docs/how-to-use.md +389 -31
- package/docs/installation.md +261 -147
- package/docs/publishing.md +33 -14
- package/docs/refactoring.md +332 -0
- package/lib/cli/agentsStatus.js +198 -0
- package/lib/cli/guide.js +27 -0
- package/lib/cli/guide.md +217 -0
- package/lib/cli/help.js +45 -7
- package/lib/cli/main.js +58 -207
- package/lib/cli/project.js +34 -294
- package/lib/core/projectRegistry.js +2 -2
- package/lib/kit/appInfo.js +13 -0
- package/lib/kit/usage.js +27 -0
- package/lib/server/api/projectsRoutes.js +5 -5
- package/lib/server/server.js +7 -4
- package/lib/{cli → tasks/cli}/args.js +73 -9
- package/lib/{cli → tasks/cli}/chatgpt.js +1 -1
- package/lib/{cli → tasks/cli}/codex.js +1 -1
- package/lib/{cli → tasks/cli}/output.js +12 -2
- package/lib/{cli → tasks/cli}/preflightCommands.js +1 -1
- package/lib/tasks/cli/readOnly.js +75 -0
- package/lib/{cli → tasks/cli}/render.js +1 -1
- package/lib/{cli → tasks/cli}/requestCommands.js +24 -7
- package/lib/tasks/cli/showView.js +279 -0
- package/lib/{cli → tasks/cli}/taskCommands.js +55 -21
- package/lib/tasks/cli/tasksCli.js +149 -0
- package/lib/{core → tasks/core}/context.js +6 -9
- package/lib/tasks/core/errorOutcome.js +125 -0
- package/lib/{core → tasks/core}/hierarchy.js +1 -1
- package/lib/{core → tasks/core}/ops.js +17 -2
- package/lib/{core → tasks/core}/preflight/carryover.js +5 -1
- package/lib/{core → tasks/core}/preflight/codexEngine.js +36 -28
- package/lib/{core → tasks/core}/preflight/diagnose.js +4 -9
- package/lib/{core → tasks/core}/preflight/engine.js +9 -0
- package/lib/tasks/core/preflight/hostPaths.js +299 -0
- package/lib/{core → tasks/core}/preflight/input.js +33 -5
- package/lib/{core → tasks/core}/preflight/instructions.js +19 -2
- package/lib/{core → tasks/core}/preflight/mockEngine.js +27 -8
- package/lib/{core → tasks/core}/preflight/render.js +22 -3
- package/lib/{core → tasks/core}/preflight/service.js +86 -11
- package/lib/{core → tasks/core}/preflight/uiRender.js +5 -2
- package/lib/{core → tasks/core}/requestOps.js +214 -17
- package/lib/{core → tasks/core}/reviewRuns.js +127 -22
- package/lib/{core → tasks/core}/store/attachments.js +3 -2
- package/lib/{core → tasks/core}/store/collection.js +21 -2
- package/lib/tasks/core/store/fieldGroups.js +30 -0
- package/lib/tasks/core/store/jsonRecord.js +30 -0
- package/lib/{core → tasks/core}/store/normalize.js +15 -10
- package/lib/{core → tasks/core}/store/noteStore.js +2 -2
- package/lib/{core → tasks/core}/store/preflightStore.js +59 -22
- package/lib/{core → tasks/core}/store/projectFile.js +1 -1
- package/lib/{core → tasks/core}/store/workspace.js +28 -6
- package/lib/{core → tasks/core}/userConfig.js +1 -1
- package/lib/{core → tasks/core}/workTargets.js +1 -1
- package/lib/tasks/features/metrics/cli/metricsCommands.js +77 -0
- package/lib/tasks/features/metrics/core/definitions.js +445 -0
- package/lib/tasks/features/metrics/core/index.js +112 -0
- package/lib/tasks/features/metrics/core/manual.js +179 -0
- package/lib/tasks/features/metrics/server/metricsRoutes.js +8 -0
- package/lib/tasks/features/metrics/shared/metrics.js +42 -0
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/code.js +2 -11
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/material.js +5 -6
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/review.js +2 -2
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/service.js +38 -100
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/store.js +3 -3
- package/lib/{server/api → tasks/features/milestoneReview/server}/milestoneReviewRoutes.js +7 -13
- package/lib/{cli → tasks/features/quality/cli}/qualityCommands.js +36 -11
- package/lib/{core → tasks/features/quality/core}/qualityImprovement.js +16 -15
- package/lib/tasks/features/records/cli/revisitCommands.js +73 -0
- package/lib/tasks/features/records/core/completionRefs.js +46 -0
- package/lib/tasks/features/records/core/reviewCandidates.js +76 -0
- package/lib/tasks/features/records/shared/completionRecord.js +329 -0
- package/lib/tasks/features/records/shared/reviewCandidate.js +313 -0
- package/lib/tasks/features/records/shared/reworkHistory.js +86 -0
- package/lib/{cli → tasks/features/releaseNotes/cli}/releaseNotesCommands.js +7 -7
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/completeRequests.js +5 -6
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/generate.js +3 -14
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/material.js +3 -4
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/service.js +1 -1
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/store.js +2 -2
- package/lib/{server/api → tasks/features/releaseNotes/server}/releaseNoteRoutes.js +11 -20
- package/lib/tasks/features/requirements/cli/requirementCommands.js +289 -0
- package/lib/{shared → tasks/features/requirements/shared}/acceptance.js +292 -18
- package/lib/tasks/features/requirements/shared/requirementSource.js +635 -0
- package/lib/tasks/features/retro/cli/retroCommands.js +106 -0
- package/lib/tasks/features/retro/core/retrospective.js +197 -0
- package/lib/tasks/features/retro/shared/retrospective.js +286 -0
- package/lib/tasks/features/settings/cli/projectSettings.js +245 -0
- package/lib/{cli → tasks/features/settings/cli}/userConfig.js +50 -3
- package/lib/{core → tasks/features/settings/core}/machineSettingsEdit.js +2 -2
- package/lib/{core → tasks/features/settings/core}/repoAdmin.js +3 -3
- package/lib/{core → tasks/features/settings/core}/userTheme.js +2 -2
- package/lib/{server/api → tasks/features/settings/server}/repoRoutes.js +2 -2
- package/lib/{server/api → tasks/features/settings/server}/userThemeRoutes.js +3 -3
- package/lib/{cli → tasks/features/taskReview/cli}/taskReviewCommands.js +5 -5
- package/lib/{core/taskReview → tasks/features/taskReview/core}/material.js +13 -7
- package/lib/{core/taskReview → tasks/features/taskReview/core}/review.js +10 -3
- package/lib/{core/taskReview → tasks/features/taskReview/core}/service.js +24 -85
- package/lib/{core/taskReview → tasks/features/taskReview/core}/store.js +4 -4
- package/lib/{server/api → tasks/features/taskReview/server}/taskReviewRoutes.js +7 -14
- package/lib/{server → tasks/server}/api/manifest.js +51 -3
- package/lib/{server → tasks/server}/api/routes.js +134 -65
- package/lib/tasks/shared/commitRefs.js +10 -0
- package/lib/{shared → tasks/shared}/preflightInput.js +1 -1
- package/package.json +1 -43
- package/skills/p3/SKILL.md +9 -181
- package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +0 -1
- package/dist/web/assets/Outputs-_nU_p3nu.js +0 -1
- package/dist/web/assets/RequestStatus-RG-OVQYY.js +0 -1
- package/dist/web/assets/Tabs-ew9i5SKX.js +0 -1
- package/dist/web/assets/TagInput-BtlJTF7i.js +0 -1
- package/dist/web/assets/TaskDrawer-DW8GyJqI.js +0 -6
- package/dist/web/assets/_requestId-6Nb727dD.js +0 -1
- package/dist/web/assets/_requestId-BykTgPax.js +0 -1
- package/dist/web/assets/appCtx-CxDdXABS.js +0 -1
- package/dist/web/assets/archive-Ckh295Xe.js +0 -1
- package/dist/web/assets/board-BVAIjK-Y.js +0 -1
- package/dist/web/assets/done-BGfA-3MA.js +0 -1
- package/dist/web/assets/draft-CfJeyLOl.js +0 -1
- package/dist/web/assets/index-CgRU744I.css +0 -2
- package/dist/web/assets/index-DacQ0yl4.js +0 -12
- package/dist/web/assets/new-DVygWvVc.js +0 -1
- package/dist/web/assets/outputs-B6xDsLZf.js +0 -1
- package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
- package/dist/web/assets/preload-helper-DyCqp21K.js +0 -1
- package/dist/web/assets/release-notes-CCpzyiNf.js +0 -5
- package/dist/web/assets/requestData-D5vBnuMh.js +0 -1
- package/dist/web/assets/routes-Q91zvNc0.js +0 -4
- package/dist/web/assets/settings-BzRgcmUm.js +0 -1
- package/dist/web/assets/workTarget-C9c57JAO.js +0 -30
- package/lib/cli/readOnly.js +0 -38
- package/lib/cli/showView.js +0 -166
- /package/lib/{core/store → kit}/frontmatter.js +0 -0
- /package/lib/{core/store → kit}/fsutil.js +0 -0
- /package/lib/{cli → tasks/cli}/format.js +0 -0
- /package/lib/{core → tasks/core}/chatgpt.js +0 -0
- /package/lib/{core → tasks/core}/machineSettings.js +0 -0
- /package/lib/{core → tasks/core}/preflight/codexImage.js +0 -0
- /package/lib/{core → tasks/core}/preflight/docker.js +0 -0
- /package/lib/{core → tasks/core}/preflight/launch.js +0 -0
- /package/lib/{core → tasks/core}/preflight/launcher.mjs +0 -0
- /package/lib/{core → tasks/core}/preflight/mock-ui.html +0 -0
- /package/lib/{core → tasks/core}/preflight/mock-ui.png +0 -0
- /package/lib/{core → tasks/core}/preflight/owner.js +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/Dockerfile +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/fonts-ja.conf +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/render.mjs +0 -0
- /package/lib/{core → tasks/core}/preflight/split.js +0 -0
- /package/lib/{core → tasks/core}/preflight/uiMaterials.js +0 -0
- /package/lib/{core → tasks/core}/preflight/wireframe.js +0 -0
- /package/lib/{core → tasks/core}/preflight/xlsx.js +0 -0
- /package/lib/{core → tasks/core}/redact.js +0 -0
- /package/lib/{core → tasks/core}/repoRefs.js +0 -0
- /package/lib/{core → tasks/core}/requestStatus.js +0 -0
- /package/lib/{core → tasks/core}/store/archivedTasks.js +0 -0
- /package/lib/{core → tasks/core}/store/dataWatcher.js +0 -0
- /package/lib/{core → tasks/core}/store/locate.js +0 -0
- /package/lib/{core → tasks/core}/supersede.js +0 -0
- /package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/mockReviewer.js +0 -0
- /package/lib/{shared → tasks/features/milestoneReview/shared}/milestoneReview.js +0 -0
- /package/lib/{core → tasks/features/quality/core}/quality.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/quality.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/qualityImprovement.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/qualityTemplates.js +0 -0
- /package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/mockSummarizer.js +0 -0
- /package/lib/{core/taskReview → tasks/features/taskReview/core}/mockReviewer.js +0 -0
- /package/lib/{core/taskReview → tasks/features/taskReview/core}/paths.js +0 -0
- /package/lib/{shared → tasks/features/taskReview/shared}/taskReview.js +0 -0
- /package/lib/{server → tasks/server}/api/chatgptRoutes.js +0 -0
- /package/lib/{server → tasks/server}/api/local.js +0 -0
- /package/lib/{shared → tasks/shared}/dates.js +0 -0
- /package/lib/{shared → tasks/shared}/directTask.js +0 -0
- /package/lib/{shared → tasks/shared}/hierarchy.js +0 -0
- /package/lib/{shared → tasks/shared}/milestoneGoals.js +0 -0
- /package/lib/{shared → tasks/shared}/milestoneOrder.js +0 -0
- /package/lib/{shared → tasks/shared}/preflightRunner.js +0 -0
- /package/lib/{shared → tasks/shared}/refs.js +0 -0
- /package/lib/{shared → tasks/shared}/repos.js +0 -0
- /package/lib/{shared → tasks/shared}/scopeView.js +0 -0
- /package/lib/{shared → tasks/shared}/tags.js +0 -0
- /package/lib/{shared → tasks/shared}/taskBlock.js +0 -0
- /package/lib/{shared → tasks/shared}/types.js +0 -0
- /package/lib/{shared → tasks/shared}/workTarget.js +0 -0
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { REQUEST_FIELD_GROUPS, TASK_FIELD_GROUPS, withoutManaged } from "./store/fieldGroups.js";
|
|
2
|
+
import { acceptanceChanged, acceptanceSeqChanged, applyAcceptanceOps, recordedSourceSeq } from "../features/requirements/shared/acceptance.js";
|
|
3
|
+
import { readManual } from "../features/metrics/core/manual.js";
|
|
2
4
|
import { applyBlockOp, checkBlockedStatus } from "../shared/taskBlock.js";
|
|
3
|
-
import { qualityCriteria, standardHash, taskQualityDiff } from "../shared/quality.js";
|
|
5
|
+
import { qualityCriteria, standardHash, taskQualityDiff } from "../features/quality/shared/quality.js";
|
|
6
|
+
import { answersKey, applySourceOps, makeAnswer, putAnswer, requestSubject, RequirementInputError, settleSources, sourceSeq, sourcesKey, } from "../features/requirements/shared/requirementSource.js";
|
|
4
7
|
import { defaultRepo } from "../shared/workTarget.js";
|
|
8
|
+
import { appendCompletion, COMPLETION_SKIPPED, requestCompletionRecord, requestTriggers, taskCompletionRecord, taskTriggers } from "../features/records/shared/completionRecord.js";
|
|
9
|
+
import { captureRefs } from "../features/records/core/completionRefs.js";
|
|
10
|
+
import { appendRework, reworkOf, REWORK_SKIPPED } from "../features/records/shared/reworkHistory.js";
|
|
11
|
+
import { applyPremiseOp, PremiseInputError } from "../features/records/shared/reviewCandidate.js";
|
|
5
12
|
import { withArchiveCheck, withChildOrder, withNewChild, withParentChange } from "./hierarchy.js";
|
|
6
13
|
import { checkStatusChange, reopenAncestors, reopenIfNeeded } from "./requestStatus.js";
|
|
7
14
|
import { startWarnings } from "./supersede.js";
|
|
@@ -59,6 +66,33 @@ class NoChange extends Error {
|
|
|
59
66
|
}
|
|
60
67
|
/** 済みを外した理由(基準・証拠の中身が変わった) */
|
|
61
68
|
export const CHECK_CLEARED_BY_ACCEPTANCE = "受け入れ基準か証拠の中身が変わったため、人の「済み」を外しました(もう一度確かめてください)";
|
|
69
|
+
/** 完了の記録を作るときの周りの値(品質は今の project.yaml、参照先は書く前に取ったもの) */
|
|
70
|
+
const completionContext = (ctx, at, by, refs) => ({
|
|
71
|
+
at,
|
|
72
|
+
...(by ? { by } : {}),
|
|
73
|
+
quality: ctx.ws.project.quality,
|
|
74
|
+
qualityVersion: ctx.ws.project.qualityVersion,
|
|
75
|
+
...(refs ? { refs } : {}),
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* タスクを書いた後の値(final)に、足すべき完了の記録を足した patch の部分(無ければ空)。rev は書いた後の rev。
|
|
79
|
+
* 記録が壊れていて足せなければ skipped に理由を入れ、記録の項目には触れない(元の値のまま書き戻す)
|
|
80
|
+
*/
|
|
81
|
+
function taskCompletionPatch(ctx, rid, prev, final, rev, acceptanceChanged, c) {
|
|
82
|
+
const triggers = taskTriggers(prev, final, acceptanceChanged);
|
|
83
|
+
if (!triggers.length)
|
|
84
|
+
return { patch: {} };
|
|
85
|
+
const request = ctx.ws.requests.get(rid);
|
|
86
|
+
const cc = completionContext(ctx, c.at, c.by, c.refs);
|
|
87
|
+
let state = final;
|
|
88
|
+
for (const trigger of triggers) {
|
|
89
|
+
const list = appendCompletion(state, (id) => taskCompletionRecord(id, trigger, final, rev, request, cc));
|
|
90
|
+
if (!list)
|
|
91
|
+
return { patch: {}, skipped: COMPLETION_SKIPPED };
|
|
92
|
+
state = { completionRecords: list };
|
|
93
|
+
}
|
|
94
|
+
return { patch: { completionRecords: state.completionRecords } };
|
|
95
|
+
}
|
|
62
96
|
function changed(ctx, kind, request, ref) {
|
|
63
97
|
ctx.ws.emit({ type: "changed", kind, request, ref });
|
|
64
98
|
}
|
|
@@ -90,6 +124,14 @@ export async function checkMilestoneRemoval(ctx, next) {
|
|
|
90
124
|
if (reviewed.length) {
|
|
91
125
|
throw new OpRuleError(`レビューの履歴のあるマイルストーンは消せません(ID も変えられません): ${reviewed.join(", ")}(milestone-reviews/<ID>/ に残っています)`);
|
|
92
126
|
}
|
|
127
|
+
// 人が記録した指標の値(読めなければ参照があるか分からないので消さない)
|
|
128
|
+
const manual = await readManual(ctx.ws.dataDir);
|
|
129
|
+
if (manual.problem)
|
|
130
|
+
throw new OpRuleError(`指標の記録(metrics/manual.json)が読めないため、マイルストーンを消せるか分かりません: ${manual.problem}`);
|
|
131
|
+
const measured = [...new Set(manual.records.filter((r) => removed.includes(r.scope)).map((r) => r.scope))];
|
|
132
|
+
if (measured.length) {
|
|
133
|
+
throw new OpRuleError(`指標の値を記録したマイルストーンは消せません(ID も変えられません): ${measured.join(", ")}(p3 metrics --milestone <ID> で確かめ、要らなければ p3 metrics rm で消してから)`);
|
|
134
|
+
}
|
|
93
135
|
}
|
|
94
136
|
/** 要望を変えた後: 配下に未完了ができたら対応済の祖先を進行中に戻し(変更通知も)、完了済の祖先は警告にする */
|
|
95
137
|
async function afterRequestWrite(ctx, rid, actor) {
|
|
@@ -126,12 +168,19 @@ export async function createTask(ctx, rid, { criteria, quality, ...input }, acto
|
|
|
126
168
|
checkRepoTarget(ctx.ws, o.repo);
|
|
127
169
|
// 受け入れ基準は文の並びで受け取り、ID(A1, A2, ...)はここで振る(基準・証拠をそのまま渡す道は持たない)
|
|
128
170
|
// 停止は作るときには付けない(作業中にしてから block で付ける)
|
|
129
|
-
|
|
171
|
+
// 完了の記録は p3 が作る(値をそのまま書く道は持たない)
|
|
172
|
+
const plain = withoutManaged(input, TASK_FIELD_GROUPS);
|
|
130
173
|
// 品質基準: 作業先があれば当てはまるものを取り込む(auto)。作業先なしは明示したものだけ。none は取り込まない
|
|
131
174
|
const fromQuality = qualityOpsFor(ctx, repo, quality ?? "auto");
|
|
132
175
|
const ops = [...(criteria ?? []).map((text) => ({ op: "add", text })), ...fromQuality];
|
|
133
|
-
const
|
|
134
|
-
const
|
|
176
|
+
const now = new Date().toISOString();
|
|
177
|
+
const acceptance = ops.length ? applyAcceptanceOps({}, ops, { now, actor }) : {};
|
|
178
|
+
const status = input.status ?? "todo";
|
|
179
|
+
// 完了で作るなら、完了の記録を最初の記録として足す(参照先は書く前に取る)
|
|
180
|
+
const refs = status === "done" ? await captureRefs(ctx.ws.refs()) : undefined;
|
|
181
|
+
const draft = { ...plain, ...acceptance, repo, status };
|
|
182
|
+
const { patch: records } = taskCompletionPatch(ctx, rid, undefined, draft, 1, false, { at: now, by: actor, refs });
|
|
183
|
+
const task = await ctx.ws.tasksOf(rid).create({ ...plain, ...acceptance, repo, status, ...records }, actor);
|
|
135
184
|
const { ancestorWarnings, ...after } = await afterTaskWrite(ctx, rid, task, repo, actor);
|
|
136
185
|
return { task, warnings: ancestorWarnings, ...after };
|
|
137
186
|
}
|
|
@@ -146,7 +195,8 @@ export async function updateTask(ctx, rid, tid, patch, opts = {}) {
|
|
|
146
195
|
const cur = col.require(tid);
|
|
147
196
|
const { checked, acceptance, blockOp, ...rest } = patch;
|
|
148
197
|
// 基準・証拠は操作(acceptance)、停止は操作(blockOp)でだけ変える(値・履歴をそのまま書く道は持たない)
|
|
149
|
-
|
|
198
|
+
// 完了の記録は p3 が作る(値をそのまま書く道は持たない)
|
|
199
|
+
const plain = withoutManaged(rest, TASK_FIELD_GROUPS);
|
|
150
200
|
const next = { ...plain };
|
|
151
201
|
if ("repo" in patch) {
|
|
152
202
|
checkRepoTarget(ctx.ws, patch.repo);
|
|
@@ -161,6 +211,10 @@ export async function updateTask(ctx, rid, tid, patch, opts = {}) {
|
|
|
161
211
|
}
|
|
162
212
|
const warnings = startWarnings(ctx.ws, cur.ref, cur.status, next.status);
|
|
163
213
|
let checkCleared;
|
|
214
|
+
let completionSkipped;
|
|
215
|
+
let reworkSkipped;
|
|
216
|
+
// 完了・済みになりうる更新なら、参照先を書く前に取る(ロックの外。取得時刻を残す)
|
|
217
|
+
const refs = next.status === "done" || checked === true ? await captureRefs(ctx.ws.refs()) : undefined;
|
|
164
218
|
// 停止の操作だけで何も変わらない(同じ内容の付け直し・付いていない解除)なら書かない(rev を上げない)
|
|
165
219
|
const onlyBlock = !!blockOp && !acceptance?.length && Object.keys(next).length === 0;
|
|
166
220
|
let unchanged;
|
|
@@ -177,16 +231,39 @@ export async function updateTask(ctx, rid, tid, patch, opts = {}) {
|
|
|
177
231
|
if (blockTo)
|
|
178
232
|
out = { ...out, ...blockTo };
|
|
179
233
|
checkBlockedStatus(fresh.status, status, blockTo ? blockTo.block : fresh.block, fresh.ref);
|
|
234
|
+
// 書いた後の値で完了の記録を足す(同時に変えた基準・証拠は変えた後の内容を写す)
|
|
235
|
+
const withRecords = (o, contentChanged) => {
|
|
236
|
+
const final = { ...fresh, ...o };
|
|
237
|
+
if (final.status !== "done")
|
|
238
|
+
final.checkedAt = undefined;
|
|
239
|
+
const r = taskCompletionPatch(ctx, rid, fresh, final, fresh.rev + 1, contentChanged, { at: now, by: opts.actor, refs });
|
|
240
|
+
completionSkipped = r.skipped;
|
|
241
|
+
// 手戻り(済みの解除・完了からの再開)。書く直前の値と保存する値で決める
|
|
242
|
+
const rw = reworkOf(fresh, final, { explicitUncheck: checked === false, acceptanceChanged: contentChanged });
|
|
243
|
+
let history = {};
|
|
244
|
+
if (rw) {
|
|
245
|
+
const list = appendRework(fresh, { at: now, ...(opts.actor ? { by: opts.actor } : {}), rev: fresh.rev + 1, ...rw });
|
|
246
|
+
if (list)
|
|
247
|
+
history = { reworkHistory: list };
|
|
248
|
+
else
|
|
249
|
+
reworkSkipped = REWORK_SKIPPED;
|
|
250
|
+
}
|
|
251
|
+
return { ...o, ...r.patch, ...history };
|
|
252
|
+
};
|
|
180
253
|
if (!acceptance?.length)
|
|
181
|
-
return out;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
254
|
+
return withRecords(out, false);
|
|
255
|
+
// 根拠の番号は、保存した番号・今ある記録・完了の記録の写しに残る番号の続き(旧データでも写しに残る番号は使い直さない)
|
|
256
|
+
const changedTo = applyAcceptanceOps(fresh, acceptance, { now, actor: opts.actor, requestSources: ctx.ws.requests.get(rid)?.requirementSources ?? [], sourceSeqFloor: recordedSourceSeq(fresh.completionRecords) });
|
|
257
|
+
if (!acceptanceChanged(fresh, changedTo)) {
|
|
258
|
+
// 中身は同じでも(同じ操作の中で足して消したなど)採番が進んだら、採番だけを書く(済み・完了の記録・手戻りは中身の変化として扱わない)
|
|
259
|
+
const seqOnly = acceptanceSeqChanged(fresh, changedTo) ? { acceptanceSeq: changedTo.acceptanceSeq, acceptanceSourceSeq: changedTo.acceptanceSourceSeq } : {};
|
|
260
|
+
return withRecords({ ...out, ...seqOnly }, false);
|
|
261
|
+
}
|
|
185
262
|
// 済みの後に中身が変わった(同じ操作で済みを付け直すときは外さない)
|
|
186
263
|
const clear = !!fresh.checkedAt && !("checkedAt" in next);
|
|
187
264
|
if (clear)
|
|
188
265
|
checkCleared = CHECK_CLEARED_BY_ACCEPTANCE;
|
|
189
|
-
return { ...out, ...changedTo, ...(clear ? { checkedAt: undefined } : {}) };
|
|
266
|
+
return withRecords({ ...out, ...changedTo, ...(clear ? { checkedAt: undefined } : {}) }, true);
|
|
190
267
|
}, opts);
|
|
191
268
|
const task = await write().catch((e) => {
|
|
192
269
|
if (e instanceof NoChange && unchanged)
|
|
@@ -196,7 +273,7 @@ export async function updateTask(ctx, rid, tid, patch, opts = {}) {
|
|
|
196
273
|
if (unchanged && task === unchanged)
|
|
197
274
|
return { task, warnings };
|
|
198
275
|
const { ancestorWarnings, ...after } = await afterTaskWrite(ctx, rid, task, patch.repo, opts.actor);
|
|
199
|
-
return { task, warnings: [...warnings, ...ancestorWarnings], ...after, ...(checkCleared ? { checkCleared } : {}) };
|
|
276
|
+
return { task, warnings: [...warnings, ...ancestorWarnings], ...after, ...(checkCleared ? { checkCleared } : {}), ...(completionSkipped ? { completionSkipped } : {}), ...(reworkSkipped ? { reworkSkipped } : {}) };
|
|
200
277
|
}
|
|
201
278
|
/** タスクをアーカイブする(.archive/ へ移す。消さない) */
|
|
202
279
|
export async function archiveTask(ctx, rid, tid) {
|
|
@@ -224,23 +301,124 @@ export async function createRequest(ctx, input, actor) {
|
|
|
224
301
|
* 要望を変える。対応済にするのは全タスクが完了のときだけ(requestStatus.ts)。
|
|
225
302
|
* parent を含むなら親の付け替え(undefined で外す)を関係のロックの中で確かめてから書く(hierarchy.ts)
|
|
226
303
|
*/
|
|
227
|
-
export async function updateRequest(ctx, rid,
|
|
304
|
+
export async function updateRequest(ctx, rid, input, opts = {}) {
|
|
305
|
+
// 要求の根拠・回答は操作(updateRequirement・answerClarification)でだけ変える(値をそのまま書く道は持たない)
|
|
306
|
+
// 完了の記録も p3 が作る
|
|
307
|
+
const patch = withoutManaged(input, REQUEST_FIELD_GROUPS);
|
|
228
308
|
checkMilestone(ctx, patch.milestone);
|
|
229
309
|
await checkStatusChange(ctx.ws, rid, patch.status);
|
|
310
|
+
// 対応済・完了済になりうる更新なら、参照先を書く前に取る
|
|
311
|
+
const refs = patch.status === "resolved" || patch.status === "done" ? await captureRefs(ctx.ws.refs()) : undefined;
|
|
312
|
+
let completionSkipped;
|
|
230
313
|
// 状態か親が変わったら、未完了になった配下の分だけ祖先を戻す
|
|
231
314
|
const after = async (r) => (patch.status !== undefined || "parent" in patch ? withAncestors(r, await afterRequestWrite(ctx, r.id, opts.actor)) : r);
|
|
315
|
+
// 題・本文を変えたら、要望の根拠の記録の確認は効かなくなる(書く直前に読み直した値で、履歴へ移す)
|
|
316
|
+
// 対応済・完了済にしたら、書いた後の値で完了の記録を足す(判定に使ったタスクと子の要望を写す)
|
|
317
|
+
const write = () => ctx.ws.requests.update(rid, (fresh) => {
|
|
318
|
+
const p = withSettledSources(fresh, patch);
|
|
319
|
+
const final = { ...fresh, ...p };
|
|
320
|
+
const triggers = requestTriggers(fresh.status, final.status);
|
|
321
|
+
if (!triggers.length)
|
|
322
|
+
return p;
|
|
323
|
+
const at = new Date().toISOString();
|
|
324
|
+
const parts = { tasks: ctx.ws.tasksOf(rid).list(), children: ctx.ws.requests.list().filter((r) => r.parent === rid) };
|
|
325
|
+
const list = appendCompletion(fresh, (id) => requestCompletionRecord(id, triggers[0], final, fresh.rev + 1, parts, completionContext(ctx, at, opts.actor, refs)));
|
|
326
|
+
if (!list) {
|
|
327
|
+
completionSkipped = COMPLETION_SKIPPED;
|
|
328
|
+
return p;
|
|
329
|
+
}
|
|
330
|
+
return { ...p, completionRecords: list };
|
|
331
|
+
}, opts);
|
|
332
|
+
const skipped = (r) => (completionSkipped ? { ...r, completionSkipped } : r);
|
|
232
333
|
if (!("parent" in patch)) {
|
|
233
|
-
const r = await
|
|
334
|
+
const r = await write();
|
|
234
335
|
changed(ctx, "request", r.id);
|
|
235
|
-
return after(r);
|
|
336
|
+
return skipped(await after(r));
|
|
236
337
|
}
|
|
237
|
-
const { result: r, previous } = await withParentChange(ctx.ws, rid, patch.parent,
|
|
338
|
+
const { result: r, previous } = await withParentChange(ctx.ws, rid, patch.parent, write);
|
|
238
339
|
changed(ctx, "request", r.id);
|
|
239
340
|
// 前と今の親の子の一覧も変わる
|
|
240
341
|
for (const p of new Set([previous, r.parent]))
|
|
241
342
|
if (p && p !== r.id)
|
|
242
343
|
changed(ctx, "request", p);
|
|
243
|
-
return after(r);
|
|
344
|
+
return skipped(await after(r));
|
|
345
|
+
}
|
|
346
|
+
/** 題・本文の変更で効かなくなった要望の根拠の確認を履歴へ移した patch(変わらなければ patch のまま) */
|
|
347
|
+
function withSettledSources(fresh, patch) {
|
|
348
|
+
if ((patch.title === undefined && patch.body === undefined) || !fresh.requirementSources?.length || fresh.requirementProblems?.length)
|
|
349
|
+
return patch;
|
|
350
|
+
const subject = requestSubject({ title: patch.title ?? fresh.title, body: patch.body ?? fresh.body });
|
|
351
|
+
const settled = settleSources(fresh.requirementSources, () => subject, new Date().toISOString());
|
|
352
|
+
return sourcesKey(settled) === sourcesKey(fresh.requirementSources) ? patch : { ...patch, requirementSources: settled };
|
|
353
|
+
}
|
|
354
|
+
/** 要望の根拠・回答が読めないときは変えない */
|
|
355
|
+
function checkRequirementReadable(r) {
|
|
356
|
+
if (r.requirementProblems?.length)
|
|
357
|
+
throw new RequirementInputError(`${r.id} の要求の根拠・回答のファイルの値が読めないため変えられません。request.md を直してください: ${r.requirementProblems.join(" / ")}`);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* 要望の要求の根拠の記録を変える(shared/requirementSource.ts の操作。書く直前に読み直した値に当て、規則に合わなければ何も書かない)。
|
|
361
|
+
* 同じ値の再保存では書かない(rev を上げない)。expectedRev で競合を見る
|
|
362
|
+
*/
|
|
363
|
+
export async function updateRequirement(ctx, rid, ops, opts = {}) {
|
|
364
|
+
if (!ops.length)
|
|
365
|
+
throw new RequirementInputError("根拠の記録への操作がありません");
|
|
366
|
+
let unchanged;
|
|
367
|
+
const r = await ctx.ws.requests
|
|
368
|
+
.update(rid, (fresh) => {
|
|
369
|
+
checkRequirementReadable(fresh);
|
|
370
|
+
const before = fresh.requirementSources ?? [];
|
|
371
|
+
const subject = requestSubject(fresh);
|
|
372
|
+
const { list, seq } = applySourceOps(before, ops, { now: new Date().toISOString(), actor: opts.actor, subjectOf: () => subject, seq: fresh.requirementSeq });
|
|
373
|
+
if (sourcesKey(list) === sourcesKey(before) && seq === (fresh.requirementSeq ?? sourceSeq(before))) {
|
|
374
|
+
unchanged = fresh;
|
|
375
|
+
throw new NoChange();
|
|
376
|
+
}
|
|
377
|
+
return { requirementSources: list.length ? list : undefined, requirementSeq: seq > 0 ? seq : undefined };
|
|
378
|
+
}, opts)
|
|
379
|
+
.catch((e) => {
|
|
380
|
+
if (e instanceof NoChange && unchanged)
|
|
381
|
+
return unchanged;
|
|
382
|
+
throw e;
|
|
383
|
+
});
|
|
384
|
+
if (r !== unchanged)
|
|
385
|
+
changed(ctx, "request", rid);
|
|
386
|
+
return r;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Preflight の確認事項に回答する(要望の clarifyAnswers に残す。過去の run と評価は書き換えない)。clarification は元の run の確認事項
|
|
390
|
+
* (呼ぶ側が run から取り出す)。回答しただけでは根拠の記録を確認記録ありにしない。answer が null なら回答を消す
|
|
391
|
+
*/
|
|
392
|
+
export async function saveClarifyAnswer(ctx, rid, runId, q, input, opts = {}) {
|
|
393
|
+
let unchanged;
|
|
394
|
+
let saved;
|
|
395
|
+
const r = await ctx.ws.requests
|
|
396
|
+
.update(rid, (fresh) => {
|
|
397
|
+
checkRequirementReadable(fresh);
|
|
398
|
+
const cur = fresh.clarifyAnswers ?? [];
|
|
399
|
+
if (input === null) {
|
|
400
|
+
if (!cur.some((a) => a.run === runId && a.question === q.id))
|
|
401
|
+
throw new RequirementInputError(`${runId}/${q.id} への回答はありません`);
|
|
402
|
+
const next = cur.filter((a) => !(a.run === runId && a.question === q.id));
|
|
403
|
+
return { clarifyAnswers: next.length ? next : undefined };
|
|
404
|
+
}
|
|
405
|
+
saved = makeAnswer(runId, q, input, fresh.requirementSources ?? [], { now: new Date().toISOString(), actor: opts.actor });
|
|
406
|
+
const next = putAnswer(cur, saved);
|
|
407
|
+
if (answersKey(next) === answersKey(cur)) {
|
|
408
|
+
saved = cur.find((a) => a.run === runId && a.question === q.id);
|
|
409
|
+
unchanged = fresh;
|
|
410
|
+
throw new NoChange();
|
|
411
|
+
}
|
|
412
|
+
return { clarifyAnswers: next };
|
|
413
|
+
}, opts)
|
|
414
|
+
.catch((e) => {
|
|
415
|
+
if (e instanceof NoChange && unchanged)
|
|
416
|
+
return unchanged;
|
|
417
|
+
throw e;
|
|
418
|
+
});
|
|
419
|
+
if (r !== unchanged)
|
|
420
|
+
changed(ctx, "request", rid);
|
|
421
|
+
return { request: r, ...(saved ? { answer: saved } : {}) };
|
|
244
422
|
}
|
|
245
423
|
/**
|
|
246
424
|
* 子の表示順を保存する(親の request.md の childOrder だけを書く。子・タスク・親子の所属は変えない)。ids は今の直下の子の完全な並び。
|
|
@@ -257,3 +435,22 @@ export async function archiveRequest(ctx, rid) {
|
|
|
257
435
|
await withArchiveCheck(ctx.ws, rid, () => ctx.ws.requests.archive(rid));
|
|
258
436
|
changed(ctx, "request", rid);
|
|
259
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* 前提の変更を記録する(外部の規則の変更など。要望の premiseChanges に追記。shared/reviewCandidate.ts)。add: 対象(要望 ID・この要望の
|
|
440
|
+
* タスク ID・要望の根拠の ID)と理由・新しい条件 / ack: 変更を確かめたことを対象と条件の版つきで残す。過去の完了の記録・状態・済み・
|
|
441
|
+
* 基準・証拠は変えない。対象が無い・規則に合わない・rev の競合では何も書かない
|
|
442
|
+
*/
|
|
443
|
+
export async function recordPremise(ctx, rid, op, opts = {}) {
|
|
444
|
+
let change;
|
|
445
|
+
const r = await ctx.ws.requests.update(rid, (fresh) => {
|
|
446
|
+
if (fresh.premiseProblems?.length)
|
|
447
|
+
throw new PremiseInputError(`${rid} の前提の変更の記録が読めないため足せません。request.md を直してください: ${fresh.premiseProblems.join(" / ")}`);
|
|
448
|
+
const tasks = ctx.ws.tasksOf(rid);
|
|
449
|
+
const exists = (t) => t === rid || !!tasks.get(t) || !!fresh.requirementSources?.some((s) => s.id === t);
|
|
450
|
+
const list = applyPremiseOp(fresh.premiseChanges ?? [], op, { now: new Date().toISOString(), actor: opts.actor, exists });
|
|
451
|
+
change = op.op === "add" ? list.at(-1) : list.find((c) => c.id === op.id);
|
|
452
|
+
return { premiseChanges: list };
|
|
453
|
+
}, opts);
|
|
454
|
+
changed(ctx, "request", rid);
|
|
455
|
+
return { request: r, change: change };
|
|
456
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { readdir
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
2
|
import { ownerState, systemProbe } from "./preflight/owner.js";
|
|
3
|
-
import {
|
|
3
|
+
import { readJsonRecord, writeJsonRecord } from "./store/jsonRecord.js";
|
|
4
|
+
import { ChatGptAuthError } from "./chatgpt.js";
|
|
5
|
+
import { CodexUnavailableError, CodexUsageLimitError } from "./preflight/codexEngine.js";
|
|
4
6
|
/**
|
|
5
7
|
* レビューの実行の記録の共通部分(マイルストーンレビュー・タスクの AI レビュー)。比較材料と結果の形は各レビューに残し、ここには
|
|
6
8
|
* 「保存の仕方」と「実行中の run の扱い」だけを置く。
|
|
@@ -27,27 +29,27 @@ export class ReviewCancelRefused extends Error {
|
|
|
27
29
|
this.code = code;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
text = await readFile(path, "utf8");
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
if (e.code === "ENOENT")
|
|
32
|
+
export const writeJson = writeJsonRecord;
|
|
33
|
+
/** run の記録を読む(無ければ not_found、JSON として読めない・形が違えば broken) */
|
|
34
|
+
export function readJson(path, label, check) {
|
|
35
|
+
const broken = (m) => new ReviewStoreError("broken", `レビューの記録を読めません: ${label}(${m})`);
|
|
36
|
+
return readJsonRecord(path, {
|
|
37
|
+
missing: () => {
|
|
40
38
|
throw new ReviewStoreError("not_found", `レビューの記録がありません: ${label}`);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
},
|
|
40
|
+
invalidJson: (m) => {
|
|
41
|
+
throw broken(m);
|
|
42
|
+
},
|
|
43
|
+
shape: (v) => {
|
|
44
|
+
try {
|
|
45
|
+
check(v);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
throw broken(e.message);
|
|
49
|
+
}
|
|
50
|
+
return v;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
51
53
|
}
|
|
52
54
|
/** フォルダの中のフォルダ(無ければ空。シンボリックリンクは含めない) */
|
|
53
55
|
export async function dirs(path) {
|
|
@@ -203,3 +205,106 @@ export class RunControl {
|
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
207
|
}
|
|
208
|
+
/** AI の実行の失敗の分類(レビュー 2 つとリリースノートの要約で共通)。invalid は「結果を読めない」のエラー */
|
|
209
|
+
export function classifyAiFailure(e, invalid) {
|
|
210
|
+
const msg = e?.message ?? String(e);
|
|
211
|
+
const kind = e instanceof CodexUnavailableError || e instanceof ChatGptAuthError ? "unavailable" : e instanceof CodexUsageLimitError ? "usage_limit" : invalid(e) ? "invalid_output" : "error";
|
|
212
|
+
return [kind, msg];
|
|
213
|
+
}
|
|
214
|
+
/** 頼む先を選ぶ(明示 → preflight.engine の設定 → codex)。無ければ reviewer は undefined(各機能が unavailable で断る) */
|
|
215
|
+
export async function pickReviewer(reviewers, explicit, configured) {
|
|
216
|
+
const name = explicit ?? (await configured?.().catch(() => "codex")) ?? "codex";
|
|
217
|
+
return { name, reviewer: reviewers[name] };
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* レビューの実行の骨組み: このプロセスの実行・二重の開始の確かめ・実行(ログ・時間切れ・取り消し・ほかのプロセスの取消の要求・失敗の分類・
|
|
221
|
+
* 遅れた結果の拒否)・回復・取り消し・待つ。材料・依頼文・結果の読み方・終わる前の確かめ(after。材料の変化など)は各レビュー
|
|
222
|
+
*/
|
|
223
|
+
export class ReviewRunner {
|
|
224
|
+
store;
|
|
225
|
+
opts;
|
|
226
|
+
local = new Map();
|
|
227
|
+
control;
|
|
228
|
+
constructor(store, opts) {
|
|
229
|
+
this.store = store;
|
|
230
|
+
this.opts = opts;
|
|
231
|
+
this.control = new RunControl(store, this.local, opts.probe, (_k, r) => opts.emit(r));
|
|
232
|
+
}
|
|
233
|
+
/** キーのロックの中で、実行中の run が無いことを確かめてから create を呼ぶ(あれば busy が返すエラーを投げ、何も作らない) */
|
|
234
|
+
begin(key, create, busy) {
|
|
235
|
+
return this.store.withLock(key, async () => {
|
|
236
|
+
const b = await this.control.runningLocked(key);
|
|
237
|
+
if (b)
|
|
238
|
+
throw busy(b);
|
|
239
|
+
await create();
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/** このプロセスで実行する(終わるのは waitLocal で待つ) */
|
|
243
|
+
launch(key, run, work, classify, after) {
|
|
244
|
+
const abort = new AbortController();
|
|
245
|
+
const job = { key, abort, done: Promise.resolve() };
|
|
246
|
+
this.local.set(run.id, job);
|
|
247
|
+
this.opts.emit(run);
|
|
248
|
+
const exec = async () => {
|
|
249
|
+
const log = [];
|
|
250
|
+
const push = (e) => log.push({ at: new Date().toISOString(), ...e });
|
|
251
|
+
const { timeoutMs } = this.opts;
|
|
252
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
253
|
+
const signal = AbortSignal.any([abort.signal, timeout]);
|
|
254
|
+
// ほかのプロセスからの取消の要求を見つけ、ログを run.json に書き足す
|
|
255
|
+
const stopWatch = this.control.watch(key, run.id, log, abort, this.opts.pollMs ?? 1000);
|
|
256
|
+
let end;
|
|
257
|
+
let result;
|
|
258
|
+
try {
|
|
259
|
+
const r = await work(push, signal);
|
|
260
|
+
if (signal.aborted)
|
|
261
|
+
throw signal.reason;
|
|
262
|
+
result = r.result;
|
|
263
|
+
end = { ...r.end, status: "completed" };
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
const [failure, error] = abort.signal.aborted ? [undefined, "取り消しました"] : timeout.aborted ? ["timeout", `時間切れです(${Math.round(timeoutMs / 1000)} 秒)`] : classify(e);
|
|
267
|
+
end = (abort.signal.aborted ? { status: "cancelled", error } : { status: "failed", failure, error });
|
|
268
|
+
push({ kind: "error", text: error });
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
stopWatch();
|
|
272
|
+
}
|
|
273
|
+
if (after)
|
|
274
|
+
end = await after(end, push);
|
|
275
|
+
// 既に終わっていた(人が中断した・回復した)なら、遅れて届いた結果は取り込まない
|
|
276
|
+
await this.control.end(key, run.id, { ...end, log: [...log] }, result);
|
|
277
|
+
};
|
|
278
|
+
job.done = exec().finally(() => this.local.delete(run.id));
|
|
279
|
+
}
|
|
280
|
+
/** 死んだ所有者の run を回復する(一覧・取得の前に) */
|
|
281
|
+
async recover(key) {
|
|
282
|
+
if (await this.store.hasHistory(key))
|
|
283
|
+
await this.store.withLock(key, () => this.control.recoverLocked(key));
|
|
284
|
+
}
|
|
285
|
+
/** 記録(実行中なら所有者の状態を添える) */
|
|
286
|
+
async get(key, run) {
|
|
287
|
+
await this.recover(key);
|
|
288
|
+
const rec = await this.store.get(key, run);
|
|
289
|
+
return { ...rec, ...(rec.run.status === "running" ? { owner: this.control.ownerOf(rec.run) } : {}) };
|
|
290
|
+
}
|
|
291
|
+
/** 取り消す(このプロセスの run は止め、ほかのプロセスの run は要求を書く。acknowledgeStopped は人が止まっていると確かめた run を記録の上で中断にする) */
|
|
292
|
+
cancel(key, run, by, opts = {}) {
|
|
293
|
+
const local = this.local.get(run);
|
|
294
|
+
return this.control.cancel(key, run, by, { ...opts, label: `${key}/${run}`, abortLocal: () => local?.abort.abort(new Error("cancelled")) });
|
|
295
|
+
}
|
|
296
|
+
async waitLocal(run) {
|
|
297
|
+
await this.local.get(run)?.done;
|
|
298
|
+
}
|
|
299
|
+
running() {
|
|
300
|
+
return this.local.size;
|
|
301
|
+
}
|
|
302
|
+
/** このプロセスの実行が全部終わるまで待つ(cancel: 先に全部を取り消す) */
|
|
303
|
+
async settle(opts = {}) {
|
|
304
|
+
const jobs = [...this.local.values()];
|
|
305
|
+
if (opts.cancel)
|
|
306
|
+
for (const j of jobs)
|
|
307
|
+
j.abort.abort(new Error("cancelled"));
|
|
308
|
+
await Promise.allSettled(jobs.map((j) => j.done));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -3,7 +3,8 @@ import { lstat, mkdir, readdir, readFile, rename, rm, writeFile } from "node:fs/
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { ATTACHMENT_FILE_LIMITS } from "../../shared/types.js";
|
|
5
5
|
import { imageInfo, UI_LIMITS } from "../preflight/uiMaterials.js";
|
|
6
|
-
import { nowIso
|
|
6
|
+
import { nowIso } from "../../../kit/fsutil.js";
|
|
7
|
+
import { writeJsonRecord } from "./jsonRecord.js";
|
|
7
8
|
export const ATTACHMENT_ID = /^A-\d{8}-\d{6}-[0-9a-f]{4}$/;
|
|
8
9
|
/** 上限(1つの要望あたり) */
|
|
9
10
|
export const ATTACHMENT_LIMITS = {
|
|
@@ -235,7 +236,7 @@ export class AttachmentStore {
|
|
|
235
236
|
fixed.push({ ...rest, path });
|
|
236
237
|
}
|
|
237
238
|
if (fixed.length)
|
|
238
|
-
await
|
|
239
|
+
await writeJsonRecord(join(runDir, "attachments.json"), fixed);
|
|
239
240
|
return fixed;
|
|
240
241
|
}
|
|
241
242
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { access, mkdir, readFile, readdir, rename } from "node:fs/promises";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import { parseFrontmatter, stringifyFrontmatter } from "
|
|
4
|
-
import { createExclusive, nowIso, writeFileAtomic } from "
|
|
3
|
+
import { parseFrontmatter, stringifyFrontmatter } from "../../../kit/frontmatter.js";
|
|
4
|
+
import { createExclusive, nowIso, withFileLock, writeFileAtomic } from "../../../kit/fsutil.js";
|
|
5
5
|
export class ConflictError extends Error {
|
|
6
6
|
id;
|
|
7
7
|
expected;
|
|
@@ -20,6 +20,8 @@ export class NotFoundError extends Error {
|
|
|
20
20
|
this.id = id;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
/** ロックを待ちきれなかったときの案内 */
|
|
24
|
+
const LOCK_BUSY = "別のプロセスがこの要望を保存中です。少し待ってやり直してください";
|
|
23
25
|
/**
|
|
24
26
|
* 1エンティティ = 1 Markdown ファイル(YAML frontmatter + 本文)のコレクション。
|
|
25
27
|
* メモリ上にキャッシュし、ファイル変更(人手・AI・Codex・git pull)は reload() で取り込む。
|
|
@@ -168,6 +170,10 @@ export class MarkdownCollection {
|
|
|
168
170
|
}
|
|
169
171
|
/** 作る。省いた項目は normalize の既定値になる */
|
|
170
172
|
async create(input, actor) {
|
|
173
|
+
// タスクは要望のロックの中で作る(要望のアーカイブと重なって、移した後のフォルダに作らない)。要望(ID は新しく作る)は取らない
|
|
174
|
+
return this.locked("", () => this.createUnlocked(input, actor));
|
|
175
|
+
}
|
|
176
|
+
async createUnlocked(input, actor) {
|
|
171
177
|
// アーカイブ済みの ID も使わない(アーカイブしたタスクへの関係が新しいタスクを指さないように)
|
|
172
178
|
const existing = [...new Set([...this.items.keys(), ...(await this.layout.scan()), ...((await this.layout.reserved?.()) ?? [])])];
|
|
173
179
|
// 別のプロセス(CLI・AI)と同時に作っても、排他作成で衝突を検出して次の ID にする
|
|
@@ -203,6 +209,14 @@ export class MarkdownCollection {
|
|
|
203
209
|
* patch に関数を渡すと、直前に読み直した今の値から patch を作る(基準の操作のように、今の値に当てる変更)。関数が投げたら書かない
|
|
204
210
|
*/
|
|
205
211
|
async update(id, patch, opts = {}) {
|
|
212
|
+
return this.locked(id, () => this.updateUnlocked(id, patch, opts));
|
|
213
|
+
}
|
|
214
|
+
/** ロックの中で動かす(ロックを持たないコレクションはそのまま) */
|
|
215
|
+
locked(id, fn) {
|
|
216
|
+
const lock = this.opts.lock?.(id);
|
|
217
|
+
return lock ? withFileLock(lock, fn, { busyMessage: LOCK_BUSY }) : fn();
|
|
218
|
+
}
|
|
219
|
+
async updateUnlocked(id, patch, opts) {
|
|
206
220
|
// 外部での編集を取りこぼさないよう、更新の直前にディスクから読み直す。
|
|
207
221
|
// この版が知らない項目(新しい版の p3 が書いた項目)は消さずに書き戻す(古い版の更新で親子などが消えないように)
|
|
208
222
|
const r = await this.read(id);
|
|
@@ -233,6 +247,11 @@ export class MarkdownCollection {
|
|
|
233
247
|
}
|
|
234
248
|
/** 物理削除はせず .archive/ へ移す */
|
|
235
249
|
async archive(id) {
|
|
250
|
+
return this.locked(id, () => this.archiveUnlocked(id));
|
|
251
|
+
}
|
|
252
|
+
async archiveUnlocked(id) {
|
|
253
|
+
// ロックの中で読み直す(別のプロセスが先に移した・消したなら無い)
|
|
254
|
+
this.apply(id, await this.read(id));
|
|
236
255
|
this.require(id);
|
|
237
256
|
const { from, to } = this.layout.archive(id);
|
|
238
257
|
// 既にアーカイブに同じ ID があれば上書きしない(rename は黙って置き換えるので先に確かめる)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ACCEPTANCE_KEYS, readAcceptance } from "../../features/requirements/shared/acceptance.js";
|
|
2
|
+
import { BLOCK_KEYS, readBlock } from "../../shared/taskBlock.js";
|
|
3
|
+
import { COMPLETION_KEYS, readCompletion } from "../../features/records/shared/completionRecord.js";
|
|
4
|
+
import { PREMISE_KEYS, readPremises } from "../../features/records/shared/reviewCandidate.js";
|
|
5
|
+
import { readRework, REWORK_KEYS } from "../../features/records/shared/reworkHistory.js";
|
|
6
|
+
import { readRequirement, REQUIREMENT_KEYS } from "../../features/requirements/shared/requirementSource.js";
|
|
7
|
+
export const TASK_FIELD_GROUPS = [
|
|
8
|
+
{ name: "受け入れ基準・証拠・基準の根拠", keys: ACCEPTANCE_KEYS, problems: "acceptanceProblems", read: readAcceptance },
|
|
9
|
+
{ name: "停止と履歴", keys: BLOCK_KEYS, problems: "blockProblems", read: readBlock },
|
|
10
|
+
{ name: "完了の記録", keys: COMPLETION_KEYS, problems: "completionProblems", read: readCompletion },
|
|
11
|
+
{ name: "手戻りの履歴", keys: REWORK_KEYS, problems: "reworkProblems", read: readRework },
|
|
12
|
+
];
|
|
13
|
+
export const REQUEST_FIELD_GROUPS = [
|
|
14
|
+
{ name: "要求の根拠・回答", keys: REQUIREMENT_KEYS, problems: "requirementProblems", read: readRequirement },
|
|
15
|
+
{ name: "完了の記録", keys: COMPLETION_KEYS, problems: "completionProblems", read: readCompletion },
|
|
16
|
+
{ name: "前提の変更", keys: PREMISE_KEYS, problems: "premiseProblems", read: readPremises },
|
|
17
|
+
];
|
|
18
|
+
/** まとまりを順に読んだ値(読む順は定義の順。後のまとまりが前の項目を上書きしない) */
|
|
19
|
+
export const readFieldGroups = (groups, d) => Object.assign({}, ...groups.map((g) => g.read(d)));
|
|
20
|
+
/** 元の値のまま書き戻す項目(problems があるまとまりの項目) */
|
|
21
|
+
export const keepRawOf = (groups) => (item) => groups.flatMap((g) => (item[g.problems]?.length ? g.keys : []));
|
|
22
|
+
/** ファイルに書かない項目(problems) */
|
|
23
|
+
export const problemKeysOf = (groups) => [...new Set(groups.map((g) => g.problems))];
|
|
24
|
+
/** CLI・API の入力から外す項目(まとまりの項目と problems。p3 が操作でだけ変える) */
|
|
25
|
+
export const managedKeysOf = (groups) => [...new Set(groups.flatMap((g) => [...g.keys, g.problems]))];
|
|
26
|
+
/** 入力から p3 が管理する項目を外す(値をそのまま書く道を持たない) */
|
|
27
|
+
export function withoutManaged(input, groups) {
|
|
28
|
+
const managed = new Set(managedKeysOf(groups));
|
|
29
|
+
return Object.fromEntries(Object.entries(input).filter(([k]) => !managed.has(k)));
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { writeFileAtomic } from "../../../kit/fsutil.js";
|
|
3
|
+
export async function readJsonRecord(path, policy) {
|
|
4
|
+
let text;
|
|
5
|
+
try {
|
|
6
|
+
text = await readFile(path, "utf8");
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
const err = e;
|
|
10
|
+
if (err.code === "ENOENT")
|
|
11
|
+
return policy.missing();
|
|
12
|
+
if (policy.readFailed)
|
|
13
|
+
return policy.readFailed(err);
|
|
14
|
+
throw e;
|
|
15
|
+
}
|
|
16
|
+
if (text === "" && policy.blank)
|
|
17
|
+
return policy.blank();
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = JSON.parse(text);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return policy.invalidJson(e.message);
|
|
24
|
+
}
|
|
25
|
+
return policy.shape(raw);
|
|
26
|
+
}
|
|
27
|
+
/** 整形した JSON を置き換えで書く(末尾に改行) */
|
|
28
|
+
export async function writeJsonRecord(path, value) {
|
|
29
|
+
await writeFileAtomic(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
30
|
+
}
|