@infodb/p3 0.3.0 → 0.5.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/bin/p3.mjs +11 -5
- package/dist/web/assets/Outputs-C83ZDXvs.js +1 -0
- package/dist/web/assets/RequestStatus-GmiWYEcL.js +1 -0
- package/dist/web/assets/Tabs-CJn0Qy7W.js +1 -0
- package/dist/web/assets/TagInput-CtM8HM8Z.js +1 -0
- package/dist/web/assets/TaskDrawer-D5v36QoF.js +3 -0
- package/dist/web/assets/_requestId-BHUqLO-j.js +1 -0
- package/dist/web/assets/_requestId-DxwxbXY2.js +30 -0
- package/dist/web/assets/{ui-Sz7y5_TS.js → appCtx-B-VRVOyv.js} +1 -1
- package/dist/web/assets/board-DAaVR04x.js +1 -0
- package/dist/web/assets/copy-CKsXEjMi.js +1 -0
- package/dist/web/assets/done-CaqB_qTH.js +1 -0
- package/dist/web/assets/index-BF1xMdJo.css +2 -0
- package/dist/web/assets/index-BQYvKpjF.js +12 -0
- package/dist/web/assets/milestoneOrder-N7b5XFJP.js +1 -0
- package/dist/web/assets/new-DLVnRvrB.js +1 -0
- package/dist/web/assets/preflightInput-BAeEJYUK.js +2 -0
- package/dist/web/assets/preload-helper-B74h5i3O.js +1 -0
- package/dist/web/assets/progressTree-wp9mH4VF.js +1 -0
- package/dist/web/assets/release-notes-MTLcOcvZ.js +3 -0
- package/dist/web/assets/requestData-D-HXu-cy.js +1 -0
- package/dist/web/assets/routes-CI4Qfkjs.js +3 -0
- package/dist/web/assets/settings-CJMNgzi6.js +1 -0
- package/dist/web/index.html +4 -4
- package/docs/architecture.md +238 -9
- package/docs/development.md +16 -9
- package/docs/how-to-use.md +128 -12
- package/docs/installation.md +8 -6
- package/docs/publishing.md +4 -2
- package/lib/cli/args.js +172 -0
- package/lib/cli/chatgpt.js +70 -0
- package/lib/cli/codex.js +30 -0
- package/lib/cli/format.js +9 -0
- package/{src/cli/help.ts → lib/cli/help.js} +11 -8
- package/lib/cli/main.js +326 -0
- package/lib/cli/output.js +110 -0
- package/lib/cli/preflightCommands.js +301 -0
- package/lib/cli/project.js +649 -0
- package/lib/cli/readOnly.js +36 -0
- package/lib/cli/releaseNotesCommands.js +197 -0
- package/lib/cli/render.js +58 -0
- package/lib/cli/requestCommands.js +180 -0
- package/lib/cli/showView.js +100 -0
- package/lib/cli/taskCommands.js +152 -0
- package/lib/cli/userConfig.js +64 -0
- package/{src/core/chatgpt.ts → lib/core/chatgpt.js} +10 -16
- package/lib/core/context.js +41 -0
- package/lib/core/hierarchy.js +128 -0
- package/lib/core/machineSettings.js +146 -0
- package/lib/core/machineSettingsEdit.js +148 -0
- package/lib/core/ops.js +120 -0
- package/lib/core/preflight/carryover.js +105 -0
- package/lib/core/preflight/codexEngine.js +687 -0
- package/lib/core/preflight/codexImage.js +61 -0
- package/lib/core/preflight/diagnose.js +95 -0
- package/lib/core/preflight/engine.js +58 -0
- package/lib/core/preflight/input.js +83 -0
- package/lib/core/preflight/launch.js +68 -0
- package/lib/core/preflight/mockEngine.js +175 -0
- package/lib/core/preflight/render.js +304 -0
- package/lib/core/preflight/service.js +868 -0
- package/lib/core/preflight/split.js +83 -0
- package/lib/core/preflight/uiMaterials.js +281 -0
- package/lib/core/preflight/uiRender.js +89 -0
- package/lib/core/preflight/wireframe.js +63 -0
- package/lib/core/preflight/xlsx.js +324 -0
- package/lib/core/projectRegistry.js +207 -0
- package/lib/core/redact.js +28 -0
- package/lib/core/releaseNotes/completeRequests.js +106 -0
- package/lib/core/releaseNotes/generate.js +266 -0
- package/lib/core/releaseNotes/material.js +141 -0
- package/lib/core/releaseNotes/mockSummarizer.js +26 -0
- package/lib/core/releaseNotes/service.js +83 -0
- package/lib/core/releaseNotes/store.js +209 -0
- package/lib/core/repoAdmin.js +82 -0
- package/lib/core/repoRefs.js +72 -0
- package/lib/core/requestOps.js +154 -0
- package/lib/core/requestStatus.js +171 -0
- package/lib/core/store/attachments.js +242 -0
- package/lib/core/store/collection.js +254 -0
- package/lib/core/store/frontmatter.js +18 -0
- package/lib/core/store/fsutil.js +84 -0
- package/lib/core/store/locate.js +162 -0
- package/lib/core/store/normalize.js +150 -0
- package/lib/core/store/noteStore.js +59 -0
- package/lib/core/store/preflightStore.js +161 -0
- package/lib/core/store/projectFile.js +99 -0
- package/lib/core/store/workspace.js +320 -0
- package/lib/core/supersede.js +69 -0
- package/lib/core/userConfig.js +158 -0
- package/{src/core/userTheme.ts → lib/core/userTheme.js} +11 -13
- package/lib/core/workTargets.js +106 -0
- package/lib/server/api/chatgptRoutes.js +46 -0
- package/{src/server/api/local.ts → lib/server/api/local.js} +23 -22
- package/lib/server/api/manifest.js +140 -0
- package/lib/server/api/projectsRoutes.js +82 -0
- package/lib/server/api/releaseNoteRoutes.js +88 -0
- package/lib/server/api/repoRoutes.js +67 -0
- package/lib/server/api/routes.js +404 -0
- package/lib/server/api/userThemeRoutes.js +60 -0
- package/lib/server/server.js +85 -0
- package/lib/shared/dates.js +10 -0
- package/{src/shared/directTask.ts → lib/shared/directTask.js} +3 -11
- package/lib/shared/hierarchy.js +120 -0
- package/lib/shared/milestoneOrder.js +45 -0
- package/lib/shared/preflightInput.js +19 -0
- package/lib/shared/refs.js +44 -0
- package/lib/shared/repos.js +69 -0
- package/lib/shared/scopeView.js +39 -0
- package/{src/shared/tags.ts → lib/shared/tags.js} +9 -14
- package/lib/shared/types.js +74 -0
- package/lib/shared/workTarget.js +31 -0
- package/package.json +4 -7
- package/skills/p3/SKILL.md +29 -8
- package/dist/web/assets/Outputs-DqJdybkd.js +0 -1
- package/dist/web/assets/RequestStatus-DN-2iAM0.js +0 -1
- package/dist/web/assets/TagInput-D-1ILLDX.js +0 -1
- package/dist/web/assets/TaskDrawer-CHD7T-Su.js +0 -3
- package/dist/web/assets/_requestId-BzSepQIV.js +0 -30
- package/dist/web/assets/_requestId-pIds2tFU.js +0 -1
- package/dist/web/assets/board-BIkOpuC4.js +0 -1
- package/dist/web/assets/copy-B1ZbihKL.js +0 -2
- package/dist/web/assets/done-BUAUhIRr.js +0 -1
- package/dist/web/assets/index-Byv9j77D.js +0 -12
- package/dist/web/assets/index-DTfUhuQw.css +0 -2
- package/dist/web/assets/new-6kly4-PX.js +0 -1
- package/dist/web/assets/preload-helper-DlN0ouRj.js +0 -1
- package/dist/web/assets/release-notes-iwQWmfX6.js +0 -3
- package/dist/web/assets/requestData-DJ1Rlx-u.js +0 -1
- package/dist/web/assets/routes-Ciot9p4x.js +0 -2
- package/dist/web/assets/settings-DBCi6lAY.js +0 -1
- package/src/cli/args.ts +0 -186
- package/src/cli/chatgpt.ts +0 -74
- package/src/cli/codex.ts +0 -28
- package/src/cli/format.ts +0 -9
- package/src/cli/main.ts +0 -336
- package/src/cli/output.ts +0 -117
- package/src/cli/preflightCommands.ts +0 -245
- package/src/cli/project.ts +0 -672
- package/src/cli/readOnly.ts +0 -36
- package/src/cli/releaseNotesCommands.ts +0 -159
- package/src/cli/render.ts +0 -60
- package/src/cli/requestCommands.ts +0 -170
- package/src/cli/showView.ts +0 -110
- package/src/cli/taskCommands.ts +0 -167
- package/src/cli/userConfig.ts +0 -58
- package/src/core/context.ts +0 -58
- package/src/core/machineSettings.ts +0 -207
- package/src/core/machineSettingsEdit.ts +0 -156
- package/src/core/ops.ts +0 -114
- package/src/core/preflight/carryover.ts +0 -133
- package/src/core/preflight/codexEngine.ts +0 -703
- package/src/core/preflight/codexImage.ts +0 -98
- package/src/core/preflight/diagnose.ts +0 -124
- package/src/core/preflight/engine.ts +0 -92
- package/src/core/preflight/input.ts +0 -65
- package/src/core/preflight/launch.ts +0 -86
- package/src/core/preflight/mockEngine.ts +0 -145
- package/src/core/preflight/render.ts +0 -339
- package/src/core/preflight/service.ts +0 -707
- package/src/core/preflight/uiMaterials.ts +0 -272
- package/src/core/preflight/uiRender.ts +0 -84
- package/src/core/preflight/wireframe.ts +0 -69
- package/src/core/preflight/xlsx.ts +0 -328
- package/src/core/projectRegistry.ts +0 -264
- package/src/core/redact.ts +0 -31
- package/src/core/releaseNotes/generate.ts +0 -283
- package/src/core/releaseNotes/material.ts +0 -114
- package/src/core/releaseNotes/mockSummarizer.ts +0 -28
- package/src/core/releaseNotes/service.ts +0 -106
- package/src/core/releaseNotes/store.ts +0 -216
- package/src/core/repoAdmin.ts +0 -81
- package/src/core/repoRefs.ts +0 -90
- package/src/core/requestOps.ts +0 -140
- package/src/core/requestStatus.ts +0 -58
- package/src/core/store/attachments.ts +0 -228
- package/src/core/store/collection.ts +0 -282
- package/src/core/store/frontmatter.ts +0 -22
- package/src/core/store/fsutil.ts +0 -90
- package/src/core/store/locate.ts +0 -181
- package/src/core/store/normalize.ts +0 -155
- package/src/core/store/noteStore.ts +0 -56
- package/src/core/store/preflightStore.ts +0 -136
- package/src/core/store/projectFile.ts +0 -101
- package/src/core/store/workspace.ts +0 -328
- package/src/core/supersede.ts +0 -74
- package/src/core/userConfig.ts +0 -205
- package/src/core/workTargets.ts +0 -120
- package/src/server/api/chatgptRoutes.ts +0 -49
- package/src/server/api/manifest.ts +0 -128
- package/src/server/api/projectsRoutes.ts +0 -89
- package/src/server/api/releaseNoteRoutes.ts +0 -78
- package/src/server/api/repoRoutes.ts +0 -67
- package/src/server/api/routes.ts +0 -382
- package/src/server/api/userThemeRoutes.ts +0 -62
- package/src/server/server.ts +0 -108
- package/src/shared/dates.ts +0 -12
- package/src/shared/preflightInput.ts +0 -27
- package/src/shared/refs.ts +0 -55
- package/src/shared/repos.ts +0 -113
- package/src/shared/scopeView.ts +0 -48
- package/src/shared/types.ts +0 -700
- package/src/shared/workTarget.ts +0 -44
- /package/{src → lib}/core/preflight/launcher.mjs +0 -0
- /package/{src → lib}/core/preflight/mock-ui.html +0 -0
- /package/{src → lib}/core/preflight/mock-ui.png +0 -0
- /package/{src → lib}/core/preflight/render-image/Dockerfile +0 -0
- /package/{src → lib}/core/preflight/render-image/fonts-ja.conf +0 -0
- /package/{src → lib}/core/preflight/render-image/render.mjs +0 -0
package/src/cli/project.ts
DELETED
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
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";
|
|
6
|
-
import { createInterface } from "node:readline/promises";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import YAML from "yaml";
|
|
9
|
-
import { REQUEST_ID } from "../shared/refs.ts";
|
|
10
|
-
import type { ProjectConfig } from "../shared/types.ts";
|
|
11
|
-
import type { P3Context } from "../core/context.ts";
|
|
12
|
-
import { resolveRequestId } from "../core/ops.ts";
|
|
13
|
-
import { writeProjectFile, writeRepoEntry } from "../core/store/projectFile.ts";
|
|
14
|
-
import { repoNameProblem } from "../shared/repos.ts";
|
|
15
|
-
import { addRepo, checkFolder, RepoAdminError, removeRepo, setLocalRepoPath, updateRepo, type RepoPatch } from "../core/repoAdmin.ts";
|
|
16
|
-
import { normalizeProject } from "../core/store/normalize.ts";
|
|
17
|
-
import { requestWorkstreams } from "../shared/workTarget.ts";
|
|
18
|
-
import type { Workspace } from "../core/store/workspace.ts";
|
|
19
|
-
import { DATA_DIR_NAME } from "../core/store/locate.ts";
|
|
20
|
-
import { loadUserConfig, PROJECT_NAME, setProjectNode, updateUserConfig, userConfigPath } from "../core/userConfig.ts";
|
|
21
|
-
|
|
22
|
-
/** プロジェクトの初期設定・設定変更、変更者と「今の要望」の判定(CLI) */
|
|
23
|
-
|
|
24
|
-
export class UsageError extends Error {}
|
|
25
|
-
|
|
26
|
-
function git(cwd: string, ...args: string[]): string | undefined {
|
|
27
|
-
try {
|
|
28
|
-
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || undefined;
|
|
29
|
-
} catch {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** リポジトリのルート(git のメインの作業ツリー)。git 管理外ならカレント */
|
|
35
|
-
export function repoRoot(cwd: string): string {
|
|
36
|
-
const common = git(cwd, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
37
|
-
if (common?.endsWith("/.git")) return common.slice(0, -"/.git".length);
|
|
38
|
-
return git(cwd, "rev-parse", "--show-toplevel") ?? cwd;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* CLI の変更者。明示(--actor / P3_ACTOR。AI は ai:<名前>)→ human:<git の user.name> → OS のユーザー名。
|
|
43
|
-
*/
|
|
44
|
-
export function resolveActor(explicit: string | undefined, cwd: string): string {
|
|
45
|
-
if (explicit) return explicit;
|
|
46
|
-
return `human:${git(cwd, "config", "user.name") ?? process.env.USER ?? userInfo().username}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** 今いる場所が、どの参照先(リポジトリ・フォルダ)か。参照先の中か、その git のリポジトリの作業ツリーの中なら当たる */
|
|
50
|
-
export function locateHere(ctx: P3Context, cwd: string): { repos: string[]; branch?: string } {
|
|
51
|
-
const here = resolve(cwd);
|
|
52
|
-
const common = git(here, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
53
|
-
const repos = ctx.ws
|
|
54
|
-
.refs()
|
|
55
|
-
.filter((r) => r.status === "ok" && r.local)
|
|
56
|
-
.filter((r) => {
|
|
57
|
-
if (inside(here, r.local!)) return true;
|
|
58
|
-
// 要望の作業ツリーの中: 参照先と同じ git のリポジトリで、作業ツリーの中の同じ場所(サブフォルダなら同じ相対位置)より下
|
|
59
|
-
if (!common) return false;
|
|
60
|
-
const theirs = git(r.local!, "rev-parse", "--path-format=absolute", "--git-common-dir");
|
|
61
|
-
if (theirs !== common) 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
|
-
|
|
71
|
-
const inside = (path: string, dir: string) => path === dir || path.startsWith(dir.endsWith("/") ? dir : `${dir}/`);
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 今の要望。明示(--req / P3_REQUEST)→ 今いる参照先のブランチ(その参照先の割当だけと照らす)→
|
|
75
|
-
* ブランチ名に要望 ID が入っている(detached HEAD などで決まらなければ --req で指定してもらう)。
|
|
76
|
-
* パスに要望 ID が入っているだけでは決めない。候補が複数なら --req を案内する。
|
|
77
|
-
* AI が要望の作業ツリーで作業していれば、`p3 new "..."` だけでその要望のタスクになる。
|
|
78
|
-
*/
|
|
79
|
-
export function currentRequest(ctx: P3Context, explicit: string | undefined, cwd: string): string | undefined {
|
|
80
|
-
if (explicit) {
|
|
81
|
-
const id = resolveRequestId(ctx, explicit);
|
|
82
|
-
if (!id) throw new UsageError(`要望が見つかりません: ${explicit}`);
|
|
83
|
-
return id;
|
|
84
|
-
}
|
|
85
|
-
const { repos: hereRepos, branch } = locateHere(ctx, cwd);
|
|
86
|
-
const requests = ctx.ws.requests.list();
|
|
87
|
-
const pick = (ids: string[], why: string) => {
|
|
88
|
-
const uniq = [...new Set(ids)];
|
|
89
|
-
if (uniq.length > 1) 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) return hit;
|
|
99
|
-
}
|
|
100
|
-
if (branch) {
|
|
101
|
-
const m = new RegExp(REQUEST_ID.source.slice(1, -1)).exec(branch);
|
|
102
|
-
if (m && ctx.ws.requests.get(m[0])) return m[0];
|
|
103
|
-
}
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** init で本体の主なフォルダ(最初に読むもの)の候補にするドキュメントと、フォルダの入口の候補 */
|
|
108
|
-
const DOC_CANDIDATES = ["docs", "doc", "README.md", "ARCHITECTURE.md", "DESIGN.md", "AGENTS.md", "CLAUDE.md", "CONTRIBUTING.md"];
|
|
109
|
-
const DOC_ENTRIES = ["README.md", "index.md"];
|
|
110
|
-
|
|
111
|
-
const AGENTS_MARK = "タスク管理(infodb p3)";
|
|
112
|
-
|
|
113
|
-
/** AI 向けの使い方を置く先(リポジトリのルートからの相対パス。どれも同じ原本 skills/p3/SKILL.md を写す) */
|
|
114
|
-
export const AGENT_TARGETS = {
|
|
115
|
-
claude: { path: ".claude/skills/p3/SKILL.md", agent: "Claude Code" },
|
|
116
|
-
codex: { path: ".agents/skills/p3/SKILL.md", agent: "Codex" },
|
|
117
|
-
} as const;
|
|
118
|
-
export type AgentKind = keyof typeof AGENT_TARGETS;
|
|
119
|
-
/** --agents / p3 agents の選び方(値なしの --agents は both) */
|
|
120
|
-
export const AGENT_CHOICES = { claude: ["claude"], codex: ["codex"], both: ["claude", "codex"] } as const satisfies Record<string, readonly AgentKind[]>;
|
|
121
|
-
export type AgentChoice = keyof typeof AGENT_CHOICES;
|
|
122
|
-
export const isAgentChoice = (v: unknown): v is AgentChoice => typeof v === "string" && Object.hasOwn(AGENT_CHOICES, v);
|
|
123
|
-
const KINDS = Object.keys(AGENT_TARGETS) as AgentKind[];
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* AGENTS.md / CLAUDE.md に書く指示(節)。スキルの参照は、置いた先(と既にある先)だけを書く。手順の詳しい版は同梱のスキル
|
|
127
|
-
* (skills/p3/SKILL.md)で、役割と終わり方はそちらとそろえる(test/agents.test.ts が確かめる)
|
|
128
|
-
*/
|
|
129
|
-
export function agentsSnippet(kinds: readonly AgentKind[]): string {
|
|
130
|
-
const list = KINDS.filter((k) => kinds.includes(k));
|
|
131
|
-
const skills = list.map((k) => `\`${AGENT_TARGETS[k].path}\`(${AGENT_TARGETS[k].agent})`).join("・") + (list.length > 1 ? "。中身は同じ" : "");
|
|
132
|
-
return `
|
|
133
|
-
## ${AGENTS_MARK}
|
|
134
|
-
|
|
135
|
-
- 作業の単位は要望。タスクは \`p3\` CLI(入っていなければ \`pnpx @infodb/p3\`)で操作し、\`--json\` で結果を読むこと(データのフォルダを直接編集しない)。
|
|
136
|
-
詳しい手順はスキル ${skills}
|
|
137
|
-
- 変更するときは環境変数 \`P3_ACTOR=ai:<エージェント名>\` を付ける
|
|
138
|
-
- 操作する要望は \`--req <要望ID>\` で指定する(要望の作業ツリーの中なら省ける)。まず \`p3 whoami --json\` で確かめる
|
|
139
|
-
- \`whoami\` の \`via\`(プロジェクトの決まり方)が \`cwd\` でなければ(\`dir\` / \`project\` / \`legacy\` / \`only\`)、それ以上 p3 を操作せず、対象のプロジェクトでよいか人に確かめる(推測した \`--project\` / \`--dir\` で避けない。人が指定・確認した後はその対象のまま続ける)
|
|
140
|
-
- プロジェクトが無い・未登録のときは \`p3 init\` / \`p3 join\` を自分から実行せず、新しく作る(\`init\`)のか共有されたものに参加する(\`join\`)のかを人に確かめる
|
|
141
|
-
- 新しい作業を頼まれたら \`p3 request new "<タイトル>" --body "..."\` で要望を登録し、ID を伝えて終える。
|
|
142
|
-
Preflight(\`preflight\`)とタスク化(\`accept\`)は人が行う(AI は実行しない。結果を \`p3 drafts\` で読むのと、頼まれたメモの保存 \`--note-only\` はよい)
|
|
143
|
-
- 着手する前に \`p3 show T003 --brief --json\` で本文・依存とその状態(\`dependencies\`)・置き換えの注意(\`warnings\`)を読む
|
|
144
|
-
- 着手する前に、\`--brief --json\` の \`work\`(作業先のリポジトリとブランチ)を見て、そのリポジトリでブランチに入る(作業先なしなら移動しない)
|
|
145
|
-
- 着手するときは \`p3 move T003 doing\`、終えたら \`p3 move T003 done --output <PR の URL など> --record -\`(変更の記録は必須: 何を変えたか・なぜ・入れた決まり・やめたもの を標準入力から Markdown で)。複数のリポジトリにまたがるときは最後のタスクに \`--repo-output <参照先>=<PR の URL>\` で全部の PR を残す
|
|
146
|
-
- 要望のタスクを全部終えたら \`p3 request set <要望ID> status=resolved\`(対応済)にする。完了済(done)・見送り(rejected)とタスクの済み(check)は人が決める
|
|
147
|
-
- 置き換えられたタスク(\`p3 ls\` の \`※置換\`、\`--json\` の \`superseded\`)からは始めない。\`move\` が \`warnings\` を返したら止めて人に確かめる
|
|
148
|
-
- 作業中に新しく必要になった作業は \`p3 new "<タイトル>" --body "..."\` でタスクにする(人への質問はタスクにしない)
|
|
149
|
-
`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** 両方に置いたときの節(docs/architecture.md に載せる例。test/agents.test.ts が同じことを確かめる) */
|
|
153
|
-
export const AGENTS_SNIPPET = agentsSnippet(KINDS);
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 同梱のスキルの原本。置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)
|
|
157
|
-
*/
|
|
158
|
-
export const SKILL_SOURCE = fileURLToPath(new URL("../../skills/p3/SKILL.md", import.meta.url));
|
|
159
|
-
|
|
160
|
-
/** 2つの文の最初に違う行(1 から) */
|
|
161
|
-
function firstDiffLine(a: string, b: string): number {
|
|
162
|
-
const x = a.split("\n");
|
|
163
|
-
const y = b.split("\n");
|
|
164
|
-
let i = 0;
|
|
165
|
-
while (i < x.length && i < y.length && x[i] === y[i]) i++;
|
|
166
|
-
return i + 1;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** 指示の節(見出し「タスク管理(infodb p3)」からその見出しと同じか上の段の次の見出しの前まで。コードの囲みの中は見出しに数えない) */
|
|
170
|
-
function findSections(text: string): { start: number; end: number; level: number }[] {
|
|
171
|
-
const lines = text.split("\n");
|
|
172
|
-
const heads: { line: number; level: number; mark: boolean }[] = [];
|
|
173
|
-
let fence = false;
|
|
174
|
-
lines.forEach((l, i) => {
|
|
175
|
-
if (/^\s*(```|~~~)/.test(l)) fence = !fence;
|
|
176
|
-
const m = fence ? null : /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(l);
|
|
177
|
-
if (m) heads.push({ line: i, level: m[1].length, mark: m[2] === AGENTS_MARK });
|
|
178
|
-
});
|
|
179
|
-
return heads
|
|
180
|
-
.filter((h) => h.mark)
|
|
181
|
-
.map((h) => ({ start: h.line, level: h.level, end: heads.find((n) => n.line > h.line && n.level <= h.level)?.line ?? lines.length }));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* AI 向けの使い方を置く(init --agents と p3 agents)。kinds の先だけを扱い、ほかの先は作らず・変えず・消さない。
|
|
186
|
-
* - スキル: 無ければ置く・同じなら何もしない・違えば上書きせず違う行と最新にする方法を出す(force なら同梱の版にする)
|
|
187
|
-
* - 指示: AGENTS.md(無ければ CLAUDE.md、どちらも無ければ AGENTS.md を作る)の節。スキルの参照は kinds と既にある先。
|
|
188
|
-
* 節が無ければ足す・同じなら何もしない・違えば変えずに知らせる(force なら節だけを置き換え、前後の文は残す)。
|
|
189
|
-
* 節が複数・見出しの形が分からないときは force でも変えず、手で整理するよう知らせる
|
|
190
|
-
*/
|
|
191
|
-
export async function placeAgents(root: string, cwd: string, choice: AgentChoice, force = false): Promise<string[]> {
|
|
192
|
-
const kinds: readonly AgentKind[] = AGENT_CHOICES[choice];
|
|
193
|
-
const lines: string[] = [];
|
|
194
|
-
const update = `p3 agents ${choice} --force`;
|
|
195
|
-
const source = readFileSync(SKILL_SOURCE, "utf8");
|
|
196
|
-
for (const k of kinds) {
|
|
197
|
-
const t = AGENT_TARGETS[k];
|
|
198
|
-
const skill = join(root, t.path);
|
|
199
|
-
const shown = relative(cwd, skill) || skill;
|
|
200
|
-
if (!existsSync(skill)) {
|
|
201
|
-
await mkdir(dirname(skill), { recursive: true });
|
|
202
|
-
await copyFile(SKILL_SOURCE, skill);
|
|
203
|
-
lines.push(` 作成 AI 向けのスキル(${t.agent})を ${shown} に置きました`);
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
const now = readFileSync(skill, "utf8");
|
|
207
|
-
if (now === source) lines.push(` 同一 AI 向けのスキル(${t.agent})${shown} は最新です`);
|
|
208
|
-
else if (force) {
|
|
209
|
-
await copyFile(SKILL_SOURCE, skill);
|
|
210
|
-
lines.push(` 更新 AI 向けのスキル(${t.agent})${shown} を同梱の版にしました`);
|
|
211
|
-
} else {
|
|
212
|
-
lines.push(` 保護 ※ ${shown}(${t.agent})は既にあり、同梱の版と違うので上書きしません(${firstDiffLine(now, source)} 行目から違います)。最新にするなら ${update}(原本: ${SKILL_SOURCE})`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// 指示の節のスキルの参照: 置いた先と、既にある先(後から片方を足したとき、もう片方も指す。無い先は書かない)
|
|
217
|
-
const refs = KINDS.filter((k) => kinds.includes(k) || existsSync(join(root, AGENT_TARGETS[k].path)));
|
|
218
|
-
const snippet = agentsSnippet(refs);
|
|
219
|
-
const file = ["AGENTS.md", "CLAUDE.md"].find((f) => existsSync(join(root, f))) ?? "AGENTS.md";
|
|
220
|
-
const target = join(root, file);
|
|
221
|
-
const shown = relative(cwd, target) || target;
|
|
222
|
-
const text = existsSync(target) ? readFileSync(target, "utf8") : "";
|
|
223
|
-
const sections = findSections(text);
|
|
224
|
-
if (!sections.length && !text.includes(AGENTS_MARK)) {
|
|
225
|
-
await appendFile(target, text ? snippet : snippet.replace(/^\n/, ""));
|
|
226
|
-
lines.push(` 作成 AI 向けの使い方を ${shown} に${text ? "追記しました" : "書きました"}`);
|
|
227
|
-
} else if (sections.length !== 1) {
|
|
228
|
-
lines.push(
|
|
229
|
-
` 保護 ※ ${shown} の「${AGENTS_MARK}」の節が${sections.length ? `${sections.length} つあります` : "見出しとして見つかりません"}。どこまでが p3 の節か決められないので変えません。手で1つの節(見出し「## ${AGENTS_MARK}」)に整理してから、もう一度実行してください`,
|
|
230
|
-
);
|
|
231
|
-
} else {
|
|
232
|
-
const all = text.split("\n");
|
|
233
|
-
const { start, end, level } = sections[0];
|
|
234
|
-
// 見出しの段は今のもの(### などで書かれていればそのまま)
|
|
235
|
-
const body = snippet.replace(/^\n/, "").replace(/^## /, `${"#".repeat(level)} `);
|
|
236
|
-
const current = all.slice(start, end).join("\n");
|
|
237
|
-
if (current.trim() === body.trim()) lines.push(` 同一 AI 向けの使い方(${shown} の節)は最新です`);
|
|
238
|
-
else if (force) {
|
|
239
|
-
const before = all.slice(0, start).join("\n");
|
|
240
|
-
const after = all.slice(end).join("\n");
|
|
241
|
-
await writeFile(target, `${before}${before ? "\n" : ""}${body.trimEnd()}\n${after ? `\n${after.replace(/^\n+/, "")}` : ""}`);
|
|
242
|
-
lines.push(` 更新 AI 向けの使い方(${shown} の「${AGENTS_MARK}」の節)を置き換えました(前後の文はそのまま)`);
|
|
243
|
-
} else {
|
|
244
|
-
lines.push(` 保護 ※ ${shown} の「${AGENTS_MARK}」の節は同梱の版と違うので変えません。最新にするなら ${update}(節だけを置き換えます)`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return lines;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export interface InitOptions {
|
|
251
|
-
cwd: string;
|
|
252
|
-
/** 個人設定に登録する名前(既定: リポジトリのフォルダ名) */
|
|
253
|
-
project?: string;
|
|
254
|
-
/** データを置くフォルダ(既定はリポジトリのルートの .p3。端末では聞く)。相対パスは実行した場所から */
|
|
255
|
-
dir?: string;
|
|
256
|
-
name?: string;
|
|
257
|
-
description?: string;
|
|
258
|
-
instructions?: string;
|
|
259
|
-
/** AI 向けの使い方を置く先(未指定なら、対話では聞き(Enter は置かない)、非対話では置かない) */
|
|
260
|
-
agents?: AgentChoice;
|
|
261
|
-
yes?: boolean;
|
|
262
|
-
/** このリポジトリの参照先の名前(既定はフォルダ名) */
|
|
263
|
-
repoName?: string;
|
|
264
|
-
/** 対話の問い(既定は端末の readline。テストが答えを渡す)。渡すと対話として聞く */
|
|
265
|
-
prompt?: (question: string) => Promise<string>;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** 対話の問い(--yes・非対話なら既定値のまま)。使い終えたら close */
|
|
269
|
-
function prompter(o: { yes?: boolean; prompt?: (q: string) => Promise<string> }) {
|
|
270
|
-
const interactive = !o.yes && (!!o.prompt || (process.stdin.isTTY && process.stdout.isTTY));
|
|
271
|
-
const rl = interactive && !o.prompt ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
272
|
-
const question = o.prompt ?? (rl ? (q: string) => rl.question(q) : undefined);
|
|
273
|
-
const ask = async (q: string, def: string) => {
|
|
274
|
-
if (!question) return def;
|
|
275
|
-
const a = (await question(`${q}${def ? ` [${def}]` : ""}: `)).trim();
|
|
276
|
-
return a || def;
|
|
277
|
-
};
|
|
278
|
-
return { interactive: !!question, ask, close: () => rl?.close() };
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/** プロジェクト名とデータのフォルダ(init・join で同じ決め方。未指定はルートの .p3、指定は相対なら実行した場所から・~・絶対) */
|
|
282
|
-
async function projectAndDir(o: { cwd: string; project?: string; dir?: string }, root: string, ask: (q: string, def: string) => Promise<string>, dirQuestion: string) {
|
|
283
|
-
const key = await ask("プロジェクト名(切り替えに使う短い名前)", o.project ?? slugifyName(basename(root)) ?? "project");
|
|
284
|
-
if (!PROJECT_NAME.test(key)) throw new UsageError(`プロジェクト名は英数字と . _ - で: ${key}`);
|
|
285
|
-
// 明示した空のパスは未指定と分けて断る
|
|
286
|
-
if (o.dir !== undefined && !o.dir.trim()) throw new UsageError("--dir が空です。既定(リポジトリのルートの .p3)にするなら --dir を付けずに実行してください");
|
|
287
|
-
const dir = resolvePath(o.cwd, o.dir ?? (await ask(dirQuestion, join(root, DATA_DIR_NAME))));
|
|
288
|
-
return { key, dir };
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/** --dir の案内(既定の場所なら付けない) */
|
|
292
|
-
const dirHint = (dir: string, root: string) => (dir === join(root, DATA_DIR_NAME) ? "" : ` --dir ${dir}`);
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* p3 init。管理したいリポジトリの中で実行し、新しくプロジェクトを作る(作るだけ。既にあるプロジェクトへの参加は p3 join)。
|
|
296
|
-
* - データを置くフォルダに project.yaml と requests/ を作る。既定はリポジトリのルート(git のメインの作業ツリー。
|
|
297
|
-
* git 管理外なら実行した場所)の .p3。サブフォルダや追加の作業ツリーから実行してもルートの .p3 にする。
|
|
298
|
-
* 公開できないデータや、リポジトリと別に管理したいときは --dir でリポジトリの外を指せる
|
|
299
|
-
* - そのフォルダに既に project.yaml があれば、何も書かずに断って p3 join を案内する(--agents を付けても置かない)
|
|
300
|
-
* - 個人設定に「プロジェクト名 → フォルダ・手元のリポジトリ」を登録する。以後はリポジトリの中なら指定が要らない
|
|
301
|
-
* 端末から実行すると対話式で聞き、--yes か非対話(AI・スクリプト)なら引数と推測した既定値で作る。
|
|
302
|
-
*/
|
|
303
|
-
export async function init(o: InitOptions): Promise<string> {
|
|
304
|
-
const root = repoRoot(o.cwd);
|
|
305
|
-
const user = await loadUserConfig();
|
|
306
|
-
const { interactive, ask, close } = prompter(o);
|
|
307
|
-
|
|
308
|
-
try {
|
|
309
|
-
if (interactive) console.log(`p3 のプロジェクトを作ります(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
|
|
310
|
-
const { key, dir } = await projectAndDir(o, root, ask, "データを置くフォルダ(相対パスは今いる場所から。リポジトリの外も指定できます)");
|
|
311
|
-
|
|
312
|
-
// 既にあるプロジェクト: 作らず、何も書かない(参加は join、AI 向けの使い方は agents)
|
|
313
|
-
if (existsSync(join(dir, "project.yaml"))) {
|
|
314
|
-
throw new UsageError(
|
|
315
|
-
[
|
|
316
|
-
`${dir} には既にプロジェクトがあります(init は新しく作るだけです。何も変えていません)`,
|
|
317
|
-
` 参加するなら: p3 join --project ${key}${dirHint(dir, root)}`,
|
|
318
|
-
...(o.agents ? [" AI 向けの使い方を置く・最新にするなら: p3 agents claude|codex|both"] : []),
|
|
319
|
-
].join("\n"),
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
const registered = user.projects[key];
|
|
323
|
-
if (registered && registered.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${registered.dir}`);
|
|
324
|
-
const refName = o.repoName ?? slugifyName(basename(root)) ?? "app";
|
|
325
|
-
if (repoNameProblem(refName)) throw new UsageError(`参照先の名前: ${repoNameProblem(refName)}(--repo-name で指定してください)`);
|
|
326
|
-
|
|
327
|
-
// 既定値: git とリポジトリの中身から推測する
|
|
328
|
-
const docsFound = DOC_CANDIDATES.filter((d) => existsSync(join(root, d)));
|
|
329
|
-
const name = o.name ?? key;
|
|
330
|
-
const description = await ask("何を作っているプロジェクトか(Preflight の前提になります)", o.description ?? "");
|
|
331
|
-
// ドキュメントは本体(最初に読む)の主なフォルダにする。Preflight は評価の前に必要な範囲で読む。
|
|
332
|
-
// フォルダの入口は、その中に README.md / index.md があればそれ(任意)
|
|
333
|
-
const docs = splitList(await ask("最初に読むドキュメント(カンマ区切り。Preflight が評価の前に読みます)", docsFound.join(", ")));
|
|
334
|
-
const map = docs.map((d) => {
|
|
335
|
-
const entry = DOC_ENTRIES.map((e) => `${d}/${e}`).find((e) => existsSync(join(root, e)));
|
|
336
|
-
return { path: d, role: "ドキュメント", ...(entry ? { entry } : {}) };
|
|
337
|
-
});
|
|
338
|
-
const instructions = await ask("Preflight で重視する観点・制約(任意)", o.instructions ?? "");
|
|
339
|
-
// 既にある AGENTS.md / CLAUDE.md からは推測しない(Enter は置かない)
|
|
340
|
-
let agents = o.agents;
|
|
341
|
-
if (agents === undefined && interactive) {
|
|
342
|
-
const a = await ask("AI 向けの p3 の使い方(スキルと AGENTS.md / CLAUDE.md の節)を置く先(置かない / claude / codex / both)", "置かない");
|
|
343
|
-
if (!["置かない", "none", "n", "no"].includes(a)) {
|
|
344
|
-
if (!isAgentChoice(a)) throw new UsageError(`置く先は 置かない / claude / codex / both のどれか: ${a}`);
|
|
345
|
-
agents = a;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const cfg: ProjectConfig = {
|
|
350
|
-
name,
|
|
351
|
-
description,
|
|
352
|
-
// このリポジトリを本体の参照先にする(このマシンのパスは個人設定に持ち、共有するデータには書かない)
|
|
353
|
-
repos: [{ name: refName, role: "本体", readFirst: true, writable: true, map }],
|
|
354
|
-
milestones: [],
|
|
355
|
-
branchPattern: "req/{id}-{slug}",
|
|
356
|
-
preflight: { instructions },
|
|
357
|
-
};
|
|
358
|
-
await mkdir(join(dir, "requests"), { recursive: true });
|
|
359
|
-
await writeProjectFile(join(dir, "project.yaml"), cfg);
|
|
360
|
-
await writeRepoEntry(join(dir, "project.yaml"), refName, cfg.repos[0]);
|
|
361
|
-
await register(key, dir, refName, root);
|
|
362
|
-
|
|
363
|
-
const agentLines = agents ? await placeAgents(root, o.cwd, agents) : [];
|
|
364
|
-
return [
|
|
365
|
-
`作りました: ${key} → ${dir}`,
|
|
366
|
-
` 参照先 ${refName}(本体) → ${root}`,
|
|
367
|
-
` 主なフォルダ ${map.map((m) => m.path).join(", ") || "(なし。設定画面で足せます)"}`,
|
|
368
|
-
` 個人設定 ${userConfigPath()} に登録しました`,
|
|
369
|
-
...agentLines,
|
|
370
|
-
"",
|
|
371
|
-
"次に: p3 request new \"<やりたいこと>\" --body \"...\" → p3 preflight <要望ID> → p3 serve",
|
|
372
|
-
cfg.description ? "" : "※ description が空です。p3 config set description=\"...\" で設定してください(Preflight の精度に効きます)",
|
|
373
|
-
]
|
|
374
|
-
.filter((l, i, a) => l !== "" || (i > 0 && a[i - 1] !== ""))
|
|
375
|
-
.join("\n")
|
|
376
|
-
.trimEnd();
|
|
377
|
-
} finally {
|
|
378
|
-
close();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/** 最新の個人設定の上で、このプロジェクトの登録だけを書く(聞いている間にほかで変わっていても、ほかの登録・項目は消さない) */
|
|
383
|
-
function register(key: string, dir: string, refName: string | undefined, root: string) {
|
|
384
|
-
return updateUserConfig((doc, now) => {
|
|
385
|
-
const prev = now.projects[key];
|
|
386
|
-
if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
|
|
387
|
-
setProjectNode(doc, key, { dir, repos: refName ? { ...prev?.repos, [refName]: root } : (prev?.repos ?? {}) });
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/** 参加する前に、データのフォルダが読める p3 のプロジェクトかを確かめ、共有の定義(読むだけ)を返す */
|
|
392
|
-
async function readSharedProject(dir: string): Promise<ProjectConfig> {
|
|
393
|
-
const create = "新しく作るなら p3 init";
|
|
394
|
-
const st = await stat(dir).catch((e: NodeJS.ErrnoException) => e);
|
|
395
|
-
if (st instanceof Error) {
|
|
396
|
-
throw new UsageError(
|
|
397
|
-
st.code === "ENOENT"
|
|
398
|
-
? `データのフォルダがありません: ${dir}(パスと、共有のフォルダがつながっているかを確かめてください。${create})`
|
|
399
|
-
: `データのフォルダを読めません: ${dir}(${st.code ?? st.message})`,
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
if (!st.isDirectory()) throw new UsageError(`データのフォルダがフォルダではありません: ${dir}`);
|
|
403
|
-
const file = join(dir, "project.yaml");
|
|
404
|
-
let text: string;
|
|
405
|
-
try {
|
|
406
|
-
text = await readFile(file, "utf8");
|
|
407
|
-
} catch (e) {
|
|
408
|
-
const code = (e as NodeJS.ErrnoException).code;
|
|
409
|
-
throw new UsageError(
|
|
410
|
-
code === "ENOENT"
|
|
411
|
-
? `${dir} は p3 のプロジェクトではありません(project.yaml がありません)。指したフォルダと中身を確かめてください(参加では作りません。${create})`
|
|
412
|
-
: `project.yaml を読めません: ${file}(${code ?? (e as Error).message})`,
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
let data: unknown;
|
|
416
|
-
try {
|
|
417
|
-
data = YAML.parse(text);
|
|
418
|
-
} catch (e) {
|
|
419
|
-
throw new UsageError(`project.yaml を読めません(YAML として壊れています): ${file}: ${(e as Error).message.split("\n")[0]}`);
|
|
420
|
-
}
|
|
421
|
-
if (!data || typeof data !== "object" || Array.isArray(data)) throw new UsageError(`project.yaml の中身が p3 の設定ではありません: ${file}`);
|
|
422
|
-
return normalizeProject(data as Record<string, unknown>);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export interface JoinOptions {
|
|
426
|
-
cwd: string;
|
|
427
|
-
project?: string;
|
|
428
|
-
dir?: string;
|
|
429
|
-
repoName?: string;
|
|
430
|
-
yes?: boolean;
|
|
431
|
-
prompt?: (question: string) => Promise<string>;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* p3 join。既にあるプロジェクト(ほかの人が作って共有したデータのフォルダ)に参加する。個人設定に
|
|
436
|
-
* 「プロジェクト名 → フォルダ・このリポジトリのこのマシンのパス」を登録するだけで、共有の定義・データ・
|
|
437
|
-
* AI 向けのファイル(スキル・AGENTS.md / CLAUDE.md)は書かない。データのフォルダの既定と指定の仕方は init と同じ。
|
|
438
|
-
* - このリポジトリを登録する参照先: --repo-name(共有の定義にある名前)→ フォルダ名と同じ名前 → 参照先が1つならそれ。
|
|
439
|
-
* 決まらなければ登録せず p3 repo path を案内する
|
|
440
|
-
* - 同じ名前で別のフォルダは断る。同じ名前・同じフォルダ・同じパスなら何もしない(成功)
|
|
441
|
-
*/
|
|
442
|
-
export async function joinProject(o: JoinOptions): Promise<string> {
|
|
443
|
-
const root = repoRoot(o.cwd);
|
|
444
|
-
const { interactive, ask, close } = prompter(o);
|
|
445
|
-
try {
|
|
446
|
-
if (interactive) console.log(`p3 のプロジェクトに参加します(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
|
|
447
|
-
const { key, dir } = await projectAndDir(o, root, ask, "参加するデータのフォルダ(相対パスは今いる場所から)");
|
|
448
|
-
const shared = (await readSharedProject(dir)).repos;
|
|
449
|
-
let refName: string | undefined;
|
|
450
|
-
if (o.repoName !== undefined) {
|
|
451
|
-
if (!shared.some((r) => r.name === o.repoName)) {
|
|
452
|
-
throw new UsageError(`参照先「${o.repoName}」は共有の定義にありません(あるもの: ${shared.map((r) => r.name).join(", ") || "なし"})`);
|
|
453
|
-
}
|
|
454
|
-
refName = o.repoName;
|
|
455
|
-
} else {
|
|
456
|
-
const derived = slugifyName(basename(root));
|
|
457
|
-
refName = (shared.find((r) => r.name === derived) ?? (shared.length === 1 ? shared[0] : undefined))?.name;
|
|
458
|
-
}
|
|
459
|
-
const user = await loadUserConfig();
|
|
460
|
-
const prev = user.projects[key];
|
|
461
|
-
if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
|
|
462
|
-
if (prev && (!refName || prev.repos[refName] === root)) return `登録済みです: ${key} → ${dir}(変えていません)`;
|
|
463
|
-
await register(key, dir, refName, root);
|
|
464
|
-
return [
|
|
465
|
-
`参加しました: ${key} → ${dir}`,
|
|
466
|
-
refName
|
|
467
|
-
? ` 参照先 ${refName} ${root}`
|
|
468
|
-
: ` このリポジトリを参照先として登録していません。p3 repo ls で名前を確かめ、p3 repo path <名前> ${root} で登録してください`,
|
|
469
|
-
` 個人設定 ${userConfigPath()} に登録しました(データ・リポジトリのファイルは変えていません)`,
|
|
470
|
-
"",
|
|
471
|
-
"次に: p3 request ls / p3 serve",
|
|
472
|
-
].join("\n");
|
|
473
|
-
} finally {
|
|
474
|
-
close();
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/** p3 project [ls | add <名前> <フォルダ> | rm <名前>]: 個人設定のプロジェクトの一覧・登録・登録解除(データは消さない) */
|
|
479
|
-
export async function projectCommand(
|
|
480
|
-
cwd: string,
|
|
481
|
-
args: string[],
|
|
482
|
-
o: { repo?: string },
|
|
483
|
-
current: string | undefined,
|
|
484
|
-
): Promise<{ data: unknown; text: string }> {
|
|
485
|
-
const user = await loadUserConfig();
|
|
486
|
-
const [sub = "ls", name, dirRaw] = args;
|
|
487
|
-
if (sub === "ls") {
|
|
488
|
-
const rows = Object.entries(user.projects).map(([n, p]) => ({ name: n, ...p, current: n === current }));
|
|
489
|
-
const w = Math.max(4, ...rows.map((r) => r.name.length));
|
|
490
|
-
return {
|
|
491
|
-
data: rows,
|
|
492
|
-
text: rows.length
|
|
493
|
-
? rows.map((r) => `${r.current ? "*" : " "} ${r.name.padEnd(w)} ${r.dir}${Object.keys(r.repos).length ? ` (参照先 ${Object.keys(r.repos).join(", ")})` : ""}`).join("\n")
|
|
494
|
-
: "登録済みのプロジェクトはありません。管理したいリポジトリの中で p3 init --project <名前>(新しく作る)か p3 join --project <名前>(参加する)",
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
if (sub === "add") {
|
|
498
|
-
if (!name || !dirRaw) throw new UsageError("p3 project add <名前> <フォルダ>");
|
|
499
|
-
if (o.repo) throw new UsageError("--repo は使えなくなりました。登録したあと、p3 repo path <参照先の名前> <パス> でこのマシンのパスを登録してください");
|
|
500
|
-
if (!PROJECT_NAME.test(name)) throw new UsageError(`プロジェクト名は英数字と . _ - で: ${name}`);
|
|
501
|
-
const dir = resolvePath(cwd, dirRaw);
|
|
502
|
-
if (!existsSync(join(dir, "project.yaml"))) throw new UsageError(`${dir} はまだ p3 のプロジェクトではありません。作るときは管理したいリポジトリの中で p3 init`);
|
|
503
|
-
const saved = await updateUserConfig((doc, now) => {
|
|
504
|
-
const prev = now.projects[name];
|
|
505
|
-
if (prev && prev.dir !== dir) throw new UsageError(`「${name}」は別のフォルダで登録済みです: ${prev.dir}`);
|
|
506
|
-
const next = { dir, repos: prev?.repos ?? {} };
|
|
507
|
-
setProjectNode(doc, name, next);
|
|
508
|
-
return next;
|
|
509
|
-
});
|
|
510
|
-
return {
|
|
511
|
-
data: { name, ...saved },
|
|
512
|
-
text: `登録しました: ${name} → ${dir}\n 参照先のこのマシンのパスは p3 --project ${name} repo ls で確かめ、p3 repo path <名前> <パス> で登録してください`,
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
if (sub === "rm") {
|
|
516
|
-
if (!name) throw new UsageError("p3 project rm <名前>");
|
|
517
|
-
await updateUserConfig((doc, now) => {
|
|
518
|
-
if (!now.projects[name]) throw new UsageError(`登録されていません: ${name}`);
|
|
519
|
-
setProjectNode(doc, name, null);
|
|
520
|
-
});
|
|
521
|
-
return { data: { name }, text: `登録を外しました: ${name}(データのフォルダはそのまま)` };
|
|
522
|
-
}
|
|
523
|
-
throw new UsageError("p3 project [ls | add <名前> <フォルダ> | rm <名前>]");
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/** 入力されたパス。対話式の入力ではシェルが ~ を展開しないので、ここで展開する */
|
|
527
|
-
export const resolvePath = (cwd: string, p: string) => resolve(cwd, p === "~" ? homedir() : p.startsWith("~/") ? join(homedir(), p.slice(2)) : p);
|
|
528
|
-
|
|
529
|
-
const slugifyName = (s: string) => s.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[-._]+|-+$/g, "") || undefined;
|
|
530
|
-
|
|
531
|
-
const CONFIG_KEYS = ["name", "description", "branchPattern", "instructions"] as const;
|
|
532
|
-
|
|
533
|
-
/** p3 config [set key=value ...] */
|
|
534
|
-
export async function config(ws: Workspace, args: string[]): Promise<{ data: unknown; text: string }> {
|
|
535
|
-
if (args[0] === "set") {
|
|
536
|
-
const patch: Partial<ProjectConfig> = {};
|
|
537
|
-
for (const pair of args.slice(1)) {
|
|
538
|
-
const eq = pair.indexOf("=");
|
|
539
|
-
const key = pair.slice(0, eq) as (typeof CONFIG_KEYS)[number];
|
|
540
|
-
const value = pair.slice(eq + 1).trim();
|
|
541
|
-
if (eq < 1 || !CONFIG_KEYS.includes(key)) throw new UsageError(`設定できるキー: ${CONFIG_KEYS.join(", ")}`);
|
|
542
|
-
if (key === "instructions") patch.preflight = { instructions: value };
|
|
543
|
-
else if (key === "branchPattern" && !value.includes("{id}")) throw new UsageError("branchPattern には {id} を含めてください");
|
|
544
|
-
else if (key === "name" && !value) throw new UsageError(`${key} は空にできません`);
|
|
545
|
-
else patch[key] = value;
|
|
546
|
-
}
|
|
547
|
-
if (!Object.keys(patch).length) throw new UsageError("p3 config set キー=値 ...");
|
|
548
|
-
const next = await ws.saveProject(patch);
|
|
549
|
-
const keys = args.slice(1).map((p) => p.slice(0, p.indexOf("=")));
|
|
550
|
-
return { data: next, text: `更新しました: ${keys.join(", ")}` };
|
|
551
|
-
}
|
|
552
|
-
const p = ws.project;
|
|
553
|
-
const text = [
|
|
554
|
-
`name ${p.name}`,
|
|
555
|
-
`description ${p.description || "(なし)"}`,
|
|
556
|
-
`repos ${p.repos.map((r) => r.name).join(", ") || "(なし)"} (p3 repo ls)`,
|
|
557
|
-
`milestones ${p.milestones.map((m) => `${m.id}${m.due ? `(${m.due})` : ""}${m.done ? "[済]" : ""}`).join(", ") || "(なし)"}`,
|
|
558
|
-
`branchPattern ${p.branchPattern}`,
|
|
559
|
-
`instructions ${p.preflight.instructions || "(なし)"}`,
|
|
560
|
-
"",
|
|
561
|
-
`ファイル: ${join(ws.dataDir, "project.yaml")}`,
|
|
562
|
-
].join("\n");
|
|
563
|
-
return { data: p, text };
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
function splitList(s: string): string[] {
|
|
567
|
-
return s.split(",").map((x) => x.trim()).filter(Boolean);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* p3 repo: Preflight が読む参照先(リポジトリ・フォルダ)。共有の定義(project.yaml の repos)と、このマシンのパス
|
|
572
|
-
* (個人設定の projects.<プロジェクト>.repos)を分けて扱う。
|
|
573
|
-
*
|
|
574
|
-
* ls 一覧(このマシンのパスが無いものは登録の仕方を出す)
|
|
575
|
-
* add <名前> [<パス>] [キー=値 ...] 共有の定義を足す(パスを渡せばこのマシンのパスも登録する)
|
|
576
|
-
* set <名前> キー=値 ... 共有の定義を変える(role readFirst writable)
|
|
577
|
-
* path <名前> <パス> このマシンのパスだけを登録する(ほかの人が足した参照先に)
|
|
578
|
-
* rm <名前> [--local] 共有の定義とこのマシンのパスを消す(--local はこのマシンのパスだけ)
|
|
579
|
-
*/
|
|
580
|
-
export async function repoCommand(
|
|
581
|
-
ws: Workspace,
|
|
582
|
-
projectName: string | undefined,
|
|
583
|
-
cwd: string,
|
|
584
|
-
args: string[],
|
|
585
|
-
o: { local?: boolean },
|
|
586
|
-
): Promise<{ data: unknown; text: string }> {
|
|
587
|
-
const [sub = "ls", name, ...rest] = args;
|
|
588
|
-
const shared = () => ws.project.repos.find((r) => r.name === name);
|
|
589
|
-
const usage = "p3 repo [ls | add <名前> [<パス>] [role=… readFirst=true writable=true] | set <名前> キー=値 … | path <名前> <パス> | rm <名前> [--local]]";
|
|
590
|
-
|
|
591
|
-
const pairs = (list: string[]): RepoPatch => {
|
|
592
|
-
const patch: RepoPatch = {};
|
|
593
|
-
for (const pair of list) {
|
|
594
|
-
const eq = pair.indexOf("=");
|
|
595
|
-
const key = pair.slice(0, eq);
|
|
596
|
-
const value = pair.slice(eq + 1).trim();
|
|
597
|
-
if (key === "role") patch.role = value;
|
|
598
|
-
else if (key === "readFirst" || key === "writable") {
|
|
599
|
-
if (!["true", "false"].includes(value)) throw new UsageError(`${key} は true か false`);
|
|
600
|
-
patch[key] = value === "true";
|
|
601
|
-
} else throw new UsageError(`変えられるキー: role readFirst writable(主なフォルダ map は設定画面か project.yaml で)`);
|
|
602
|
-
}
|
|
603
|
-
return patch;
|
|
604
|
-
};
|
|
605
|
-
/** 共通の操作の失敗は使い方の誤りとして出す */
|
|
606
|
-
const run = async <T>(f: () => Promise<T>): Promise<T> => {
|
|
607
|
-
try {
|
|
608
|
-
return await f();
|
|
609
|
-
} catch (e) {
|
|
610
|
-
if (e instanceof RepoAdminError) throw new UsageError(e.message);
|
|
611
|
-
throw e;
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
const folder = (raw: string) => resolvePath(cwd, raw);
|
|
615
|
-
|
|
616
|
-
if (sub === "ls") {
|
|
617
|
-
const refs = ws.refs();
|
|
618
|
-
const rows = refs.map((r) => ({ ...r, local: r.local ?? null }));
|
|
619
|
-
const text = [
|
|
620
|
-
...(!refs.length ? ["(参照先はまだありません。足すときは p3 repo add <名前> <パス> role=…)"] : []),
|
|
621
|
-
...refs.map((r) => {
|
|
622
|
-
const flags = [r.readFirst && "最初に読む", r.writable && "作業先候補"].filter(Boolean).join("・");
|
|
623
|
-
const where =
|
|
624
|
-
r.status === "ok" ? r.local : r.status === "unregistered" ? `未登録 → p3 repo path ${r.name} <このマシンのパス>` : `${r.reason}`;
|
|
625
|
-
return `${r.name}${r.role ? `(${r.role})` : ""}${flags ? ` [${flags}]` : ""} /workspace/${r.mount}\n ${where}${
|
|
626
|
-
r.map.length ? `\n 主なフォルダ: ${r.map.map((m) => (m.entry ? `${m.path}(入口 ${m.entry})` : m.path)).join(", ")}` : ""
|
|
627
|
-
}`;
|
|
628
|
-
}),
|
|
629
|
-
].join("\n");
|
|
630
|
-
return { data: rows, text };
|
|
631
|
-
}
|
|
632
|
-
if (!name) throw new UsageError(usage);
|
|
633
|
-
const problem = repoNameProblem(name);
|
|
634
|
-
if (problem && sub !== "rm") throw new UsageError(`参照先の名前: ${problem}`);
|
|
635
|
-
|
|
636
|
-
if (sub === "add") {
|
|
637
|
-
const maybePath = rest[0] && !rest[0].includes("=") ? rest[0] : undefined;
|
|
638
|
-
const patch = pairs(maybePath ? rest.slice(1) : rest);
|
|
639
|
-
if (shared()) throw new UsageError(`「${name}」は既にあります。変えるときは p3 repo set ${name} キー=値、このマシンのパスは p3 repo path ${name} <パス>`);
|
|
640
|
-
const path = maybePath ? folder(maybePath) : undefined;
|
|
641
|
-
if (path) await run(async () => checkFolder(path));
|
|
642
|
-
const entry = await run(() => addRepo(ws, name, patch));
|
|
643
|
-
if (path) await run(() => setLocalRepoPath(ws, projectName, name, path));
|
|
644
|
-
return {
|
|
645
|
-
data: { ...entry, local: path ?? null },
|
|
646
|
-
text: `参照先を足しました: ${name}${entry.role ? `(${entry.role})` : ""}${path ? ` → ${path}` : `(このマシンのパスは未登録: p3 repo path ${name} <パス>)`}`,
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
if (sub === "set") {
|
|
650
|
-
if (!shared()) throw new UsageError(`「${name}」はありません。足すときは p3 repo add ${name} <パス>`);
|
|
651
|
-
if (!rest.length) 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()) throw new UsageError(`「${name}」は共有の参照先にありません(p3 repo ls)。足すときは p3 repo add ${name} <パス>`);
|
|
657
|
-
if (!rest[0]) throw new UsageError(`p3 repo path ${name} <このマシンのパス>`);
|
|
658
|
-
const path = folder(rest[0]);
|
|
659
|
-
await run(() => setLocalRepoPath(ws, projectName, name, path));
|
|
660
|
-
return { data: { name, local: path }, text: `このマシンのパスを登録しました: ${name} → ${path}(共有の定義は変えていません)` };
|
|
661
|
-
}
|
|
662
|
-
if (sub === "rm") {
|
|
663
|
-
if (o.local) {
|
|
664
|
-
await run(() => setLocalRepoPath(ws, projectName, name, null));
|
|
665
|
-
return { data: { name, local: null }, text: `このマシンのパスを外しました: ${name}(共有の定義は残しています。ほかの人には影響しません)` };
|
|
666
|
-
}
|
|
667
|
-
if (!shared()) throw new UsageError(`「${name}」は共有の参照先にありません。このマシンのパスだけを外すときは --local`);
|
|
668
|
-
await run(() => removeRepo(ws, projectName, name));
|
|
669
|
-
return { data: { name }, text: `参照先を消しました: ${name}(共有の定義。ほかの人の Preflight でも読まなくなります。ファイルやフォルダは消していません)` };
|
|
670
|
-
}
|
|
671
|
-
throw new UsageError(usage);
|
|
672
|
-
}
|