@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.
Files changed (219) hide show
  1. package/README.md +33 -35
  2. package/bin/p3.mjs +3 -2
  3. package/dist/web/assets/CompletionReview-BD7d6Yzt.js +1 -0
  4. package/dist/web/assets/ImprovementDialog-BoAZN1KR.js +1 -0
  5. package/dist/web/assets/Outputs-D-ZouoxF.js +1 -0
  6. package/dist/web/assets/RequestStatus-Bl3fdSbM.js +1 -0
  7. package/dist/web/assets/Tabs-CxeceOL-.js +1 -0
  8. package/dist/web/assets/TagInput-CeAbmGRR.js +1 -0
  9. package/dist/web/assets/TaskDrawer-BCriSnhe.js +6 -0
  10. package/dist/web/assets/_requestId-CZKMe_mC.js +1 -0
  11. package/dist/web/assets/_requestId-Fx4lLkFo.js +1 -0
  12. package/dist/web/assets/appCtx-BdxbkSZa.js +1 -0
  13. package/dist/web/assets/archive-D5IIxcSV.js +1 -0
  14. package/dist/web/assets/board-p6R9KMqd.js +1 -0
  15. package/dist/web/assets/done-BTOF188x.js +1 -0
  16. package/dist/web/assets/draft-BWYpm3PD.js +2 -0
  17. package/dist/web/assets/index-DFbY8NAR.css +2 -0
  18. package/dist/web/assets/index-Dpqi2dcC.js +12 -0
  19. package/dist/web/assets/link-D481whDt.js +1 -0
  20. package/dist/web/assets/metrics-CAzP6V8I.js +1 -0
  21. package/dist/web/assets/new-C65IJJg3.js +1 -0
  22. package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
  23. package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
  24. package/dist/web/assets/preload-helper-_dAYMct_.js +1 -0
  25. package/dist/web/assets/{quality-Pu6EISAM.js → quality-RFd-7k3r.js} +1 -1
  26. package/dist/web/assets/release-notes-Dtif8xsQ.js +5 -0
  27. package/dist/web/assets/requestData-SPc36t8Q.js +1 -0
  28. package/dist/web/assets/routes-DJj8CWuk.js +6 -0
  29. package/dist/web/assets/settings-DKJd7CLe.js +1 -0
  30. package/dist/web/assets/ui-CbEOnPnF.js +1 -0
  31. package/dist/web/assets/workTarget-DavxMs-c.js +30 -0
  32. package/dist/web/index.html +6 -4
  33. package/docs/architecture.md +430 -72
  34. package/docs/chatgpt-sign-in.md +2 -2
  35. package/docs/development.md +141 -64
  36. package/docs/feature-inventory.md +139 -0
  37. package/docs/how-to-use.md +389 -31
  38. package/docs/installation.md +261 -147
  39. package/docs/publishing.md +33 -14
  40. package/docs/refactoring.md +332 -0
  41. package/lib/cli/agentsStatus.js +198 -0
  42. package/lib/cli/guide.js +27 -0
  43. package/lib/cli/guide.md +217 -0
  44. package/lib/cli/help.js +45 -7
  45. package/lib/cli/main.js +58 -207
  46. package/lib/cli/project.js +34 -294
  47. package/lib/core/projectRegistry.js +2 -2
  48. package/lib/kit/appInfo.js +13 -0
  49. package/lib/kit/usage.js +27 -0
  50. package/lib/server/api/projectsRoutes.js +5 -5
  51. package/lib/server/server.js +7 -4
  52. package/lib/{cli → tasks/cli}/args.js +73 -9
  53. package/lib/{cli → tasks/cli}/chatgpt.js +1 -1
  54. package/lib/{cli → tasks/cli}/codex.js +1 -1
  55. package/lib/{cli → tasks/cli}/output.js +12 -2
  56. package/lib/{cli → tasks/cli}/preflightCommands.js +1 -1
  57. package/lib/tasks/cli/readOnly.js +75 -0
  58. package/lib/{cli → tasks/cli}/render.js +1 -1
  59. package/lib/{cli → tasks/cli}/requestCommands.js +24 -7
  60. package/lib/tasks/cli/showView.js +279 -0
  61. package/lib/{cli → tasks/cli}/taskCommands.js +55 -21
  62. package/lib/tasks/cli/tasksCli.js +149 -0
  63. package/lib/{core → tasks/core}/context.js +6 -9
  64. package/lib/tasks/core/errorOutcome.js +125 -0
  65. package/lib/{core → tasks/core}/hierarchy.js +1 -1
  66. package/lib/{core → tasks/core}/ops.js +17 -2
  67. package/lib/{core → tasks/core}/preflight/carryover.js +5 -1
  68. package/lib/{core → tasks/core}/preflight/codexEngine.js +36 -28
  69. package/lib/{core → tasks/core}/preflight/diagnose.js +4 -9
  70. package/lib/{core → tasks/core}/preflight/engine.js +9 -0
  71. package/lib/tasks/core/preflight/hostPaths.js +299 -0
  72. package/lib/{core → tasks/core}/preflight/input.js +33 -5
  73. package/lib/{core → tasks/core}/preflight/instructions.js +19 -2
  74. package/lib/{core → tasks/core}/preflight/mockEngine.js +27 -8
  75. package/lib/{core → tasks/core}/preflight/render.js +22 -3
  76. package/lib/{core → tasks/core}/preflight/service.js +86 -11
  77. package/lib/{core → tasks/core}/preflight/uiRender.js +5 -2
  78. package/lib/{core → tasks/core}/requestOps.js +214 -17
  79. package/lib/{core → tasks/core}/reviewRuns.js +127 -22
  80. package/lib/{core → tasks/core}/store/attachments.js +3 -2
  81. package/lib/{core → tasks/core}/store/collection.js +21 -2
  82. package/lib/tasks/core/store/fieldGroups.js +30 -0
  83. package/lib/tasks/core/store/jsonRecord.js +30 -0
  84. package/lib/{core → tasks/core}/store/normalize.js +15 -10
  85. package/lib/{core → tasks/core}/store/noteStore.js +2 -2
  86. package/lib/{core → tasks/core}/store/preflightStore.js +59 -22
  87. package/lib/{core → tasks/core}/store/projectFile.js +1 -1
  88. package/lib/{core → tasks/core}/store/workspace.js +28 -6
  89. package/lib/{core → tasks/core}/userConfig.js +1 -1
  90. package/lib/{core → tasks/core}/workTargets.js +1 -1
  91. package/lib/tasks/features/metrics/cli/metricsCommands.js +77 -0
  92. package/lib/tasks/features/metrics/core/definitions.js +445 -0
  93. package/lib/tasks/features/metrics/core/index.js +112 -0
  94. package/lib/tasks/features/metrics/core/manual.js +179 -0
  95. package/lib/tasks/features/metrics/server/metricsRoutes.js +8 -0
  96. package/lib/tasks/features/metrics/shared/metrics.js +42 -0
  97. package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/code.js +2 -11
  98. package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/material.js +5 -6
  99. package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/review.js +2 -2
  100. package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/service.js +38 -100
  101. package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/store.js +3 -3
  102. package/lib/{server/api → tasks/features/milestoneReview/server}/milestoneReviewRoutes.js +7 -13
  103. package/lib/{cli → tasks/features/quality/cli}/qualityCommands.js +36 -11
  104. package/lib/{core → tasks/features/quality/core}/qualityImprovement.js +16 -15
  105. package/lib/tasks/features/records/cli/revisitCommands.js +73 -0
  106. package/lib/tasks/features/records/core/completionRefs.js +46 -0
  107. package/lib/tasks/features/records/core/reviewCandidates.js +76 -0
  108. package/lib/tasks/features/records/shared/completionRecord.js +329 -0
  109. package/lib/tasks/features/records/shared/reviewCandidate.js +313 -0
  110. package/lib/tasks/features/records/shared/reworkHistory.js +86 -0
  111. package/lib/{cli → tasks/features/releaseNotes/cli}/releaseNotesCommands.js +7 -7
  112. package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/completeRequests.js +5 -6
  113. package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/generate.js +3 -14
  114. package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/material.js +3 -4
  115. package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/service.js +1 -1
  116. package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/store.js +2 -2
  117. package/lib/{server/api → tasks/features/releaseNotes/server}/releaseNoteRoutes.js +11 -20
  118. package/lib/tasks/features/requirements/cli/requirementCommands.js +289 -0
  119. package/lib/{shared → tasks/features/requirements/shared}/acceptance.js +292 -18
  120. package/lib/tasks/features/requirements/shared/requirementSource.js +635 -0
  121. package/lib/tasks/features/retro/cli/retroCommands.js +106 -0
  122. package/lib/tasks/features/retro/core/retrospective.js +197 -0
  123. package/lib/tasks/features/retro/shared/retrospective.js +286 -0
  124. package/lib/tasks/features/settings/cli/projectSettings.js +245 -0
  125. package/lib/{cli → tasks/features/settings/cli}/userConfig.js +50 -3
  126. package/lib/{core → tasks/features/settings/core}/machineSettingsEdit.js +2 -2
  127. package/lib/{core → tasks/features/settings/core}/repoAdmin.js +3 -3
  128. package/lib/{core → tasks/features/settings/core}/userTheme.js +2 -2
  129. package/lib/{server/api → tasks/features/settings/server}/repoRoutes.js +2 -2
  130. package/lib/{server/api → tasks/features/settings/server}/userThemeRoutes.js +3 -3
  131. package/lib/{cli → tasks/features/taskReview/cli}/taskReviewCommands.js +5 -5
  132. package/lib/{core/taskReview → tasks/features/taskReview/core}/material.js +13 -7
  133. package/lib/{core/taskReview → tasks/features/taskReview/core}/review.js +10 -3
  134. package/lib/{core/taskReview → tasks/features/taskReview/core}/service.js +24 -85
  135. package/lib/{core/taskReview → tasks/features/taskReview/core}/store.js +4 -4
  136. package/lib/{server/api → tasks/features/taskReview/server}/taskReviewRoutes.js +7 -14
  137. package/lib/{server → tasks/server}/api/manifest.js +51 -3
  138. package/lib/{server → tasks/server}/api/routes.js +134 -65
  139. package/lib/tasks/shared/commitRefs.js +10 -0
  140. package/lib/{shared → tasks/shared}/preflightInput.js +1 -1
  141. package/package.json +1 -43
  142. package/skills/p3/SKILL.md +9 -181
  143. package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +0 -1
  144. package/dist/web/assets/Outputs-_nU_p3nu.js +0 -1
  145. package/dist/web/assets/RequestStatus-RG-OVQYY.js +0 -1
  146. package/dist/web/assets/Tabs-ew9i5SKX.js +0 -1
  147. package/dist/web/assets/TagInput-BtlJTF7i.js +0 -1
  148. package/dist/web/assets/TaskDrawer-DW8GyJqI.js +0 -6
  149. package/dist/web/assets/_requestId-6Nb727dD.js +0 -1
  150. package/dist/web/assets/_requestId-BykTgPax.js +0 -1
  151. package/dist/web/assets/appCtx-CxDdXABS.js +0 -1
  152. package/dist/web/assets/archive-Ckh295Xe.js +0 -1
  153. package/dist/web/assets/board-BVAIjK-Y.js +0 -1
  154. package/dist/web/assets/done-BGfA-3MA.js +0 -1
  155. package/dist/web/assets/draft-CfJeyLOl.js +0 -1
  156. package/dist/web/assets/index-CgRU744I.css +0 -2
  157. package/dist/web/assets/index-DacQ0yl4.js +0 -12
  158. package/dist/web/assets/new-DVygWvVc.js +0 -1
  159. package/dist/web/assets/outputs-B6xDsLZf.js +0 -1
  160. package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
  161. package/dist/web/assets/preload-helper-DyCqp21K.js +0 -1
  162. package/dist/web/assets/release-notes-CCpzyiNf.js +0 -5
  163. package/dist/web/assets/requestData-D5vBnuMh.js +0 -1
  164. package/dist/web/assets/routes-Q91zvNc0.js +0 -4
  165. package/dist/web/assets/settings-BzRgcmUm.js +0 -1
  166. package/dist/web/assets/workTarget-C9c57JAO.js +0 -30
  167. package/lib/cli/readOnly.js +0 -38
  168. package/lib/cli/showView.js +0 -166
  169. /package/lib/{core/store → kit}/frontmatter.js +0 -0
  170. /package/lib/{core/store → kit}/fsutil.js +0 -0
  171. /package/lib/{cli → tasks/cli}/format.js +0 -0
  172. /package/lib/{core → tasks/core}/chatgpt.js +0 -0
  173. /package/lib/{core → tasks/core}/machineSettings.js +0 -0
  174. /package/lib/{core → tasks/core}/preflight/codexImage.js +0 -0
  175. /package/lib/{core → tasks/core}/preflight/docker.js +0 -0
  176. /package/lib/{core → tasks/core}/preflight/launch.js +0 -0
  177. /package/lib/{core → tasks/core}/preflight/launcher.mjs +0 -0
  178. /package/lib/{core → tasks/core}/preflight/mock-ui.html +0 -0
  179. /package/lib/{core → tasks/core}/preflight/mock-ui.png +0 -0
  180. /package/lib/{core → tasks/core}/preflight/owner.js +0 -0
  181. /package/lib/{core → tasks/core}/preflight/render-image/Dockerfile +0 -0
  182. /package/lib/{core → tasks/core}/preflight/render-image/fonts-ja.conf +0 -0
  183. /package/lib/{core → tasks/core}/preflight/render-image/render.mjs +0 -0
  184. /package/lib/{core → tasks/core}/preflight/split.js +0 -0
  185. /package/lib/{core → tasks/core}/preflight/uiMaterials.js +0 -0
  186. /package/lib/{core → tasks/core}/preflight/wireframe.js +0 -0
  187. /package/lib/{core → tasks/core}/preflight/xlsx.js +0 -0
  188. /package/lib/{core → tasks/core}/redact.js +0 -0
  189. /package/lib/{core → tasks/core}/repoRefs.js +0 -0
  190. /package/lib/{core → tasks/core}/requestStatus.js +0 -0
  191. /package/lib/{core → tasks/core}/store/archivedTasks.js +0 -0
  192. /package/lib/{core → tasks/core}/store/dataWatcher.js +0 -0
  193. /package/lib/{core → tasks/core}/store/locate.js +0 -0
  194. /package/lib/{core → tasks/core}/supersede.js +0 -0
  195. /package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/mockReviewer.js +0 -0
  196. /package/lib/{shared → tasks/features/milestoneReview/shared}/milestoneReview.js +0 -0
  197. /package/lib/{core → tasks/features/quality/core}/quality.js +0 -0
  198. /package/lib/{shared → tasks/features/quality/shared}/quality.js +0 -0
  199. /package/lib/{shared → tasks/features/quality/shared}/qualityImprovement.js +0 -0
  200. /package/lib/{shared → tasks/features/quality/shared}/qualityTemplates.js +0 -0
  201. /package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/mockSummarizer.js +0 -0
  202. /package/lib/{core/taskReview → tasks/features/taskReview/core}/mockReviewer.js +0 -0
  203. /package/lib/{core/taskReview → tasks/features/taskReview/core}/paths.js +0 -0
  204. /package/lib/{shared → tasks/features/taskReview/shared}/taskReview.js +0 -0
  205. /package/lib/{server → tasks/server}/api/chatgptRoutes.js +0 -0
  206. /package/lib/{server → tasks/server}/api/local.js +0 -0
  207. /package/lib/{shared → tasks/shared}/dates.js +0 -0
  208. /package/lib/{shared → tasks/shared}/directTask.js +0 -0
  209. /package/lib/{shared → tasks/shared}/hierarchy.js +0 -0
  210. /package/lib/{shared → tasks/shared}/milestoneGoals.js +0 -0
  211. /package/lib/{shared → tasks/shared}/milestoneOrder.js +0 -0
  212. /package/lib/{shared → tasks/shared}/preflightRunner.js +0 -0
  213. /package/lib/{shared → tasks/shared}/refs.js +0 -0
  214. /package/lib/{shared → tasks/shared}/repos.js +0 -0
  215. /package/lib/{shared → tasks/shared}/scopeView.js +0 -0
  216. /package/lib/{shared → tasks/shared}/tags.js +0 -0
  217. /package/lib/{shared → tasks/shared}/taskBlock.js +0 -0
  218. /package/lib/{shared → tasks/shared}/types.js +0 -0
  219. /package/lib/{shared → tasks/shared}/workTarget.js +0 -0
