@tamai/hub-cli 0.1.7 → 0.1.9
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 +58 -3
- package/commands/infra-note.mjs +114 -0
- package/commands/infra-update.mjs +32 -3
- package/commands/task-brief.mjs +165 -0
- package/lib/args.mjs +22 -4
- package/lib/brief.mjs +708 -0
- package/lib/cli.mjs +14 -19
- package/lib/format.mjs +42 -3
- package/lib/ulid.mjs +26 -0
- package/lib/version.mjs +24 -0
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
//
|
|
5
5
|
// hub task <verb> ... タスク操作
|
|
6
6
|
// hub project <verb> ... プロジェクト操作(読み取り + 作成・更新)
|
|
7
|
-
// hub infra <verb> ... インフラ資産操作(読み取り +
|
|
7
|
+
// hub infra <verb> ... インフラ資産操作(読み取り + 更新・経緯・紐付け)
|
|
8
8
|
//
|
|
9
9
|
// 全サブコマンドが `--json` を受け付け、付けると生のAPI応答をそのまま出力する。
|
|
10
10
|
//
|
|
@@ -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,
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
} from "./args.mjs";
|
|
34
34
|
import { infraLinkCommand } from "../commands/infra-link.mjs";
|
|
35
35
|
import { infraListCommand } from "../commands/infra-list.mjs";
|
|
36
|
+
import { infraNoteCommand } from "../commands/infra-note.mjs";
|
|
36
37
|
import { infraShowCommand } from "../commands/infra-show.mjs";
|
|
37
38
|
import { infraUnlinkCommand } from "../commands/infra-unlink.mjs";
|
|
38
39
|
import { infraUpdateCommand } from "../commands/infra-update.mjs";
|
|
@@ -43,6 +44,7 @@ import { projectShowCommand } from "../commands/project-show.mjs";
|
|
|
43
44
|
import { projectUpdateCommand } from "../commands/project-update.mjs";
|
|
44
45
|
import { taskAddCommand } from "../commands/task-add.mjs";
|
|
45
46
|
import { taskAuditCommand } from "../commands/task-audit.mjs";
|
|
47
|
+
import { taskBriefCommand } from "../commands/task-brief.mjs";
|
|
46
48
|
import { taskClaimCommand } from "../commands/task-claim.mjs";
|
|
47
49
|
import { taskListCommand } from "../commands/task-list.mjs";
|
|
48
50
|
import { taskNewCommand } from "../commands/task-new.mjs";
|
|
@@ -51,7 +53,9 @@ import { taskNoteCommand } from "../commands/task-note.mjs";
|
|
|
51
53
|
import { taskReportCommand } from "../commands/task-report.mjs";
|
|
52
54
|
import { taskShowCommand } from "../commands/task-show.mjs";
|
|
53
55
|
import { defaultRunGit } from "./git.mjs";
|
|
56
|
+
import { packageVersion } from "./version.mjs";
|
|
54
57
|
|
|
58
|
+
export { packageVersion } from "./version.mjs";
|
|
55
59
|
export { configFromEnv, createHubApi } from "./api.mjs";
|
|
56
60
|
export { defaultEnvFilePath, parseEnvFile } from "./api.mjs";
|
|
57
61
|
export { projectLines } from "./format.mjs";
|
|
@@ -75,6 +79,7 @@ const COMMAND_GROUPS = {
|
|
|
75
79
|
commands: commandMap([
|
|
76
80
|
taskAddCommand,
|
|
77
81
|
taskAuditCommand,
|
|
82
|
+
taskBriefCommand,
|
|
78
83
|
taskClaimCommand,
|
|
79
84
|
taskListCommand,
|
|
80
85
|
taskNewCommand,
|
|
@@ -100,29 +105,13 @@ const COMMAND_GROUPS = {
|
|
|
100
105
|
infraListCommand,
|
|
101
106
|
infraShowCommand,
|
|
102
107
|
infraUpdateCommand,
|
|
108
|
+
infraNoteCommand,
|
|
103
109
|
infraLinkCommand,
|
|
104
110
|
infraUnlinkCommand,
|
|
105
111
|
]),
|
|
106
112
|
},
|
|
107
113
|
};
|
|
108
114
|
|
|
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
115
|
async function execute(argv, dependencies, onConfig) {
|
|
127
116
|
const [group, ...rest] = argv;
|
|
128
117
|
if (group === undefined || group === "help" || group === "--help" || group === "-h") {
|
|
@@ -191,10 +180,16 @@ export async function runCli(argv, overrides = {}) {
|
|
|
191
180
|
statImpl: overrides.statImpl ?? stat,
|
|
192
181
|
// symlink を追わない版。記録ファイルの実在確認はこちらを使う(記録153・codex1 Medium 1)
|
|
193
182
|
lstatImpl: overrides.lstatImpl ?? lstat,
|
|
183
|
+
// 書き込み先の実体。`--out` の追跡検査を字面ではなく実体に対して行うのに要る(記録183 便1 レビュー)
|
|
184
|
+
realpathImpl: overrides.realpathImpl ?? realpath,
|
|
194
185
|
cwd: overrides.cwd ?? (() => process.cwd()),
|
|
195
186
|
runGitImpl: overrides.runGitImpl ?? defaultRunGit,
|
|
196
187
|
stdout: guarded(overrides.stdout ?? process.stdout),
|
|
197
188
|
stderr: guarded(overrides.stderr ?? process.stderr),
|
|
189
|
+
// **出口を通らない経路のための同じ関数**(記録183)。`hub task brief --out` が書くファイルは
|
|
190
|
+
// stdout / stderr を通らないので、コマンドが書く直前に自分で通す。config はコマンドから
|
|
191
|
+
// 見えないため、ここで閉じ込めて渡す。**新しい出力先を足すときだけ使うこと。**
|
|
192
|
+
redact: (text) => redactSecrets(text, redaction.config),
|
|
198
193
|
};
|
|
199
194
|
|
|
200
195
|
try {
|
package/lib/format.mjs
CHANGED
|
@@ -284,10 +284,49 @@ export function printInfraResult(payload, json, stdout, kind) {
|
|
|
284
284
|
const lines = infraAssetLines(payload?.item);
|
|
285
285
|
if (kind === "show" && Array.isArray(payload?.events) && payload.events.length > 0) {
|
|
286
286
|
lines.push("", "events:");
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
287
|
+
// **5件で切らない**(記録188 §3.5)。経緯が読みものになった以上、直近5件では
|
|
288
|
+
// 「いつ何があったか」が追えない。1件ずつは120文字で切るので行数だけが増える
|
|
289
|
+
for (const event of payload.events) {
|
|
290
|
+
const summary = infraEventSummary(event);
|
|
291
|
+
const body = summary === "" ? "" : ` — ${summary}`;
|
|
292
|
+
// `edited` の `note` は更新の理由。`noted` / `legacy_note` の `note` は本文なので、
|
|
293
|
+
// そちらは `body` に出ている(二重に出さない)
|
|
294
|
+
const reason = event?.kind === "edited" && event.note ? `(理由: ${shortened(event.note)})` : "";
|
|
295
|
+
lines.push(`- ${displayValue(event?.at)} ${displayValue(event?.kind)} (${displayValue(event?.actor)})${body}${reason}`);
|
|
290
296
|
}
|
|
291
297
|
}
|
|
292
298
|
stdout.write(`${lines.join("\n")}\n`);
|
|
293
299
|
}
|
|
300
|
+
|
|
301
|
+
/** 経緯1行の本文の上限。`legacy_note` は5,000文字まで在りうるので、行の密度を守って切る。 */
|
|
302
|
+
const INFRA_EVENT_BODY_LIMIT = 120;
|
|
303
|
+
|
|
304
|
+
function shortened(text, limit = INFRA_EVENT_BODY_LIMIT) {
|
|
305
|
+
const body = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
306
|
+
return body.length > limit ? `${body.slice(0, limit)}…` : body;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 経緯1件の要約(記録188 §3.5)。
|
|
311
|
+
*
|
|
312
|
+
* - `noted` / `legacy_note` … `note` 列が本文なのでそのまま(120文字で切る)
|
|
313
|
+
* - `edited` … `meta.fields` を `status: to_cancel → active` の形で1行に
|
|
314
|
+
* (`note` は理由なので呼び出し側が末尾へ回す)
|
|
315
|
+
* - `created` / `synced` … 出す本文が無い(`meta` は作成時の全列なので行に収まらない)
|
|
316
|
+
*/
|
|
317
|
+
function infraEventSummary(event) {
|
|
318
|
+
if (event?.kind === "noted" || event?.kind === "legacy_note") return shortened(event.note);
|
|
319
|
+
if (event?.kind !== "edited") return "";
|
|
320
|
+
const meta = event.meta;
|
|
321
|
+
if (meta === null || typeof meta !== "object" || Array.isArray(meta)) return "";
|
|
322
|
+
const fields = Array.isArray(meta.fields) ? meta.fields.filter((field) => typeof field === "string") : [];
|
|
323
|
+
const omitted = new Set(Array.isArray(meta.omitted) ? meta.omitted : []);
|
|
324
|
+
const from = meta.from ?? {};
|
|
325
|
+
const to = meta.to ?? {};
|
|
326
|
+
return fields
|
|
327
|
+
.map((field) => (omitted.has(field)
|
|
328
|
+
// `note` は監査metaへ値を積まない列なので、変わったことだけを出す
|
|
329
|
+
? `${field}: 変更あり`
|
|
330
|
+
: `${field}: ${formatEventValue(from[field])} → ${formatEventValue(to[field])}`))
|
|
331
|
+
.join(" / ");
|
|
332
|
+
}
|
package/lib/ulid.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ULIDの採番(Crockford Base32の26文字)。CLIが**操作ID**を作るのに使う。
|
|
3
|
+
*
|
|
4
|
+
* Worker・SPA は `@hub/shared/ulid` を使うが、**CLIはそこをimportしない**——
|
|
5
|
+
* `@tamai/hub-cli` は依存ゼロのnpmパッケージで、repo内の workspace パッケージを
|
|
6
|
+
* 抱えると配布物が壊れる(AGENTS.md「CLIの実体はここだけ」)。採番の挙動は共有側と同じ
|
|
7
|
+
* (ミリ秒10文字+乱数16文字)にしてあるが、**CLIが作るのは自分が送るIDだけ**なので、
|
|
8
|
+
* 共有側の実装が変わっても突き合わせる必要は無い。
|
|
9
|
+
*
|
|
10
|
+
* 用途は「同じ操作を二重に積まないための識別子」で、並び順には使わない
|
|
11
|
+
* (同一ミリ秒内では辞書順が生成順にならない。共有側と同じ制約)。
|
|
12
|
+
*/
|
|
13
|
+
const ULID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
14
|
+
|
|
15
|
+
export function newUlid(date = new Date()) {
|
|
16
|
+
let timestamp = date.getTime();
|
|
17
|
+
let prefix = "";
|
|
18
|
+
for (let index = 0; index < 10; index += 1) {
|
|
19
|
+
prefix = ULID_ALPHABET[timestamp % 32] + prefix;
|
|
20
|
+
timestamp = Math.floor(timestamp / 32);
|
|
21
|
+
}
|
|
22
|
+
const random = crypto.getRandomValues(new Uint8Array(16));
|
|
23
|
+
let suffix = "";
|
|
24
|
+
for (const value of random) suffix += ULID_ALPHABET[value & 31];
|
|
25
|
+
return prefix + suffix;
|
|
26
|
+
}
|
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
|
+
}
|