@tamai/hub-cli 0.1.8 → 0.1.10

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 CHANGED
@@ -68,7 +68,7 @@ hub infra help
68
68
 
69
69
  動詞は `task` が `new` / `add` / `claim` / `next` / `show` / `report` / `note` / `list` / `audit` / `brief`、
70
70
  `project` が `list` / `show` / `create` / `update` / `move`、
71
- `infra` が `list` / `show` / `update` / `link` / `unlink`。
71
+ `infra` が `list` / `show` / `update` / `note` / `link` / `unlink`。
72
72
  **正確なオプションは常に `--help` を見る**(ここにも、スキルにも写経しない)。
73
73
  全動詞が `--json` を受ける。機械が読むときは必ず `--json` を使い、人向けの整形を parse しない。
74
74
 
@@ -156,8 +156,14 @@ hub task brief 183 --role review --worker codex1 --out /tmp/brief-183.md --sandb
156
156
  hub infra list # 自分で管理する資産だけ(既定)
157
157
  hub infra list --management all # 他社管理を含む全件
158
158
  hub infra show example.jp
159
- hub infra update example.jp --status to_cancel --append-note '解約申請済み'
159
+ hub infra update example.jp --status to_cancel --reason '11/30までに解約と決めた'
160
160
  hub infra update example.jp --prod-platform none # 本番の置き場なし(確定値)
161
+ hub infra update example.jp --renew-source bundled --bundle-server motokura
162
+ hub infra update example.jp --transfer-to cloudflare --transfer-stage awaiting_approval \
163
+ --transfer-due 2026-09-26T11:00:00+09:00
164
+ hub infra note example.jp --note 'Xserverのパネルで自動更新onを確認'
165
+ hub infra note example.jp --note-file /tmp/note.md
166
+ hub infra note example.jp --note '…' --operation-id 01M33H236V8MACB2DFR641ATK3 # 送り直し
161
167
  hub infra link example.jp --project hub
162
168
  hub infra unlink example.jp --project hub
163
169
  hub infra unlink example.jp # 紐付けを全部外す
@@ -168,6 +174,42 @@ hub infra unlink example.jp # 紐付けを全部外す
168
174
  1回だけ再試行する。`link` は現在の紐付けへ追加、`unlink` は指定分を削除し、APIへはどちらも
169
175
  `PUT /:id/projects` の全置換として送る。
170
176
 
177
+ `--renew-source` は更新の**方式**(`paid` / `bundled`)で、`--auto-renew`(確認できた更新状態)とは
178
+ **別の軸**である。特典ドメインでも `on` には化けない——特典元のサーバー契約が解約されれば更新は止まる。
179
+ `--bundle-server` は特典元のサーバーで、`bundled` のときだけ持てる(`--hosted-on` と同じく名前かIDで指定する)。
180
+ 収容先(どのサーバーに乗っているか)とは別の事実なので、一致しない行がある。
181
+
182
+ `--transfer-to` / `--transfer-stage` / `--transfer-due` は移管の進み。段階は
183
+ `requested` / `awaiting_approval` / `approved` / `rejected` / `cancelled` で、`rejected` と `cancelled` は
184
+ `provider` を変えない(移管しなかった)。`--transfer-due` は**時刻を含む** ISO 8601 だけを受ける。
185
+ 移管の完了は `--provider <移管先> --transfer-to none --transfer-stage none --transfer-due none` を
186
+ 1回で送る(移管先が残ったまま `--provider` を変えると400)。
187
+ **移管の3項目を含む更新は409で自動再送しない**(`--reason` と同じ扱い。段階は人が申請・承認メールを
188
+ 見て書く値なので、取り直して自分の古い認識で巻き戻さない)。
189
+ 特典元にしているドメインがあるサーバーは、`hub infra` からは消せない(APIが409で拒む)。
190
+
191
+ `note` は台帳の**経緯**を1件足す(`POST /:id/notes`)。資産の `version` を進めないので、
192
+ 画面を開いたまま追記しても、そのあとの保存が競合しない。本文は2,000文字までで**分割しない**
193
+ (`hub task note` と違い、長い本文は要点へ縮める。旧メモの原文保管はCLIでは行わない)。
194
+ 操作ID(ULID)は**1操作につき1つ**をCLIが作り、送信の前に決める。応答が返る前に通信が
195
+ 切れた失敗だけ、**同じ操作IDで1回だけ**送り直す——届いていた場合はAPIがその操作IDを見て
196
+ 既存のイベントを返すので、二重に積まれない。応答が返った失敗(400 / 409 など)は
197
+ サーバが答えているので再試行しない。
198
+
199
+ 失敗すると `操作ID: <ULID>` を出す。後から送り直すときは、素で打ち直さず
200
+ `--operation-id <ULID>` にその値を渡す(素の打ち直しは別の操作IDになるので、
201
+ 1回目が届いていた場合に2件積まれる)。
202
+
203
+ ```bash
204
+ hub infra note example.jp --note '…' --operation-id 01M33H236V8MACB2DFR641ATK3
205
+ ```
206
+
207
+ `update --reason <text>` は**その更新の理由**(500文字まで)で、列ではなく監査イベントへ入る。
208
+ 値の変更と一緒に指定する(理由だけの更新は400。経緯は `hub infra note`)。
209
+ **`--reason` を含む更新は409で自動再送しない**——理由は読んだ状態に依存するので、
210
+ 最新を確認して書き直す。`--append-note` は**次の版で外す**(使うと stderr へ予告が出る)。
211
+ 「現在の補足」を上書きする `--note` は残り、経緯は `note` 動詞へ分かれる。
212
+
171
213
  `--dns-host` / `--mail-host` / `--migration-plan` / `--contract` / `--hosted-on-basis`は
