@tamai/hub-cli 0.1.1 → 0.1.2
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 +6 -4
- package/commands/task-claim.mjs +3 -1
- package/commands/task-note.mjs +3 -1
- package/commands/task-report.mjs +3 -1
- package/commands/task-show.mjs +2 -1
- package/lib/args.mjs +1 -0
- package/lib/cli.mjs +3 -1
- package/lib/task-ref.mjs +193 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,8 @@ hub project help
|
|
|
72
72
|
|
|
73
73
|
`help` と `--version` は認証情報なしでも読める。
|
|
74
74
|
|
|
75
|
+
`show` / `claim` / `report` / `note` の `<id>` には**記録番号**(`150` / `#150`)も渡せる(`context_ref` が `docs/records/150-…` のタスクを一覧から引く。番号は repo ごとの採番なので別 repo と重なることがあり、そのときは今いる作業ツリーに記録ファイルがある方を採り、割り切れなければ候補を出して止まる)。
|
|
76
|
+
|
|
75
77
|
### `--repo-card` の出力先は cwd 基準
|
|
76
78
|
|
|
77
79
|
```bash
|
|
@@ -135,10 +137,10 @@ GitHub 側には `hub-cli-v*` タグの作成・変更・削除を release 担
|
|
|
135
137
|
|
|
136
138
|
## 配備(Mac mini)
|
|
137
139
|
|
|
138
|
-
`runner/deploy-from-macbook.sh`
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
`runner/deploy-from-macbook.sh` の手順 3 が `npm i -g @tamai/hub-cli@latest` を実行する
|
|
141
|
+
(2026-09-16 に旧ラッパー `/opt/homebrew/bin/hub` を `hub.wrapper.bak` へ退避して切替済み)。
|
|
142
|
+
repo 直参照のラッパー(`~/.local/bin/hub`)は Mac mini には置かない。PATH 上で先に当たると
|
|
143
|
+
旧実体を指すため、切り替えたら `command -v hub` と `hub --version` で実体を確かめる。
|
|
142
144
|
|
|
143
145
|
## ライセンス
|
|
144
146
|
|
package/commands/task-claim.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { cliError, requireSinglePositional, usageError } from "../lib/args.mjs";
|
|
2
2
|
import { ApiError, isConflictError } from "../lib/api.mjs";
|
|
3
3
|
import { printTaskResult, taskLines } from "../lib/format.mjs";
|
|
4
|
+
import { resolveTaskIdArg } from "../lib/task-ref.mjs";
|
|
4
5
|
|
|
5
6
|
export const taskClaimCommand = {
|
|
6
7
|
name: "claim",
|
|
7
8
|
options: { allowed: ["owner"] },
|
|
8
9
|
async run({ options, positional, dependencies, api }) {
|
|
9
|
-
const
|
|
10
|
+
const ref = requireSinglePositional(positional, "タスクID");
|
|
10
11
|
if (!options.owner?.trim()) throw usageError("--ownerを指定してください");
|
|
12
|
+
const id = await resolveTaskIdArg(ref, api, dependencies);
|
|
11
13
|
|
|
12
14
|
const currentPayload = await api(`/api/tasks/${encodeURIComponent(id)}`);
|
|
13
15
|
let task = currentPayload?.item;
|
package/commands/task-note.mjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { requireSinglePositional, usageError } from "../lib/args.mjs";
|
|
2
2
|
import { postChunks } from "../lib/api.mjs";
|
|
3
3
|
import { splitNote } from "../lib/records.mjs";
|
|
4
|
+
import { resolveTaskIdArg } from "../lib/task-ref.mjs";
|
|
4
5
|
|
|
5
6
|
export const taskNoteCommand = {
|
|
6
7
|
name: "note",
|
|
7
8
|
options: { allowed: ["note", "note-file"] },
|
|
8
9
|
async run({ options, positional, dependencies, api }) {
|
|
9
|
-
const
|
|
10
|
+
const ref = requireSinglePositional(positional, "タスクID");
|
|
10
11
|
if (options.note && options["note-file"]) throw usageError("--note と --note-file は同時に指定できません");
|
|
11
12
|
const source = options["note-file"]
|
|
12
13
|
? await dependencies.readFileImpl(options["note-file"], "utf8")
|
|
13
14
|
: options.note;
|
|
14
15
|
if (!source?.trim()) throw usageError("--note か --note-file を指定してください");
|
|
16
|
+
const id = await resolveTaskIdArg(ref, api, dependencies);
|
|
15
17
|
|
|
16
18
|
const events = await postChunks(
|
|
17
19
|
splitNote(source),
|
package/commands/task-report.mjs
CHANGED
|
@@ -2,13 +2,15 @@ import { requireSinglePositional, usageError } from "../lib/args.mjs";
|
|
|
2
2
|
import { postChunks } from "../lib/api.mjs";
|
|
3
3
|
import { printTaskResult } from "../lib/format.mjs";
|
|
4
4
|
import { splitNote } from "../lib/records.mjs";
|
|
5
|
+
import { resolveTaskIdArg } from "../lib/task-ref.mjs";
|
|
5
6
|
|
|
6
7
|
export const taskReportCommand = {
|
|
7
8
|
name: "report",
|
|
8
9
|
options: { allowed: ["note"] },
|
|
9
10
|
async run({ options, positional, dependencies, api }) {
|
|
10
|
-
const
|
|
11
|
+
const ref = requireSinglePositional(positional, "タスクID");
|
|
11
12
|
if (!options.note?.trim()) throw usageError("--noteを指定してください");
|
|
13
|
+
const id = await resolveTaskIdArg(ref, api, dependencies);
|
|
12
14
|
const results = await postChunks(
|
|
13
15
|
splitNote(options.note),
|
|
14
16
|
(chunk) => api(`/api/tasks/${encodeURIComponent(id)}/report`, {
|
package/commands/task-show.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { requireSinglePositional } from "../lib/args.mjs";
|
|
2
2
|
import { printTaskResult } from "../lib/format.mjs";
|
|
3
|
+
import { resolveTaskIdArg } from "../lib/task-ref.mjs";
|
|
3
4
|
|
|
4
5
|
export const taskShowCommand = {
|
|
5
6
|
name: "show",
|
|
6
7
|
options: {},
|
|
7
8
|
async run({ options, positional, dependencies, api }) {
|
|
8
|
-
const id = requireSinglePositional(positional, "タスクID");
|
|
9
|
+
const id = await resolveTaskIdArg(requireSinglePositional(positional, "タスクID"), api, dependencies);
|
|
9
10
|
const payload = await api(`/api/tasks/${encodeURIComponent(id)}`);
|
|
10
11
|
printTaskResult(payload, options.json, dependencies.stdout, "show");
|
|
11
12
|
},
|
package/lib/args.mjs
CHANGED
|
@@ -15,6 +15,7 @@ export const TASK_USAGE = `使い方:
|
|
|
15
15
|
hub task list [--status <s>] [--project <name>] [--owner <name>] [--q <text>] [--json]
|
|
16
16
|
hub task audit [--json]
|
|
17
17
|
|
|
18
|
+
show / claim / report / note の <id> には記録番号(150 / #150)も指定できる(context_ref が docs/records/150-… のタスクを一覧から引く。番号はrepoごとの採番なので、複数一致は作業ツリーに記録ファイルがある1件で割る。0件・それでも割れない複数一致はエラー)。
|
|
18
19
|
hub task new は「D1へ起票 → repoに記録の雛形を作成 → context_ref で紐付け」を1コマンドで行う。
|
|
19
20
|
記録には status / owner / priority を書かない(状態の正本はD1だけ)。
|
|
20
21
|
--repo-card はリポジトリ相対のディレクトリのみ。context_ref にはリポジトリルート相対のパスが入る。
|
package/lib/cli.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// (Astra High 1・実測: 実体パス447 byte / symlink 0 byte)。入口は `bin/hub.mjs` 専用にして、
|
|
13
13
|
// 比較そのものを無くしてある。このファイルはライブラリとしてだけ読まれる。
|
|
14
14
|
|
|
15
|
-
import { mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
15
|
+
import { lstat, mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
18
|
ApiError,
|
|
@@ -174,6 +174,8 @@ export async function runCli(argv, overrides = {}) {
|
|
|
174
174
|
readdirImpl: overrides.readdirImpl ?? readdir,
|
|
175
175
|
mkdirImpl: overrides.mkdirImpl ?? mkdir,
|
|
176
176
|
statImpl: overrides.statImpl ?? stat,
|
|
177
|
+
// symlink を追わない版。記録ファイルの実在確認はこちらを使う(記録153・codex1 Medium 1)
|
|
178
|
+
lstatImpl: overrides.lstatImpl ?? lstat,
|
|
177
179
|
cwd: overrides.cwd ?? (() => process.cwd()),
|
|
178
180
|
runGitImpl: overrides.runGitImpl ?? defaultRunGit,
|
|
179
181
|
stdout: guarded(overrides.stdout ?? process.stdout),
|
package/lib/task-ref.mjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// `<id>` の解決(記録153・仕様3)。
|
|
2
|
+
//
|
|
3
|
+
// AIとのやり取りでは「タスク153」「記録150の続き」のように**記録番号**で呼ぶことが多い一方、
|
|
4
|
+
// CLIが受けていたのはULIDだけだった。人が毎回 `hub task list` からULIDを探して貼り直す手間を
|
|
5
|
+
// 無くすため、`show / claim / report / note` の `<id>` で記録番号(`150` / `#150`)も受ける。
|
|
6
|
+
//
|
|
7
|
+
// **解決はCLI側でやる**(APIは変えない)。`GET /api/tasks` の応答に `context_ref` が入っている
|
|
8
|
+
// (`dash/src/features/tasks/db.ts` の `listTasks` が SELECT している)ので、一覧を取って
|
|
9
|
+
// CLIで絞れば足りる。記録番号は運用上の呼び名であってD1の列ではないため、
|
|
10
|
+
// 検索パラメータをAPIへ足す理由も無い。
|
|
11
|
+
//
|
|
12
|
+
// **ULID以外は素通しする。** ここで「ULIDらしさ」を判定して弾くと、ID形式が変わったときに
|
|
13
|
+
// CLIが先に壊れる。数字だけのときに限って一覧を引き、それ以外はこれまで通りAPIへ渡して
|
|
14
|
+
// APIの `not_found` に判断を任せる。
|
|
15
|
+
//
|
|
16
|
+
// **記録番号はrepo内でしか一意でない。** 看板は全プロジェクトを1つのD1で持つので、
|
|
17
|
+
// 実データでは番号の重複が18件あった(例: 記録150 が stw-manage と hub の両方にある。
|
|
18
|
+
// 番号はrepoごとに採番されるので当然そうなる)。番号だけで引くと `hub task show 153` が
|
|
19
|
+
// ほぼ毎回「複数あります」で止まり、道具として使えない。そこで**今いるrepoの作業ツリーに
|
|
20
|
+
// その記録ファイルが在るか**でだけ同点を割る(`docs/records/150-…md` が手元にあるものを採る)。
|
|
21
|
+
// プロジェクト名やgitのremoteを引かないのは、API呼び出しを増やさずに済み、
|
|
22
|
+
// 「自分が読んでいる記録の番号」という呼び方の実態と一致するため。
|
|
23
|
+
// 割り切れないときは候補を出して止まる(勝手に先頭を採らない)。
|
|
24
|
+
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
|
|
27
|
+
import { cliError } from "./args.mjs";
|
|
28
|
+
import { findRepoRoot } from "./records.mjs";
|
|
29
|
+
|
|
30
|
+
/** `<id>` として記録番号と解釈する形。`#` 付き・4桁まで(ULIDは26文字なので衝突しない)。 */
|
|
31
|
+
const RECORD_NUMBER_ARG = /^#?(\d{1,4})$/;
|
|
32
|
+
|
|
33
|
+
/** 端末の1行を破れる文字(制御文字・行区切り)。APIから来た文字列をそのまま流さないための的。 */
|
|
34
|
+
const LINE_BREAKING = /[\u0000-\u001F\u007F\u2028\u2029]/g;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* API由来の文字列を**1行**に均す(codex1 レビュー Medium 2)。
|
|
38
|
+
*
|
|
39
|
+
* `context_ref` は API 側で長さしか検査していないので、改行を仕込めば
|
|
40
|
+
* 「解決結果は stderr へ1行」という契約を破って偽の行を足せる(ログ注入)。
|
|
41
|
+
* 引用符やbackslashまでescapeすると日本語タイトルが読みにくくなるので、
|
|
42
|
+
* **行を割れる文字だけ**を `\uXXXX` 表記へ置き換える。
|
|
43
|
+
*/
|
|
44
|
+
export function toSingleLine(value) {
|
|
45
|
+
return String(value).replace(
|
|
46
|
+
LINE_BREAKING,
|
|
47
|
+
(character) => `\\u${character.codePointAt(0).toString(16).padStart(4, "0")}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `context_ref`(リポジトリルート相対。dash配下なら `dash/docs/records/...`)から番号を取る形。 */
|
|
52
|
+
const RECORD_CONTEXT_REF = /(?:^|\/)docs\/records\/(\d+)-/;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* `context_ref` の記録番号。記録以外を指している・番号が無いなら null。
|
|
56
|
+
*
|
|
57
|
+
* **数値で比べる**(文字列の前方一致にしない)。記録のファイル名は2桁ゼロ詰めで始まった
|
|
58
|
+
* (`01-...`)ので、`hub task show 1` と `hub task show 01` が別物になってしまう。
|
|
59
|
+
*/
|
|
60
|
+
export function recordNumberFromContextRef(contextRef) {
|
|
61
|
+
if (typeof contextRef !== "string") return null;
|
|
62
|
+
const matched = RECORD_CONTEXT_REF.exec(contextRef);
|
|
63
|
+
if (matched === null) return null;
|
|
64
|
+
const number = Number.parseInt(matched[1], 10);
|
|
65
|
+
return Number.isSafeInteger(number) ? number : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `<id>` をタスクIDへ解決する。
|
|
70
|
+
*
|
|
71
|
+
* @param {string} ref コマンドラインの `<id>`
|
|
72
|
+
* @param {() => Promise<unknown[]>} listTasks 一覧を取る関数(`context_ref` を含む行の配列)
|
|
73
|
+
* @returns {Promise<string>} タスクID
|
|
74
|
+
*
|
|
75
|
+
* @param {{narrow?: (hits: unknown[]) => Promise<unknown[]>, onResolved?: (item: unknown, number: number) => void}} options
|
|
76
|
+
*
|
|
77
|
+
* 記録番号でないものは**そのまま返す**(一覧を引かない=余計なAPI呼び出しをしない)。
|
|
78
|
+
* 0件・複数一致はAPIを叩く前にCLIのエラーにする。**エラー文には認証値もURLも出さない**
|
|
79
|
+
* (出口の `redactSecrets` に頼らず、そもそも載せない)。
|
|
80
|
+
*/
|
|
81
|
+
export async function resolveTaskRef(ref, listTasks, options = {}) {
|
|
82
|
+
const trimmed = String(ref ?? "").trim();
|
|
83
|
+
const matched = RECORD_NUMBER_ARG.exec(trimmed);
|
|
84
|
+
if (matched === null) return trimmed;
|
|
85
|
+
|
|
86
|
+
const number = Number.parseInt(matched[1], 10);
|
|
87
|
+
const items = await listTasks();
|
|
88
|
+
let hits = (Array.isArray(items) ? items : []).filter(
|
|
89
|
+
(item) => typeof item?.id === "string" && recordNumberFromContextRef(item?.context_ref) === number,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// 同点のときだけ絞る。1件しかないものを手元のファイルの有無で消すと、
|
|
93
|
+
// 記録をまだpullしていないだけの相手を「無い」と言ってしまう。
|
|
94
|
+
if (hits.length > 1 && typeof options.narrow === "function") {
|
|
95
|
+
const narrowed = await options.narrow(hits);
|
|
96
|
+
if (Array.isArray(narrowed) && narrowed.length === 1) hits = narrowed;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (hits.length === 0) {
|
|
100
|
+
throw cliError(
|
|
101
|
+
`記録 ${number} のタスクは見つかりません。\n`
|
|
102
|
+
+ `context_ref が docs/records/${number}-… のタスクが一覧にありません。`
|
|
103
|
+
+ "IDで指定するか、hub task list で確かめてください",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (hits.length > 1) {
|
|
107
|
+
// 候補は「1行1件」で読む(title にも改行を仕込めるので同じく均す)
|
|
108
|
+
const candidates = hits.map(
|
|
109
|
+
(item) => `- ${toSingleLine(item.id)} [${toSingleLine(item.status)}] ${toSingleLine(item.title)}`,
|
|
110
|
+
);
|
|
111
|
+
throw cliError(
|
|
112
|
+
`記録 ${number} のタスクが複数あります。IDで指定してください。\n`
|
|
113
|
+
+ "(記録番号はrepoごとの採番なので、別プロジェクトと重なることがあります)\n"
|
|
114
|
+
+ candidates.join("\n"),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
options.onResolved?.(hits[0], number);
|
|
118
|
+
return hits[0].id;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 候補の `context_ref` が「今いるrepoの作業ツリーにある**通常ファイル**」を指すか。
|
|
123
|
+
*
|
|
124
|
+
* **`lstat` で1要素ずつ確かめ、symlink は追わない**(codex1 レビュー Medium 1)。
|
|
125
|
+
* `stat` は symlink をたどるので、作業ツリー内の symlink が repo の外を指していれば
|
|
126
|
+
* repo外の実体を見て「記録が在る」と判定してしまう。同点の割り方は
|
|
127
|
+
* `claim` / `report` / `note` の**更新先**を決めるので、ここを緩めると
|
|
128
|
+
* 作業ツリーに置いた1本のリンクで別プロジェクトのタスクを書き換えさせられる。
|
|
129
|
+
*
|
|
130
|
+
* 途中の要素は directory、末尾は通常 file であることも要る(`153-x.md` という名の
|
|
131
|
+
* ディレクトリを「記録が在る」と数えない)。symlink はその場で打ち切るので、
|
|
132
|
+
* リンクの**先**へfilesystem操作を進めない。
|
|
133
|
+
*/
|
|
134
|
+
async function hasPlainRecordFile(root, segments, lstatImpl) {
|
|
135
|
+
let current = root;
|
|
136
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
137
|
+
current = path.join(current, segments[index]);
|
|
138
|
+
let entry;
|
|
139
|
+
try {
|
|
140
|
+
entry = await lstatImpl(current);
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
// symlink はここで打ち切る(先を見に行かない)
|
|
145
|
+
if (entry.isSymbolicLink?.()) return false;
|
|
146
|
+
const last = index === segments.length - 1;
|
|
147
|
+
if (last ? entry.isFile?.() !== true : entry.isDirectory?.() !== true) return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 同点の候補を「今いるrepoの作業ツリーに記録ファイルが在るもの」へ絞る。
|
|
154
|
+
*
|
|
155
|
+
* `context_ref` はリポジトリルート相対(記録147・`resolveRecordTarget`)。repoの外へ出る
|
|
156
|
+
* 綴りは**stat もせずに捨てる**(APIから来た文字列で作業ツリーの外を触らない)。
|
|
157
|
+
* repoの外で実行した・判定できないときは元の候補をそのまま返す(=候補提示のエラーになる)。
|
|
158
|
+
*/
|
|
159
|
+
export async function narrowByRepoRecord(hits, dependencies) {
|
|
160
|
+
const root = await findRepoRoot(dependencies.cwd(), dependencies.statImpl);
|
|
161
|
+
if (root === null) return hits;
|
|
162
|
+
const survivors = [];
|
|
163
|
+
for (const item of hits) {
|
|
164
|
+
const ref = typeof item?.context_ref === "string" ? item.context_ref : "";
|
|
165
|
+
const segments = ref.split("/");
|
|
166
|
+
if (ref === "" || path.isAbsolute(ref) || segments.includes("..") || segments.includes("")) continue;
|
|
167
|
+
if (await hasPlainRecordFile(root, segments, dependencies.lstatImpl)) survivors.push(item);
|
|
168
|
+
}
|
|
169
|
+
return survivors;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* コマンドから使う入口。一覧は **iced も含めて**取る(記録番号で呼ぶ相手が保留中でも引けるように)。
|
|
174
|
+
*/
|
|
175
|
+
export async function resolveTaskIdArg(ref, api, dependencies) {
|
|
176
|
+
return await resolveTaskRef(
|
|
177
|
+
ref,
|
|
178
|
+
async () => {
|
|
179
|
+
const payload = await api("/api/tasks?include_iced=true");
|
|
180
|
+
return payload?.items ?? [];
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
narrow: (hits) => narrowByRepoRecord(hits, dependencies),
|
|
184
|
+
// どのIDになったかは**必ず見せる**(番号で書いた指示と実際に触った相手を突き合わせられるように)。
|
|
185
|
+
// stdout は `--json` のデータ専用なので stderr へ1行(`--repo-card` の出力先表示と同じ扱い)。
|
|
186
|
+
onResolved: (item, number) => {
|
|
187
|
+
dependencies.stderr.write(
|
|
188
|
+
`記録 ${number} → ${toSingleLine(item.id)}(${toSingleLine(item.context_ref)})\n`,
|
|
189
|
+
);
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
);
|
|
193
|
+
}
|