@tamai/hub-cli 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -1
- package/commands/project-update.mjs +34 -4
- package/commands/task-brief.mjs +165 -0
- package/lib/args.mjs +28 -1
- package/lib/brief.mjs +708 -0
- package/lib/cli.mjs +11 -18
- package/lib/format.mjs +52 -0
- package/lib/version.mjs +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ hub project help
|
|
|
66
66
|
hub infra help
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
動詞は `task` が `new` / `add` / `claim` / `next` / `show` / `report` / `note` / `list` / `audit`、
|
|
69
|
+
動詞は `task` が `new` / `add` / `claim` / `next` / `show` / `report` / `note` / `list` / `audit` / `brief`、
|
|
70
70
|
`project` が `list` / `show` / `create` / `update` / `move`、
|
|
71
71
|
`infra` が `list` / `show` / `update` / `link` / `unlink`。
|
|
72
72
|
**正確なオプションは常に `--help` を見る**(ここにも、スキルにも写経しない)。
|
|
@@ -98,6 +98,58 @@ URL から決める。`"<ラベル>=<URL>"` の形は従来どおり最初の `=
|
|
|
98
98
|
入力した URL は資格情報を抱えていることがあるため、**どのエラー文にも再掲しない**
|
|
99
99
|
(何番目の `--add-link` か・既存側のラベルだけを出す)。
|
|
100
100
|
|
|
101
|
+
### グループ(プロジェクトの親子)
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
hub project update koyo --entity-type group # 案件 → グループへ
|
|
105
|
+
hub project update koyo-cms --parent koyo # グループに属させる
|
|
106
|
+
hub project update koyo-cms --parent none # グループから外す
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`--entity-type` は `project`(案件・既定)か `group`(グループ)。グループは案件の上の層で、
|
|
110
|
+
**自分は親を持てない**(1 段)。`--parent` は所属するグループの slug で、`none` で外す。
|
|
111
|
+
指定できるのは**グループの slug だけ**なので、`--entity-type group --parent <slug>` は
|
|
112
|
+
CLI が送る前に断る。
|
|
113
|
+
|
|
114
|
+
配下の案件がある `group` の拒否は3条件で別々である。**削除**と**案件(`project`)への変更**は
|
|
115
|
+
子が1件でもあれば拒否され、**終了(`status=closed`)は終了していない子があるときだけ**拒否される
|
|
116
|
+
(子が全部終了していればグループも終了にできる)。いずれも API が 409 `project_has_children` を
|
|
117
|
+
返し、CLI はその message をそのまま出す。
|
|
118
|
+
|
|
119
|
+
`show` / `list` は、グループのときだけ `type: group` と `children: N` の行を、親を持つ案件には
|
|
120
|
+
`parent: <slug>` の行を出す(`kind` と同じく**既定でないときだけ**出す流儀)。`show` は
|
|
121
|
+
配下の案件を `children:` の下に `- <slug> [<status>] <name>` で並べる。`--json` は応答そのまま。
|
|
122
|
+
|
|
123
|
+
### 依頼書(`hub task brief`)
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
hub task brief 180 --role implement --worker opus35
|
|
127
|
+
hub task brief 181 --role review --worker codex1 --commits "4803003 79410c1" --note-file 裁定.md
|
|
128
|
+
hub task brief 183 --role review --worker codex1 --out /tmp/brief-183.md --sandboxed
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
文脈ゼロの AI へ渡す依頼を Markdown 1 枚にまとめる。看板(本文・status・owner・直近の報告)、
|
|
132
|
+
案件(repo・リンク・デプロイ先・台帳)、作業ディレクトリの規約ファイルの場所を 1 コマンドで束ねる。
|
|
133
|
+
既定は stdout、`--out <path>` でファイルへ、`--json` は集めた素材をそのまま返す。
|
|
134
|
+
`--role` は `implement`(既定)/ `review` / `design` で定型部分が変わる。
|
|
135
|
+
|
|
136
|
+
3 つだけ性質を覚えておけばよい。
|
|
137
|
+
|
|
138
|
+
- **定型文は CLI の中にあり、repo の規約は写していない。** 依頼書は作業ディレクトリの
|
|
139
|
+
`AGENTS.md` / `CLAUDE.md` を「最初に読む」と指すだけで、検証コマンドもそちらへ送る。
|
|
140
|
+
- **看板の本文は全文が入る**ので、依頼書は `hub task show` を指さない。API に届かない相手には
|
|
141
|
+
`--out` のファイルだけを渡せばよい(`--sandboxed` を付けると、CLI を使わない・commit できなければ
|
|
142
|
+
ファイルに書くだけ・報告は依頼者が代行、の段落が入り、認証の行が消える)。
|
|
143
|
+
`--sandboxed` は明示するもので、**`--worker` の呼び名から環境を推測しない**。
|
|
144
|
+
- **台帳の口座欄(`account` / `account_ref` / `note` / `payer` / `holder`)は出ない。**
|
|
145
|
+
依頼に要らないので素材の段階で落としてあり、`--json` にも現れない。
|
|
146
|
+
`--out` のファイルの中身も、書く前に認証値の秘匿を通す。
|
|
147
|
+
|
|
148
|
+
`--out` は生成物なので既存ファイルを上書きするが、**git で追跡されているパスには書かない**
|
|
149
|
+
(記録や指示書の上に依頼書を書かないため)。`--commits` は自由文で、`--role review` で省くと
|
|
150
|
+
警告が出て「対象は依頼者から受け取る」と書かれる。案件が引けないときは案件の節を省いて警告し、
|
|
151
|
+
依頼書そのものは出す(看板が引けないときだけ何も出さない)。
|
|
152
|
+
|
|
101
153
|
### インフラ資産を読む・更新する
|
|
102
154
|
|
|
103
155
|
```bash
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
PROJECT_ENTITY_TYPES,
|
|
3
|
+
PROJECT_KINDS,
|
|
4
|
+
PROJECT_LINK_ROLES,
|
|
5
|
+
PROJECT_SLUG_PATTERN,
|
|
6
|
+
cliError,
|
|
7
|
+
requireSinglePositional,
|
|
8
|
+
usageError,
|
|
9
|
+
} from "../lib/args.mjs";
|
|
2
10
|
import { printProjectResult, toProjectLinkInput } from "../lib/format.mjs";
|
|
3
11
|
|
|
4
12
|
/** `--add-link` の値がURL単独かどうか。**= で割るより先に見る**(指示 §5.6・Astra High 4)。 */
|
|
@@ -14,7 +22,10 @@ const ordinal = (index) => `${index + 1} 番目`;
|
|
|
14
22
|
export const projectUpdateCommand = {
|
|
15
23
|
name: "update",
|
|
16
24
|
options: {
|
|
17
|
-
allowed: [
|
|
25
|
+
allowed: [
|
|
26
|
+
"name", "repo", "slug", "kind", "entity-type", "parent",
|
|
27
|
+
"add-link", "link-role", "remove-link", "remove-link-url", "clear-links",
|
|
28
|
+
],
|
|
18
29
|
boolean: ["clear-links"],
|
|
19
30
|
repeatable: ["add-link", "remove-link", "remove-link-url"],
|
|
20
31
|
},
|
|
@@ -31,12 +42,28 @@ export const projectUpdateCommand = {
|
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
const hasLinkChange = flags["add-link"] || flags["remove-link"] || flags["remove-link-url"] || flags["clear-links"];
|
|
34
|
-
if (
|
|
35
|
-
|
|
45
|
+
if (
|
|
46
|
+
!flags.name && !flags.repo && !flags.slug && !flags.kind
|
|
47
|
+
&& !flags["entity-type"] && !flags.parent && !hasLinkChange
|
|
48
|
+
) {
|
|
49
|
+
throw usageError("--name / --repo / --slug / --kind / --entity-type / --parent / --add-link / --remove-link / --remove-link-url / --clear-links のいずれかを指定してください");
|
|
36
50
|
}
|
|
37
51
|
if (flags.kind && !PROJECT_KINDS.includes(options.kind)) {
|
|
38
52
|
throw usageError(`--kind は ${PROJECT_KINDS.join(" / ")} のいずれかです`);
|
|
39
53
|
}
|
|
54
|
+
// 種類とグループ(記録180)。**語彙と形だけ**を先に見る——親が本当に group か、
|
|
55
|
+
// 配下の案件が居るかは Worker が書き込みと同じ文の中で見る。
|
|
56
|
+
if (flags["entity-type"] && !PROJECT_ENTITY_TYPES.includes(options["entity-type"])) {
|
|
57
|
+
throw usageError(`--entity-type は ${PROJECT_ENTITY_TYPES.join(" / ")} のいずれかです`);
|
|
58
|
+
}
|
|
59
|
+
const parentValue = flags.parent ? options.parent.trim() : null;
|
|
60
|
+
if (parentValue !== null && parentValue !== "none" && !PROJECT_SLUG_PATTERN.test(parentValue)) {
|
|
61
|
+
throw usageError("--parent は英小文字・数字で始まるslugか none を指定してください");
|
|
62
|
+
}
|
|
63
|
+
// グループは親を持てない(1段)。APIも400にするが、往復を省く
|
|
64
|
+
if (options["entity-type"] === "group" && flags.parent && parentValue !== "none") {
|
|
65
|
+
throw usageError("--entity-type group と --parent <slug> は同時に指定できません");
|
|
66
|
+
}
|
|
40
67
|
if (flags["clear-links"] && (flags["add-link"] || flags["remove-link"] || flags["remove-link-url"])) {
|
|
41
68
|
throw usageError("--clear-links と --add-link / --remove-link / --remove-link-url は同時に指定できません");
|
|
42
69
|
}
|
|
@@ -90,6 +117,9 @@ export const projectUpdateCommand = {
|
|
|
90
117
|
body.slug = options.slug.trim();
|
|
91
118
|
}
|
|
92
119
|
if (flags.kind) body.kind = options.kind;
|
|
120
|
+
if (flags["entity-type"]) body.entity_type = options["entity-type"];
|
|
121
|
+
// `none` は**文字列ではなく null**(「グループを外す」の指定・変異表 G17)
|
|
122
|
+
if (flags.parent) body.parent_slug = parentValue === "none" ? null : parentValue;
|
|
93
123
|
if (hasLinkChange) {
|
|
94
124
|
// 応答形(system / role_inferred 付き)のまま送り返さない。§3.5 の入力形へ戻してから触る
|
|
95
125
|
const currentLinks = Array.isArray(current.item.links) ? current.item.links : [];
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { cliError, requireSinglePositional, usageError } from "../lib/args.mjs";
|
|
4
|
+
import {
|
|
5
|
+
BRIEF_ROLES,
|
|
6
|
+
WORKER_PATTERN,
|
|
7
|
+
collectBrief,
|
|
8
|
+
redactAccountIds,
|
|
9
|
+
renderBrief,
|
|
10
|
+
} from "../lib/brief.mjs";
|
|
11
|
+
import { packageVersion } from "../lib/version.mjs";
|
|
12
|
+
import { findRepoRoot } from "../lib/records.mjs";
|
|
13
|
+
import { resolveTaskIdArg } from "../lib/task-ref.mjs";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 存在する祖先まで遡って `realpath` を当て、無い分を繋ぎ直す。
|
|
17
|
+
*
|
|
18
|
+
* これから作るディレクトリは `realpath` できない(ENOENT)ので、途中で諦めると
|
|
19
|
+
* **symlink を含む祖先が未解決のまま残る**。解決できた実体に未作成分を足せば、
|
|
20
|
+
* 「後で mkdir されるのは実体の下」という書き込みの実態と一致する。
|
|
21
|
+
*/
|
|
22
|
+
async function realDirectory(dir, realpathImpl) {
|
|
23
|
+
const missing = [];
|
|
24
|
+
let current = dir;
|
|
25
|
+
for (;;) {
|
|
26
|
+
try {
|
|
27
|
+
return path.join(await realpathImpl(current), ...missing);
|
|
28
|
+
} catch {
|
|
29
|
+
const parent = path.dirname(current);
|
|
30
|
+
if (parent === current) return dir;
|
|
31
|
+
missing.unshift(path.basename(current));
|
|
32
|
+
current = parent;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `--out` の書き先を決める(指示書 §7・便1 レビュー High)。
|
|
39
|
+
*
|
|
40
|
+
* 依頼書は生成物なので**既存ファイルは上書きしてよい**。ただし **git で追跡されているパスは
|
|
41
|
+
* 拒否する** ——「依頼書を作る」つもりで記録や指示書を潰すのが一番痛い事故で、追跡の有無は
|
|
42
|
+
* その2つをほぼそのまま言い当てる。git が動かない環境では拒否せず警告に留める
|
|
43
|
+
* (追跡を確かめられないだけで書けなくなる方が困る)。
|
|
44
|
+
*
|
|
45
|
+
* **検査は字面ではなく実体に対して行う。** `stat` と `writeFile` は symlink を追うのに
|
|
46
|
+
* `git ls-files` は渡した綴りしか見ないので、repo 内の未追跡 symlink(や symlink の親)から
|
|
47
|
+
* 追跡中の記録を指せば、追跡検査をすり抜けて実体を上書きできた。そこで
|
|
48
|
+
* **最終要素が symlink なら拒否**し、親は `realpath` で解いてから追跡検査する
|
|
49
|
+
* (repo root も実体側から探し直す。symlink が別の repo を指していることもある)。
|
|
50
|
+
*
|
|
51
|
+
* 検査は**API を呼ぶ前**に済ませる。書けないと分かっているのに看板を引いて依頼書を組むと、
|
|
52
|
+
* 失敗の直前まで走って何も残らない。
|
|
53
|
+
*/
|
|
54
|
+
async function prepareOutPath(out, dependencies) {
|
|
55
|
+
const requested = path.resolve(dependencies.cwd(), out);
|
|
56
|
+
try {
|
|
57
|
+
const entry = await dependencies.lstatImpl(requested);
|
|
58
|
+
if (entry?.isSymbolicLink?.() === true) {
|
|
59
|
+
throw cliError(
|
|
60
|
+
`${requested} は symlink なので依頼書を書けません(リンク先が追跡ファイルでないか確かめて、実体のパスを指定してください)`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (entry?.isDirectory?.() === true) {
|
|
64
|
+
throw usageError(`--out にはファイル名を指定してください(ディレクトリです): ${requested}`);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error?.code === "cli_error") throw error;
|
|
68
|
+
// 存在しないのは正常(これから書く)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const absolute = path.join(
|
|
72
|
+
await realDirectory(path.dirname(requested), dependencies.realpathImpl),
|
|
73
|
+
path.basename(requested),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const root = await findRepoRoot(path.dirname(absolute), dependencies.statImpl);
|
|
77
|
+
if (root === null) return absolute;
|
|
78
|
+
const relative = path.relative(root, absolute).split(path.sep).join("/");
|
|
79
|
+
if (relative === "" || relative.startsWith("../")) return absolute;
|
|
80
|
+
|
|
81
|
+
// `--error-unmatch` は使わない。終了コードが「追跡されていない」と「git を実行できない」を
|
|
82
|
+
// 区別できず、fail-open(git が無ければ書く)の契約を保てないため、出力の有無で見る。
|
|
83
|
+
const result = await dependencies.runGitImpl(
|
|
84
|
+
["-c", "core.quotepath=false", "ls-files", "-z", "--", relative],
|
|
85
|
+
{ cwd: root },
|
|
86
|
+
);
|
|
87
|
+
if (result?.ok === false) {
|
|
88
|
+
dependencies.stderr.write(`警告: git を実行できないため --out の追跡検査を省きました: ${relative}\n`);
|
|
89
|
+
return absolute;
|
|
90
|
+
}
|
|
91
|
+
if (String(result?.stdout ?? "") !== "") {
|
|
92
|
+
throw cliError(
|
|
93
|
+
`${relative} は git で追跡されているので依頼書を書けません(記録や指示書の上に書かないため)`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return absolute;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const taskBriefCommand = {
|
|
100
|
+
name: "brief",
|
|
101
|
+
options: {
|
|
102
|
+
allowed: ["role", "worker", "commits", "note", "note-file", "out", "sandboxed"],
|
|
103
|
+
boolean: ["sandboxed"],
|
|
104
|
+
},
|
|
105
|
+
async run({ options, positional, flags, dependencies, api }) {
|
|
106
|
+
const ref = requireSinglePositional(positional, "タスクID");
|
|
107
|
+
|
|
108
|
+
// 語彙と形の誤りは**APIを呼ぶ前**に落とす(往復してから気づくより速い)
|
|
109
|
+
const role = options.role ?? "implement";
|
|
110
|
+
if (!BRIEF_ROLES.includes(role)) {
|
|
111
|
+
throw usageError(`--role は ${BRIEF_ROLES.join(" / ")} のいずれかです: ${role}`);
|
|
112
|
+
}
|
|
113
|
+
const worker = options.worker ?? null;
|
|
114
|
+
if (worker !== null && !WORKER_PATTERN.test(worker)) {
|
|
115
|
+
throw usageError("--worker は英小文字・数字・ハイフンの呼び名です(HUB_ACTOR と同じ形)");
|
|
116
|
+
}
|
|
117
|
+
// **値ではなく指定の有無で見る**(`--note= --note-file=x.md` も同時指定である)
|
|
118
|
+
if (flags.note && flags["note-file"]) {
|
|
119
|
+
throw usageError("--note と --note-file は同時に指定できません");
|
|
120
|
+
}
|
|
121
|
+
const noteSource = options["note-file"]
|
|
122
|
+
? await dependencies.readFileImpl(options["note-file"], "utf8")
|
|
123
|
+
: options.note;
|
|
124
|
+
if (flags.note || flags["note-file"]) {
|
|
125
|
+
if (!noteSource?.trim()) throw usageError("--note / --note-file が空です");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const outPath = flags.out ? await prepareOutPath(options.out, dependencies) : null;
|
|
129
|
+
|
|
130
|
+
const id = await resolveTaskIdArg(ref, api, dependencies);
|
|
131
|
+
const material = await collectBrief({
|
|
132
|
+
ref,
|
|
133
|
+
id,
|
|
134
|
+
api,
|
|
135
|
+
dependencies,
|
|
136
|
+
version: await packageVersion(),
|
|
137
|
+
options: {
|
|
138
|
+
role,
|
|
139
|
+
worker,
|
|
140
|
+
commits: options.commits ?? null,
|
|
141
|
+
note: noteSource?.trim() ? noteSource : null,
|
|
142
|
+
noteFile: options["note-file"] ?? null,
|
|
143
|
+
sandboxed: flags.sandboxed === true,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
for (const warning of material.warnings) dependencies.stderr.write(`警告: ${warning}\n`);
|
|
147
|
+
|
|
148
|
+
// **依頼書の出口はこの2行だけ**(Markdown / `--json` / `--out` のどれもここを通る)。
|
|
149
|
+
// アカウント ID の秘匿を経路ごとに書くと、出力を足したときに通し忘れる(資格情報の秘匿を
|
|
150
|
+
// `runCli` の出口1か所に寄せてあるのと同じ理屈)。
|
|
151
|
+
const markdown = redactAccountIds(renderBrief(material));
|
|
152
|
+
const json = options.json ? redactAccountIds(`${JSON.stringify(material, null, 2)}\n`) : null;
|
|
153
|
+
|
|
154
|
+
if (outPath !== null) {
|
|
155
|
+
// `--out` は `runCli` の `redactSecrets` を通らない経路なので、資格情報の秘匿も自分で通す
|
|
156
|
+
await dependencies.mkdirImpl(path.dirname(outPath), { recursive: true });
|
|
157
|
+
await dependencies.writeFileImpl(outPath, dependencies.redact(markdown), "utf8");
|
|
158
|
+
dependencies.stderr.write(`依頼書を書きました: ${outPath}\n`);
|
|
159
|
+
if (json !== null) dependencies.stdout.write(json);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
dependencies.stdout.write(json ?? markdown);
|
|
164
|
+
},
|
|
165
|
+
};
|
package/lib/args.mjs
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
/** プロジェクトの区分。共有範囲のvisibility(private|team)とは別の軸。 */
|
|
2
2
|
export const PROJECT_KINDS = ["work", "private"];
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 行の種類(記録180)。`group`=グループ(案件の上の層)で、`kind` とも別の軸。
|
|
6
|
+
*
|
|
7
|
+
* **CLIが持つのは語彙だけ**で、親子の規則(親は group だけ・1段・子がいる group は
|
|
8
|
+
* 閉じない)は Worker が見る。ここに置くのは「GETより前に打ち間違いを弾く」ためだけ。
|
|
9
|
+
* 語が増えたら Worker の `PROJECT_ENTITY_TYPES` と同時に直すこと。
|
|
10
|
+
*/
|
|
11
|
+
export const PROJECT_ENTITY_TYPES = ["project", "group"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `--parent` のslugの形(Worker の `SLUG_PATTERN` と同じ)。
|
|
15
|
+
* `none` は「グループを外す」の指定で、これに当てはめない。
|
|
16
|
+
*/
|
|
17
|
+
export const PROJECT_SLUG_PATTERN = /^[a-z0-9][a-z0-9_-]{0,99}$/;
|
|
18
|
+
|
|
4
19
|
/**
|
|
5
20
|
* 参照リンクの役割(`2026-09-16 プロジェクト参照リンクの実装指示.md` §1.2 の9語)。
|
|
6
21
|
*
|
|
@@ -34,6 +49,8 @@ export const TASK_USAGE = `使い方:
|
|
|
34
49
|
[--repo-card [<dir>]] [--slug <slug>] [--force] [--json]
|
|
35
50
|
hub task list [--status <s>] [--project <name>] [--owner <name>] [--q <text>] [--json]
|
|
36
51
|
hub task audit [--json]
|
|
52
|
+
hub task brief <id> [--role implement|review|design] [--worker <name>] [--commits <range>]
|
|
53
|
+
[--note <text> | --note-file <path>] [--out <path>] [--sandboxed] [--json]
|
|
37
54
|
|
|
38
55
|
show / claim / report / note の <id> には記録番号(150 / #150)も指定できる(context_ref が docs/records/150-… のタスクを一覧から引く。番号はrepoごとの採番なので、複数一致は作業ツリーに記録ファイルがある1件で割る。0件・それでも割れない複数一致はエラー)。
|
|
39
56
|
hub task new は「D1へ起票 → repoに記録の雛形を作成 → context_ref で紐付け」を1コマンドで行う。
|
|
@@ -42,6 +59,9 @@ hub task new は「D1へ起票 → repoに記録の雛形を作成 → context_r
|
|
|
42
59
|
--repo-card で題名からslugを作れない場合は、3文字以上のkebab-caseで --slug <slug> が必要(例: --slug project-detail-pc-layout)。
|
|
43
60
|
hub task audit は done のタスクの context_ref を git と突き合わせ、記録が未コミット・
|
|
44
61
|
未pushのまま done になっていないかを見る(「doneなのに本番に無い」の検出)。
|
|
62
|
+
hub task brief は文脈ゼロのAIへ渡す依頼書をMarkdownで出す。既定はstdout。
|
|
63
|
+
--out はファイルへ書く(生成物なので上書きするが、gitで追跡されているパスには書かない)。
|
|
64
|
+
--sandboxed はAPIに届かない・commitできない環境向けの段落を足す(--workerの名前からは推測しない)。
|
|
45
65
|
-- 以降はすべて位置引数になる。-- で始まるタイトルは hub task new --project hub -- "--で始まる題" の順で渡す。
|
|
46
66
|
オプションは --name=value の形でも書ける。値が -- で始まるとき(例 --note='--- 見出し')はこの形で渡す。
|
|
47
67
|
report / note の長文は約2000字ごとに分割して送る。途中で失敗すると「n件中m件まで送信済み」と出る。
|
|
@@ -53,6 +73,7 @@ export const PROJECT_USAGE = `使い方:
|
|
|
53
73
|
hub project create <slug> --name <text> [--kind work|private] [--repo <text>] [--json]
|
|
54
74
|
hub project update <slug> [--name <text>] [--repo <text>] [--slug <new-slug>]
|
|
55
75
|
[--kind work|private]
|
|
76
|
+
[--entity-type project|group] [--parent <slug>|none]
|
|
56
77
|
[--add-link <URL>]... [--add-link "<ラベル>=<URL>"]...
|
|
57
78
|
[--link-role <role>]
|
|
58
79
|
[--remove-link "<ラベル>"]... [--remove-link-url <URL>]...
|
|
@@ -73,6 +94,12 @@ export const PROJECT_USAGE = `使い方:
|
|
|
73
94
|
--remove-link-url はURL完全一致で1件だけ消す(該当なし・複数該当はエラー)。
|
|
74
95
|
--clear-links は全消し(--add-link / --remove-link / --remove-link-url と同時指定不可)。
|
|
75
96
|
--kind は仕事/プライベートの区分(既定 work)。共有範囲のvisibilityとは別。
|
|
97
|
+
--entity-type は案件(project)かグループ(group)か。グループは案件の上の層で、
|
|
98
|
+
親を持てない(1段)。配下の案件があるグループは、削除と案件(project)への変更が
|
|
99
|
+
1件でも子があれば拒否され、終了(status=closed)は**終了していない子**があるときだけ
|
|
100
|
+
拒否される(子が全部終了していればグループも終了にできる)。
|
|
101
|
+
--parent は所属するグループのslug。--parent none で外す。指定できるのは group だけで、
|
|
102
|
+
--entity-type group と --parent <slug> は同時に指定できない。
|
|
76
103
|
list は既定で全件出す(--kind を付けたときだけ絞る)。
|
|
77
104
|
オプションは --name=value の形でも書ける(値が -- で始まるときはこの形で渡す)。
|
|
78
105
|
`;
|
|
@@ -108,7 +135,7 @@ export const INFRA_USAGE = `使い方:
|
|
|
108
135
|
`;
|
|
109
136
|
|
|
110
137
|
export const USAGE = `使い方:
|
|
111
|
-
hub task <verb> ... タスク操作(new / add / claim / next / show / report / note / list)
|
|
138
|
+
hub task <verb> ... タスク操作(new / add / claim / next / show / report / note / list / brief)
|
|
112
139
|
hub task help
|
|
113
140
|
hub project <verb> ... プロジェクト操作(list / show / create / update / move)
|
|
114
141
|
hub project help
|
package/lib/brief.mjs
ADDED
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
// 依頼書(`hub task brief`)の素材集めと整形(記録183・`docs/notes/2026-09-20 依頼書(hub task brief)の実装指示.md`)。
|
|
2
|
+
//
|
|
3
|
+
// **文脈ゼロのAIへ渡す1枚**を作る。看板の本文は要約せず全文を入れ、`hub task show` を指さない
|
|
4
|
+
// ——依頼先がサンドボックスからAPIに届かないことがあり、その場合は `--out` のファイルだけが
|
|
5
|
+
// 相手の持つ情報のすべてになるからである(受け入れ条件)。
|
|
6
|
+
//
|
|
7
|
+
// **repo固有の規則はここに書かない。** 検証コマンドもディレクトリ名もmigration番号も、正本は
|
|
8
|
+
// 作業ディレクトリの `AGENTS.md` / `CLAUDE.md` と看板の本文で、依頼書はその場所を指すだけにする。
|
|
9
|
+
// 写すと、repoが変わったとき・規約が変わったときに依頼書だけが古い規則を配って回る。
|
|
10
|
+
//
|
|
11
|
+
// **秘密は「出さない」ではなく「持たない」。** 台帳の口座欄(`account` / `account_ref` / `note` /
|
|
12
|
+
// `payer` / `holder`)とデプロイ先の `account_key` は `collectBrief` の写しの時点で落とすので、
|
|
13
|
+
// `renderBrief` にも `--json` にも届かない(指示書 §6)。
|
|
14
|
+
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
|
|
17
|
+
import { cliError } from "./args.mjs";
|
|
18
|
+
import { REDACTED, describeFailure } from "./api.mjs";
|
|
19
|
+
import { findRepoRoot } from "./records.mjs";
|
|
20
|
+
import { recordNumberFromContextRef } from "./task-ref.mjs";
|
|
21
|
+
|
|
22
|
+
/** `--role` の語彙。増やすときは定型文(`ROLE_TEXT`)も同時に足す。 */
|
|
23
|
+
export const BRIEF_ROLES = ["implement", "review", "design"];
|
|
24
|
+
|
|
25
|
+
/** `--worker` の呼び名の形(`HUB_ACTOR` と同じ流儀)。 */
|
|
26
|
+
export const WORKER_PATTERN = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
27
|
+
|
|
28
|
+
/** 依頼書へ写す看板eventの種類と件数(指示書 §3 の節6)。 */
|
|
29
|
+
const REPORT_KINDS = new Set(["reported", "note"]);
|
|
30
|
+
const RECENT_REPORT_LIMIT = 3;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 本文・報告から拾う repo 内の文書(指示書 §4 の正規表現を2本に割ったもの)。
|
|
34
|
+
*
|
|
35
|
+
* **指示書の1本(区切りで始まり空白・閉じ括弧で終わる)では、この repo の文書が1つも拾えない。**
|
|
36
|
+
* `docs/notes/2026-09-20 まとまり(プロジェクトの親子)の実装指示.md` のように、時点記録の名前は
|
|
37
|
+
* **空白も全角括弧も含む**(`docs/notes/` の命名規約が `YYYY-MM-DD タイトル.md` だから)。
|
|
38
|
+
* 拾えないと §8 の見本の「本文が指す文書」が空になり、依頼書の役目が半分消える。
|
|
39
|
+
*
|
|
40
|
+
* そこで書かれ方で分ける。backtick で囲まれていれば**囲みの中を全部**(空白も括弧も名前の一部)、
|
|
41
|
+
* 裸なら空白・閉じ括弧で切る(囲まれていない以上、どこで終わるかは空白でしか分からない)。
|
|
42
|
+
*/
|
|
43
|
+
const DOC_TAIL = "(?:dash\\/)?docs\\/(?:notes|guides|records)\\/";
|
|
44
|
+
const DOC_IN_BACKTICKS = new RegExp(`\`(${DOC_TAIL}[^\`\\n]+\\.md)\``, "g");
|
|
45
|
+
const DOC_BARE = new RegExp(`(?:^|[\\s((「])(${DOC_TAIL}[^\\s\`))」]+\\.md)`, "g");
|
|
46
|
+
|
|
47
|
+
/** 「最初に読むもの」の1行目に指す規約ファイル。両方あれば前者だけを指す。 */
|
|
48
|
+
const READ_FIRST_FILES = ["AGENTS.md", "CLAUDE.md"];
|
|
49
|
+
|
|
50
|
+
/** リンクの並び順(役割ごと)。同じ役割の中は配列順を保つ。 */
|
|
51
|
+
const LINK_ROLE_ORDER = [
|
|
52
|
+
"production", "preview", "admin", "docs", "minutes", "code", "files", "communication", "other",
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
const LINK_ROLE_LABELS = {
|
|
56
|
+
production: "本番",
|
|
57
|
+
preview: "プレビュー",
|
|
58
|
+
admin: "管理画面",
|
|
59
|
+
docs: "資料",
|
|
60
|
+
minutes: "議事録",
|
|
61
|
+
code: "コード",
|
|
62
|
+
files: "ファイル",
|
|
63
|
+
communication: "連絡",
|
|
64
|
+
other: "その他",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** 表示名が分からない値はそのまま出す(語彙が増えてもCLIが先に古びないように)。 */
|
|
68
|
+
const PLATFORM_LABELS = {
|
|
69
|
+
cloudflare_workers: "Workers",
|
|
70
|
+
cloudflare_pages: "Pages",
|
|
71
|
+
vercel: "Vercel",
|
|
72
|
+
netlify: "Netlify",
|
|
73
|
+
xserver: "エックスサーバー",
|
|
74
|
+
other: "その他",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const DEPLOY_STATE_LABELS = {
|
|
78
|
+
running: "運用中",
|
|
79
|
+
stopped: "停止中",
|
|
80
|
+
planned: "予定",
|
|
81
|
+
retired: "廃止",
|
|
82
|
+
unknown: "不明",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// --------------------------------------------------------------------- 純関数
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* アカウント ID の形(境界つきの32桁hex・大文字小文字は問わない)。
|
|
89
|
+
*
|
|
90
|
+
* Cloudflare のアカウント ID は32桁hexで、看板の本文・報告・リンクの URL(`/accounts/<id>/…`)へ
|
|
91
|
+
* 素のまま現れうる。出口の `redactSecrets` が消すのは**設定中の Access 資格情報だけ**なので、
|
|
92
|
+
* 看板から来たアカウント ID はそのまま依頼書へ載っていた(便1 レビュー High)。
|
|
93
|
+
*
|
|
94
|
+
* **境界を見るのは巻き添えを避けるためである。** 前後にhexが続くものは対象外なので、
|
|
95
|
+
* 40桁のcommitハッシュも `cfast_` 始まりの秘密も欠けずに残る(7桁の短縮ハッシュも短すぎて当たらない)。
|
|
96
|
+
*/
|
|
97
|
+
const ACCOUNT_ID_PATTERN = /(?<![0-9a-f])[0-9a-f]{32}(?![0-9a-f])/gi;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 依頼書の出口で**アカウント ID だけ**を消す(`redactSecrets` と同じ置換先を使う)。
|
|
101
|
+
*
|
|
102
|
+
* **効かせるのは `hub task brief` の3経路(Markdown / `--json` / `--out`)だけ**で、
|
|
103
|
+
* `runCli` の出口へは入れない。他のコマンド(`hub infra show` 等)はアカウント ID を
|
|
104
|
+
* **見るための道具**であり、そこまで消すと台帳が読めなくなる。
|
|
105
|
+
*/
|
|
106
|
+
export function redactAccountIds(text) {
|
|
107
|
+
return String(text).replace(ACCOUNT_ID_PATTERN, REDACTED);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function extractDocPaths(text) {
|
|
111
|
+
if (typeof text !== "string" || text === "") return [];
|
|
112
|
+
const found = [];
|
|
113
|
+
for (const pattern of [DOC_IN_BACKTICKS, DOC_BARE]) {
|
|
114
|
+
for (const match of text.matchAll(pattern)) found.push({ at: match.index, path: match[1] });
|
|
115
|
+
}
|
|
116
|
+
// 2本を混ぜるので出現順へ並べ直す(依頼書は本文に出てきた順で並べる)
|
|
117
|
+
found.sort((left, right) => left.at - right.at);
|
|
118
|
+
return uniqueInOrder(found.map((entry) => entry.path));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function uniqueInOrder(values) {
|
|
122
|
+
const seen = new Set();
|
|
123
|
+
const out = [];
|
|
124
|
+
for (const value of values) {
|
|
125
|
+
if (typeof value !== "string" || value === "" || seen.has(value)) continue;
|
|
126
|
+
seen.add(value);
|
|
127
|
+
out.push(value);
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function oneLine(value) {
|
|
133
|
+
return String(value ?? "").replace(/\s+/g, " ").trim();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function textOrNull(value) {
|
|
137
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
138
|
+
return text === "" ? null : text;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 表示用のUTC時刻(ミリ秒は落とす。見本 §8 の `2026-09-20T13:05:00Z`)。 */
|
|
142
|
+
function displayTime(iso) {
|
|
143
|
+
return String(iso ?? "").replace(/\.\d{3}Z$/, "Z");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ----------------------------------------------------------------- 素材の収集
|
|
147
|
+
|
|
148
|
+
async function isPlainFile(absolute, lstatImpl) {
|
|
149
|
+
if (typeof lstatImpl !== "function") return false;
|
|
150
|
+
try {
|
|
151
|
+
const entry = await lstatImpl(absolute);
|
|
152
|
+
if (entry?.isSymbolicLink?.() === true) return false;
|
|
153
|
+
return entry?.isFile?.() === true;
|
|
154
|
+
} catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function collectRepo(contextRef, dependencies) {
|
|
160
|
+
const root = await findRepoRoot(dependencies.cwd(), dependencies.statImpl);
|
|
161
|
+
if (root === null) return { root: null, read_first: null, record_exists: false };
|
|
162
|
+
|
|
163
|
+
let readFirst = null;
|
|
164
|
+
for (const name of READ_FIRST_FILES) {
|
|
165
|
+
if (await isPlainFile(path.join(root, name), dependencies.lstatImpl)) {
|
|
166
|
+
readFirst = name;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let recordExists = false;
|
|
172
|
+
const ref = typeof contextRef === "string" ? contextRef : "";
|
|
173
|
+
const segments = ref.split("/");
|
|
174
|
+
// APIから来た綴りで作業ツリーの外を触らない(`narrowByRepoRecord` と同じ用心)
|
|
175
|
+
if (ref !== "" && !path.isAbsolute(ref) && !segments.includes("..") && !segments.includes("")) {
|
|
176
|
+
recordExists = await isPlainFile(path.join(root, ...segments), dependencies.lstatImpl);
|
|
177
|
+
}
|
|
178
|
+
return { root, read_first: readFirst, record_exists: recordExists };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** 台帳の行から**依頼に要る列だけ**を写す(口座欄はここで落とす)。 */
|
|
182
|
+
function pickAsset(asset) {
|
|
183
|
+
return {
|
|
184
|
+
name: oneLine(asset?.name),
|
|
185
|
+
kind: textOrNull(asset?.kind),
|
|
186
|
+
provider: textOrNull(asset?.provider),
|
|
187
|
+
status: textOrNull(asset?.status),
|
|
188
|
+
management: textOrNull(asset?.management),
|
|
189
|
+
auto_renew: textOrNull(asset?.auto_renew),
|
|
190
|
+
expires_on: textOrNull(asset?.expires_on),
|
|
191
|
+
purpose: textOrNull(asset?.purpose),
|
|
192
|
+
hosted_on: asset?.hosted_on ? { name: oneLine(asset.hosted_on.name) } : null,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** デプロイ先の行。`account_key` は写さない(呼び名 `account_label` で足りる)。 */
|
|
197
|
+
function pickDeployTarget(target) {
|
|
198
|
+
return {
|
|
199
|
+
name: oneLine(target?.name),
|
|
200
|
+
platform: textOrNull(target?.platform),
|
|
201
|
+
account_label: textOrNull(target?.account_label),
|
|
202
|
+
platform_ref: textOrNull(target?.platform_ref),
|
|
203
|
+
target_kind: textOrNull(target?.target_kind),
|
|
204
|
+
state: textOrNull(target?.state),
|
|
205
|
+
url: textOrNull(target?.url),
|
|
206
|
+
repo: textOrNull(target?.repo),
|
|
207
|
+
repo_path: textOrNull(target?.repo_path),
|
|
208
|
+
domain: textOrNull(target?.domain_candidate?.name),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function pickLink(link) {
|
|
213
|
+
return {
|
|
214
|
+
label: oneLine(link?.label),
|
|
215
|
+
url: oneLine(link?.url),
|
|
216
|
+
system: textOrNull(link?.system),
|
|
217
|
+
role: textOrNull(link?.role),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 案件の素材。**引けなければ null を返して warnings へ積む**(依頼書そのものは出す)。
|
|
223
|
+
* 看板の本文が一番大事なので、周辺の素材の失敗で1枚ごと止めない(`resolveTaskProject` と同じ理屈)。
|
|
224
|
+
*/
|
|
225
|
+
async function collectProject(projectName, api, warnings) {
|
|
226
|
+
if (projectName === null) {
|
|
227
|
+
warnings.push("看板に案件が無いので案件の節を省きました");
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let items;
|
|
232
|
+
try {
|
|
233
|
+
const payload = await api("/api/projects");
|
|
234
|
+
if (!Array.isArray(payload?.items)) throw cliError("projects一覧のAPI応答が不正です");
|
|
235
|
+
items = payload.items;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
warnings.push(`案件を引けなかったので案件の節を省きました(${describeFailure(error)})`);
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const found = items.find((entry) => entry?.name === projectName);
|
|
242
|
+
if (found === undefined || typeof found?.slug !== "string") {
|
|
243
|
+
warnings.push(`案件「${oneLine(projectName)}」が一覧に無いので案件の節を省きました`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
let detail;
|
|
248
|
+
try {
|
|
249
|
+
detail = await api(`/api/projects/${encodeURIComponent(found.slug)}`);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
warnings.push(`案件の詳細を引けなかったので案件の節を省きました(${describeFailure(error)})`);
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const item = detail?.item ?? found;
|
|
255
|
+
|
|
256
|
+
let assets = [];
|
|
257
|
+
try {
|
|
258
|
+
const payload = await api(
|
|
259
|
+
`/api/infra/assets?project=${encodeURIComponent(found.slug)}&management=all`,
|
|
260
|
+
);
|
|
261
|
+
assets = Array.isArray(payload?.items) ? payload.items.map(pickAsset) : [];
|
|
262
|
+
} catch (error) {
|
|
263
|
+
warnings.push(`台帳を引けなかったので台帳の小節を省きました(${describeFailure(error)})`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const parentSlug = textOrNull(item?.parent_slug);
|
|
267
|
+
const parent = parentSlug === null
|
|
268
|
+
? null
|
|
269
|
+
: { slug: parentSlug, name: textOrNull(items.find((entry) => entry?.slug === parentSlug)?.name) };
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
slug: found.slug,
|
|
273
|
+
name: oneLine(item?.name),
|
|
274
|
+
kind: textOrNull(item?.kind),
|
|
275
|
+
entity_type: textOrNull(item?.entity_type) ?? "project",
|
|
276
|
+
parent,
|
|
277
|
+
repo: textOrNull(item?.repo),
|
|
278
|
+
memory_home: textOrNull(item?.memory_home),
|
|
279
|
+
links: Array.isArray(item?.links) ? item.links.map(pickLink) : [],
|
|
280
|
+
deploy_targets: Array.isArray(detail?.deploy_targets)
|
|
281
|
+
? detail.deploy_targets.map(pickDeployTarget)
|
|
282
|
+
: [],
|
|
283
|
+
assets,
|
|
284
|
+
children: Array.isArray(detail?.children)
|
|
285
|
+
? detail.children.map((child) => ({
|
|
286
|
+
slug: textOrNull(child?.slug),
|
|
287
|
+
name: oneLine(child?.name),
|
|
288
|
+
status: textOrNull(child?.status),
|
|
289
|
+
}))
|
|
290
|
+
: [],
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 依頼書の素材(指示書 §4)。
|
|
296
|
+
*
|
|
297
|
+
* **看板の取得失敗だけが致命**で、そのまま投げる(依頼書を出さない)。案件・台帳の失敗は
|
|
298
|
+
* `warnings` へ積んで続ける。
|
|
299
|
+
*/
|
|
300
|
+
export async function collectBrief({ ref, id, api, dependencies, options, version, now = new Date() }) {
|
|
301
|
+
const warnings = [];
|
|
302
|
+
const payload = await api(`/api/tasks/${encodeURIComponent(id)}`);
|
|
303
|
+
const item = payload?.item;
|
|
304
|
+
if (item === null || typeof item !== "object" || Array.isArray(item)) {
|
|
305
|
+
throw cliError("タスク詳細のAPI応答が不正です");
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const status = textOrNull(item.status);
|
|
309
|
+
if (status === "done" || status === "iced") {
|
|
310
|
+
warnings.push(`この看板は ${status} です。依頼者に確かめてから着手してもらってください`);
|
|
311
|
+
}
|
|
312
|
+
if (options.role === "review" && options.commits === null) {
|
|
313
|
+
warnings.push("--commits が無いので対象コミットの節は空です");
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const events = Array.isArray(payload?.events) ? payload.events : [];
|
|
317
|
+
const reports = events
|
|
318
|
+
.filter((event) => REPORT_KINDS.has(event?.kind) && textOrNull(event?.note) !== null)
|
|
319
|
+
.sort((left, right) => String(right?.at ?? "").localeCompare(String(left?.at ?? "")))
|
|
320
|
+
.slice(0, RECENT_REPORT_LIMIT)
|
|
321
|
+
.map((event) => ({
|
|
322
|
+
at: textOrNull(event?.at),
|
|
323
|
+
actor: textOrNull(event?.actor),
|
|
324
|
+
kind: textOrNull(event?.kind),
|
|
325
|
+
note: String(event.note),
|
|
326
|
+
}));
|
|
327
|
+
|
|
328
|
+
const contextRef = textOrNull(item.context_ref);
|
|
329
|
+
const task = {
|
|
330
|
+
id: String(item.id ?? id),
|
|
331
|
+
title: oneLine(item.title),
|
|
332
|
+
status,
|
|
333
|
+
owner: textOrNull(item.owner),
|
|
334
|
+
due: textOrNull(item.due),
|
|
335
|
+
project: textOrNull(item.project),
|
|
336
|
+
context_ref: contextRef,
|
|
337
|
+
record_number: recordNumberFromContextRef(contextRef),
|
|
338
|
+
body: typeof item.body === "string" ? item.body : "",
|
|
339
|
+
reports,
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const project = await collectProject(task.project, api, warnings);
|
|
343
|
+
const repo = await collectRepo(contextRef, dependencies);
|
|
344
|
+
|
|
345
|
+
const fromBody = uniqueInOrder(extractDocPaths(task.body));
|
|
346
|
+
const fromReports = uniqueInOrder(reports.flatMap((report) => extractDocPaths(report.note)));
|
|
347
|
+
const docs = uniqueInOrder([...fromBody, ...fromReports]).filter((doc) => doc !== contextRef);
|
|
348
|
+
// 「本文が指す文書」か「本文と報告が指す文書」か(見出しの文言が変わるだけ)
|
|
349
|
+
const docsFromReports = docs.some((doc) => !fromBody.includes(doc));
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
generated_at: now.toISOString(),
|
|
353
|
+
cli_version: version,
|
|
354
|
+
options: {
|
|
355
|
+
ref: String(ref ?? id),
|
|
356
|
+
role: options.role,
|
|
357
|
+
worker: options.worker,
|
|
358
|
+
commits: options.commits,
|
|
359
|
+
sandboxed: options.sandboxed === true,
|
|
360
|
+
note: options.note,
|
|
361
|
+
note_file: options.noteFile ?? null,
|
|
362
|
+
},
|
|
363
|
+
task,
|
|
364
|
+
project,
|
|
365
|
+
repo,
|
|
366
|
+
docs,
|
|
367
|
+
docs_from_reports: docsFromReports,
|
|
368
|
+
warnings,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ------------------------------------------------------------------- 定型文
|
|
373
|
+
|
|
374
|
+
/** 節8「守ること」の共通(指示書 §5.2)。 */
|
|
375
|
+
const KEEP_COMMON = [
|
|
376
|
+
"- 作業ディレクトリの AGENTS.md / CLAUDE.md が repo の規約の正本です。この依頼書と食い違ったら AGENTS.md を信じ、その旨を報告に書きます。",
|
|
377
|
+
"- 共有ファイルは編集の直前に読み直します(並行作業の上書きを防ぐため)。",
|
|
378
|
+
"- コミットは自分が触ったファイルだけを `git add <path>` し、`git commit -- <path>` でパスを指定します。`git add -A` / `git commit -a` は使いません。コミットメッセージの言語と形式は AGENTS.md に従います。",
|
|
379
|
+
"- 既存の型・作法(テストの書き方・エラーの形・ファイルの置き場)に合わせます。新しい依存を足しません。",
|
|
380
|
+
"- 看板の本文と §2 の補足が指示書と食い違ったら、§2 → 本文 → 指示書 の順で優先します。",
|
|
381
|
+
];
|
|
382
|
+
|
|
383
|
+
/** 節9「やってはいけないこと」の共通(指示書 §5.3)。 */
|
|
384
|
+
const FORBID_COMMON = [
|
|
385
|
+
"- git push・デプロイ・リモートの DB への migration 適用・本番データの変更・タグの作成・パッケージの公開。これらは依頼者だけが行います。",
|
|
386
|
+
"- `hub task report` と done への変更(検収は人が行います。報告は §12 の形で依頼者へ)。",
|
|
387
|
+
"- 秘密(トークン・パスワード・アカウント ID・会員 ID)をコード・コミット・記録・報告に書くこと。",
|
|
388
|
+
"- 指示に無い削除・履歴の改変(git reset・rebase -i・force push)。",
|
|
389
|
+
"- 他の作業者が doing にしている看板への着手。",
|
|
390
|
+
];
|
|
391
|
+
|
|
392
|
+
/** `--sandboxed` のとき節1の末尾に足す段落(指示書 §5.4)。 */
|
|
393
|
+
const SANDBOXED_PARAGRAPH =
|
|
394
|
+
"この環境は hub の API に届かず、commit できないことがあります。hub CLI は使いません"
|
|
395
|
+
+ "(看板の本文はこの依頼書の §5 に入っています)。記録への追記は commit できなければ"
|
|
396
|
+
+ "ファイルに書くだけで構いません(依頼者が代わりにコミットします)。看板への報告(note / report)も"
|
|
397
|
+
+ "依頼者が代行するので、最終報告は §12 の形で依頼者へ返してください。";
|
|
398
|
+
|
|
399
|
+
const ROLE_TEXT = {
|
|
400
|
+
implement: {
|
|
401
|
+
title: "実装担当",
|
|
402
|
+
lead: "あなたは <worker>(実装担当)です。",
|
|
403
|
+
guidance: "設計の正本が本文か §4 の文書にあれば、そのとおりに実装します。迷ったら本文の「決まっていること」を優先し、それでも決められないことは記録に「未確認」と書いて先へ進みます。",
|
|
404
|
+
claim: true,
|
|
405
|
+
keep: [
|
|
406
|
+
"- 依頼の範囲より広げません。迷ったら「やらないこと」へ送り、記録に書きます。",
|
|
407
|
+
"- パッケージの版(version)を上げません(公開は依頼者が行います)。",
|
|
408
|
+
],
|
|
409
|
+
forbid: [],
|
|
410
|
+
verify: true,
|
|
411
|
+
},
|
|
412
|
+
review: {
|
|
413
|
+
title: "最終レビュー担当",
|
|
414
|
+
lead: "あなたは <worker>(最終レビュー担当)です。コードは直しません。",
|
|
415
|
+
guidance: "対象は §3 のコミットです。設計の正本と看板の本文(裁定を含む)に照らして、受け入れ条件が1つずつコードとテストで裏が取れているかを見ます。取れていない条件は「未担保」と書きます。",
|
|
416
|
+
claim: false,
|
|
417
|
+
keep: [
|
|
418
|
+
"- 所見は 重要度(High / Medium / Low)・該当ファイル:行・理由・直し方 の形で書きます。",
|
|
419
|
+
"- 疑わしい変異は1〜2本、自分で当てて再現します(テストが本当に落ちるか)。",
|
|
420
|
+
"- 最後に「approve」か「差し戻し(High の件数)」を1行で明記します。",
|
|
421
|
+
],
|
|
422
|
+
forbid: ["- コードを直すこと(所見を書くだけ。直すのは実装者です)。"],
|
|
423
|
+
verify: true,
|
|
424
|
+
},
|
|
425
|
+
design: {
|
|
426
|
+
title: "設計担当",
|
|
427
|
+
lead: "あなたは <worker>(設計担当)です。コードは書きません。",
|
|
428
|
+
guidance: "成果物は実装指示(docs/notes/ の時点記録)で、実装者が読むだけで着手できる粒度にします。",
|
|
429
|
+
claim: true,
|
|
430
|
+
keep: [
|
|
431
|
+
"- 事実(コードの該当行・実測)と決定を分けて書き、推測は「未確認」と明記します。",
|
|
432
|
+
"- 実装者が迷いそうな点には指示書の中で答えを決めておきます。",
|
|
433
|
+
],
|
|
434
|
+
forbid: [],
|
|
435
|
+
verify: false,
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
/** 節10「検証」(指示書 §5.6)。 */
|
|
440
|
+
function verifyLines(role) {
|
|
441
|
+
return [
|
|
442
|
+
"検証コマンドは AGENTS.md の「検証コマンド」と、本文・指示書の検証節が正です(この依頼書には写しません)。",
|
|
443
|
+
"- 全部通してから報告します。落ちたものは落ちたまま報告し、直したふりをしません。",
|
|
444
|
+
role === "review"
|
|
445
|
+
? "- 依頼者が指す検証コマンドを自分でも回し、件数(pass / fail)を所見に書きます。"
|
|
446
|
+
: "- 本文や指示書に変異表があれば、1つずつ当ててテストが落ちることを確かめ、結果を記録に書きます。",
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** 節11「記録に書くこと」(指示書 §5.7)。 */
|
|
451
|
+
function recordLine(role, contextRef, worker) {
|
|
452
|
+
if (contextRef === null) {
|
|
453
|
+
return "依頼者が指す記録へ書きます(無ければ `hub task new --repo-card` で作る、と依頼者に確かめてください)。";
|
|
454
|
+
}
|
|
455
|
+
if (role === "implement") {
|
|
456
|
+
return `記録 \`${contextRef}\` に「## 便N 実装(${worker})」の節を足し、変更ファイル・指示書との差分(理由つき)・検証の結果・変異表の結果・やらなかったこと・未計測を書きます。frontmatter の related_commits にコミットのハッシュを足します(記録の書き方は AGENTS.md と docs/records/README.md)。`;
|
|
457
|
+
}
|
|
458
|
+
if (role === "review") {
|
|
459
|
+
return `記録 \`${contextRef}\` の末尾に「## 便N レビュー(${worker})」の節を足し、結論(High / Medium / Low の件数)・所見・受け入れ条件の照合表・検証の件数を書きます。`;
|
|
460
|
+
}
|
|
461
|
+
return `成果物は docs/notes/<日付> <題>.md(時点記録。書いたら更新しない)。記録 \`${contextRef}\` に判断の要点を書きます。`;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** 節12「最終報告」(指示書 §5.8)。 */
|
|
465
|
+
function reportLines(worker) {
|
|
466
|
+
return [
|
|
467
|
+
"依頼者への最終報告は次の形で、行数は 5 行以内:",
|
|
468
|
+
`1行目: 「実作業: ${worker}」と結論(何をしたか・approve / 差し戻し)`,
|
|
469
|
+
"2行目〜: コミットのハッシュ(あれば)、検証の件数、指示書との差分、未確認・未計測、依頼者に聞く点",
|
|
470
|
+
];
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// ------------------------------------------------------------------- 整形
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* claim の行(指示書 §5.5)。
|
|
477
|
+
*
|
|
478
|
+
* `--sandboxed` のときは**行の後ろに代行の一文を足す**。付けないと、sandboxed の依頼書で
|
|
479
|
+
* 「hub CLI は使いません」(§5.4)と「着手前に `hub task claim` で claim します」が同居し、
|
|
480
|
+
* 受け取った相手が打てないコマンドを指示されたまま止まる(便1 レビュー Medium)。
|
|
481
|
+
*/
|
|
482
|
+
function claimLine(task, worker, workerRef, sandboxed) {
|
|
483
|
+
const status = task.status;
|
|
484
|
+
const relay = sandboxed ? "(この環境から claim できなければ依頼者が代行します)" : "";
|
|
485
|
+
if ((status === "doing" || status === "review") && task.owner !== null) {
|
|
486
|
+
return `この看板は ${task.owner} 名義で ${status} です。claim し直しません(claim は doing / review を拒否します)。`
|
|
487
|
+
+ `着手したら看板の note の冒頭に「実作業: ${worker}」と書きます。${relay}`;
|
|
488
|
+
}
|
|
489
|
+
if (status === "inbox" || status === "ready") {
|
|
490
|
+
return `この看板はまだ ${status} です。着手前に \`hub task claim ${task.id} --owner ${workerRef}\` で claim します。${relay}`;
|
|
491
|
+
}
|
|
492
|
+
return "";
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function invocation(options) {
|
|
496
|
+
const parts = ["hub task brief", options.ref, "--role", options.role];
|
|
497
|
+
if (options.worker !== null) parts.push("--worker", options.worker);
|
|
498
|
+
if (options.commits !== null) parts.push("--commits", JSON.stringify(options.commits));
|
|
499
|
+
if (options.note_file !== null) parts.push("--note-file", options.note_file);
|
|
500
|
+
else if (options.note !== null) parts.push("--note", "…");
|
|
501
|
+
if (options.sandboxed) parts.push("--sandboxed");
|
|
502
|
+
return parts.join(" ");
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function readFirstLines(material, worker) {
|
|
506
|
+
const lines = [];
|
|
507
|
+
const root = material.repo.root;
|
|
508
|
+
const where = root === null ? "作業ディレクトリ" : `作業ディレクトリ ${root}`;
|
|
509
|
+
if (material.repo.read_first === null) {
|
|
510
|
+
lines.push(`${where} に \`AGENTS.md\` / \`CLAUDE.md\` があれば最初に読みます(repo の規約の正本)`);
|
|
511
|
+
} else {
|
|
512
|
+
lines.push(`\`${material.repo.read_first}\`(${where} の規約の正本。Read Order もここ)`);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (!material.options.sandboxed) {
|
|
516
|
+
const cd = root === null ? "" : `\`cd ${root}\` → `;
|
|
517
|
+
lines.push(
|
|
518
|
+
`認証と名乗り: ${cd}\`set -a && source ~/.config/tamai/hub-tasks.env && set +a\` → \`export HUB_ACTOR=${worker}\``,
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
lines.push("看板の本文は §5(この依頼書に全文があります)");
|
|
523
|
+
|
|
524
|
+
const ref = material.task.context_ref;
|
|
525
|
+
if (ref !== null) {
|
|
526
|
+
if (material.task.record_number === null) {
|
|
527
|
+
lines.push(`参照: ${ref}`);
|
|
528
|
+
} else {
|
|
529
|
+
lines.push(`記録: \`${ref}\`(${material.repo.record_exists ? "手元にあり" : "手元に無ければ pull する"})`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (material.docs.length > 0) {
|
|
534
|
+
const label = material.docs_from_reports ? "本文と報告が指す文書" : "本文が指す文書";
|
|
535
|
+
lines.push(`${label}: ${material.docs.map((doc) => `\`${doc}\``).join("、")}`);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const project = material.project;
|
|
539
|
+
if (project !== null && (project.repo !== null || project.memory_home !== null)) {
|
|
540
|
+
const home = project.repo === null ? "(repo の登録なし)" : `\`${project.repo}\``;
|
|
541
|
+
const where2 = project.memory_home === "vault"
|
|
542
|
+
? "記憶は Vault 側。repo に記録を置きません"
|
|
543
|
+
: "記録はこの repo の `docs/records/`";
|
|
544
|
+
lines.push(`記憶の家: ${home}(${where2})`);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return lines.map((line, index) => `${index + 1}. ${line}`);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function projectSection(project) {
|
|
551
|
+
const lines = [];
|
|
552
|
+
const kind = project.kind === null ? "" : `・${project.kind}`;
|
|
553
|
+
const shape = project.entity_type === "group" ? "グループ" : "案件";
|
|
554
|
+
const home = project.repo === null
|
|
555
|
+
? (project.memory_home === null ? "" : `・記憶の家 ${project.memory_home}`)
|
|
556
|
+
: `・記憶の家 \`${project.repo}\`(${project.memory_home ?? "?"})`;
|
|
557
|
+
lines.push(`${project.name}(\`${project.slug}\`${kind}・${shape})${home}`);
|
|
558
|
+
if (project.parent !== null) {
|
|
559
|
+
lines.push(`グループ: ${project.parent.name ?? "(名前を引けず)"}(\`${project.parent.slug}\`)`);
|
|
560
|
+
}
|
|
561
|
+
if (project.children.length > 0) {
|
|
562
|
+
lines.push(
|
|
563
|
+
`配下の案件 ${project.children.length} 件: ${project.children.map((child) => `\`${child.slug}\``).join("、")}`,
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (project.links.length > 0) {
|
|
568
|
+
const ordered = [...project.links].sort((left, right) => {
|
|
569
|
+
const leftIndex = LINK_ROLE_ORDER.indexOf(left.role ?? "other");
|
|
570
|
+
const rightIndex = LINK_ROLE_ORDER.indexOf(right.role ?? "other");
|
|
571
|
+
return (leftIndex === -1 ? LINK_ROLE_ORDER.length : leftIndex)
|
|
572
|
+
- (rightIndex === -1 ? LINK_ROLE_ORDER.length : rightIndex);
|
|
573
|
+
});
|
|
574
|
+
lines.push("", "リンク(役割ごと):");
|
|
575
|
+
for (const link of ordered) {
|
|
576
|
+
const label = LINK_ROLE_LABELS[link.role ?? "other"] ?? link.role ?? "その他";
|
|
577
|
+
lines.push(`- ${label}: ${link.label} — ${link.url}`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (project.deploy_targets.length > 0) {
|
|
582
|
+
lines.push("", "デプロイ先:");
|
|
583
|
+
for (const target of project.deploy_targets) {
|
|
584
|
+
const platform = PLATFORM_LABELS[target.platform] ?? target.platform ?? "?";
|
|
585
|
+
const account = target.account_label ?? "?";
|
|
586
|
+
const ref = target.platform_ref === null ? "(未照合)" : `\`${target.platform_ref}\``;
|
|
587
|
+
const state = DEPLOY_STATE_LABELS[target.state] ?? target.state ?? "?";
|
|
588
|
+
const parts = [`- ${target.name} — ${platform} / ${account} / ${ref} / ${state}`];
|
|
589
|
+
if (target.url !== null) parts.push(target.url);
|
|
590
|
+
if (target.repo !== null) {
|
|
591
|
+
parts.push(`コード ${target.repo}${target.repo_path === null ? "" : ` ${target.repo_path}`}`);
|
|
592
|
+
}
|
|
593
|
+
if (target.domain !== null) parts.push(`台帳の候補: ${target.domain}`);
|
|
594
|
+
lines.push(parts.join(" — "));
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (project.assets.length > 0) {
|
|
599
|
+
lines.push("", "台帳の資産:");
|
|
600
|
+
for (const asset of project.assets) {
|
|
601
|
+
const meta = [
|
|
602
|
+
asset.kind ?? "?",
|
|
603
|
+
asset.provider ?? "?",
|
|
604
|
+
asset.status ?? "?",
|
|
605
|
+
`自動更新 ${asset.auto_renew ?? "?"}`,
|
|
606
|
+
`期限 ${asset.expires_on ?? "なし"}`,
|
|
607
|
+
].join("・");
|
|
608
|
+
const external = asset.management === "external" ? "(他社管理)" : "";
|
|
609
|
+
const purpose = asset.purpose === null ? "" : ` — ${asset.purpose}`;
|
|
610
|
+
const hosted = asset.hosted_on === null ? "" : ` — ${asset.hosted_on.name} 上`;
|
|
611
|
+
lines.push(`- ${asset.name}(${meta})${external}${purpose}${hosted}`);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return lines;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* 依頼書のMarkdown(純関数。時刻も版も素材に入っている)。
|
|
620
|
+
*
|
|
621
|
+
* **節の番号は固定**(1〜12)で、出ない節はその番号ごと飛ばす。依頼書の中で「§5 の本文」と
|
|
622
|
+
* 指すので、role によって番号がずれると参照が壊れる。
|
|
623
|
+
*/
|
|
624
|
+
export function renderBrief(material) {
|
|
625
|
+
const { task, options } = material;
|
|
626
|
+
const role = ROLE_TEXT[options.role];
|
|
627
|
+
const worker = options.worker ?? "(呼び名は依頼者から受け取ります)";
|
|
628
|
+
// コマンドや引用の中では括弧書きが読めないので、埋める語を分ける
|
|
629
|
+
const workerRef = options.worker ?? "<自分の呼び名>";
|
|
630
|
+
const out = [];
|
|
631
|
+
|
|
632
|
+
const recordLabel = task.record_number === null ? null : `記録 ${task.record_number}`;
|
|
633
|
+
out.push(`# 依頼書: ${task.title}`, "");
|
|
634
|
+
out.push(
|
|
635
|
+
[`看板 ${task.id}`, recordLabel, `生成 \`${invocation(options)}\``]
|
|
636
|
+
.filter((part) => part !== null)
|
|
637
|
+
.join(" ・ ")
|
|
638
|
+
+ `(${displayTime(material.generated_at)}・hub-cli ${material.cli_version})`,
|
|
639
|
+
);
|
|
640
|
+
|
|
641
|
+
if (task.status === "done" || task.status === "iced") {
|
|
642
|
+
out.push("", "## 0. 注意", "");
|
|
643
|
+
out.push(`注意: この看板は ${task.status} です。依頼者に確かめてから着手してください。`);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
out.push("", "## 1. あなたの役割", "");
|
|
647
|
+
const claim = role.claim ? claimLine(task, worker, workerRef, options.sandboxed) : "";
|
|
648
|
+
// `--worker` が無いときの差し込みは括弧書きなので、前の空白ごと差し替える(「あなたは (…」を避ける)
|
|
649
|
+
const lead = role.lead.replace(" <worker>", options.worker === null ? worker : ` ${worker}`);
|
|
650
|
+
out.push(`${lead}${claim === "" ? "" : claim}`);
|
|
651
|
+
out.push(role.guidance);
|
|
652
|
+
if (options.sandboxed) out.push("", SANDBOXED_PARAGRAPH);
|
|
653
|
+
|
|
654
|
+
if (options.note !== null) {
|
|
655
|
+
out.push("", "## 2. 依頼者の補足(本文・指示書より優先)", "");
|
|
656
|
+
out.push(options.note.replace(/\s+$/, ""));
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
if (options.commits !== null) {
|
|
660
|
+
out.push("", "## 3. 対象コミット", "");
|
|
661
|
+
out.push(`${options.commits}(\`git show\` で差分を読みます)`);
|
|
662
|
+
} else if (options.role === "review") {
|
|
663
|
+
out.push("", "## 3. 対象コミット", "");
|
|
664
|
+
out.push("対象コミットは依頼者から受け取る(`git log --oneline` で確かめる)。");
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
out.push("", "## 4. 最初に読むもの", "");
|
|
668
|
+
out.push(...readFirstLines(material, workerRef));
|
|
669
|
+
|
|
670
|
+
out.push("", "## 5. 看板の本文", "");
|
|
671
|
+
out.push(
|
|
672
|
+
`status: ${task.status ?? "なし"} ・ owner: ${task.owner ?? "なし"}`
|
|
673
|
+
+ ` ・ due: ${task.due ?? "なし"} ・ context_ref: ${task.context_ref ?? "なし"}`,
|
|
674
|
+
);
|
|
675
|
+
out.push("", task.body.replace(/\s+$/, ""));
|
|
676
|
+
|
|
677
|
+
if (task.reports.length > 0) {
|
|
678
|
+
out.push("", "## 6. 看板の直近の報告", "");
|
|
679
|
+
for (const report of task.reports) {
|
|
680
|
+
out.push(`- ${displayTime(report.at) || "?"} ${report.actor ?? "?"}(${report.kind ?? "?"})`);
|
|
681
|
+
for (const line of report.note.replace(/\s+$/, "").split("\n")) out.push(` ${line}`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (material.project !== null) {
|
|
686
|
+
out.push("", "## 7. 案件", "");
|
|
687
|
+
out.push(...projectSection(material.project));
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
out.push("", "## 8. 守ること", "");
|
|
691
|
+
out.push(...KEEP_COMMON, ...role.keep);
|
|
692
|
+
|
|
693
|
+
out.push("", "## 9. やってはいけないこと", "");
|
|
694
|
+
out.push(...FORBID_COMMON, ...role.forbid);
|
|
695
|
+
|
|
696
|
+
if (role.verify) {
|
|
697
|
+
out.push("", "## 10. 検証", "");
|
|
698
|
+
out.push(...verifyLines(options.role));
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
out.push("", "## 11. 記録に書くこと", "");
|
|
702
|
+
out.push(recordLine(options.role, task.context_ref, workerRef));
|
|
703
|
+
|
|
704
|
+
out.push("", "## 12. 最終報告", "");
|
|
705
|
+
out.push(...reportLines(workerRef));
|
|
706
|
+
|
|
707
|
+
return `${out.join("\n").replace(/\n{3,}/g, "\n\n")}\n`;
|
|
708
|
+
}
|
package/lib/cli.mjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// (Astra High 1・実測: 実体パス447 byte / symlink 0 byte)。入口は `bin/hub.mjs` 専用にして、
|
|
14
14
|
// 比較そのものを無くしてある。このファイルはライブラリとしてだけ読まれる。
|
|
15
15
|
|
|
16
|
-
import { lstat, mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
16
|
+
import { lstat, mkdir, readdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
ApiError,
|
|
@@ -43,6 +43,7 @@ import { projectShowCommand } from "../commands/project-show.mjs";
|
|
|
43
43
|
import { projectUpdateCommand } from "../commands/project-update.mjs";
|
|
44
44
|
import { taskAddCommand } from "../commands/task-add.mjs";
|
|
45
45
|
import { taskAuditCommand } from "../commands/task-audit.mjs";
|
|
46
|
+
import { taskBriefCommand } from "../commands/task-brief.mjs";
|
|
46
47
|
import { taskClaimCommand } from "../commands/task-claim.mjs";
|
|
47
48
|
import { taskListCommand } from "../commands/task-list.mjs";
|
|
48
49
|
import { taskNewCommand } from "../commands/task-new.mjs";
|
|
@@ -51,7 +52,9 @@ import { taskNoteCommand } from "../commands/task-note.mjs";
|
|
|
51
52
|
import { taskReportCommand } from "../commands/task-report.mjs";
|
|
52
53
|
import { taskShowCommand } from "../commands/task-show.mjs";
|
|
53
54
|
import { defaultRunGit } from "./git.mjs";
|
|
55
|
+
import { packageVersion } from "./version.mjs";
|
|
54
56
|
|
|
57
|
+
export { packageVersion } from "./version.mjs";
|
|
55
58
|
export { configFromEnv, createHubApi } from "./api.mjs";
|
|
56
59
|
export { defaultEnvFilePath, parseEnvFile } from "./api.mjs";
|
|
57
60
|
export { projectLines } from "./format.mjs";
|
|
@@ -75,6 +78,7 @@ const COMMAND_GROUPS = {
|
|
|
75
78
|
commands: commandMap([
|
|
76
79
|
taskAddCommand,
|
|
77
80
|
taskAuditCommand,
|
|
81
|
+
taskBriefCommand,
|
|
78
82
|
taskClaimCommand,
|
|
79
83
|
taskListCommand,
|
|
80
84
|
taskNewCommand,
|
|
@@ -106,23 +110,6 @@ const COMMAND_GROUPS = {
|
|
|
106
110
|
},
|
|
107
111
|
};
|
|
108
112
|
|
|
109
|
-
/**
|
|
110
|
-
* 配布されている版(`packages/hub-cli/package.json` の `version`)。
|
|
111
|
-
*
|
|
112
|
-
* **`import.meta.url` 基準で読む。** cwd 基準にすると `npm i -g` した bin をどこから
|
|
113
|
-
* 呼ぶかで値が変わる(=どの hub が入っているのか確かめる道具にならない)。
|
|
114
|
-
* スキル側は「`command not found` なら `npm i -g`」だけでは古い CLI が残る場合を扱えないので、
|
|
115
|
-
* 対応版の確認はこの値で行う(Astra B-4-4)。
|
|
116
|
-
*/
|
|
117
|
-
export async function packageVersion(readFileImpl = readFile) {
|
|
118
|
-
const raw = await readFileImpl(new URL("../package.json", import.meta.url), "utf8");
|
|
119
|
-
const parsed = JSON.parse(raw);
|
|
120
|
-
if (typeof parsed.version !== "string" || parsed.version === "") {
|
|
121
|
-
throw cliError("package.json に version がありません");
|
|
122
|
-
}
|
|
123
|
-
return parsed.version;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
113
|
async function execute(argv, dependencies, onConfig) {
|
|
127
114
|
const [group, ...rest] = argv;
|
|
128
115
|
if (group === undefined || group === "help" || group === "--help" || group === "-h") {
|
|
@@ -191,10 +178,16 @@ export async function runCli(argv, overrides = {}) {
|
|
|
191
178
|
statImpl: overrides.statImpl ?? stat,
|
|
192
179
|
// symlink を追わない版。記録ファイルの実在確認はこちらを使う(記録153・codex1 Medium 1)
|
|
193
180
|
lstatImpl: overrides.lstatImpl ?? lstat,
|
|
181
|
+
// 書き込み先の実体。`--out` の追跡検査を字面ではなく実体に対して行うのに要る(記録183 便1 レビュー)
|
|
182
|
+
realpathImpl: overrides.realpathImpl ?? realpath,
|
|
194
183
|
cwd: overrides.cwd ?? (() => process.cwd()),
|
|
195
184
|
runGitImpl: overrides.runGitImpl ?? defaultRunGit,
|
|
196
185
|
stdout: guarded(overrides.stdout ?? process.stdout),
|
|
197
186
|
stderr: guarded(overrides.stderr ?? process.stderr),
|
|
187
|
+
// **出口を通らない経路のための同じ関数**(記録183)。`hub task brief --out` が書くファイルは
|
|
188
|
+
// stdout / stderr を通らないので、コマンドが書く直前に自分で通す。config はコマンドから
|
|
189
|
+
// 見えないため、ここで閉じ込めて渡す。**新しい出力先を足すときだけ使うこと。**
|
|
190
|
+
redact: (text) => redactSecrets(text, redaction.config),
|
|
198
191
|
};
|
|
199
192
|
|
|
200
193
|
try {
|
package/lib/format.mjs
CHANGED
|
@@ -51,6 +51,14 @@ export function projectLines(project, { includeLinks = false } = {}) {
|
|
|
51
51
|
else if (project.default_agent) lines.push(`agents: -(既定 ${project.default_agent})`);
|
|
52
52
|
if (project.last_activity_at) lines.push(`last_activity: ${project.last_activity_at}`);
|
|
53
53
|
if (project.kind && project.kind !== "work") lines.push(`kind: ${project.kind}`);
|
|
54
|
+
// 種類とグループ(記録180)。`kind` と同じ流儀で**既定でないときだけ**出す
|
|
55
|
+
// ——案件で親なしの行に毎回2行足すと、一覧が読みにくくなる。
|
|
56
|
+
// `children` は0件でも出す(「グループなのに空」が分かる。画面の帯と同じ)。
|
|
57
|
+
if (project.entity_type === "group") {
|
|
58
|
+
lines.push("type: group");
|
|
59
|
+
lines.push(`children: ${Number(project.children_count ?? 0)}`);
|
|
60
|
+
}
|
|
61
|
+
if (project.parent_slug) lines.push(`parent: ${project.parent_slug}`);
|
|
54
62
|
if (project.repo) lines.push(`repo: ${project.repo}`);
|
|
55
63
|
if (project.memory_home) lines.push(`memory: ${project.memory_home}`);
|
|
56
64
|
if (project.auto_policy && project.auto_policy !== "off") lines.push(`auto: ${project.auto_policy}`);
|
|
@@ -66,6 +74,35 @@ export function projectLines(project, { includeLinks = false } = {}) {
|
|
|
66
74
|
return lines;
|
|
67
75
|
}
|
|
68
76
|
|
|
77
|
+
/**
|
|
78
|
+
* `hub project show` の `deploy:` の1行(記録181・指示書 §5)。
|
|
79
|
+
*
|
|
80
|
+
* - 予約サイト [vercel/tamaitakamasa] discover-fuke running https://… (domain: fuke.example?)
|
|
81
|
+
*
|
|
82
|
+
* `platform_ref` が無ければ `(未照合)`——空文字にすると「名前が無い」ように見えて、
|
|
83
|
+
* 「まだ突き合わせていない」という事実が消える。台帳は**候補**なので `?` を付ける
|
|
84
|
+
* (links の `role?` と同じ流儀)。`url` と `repo` は無ければ省く。
|
|
85
|
+
*/
|
|
86
|
+
function deployLine(target) {
|
|
87
|
+
const name = String(target?.name ?? "").replace(/\s+/g, " ").trim();
|
|
88
|
+
const platform = String(target?.platform ?? "").trim();
|
|
89
|
+
const account = String(target?.account_label ?? target?.account_key ?? "").trim();
|
|
90
|
+
const ref = typeof target?.platform_ref === "string" && target.platform_ref.trim() !== ""
|
|
91
|
+
? target.platform_ref.trim()
|
|
92
|
+
: "(未照合)";
|
|
93
|
+
const parts = [name, `[${platform}/${account}]`, ref, String(target?.state ?? "").trim()];
|
|
94
|
+
const url = typeof target?.url === "string" ? target.url.trim() : "";
|
|
95
|
+
if (url !== "") parts.push(url);
|
|
96
|
+
const repo = typeof target?.repo === "string" ? target.repo.trim() : "";
|
|
97
|
+
if (repo !== "") {
|
|
98
|
+
const repoPath = typeof target?.repo_path === "string" ? target.repo_path.trim() : "";
|
|
99
|
+
parts.push(`repo: ${repo}${repoPath === "" ? "" : ` ${repoPath}`}`);
|
|
100
|
+
}
|
|
101
|
+
const domain = target?.domain_candidate;
|
|
102
|
+
if (domain && typeof domain.name === "string") parts.push(`(domain: ${domain.name}?)`);
|
|
103
|
+
return parts.filter((part) => part !== "").join(" ");
|
|
104
|
+
}
|
|
105
|
+
|
|
69
106
|
/**
|
|
70
107
|
* `[system/role]` の印(指示 §5.6)。role がWorkerの候補(`role_inferred: true`)なら `?` を付ける。
|
|
71
108
|
* 印が付かないのは system も role も無いときだけ —— 旧いAPIの応答をそのまま読めるようにしてある。
|
|
@@ -117,6 +154,21 @@ export function printProjectResult(payload, json, stdout, kind) {
|
|
|
117
154
|
}
|
|
118
155
|
const lines = projectLines(payload.item, { includeLinks: kind === "show" });
|
|
119
156
|
if (kind === "update") lines.push(`updated_tasks: ${payload.updated_tasks}`);
|
|
157
|
+
// 配下の案件(記録180)。`show` の応答にだけ載るので、あるときだけ並べる。
|
|
158
|
+
// 1行の形は `list` の見出し行と同じ(`<slug> [<status>] <name>`)
|
|
159
|
+
const children = Array.isArray(payload.children) ? payload.children : [];
|
|
160
|
+
if (children.length > 0) {
|
|
161
|
+
lines.push("children:");
|
|
162
|
+
for (const child of children) {
|
|
163
|
+
lines.push(`- ${child.slug} [${child.status}] ${child.name}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// デプロイ先(記録181)。`children:` の後・`activity:` の前。対象が無ければ行ごと出ない
|
|
167
|
+
const deployTargets = kind === "show" && Array.isArray(payload.deploy_targets) ? payload.deploy_targets : [];
|
|
168
|
+
if (deployTargets.length > 0) {
|
|
169
|
+
lines.push("deploy:");
|
|
170
|
+
for (const target of deployTargets) lines.push(`- ${deployLine(target)}`);
|
|
171
|
+
}
|
|
120
172
|
const activity = Array.isArray(payload.activity) ? payload.activity : [];
|
|
121
173
|
if (activity.length > 0) {
|
|
122
174
|
lines.push("", "activity:");
|
package/lib/version.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
import { cliError } from "./args.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 配布されている版(`packages/hub-cli/package.json` の `version`)。
|
|
7
|
+
*
|
|
8
|
+
* **`import.meta.url` 基準で読む。** cwd 基準にすると `npm i -g` した bin をどこから
|
|
9
|
+
* 呼ぶかで値が変わる(=どの hub が入っているのか確かめる道具にならない)。
|
|
10
|
+
* スキル側は「`command not found` なら `npm i -g`」だけでは古い CLI が残る場合を扱えないので、
|
|
11
|
+
* 対応版の確認はこの値で行う(Astra B-4-4)。
|
|
12
|
+
*
|
|
13
|
+
* **`lib/cli.mjs` から分けてある。** `commands/task-brief.mjs` が依頼書の見出しへ版を書くのに
|
|
14
|
+
* これを要るが、コマンドが `lib/cli.mjs` を import すると循環(cli → commands → cli)になる。
|
|
15
|
+
* `lib/cli.mjs` は互換のためここを再輸出する。
|
|
16
|
+
*/
|
|
17
|
+
export async function packageVersion(readFileImpl = readFile) {
|
|
18
|
+
const raw = await readFileImpl(new URL("../package.json", import.meta.url), "utf8");
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
if (typeof parsed.version !== "string" || parsed.version === "") {
|
|
21
|
+
throw cliError("package.json に version がありません");
|
|
22
|
+
}
|
|
23
|
+
return parsed.version;
|
|
24
|
+
}
|