@@ -1,114 +1,23 @@
1
- import { execFileSync } from "node:child_process";
2
1
  import { existsSync, readFileSync } from "node:fs";
3
2
  import { appendFile, copyFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
4
- import { homedir, userInfo } from "node:os";
5
- import { basename, dirname, join, relative, resolve } from "node:path";
3
+ import { basename, dirname, join, relative } from "node:path";
6
4
  import { createInterface } from "node:readline/promises";
7
5
  import { fileURLToPath } from "node:url";
8
6
  import YAML from "yaml";
9
- import { REQUEST_ID } from "../shared/refs.js";
10
- import { resolveRequestId } from "../core/ops.js";
11
- import { writeProjectFile, writeRepoEntry } from "../core/store/projectFile.js";
12
- import { repoNameProblem } from "../shared/repos.js";
13
- import { addRepo, checkFolder, RepoAdminError, removeRepo, setLocalRepoPath, updateRepo } from "../core/repoAdmin.js";
14
- import { normalizeProject } from "../core/store/normalize.js";
15
- import { requestWorkstreams } from "../shared/workTarget.js";
16
- import { DEFAULT_PREFLIGHT_RUNNER, isPreflightRunner, PREFLIGHT_RUNNERS, RUNNER_LABEL, runnerView } from "../shared/preflightRunner.js";
17
- import { DATA_DIR_NAME } from "../core/store/locate.js";
18
- import { sortMilestones } from "../shared/milestoneOrder.js";
19
- import { loadUserConfig, PROJECT_NAME, setProjectNode, updateUserConfig, userConfigPath } from "../core/userConfig.js";
20
- /** プロジェクトの初期設定・設定変更、変更者と「今の要望」の判定(CLI) */
21
- export class UsageError extends Error {
22
- }
23
- function git(cwd, ...args) {
24
- try {
25
- return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || undefined;
26
- }
27
- catch {
28
- return undefined;
29
- }
30
- }
31
- /** リポジトリのルート(git のメインの作業ツリー)。git 管理外ならカレント */
32
- export function repoRoot(cwd) {
33
- const common = git(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
34
- if (common?.endsWith("/.git"))
35
- return common.slice(0, -"/.git".length);
36
- return git(cwd, "rev-parse", "--show-toplevel") ?? cwd;
37
- }
38
- /**
39
- * CLI の変更者。明示(--actor / P3_ACTOR。AI は ai:<名前>)→ human:<git の user.name> → OS のユーザー名。
40
- */
41
- export function resolveActor(explicit, cwd) {
42
- if (explicit)
43
- return explicit;
44
- return `human:${git(cwd, "config", "user.name") ?? process.env.USER ?? userInfo().username}`;
45
- }
46
- /** 今いる場所が、どの参照先(リポジトリ・フォルダ)か。参照先の中か、その git のリポジトリの作業ツリーの中なら当たる */
47
- export function locateHere(ctx, cwd) {
48
- const here = resolve(cwd);
49
- const common = git(here, "rev-parse", "--path-format=absolute", "--git-common-dir");
50
- const repos = ctx.ws
51
- .refs()
52
- .filter((r) => r.status === "ok" && r.local)
53
- .filter((r) => {
54
- if (inside(here, r.local))
55
- return true;
56
- // 要望の作業ツリーの中: 参照先と同じ git のリポジトリで、作業ツリーの中の同じ場所(サブフォルダなら同じ相対位置)より下
57
- if (!common)
58
- return false;
59
- const theirs = git(r.local, "rev-parse", "--path-format=absolute", "--git-common-dir");
60
- if (theirs !== common)
61
- return false;
62
- const top = git(here, "rev-parse", "--show-toplevel");
63
- const theirTop = git(r.local, "rev-parse", "--show-toplevel");
64
- return !!top && !!theirTop && inside(here, join(top, relative(theirTop, r.local)));
65
- })
66
- .map((r) => r.name);
67
- const branch = common ? git(here, "symbolic-ref", "--quiet", "--short", "HEAD") : undefined;
68
- return { repos, branch };
69
- }
70
- const inside = (path, dir) => path === dir || path.startsWith(dir.endsWith("/") ? dir : `${dir}/`);
71
- /**
72
- * 今の要望。明示(--req / P3_REQUEST)→ 今いる参照先のブランチ(その参照先の割当だけと照らす)→
73
- * ブランチ名に要望 ID が入っている(detached HEAD などで決まらなければ --req で指定してもらう)。
74
- * パスに要望 ID が入っているだけでは決めない。候補が複数なら --req を案内する。
75
- * AI が要望の作業ツリーで作業していれば、`p3 new "..."` だけでその要望のタスクになる。
76
- */
77
- export function currentRequest(ctx, explicit, cwd) {
78
- if (explicit) {
79
- const id = resolveRequestId(ctx, explicit);
80
- if (!id)
81
- throw new UsageError(`要望が見つかりません: ${explicit}`);
82
- return id;
83
- }
84
- const { repos: hereRepos, branch } = locateHere(ctx, cwd);
85
- const requests = ctx.ws.requests.list();
86
- const pick = (ids, why) => {
87
- const uniq = [...new Set(ids)];
88
- if (uniq.length > 1)
89
- throw new UsageError(`${why}が複数の要望に当たります: ${uniq.join(", ")}。--req <要望ID> で指定してください`);
90
- return uniq[0];
91
- };
92
- if (branch) {
93
- // 今いる参照先の割当だけと照らす(別のリポジトリの同じ名前のブランチと取り違えない)。参照先の外なら全部と照らす
94
- const byBranch = requests
95
- .filter((r) => Object.entries(requestWorkstreams(r)).some(([name, w]) => w.branch === branch && (!hereRepos.length || hereRepos.includes(name))))
96
- .map((r) => r.id);
97
- const hit = pick(byBranch, `ブランチ ${branch} `);
98
- if (hit)
99
- return hit;
100
- }
101
- if (branch) {
102
- const m = new RegExp(REQUEST_ID.source.slice(1, -1)).exec(branch);
103
- if (m && ctx.ws.requests.get(m[0]))
104
- return m[0];
105
- }
106
- return undefined;
107
- }
7
+ import { writeProjectFile, writeRepoEntry } from "../tasks/core/store/projectFile.js";
8
+ import { normalizeProject } from "../tasks/core/store/normalize.js";
9
+ import { repoNameProblem } from "../tasks/shared/repos.js";
10
+ import { DEFAULT_PREFLIGHT_RUNNER, isPreflightRunner, PREFLIGHT_RUNNERS, RUNNER_LABEL } from "../tasks/shared/preflightRunner.js";
11
+ import { DATA_DIR_NAME } from "../tasks/core/store/locate.js";
12
+ import { ENTRY_VERSION } from "./guide.js";
13
+ import { loadUserConfig, PROJECT_NAME, setProjectNode, updateUserConfig, userConfigPath } from "../tasks/core/userConfig.js";
14
+ import { repoRoot, resolvePath, UsageError } from "../kit/usage.js";
15
+ import { splitList } from "../tasks/features/settings/cli/projectSettings.js";
16
+ /** 入口: プロジェクトの初期設定(init)・参加(join)・登録(project)と AI 向けの入口(agents)。設定の変更と今の要望の判定は projectSettings.ts(tasks) */
108
17
  /** init で本体の主なフォルダ(最初に読むもの)の候補にするドキュメントと、フォルダの入口の候補 */
109
18
  const DOC_CANDIDATES = ["docs", "doc", "README.md", "ARCHITECTURE.md", "DESIGN.md", "AGENTS.md", "CLAUDE.md", "CONTRIBUTING.md"];
110
19
  const DOC_ENTRIES = ["README.md", "index.md"];
111
- const AGENTS_MARK = "タスク管理(infodb p3)";
20
+ export const AGENTS_MARK = "タスク管理(infodb p3)";
112
21
  /** AI 向けの使い方を置く先(リポジトリのルートからの相対パス。どれも同じ原本 skills/p3/SKILL.md を写す) */
113
22
  export const AGENT_TARGETS = {
114
23
  claude: { path: ".claude/skills/p3/SKILL.md", agent: "Claude Code" },
@@ -117,10 +26,12 @@ export const AGENT_TARGETS = {
117
26
  /** --agents / p3 agents の選び方(値なしの --agents は both) */
118
27
  export const AGENT_CHOICES = { claude: ["claude"], codex: ["codex"], both: ["claude", "codex"] };
119
28
  export const isAgentChoice = (v) => typeof v === "string" && Object.hasOwn(AGENT_CHOICES, v);
120
- const KINDS = Object.keys(AGENT_TARGETS);
29
+ export const KINDS = Object.keys(AGENT_TARGETS);
30
+ /** 節の入口の版を書く機械可読のコメント(ENTRY_VERSION。見出しの次の行) */
31
+ export const ENTRY_COMMENT = (v) => `<!-- p3-entry-version: ${v} -->`;
121
32
  /**
122
- * AGENTS.md / CLAUDE.md に書く指示(節)。スキルの参照は、置いた先(と既にある先)だけを書く。手順の詳しい版は同梱のスキル
123
- * (skills/p3/SKILL.md)で、役割と終わり方はそちらとそろえる(test/agents.test.ts が確かめる)
33
+ * AGENTS.md / CLAUDE.md に書く指示(節)。入口だけで、手順の本文は CLI(p3 guide)から読ませる。
34
+ * スキルの参照は、置いた先(と既にある先)だけを書く。入口の決まりを変えたら ENTRY_VERSION を上げる(test/agents.test.ts が確かめる)
124
35
  */
125
36
  export function agentsSnippet(kinds) {
126
37
  const list = KINDS.filter((k) => kinds.includes(k));
@@ -128,36 +39,28 @@ export function agentsSnippet(kinds) {
128
39
  return `
129
40
  ## ${AGENTS_MARK}
130
41
 
131
- - 作業の単位は要望。タスクは \`p3\` CLI(入っていなければ \`pnpx @infodb/p3\`)で操作し、\`--json\` で結果を読むこと(データのフォルダを直接編集しない)。
132
- 詳しい手順はスキル ${skills}
133
- - 変更するときは環境変数 \`P3_ACTOR=ai:<エージェント名>\` を付ける
134
- - 操作する要望は \`--req <要望ID>\` で指定する(要望の作業ツリーの中なら省ける)。まず \`p3 whoami --json\` で確かめる(Preflight の担当 \`preflight.runner\` も出る)
135
- - \`whoami\` の \`via\`(プロジェクトの決まり方)が \`cwd\` でなければ(\`dir\` / \`project\` / \`legacy\` / \`only\`)、それ以上 p3 を操作せず、対象のプロジェクトでよいか人に確かめる(推測した \`--project\` / \`--dir\` で避けない。人が指定・確認した後はその対象のまま続ける)
136
- - プロジェクトが無い・未登録のときは \`p3 init\` / \`p3 join\` を自分から実行せず、新しく作る(\`init\`)のか共有されたものに参加する(\`join\`)のかを人に確かめる
137
- - 新しい作業を頼まれたら \`p3 request new "<タイトル>" --body "..."\` で要望を登録し、ID を伝えて終える。
138
- Preflight(\`preflight\`)は自分から始めない(勧めない・尋ねない)。タスク化(\`accept\`)は人が行う(結果を \`p3 drafts\` で読むのと、頼まれたメモの保存 \`--note-only\` はよい)
139
- - Preflight を頼まれたら、担当(\`whoami --json\` の \`preflight.runner\`)で分ける。\`codex\`: 人が \`p3 preflight\` か画面で実行する(AI は \`--prepare\` の無い \`p3 preflight\` をしない)。人がチャットで対象の要望の手元の評価を明示的に頼んだときだけ手元で評価し、「Preflight して」とだけなら、人が実行するのか手元で評価するのかを確かめる。\`agent\`: 人に「Preflight して」と頼まれたら手元で評価する(「このチャットで」は求めない)。\`null\`(読めない): \`agent\` と推測せず \`problem\` を伝え、\`codex\` と同じ扱い。子の要望も同じ。対象の要望が分からなければ確かめる
140
- - 手元の評価: \`p3 preflight <要望ID> --prepare --json\` → 返った指示のファイル(\`instructions\`)を最後まで読み、書くのは返った run の成果物(\`outputs\`)だけ → \`p3 preflight <要望ID> --complete --run <run> --json\` → \`p3 drafts\` の結果を伝えて終える(自分から始めない。タスク化 \`accept\` と着手はしない)
141
- - 着手する前に \`p3 show T003 --brief --json\` で本文・依存とその状態(\`dependencies\`)・置き換えの注意(\`warnings\`)を読む
142
- - 着手する前に、\`--brief --json\` の \`work\`(作業先のリポジトリとブランチ)を見て、そのリポジトリでブランチに入る(作業先なしなら移動しない)
143
- - 着手するときは \`p3 move T003 doing\`。テストを通したら、コミットする前に \`p3 move T003 done --output <今ある成果物(変えたファイルや説明)> --record -\` で完了にする(変更の記録は必須: 何を変えたか・なぜ・入れた決まり・やめたもの を標準入力から Markdown で。まだ無い URL は書かない)
144
- - 受け入れ基準(\`--brief --json\` の \`item.acceptanceCriteria\`)があれば着手する前に読み、完了するときに基準ごとの証拠を \`--evidence-file evidence.md\`(見出し \`## A1 met\` ごとに通したテスト・コマンドと結果・確かめたこと)で残す。\`[Q1]\` で始まる基準はプロジェクトの品質基準で、その検査は自分で実行してコマンド・参照先とコミット(未コミットならそう書く)・結果・範囲を証拠に書く(P3 が実行したとは書かない)。満たせなかった・確かめていない項目は \`unmet\` / \`unverified\` と理由を正直に書き(推測で \`met\` にしない)、未達・未検証を残して完了にしたら人に伝える。証拠は自分の申告で、済みにするかは人が決める。基準を自分で消す・書き換えて満たしたことにしない
145
- - 要望のタスクを全部終えたら、コミットする前に \`p3 request set <要望ID> status=resolved\`(対応済)にする。完了済(done)・見送り(rejected)とタスクの済み(check)は人が決める
146
- - 子の要望(\`parent\` のある要望)は、親とは別の要望として子ごとのタスクとブランチで作業する(親のタスクにしない)。分割の案の採用(\`accept\`)は人が行う。子の Preflight は親と同じ担当で、頼まれたときだけ(分割の採用・子の作成から自分で評価へ進まない)。親を対応済にするのは、親のタスクと見送り以外の子(\`request show <親> --brief --json\` の \`children\`)が全部終わってから
147
- - データのフォルダがこの作業ツリーの中で git 管理されているなら、要望のフォルダ(\`requests/<要望ID>/\`)の変更も実装と同じコミットに入れる(後のレビューで要望とやったことを精査するため。子なら祖先の要望のフォルダ、親を対応済にするときは子孫の要望のフォルダ(見送りの子など)のまだ入っていない変更も入れ、ほかの要望・関係ない変更は入れない。外・無視・worktree のときは入らないので、移動や \`git add -f\` はしない)。push に失敗したら完了の記録は残し、公開できていないことを伝える。要望のフォルダは、マージするまで要望のブランチにしか無い。既定のブランチに切り替えると、その要望(子なら親の子の一覧からも)が消えたように見えるが、データはブランチにある(作り直したり、別のブランチから写したりしない)
148
- - コミットや PR の URL は後から \`p3 move T003 done --output <URL>\` で足す(完了・記録はそのまま。データをコミットしているなら追記もコミットして push)。複数のリポジトリにまたがるときは最後のタスクに \`--repo-output <参照先>=<PR の URL>\` で全部の PR を残す
149
- - タスクの AI レビュー(\`p3 review\`)は頼まれずに始めない(Codex を使う)。結果を理由に済みにしたり基準・証拠を書き換えたりしない
150
- - 置き換えられたタスク(\`p3 ls\` の \`※置換\`、\`--json\` の \`superseded\`)からは始めない。\`move\` が \`warnings\` を返したら止めて人に確かめる
151
- - 人の判断・権限が要る・前提が崩れた・テストが通らず先に進めないなどでタスクを続けられなくなったら、\`p3 block T003 --reason "<具体的な理由>" --decision "<人に決めてほしいこと>" --json\` で止まっている理由を付け(通常の修正・調査の途中では使わない)、JSON の \`block\` で保存できたことを確かめてから、理由・いつから・答えてほしいこと・再開のしかたを人に伝えて作業を終える(止まったまま完了・済み・対応済に進めない。基準や証拠を書き換えない)。回答を受けたら \`p3 unblock T003 --resolution "<回答>"\` で解除して再開する(解除だけでは再開しない。人が先に解除していたら履歴の回答を読んで確かめる)
152
- - 作業中に新しく必要になった作業は \`p3 new "<タイトル>" --body "..."\` でタスクにする(人への質問はタスクにしない)
42
+ ${ENTRY_COMMENT(ENTRY_VERSION)}
43
+
44
+ - このリポジトリの作業は infodb p3 の要望とタスクで管理する。p3 を操作する前に \`pnpx @infodb/p3 guide --json\` を実行し、返った \`guide\`(作業の手順)を最後まで読んで従う(手順は動いている CLI の版のものが返る。ここには写さない)
45
+ - \`guide\` を取得できなければ(コマンドが無い・エラーになる・JSON が読めない)、p3 を操作しない。出たエラーと呼び方(\`pnpx @infodb/p3 guide --json\`)を人に伝えて終える
46
+ - 同じ入口のスキル: ${skills}
153
47
  `;
154
48
  }
155
49
  /** 両方に置いたときの節(docs/architecture.md に載せる例。test/agents.test.ts が同じことを確かめる) */
156
50
  export const AGENTS_SNIPPET = agentsSnippet(KINDS);
157
51
  /**
158
- * 同梱のスキルの原本。置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)
52
+ * 同梱のスキルの原本。置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)。
53
+ * 原本(skills/p3/SKILL.md)は、この CLI のファイルから上へ探す: 配布物では同梱した <パッケージ>/skills、開発のリポジトリでは
54
+ * ルートの skills(packages/p3/src/cli から 4 つ上)。原本は1つだけで、配布物を作るときに写す(scripts/build-cli.mjs)
159
55
  */
160
- export const SKILL_SOURCE = fileURLToPath(new URL("../../skills/p3/SKILL.md", import.meta.url));
56
+ export const SKILL_SOURCE = (() => {
57
+ for (const up of ["../../", "../../../../"]) {
58
+ const p = fileURLToPath(new URL(`${up}skills/p3/SKILL.md`, import.meta.url));
59
+ if (existsSync(p))
60
+ return p;
61
+ }
62
+ return fileURLToPath(new URL("../../skills/p3/SKILL.md", import.meta.url));
63
+ })();
161
64
  /** 2つの文の最初に違う行(1 から) */
162
65
  function firstDiffLine(a, b) {
163
66
  const x = a.split("\n");
@@ -168,7 +71,7 @@ function firstDiffLine(a, b) {
168
71
  return i + 1;
169
72
  }
170
73
  /** 指示の節(見出し「タスク管理(infodb p3)」からその見出しと同じか上の段の次の見出しの前まで。コードの囲みの中は見出しに数えない) */
171
- function findSections(text) {
74
+ export function findSections(text) {
172
75
  const lines = text.split("\n");
173
76
  const heads = [];
174
77
  let fence = false;
@@ -509,167 +412,4 @@ export async function projectCommand(cwd, args, o, current) {
509
412
  }
510
413
  throw new UsageError("p3 project [ls | add <名前> <フォルダ> | rm <名前>]");
511
414
  }
512
- /** 入力されたパス。対話式の入力ではシェルが ~ を展開しないので、ここで展開する */
513
- export const resolvePath = (cwd, p) => resolve(cwd, p === "~" ? homedir() : p.startsWith("~/") ? join(homedir(), p.slice(2)) : p);
514
415
  const slugifyName = (s) => s.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[-._]+|-+$/g, "") || undefined;
515
- const CONFIG_KEYS = ["name", "description", "branchPattern", "instructions", "preflight.runner"];
516
- /** p3 config [set key=value ...] */
517
- export async function config(ws, args) {
518
- if (args[0] === "set") {
519
- const patch = {};
520
- for (const pair of args.slice(1)) {
521
- const eq = pair.indexOf("=");
522
- const key = pair.slice(0, eq);
523
- const value = pair.slice(eq + 1).trim();
524
- if (eq < 1 || !CONFIG_KEYS.includes(key))
525
- throw new UsageError(`設定できるキー: ${CONFIG_KEYS.join(", ")}`);
526
- if (key === "instructions")
527
- patch.preflight = { ...patch.preflight, instructions: value };
528
- else if (key === "preflight.runner") {
529
- if (!isPreflightRunner(value))
530
- throw new UsageError(`preflight.runner は ${PREFLIGHT_RUNNERS.join(" / ")} のどれか: ${value || "(空)"}`);
531
- patch.preflight = { ...patch.preflight, runner: value };
532
- }
533
- else if (key === "branchPattern" && !value.includes("{id}"))
534
- throw new UsageError("branchPattern には {id} を含めてください");
535
- else if (key === "name" && !value)
536
- throw new UsageError(`${key} は空にできません`);
537
- else
538
- patch[key] = value;
539
- }
540
- if (!Object.keys(patch).length)
541
- throw new UsageError("p3 config set キー=値 ...");
542
- const next = await ws.saveProject(patch);
543
- const keys = args.slice(1).map((p) => p.slice(0, p.indexOf("=")));
544
- return { data: next, text: `更新しました: ${keys.join(", ")}` };
545
- }
546
- const p = ws.project;
547
- const text = [
548
- `name ${p.name}`,
549
- `description ${p.description || "(なし)"}`,
550
- `repos ${p.repos.map((r) => r.name).join(", ") || "(なし)"} (p3 repo ls)`,
551
- `milestones ${sortMilestones(p.milestones).map((m) => `${m.id}${m.due ? `(${m.due})` : ""}${m.done ? "[済]" : ""}`).join(", ") || "(なし)"}`,
552
- `branchPattern ${p.branchPattern}`,
553
- `instructions ${p.preflight.instructions || "(なし)"}`,
554
- `preflight.runner ${runnerText(runnerView(p.preflight))}`,
555
- "",
556
- `ファイル: ${join(ws.dataDir, "project.yaml")}`,
557
- ].join("\n");
558
- return { data: { ...p, preflightRunner: runnerView(p.preflight) }, text };
559
- }
560
- /** 担当の表示(config・whoami)。読めない値は理由を出す */
561
- export function runnerText(v) {
562
- if (!v.runner)
563
- return `(読めません)${v.problem}`;
564
- return `${v.runner}(${RUNNER_LABEL[v.runner]}${v.source === "default" ? "。未設定なので既定" : ""})`;
565
- }
566
- function splitList(s) {
567
- return s.split(",").map((x) => x.trim()).filter(Boolean);
568
- }
569
- /**
570
- * p3 repo: Preflight が読む参照先(リポジトリ・フォルダ)。共有の定義(project.yaml の repos)と、このマシンのパス
571
- * (個人設定の projects.<プロジェクト>.repos)を分けて扱う。
572
- *
573
- * ls 一覧(このマシンのパスが無いものは登録の仕方を出す)
574
- * add <名前> [<パス>] [キー=値 ...] 共有の定義を足す(パスを渡せばこのマシンのパスも登録する)
575
- * set <名前> キー=値 ... 共有の定義を変える(role readFirst writable)
576
- * path <名前> <パス> このマシンのパスだけを登録する(ほかの人が足した参照先に)
577
- * rm <名前> [--local] 共有の定義とこのマシンのパスを消す(--local はこのマシンのパスだけ)
578
- */
579
- export async function repoCommand(ws, projectName, cwd, args, o) {
580
- const [sub = "ls", name, ...rest] = args;
581
- const shared = () => ws.project.repos.find((r) => r.name === name);
582
- const usage = "p3 repo [ls | add <名前> [<パス>] [role=… readFirst=true writable=true] | set <名前> キー=値 … | path <名前> <パス> | rm <名前> [--local]]";
583
- const pairs = (list) => {
584
- const patch = {};
585
- for (const pair of list) {
586
- const eq = pair.indexOf("=");
587
- const key = pair.slice(0, eq);
588
- const value = pair.slice(eq + 1).trim();
589
- if (key === "role")
590
- patch.role = value;
591
- else if (key === "readFirst" || key === "writable") {
592
- if (!["true", "false"].includes(value))
593
- throw new UsageError(`${key} は true か false`);
594
- patch[key] = value === "true";
595
- }
596
- else
597
- throw new UsageError(`変えられるキー: role readFirst writable(主なフォルダ map は設定画面か project.yaml で)`);
598
- }
599
- return patch;
600
- };
601
- /** 共通の操作の失敗は使い方の誤りとして出す */
602
- const run = async (f) => {
603
- try {
604
- return await f();
605
- }
606
- catch (e) {
607
- if (e instanceof RepoAdminError)
608
- throw new UsageError(e.message);
609
- throw e;
610
- }
611
- };
612
- const folder = (raw) => resolvePath(cwd, raw);
613
- if (sub === "ls") {
614
- const refs = ws.refs();
615
- const rows = refs.map((r) => ({ ...r, local: r.local ?? null }));
616
- const text = [
617
- ...(!refs.length ? ["(参照先はまだありません。足すときは p3 repo add <名前> <パス> role=…)"] : []),
618
- ...refs.map((r) => {
619
- const flags = [r.readFirst && "最初に読む", r.writable && "作業先候補"].filter(Boolean).join("・");
620
- const where = r.status === "ok" ? r.local : r.status === "unregistered" ? `未登録 → p3 repo path ${r.name} <このマシンのパス>` : `${r.reason}`;
621
- return `${r.name}${r.role ? `(${r.role})` : ""}${flags ? ` [${flags}]` : ""} /workspace/${r.mount}\n ${where}${r.map.length ? `\n 主なフォルダ: ${r.map.map((m) => (m.entry ? `${m.path}(入口 ${m.entry})` : m.path)).join(", ")}` : ""}`;
622
- }),
623
- ].join("\n");
624
- return { data: rows, text };
625
- }
626
- if (!name)
627
- throw new UsageError(usage);
628
- const problem = repoNameProblem(name);
629
- if (problem && sub !== "rm")
630
- throw new UsageError(`参照先の名前: ${problem}`);
631
- if (sub === "add") {
632
- const maybePath = rest[0] && !rest[0].includes("=") ? rest[0] : undefined;
633
- const patch = pairs(maybePath ? rest.slice(1) : rest);
634
- if (shared())
635
- throw new UsageError(`「${name}」は既にあります。変えるときは p3 repo set ${name} キー=値、このマシンのパスは p3 repo path ${name} <パス>`);
636
- const path = maybePath ? folder(maybePath) : undefined;
637
- if (path)
638
- await run(async () => checkFolder(path));
639
- const entry = await run(() => addRepo(ws, name, patch));
640
- if (path)
641
- await run(() => setLocalRepoPath(ws, projectName, name, path));
642
- return {
643
- data: { ...entry, local: path ?? null },
644
- text: `参照先を足しました: ${name}${entry.role ? `(${entry.role})` : ""}${path ? ` → ${path}` : `(このマシンのパスは未登録: p3 repo path ${name} <パス>)`}`,
645
- };
646
- }
647
- if (sub === "set") {
648
- if (!shared())
649
- throw new UsageError(`「${name}」はありません。足すときは p3 repo add ${name} <パス>`);
650
- if (!rest.length)
651
- throw new UsageError("キー=値 を指定してください(role readFirst writable)");
652
- const next = await run(() => updateRepo(ws, name, pairs(rest)));
653
- return { data: next, text: `参照先を変えました: ${name}` };
654
- }
655
- if (sub === "path") {
656
- if (!shared())
657
- throw new UsageError(`「${name}」は共有の参照先にありません(p3 repo ls)。足すときは p3 repo add ${name} <パス>`);
658
- if (!rest[0])
659
- throw new UsageError(`p3 repo path ${name} <このマシンのパス>`);
660
- const path = folder(rest[0]);
661
- await run(() => setLocalRepoPath(ws, projectName, name, path));
662
- return { data: { name, local: path }, text: `このマシンのパスを登録しました: ${name} → ${path}(共有の定義は変えていません)` };
663
- }
664
- if (sub === "rm") {
665
- if (o.local) {
666
- await run(() => setLocalRepoPath(ws, projectName, name, null));
667
- return { data: { name, local: null }, text: `このマシンのパスを外しました: ${name}(共有の定義は残しています。ほかの人には影響しません)` };
668
- }
669
- if (!shared())
670
- throw new UsageError(`「${name}」は共有の参照先にありません。このマシンのパスだけを外すときは --local`);
671
- await run(() => removeRepo(ws, projectName, name));
672
- return { data: { name }, text: `参照先を消しました: ${name}(共有の定義。ほかの人の Preflight でも読まなくなります。ファイルやフォルダは消していません)` };
673
- }
674
- throw new UsageError(usage);
675
- }
@@ -1,7 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { realpath } from "node:fs/promises";
3
- import { openProject } from "./context.js";
4
- import { inspectUserProjects, PROJECT_NAME, userConfigPath } from "./userConfig.js";
3
+ import { openProject } from "../tasks/core/context.js";
4
+ import { inspectUserProjects, PROJECT_NAME, userConfigPath } from "../tasks/core/userConfig.js";
5
5
  /** 開けない(unknown: 登録に無い / changed: 登録世代が違う / duplicate: 同じデータを複数の名前で登録 / unavailable: 開けない) */
6
6
  export class RegistryError extends Error {
7
7
  code;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 動いている p3 の版(Codex に名乗る clientInfo など)。配布の単位(npm の @infodb/p3)の版は入口が知っているので、入口が起動のときに渡す。
3
+ * 製品(tasks など)は自分の package.json を探さずにここを読む(複数パッケージの構成では kit。docs/architecture.md「パッケージの構成」)
4
+ */
5
+ let version = "0.0.0";
6
+ /** 入口が起動のときに一度だけ呼ぶ */
7
+ export function setAppVersion(v) {
8
+ version = v;
9
+ }
10
+ /** 渡されていなければ 0.0.0(テストで部品を直接作ったときなど) */
11
+ export function appVersion() {
12
+ return version;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { homedir } from "node:os";
3
+ import { join, resolve } from "node:path";
4
+ /**
5
+ * CLI の共通の小物(入口と製品のコマンドの両方が使う。複数パッケージの構成では kit に置く候補。docs/architecture.md「パッケージの構成」)
6
+ */
7
+ /** 使い方の誤り(終了コード 1。メッセージだけを出す) */
8
+ export class UsageError extends Error {
9
+ }
10
+ /** 入力されたパス。対話式の入力ではシェルが ~ を展開しないので、ここで展開する */
11
+ export const resolvePath = (cwd, p) => resolve(cwd, p === "~" ? homedir() : p.startsWith("~/") ? join(homedir(), p.slice(2)) : p);
12
+ /** git の出力(失敗・空は undefined) */
13
+ export function git(cwd, ...args) {
14
+ try {
15
+ return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || undefined;
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ }
21
+ /** リポジトリのルート(git のメインの作業ツリー)。git 管理外ならカレント */
22
+ export function repoRoot(cwd) {
23
+ const common = git(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
24
+ if (common?.endsWith("/.git"))
25
+ return common.slice(0, -"/.git".length);
26
+ return git(cwd, "rev-parse", "--show-toplevel") ?? cwd;
27
+ }
@@ -1,10 +1,10 @@
1
1
  import { Hono } from "hono";
2
2
  import { ProjectRegistry, RegistryError } from "../../core/projectRegistry.js";
3
- import { PROJECT_NAME } from "../../core/userConfig.js";
4
- import { chatgptRoutes } from "./chatgptRoutes.js";
5
- import { apiRoutes, eventStream } from "./routes.js";
6
- import { userThemeRoutes, userThemeScriptRoute } from "./userThemeRoutes.js";
7
- import { AI_MANIFEST } from "./manifest.js";
3
+ import { PROJECT_NAME } from "../../tasks/core/userConfig.js";
4
+ import { chatgptRoutes } from "../../tasks/server/api/chatgptRoutes.js";
5
+ import { apiRoutes, eventStream } from "../../tasks/server/api/routes.js";
6
+ import { userThemeRoutes, userThemeScriptRoute } from "../../tasks/features/settings/server/userThemeRoutes.js";
7
+ import { AI_MANIFEST } from "../../tasks/server/api/manifest.js";
8
8
  /** 変える操作に添える登録世代のヘッダー(GET でも添えれば、違うときは断る) */
9
9
  export const GENERATION_HEADER = "x-p3-project-generation";
10
10
  const STATUS = { unknown: 404, changed: 409, duplicate: 409, unavailable: 503 };
@@ -3,12 +3,15 @@ import { serveStatic } from "@hono/node-server/serve-static";
3
3
  import { Hono } from "hono";
4
4
  import { existsSync } from "node:fs";
5
5
  import { relative } from "node:path";
6
- import { apiRoutes } from "./api/routes.js";
6
+ import { fileURLToPath } from "node:url";
7
+ import { apiRoutes } from "../tasks/server/api/routes.js";
7
8
  import { projectsRoutes } from "./api/projectsRoutes.js";
8
- import { chatgptAccount } from "../core/chatgpt.js";
9
- import { openProject, P3_ROOT } from "../core/context.js";
10
- import { machineSettingsSource } from "../core/machineSettings.js";
9
+ import { chatgptAccount } from "../tasks/core/chatgpt.js";
10
+ import { openProject } from "../tasks/core/context.js";
11
+ import { machineSettingsSource } from "../tasks/core/machineSettings.js";
11
12
  import { ProjectRegistry } from "../core/projectRegistry.js";
13
+ /** p3 本体(配布するパッケージ)のルート。画面のビルド(dist/web)を探す(src/server・lib/server のどちらからも2つ上) */
14
+ const P3_ROOT = fileURLToPath(new URL("../../", import.meta.url));
12
15
  /** 1つのプロジェクトの API(通常の serve)。/api の下 */
13
16
  export function singleProjectApp(ctx) {
14
17
  const app = new Hono();
@@ -3,11 +3,11 @@ import { readFile } from "node:fs/promises";
3
3
  import { basename, resolve as resolvePath } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
5
  import { ATTACHMENT_LIMITS, AttachmentError, inspectAttachment } from "../core/store/attachments.js";
6
- import { parseEvidenceArg, parseEvidenceFile } from "../shared/acceptance.js";
6
+ import { cleanBasis, EVIDENCE_BASIS_KINDS, isEvidenceBasisKind, parseEvidenceArg, parseEvidenceFile, parseEvidenceJson } from "../features/requirements/shared/acceptance.js";
7
7
  import { TASK_STATUSES, isTaskStatus } from "../shared/types.js";
8
8
  import {} from "../core/context.js";
9
9
  import { repoArg } from "../core/workTargets.js";
10
- import { UsageError } from "./project.js";
10
+ import { UsageError } from "../../kit/usage.js";
11
11
  import { Output } from "./output.js";
12
12
  /** CLI の入力の解釈(オプション・キー=値・本文・添付のファイル)と、コマンドに渡すもの(CommandEnv) */
13
13
  const OPTIONS = {
@@ -41,6 +41,9 @@ const OPTIONS = {
41
41
  criterion: { type: "string", multiple: true },
42
42
  evidence: { type: "string", multiple: true },
43
43
  "evidence-file": { type: "string" },
44
+ "evidence-json": { type: "string" },
45
+ basis: { type: "string" },
46
+ "check-result": { type: "string" },
44
47
  target: { type: "string", multiple: true },
45
48
  reason: { type: "string" },
46
49
  text: { type: "string" },
@@ -55,6 +58,11 @@ const OPTIONS = {
55
58
  decision: { type: "string" },
56
59
  resolution: { type: "string" },
57
60
  blocked: { type: "boolean" },
61
+ review: { type: "boolean" },
62
+ condition: { type: "string" },
63
+ state: { type: "string" },
64
+ facts: { type: "string" },
65
+ scope: { type: "string" },
58
66
  viewpoint: { type: "string" },
59
67
  preview: { type: "boolean" },
60
68
  note: { type: "string" },
@@ -63,7 +71,8 @@ const OPTIONS = {
63
71
  only: { type: "string" },
64
72
  skip: { type: "string" },
65
73
  name: { type: "string" },
66
- repo: { type: "string" },
74
+ // 繰り返せるのは MULTI_REPO_COMMANDS だけ(ほかは checkRepeatedRepo が断る。後勝ちで黙って成功させない)
75
+ repo: { type: "string", multiple: true },
67
76
  description: { type: "string" },
68
77
  instructions: { type: "string" },
69
78
  "preflight-runner": { type: "string" },
@@ -91,8 +100,34 @@ const OPTIONS = {
91
100
  version: { type: "string" },
92
101
  file: { type: "string" },
93
102
  "based-on": { type: "string" },
103
+ // 要求の根拠と確認事項への回答(p3 source / clarify / answer)
104
+ by: { type: "string" },
105
+ on: { type: "string" },
106
+ from: { type: "string" },
107
+ to: { type: "string" },
108
+ unit: { type: "string" },
109
+ grounds: { type: "string" },
110
+ link: { type: "string", multiple: true },
111
+ "sources-json": { type: "string" },
112
+ "answer-json": { type: "string" },
94
113
  };
95
- export const parse = (argv) => parseArgs({ args: joinValues(argv), options: OPTIONS, allowPositionals: true });
114
+ /**
115
+ * 引数を読む。--repo は全部を repos に、1つだけのときは repo にも入れる(繰り返したときの repo は undefined。
116
+ * 繰り返してよいかは checkRepeatedRepo で確かめる)
117
+ */
118
+ export function parse(argv) {
119
+ const { values, positionals } = parseArgs({ args: joinValues(argv), options: OPTIONS, allowPositionals: true });
120
+ const { repo: repos, ...rest } = values;
121
+ return { positionals, values: { ...rest, repos, repo: repos?.length === 1 ? repos[0] : undefined } };
122
+ }
123
+ /** --repo を繰り返して複数の参照先を渡せるコマンド(品質基準の対象。ほかは作業先などの1つだけを取る) */
124
+ const MULTI_REPO_COMMANDS = new Set(["quality"]);
125
+ /** --repo を繰り返せないコマンドで繰り返したら断る(最後の1つだけで黙って成功させない) */
126
+ export function checkRepeatedRepo(cmd, o) {
127
+ if ((o.repos?.length ?? 0) > 1 && !MULTI_REPO_COMMANDS.has(cmd)) {
128
+ throw new UsageError(`p3 ${cmd} の --repo は1つだけ指定できます(指定: ${o.repos.join(", ")})。--repo を繰り返して複数の参照先を指定できるのは p3 quality add / set だけです`);
129
+ }
130
+ }
96
131
  /** `--body "- 箇条書き"` のように値が - で始まっても受け取れるよう、`--body=...` の形にまとめる */
97
132
  function joinValues(argv) {
98
133
  const out = [];
@@ -170,15 +205,21 @@ export function date(v) {
170
205
  return v;
171
206
  }
172
207
  /**
173
- * set / move の証拠の入力(--evidence <ID>=<結果>[:本文] を繰り返す / --evidence-file <Markdown>|-)を操作にする。
174
- * --evidence-file - と --record - は同じ標準入力を取り合うので一緒には使えない
208
+ * set / move / evidence の証拠の入力を操作にする:
209
+ * --evidence <ID>=<結果>[:本文] を繰り返す(根拠は省いた扱い)/ --evidence-file <Markdown>|-(同じ)/ --evidence-json <JSON>|-(根拠つき)
210
+ * --evidence-file と --evidence-json は一緒に使えない。- は標準入力で、--record - / --body - とは取り合うので一緒に使えない
175
211
  */
176
212
  export function evidenceOps(o) {
177
213
  const ops = (o.evidence ?? []).map(parseEvidenceArg);
178
- const file = o["evidence-file"];
214
+ const md = o["evidence-file"];
215
+ const json = o["evidence-json"];
216
+ if (md !== undefined && json !== undefined)
217
+ throw new UsageError("--evidence-file(Markdown)と --evidence-json(JSON)はどちらか一方です");
218
+ const file = md ?? json;
179
219
  if (file !== undefined) {
220
+ const flag = md !== undefined ? "--evidence-file" : "--evidence-json";
180
221
  if (file === "-" && (o.record === "-" || o.body === "-"))
181
- throw new UsageError("標準入力(-)は --evidence-file と --record / --body のどちらか一方だけに使えます(もう一方はファイルか文字で渡してください)");
222
+ throw new UsageError(`標準入力(-)は ${flag} と --record / --body のどちらか一方だけに使えます(もう一方はファイルか文字で渡してください)`);
182
223
  let src;
183
224
  try {
184
225
  src = file === "-" ? readFileSync(0, "utf8") : readFileSync(resolvePath(process.cwd(), file), "utf8");
@@ -186,13 +227,36 @@ export function evidenceOps(o) {
186
227
  catch {
187
228
  throw new UsageError(`証拠のファイルが読めません: ${file}`);
188
229
  }
189
- ops.push(...parseEvidenceFile(src));
230
+ ops.push(...(md !== undefined ? parseEvidenceFile(src) : parseEvidenceJson(src)));
190
231
  }
191
232
  const dup = ops.map((x) => (x.op === "record" ? x.id : "")).find((id, i, a) => id && a.indexOf(id) !== i);
192
233
  if (dup)
193
234
  throw new UsageError(`${dup} の証拠が2回指定されています`);
194
235
  return ops;
195
236
  }
237
+ /**
238
+ * evidence <タスク> <ID> <結果> の根拠(--basis 種類 と、read は --reference、machine は --command・--check-result・--target)。
239
+ * 省けば undefined(根拠を省いた扱い)。種類に合わない項目・種類なしの項目は断る(黙って捨てない)
240
+ */
241
+ export function basisFromOptions(o) {
242
+ const given = { reference: o.reference, command: o.command, result: o["check-result"], target: o.target?.length ? o.target : undefined };
243
+ const names = { reference: "--reference", command: "--command", result: "--check-result", target: "--target" };
244
+ const present = Object.keys(given).filter((k) => given[k] !== undefined);
245
+ if (o.basis === undefined) {
246
+ if (present.length)
247
+ throw new UsageError(`${present.map((k) => names[k]).join("・")} を使うときは --basis(${EVIDENCE_BASIS_KINDS.join("|")})も指定してください`);
248
+ return undefined;
249
+ }
250
+ if (!isEvidenceBasisKind(o.basis))
251
+ throw new UsageError(`--basis は ${EVIDENCE_BASIS_KINDS.join(" / ")} のどれかです: ${o.basis}`);
252
+ const allowed = { unverified: [], declaration: [], read: ["reference"], machine: ["command", "result", "target"] };
253
+ const extra = present.filter((k) => !allowed[o.basis].includes(k));
254
+ if (extra.length)
255
+ throw new UsageError(`--basis ${o.basis} には ${extra.map((k) => names[k]).join("・")} を使いません`);
256
+ if ((given.target?.length ?? 0) > 1)
257
+ throw new UsageError("--target は1つだけ指定できます");
258
+ return cleanBasis({ kind: o.basis, reference: given.reference, command: given.command, result: given.result, target: given.target?.[0] });
259
+ }
196
260
  export function readBody(v) {
197
261
  if (v === undefined)
198
262
  return "";
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { createInterface } from "node:readline";
3
3
  import { chatgptAccount, signInFailure } from "../core/chatgpt.js";
4
- import { UsageError } from "./project.js";
4
+ import { UsageError } from "../../kit/usage.js";
5
5
  /**
6
6
  * p3 chatgpt login | status | logout。プロジェクトを決める前に動く(どのプロジェクトにも属さない、このマシンの接続)。
7
7
  * 設計: docs/chatgpt-sign-in.md