172
214
  `none`で未記入(`null`)へ戻せる。`--prod-platform none`だけは「本番の置き場は無い」という
173
215
  確定済みのenum値を送り、未記入には戻さない。
@@ -0,0 +1,114 @@
1
+ import { ApiError, withGuidance } from "../lib/api.mjs";
2
+ import { requireSinglePositional, usageError } from "../lib/args.mjs";
3
+ import { resolveInfraAssetId } from "../lib/infra.mjs";
4
+ import { newUlid } from "../lib/ulid.mjs";
5
+
6
+ /** APIの上限(`MAX_NOTE_TEXT`)と同じ。**分割しない**ので超えたら送らずに案内する。 */
7
+ export const INFRA_NOTE_LIMIT = 2_000;
8
+
9
+ /** 操作IDの形(`newUlid` が作る26文字のCrockford Base32)。`--operation-id` の受理判定。 */
10
+ const OPERATION_ID_PATTERN = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
11
+
12
+ /**
13
+ * 通信の結果が**分からない**失敗か(codex2レビュー High 1)。
14
+ *
15
+ * `fetch` が応答を返す前に落ちた失敗は、「届いていない」と「届いたが応答を失った」の
16
+ * 区別が付かない。一方、応答が返った失敗——`ApiError`(4xx / 5xx)と「JSONでない応答」
17
+ * (`cliError` なので `code === "cli_error"`)——はサーバが答えているので、同じ本文を
18
+ * 打ち直しても同じ答えになる。再試行するのは前者だけ。
19
+ */
20
+ function isUnknownOutcome(error) {
21
+ return !(error instanceof ApiError) && error?.code !== "cli_error";
22
+ }
23
+
24
+ function operationIdFrom(value) {
25
+ const id = String(value ?? "").trim().toUpperCase();
26
+ if (!OPERATION_ID_PATTERN.test(id)) {
27
+ throw usageError(
28
+ "--operation-id にはULID(26文字のCrockford Base32)を指定してください。"
29
+ + "前回の失敗が出した「操作ID: …」の値をそのまま渡します",
30
+ );
31
+ }
32
+ return id;
33
+ }
34
+
35
+ /**
36
+ * 失敗のときに**操作IDを必ず出す**(codex2レビュー High 1)。
37
+ *
38
+ * 届いたかどうか分からないまま素で打ち直すと別の操作IDになり、届いていた場合に2件積まれる。
39
+ * 人が同じ操作として送り直せるように、idと `--operation-id` の使い方を添える。
40
+ */
41
+ function operationGuidance(operationId, unknownOutcome) {
42
+ const line = `操作ID: ${operationId}`;
43
+ if (!unknownOutcome) return line;
44
+ return `${line}\n`
45
+ + "届いたかどうかは分かりません(応答の前に通信が切れ、同じ操作IDでの再送も失敗しました)。\n"
46
+ + `送り直すときは --operation-id ${operationId} を付けてください(届いていれば二重に積まれません)。`;
47
+ }
48
+
49
+ /**
50
+ * 同じ操作ID・同じbodyで最大2回送る(codex2レビュー High 1)。
51
+ *
52
+ * 2回目を送るのは**結果が不明な失敗**のときだけ。1回目がD1へ届いていた場合は、
53
+ * APIが同じ操作IDを見て200で既存のイベントを返す(`NOT EXISTS` のガード)ので、
54
+ * 2件目は積まれない。
55
+ */
56
+ async function postNote(api, assetId, init, operationId) {
57
+ const requestPath = `/api/infra/assets/${encodeURIComponent(assetId)}/notes`;
58
+ try {
59
+ return await api(requestPath, init);
60
+ } catch (error) {
61
+ if (!isUnknownOutcome(error)) throw withGuidance(error, operationGuidance(operationId, false));
62
+ try {
63
+ return await api(requestPath, init);
64
+ } catch (retryError) {
65
+ throw withGuidance(retryError, operationGuidance(operationId, isUnknownOutcome(retryError)));
66
+ }
67
+ }
68
+ }
69
+
70
+ /**
71
+ * 経緯を1件足す(記録188 §3.5)。
72
+ *
73
+ * `hub task note` と違って**分割しない**。看板のnoteは同じタスクに何件積んでも読めるが、
74
+ * 台帳の経緯は「1件=1つの事実」で読むもので、機械的に切ると意味の単位が壊れる。
75
+ * 長すぎるものは人が要点へ縮める(原文の保管は `legacy_note`=便Dの口の仕事)。
76
+ *
77
+ * 操作IDは**1操作につき1回だけ**作り、再試行でも使い回す。同じidの再送はAPIが200で
78
+ * 既存イベントを返すので、通信が切れて結果が分からないときも二重に積まれない。
79
+ * 人が後から送り直すときは `--operation-id <ULID>`(失敗時のメッセージに出る)。
80
+ */
81
+ export const infraNoteCommand = {
82
+ name: "note",
83
+ options: { allowed: ["note", "note-file", "operation-id"] },
84
+ async run({ options, positional, flags, dependencies, api }) {
85
+ const reference = requireSinglePositional(positional, "資産名またはid");
86
+ if (flags.note && flags["note-file"]) throw usageError("--note と --note-file は同時に指定できません");
87
+ const source = flags["note-file"]
88
+ ? await dependencies.readFileImpl(options["note-file"], "utf8")
89
+ : options.note;
90
+ const text = String(source ?? "").trim();
91
+ if (text === "") throw usageError("--note か --note-file を指定してください");
92
+ if (text.length > INFRA_NOTE_LIMIT) {
93
+ throw usageError(
94
+ `経緯は${INFRA_NOTE_LIMIT}文字までです(${text.length}文字)。`
95
+ + "分割せずに要点へ縮めてください(旧メモの原文保管はCLIでは行いません)",
96
+ );
97
+ }
98
+
99
+ // 操作IDは**送信の外で1回だけ**決める。POSTの直前で作ると、応答を失った1回目と
100
+ // 2回目が別のidになり、届いていた場合に2件積まれる(codex2レビュー High 1)
101
+ const operationId = flags["operation-id"] ? operationIdFrom(options["operation-id"]) : newUlid();
102
+
103
+ const id = await resolveInfraAssetId(reference, api);
104
+ const payload = await postNote(api, id, {
105
+ method: "POST",
106
+ body: JSON.stringify({ id: operationId, text }),
107
+ }, operationId);
108
+ if (options.json) {
109
+ dependencies.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
110
+ return;
111
+ }
112
+ dependencies.stdout.write(`経緯を1件追加しました(${payload?.event?.id ?? "-"})。\n`);
113
+ },
114
+ };
@@ -28,15 +28,54 @@ const OPTION_FIELDS = {
28
28
  "account-ref": "account_ref",
29
29
  note: "note",
30
30
  "hosted-on-basis": "hosted_on_basis",
31
+ // 特典と移管(記録191 / migration 0029)。`--bundle-server` だけは名前解決が要るので
32
+ // ここには入れず、`--hosted-on` と同じ扱いで別に処理する
33
+ "renew-source": "renew_source",
34
+ "transfer-to": "transfer_to",
35
+ "transfer-stage": "transfer_stage",
36
+ "transfer-due": "transfer_due_at",
31
37
  };
