@tamai/hub-cli 0.1.13 → 0.1.14

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
@@ -67,7 +67,7 @@ hub infra help
67
67
  hub deploy help
68
68
  ```
69
69
 
70
- 動詞は `task` が `new` / `add` / `claim` / `next` / `show` / `edit` / `report` / `note` / `list` / `audit` / `brief`、
70
+ 動詞は `task` が `new` / `add` / `claim` / `next` / `show` / `edit` / `report` / `accept` / `note` / `list` / `audit` / `brief`、
71
71
  `project` が `list` / `show` / `create` / `update` / `move`、
72
72
  `infra` が `list` / `new` / `show` / `update` / `note` / `link` / `unlink`、
73
73
  `deploy` が `list` / `show` / `link` / `unlink`。
@@ -283,10 +283,26 @@ git root は探すが、出力先の基準にはしない(`context_ref` だけ
283
283
  **解決した出力先を起票前に stderr へ 1 行出す**。確認待ちや自動停止は行わない。
284
284
  `--repo-card <dir>` でディレクトリを明示できる(リポジトリ相対のみ。絶対パスは不可)。
285
285
 
286
- ## done にしない
286
+ ## done にする(`hub task accept`・オーケストレーターだけ)
287
287
 
288
- `done`(検収)は CLI から行えない。エージェントは `hub task report` までで、
289
- done にするのは人間が dash で行う。done は「本番へ反映し、本番で検証まで終えた」状態を指す。
288
+ done は「本番へ反映し、本番で検証まで終えた」状態を指す(デプロイを伴わないタスクでも、記録の
289
+ commit と push まで済んでいること)。**ワーカーは `hub task report` まで**で、done にはしない。
290
+
291
+ オーケストレーターだけは、閉じてよい区分のタスク(`docs/notes/2026-10-16 エージェントによる完了(裁定と実装指示).md`
292
+ §1)を根拠つきで閉じられる。人の確認が要る区分は人が dash で閉じる。
293
+
294
+ ```bash
295
+ HUB_ACTOR=orchestrator hub task accept <id> --verified production --summary "本番で一覧が200を返すことを確かめた" \
296
+ --ref abc1234 --ref docs/records/208-agent-accept.md
297
+ ```
298
+
299
+ - `--verified` は本番で確かめた(`production`)か、デプロイが無い(`no-deploy`)か。`--summary` は1〜2000文字。
300
+ `--ref` は commit・CI の run・記録のパス(1〜500文字・20個まで・繰り返し指定可)。欠けたら HTTP を送らずに止まる
301
+ - API は `HUB_ACTOR` の名乗りを Worker の許可リスト(env `AGENT_ACCEPT_ACTORS`)と突き合わせる。
302
+ 許可されていなければ 403、review でなければ 409。**再送しない**
303
+ - 成功すると結果(status: done)を表示する。経緯には「エージェントが閉じた」と根拠が残り、
304
+ `hub task audit` がエージェントの閉じた done を一覧にする(週1回の抜き取りの入口)
305
+ - 間違えて閉じたら owner が review へ戻して理由を note に残す。成果物の復旧(コードの差し戻し・データの復元)は別の作業
290
306
 
291
307
  ## リリース手順
292
308
 
@@ -0,0 +1,60 @@
1
+ import { cliError, requireSinglePositional, usageError } from "../lib/args.mjs";
2
+ import { ApiError, withGuidance } from "../lib/api.mjs";
3
+ import { printTaskResult } from "../lib/format.mjs";
4
+ import { resolveTaskIdArg } from "../lib/task-ref.mjs";
5
+
6
+ // エージェントによる完了(記録208・`docs/notes/2026-10-16 エージェントによる完了(裁定と実装指示).md`)。
7
+ //
8
+ // **閉じてよいのはオーケストレーターだけ**で、API が `HUB_ACTOR` の名乗りを許可リスト
9
+ // (Worker の env `AGENT_ACCEPT_ACTORS`)と突き合わせる。CLI は根拠(evidence)の形を
10
+ // HTTP より前に検査し、結果を必ず表示する。**再送しない**(done は取り消しの効かない記録になる)。
11
+
12
+ /** `--verified` の語と API の値。CLI はハイフン、API はアンダースコア。 */
13
+ const VERIFIED = { production: "production", "no-deploy": "no_deploy" };
14
+ // API(`dash/src/features/tasks/routes.ts`)の上限と同じ。往復してから400を読むより速く弾く
15
+ const MAX_SUMMARY = 2_000;
16
+ const MAX_REF = 500;
17
+ const MAX_REFS = 20;
18
+
19
+ const FORBIDDEN_GUIDANCE = "この名乗り(HUB_ACTOR)は accept を許可されていません(この操作は再送しません)";
20
+ const CONFLICT_GUIDANCE = "review ではありません(hub task show で今の status を確かめてください)";
21
+
22
+ function guided(error) {
23
+ if (!(error instanceof ApiError)) return error;
24
+ if (error.status === 403) return withGuidance(error, FORBIDDEN_GUIDANCE);
25
+ if (error.status === 409) return withGuidance(error, CONFLICT_GUIDANCE);
26
+ return error;
27
+ }
28
+
29
+ export const taskAcceptCommand = {
30
+ name: "accept",
31
+ options: { allowed: ["verified", "summary", "ref"], repeatable: ["ref"] },
32
+ async run({ options, positional, dependencies, api }) {
33
+ const ref = requireSinglePositional(positional, "タスクID");
34
+ if (options.verified === undefined) throw usageError("--verified production|no-deploy を指定してください");
35
+ const verified = Object.hasOwn(VERIFIED, options.verified) ? VERIFIED[options.verified] : undefined;
36
+ if (verified === undefined) throw usageError("--verified は production か no-deploy です");
37
+ if (!options.summary?.trim()) throw usageError("--summaryを指定してください");
38
+ if (options.summary.length > MAX_SUMMARY) throw usageError(`--summary は${MAX_SUMMARY}文字までです`);
39
+ const refs = options.ref;
40
+ if (refs.length > MAX_REFS) throw usageError(`--ref は${MAX_REFS}個までです`);
41
+ if (refs.some((value) => value.trim() === "" || value.length > MAX_REF)) {
42
+ throw usageError(`--ref は1〜${MAX_REF}文字です`);
43
+ }
44
+ const id = await resolveTaskIdArg(ref, api, dependencies);
45
+
46
+ let payload;
47
+ try {
48
+ payload = await api(`/api/tasks/${encodeURIComponent(id)}/accept`, {
49
+ method: "POST",
50
+ body: JSON.stringify({ evidence: { verified, summary: options.summary, refs } }),
51
+ });
52
+ } catch (error) {
53
+ throw guided(error);
54
+ }
55
+ if (typeof payload?.item?.id !== "string" || payload.item.status !== "done") {
56
+ throw cliError("accept後のAPI応答が不正です(hub task show で status を確かめてください)");
57
+ }
58
+ printTaskResult(payload, options.json, dependencies.stdout, "show");
59
+ },
60
+ };
@@ -1,3 +1,4 @@
1
+ import { withProjectOnLinearGuidance } from "../lib/api.mjs";
1
2
  import { requireSinglePositional } from "../lib/args.mjs";
2
3
  import { printTaskResult } from "../lib/format.mjs";
3
4
  import { resolveTaskProject } from "../lib/records.mjs";
@@ -16,7 +17,12 @@ export const taskAddCommand = {
16
17
  if (project) body.project = project;
17
18
  if (options.due) body.due = options.due;
18
19
  if (options["body-file"]) body.body = await dependencies.readFileImpl(options["body-file"], "utf8");
19
- const payload = await api("/api/tasks", { method: "POST", body: JSON.stringify(body) });
20
+ let payload;
21
+ try {
22
+ payload = await api("/api/tasks", { method: "POST", body: JSON.stringify(body) });
23
+ } catch (error) {
24
+ throw withProjectOnLinearGuidance(error);
25
+ }
20
26
  printTaskResult(payload, options.json, dependencies.stdout, "task");
21
27
  },
22
28
  };
@@ -7,6 +7,55 @@ import {
7
7
  } from "../lib/git.mjs";
8
8
  import { findRepoRoot } from "../lib/records.mjs";
9
9
 
10
+ /**
11
+ * service の accept(記録208)が API に入った日。accept は `updated_at` を進めるので、
12
+ * これより前に最後に更新された done は**エージェントが閉じたものではありえない**。
13
+ * done は数百件あり全件の詳細を引くと重いので、この日以降の done だけ経緯を見る。
14
+ */
15
+ export const AGENT_ACCEPT_SINCE = "2026-10-16";
16
+ const DETAIL_CONCURRENCY = 6;
17
+
18
+ /** done のうち、最後の accepted が `via: "agent"` のもの。経緯を引けなかった件数も返す。 */
19
+ async function agentAccepted(items, api) {
20
+ const candidates = items.filter((item) => typeof item?.id === "string"
21
+ && typeof item.updated_at === "string" && item.updated_at >= AGENT_ACCEPT_SINCE);
22
+ const found = [];
23
+ let failed = 0;
24
+ let next = 0;
25
+ async function worker() {
26
+ while (next < candidates.length) {
27
+ const item = candidates[next];
28
+ next += 1;
29
+ let events;
30
+ try {
31
+ const detail = await api(`/api/tasks/${encodeURIComponent(item.id)}`);
32
+ events = Array.isArray(detail?.events) ? detail.events : null;
33
+ } catch {
34
+ events = null;
35
+ }
36
+ if (events === null) {
37
+ failed += 1;
38
+ continue;
39
+ }
40
+ const accepted = events.filter((event) => event?.kind === "accepted").at(-1);
41
+ if (accepted?.meta?.via !== "agent") continue;
42
+ const evidence = accepted.meta.evidence ?? {};
43
+ found.push({
44
+ id: item.id,
45
+ title: item.title ?? null,
46
+ actor: accepted.actor ?? null,
47
+ at: accepted.at ?? null,
48
+ verified: typeof evidence.verified === "string" ? evidence.verified : null,
49
+ summary: typeof evidence.summary === "string" ? evidence.summary : null,
50
+ refs: Array.isArray(evidence.refs) ? evidence.refs.filter((ref) => typeof ref === "string") : [],
51
+ });
52
+ }
53
+ }
54
+ await Promise.all(Array.from({ length: Math.min(DETAIL_CONCURRENCY, candidates.length) }, worker));
55
+ found.sort((a, b) => String(b.at).localeCompare(String(a.at)));
56
+ return { since: AGENT_ACCEPT_SINCE, checked: candidates.length - failed, failed, items: found };
57
+ }
58
+
10
59
  export const taskAuditCommand = {
11
60
  name: "audit",
12
61
  options: {},
@@ -32,7 +81,11 @@ export const taskAuditCommand = {
32
81
  unpushed: gitState.unpushed !== null,
33
82
  },
34
83
  ...auditDoneTasks(items, gitState),
84
+ agent_accepted: await agentAccepted(items, api),
35
85
  };
86
+ if (report.agent_accepted.failed > 0) {
87
+ dependencies.stderr.write(`警告: done ${report.agent_accepted.failed}件の経緯を取得できず、エージェントが閉じたかを確かめられませんでした。\n`);
88
+ }
36
89
  if (options.json) {
37
90
  dependencies.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
38
91
  return;
@@ -1,4 +1,4 @@
1
- import { isConflictError, withGuidance } from "../lib/api.mjs";
1
+ import { isConflictError, withGuidance, withProjectOnLinearGuidance } from "../lib/api.mjs";
2
2
  import { requireSinglePositional, usageError } from "../lib/args.mjs";
3
3
  import { printTaskResult } from "../lib/format.mjs";
4
4
  import { resolveTaskProject } from "../lib/records.mjs";
@@ -85,7 +85,8 @@ async function patchWithRetry(api, id, changes) {
85
85
  body: JSON.stringify({ version, ...changes }),
86
86
  });
87
87
  } catch (error) {
88
- if (!isConflictError(error)) throw error;
88
+ // 付け替え先が Linear のプロジェクト(記録207)。version を取り直しても変わらないので再送しない
89
+ if (!isConflictError(error)) throw withProjectOnLinearGuidance(error);
89
90
  if (Object.hasOwn(changes, "body")) throw withGuidance(error, BODY_CONFLICT_GUIDANCE);
90
91
  if (attempt === 1) {
91
92
  throw withGuidance(error, "再取得後にも競合しました。hub task show で最新の内容を確認してから、もう一度実行してください");
@@ -1,5 +1,12 @@
1
1
  import { cliError, requireSinglePositional, usageError } from "../lib/args.mjs";
2
- import { ApiError, describeFailure, isConflictError, withGuidance } from "../lib/api.mjs";
2
+ import {
3
+ ApiError,
4
+ describeFailure,
5
+ isConflictError,
6
+ isProjectOnLinearError,
7
+ withGuidance,
8
+ withProjectOnLinearGuidance,
9
+ } from "../lib/api.mjs";
3
10
  import { taskLines } from "../lib/format.mjs";
4
11
  import { newUlid } from "../lib/ulid.mjs";
5
12
  import {
@@ -28,6 +35,9 @@ async function postTask(api, body) {
28
35
  } catch (error) {
29
36
  // 409は「同じ操作IDが別の内容で使われている」。再送ではないので送り直しを勧めない
30
37
  // ——同じIDを付け直しても結果は変わらず、既存タスクを自分の起票と取り違える
38
+ // 行き先が Linear のプロジェクト(記録207)。操作IDを付け直しても結果は変わらないので、
39
+ // 再送も「--operation-id で送り直す」案内もしない。記録ファイルは起票の後に作るので作られない
40
+ if (isProjectOnLinearError(error)) throw withProjectOnLinearGuidance(error);
31
41
  if (isConflictError(error)) {
32
42
  throw withGuidance(error,
33
43
  `別の操作の id です(操作ID: ${body.id})。\n`
package/lib/api.mjs CHANGED
@@ -16,6 +16,25 @@ export function isConflictError(error) {
16
16
  return error instanceof ApiError && error.payload?.error?.code === "conflict";
17
17
  }
18
18
 
19
+ /**
20
+ * 行き先のプロジェクトがタスクを Linear で管理している(409 `project_on_linear`・記録207)。
21
+ *
22
+ * **競合(`conflict`)とは別物**として扱う。version を取り直しても、同じ操作IDで送り直しても
23
+ * 結果は変わらないので、`add` / `new` / `edit` はこの応答で再送せずに止まる。
24
+ */
25
+ export function isProjectOnLinearError(error) {
26
+ return error instanceof ApiError && error.payload?.error?.code === "project_on_linear";
27
+ }
28
+
29
+ /** 409 `project_on_linear` に添える案内。API の文面(1行目)の後ろに足す。 */
30
+ export const PROJECT_ON_LINEAR_GUIDANCE =
31
+ "このプロジェクトへは hub から起票も付け替えもできません。タスクは Linear で作ってください(この操作は再送しません)";
32
+
33
+ /** 409 `project_on_linear` なら案内を添えて返す。それ以外はそのまま返す。 */
34
+ export function withProjectOnLinearGuidance(error) {
35
+ return isProjectOnLinearError(error) ? withGuidance(error, PROJECT_ON_LINEAR_GUIDANCE) : error;
36
+ }
37
+
19
38
  export function defaultEnvFilePath(homedir = os.homedir()) {
20
39
  return path.join(homedir, ".config", "tamai", "hub-tasks.env");
21
40
  }
package/lib/args.mjs CHANGED
@@ -43,6 +43,7 @@ export const TASK_USAGE = `使い方:
43
43
  hub task next --owner <name> [--json]
