@tamai/hub-cli 0.1.6 → 0.1.7

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
@@ -98,6 +98,28 @@ 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
+
101
123
  ### インフラ資産を読む・更新する
102
124
 
103
125
  ```bash
@@ -1,4 +1,12 @@
1
- import { PROJECT_KINDS, PROJECT_LINK_ROLES, cliError, requireSinglePositional, usageError } from "../lib/args.mjs";
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: ["name", "repo", "slug", "kind", "add-link", "link-role", "remove-link", "remove-link-url", "clear-links"],
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 (!flags.name && !flags.repo && !flags.slug && !flags.kind && !hasLinkChange) {
35
- throw usageError("--name / --repo / --slug / --kind / --add-link / --remove-link / --remove-link-url / --clear-links のいずれかを指定してください");
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 : [];
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
  *
@@ -53,6 +68,7 @@ export const PROJECT_USAGE = `使い方:
53
68
  hub project create <slug> --name <text> [--kind work|private] [--repo <text>] [--json]
54
69
  hub project update <slug> [--name <text>] [--repo <text>] [--slug <new-slug>]
55
70
  [--kind work|private]
71
+ [--entity-type project|group] [--parent <slug>|none]
56
72
  [--add-link <URL>]... [--add-link "<ラベル>=<URL>"]...
57
73
  [--link-role <role>]
58
74
  [--remove-link "<ラベル>"]... [--remove-link-url <URL>]...
@@ -73,6 +89,12 @@ export const PROJECT_USAGE = `使い方:
73
89
  --remove-link-url はURL完全一致で1件だけ消す(該当なし・複数該当はエラー)。
74
90
  --clear-links は全消し(--add-link / --remove-link / --remove-link-url と同時指定不可)。
75
91
  --kind は仕事/プライベートの区分(既定 work)。共有範囲のvisibilityとは別。
92
+ --entity-type は案件(project)かグループ(group)か。グループは案件の上の層で、
93
+ 親を持てない(1段)。配下の案件があるグループは、削除と案件(project)への変更が
94
+ 1件でも子があれば拒否され、終了(status=closed)は**終了していない子**があるときだけ
95
+ 拒否される(子が全部終了していればグループも終了にできる)。
96
+ --parent は所属するグループのslug。--parent none で外す。指定できるのは group だけで、
97
+ --entity-type group と --parent <slug> は同時に指定できない。
76
98
  list は既定で全件出す(--kind を付けたときだけ絞る)。
77
99
  オプションは --name=value の形でも書ける(値が -- で始まるときはこの形で渡す)。
78
100
  `;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamai/hub-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "CLI for the hub personal dashboard: D1-backed task board and project registry.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",