@tamai/hub-cli 0.1.9 → 0.1.11

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
@@ -156,8 +156,11 @@ 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 --reason '11/30までに解約と決めた'
159
+ hub infra update example.jp --renewal-policy let_expire --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
161
164
  hub infra note example.jp --note 'Xserverのパネルで自動更新onを確認'
162
165
  hub infra note example.jp --note-file /tmp/note.md
163
166
  hub infra note example.jp --note '…' --operation-id 01M33H236V8MACB2DFR641ATK3 # 送り直し
@@ -171,6 +174,26 @@ hub infra unlink example.jp # 紐付けを全部外す
171
174
  1回だけ再試行する。`link` は現在の紐付けへ追加、`unlink` は指定分を削除し、APIへはどちらも
172
175
  `PUT /:id/projects` の全置換として送る。
173
176
 
177
+ `--status` は契約の**現在**(`active`=契約中 / `cancelled`=終了 / `needs_review`=要確認)で、
178
+ `--renewal-policy` が継続の**意思**(`renew` / `let_expire` / `cancel_now` / `while_bundled` / `undecided`)を持つ。
179
+ `--status to_cancel` と `--migration-plan cancel` は**APIを呼ぶ前にCLIが拒否**する——どちらも意思なので
180
+ `--renewal-policy` へ移った(台帳に残っている行はデータ移行で消える)。`--renewal-policy none` は
181
+ `undecided` へ戻す(NOT NULLの列なので空にはしない)。
182
+
183
+ `--renew-source` は更新の**方式**(`paid` / `bundled`)で、`--auto-renew`(確認できた更新状態)とは
184
+ **別の軸**である。特典ドメインでも `on` には化けない——特典元のサーバー契約が解約されれば更新は止まる。
185
+ `--bundle-server` は特典元のサーバーで、`bundled` のときだけ持てる(`--hosted-on` と同じく名前かIDで指定する)。
186
+ 収容先(どのサーバーに乗っているか)とは別の事実なので、一致しない行がある。
187
+
188
+ `--transfer-to` / `--transfer-stage` / `--transfer-due` は移管の進み。段階は
189
+ `requested` / `awaiting_approval` / `approved` / `rejected` / `cancelled` で、`rejected` と `cancelled` は
190
+ `provider` を変えない(移管しなかった)。`--transfer-due` は**時刻を含む** ISO 8601 だけを受ける。
191
+ 移管の完了は `--provider <移管先> --transfer-to none --transfer-stage none --transfer-due none` を
192
+ 1回で送る(移管先が残ったまま `--provider` を変えると400)。
193
+ **移管の3項目を含む更新は409で自動再送しない**(`--reason` と同じ扱い。段階は人が申請・承認メールを
194
+ 見て書く値なので、取り直して自分の古い認識で巻き戻さない)。
195
+ 特典元にしているドメインがあるサーバーは、`hub infra` からは消せない(APIが409で拒む)。
196
+
174
197
  `note` は台帳の**経緯**を1件足す(`POST /:id/notes`)。資産の `version` を進めないので、
175
198
  画面を開いたまま追記しても、そのあとの保存が競合しない。本文は2,000文字までで**分割しない**
176
199
  (`hub task note` と違い、長い本文は要点へ縮める。旧メモの原文保管はCLIでは行わない)。
@@ -28,9 +28,45 @@ 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",
37
+ // 継続の意思(記録192 / migration 0030)。`status`(契約の現在)とは別の軸
38
+ "renewal-policy": "renewal_policy",
31
39
  };
32
40
 
33
- const ALLOWED_OPTIONS = [...Object.keys(OPTION_FIELDS), "append-note", "hosted-on", "reason"];
41
+ /**
42
+ * 互換で残した値(記録192)。APIも400にするが、**往復する前にCLIが止める**——
43
+ * 打ち間違いではなく「古い言い方が手に残っている」ので、案内を先に出す方が早い。
44
+ */
45
+ const LEGACY_VALUES = {
46
+ status: {
47
+ to_cancel: "status に to_cancel は書けません。継続の意思は --renewal-policy let_expire / cancel_now で指定します",
48
+ },
49
+ "migration-plan": {
50
+ cancel: "migration-plan に cancel は書けません。継続の意思は --renewal-policy let_expire / cancel_now で指定します",
51
+ },
52
+ };
53
+
54
+ const ALLOWED_OPTIONS = [
55
+ ...Object.keys(OPTION_FIELDS), "append-note", "hosted-on", "reason", "bundle-server",
56
+ ];
57
+
58
+
59
+ /**
60
+ * 移管の3項目を含む更新は **409 で自動再送しない**(所見 Medium 2・記録191)。
61
+ *
62
+ * 理由(`--reason`)と同じ扱いである。移管は「いまどこまで進んだか」を人が外の出来事
63
+ * (申請・承認メール・authcode)を見て書く列で、取り直して送り直すと**他人が進めた段階を
64
+ * 自分の古い認識で巻き戻す**。`--renew-source` / `--bundle-server` は現在値に依存しない
65
+ * ので再送してよい。
66
+ */
67
+ const TRANSFER_OPTIONS = ["transfer-to", "transfer-stage", "transfer-due"];
68
+ const TRANSFER_CONFLICT_GUIDANCE =
69
+ "移管の更新は自動で再送しません。最新の段階を確認してからもう一度実行してください";
34
70
 