44
44
  hub task show <id> [--json]
45
45
  hub task report <id> --note <text> [--json]
46
+ hub task accept <id> --verified production|no-deploy --summary <text> [--ref <text>]... [--json]
46
47
  hub task note <id> (--note <text> | --note-file <path>) [--json]
47
48
  hub task edit <id> [--title <text>] [--body-file <path>] [--project <name>|none [--force]]
48
49
  [--due <YYYY-MM-DD>|none] [--context-ref <path>|none] [--json]
@@ -70,6 +71,10 @@ hub task brief は文脈ゼロのAIへ渡す依頼書をMarkdownで出す。既
70
71
  -- 以降はすべて位置引数になる。-- で始まるタイトルは hub task new --project hub -- "--で始まる題" の順で渡す。
71
72
  オプションは --name=value の形でも書ける。値が -- で始まるとき(例 --note='--- 見出し')はこの形で渡す。
72
73
  report / note の長文は約2000字ごとに分割して送る。途中で失敗すると「n件中m件まで送信済み」と出る。
74
+ hub task accept は review のタスクを根拠つきで done にする(オーケストレーターだけ。HUB_ACTOR の名乗りを
75
+ API が許可リストと突き合わせ、許可されていなければ403)。--verified は本番で確かめた(production)か
76
+ デプロイが無い(no-deploy)か。--summary は1〜2000文字、--ref は commit・CI の run・記録のパス(1〜500文字・
77
+ 20個まで・繰り返し指定可)。再送しない。ワーカーは hub task report まで。
73
78
  `;
74
79
 
75
80
  export const PROJECT_USAGE = `使い方:
@@ -195,7 +200,7 @@ export const INFRA_USAGE = `使い方:
195
200
  `;
196
201
 
197
202
  export const USAGE = `使い方:
198
- hub task <verb> ... タスク操作(new / add / claim / next / show / edit / report / note / list / audit / brief)
203
+ hub task <verb> ... タスク操作(new / add / claim / next / show / edit / report / accept / note / list / audit / brief)
199
204
  hub task help
200
205
  hub project <verb> ... プロジェクト操作(list / show / create / update / move)
201
206
  hub project help
@@ -223,7 +228,8 @@ hub task new --repo-card の出力先は**cwd基準**である(gitリポジト
223
228
  例: repo直下なら docs/records/、dash/ で実行すると dash/docs/records/ に書く。
224
229
  解決した出力先は起票前にstderrへ1行出る。確認待ちや自動停止は行わない。
225
230
 
226
- done化(検収)はCLIから行えない。人間がdashで行う。
231
+ done化(検収)は人の owner が dash で行う。オーケストレーターだけは hub task accept で根拠を添えて閉じられる
232
+ (許可リストの名乗りのときだけ。人の確認が要る区分は人が dash で行う)。
227
233
  `;
228
234
 
229
235
  export function cliError(message) {
package/lib/cli.mjs CHANGED
@@ -49,6 +49,7 @@ import { projectListCommand } from "../commands/project-list.mjs";
49
49
  import { projectMoveCommand } from "../commands/project-move.mjs";
50
50
  import { projectShowCommand } from "../commands/project-show.mjs";
51
51
  import { projectUpdateCommand } from "../commands/project-update.mjs";
52
+ import { taskAcceptCommand } from "../commands/task-accept.mjs";
52
53
  import { taskAddCommand } from "../commands/task-add.mjs";
53
54
  import { taskAuditCommand } from "../commands/task-audit.mjs";
54
55
  import { taskBriefCommand } from "../commands/task-brief.mjs";
@@ -85,6 +86,7 @@ const COMMAND_GROUPS = {
85
86
  task: {
86
87
  usage: TASK_USAGE,
87
88
  commands: commandMap([
89
+ taskAcceptCommand,
88
90
  taskAddCommand,
89
91
  taskAuditCommand,
90
92
  taskBriefCommand,
package/lib/format.mjs CHANGED
@@ -59,6 +59,14 @@ export function projectLines(project, { includeLinks = false } = {}) {
59
59
  lines.push(`children: ${Number(project.children_count ?? 0)}`);
60
60
  }
61
61
  if (project.parent_slug) lines.push(`parent: ${project.parent_slug}`);
62
+ // タスクの置き場(記録207)。owner と service の応答にだけ載る列なので、無ければ出さない。
63
+ // `show` は hub でも出す(「hub のまま」と確かめられる)。一覧は `kind` と同じく既定でないときだけ
64
+ if (project.task_backend === "linear" || (includeLinks && typeof project.task_backend === "string")) {
65
+ lines.push(`task_backend: ${project.task_backend}`);
66
+ if (typeof project.linear_project_id === "string" && project.linear_project_id !== "") {
67
+ lines.push(`linear_project: ${project.linear_project_id}`);
68
+ }
69
+ }
62
70
  if (project.repo) lines.push(`repo: ${project.repo}`);
63
71
  if (project.memory_home) lines.push(`memory: ${project.memory_home}`);
64
72
  if (project.auto_policy && project.auto_policy !== "off") lines.push(`auto: ${project.auto_policy}`);
package/lib/git.mjs CHANGED
@@ -120,11 +120,32 @@ const AUDIT_REASON_LABELS = {
120
120
  unpushed: "記録の変更が origin/main に届いていない(ローカルコミット止まり)",
121
121
  };
122
122
 
123
+ const AGENT_VERIFIED_LABELS = { production: "本番で確認", no_deploy: "デプロイなし" };
124
+
125
+ /**
126
+ * エージェントが閉じた done(記録208)。owner の週1回の抜き取りの入口なので、
127
+ * 記録の検査で問題が無くても必ず出す。
128
+ */
129
+ function agentAcceptedLines(agent) {
130
+ // 0件なら何も足さない(問題なしの1行を崩さない)。経緯を引けなかった件数は stderr の警告に出る
131
+ if (agent === undefined || agent.items.length === 0) return [];
132
+ const lines = [`エージェントが閉じた done: ${agent.items.length}件(${agent.since} 以降に更新された done ${agent.checked}件を確認)`];
133
+ for (const entry of agent.items) {
134
+ const verified = AGENT_VERIFIED_LABELS[entry.verified] ?? entry.verified ?? "?";
135
+ lines.push(`- ${entry.id} ${entry.title ?? ""}`.trimEnd());
136
+ lines.push(` ${entry.at ?? "?"} ${entry.actor ?? "?"}(${verified})${entry.summary ?? ""}`);
137
+ if (entry.refs.length > 0) lines.push(` 参照: ${entry.refs.join("・")}`);
138
+ }
139
+ return lines;
140
+ }
141
+
123
142
  export function formatAuditReport(report) {
124
143
  const skipped = `context_ref なし ${report.skipped_no_context_ref}件`
125
144
  + `・このrepo外の記録 ${report.skipped_other_repo}件は対象外`;
145
+ const agent = agentAcceptedLines(report.agent_accepted);
146
+ const agentBlock = agent.length === 0 ? "" : `\n${agent.join("\n")}\n`;
126
147
  if (report.suspicious.length === 0) {
127
- return `done ${report.checked}件の記録を確認しました(${skipped})。問題は見つかりませんでした。\n`;
148
+ return `done ${report.checked}件の記録を確認しました(${skipped})。問題は見つかりませんでした。\n${agentBlock}`;
128
149
  }
129
150
  const lines = [`done ${report.checked}件のうち ${report.suspicious.length}件が疑わしい(${skipped}):`, ""];
130
151
  for (const entry of report.suspicious) {
@@ -134,5 +155,5 @@ export function formatAuditReport(report) {
134
155
  lines.push("");
135
156
  }
136
157
  lines.push("doneは「本番反映と検証まで終えた」状態です。手元にしか無い変更が残っていないか確認してください。");
137
- return `${lines.join("\n")}\n`;
158
+ return `${lines.join("\n")}\n${agentBlock}`;
138
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamai/hub-cli",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "CLI for the hub personal dashboard: D1-backed task board and project registry.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",