32
38
 
33
- const ALLOWED_OPTIONS = [...Object.keys(OPTION_FIELDS), "append-note", "hosted-on"];
39
+ const ALLOWED_OPTIONS = [
40
+ ...Object.keys(OPTION_FIELDS), "append-note", "hosted-on", "reason", "bundle-server",
41
+ ];
42
+
43
+ /**
44
+ * 移管の3項目を含む更新は **409 で自動再送しない**(所見 Medium 2・記録191)。
45
+ *
46
+ * 理由(`--reason`)と同じ扱いである。移管は「いまどこまで進んだか」を人が外の出来事
47
+ * (申請・承認メール・authcode)を見て書く列で、取り直して送り直すと**他人が進めた段階を
48
+ * 自分の古い認識で巻き戻す**。`--renew-source` / `--bundle-server` は現在値に依存しない
49
+ * ので再送してよい。
50
+ */
51
+ const TRANSFER_OPTIONS = ["transfer-to", "transfer-stage", "transfer-due"];
52
+ const TRANSFER_CONFLICT_GUIDANCE =
53
+ "移管の更新は自動で再送しません。最新の段階を確認してからもう一度実行してください";
54
+
55
+ /**
56
+ * `--append-note` は次の版で外す(記録188 §3.5)。既存noteの末尾へ「 / 」で足す作りは、
57
+ * 「現在の補足」と「経緯」を1つの列に混ぜる——経緯は `hub infra note` が別の表へ積む。
58
+ * 打つたびに出す(1回だけの告知だと、使い続けている人には届かない)。
59
+ */
60
+ const APPEND_NOTE_DEPRECATION =
61
+ "警告: --append-note は次の版で外します。経緯は hub infra note <name|id> --note <text> へ。\n";
62
+
63
+ /**
64
+ * 理由は**読んだ状態に依存する**ので、409で自動的に取り直して再送しない(所見 Medium 2)。
65
+ * 「A を B にした理由」を書いたあとに他人が A を C へ変えていたら、その理由はもう合わない。
66
+ */
67
+ const REASON_CONFLICT_GUIDANCE =
68
+ "理由つきの更新は自動で再送しません。最新の内容を確認し、理由を書き直してからもう一度実行してください";
34
69
  const NULLABLE_VALUE_OPTIONS = new Set([
35
70
  "dns-host",
36
71
  "mail-host",
37
72
  "migration-plan",
38
73
  "contract",
39
74
  "hosted-on-basis",
75
+ "renew-source",
76
+ "transfer-to",
77
+ "transfer-stage",
78
+ "transfer-due",
40
79
  ]);