35
71
  /**
36
72
  * `--append-note` は次の版で外す(記録188 §3.5)。既存noteの末尾へ「 / 」で足す作りは、
@@ -52,6 +88,10 @@ const NULLABLE_VALUE_OPTIONS = new Set([
52
88
  "migration-plan",
53
89
  "contract",
54
90
  "hosted-on-basis",
91
+ "renew-source",
92
+ "transfer-to",
93
+ "transfer-stage",
94
+ "transfer-due",
55
95
  ]);
56
96
 
57
97
  function amountValue(value) {
@@ -92,6 +132,14 @@ export const infraUpdateCommand = {
92
132
  reason = options.reason.trim();
93
133
  if (reason === "") throw usageError("--reason に空文字は指定できません");
94
134
  }
135
+ // **互換で残した値はAPIを呼ぶ前に止める**(記録192・codex2 Medium 1)。引数だけで決まる
136
+ // 拒否なので、認証も接続も無い場所で打っても案内が出る——詳細GETの後ろに置くと、
137
+ // 台帳が引けないときに「古い言い方だ」と気づけない
138
+ for (const [option, values] of Object.entries(LEGACY_VALUES)) {
139
+ if (!flags[option]) continue;
140
+ const legacy = values[options[option].trim()];
141
+ if (legacy !== undefined) throw usageError(legacy);
142
+ }
95
143
  if (flags["append-note"]) dependencies.stderr.write(APPEND_NOTE_DEPRECATION);
96
144
 
97
145
  let currentPayload = await getInfraAsset(reference, api);
@@ -105,7 +153,9 @@ export const infraUpdateCommand = {
105
153
  for (const [option, field] of Object.entries(OPTION_FIELDS)) {
106
154
  if (!flags[option] || option === "note") continue;
107
155
  const value = options[option].trim();
108
- if (option === "expires") prepared[field] = value === "none" ? null : value;
156
+ // 継続方針は NOT NULL の列なので、`none` は null ではなく `undecided` へ戻す
157
+ if (option === "renewal-policy") prepared[field] = value === "none" ? "undecided" : value;
158
+ else if (option === "expires") prepared[field] = value === "none" ? null : value;
109
159
  else if (option === "amount") prepared[field] = amountValue(value);
110
160
  else if (NULLABLE_VALUE_OPTIONS.has(option) && value === "none") prepared[field] = null;
111
161
  else prepared[field] = value;
@@ -129,6 +179,18 @@ export const infraUpdateCommand = {
129
179
  }
130
180
  }
131
181
 
182
+ // 特典元も server の名前かidで指定する(`--hosted-on` と同じ解決。記録191)
183
+ if (flags["bundle-server"]) {
184
+ const bundleReference = options["bundle-server"].trim();
185
+ if (bundleReference === "none") {
186
+ prepared.bundle_server = null;
187
+ } else {
188
+ const bundle = await getInfraAsset(bundleReference, api, { kind: "server" });
189
+ if (bundle.item.kind !== "server") throw cliError("--bundle-server にはserver資産の名前またはidを指定してください");
190
+ prepared.bundle_server = bundle.item.id;
191
+ }
192
+ }
193
+
132
194
  for (let attempt = 0; attempt < 2; attempt += 1) {
133
195
  try {
134
196
  const payload = await api(`/api/infra/assets/${encodeURIComponent(current.id)}`, {
@@ -142,6 +204,10 @@ export const infraUpdateCommand = {
142
204
  // 理由つきは取り直して送り直さない。**書いた理由が古い前提のままになる**ので、
143
205
  // 人が最新を読んで理由を書き直す(所見 Medium 2・記録188 §3.5)
144
206
  if (reason !== null) throw withGuidance(error, REASON_CONFLICT_GUIDANCE);
207
+ // 移管も同じ(記録191)。段階は外の出来事を見て人が書く値なので巻き戻さない
208
+ if (TRANSFER_OPTIONS.some((name) => flags[name])) {
209
+ throw withGuidance(error, TRANSFER_CONFLICT_GUIDANCE);
210
+ }
145
211
  if (attempt === 1) {
146
212
  throw withGuidance(error, "再取得後にも競合しました。最新の内容を確認してから、もう一度実行してください");
147
213
  }
package/lib/args.mjs CHANGED
@@ -108,7 +108,9 @@ export const INFRA_USAGE = `使い方:
108
108
  hub infra list [--kind server|domain] [--status <status[,status...]>] [--management self|external|all]
109
109
  [--project <slug>] [--q <text>] [--json]
110
110
  hub infra show <name|id> [--json]
111
- hub infra update <name|id> [--status <status>] [--auto-renew on|off|unknown]
111
+ hub infra update <name|id> [--status active|cancelled|needs_review]
112
+ [--renewal-policy renew|let_expire|cancel_now|while_bundled|undecided|none]
113
+ [--auto-renew on|off|unknown]
112
114
  [--expires YYYY-MM-DD|none] [--dns-host <value>|none]
113
115
  [--mail-host <value>|none] [--migration-plan <value>|none]
114
116
  [--management self|external] [--purpose <text>]
@@ -119,6 +121,11 @@ export const INFRA_USAGE = `使い方:
119
121
  [--note <text>] [--append-note <text>]
120
122
  [--hosted-on <server name|id>|none]
121
123
  [--hosted-on-basis <value>|none]
124
+ [--renew-source paid|bundled|none]
125
+ [--bundle-server <server name|id>|none]
126
+ [--transfer-to <provider>|none]
127
+ [--transfer-stage <stage>|none]
128
+ [--transfer-due <ISO8601>|none]
122
129
  [--reason <text>] [--json]
123
130
  hub infra note <name|id> (--note <text> | --note-file <path>)
124
131
  [--operation-id <ULID>] [--json]
@@ -129,6 +136,10 @@ export const INFRA_USAGE = `使い方:
129
136
  list の --status はカンマ区切りで複数指定できる。
130
137
  show / update / link / unlink の資産は名前の完全一致またはidで指定する。
131
138
  update は指定した項目だけを更新する。version競合時は最新を取り直して1回だけ再試行する。
139
+ --status は契約の**現在**(active=契約中 / cancelled=終了 / needs_review=要確認)。
140
+ --renewal-policy は継続の**意思**(更新するか)。--status to_cancel と
141
+ --migration-plan cancel は書けない(どちらも意思なので --renewal-policy へ移す)。
142
+ --renewal-policy none は要判断(undecided)へ戻す(NOT NULLの列なので空にはしない)。
132
143
  --reason は更新の理由(500文字まで)。値の変更と一緒に指定する(理由だけの更新はできない)。
133
144
  **--reason を含む更新は409で自動再送しない**(理由は読んだ状態に依存するため、
134
145
  最新を確認して書き直す)。
@@ -136,12 +147,23 @@ export const INFRA_USAGE = `使い方:
136
147
  note は台帳の経緯を1件足す(2,000文字まで・分割しない)。noteは資産のversionを進めない
137
148
  ので、シートを開いたまま追記しても、その後の保存が競合しない。
138
149
  --note-file はファイルの中身をそのまま1件として送る(超過分は切らずにエラーにする)。
150
+ --renew-source は更新の方式(paid=自分で払う / bundled=サーバー契約の特典)。
151
+ --bundle-server は特典元のサーバー(--renew-source bundled のときだけ持てる)。
152
+ **--auto-renew は別の軸**で、特典でも on には化けない(確認できた更新状態を書く)。
153
+ --transfer-to / --transfer-stage / --transfer-due は移管の進み。段階は
154
+ requested / awaiting_approval / approved / rejected / cancelled。
155
+ --transfer-due は時刻を含むISO 8601(例 2026-09-26T11:00:00+09:00)。日付だけは受け付けない。
156
+ 移管の完了は「--provider <移管先> --transfer-to none --transfer-stage none --transfer-due none」を
157
+ 1回で送る(移管先が残ったまま --provider を変えると400)。
158
+ **移管の3項目を含む更新は409で自動再送しない**(--reason と同じ。段階は人が外の出来事を
159
+ 見て書く値なので、取り直して巻き戻さない)。
139
160
  note の操作IDは1操作につき1つ。応答の前に通信が切れた失敗だけ、**同じIDで1回だけ**
140
161
  送り直す(届いていればAPIが既存のイベントを返すので二重に積まれない)。
141
162
  失敗すると「操作ID: …」を出すので、後から送り直すときは --operation-id <ULID> に
142
163
  その値を渡す(素で打ち直すと別の操作になり、届いていた場合は2件積まれる)。
143
164
  server資産には dns-host / mail-host / migration-plan / hosted-on / hosted-on-basis /
144
- prod-platform / prod-ref を指定できない。
165
+ prod-platform / prod-ref / renew-source / bundle-server / transfer-to / transfer-stage /
166
+ transfer-due を指定できない。
145
167
  link は現在の紐付けへ追加し、unlink は指定分を外す。unlink の --project 省略は全解除。
146
168
  作成・削除はCLIから行えない。
147
169
  オプションは --name=value の形でも書ける(値が -- で始まるときはこの形で渡す)。
package/lib/format.mjs CHANGED
@@ -228,6 +228,50 @@ 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
+ /**
247
+ * 継続方針(記録192)。**`renew` は出さない**——一覧の大半がそれになり、密度だけ食う
248
+ * (SPAのバッジと同じ流儀)。`undecided` は出す(意思を決めていない行は拾いたい)。
249
+ */
250
+ const RENEWAL_POLICY_MARKS = {
251
+ let_expire: "期限で終了",
252
+ cancel_now: "解約手続き中",
253
+ while_bundled: "特典が続く間",
254
+ undecided: "要判断",
255
+ };
256
+
257
+ function policyMark(item) {
258
+ const mark = RENEWAL_POLICY_MARKS[item?.renewal_policy];
259
+ return mark === undefined ? "" : ` [方針:${mark}]`;
260
+ }
261
+
262
+ function transferMark(item) {
263
+ const stage = item?.transfer_stage;
264
+ if (stage === null || stage === undefined) return "";
265
+ if (stage === "rejected") return " [移管:却下]";
266
+ if (stage === "cancelled") return " [移管:中止]";
267
+ const due = item?.transfer_due_at ? ` 期限${oneLineValue(item.transfer_due_at)}` : "";
268
+ return ` [移管→${displayValue(item?.transfer_to)}:${displayValue(stage)}${due}]`;
269
+ }
270
+
271
+ function oneLineValue(value) {
272
+ return String(value ?? "").replace(/\s+/g, " ").trim();
273
+ }
274
+
231
275
  export function infraListLine(item, now = new Date()) {
232
276
  const projects = Array.isArray(item?.projects)
233
277
  ? item.projects.map((project) => displayValue(project?.slug)).filter((slug) => slug !== "-")
@@ -237,18 +281,19 @@ export function infraListLine(item, now = new Date()) {
237
281
  displayValue(item?.name),
238
282
  `[${displayValue(item?.kind)}]`,
239
283
  `provider:${displayValue(item?.provider)}`,
240
- `status:${displayValue(item?.status)}`,
241
- `auto-renew:${displayValue(item?.auto_renew)}`,
284
+ `status:${displayValue(item?.status)}${policyMark(item)}`,
285
+ `auto-renew:${displayValue(item?.auto_renew)}${bundleMark(item)}`,
242
286
  `expires:${displayValue(item?.expires_on)} (${remainingDays(item?.expires_on, now)})`,
243
- `projects:${projects.join(",") || "-"}${external}`,
287
+ `projects:${projects.join(",") || "-"}${external}${transferMark(item)}`,
244
288
  ].join(" ");
245
289
  }
246
290
 
247
291
  export function infraAssetLines(item) {
248
292
  const fields = [
249
- "id", "provider", "status", "management", "auto_renew", "expires_on", "purpose",
293
+ "id", "provider", "status", "renewal_policy", "management", "auto_renew", "expires_on", "purpose",
250
294
  "dns_host", "mail_host", "migration_plan", "hosted_on_basis", "prod_platform", "prod_ref",
251
- "contract", "amount_yen", "payer", "holder", "account", "account_ref", "note", "version",
295
+ "contract", "amount_yen", "payer", "holder", "account", "account_ref", "note",
296
+ "renew_source", "transfer_to", "transfer_stage", "transfer_due_at", "version",
252
297
  "created_at", "updated_at",
253
298
  ];
254
299
  const lines = [`${displayValue(item?.name)} [${displayValue(item?.kind)}]`];
@@ -259,6 +304,15 @@ export function infraAssetLines(item) {
259
304
  : `${displayValue(item.hosted_on.name)} (${displayValue(item.hosted_on.id)})`;
260
305
  lines.splice(11, 0, `hosted_on: ${hosted}`);
261
306
  }
307
+ // 特典元は名前とid、そして**特典元の契約の状態**を添える(記録191)。
308
+ // 依存警告の根拠(解約予定・期限)を人が同じ行で読めるようにする
309
+ if (item?.bundle_server !== undefined) {
310
+ const bundle = item.bundle_server === null
311
+ ? "-"
312
+ : `${displayValue(item.bundle_server.name)} (${displayValue(item.bundle_server.id)})`
313
+ + ` status:${displayValue(item.bundle_server_status)} expires:${displayValue(item.bundle_server_expires_on)}`;
314
+ lines.push(`bundle_server: ${bundle}`);
315
+ }
262
316
  const projects = Array.isArray(item?.projects)
263
317
  ? item.projects.map((project) => `${displayValue(project?.slug)}(${displayValue(project?.name)})`)
264
318
  : [];
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamai/hub-cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "CLI for the hub personal dashboard: D1-backed task board and project registry.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",