41
80
 
42
81
  function amountValue(value) {
@@ -47,12 +86,13 @@ function amountValue(value) {
47
86
  return parsed;
48
87
  }
49
88
 
50
- function bodyFor(current, prepared, appendNote) {
89
+ function bodyFor(current, prepared, appendNote, reason) {
51
90
  const body = { version: requireInfraVersion(current), ...prepared };
52
91
  if (appendNote !== null) {
53
92
  const note = typeof current.note === "string" ? current.note.trim() : "";
54
93
  body.note = note === "" ? appendNote : `${note} / ${appendNote}`;
55
94
  }
95
+ if (reason !== null) body.reason = reason;
56
96
  return body;
57
97
  }
58
98
 
@@ -67,6 +107,16 @@ export const infraUpdateCommand = {
67
107
  if (flags.note && flags["append-note"]) {
68
108
  throw usageError("--note と --append-note は同時に指定できません");
69
109
  }
110
+ // 理由だけの更新はAPIが400にする(経緯は `hub infra note`)。往復する前にここで案内する
111
+ let reason = null;
112
+ if (flags.reason) {
113
+ if (!ALLOWED_OPTIONS.some((name) => name !== "reason" && flags[name])) {
114
+ throw usageError("--reason は値の変更と一緒に指定してください(経緯だけを足すときは hub infra note)");
115
+ }
116
+ reason = options.reason.trim();
117
+ if (reason === "") throw usageError("--reason に空文字は指定できません");
118
+ }
119
+ if (flags["append-note"]) dependencies.stderr.write(APPEND_NOTE_DEPRECATION);
70
120
 
71
121
  let currentPayload = await getInfraAsset(reference, api);
72
122
  let current = currentPayload.item;
@@ -103,16 +153,35 @@ export const infraUpdateCommand = {
103
153
  }
104
154
  }
105
155
 
156
+ // 特典元も server の名前かidで指定する(`--hosted-on` と同じ解決。記録191)
157
+ if (flags["bundle-server"]) {
158
+ const bundleReference = options["bundle-server"].trim();
159
+ if (bundleReference === "none") {
160
+ prepared.bundle_server = null;
161
+ } else {
162
+ const bundle = await getInfraAsset(bundleReference, api, { kind: "server" });
163
+ if (bundle.item.kind !== "server") throw cliError("--bundle-server にはserver資産の名前またはidを指定してください");
164
+ prepared.bundle_server = bundle.item.id;
165
+ }
166
+ }
167
+
106
168
  for (let attempt = 0; attempt < 2; attempt += 1) {
107
169
  try {
108
170
  const payload = await api(`/api/infra/assets/${encodeURIComponent(current.id)}`, {
109
171
  method: "PATCH",
110
- body: JSON.stringify(bodyFor(current, prepared, appendNote)),
172
+ body: JSON.stringify(bodyFor(current, prepared, appendNote, reason)),
111
173
  });
112
174
  printInfraResult(payload, options.json, dependencies.stdout, "update");
113
175
  return;
114
176
  } catch (error) {
115
177
  if (!isConflictError(error)) throw error;
178
+ // 理由つきは取り直して送り直さない。**書いた理由が古い前提のままになる**ので、
179
+ // 人が最新を読んで理由を書き直す(所見 Medium 2・記録188 §3.5)
180
+ if (reason !== null) throw withGuidance(error, REASON_CONFLICT_GUIDANCE);
181
+ // 移管も同じ(記録191)。段階は外の出来事を見て人が書く値なので巻き戻さない
182
+ if (TRANSFER_OPTIONS.some((name) => flags[name])) {
183
+ throw withGuidance(error, TRANSFER_CONFLICT_GUIDANCE);
184
+ }
116
185
  if (attempt === 1) {
117
186
  throw withGuidance(error, "再取得後にも競合しました。最新の内容を確認してから、もう一度実行してください");
118
187
  }
package/lib/args.mjs CHANGED
@@ -118,7 +118,15 @@ export const INFRA_USAGE = `使い方:
118
118
  [--account <text>] [--account-ref <text>]
119
119
  [--note <text>] [--append-note <text>]
120
120
  [--hosted-on <server name|id>|none]
121
- [--hosted-on-basis <value>|none] [--json]
121
+ [--hosted-on-basis <value>|none]
122
+ [--renew-source paid|bundled|none]
123
+ [--bundle-server <server name|id>|none]
124
+ [--transfer-to <provider>|none]
125
+ [--transfer-stage <stage>|none]
126
+ [--transfer-due <ISO8601>|none]
127
+ [--reason <text>] [--json]
128
+ hub infra note <name|id> (--note <text> | --note-file <path>)
129
+ [--operation-id <ULID>] [--json]
122
130
  hub infra link <name|id> --project <slug> [--project <slug>]... [--json]
123
131
  hub infra unlink <name|id> [--project <slug>]... [--json]
124
132
 
@@ -126,9 +134,30 @@ export const INFRA_USAGE = `使い方:
126
134
  list の --status はカンマ区切りで複数指定できる。
127
135
  show / update / link / unlink の資産は名前の完全一致またはidで指定する。
128
136
  update は指定した項目だけを更新する。version競合時は最新を取り直して1回だけ再試行する。
129
- --append-note は既存noteの末尾へ「 / 」で追記する。
137
+ --reason は更新の理由(500文字まで)。値の変更と一緒に指定する(理由だけの更新はできない)。
138
+ **--reason を含む更新は409で自動再送しない**(理由は読んだ状態に依存するため、
139
+ 最新を確認して書き直す)。
140
+ --append-note は既存noteの末尾へ「 / 」で追記する。**次の版で外す**(経緯は note へ)。
141
+ note は台帳の経緯を1件足す(2,000文字まで・分割しない)。noteは資産のversionを進めない
142
+ ので、シートを開いたまま追記しても、その後の保存が競合しない。
143
+ --note-file はファイルの中身をそのまま1件として送る(超過分は切らずにエラーにする)。
144
+ --renew-source は更新の方式(paid=自分で払う / bundled=サーバー契約の特典)。
145
+ --bundle-server は特典元のサーバー(--renew-source bundled のときだけ持てる)。
146
+ **--auto-renew は別の軸**で、特典でも on には化けない(確認できた更新状態を書く)。
147
+ --transfer-to / --transfer-stage / --transfer-due は移管の進み。段階は
148
+ requested / awaiting_approval / approved / rejected / cancelled。
149
+ --transfer-due は時刻を含むISO 8601(例 2026-09-26T11:00:00+09:00)。日付だけは受け付けない。
150
+ 移管の完了は「--provider <移管先> --transfer-to none --transfer-stage none --transfer-due none」を
151
+ 1回で送る(移管先が残ったまま --provider を変えると400)。
152
+ **移管の3項目を含む更新は409で自動再送しない**(--reason と同じ。段階は人が外の出来事を
153
+ 見て書く値なので、取り直して巻き戻さない)。
154
+ note の操作IDは1操作につき1つ。応答の前に通信が切れた失敗だけ、**同じIDで1回だけ**
155
+ 送り直す(届いていればAPIが既存のイベントを返すので二重に積まれない)。
156
+ 失敗すると「操作ID: …」を出すので、後から送り直すときは --operation-id <ULID> に
157
+ その値を渡す(素で打ち直すと別の操作になり、届いていた場合は2件積まれる)。
130
158
  server資産には dns-host / mail-host / migration-plan / hosted-on / hosted-on-basis /
131
- prod-platform / prod-ref を指定できない。
159
+ prod-platform / prod-ref / renew-source / bundle-server / transfer-to / transfer-stage /
160
+ transfer-due を指定できない。
132
161
  link は現在の紐付けへ追加し、unlink は指定分を外す。unlink の --project 省略は全解除。
133
162
  作成・削除はCLIから行えない。
134
163
  オプションは --name=value の形でも書ける(値が -- で始まるときはこの形で渡す)。
@@ -139,7 +168,7 @@ export const USAGE = `使い方:
139
168
  hub task help
140
169
  hub project <verb> ... プロジェクト操作(list / show / create / update / move)
141
170
  hub project help
142
- hub infra <verb> ... インフラ資産操作(list / show / update / link / unlink)
171
+ hub infra <verb> ... インフラ資産操作(list / show / update / note / link / unlink)
143
172
  hub infra help
144
173
  hub --version 入っているCLIの版を出す(hub version も同じ)
145
174
 
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
  //
@@ -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";
@@ -104,6 +105,7 @@ const COMMAND_GROUPS = {
104
105
  infraListCommand,
105
106
  infraShowCommand,
106
107
  infraUpdateCommand,
108
+ infraNoteCommand,
107
109
  infraLinkCommand,
108
110
  infraUnlinkCommand,
109
111
  ]),
package/lib/format.mjs CHANGED
@@ -228,6 +228,34 @@ function remainingDays(expiresOn, now = new Date()) {
228
228
  return `残${days}日`;
229
229
  }
230
230
 
231
+ /**
232
+ * 特典の印(記録191)。`bundled` の行だけに出す。特典元が未確定なら**そう書く**
233
+ * ——「特典」だけだと、更新が誰の契約に乗っているか分からないまま安心してしまう。
234
+ */
235
+ function bundleMark(item) {
236
+ if (item?.renew_source !== "bundled") return "";
237
+ const server = item?.bundle_server;
238
+ const name = server === null || server === undefined ? "" : oneLineValue(server.name);
239
+ return name === "" ? " [特典:元サーバー未確定]" : ` [特典:${name}]`;
240
+ }
241
+
242
+ /**
243
+ * 移管中の印(記録191)。`rejected` / `cancelled` は「移管しなかった」なので
244
+ * 移管先を出さない——出すと、まだ動いているように読める。
245
+ */
246
+ function transferMark(item) {
247
+ const stage = item?.transfer_stage;
248
+ if (stage === null || stage === undefined) return "";
249
+ if (stage === "rejected") return " [移管:却下]";
250
+ if (stage === "cancelled") return " [移管:中止]";
251
+ const due = item?.transfer_due_at ? ` 期限${oneLineValue(item.transfer_due_at)}` : "";
252
+ return ` [移管→${displayValue(item?.transfer_to)}:${displayValue(stage)}${due}]`;
253
+ }
254
+
255
+ function oneLineValue(value) {
256
+ return String(value ?? "").replace(/\s+/g, " ").trim();
257
+ }
258
+
231
259
  export function infraListLine(item, now = new Date()) {
232
260
  const projects = Array.isArray(item?.projects)
233
261
  ? item.projects.map((project) => displayValue(project?.slug)).filter((slug) => slug !== "-")
@@ -238,9 +266,9 @@ export function infraListLine(item, now = new Date()) {
238
266
  `[${displayValue(item?.kind)}]`,
239
267
  `provider:${displayValue(item?.provider)}`,
240
268
  `status:${displayValue(item?.status)}`,
241
- `auto-renew:${displayValue(item?.auto_renew)}`,
269
+ `auto-renew:${displayValue(item?.auto_renew)}${bundleMark(item)}`,
242
270
  `expires:${displayValue(item?.expires_on)} (${remainingDays(item?.expires_on, now)})`,
243
- `projects:${projects.join(",") || "-"}${external}`,
271
+ `projects:${projects.join(",") || "-"}${external}${transferMark(item)}`,
244
272
  ].join(" ");
245
273
  }
246
274
 
@@ -248,7 +276,8 @@ export function infraAssetLines(item) {
248
276
  const fields = [
249
277
  "id", "provider", "status", "management", "auto_renew", "expires_on", "purpose",
250
278
  "dns_host", "mail_host", "migration_plan", "hosted_on_basis", "prod_platform", "prod_ref",
251
- "contract", "amount_yen", "payer", "holder", "account", "account_ref", "note", "version",
279
+ "contract", "amount_yen", "payer", "holder", "account", "account_ref", "note",
280
+ "renew_source", "transfer_to", "transfer_stage", "transfer_due_at", "version",
252
281
  "created_at", "updated_at",
253
282
  ];
254
283
  const lines = [`${displayValue(item?.name)} [${displayValue(item?.kind)}]`];
@@ -259,6 +288,15 @@ export function infraAssetLines(item) {
259
288
  : `${displayValue(item.hosted_on.name)} (${displayValue(item.hosted_on.id)})`;
260
289
  lines.splice(11, 0, `hosted_on: ${hosted}`);
261
290
  }
291
+ // 特典元は名前とid、そして**特典元の契約の状態**を添える(記録191)。
292
+ // 依存警告の根拠(解約予定・期限)を人が同じ行で読めるようにする
293
+ if (item?.bundle_server !== undefined) {
294
+ const bundle = item.bundle_server === null
295
+ ? "-"
296
+ : `${displayValue(item.bundle_server.name)} (${displayValue(item.bundle_server.id)})`
297
+ + ` status:${displayValue(item.bundle_server_status)} expires:${displayValue(item.bundle_server_expires_on)}`;
298
+ lines.push(`bundle_server: ${bundle}`);
299
+ }
262
300
  const projects = Array.isArray(item?.projects)
263
301
  ? item.projects.map((project) => `${displayValue(project?.slug)}(${displayValue(project?.name)})`)
264
302
  : [];
@@ -284,10 +322,49 @@ export function printInfraResult(payload, json, stdout, kind) {
284
322
  const lines = infraAssetLines(payload?.item);
285
323
  if (kind === "show" && Array.isArray(payload?.events) && payload.events.length > 0) {
286
324
  lines.push("", "events:");
287
- for (const event of payload.events.slice(0, 5)) {
288
- const note = event?.note ? ` — ${displayValue(event.note)}` : "";
289
- lines.push(`- ${displayValue(event?.at)} ${displayValue(event?.kind)} (${displayValue(event?.actor)})${note}`);
325
+ // **5件で切らない**(記録188 §3.5)。経緯が読みものになった以上、直近5件では
326
+ // 「いつ何があったか」が追えない。1件ずつは120文字で切るので行数だけが増える
327
+ for (const event of payload.events) {
328
+ const summary = infraEventSummary(event);
329
+ const body = summary === "" ? "" : ` — ${summary}`;
330
+ // `edited` の `note` は更新の理由。`noted` / `legacy_note` の `note` は本文なので、
331
+ // そちらは `body` に出ている(二重に出さない)
332
+ const reason = event?.kind === "edited" && event.note ? `(理由: ${shortened(event.note)})` : "";
333
+ lines.push(`- ${displayValue(event?.at)} ${displayValue(event?.kind)} (${displayValue(event?.actor)})${body}${reason}`);
290
334
  }
291
335
  }
292
336
  stdout.write(`${lines.join("\n")}\n`);
293
337
  }
338
+
339
+ /** 経緯1行の本文の上限。`legacy_note` は5,000文字まで在りうるので、行の密度を守って切る。 */
340
+ const INFRA_EVENT_BODY_LIMIT = 120;
341
+
342
+ function shortened(text, limit = INFRA_EVENT_BODY_LIMIT) {
343
+ const body = String(text ?? "").replace(/\s+/g, " ").trim();
344
+ return body.length > limit ? `${body.slice(0, limit)}…` : body;
345
+ }
346
+
347
+ /**
348
+ * 経緯1件の要約(記録188 §3.5)。
349
+ *
350
+ * - `noted` / `legacy_note` … `note` 列が本文なのでそのまま(120文字で切る)
351
+ * - `edited` … `meta.fields` を `status: to_cancel → active` の形で1行に
352
+ * (`note` は理由なので呼び出し側が末尾へ回す)
353
+ * - `created` / `synced` … 出す本文が無い(`meta` は作成時の全列なので行に収まらない)
354
+ */
355
+ function infraEventSummary(event) {
356
+ if (event?.kind === "noted" || event?.kind === "legacy_note") return shortened(event.note);
357
+ if (event?.kind !== "edited") return "";
358
+ const meta = event.meta;
359
+ if (meta === null || typeof meta !== "object" || Array.isArray(meta)) return "";
360
+ const fields = Array.isArray(meta.fields) ? meta.fields.filter((field) => typeof field === "string") : [];
361
+ const omitted = new Set(Array.isArray(meta.omitted) ? meta.omitted : []);
362
+ const from = meta.from ?? {};
363
+ const to = meta.to ?? {};
364
+ return fields
365
+ .map((field) => (omitted.has(field)
366
+ // `note` は監査metaへ値を積まない列なので、変わったことだけを出す
367
+ ? `${field}: 変更あり`
368
+ : `${field}: ${formatEventValue(from[field])} → ${formatEventValue(to[field])}`))
369
+ .join(" / ");
370
+ }
package/lib/infra.mjs CHANGED
@@ -11,6 +11,13 @@ export const INFRA_DOMAIN_ONLY_OPTIONS = [
11
11
  "hosted-on-basis",
12
12
  "prod-platform",
13
13
  "prod-ref",
14
+ // 特典と移管(migration 0029 / 記録191)。**DBのCHECKには入っていない**ので、
15
+ // server 行で弾いているのは Worker の routes とこの表だけ
16
+ "renew-source",
17
+ "bundle-server",
18
+ "transfer-to",
19
+ "transfer-stage",
20
+ "transfer-due",
14
21
  ];
15
22
 
16
23
  function oneLine(value) {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamai/hub-cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "CLI for the hub personal dashboard: D1-backed task board and project registry.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",