@pecot/workflow-mcp 7.0.1-dev.26 → 7.0.1-dev.28

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.
Files changed (31) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/cli/dist/cli.js +2 -2
  3. package/cli/dist/commands/board-add.js +12 -3
  4. package/cli/dist/commands/board-judgment.d.ts +4 -2
  5. package/cli/dist/commands/board-judgment.js +5 -3
  6. package/cli/dist/commands/board-move.js +11 -2
  7. package/cli/dist/commands/field-write-failure.d.ts +14 -0
  8. package/cli/dist/commands/field-write-failure.js +25 -0
  9. package/cli/dist/commands/issue-board.d.ts +7 -4
  10. package/cli/dist/commands/issue-board.js +24 -9
  11. package/cli/dist/commands/issue-create.js +1 -1
  12. package/cli/dist/commands/issue-reopen.js +22 -5
  13. package/cli/dist/commands/issue-shared.d.ts +1 -6
  14. package/cli/dist/commands/issue-shared.js +7 -37
  15. package/cli/dist/commands/pr-reference.js +4 -14
  16. package/cli/dist/commands/pr-waiting.d.ts +7 -2
  17. package/cli/dist/commands/pr-waiting.js +4 -4
  18. package/cli/dist/commands/pr.js +11 -7
  19. package/cli/dist/commands/repository-match.d.ts +6 -2
  20. package/cli/dist/commands/repository-match.js +11 -11
  21. package/cli/dist/commands/session-start.js +10 -1
  22. package/cli/dist/commands/tracker-sync-dependabot.js +2 -4
  23. package/cli/dist/commands/tracker-sync-security.js +2 -3
  24. package/cli/dist/domain/repository-policy.d.ts +3 -3
  25. package/cli/dist/domain/repository-policy.js +17 -4
  26. package/cli/dist/domain/repository-resolver.d.ts +30 -7
  27. package/cli/dist/domain/repository-resolver.js +64 -25
  28. package/cli/dist/infra/worktree.d.ts +1 -1
  29. package/cli/dist/infra/worktree.js +2 -2
  30. package/npm-shrinkwrap.json +2 -2
  31. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pecot-w",
3
- "version": "7.0.1-dev.26",
3
+ "version": "7.0.1-dev.28",
4
4
  "description": "pecot-w (pecot-workflow) workflow automation plugin for Claude Code - skills, hooks, agents, and commands for AI-assisted development",
5
5
  "author": {
6
6
  "name": "pecot"
package/cli/dist/cli.js CHANGED
@@ -15,7 +15,7 @@
15
15
  import { realpathSync } from 'node:fs';
16
16
  import { pathToFileURL } from 'node:url';
17
17
  import { InvalidValueError } from './domain/errors.js';
18
- import { AmbiguousRepositoryError, parseOwnerRepository, resolveRepository } from './domain/repository-resolver.js';
18
+ import { AmbiguousRepositoryError, parseOwnerRepository, resolveRepository, UnreadableRemoteError } from './domain/repository-resolver.js';
19
19
  import { readAuthoredNotes } from './infra/authored-notes.js';
20
20
  import { gitRunnerFor } from './infra/git.js';
21
21
  import { resolveApiUrlOverride } from './infra/github/client.js';
@@ -87,7 +87,7 @@ function showRepository(repository, context) {
87
87
  // eslint-disable-next-line no-restricted-syntax -- CLI の最上位でグローバルの --repo を読むときだけ出る
88
88
  if (error instanceof InvalidValueError)
89
89
  context.io.stderr(`error: --repo: ${error.message}\n`);
90
- else if (error instanceof AmbiguousRepositoryError)
90
+ else if (error instanceof AmbiguousRepositoryError || error instanceof UnreadableRemoteError)
91
91
  context.io.stderr(`error: ${error.message}\n`);
92
92
  else
93
93
  throw error;
@@ -5,6 +5,7 @@ import { defineCommand } from './command-definition.js';
5
5
  import { addIssueToBoard, isStatusConfigured, setIssueField } from './issue-board.js';
6
6
  import { stopWith, requireActiveConfigPlain } from './command-stop.js';
7
7
  import { kindOfFailure } from './failure.js';
8
+ import { fieldWriteFailure } from './field-write-failure.js';
8
9
  import { connectToProject, exitInvalidStatus, ISSUE_REF_DESCRIPTION, issuePath, notConfiguredMessage, parseIssueReferenceOrExit, runWithExit, VALID_STATUSES, } from './issue-shared.js';
9
10
  import { createOutput, DRY_RUN_FIELD } from './output.js';
10
11
  const BOARD_ADD_OUTPUT = z.strictObject({
@@ -51,11 +52,19 @@ const BOARD_ADD = defineCommand({
51
52
  const { itemId } = await addIssueToBoard(client, config, owner, repository, number, undefined);
52
53
  output.done({ verb: 'add', target: `${target} to project` });
53
54
  output.result({ issue: issuePath(owner, repository, number), added: true });
54
- if (status !== '') {
55
+ if (status === '')
56
+ return;
57
+ try {
55
58
  await setIssueField(client, config, itemId, 'workflow', status);
56
- output.done({ verb: 'set', target: `${target} status ${status}` });
57
- output.result({ status });
58
59
  }
60
+ catch (error) {
61
+ if (!(error instanceof GitHubAPIError))
62
+ throw error;
63
+ // 追加は済んでいるので、追加の失敗とは別の文で止める
64
+ stopWith(output, fieldWriteFailure(`could not set ${target} status ${status}: ${error.message}`, error), kindOfFailure(error));
65
+ }
66
+ output.done({ verb: 'set', target: `${target} status ${status}` });
67
+ output.result({ status });
59
68
  }
60
69
  catch (error) {
61
70
  if (!(error instanceof GitHubAPIError))
@@ -7,6 +7,7 @@ import type { GitHubClient } from '../infra/github/index.js';
7
7
  import type { IssueReadiness, IssueSnapshot, JudgedIssue, ReadinessCache } from './issue-readiness.js';
8
8
  import type { HintedText } from './command-hint.js';
9
9
  import type { BoardMoveLine } from './issue-board.js';
10
+ import type { FieldHintState } from './field-write-failure.js';
10
11
  import type { Output } from './output.js';
11
12
  /**
12
13
  board sync と pr create が判定し直す列
@@ -56,9 +57,10 @@ export interface BoardContext {
56
57
  /**
57
58
  判定の結果に合わせて、列と札を動かす。読めない Issue は warning にし、ボードに無い値は最後に 1 行の warning にまとめる。
58
59
  isDryRun は同じ文を予定の行で出し、書かない。書き込みに失敗した Issue の数と、行に出した列と札(dry-run では予定)を返す。
59
- moves を渡すと、行に出した列と札をそこへ足していくので、途中で例外が出ても書けた分が残る
60
+ moves を渡すと、行に出した列と札をそこへ足していくので、途中で例外が出ても書けた分が残る。
61
+ hintState は、選択肢の ID を読み直す案内を 1 回だけ出すための印。省くと呼び出しごとに 1 つ作る
60
62
  */
61
- export declare function applyJudgedMoves(context: Readonly<BoardContext>, judged: readonly JudgedTarget[], isDryRun?: boolean, moves?: BoardMoveLine[]): Promise<{
63
+ export declare function applyJudgedMoves(context: Readonly<BoardContext>, judged: readonly JudgedTarget[], isDryRun?: boolean, moves?: BoardMoveLine[], hintState?: FieldHintState): Promise<{
62
64
  readonly failures: number;
63
65
  readonly moves: readonly BoardMoveLine[];
64
66
  }>;
@@ -89,10 +89,12 @@ export async function judgeBoard(client, config, items, progress, options) {
89
89
  /**
90
90
  判定の結果に合わせて、列と札を動かす。読めない Issue は warning にし、ボードに無い値は最後に 1 行の warning にまとめる。
91
91
  isDryRun は同じ文を予定の行で出し、書かない。書き込みに失敗した Issue の数と、行に出した列と札(dry-run では予定)を返す。
92
- moves を渡すと、行に出した列と札をそこへ足していくので、途中で例外が出ても書けた分が残る
92
+ moves を渡すと、行に出した列と札をそこへ足していくので、途中で例外が出ても書けた分が残る。
93
+ hintState は、選択肢の ID を読み直す案内を 1 回だけ出すための印。省くと呼び出しごとに 1 つ作る
93
94
  */
94
- export async function applyJudgedMoves(context, judged, isDryRun = false, moves = []) {
95
+ export async function applyJudgedMoves(context, judged, isDryRun = false, moves = [], hintState) {
95
96
  const { out, client, config, home } = context;
97
+ const fieldHint = hintState ?? { hasHinted: false };
96
98
  const missing = new Set();
97
99
  let failures = 0;
98
100
  for (const { target, result } of judged) {
@@ -115,7 +117,7 @@ export async function applyJudgedMoves(context, judged, isDryRun = false, moves
115
117
  moves.push(planned);
116
118
  }
117
119
  else if (typeof itemId === 'string') {
118
- const applied = await applyBoardMove(out, client, config, itemId, destination, move, text);
120
+ const applied = await applyBoardMove(out, client, config, itemId, destination, move, text, fieldHint);
119
121
  if (applied.hasFailed)
120
122
  failures += 1;
121
123
  if (applied.written !== undefined)
@@ -6,6 +6,7 @@ import { isStatusConfigured, setIssueField } from './issue-board.js';
6
6
  import { commandHint, hinted } from './command-hint.js';
7
7
  import { stopWith, requireActiveConfigPlain } from './command-stop.js';
8
8
  import { kindOfFailure } from './failure.js';
9
+ import { fieldWriteFailure } from './field-write-failure.js';
9
10
  import { connectToProject, exitInvalidStatus, ISSUE_REF_DESCRIPTION, issuePath, notConfiguredMessage, parseIssueReferenceOrExit, runWithExit, VALID_STATUSES, } from './issue-shared.js';
10
11
  import { createOutput, DRY_RUN_FIELD } from './output.js';
11
12
  const BOARD_MOVE_OUTPUT = z.strictObject({
@@ -47,9 +48,17 @@ const BOARD_MOVE = defineCommand({
47
48
  output.result({ issue: issuePath(owner, repository, number), status });
48
49
  return;
49
50
  }
50
- if (!await setIssueField(client, config, itemId, 'workflow', status)) {
51
- stopWith(output, notConfiguredMessage(status), 'status-not-configured');
51
+ let isSet;
52
+ try {
53
+ isSet = await setIssueField(client, config, itemId, 'workflow', status);
54
+ }
55
+ catch (error) {
56
+ if (!(error instanceof GitHubAPIError))
57
+ throw error;
58
+ stopWith(output, fieldWriteFailure(`could not set ${target} status ${status}: ${error.message}`, error), kindOfFailure(error));
52
59
  }
60
+ if (!isSet)
61
+ stopWith(output, notConfiguredMessage(status), 'status-not-configured');
53
62
  output.done({ verb: 'set', target: `${target} status ${status}` });
54
63
  output.result({ issue: issuePath(owner, repository, number), status });
55
64
  }
@@ -0,0 +1,14 @@
1
+ import type { GitHubAPIError } from '../infra/github/errors.js';
2
+ import type { HintedText } from './command-hint.js';
3
+ /**
4
+ 選択肢の ID を読み直す案内を 1 回の実行で 1 回だけ出すための印
5
+ */
6
+ export interface FieldHintState {
7
+ hasHinted: boolean;
8
+ }
9
+ /**
10
+ 選択肢の書き込みの失敗の文。古い ID で落ちたとき(VALIDATION)だけ、ID を読み直す案内を添える。
11
+ hintState を渡すと案内は 1 回だけ、省くと毎回添える
12
+ */
13
+ export declare function fieldWriteFailure(message: string, error: Readonly<GitHubAPIError>, hintState?: FieldHintState): string | HintedText;
14
+ //# sourceMappingURL=field-write-failure.d.ts.map
@@ -0,0 +1,25 @@
1
+ // ボードの選択肢の書き込みの失敗の文。issue-board.ts と issue-shared.ts の両方が使うので、どちらにも置かない(循環 import を避ける)
2
+ import path from 'node:path';
3
+ import { getActiveConfigPath, projectsDirectory } from '../infra/config-store.js';
4
+ import { commandHint, hinted, joinHinted, placeholder } from './command-hint.js';
5
+ function rereadOptionsHint() {
6
+ const configPath = getActiveConfigPath();
7
+ // projects/ の外の config は、ファイル名では project activate が見つけられない
8
+ const project = configPath === undefined
9
+ ? placeholder('PROJECT')
10
+ : (path.dirname(configPath) === projectsDirectory() ? path.basename(configPath, '.json') : configPath);
11
+ return hinted `hint: if the board options were recreated, run ${commandHint(['project', 'activate'], { project })} to read their IDs again`;
12
+ }
13
+ /**
14
+ 選択肢の書き込みの失敗の文。古い ID で落ちたとき(VALIDATION)だけ、ID を読み直す案内を添える。
15
+ hintState を渡すと案内は 1 回だけ、省くと毎回添える
16
+ */
17
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- 出したことを hintState に書く
18
+ export function fieldWriteFailure(message, error, hintState) {
19
+ if (error.errorType !== 'VALIDATION' || hintState?.hasHinted === true)
20
+ return message;
21
+ if (hintState !== undefined)
22
+ hintState.hasHinted = true;
23
+ return joinHinted([message, rereadOptionsHint()]);
24
+ }
25
+ //# sourceMappingURL=field-write-failure.js.map
@@ -5,6 +5,7 @@ import type { IssueReference } from '../domain/reference-parser.js';
5
5
  import type { RepositoryReference } from '../domain/repository-resolver.js';
6
6
  import type { JsonObject } from '../domain/json.js';
7
7
  import type { GitHubClient } from '../infra/github/index.js';
8
+ import type { FieldHintState } from './field-write-failure.js';
8
9
  import type { Output } from './output.js';
9
10
  export interface BoardItem {
10
11
  readonly itemId: string;
@@ -41,9 +42,10 @@ export interface PutOnBoardOptions {
41
42
  }
42
43
  /**
43
44
  ボードへの追加と、Status(Backlog)・Priority の設定(何度やっても同じ結果になる)。
44
- 途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。失敗したら GitHubAPIError
45
+ 途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。追加と欄の読み込みの失敗は GitHubAPIError。
46
+ 欄の書き込みの失敗は error の行にして残りの欄を続け、書けなかった欄の数を返す
45
47
  */
46
- export declare function putOnBoard(client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, priority: string | undefined, options: Readonly<PutOnBoardOptions>): Promise<void>;
48
+ export declare function putOnBoard(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, priority: string | undefined, options: Readonly<PutOnBoardOptions>): Promise<number>;
47
49
  /**
48
50
  列と札の行(moved: と set: Status of)に出した値。issue は行の表示の参照、reason は列を動かす理由の文。書いていない側は undefined
49
51
  */
@@ -88,9 +90,10 @@ interface MoveTarget {
88
90
  }
89
91
  /**
90
92
  decideBoardMove の結果をボードに書く。書き込みの失敗は warning にして続ける(元の列のまま)。
91
- text は列を動かす理由の判定の文。board sync と issue block / unblock が使う
93
+ text は列を動かす理由の判定の文。board sync と issue block / unblock が使う。
94
+ hintState は、選択肢の ID を読み直す案内を 1 回の実行で 1 回だけ出すための印(省くと毎回出す)
92
95
  */
93
- export declare function applyBoardMove(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, itemId: string, target: MoveTarget, move: Readonly<BoardMove>, text: string): Promise<AppliedMove>;
96
+ export declare function applyBoardMove(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, itemId: string, target: MoveTarget, move: Readonly<BoardMove>, text: string, hintState?: FieldHintState): Promise<AppliedMove>;
94
97
  /**
95
98
  applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)。予定の列と札を返し、どちらも無ければ undefined
96
99
  */
@@ -6,6 +6,7 @@ import { COLUMN_CONFIG_KEYS, LABEL_CONFIG_KEYS } from '../domain/board-move.js';
6
6
  import { getFieldId, getOptionId } from '../domain/config.js';
7
7
  import { displayReference } from '../domain/readiness.js';
8
8
  import { GitHubAPIError } from '../infra/github/errors.js';
9
+ import { fieldWriteFailure } from './field-write-failure.js';
9
10
  // 作ったボード項目の Status(Tracker はここから始める)
10
11
  const BOARD_STATUS = 'backlog';
11
12
  /**
@@ -58,18 +59,31 @@ export async function itemHasFieldValue(client, config, owner, repository, issue
58
59
  }
59
60
  /**
60
61
  ボードへの追加と、Status(Backlog)・Priority の設定(何度やっても同じ結果になる)。
61
- 途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。失敗したら GitHubAPIError
62
+ 途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。追加と欄の読み込みの失敗は GitHubAPIError。
63
+ 欄の書き込みの失敗は error の行にして残りの欄を続け、書けなかった欄の数を返す
62
64
  */
63
- export async function putOnBoard(client, config, owner, repository, issueNumber, priority, options) {
65
+ export async function putOnBoard(out, client, config, owner, repository, issueNumber, priority, options) {
66
+ const hintState = { hasHinted: false };
64
67
  const { itemId } = await addIssueToBoard(client, config, owner, repository, issueNumber, undefined);
65
- const fields = [['workflow', BOARD_STATUS]];
68
+ // 3 つ目は error の行に出す欄の名前
69
+ const fields = [['workflow', BOARD_STATUS, 'status']];
66
70
  if (priority !== undefined)
67
- fields.push(['priority', priority]);
68
- for (const [fieldName, option] of fields) {
71
+ fields.push(['priority', priority, 'priority']);
72
+ let failures = 0;
73
+ for (const [fieldName, option, label] of fields) {
69
74
  if (options.onlyIfEmpty && await itemHasFieldValue(client, config, owner, repository, issueNumber, itemId, fieldName))
70
75
  continue;
71
- await setIssueField(client, config, itemId, fieldName, option);
76
+ try {
77
+ await setIssueField(client, config, itemId, fieldName, option);
78
+ }
79
+ catch (error) {
80
+ if (!(error instanceof GitHubAPIError))
81
+ throw error;
82
+ out.error(fieldWriteFailure(`could not set ${label} ${option} of Tracker #${String(issueNumber)}: ${error.message}`, error, hintState));
83
+ failures += 1;
84
+ }
72
85
  }
86
+ return failures;
73
87
  }
74
88
  /**
75
89
  列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync・pr create・issue block / unblock の data が使う
@@ -101,9 +115,10 @@ function warnConflict(out, name, target, conflict) {
101
115
  }
102
116
  /**
103
117
  decideBoardMove の結果をボードに書く。書き込みの失敗は warning にして続ける(元の列のまま)。
104
- text は列を動かす理由の判定の文。board sync と issue block / unblock が使う
118
+ text は列を動かす理由の判定の文。board sync と issue block / unblock が使う。
119
+ hintState は、選択肢の ID を読み直す案内を 1 回の実行で 1 回だけ出すための印(省くと毎回出す)
105
120
  */
106
- export async function applyBoardMove(out, client, config, itemId, target, move, text) {
121
+ export async function applyBoardMove(out, client, config, itemId, target, move, text, hintState) {
107
122
  const name = displayReference(target.ref, target.home);
108
123
  if (move.conflict !== undefined)
109
124
  warnConflict(out, name, target, move.conflict);
@@ -123,7 +138,7 @@ export async function applyBoardMove(out, client, config, itemId, target, move,
123
138
  catch (error) {
124
139
  if (!(error instanceof GitHubAPIError))
125
140
  throw error;
126
- out.warning(`could not move ${name}: ${error.message}`);
141
+ out.warning(fieldWriteFailure(`could not move ${name}: ${error.message}`, error, hintState));
127
142
  hasFailed = true;
128
143
  }
129
144
  const written = column === undefined && label === undefined ? undefined : { issue: name, column, label, reason: text };
@@ -162,7 +162,7 @@ async function settleColumn(output, client, config, session, issue, item, linked
162
162
  if (move === undefined)
163
163
  return undefined;
164
164
  // 起票の直後は、既定の自動化が札を書くので、札は書かない
165
- const applied = await applyBoardMove(output, client, config, item.itemId, { ref: issue, home: issue.repository }, withoutLabel(move), describeReadiness(judged.readiness, judged.prerequisites, issue.repository));
165
+ const applied = await applyBoardMove(output, client, config, item.itemId, { ref: issue, home: issue.repository }, withoutLabel(move), describeReadiness(judged.readiness, judged.prerequisites, issue.repository), session.fieldHint);
166
166
  return applied.column;
167
167
  }
168
168
  function withoutLabel(move) {
@@ -7,6 +7,7 @@ import { defineCommand } from './command-definition.js';
7
7
  import { isStatusConfigured, setIssueField } from './issue-board.js';
8
8
  import { stopWith, requireActiveConfigPlain } from './command-stop.js';
9
9
  import { kindOfFailure } from './failure.js';
10
+ import { fieldWriteFailure } from './field-write-failure.js';
10
11
  import { connectToProject, exitInvalidStatus, ISSUE_REF_DESCRIPTION, issuePath, notConfiguredMessage, parseIssueReferenceOrExit, runWithExit, VALID_STATUSES, } from './issue-shared.js';
11
12
  import { createOutput, DRY_RUN_FIELD } from './output.js';
12
13
  // Projects V2 の自動化が Issue をもう一度閉じることがあるため、status を設定した後に待つ
@@ -42,14 +43,30 @@ async function reopenAndSetStatus(output, client, config, issue, status) {
42
43
  if (itemId === undefined) {
43
44
  output.warning(`${target} is not on the project board`);
44
45
  }
45
- else if (await setIssueField(client, config, itemId, 'workflow', status)) {
46
- output.done({ verb: 'set', target: `${target} status ${status}` });
47
- output.result({ status });
48
- await delay(AUTOMATION_WAIT_MILLISECONDS);
49
- }
50
46
  else {
47
+ await setReopenedStatus(output, client, config, { target, itemId }, status);
48
+ }
49
+ }
50
+ // 列を書く。書けなければ warning にとどめ、2 回目の reopen とコメントの投稿へ進む。設定できたときだけ自動化を待つ
51
+ async function setReopenedStatus(output, client, config, item, status) {
52
+ const { target, itemId } = item;
53
+ let isSet;
54
+ try {
55
+ isSet = await setIssueField(client, config, itemId, 'workflow', status);
56
+ }
57
+ catch (error) {
58
+ if (!(error instanceof GitHubAPIError))
59
+ throw error;
60
+ output.warning(fieldWriteFailure(`could not set ${target} status ${status}: ${error.message}`, error));
61
+ return;
62
+ }
63
+ if (!isSet) {
51
64
  output.warning(notConfiguredMessage(status));
65
+ return;
52
66
  }
67
+ output.done({ verb: 'set', target: `${target} status ${status}` });
68
+ output.result({ status });
69
+ await delay(AUTOMATION_WAIT_MILLISECONDS);
53
70
  }
54
71
  // 2 回目の reopen(自動化による close への対策)で open を確かめ、--comment があれば理由を投稿する
55
72
  async function confirmReopened(output, client, issue, comment) {
@@ -6,6 +6,7 @@ import type { IssueReference } from '../domain/reference-parser.js';
6
6
  import type { JsonObject } from '../domain/json.js';
7
7
  import type { GitHubClient } from '../infra/github/index.js';
8
8
  import type { HintedText } from './command-hint.js';
9
+ import type { FieldHintState } from './field-write-failure.js';
9
10
  import type { BoardItem } from './issue-board.js';
10
11
  import type { Output } from './output.js';
11
12
  export type IssueType = IssueFrontmatter['type'];
@@ -135,12 +136,6 @@ export interface IssueField {
135
136
  readonly label: string;
136
137
  }
137
138
  /**
138
- 選択肢の ID を読み直す案内を 1 回の実行で 1 回だけ出すための印
139
- */
140
- export interface FieldHintState {
141
- hasHinted: boolean;
142
- }
143
- /**
144
139
  カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。書き込みに失敗したフィールドは warning にして飛ばす。設定できたフィールドの名前を返す
145
140
  */
146
141
  export declare function setIssueFields(output: Output, client: GitHubClient, config: ProjectConfig, itemId: string, target: string, fields: readonly IssueField[], hintState: FieldHintState): Promise<readonly string[]>;
@@ -12,16 +12,16 @@ import { CommandExit } from './command-definition.js';
12
12
  import { planOrders, usedOrdersOf } from '../domain/issue-order.js';
13
13
  import { pythonStrip } from '../domain/python-format.js';
14
14
  import { issueReferenceToCliReference, parseIssueReference, ReferenceParseError } from '../domain/reference-parser.js';
15
- import { AmbiguousRepositoryError, createRepositoryReference, resolveRepository } from '../domain/repository-resolver.js';
15
+ import { createRepositoryReference, resolveShortReferenceBase, withUnreadableReason } from '../domain/repository-resolver.js';
16
16
  import { CLOSED_HEADINGS_BY_TEMPLATE, FOLD_SUMMARY_BY_TEMPLATE, validateBodyStyle, validateClosedHeadings, validateFoldBalance, validateFoldSummaries, validateHeadingSummaries, validateSections, } from '../domain/sections.js';
17
17
  import { gitRunnerFor } from '../infra/git.js';
18
- import { GitHubAPIError, GitHubAuthError, GitHubRateLimitError } from '../infra/github/errors.js';
18
+ import { GitHubAPIError } from '../infra/github/errors.js';
19
19
  import { requireNumber, requireString } from '../infra/github/payload.js';
20
20
  import { readTemplateSections, templateFile } from '../infra/template-store.js';
21
- import { getActiveConfigPath, projectsDirectory } from '../infra/config-store.js';
22
- import { commandHint, hinted, inputHint, inputNameHint, joinHinted, placeholder } from './command-hint.js';
21
+ import { commandHint, hinted, inputHint, inputNameHint } from './command-hint.js';
23
22
  import { stopWith } from './command-stop.js';
24
23
  import { kindOfFailure } from './failure.js';
24
+ import { fieldWriteFailure } from './field-write-failure.js';
25
25
  import { createGitHubClient } from './github-client.js';
26
26
  import { addIssueToBoard, createIssue, setIssueField } from './issue-board.js';
27
27
  import { USAGE_EXIT_CODE, UsageError } from './usage-error.js';
@@ -90,31 +90,17 @@ export function issuePath(owner, repository, number) {
90
90
  return `${owner}/${repository}/${String(number)}`;
91
91
  }
92
92
  /**
93
- グローバルの --repo(run の入力の repo)か、カレントの git から base のリポジトリを決める。
94
- 曖昧なら undefined(`owner/repo/N` の主軸形を使う利用者のため)。--repo の形式が不正なら InvalidValueError を伝える
95
- */
96
- function resolveBaseRepository(repository) {
97
- try {
98
- return resolveRepository(repository, gitRunnerFor()).repository;
99
- }
100
- catch (error) {
101
- if (error instanceof AmbiguousRepositoryError)
102
- return undefined;
103
- throw error;
104
- }
105
- }
106
- /**
107
93
  Issue 参照(`owner/repo/N` または短縮形 `N`)を分ける。不正、または base が決まらない短縮形なら BadParameterError
108
94
  */
109
95
  function parseIssueReferenceFromContext(repository, raw) {
110
- const base = resolveBaseRepository(repository);
96
+ const { base, unreadable } = resolveShortReferenceBase(repository, gitRunnerFor());
111
97
  try {
112
98
  const reference = parseIssueReference(raw, base, { repositoryFlag: true });
113
99
  return { owner: reference.repository.owner, repository: reference.repository.repository, number: reference.number };
114
100
  }
115
101
  catch (error) {
116
102
  if (error instanceof ReferenceParseError)
117
- throw new BadParameterError(error.hintedText ?? error.message);
103
+ throw new BadParameterError(withUnreadableReason(error.hintedText ?? error.message, unreadable));
118
104
  throw error;
119
105
  }
120
106
  }
@@ -306,14 +292,6 @@ export async function addToBoardOrWarn(output, client, config, owner, repository
306
292
  output.done({ verb: 'add', target: `Issue ${issuePath(owner, repository, issueNumber)} to project` });
307
293
  return added;
308
294
  }
309
- function rereadOptionsHint() {
310
- const configPath = getActiveConfigPath();
311
- // projects/ の外の config は、ファイル名では project activate が見つけられない
312
- const project = configPath === undefined
313
- ? placeholder('PROJECT')
314
- : (path.dirname(configPath) === projectsDirectory() ? path.basename(configPath, '.json') : configPath);
315
- return hinted `hint: if the board options were recreated, run ${commandHint(['project', 'activate'], { project })} to read their IDs again`;
316
- }
317
295
  /**
318
296
  カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。書き込みに失敗したフィールドは warning にして飛ばす。設定できたフィールドの名前を返す
319
297
  */
@@ -330,15 +308,7 @@ export async function setIssueFields(output, client, config, itemId, target, fie
330
308
  catch (error) {
331
309
  if (!(error instanceof GitHubAPIError))
332
310
  throw error;
333
- const message = `could not set ${label} of ${target}: ${error.message}`;
334
- // 選択肢を作り直すと config の ID が古くなり、書き込みが落ちる。認証とレート制限の失敗は、読み直しても直らない
335
- const canReread = !(error instanceof GitHubAuthError || error instanceof GitHubRateLimitError);
336
- if (!canReread || hintState.hasHinted) {
337
- output.warning(message);
338
- continue;
339
- }
340
- output.warning(joinHinted([message, rereadOptionsHint()]));
341
- hintState.hasHinted = true;
311
+ output.warning(fieldWriteFailure(`could not set ${label} of ${target}: ${error.message}`, error, hintState));
342
312
  }
343
313
  }
344
314
  if (labels.length > 0)
@@ -1,29 +1,19 @@
1
1
  // PR の参照(pr_ref)の読み方。pr show・pr merge・session finish が共有する。
2
2
  import { ReferenceParseError, parsePullRequestReference } from '../domain/reference-parser.js';
3
- import { AmbiguousRepositoryError, resolveRepository } from '../domain/repository-resolver.js';
3
+ import { resolveShortReferenceBase, withUnreadableReason } from '../domain/repository-resolver.js';
4
4
  import { gitRunnerFor } from '../infra/git.js';
5
5
  import { stopWith } from './command-stop.js';
6
6
  import { USAGE_EXIT_CODE } from './usage-error.js';
7
7
  export const PR_REFERENCE_DESCRIPTION = 'PR reference (`owner/repo/N`, or the short form `N` in the repository of `--repo`, or else of the git remote of the current directory)';
8
- // グローバルの --repo か、いまの git の repository。決められなければ undefined
9
- function resolveBaseRepository(globalRepository) {
10
- try {
11
- return resolveRepository(globalRepository, gitRunnerFor(process.cwd())).repository;
12
- }
13
- catch (error) {
14
- if (error instanceof AmbiguousRepositoryError)
15
- return undefined;
16
- throw error;
17
- }
18
- }
19
8
  export function parseReference(reference, globalRepository, out) {
9
+ const { base, unreadable } = resolveShortReferenceBase(globalRepository, gitRunnerFor(process.cwd()));
20
10
  try {
21
- const parsed = parsePullRequestReference(reference, resolveBaseRepository(globalRepository), { repositoryFlag: true });
11
+ const parsed = parsePullRequestReference(reference, base, { repositoryFlag: true });
22
12
  return { owner: parsed.repository.owner, repository: parsed.repository.repository, number: parsed.number };
23
13
  }
24
14
  catch (error) {
25
15
  if (error instanceof ReferenceParseError)
26
- return stopWith(out, error.hintedText ?? error.message, 'invalid-input', USAGE_EXIT_CODE);
16
+ return stopWith(out, withUnreadableReason(error.hintedText ?? error.message, unreadable), 'invalid-input', USAGE_EXIT_CODE);
27
17
  throw error;
28
18
  }
29
19
  }
@@ -6,6 +6,7 @@ import type { GitHubClient } from '../infra/github/index.js';
6
6
  import type { BoardContext, JudgedTarget } from './board-judgment.js';
7
7
  import type { HintedText } from './command-hint.js';
8
8
  import type { BoardMoveLine } from './issue-board.js';
9
+ import type { FieldHintState } from './field-write-failure.js';
9
10
  import type { JudgedIssue, ReadinessCache } from './issue-readiness.js';
10
11
  import type { Output } from './output.js';
11
12
  export interface CreatedPullRequest {
@@ -41,6 +42,10 @@ export interface WaitingOptions {
41
42
  readonly check: WaitingCheck;
42
43
  readonly isDryRun: boolean;
43
44
  readonly cache: ReadinessCache;
45
+ /**
46
+ 選択肢の ID を読み直す案内を 1 回だけ出すための印。省くと applyJudgedMoves が 1 つ作る
47
+ */
48
+ readonly fieldHint?: FieldHintState;
44
49
  }
45
50
  /**
46
51
  判定の前提のうち、issue の前提
@@ -53,7 +58,7 @@ heads を待つ Issue を読み、判定に合わせてボードの列と札を
53
58
  export declare function moveIssuesWaitingFor(context: Readonly<BoardContext>, options: WaitingOptions, moves?: BoardMoveLine[]): Promise<readonly JudgedTarget[]>;
54
59
  /**
55
60
  pr create の後に、head の Issue を待つ Issue の列と札を動かす。作った PR が判定に出るまで 1 回だけ読み直す。
56
- 動かした列と札(moved: と set: の行の値)を moves に足していき、それを返す
61
+ 動かした列と札(moved: と set: の行の値)を moves に足していき、それを返す。fieldHint は、in_review の書き込みと同じ印を渡す
57
62
  */
58
- export declare function moveWaitingIssues(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, created: CreatedPullRequest, moves?: BoardMoveLine[]): Promise<readonly BoardMoveLine[]>;
63
+ export declare function moveWaitingIssues(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, created: CreatedPullRequest, fieldHint: FieldHintState, moves?: BoardMoveLine[]): Promise<readonly BoardMoveLine[]>;
59
64
  //# sourceMappingURL=pr-waiting.d.ts.map
@@ -83,7 +83,7 @@ async function moveWaiting(waiting, issues, moves) {
83
83
  return [];
84
84
  const { assume } = options.check;
85
85
  const confirmed = assume === undefined ? judged.confirmed : await Promise.all(judged.confirmed.map(async (target) => await assume(target)));
86
- await applyJudgedMoves(context, confirmed, options.isDryRun, moves);
86
+ await applyJudgedMoves(context, confirmed, options.isDryRun, moves, options.fieldHint);
87
87
  for (const { target } of judged.unconfirmed)
88
88
  context.out.warning(options.check.unconfirmed(displayReference(target.ref, context.home)));
89
89
  return confirmed;
@@ -128,16 +128,16 @@ export async function moveIssuesWaitingFor(context, options, moves = []) {
128
128
  }
129
129
  /**
130
130
  pr create の後に、head の Issue を待つ Issue の列と札を動かす。作った PR が判定に出るまで 1 回だけ読み直す。
131
- 動かした列と札(moved: と set: の行の値)を moves に足していき、それを返す
131
+ 動かした列と札(moved: と set: の行の値)を moves に足していき、それを返す。fieldHint は、in_review の書き込みと同じ印を渡す
132
132
  */
133
- export async function moveWaitingIssues(out, client, config, created, moves = []) {
133
+ export async function moveWaitingIssues(out, client, config, created, fieldHint, moves = []) {
134
134
  const context = { out, client, config, home: homeRepositoryOf(config) };
135
135
  const head = createIssueReference(created.repository, created.issueNumber);
136
136
  const check = {
137
137
  isReflected: judged => created.pullRequest === undefined || (prerequisiteOf(judged, head)?.issue.pullRequests.some(pullRequest => pullRequest.number === created.pullRequest) ?? false),
138
138
  unconfirmed: name => hinted `could not confirm that GitHub reflects PR #${String(created.pullRequest)} in the readiness of ${name}; its column was not moved; run ${commandHint(['board', 'sync'])} later to move it`,
139
139
  };
140
- await moveIssuesWaitingFor(context, { heads: [head], check, isDryRun: false, cache: createReadinessCache() }, moves);
140
+ await moveIssuesWaitingFor(context, { heads: [head], check, isDryRun: false, cache: createReadinessCache(), fieldHint }, moves);
141
141
  return moves;
142
142
  }
143
143
  //# sourceMappingURL=pr-waiting.js.map
@@ -40,6 +40,7 @@ import { PR_MERGE_COMMAND } from './pr-merge.js';
40
40
  import { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
41
41
  import { readRestackDecision } from './restack-reading.js';
42
42
  import { moveWaitingIssues } from './pr-waiting.js';
43
+ import { fieldWriteFailure } from './field-write-failure.js';
43
44
  export { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
44
45
  // 本文の検証の失敗。1(通信・設定・引数)と 2(preflight)と区別する
45
46
  const VALIDATION_EXIT_CODE = 3;
@@ -144,8 +145,8 @@ const PR_CREATE_OUTPUT = z.strictObject({
144
145
  function inReviewOperation(issueNumber) {
145
146
  return { verb: 'set', target: `Issue #${String(issueNumber)} status to In Review` };
146
147
  }
147
- // Status を In Review にした Issue の番号を返す。書かなかったら undefined
148
- async function updateIssueStatusToInReview(config, client, location, headBranch, out) {
148
+ // Status を In Review にした Issue の番号を返す。書かなかったら undefined。hintState は待ちの Issue の書き込みと同じ印
149
+ async function updateIssueStatusToInReview(config, client, location, headBranch, out, hintState) {
149
150
  const issueNumber = extractIssueNumberFromBranch(headBranch);
150
151
  if (issueNumber === undefined)
151
152
  return undefined;
@@ -176,7 +177,8 @@ async function updateIssueStatusToInReview(config, client, location, headBranch,
176
177
  await client.updateProjectItemField(config.project.id, itemId, fieldId, optionId);
177
178
  }
178
179
  catch (error) {
179
- out.warning(`status update of ${label} failed: ${reasonOf(error)}`);
180
+ const message = `status update of ${label} failed: ${reasonOf(error)}`;
181
+ out.warning(error instanceof GitHubAPIError ? fieldWriteFailure(message, error, hintState) : message);
180
182
  return;
181
183
  }
182
184
  out.done(inReviewOperation(issueNumber));
@@ -342,9 +344,9 @@ async function registerStack(client, location, lower, created, out) {
342
344
  }
343
345
  }
344
346
  // moves に、書けた列と札を足していく。例外で止まっても、それまでの分が残る
345
- async function moveWaitingIssuesSafely(client, config, location, issueNumber, pullRequest, out, moves) {
347
+ async function moveWaitingIssuesSafely(client, config, location, issueNumber, pullRequest, out, moves, hintState) {
346
348
  try {
347
- await moveWaitingIssues(out, client, config, { repository: location, issueNumber, pullRequest }, moves);
349
+ await moveWaitingIssues(out, client, config, { repository: location, issueNumber, pullRequest }, hintState, moves);
348
350
  }
349
351
  catch (error) {
350
352
  if (!isRequestFailure(error))
@@ -369,7 +371,9 @@ async function submitPullRequest(config, client, directory, draft, stackOn, base
369
371
  const url = jsonField(created, 'html_url');
370
372
  // url は先に渡す。後の処理が例外で止まっても、作った PR を結果から読める
371
373
  out.result({ head: draft.head, base: draft.base, title: draft.title, ...pullRequest !== undefined && { number: pullRequest }, ...typeof url === 'string' && { url } });
372
- const inReview = draft.isRelease ? undefined : await updateIssueStatusToInReview(config, client(), draft.location, draft.head, out);
374
+ // in_review と待ちの Issue の書き込みで、選択肢の ID を読み直す案内を 1 回だけ出す
375
+ const fieldHint = { hasHinted: false };
376
+ const inReview = draft.isRelease ? undefined : await updateIssueStatusToInReview(config, client(), draft.location, draft.head, out, fieldHint);
373
377
  if (inReview !== undefined)
374
378
  out.result({ inReview });
375
379
  if (stackOn !== undefined)
@@ -378,7 +382,7 @@ async function submitPullRequest(config, client, directory, draft, stackOn, base
378
382
  const moves = [];
379
383
  try {
380
384
  if (!draft.isRelease && isPositive(issueNumber))
381
- await moveWaitingIssuesSafely(client(), config, draft.location, issueNumber, pullRequest, out, moves);
385
+ await moveWaitingIssuesSafely(client(), config, draft.location, issueNumber, pullRequest, out, moves, fieldHint);
382
386
  }
383
387
  finally {
384
388
  out.result({ moves: moves.map(move => moveJson(move)) });
@@ -1,8 +1,12 @@
1
1
  import type { PolicyMode } from '../domain/repository-policy.js';
2
- import type { RepositoryReference, ResolvedRepository } from '../domain/repository-resolver.js';
2
+ import type { RepositoryReference, ResolvedRepository, UnreadableRemote } from '../domain/repository-resolver.js';
3
3
  import type { CommandIo } from './command-definition.js';
4
4
  /**
5
- 今の git remote からリポジトリを解決する。git の外・remote 無しは undefined
5
+ 今の git remote を読む。git の外・remote 無しは undefined、URL から owner/repo を読めなければ UnreadableRemote
6
+ */
7
+ export declare function readCurrentRepository(cwd: string): ResolvedRepository | UnreadableRemote | undefined;
8
+ /**
9
+ 今の git remote からリポジトリを解決する。git の外・remote 無し・URL から owner/repo を読めないときは undefined
6
10
  */
7
11
  export declare function resolveCurrentRepository(cwd: string): ResolvedRepository | undefined;
8
12
  /**
@@ -2,22 +2,22 @@
2
2
  // 判定は domain/repository-policy.ts の applyRepositoryPolicy に任せ、ここは git の解決と行の出力、止めるときの終了コードだけを行う。
3
3
  import { formatHinted } from '../domain/command-hint.js';
4
4
  import { AMBIGUOUS_REPOSITORY_LINE, applyRepositoryPolicy } from '../domain/repository-policy.js';
5
- import { AmbiguousRepositoryError, resolveRepository } from '../domain/repository-resolver.js';
5
+ import { readCurrentGitRemote } from '../domain/repository-resolver.js';
6
6
  import { gitRunnerFor, listRemotes } from '../infra/git.js';
7
7
  import { CommandExit } from './command-definition.js';
8
8
  import { WARNING_PREFIX } from './output.js';
9
9
  /**
10
- 今の git remote からリポジトリを解決する。git の外・remote 無しは undefined
10
+ 今の git remote を読む。git の外・remote 無しは undefined、URL から owner/repo を読めなければ UnreadableRemote
11
+ */
12
+ export function readCurrentRepository(cwd) {
13
+ return readCurrentGitRemote(gitRunnerFor(cwd));
14
+ }
15
+ /**
16
+ 今の git remote からリポジトリを解決する。git の外・remote 無し・URL から owner/repo を読めないときは undefined
11
17
  */
12
18
  export function resolveCurrentRepository(cwd) {
13
- try {
14
- return resolveRepository(undefined, gitRunnerFor(cwd));
15
- }
16
- catch (error) {
17
- if (error instanceof AmbiguousRepositoryError)
18
- return undefined;
19
- throw error;
20
- }
19
+ const current = readCurrentRepository(cwd);
20
+ return current?.source === 'unreadable-remote' ? undefined : current;
21
21
  }
22
22
  /**
23
23
  `--repo` と今の git remote を方針(reject か warn)に従って比べる。
@@ -25,7 +25,7 @@ export function resolveCurrentRepository(cwd) {
25
25
  止めるときは、stderr に行を書いて CommandExit(1) を投げる。warn の警告は stderr に書いて続ける
26
26
  */
27
27
  export function requireRepositoryMatch(mode, explicit, io, cwd) {
28
- const outcome = applyRepositoryPolicy({ explicit, resolved: resolveCurrentRepository(cwd), mode });
28
+ const outcome = applyRepositoryPolicy({ explicit, resolved: readCurrentRepository(cwd), mode });
29
29
  writeLines(io, outcome.stderr);
30
30
  if (outcome.kind === 'exit')
31
31
  throw new CommandExit(outcome.exitCode, outcome.failure);
@@ -12,6 +12,7 @@ import { defineCommand } from './command-definition.js';
12
12
  import { commandHint, hinted, joinHinted } from './command-hint.js';
13
13
  import { requireActiveConfig, stopWith } from './command-stop.js';
14
14
  import { kindOfFailure } from './failure.js';
15
+ import { fieldWriteFailure } from './field-write-failure.js';
15
16
  import { createGitHubClient } from './github-client.js';
16
17
  import { USAGE_EXIT_CODE } from './usage-error.js';
17
18
  import { requireRepositoryMatch, resolveCurrentRepository } from './repository-match.js';
@@ -93,7 +94,15 @@ async function setIssueStatusActive(out, client, config, issue) {
93
94
  out.warning(`could not set ${target}: the workflow status field has no 'active' option`);
94
95
  return;
95
96
  }
96
- await client.updateProjectItemField(config.project.id, itemId, fieldId, optionId);
97
+ try {
98
+ await client.updateProjectItemField(config.project.id, itemId, fieldId, optionId);
99
+ }
100
+ catch (error) {
101
+ if (!(error instanceof GitHubAPIError))
102
+ throw error;
103
+ out.warning(fieldWriteFailure(`could not set ${target}: ${error.message}`, error));
104
+ return;
105
+ }
97
106
  out.done({ verb: 'set', target });
98
107
  }
99
108
  catch (error) {
@@ -66,8 +66,7 @@ async function applyChanges(out, input) {
66
66
  out.done(operation);
67
67
  const created = requireNumber(issue['number'], 'number');
68
68
  out.result({ tracker: created, created: true, added: rows.added });
69
- await putOnBoard(client, config, owner, repository, created, PRIORITY, { onlyIfEmpty: false });
70
- return 0;
69
+ return await putOnBoard(out, client, config, owner, repository, created, PRIORITY, { onlyIfEmpty: false });
71
70
  }
72
71
  if (!isUnchanged) {
73
72
  try {
@@ -102,8 +101,7 @@ async function applyChanges(out, input) {
102
101
  return 0;
103
102
  }
104
103
  // 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
105
- await putOnBoard(client, config, owner, repository, number, PRIORITY, { onlyIfEmpty: true });
106
- return 0;
104
+ return await putOnBoard(out, client, config, owner, repository, number, PRIORITY, { onlyIfEmpty: true });
107
105
  }
108
106
  catch (error) {
109
107
  const detail = apiErrorDetail(error);
@@ -85,8 +85,7 @@ async function applyChanges(out, input) {
85
85
  out.done(operation);
86
86
  const created = requireNumber(issue['number'], 'number');
87
87
  out.result({ tracker: created, created: true, added: rows.added });
88
- await putOnBoard(client, config, owner, repository, created, priority, { onlyIfEmpty: false });
89
- return 0;
88
+ return await putOnBoard(out, client, config, owner, repository, created, priority, { onlyIfEmpty: false });
90
89
  }
91
90
  let failures = 0;
92
91
  let isUpdated = true;
@@ -110,7 +109,7 @@ async function applyChanges(out, input) {
110
109
  out.result(rows);
111
110
  }
112
111
  // 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
113
- await putOnBoard(client, config, owner, repository, number, priority, { onlyIfEmpty: true });
112
+ failures += await putOnBoard(out, client, config, owner, repository, number, priority, { onlyIfEmpty: true });
114
113
  return failures;
115
114
  }
116
115
  catch (error) {
@@ -1,5 +1,5 @@
1
1
  import type { HintedText } from './command-hint.js';
2
- import type { RepositoryReference, ResolvedRepository } from './repository-resolver.js';
2
+ import type { RepositoryReference, ResolvedRepository, UnreadableRemote } from './repository-resolver.js';
3
3
  export type PolicyMode = 'reject' | 'warn';
4
4
  /**
5
5
  今の git remote からリポジトリを決められないときの 1 行目。branch delete の remote の確認も同じ行を出す
@@ -11,9 +11,9 @@ export interface PolicyInput {
11
11
  */
12
12
  readonly explicit: string | undefined;
13
13
  /**
14
- カレント Git remote からの解決結果。解決できなければ undefined
14
+ カレント Git remote からの解決結果。git の外・remote 無しは undefined
15
15
  */
16
- readonly resolved: ResolvedRepository | undefined;
16
+ readonly resolved: ResolvedRepository | UnreadableRemote | undefined;
17
17
  readonly mode: PolicyMode;
18
18
  }
19
19
  /**
@@ -8,9 +8,11 @@
8
8
  // 1. --repo を指定しない場合
9
9
  // - カレント Git remote を解決できたら続行する(採用値なし)。
10
10
  // - 解決できなければ「リポジトリが曖昧です」で終了コード 1。
11
+ // remote の URL から owner/repo を読めないときは、その理由の行を添える。
11
12
  // 2. --repo を指定した場合
12
13
  // - 形式が不正なら終了コード 1。
13
14
  // - カレント Git remote が無い場合(Git 外・remote 無し)は、比較できないので明示値を採用して続行する。
15
+ // - remote の URL から owner/repo を読めない場合も比較できない。reject・warn とも警告を出して明示値を採用して続行する。
14
16
  // - 一致なら明示値を採用して続行する。
15
17
  // - 不一致で reject は終了コード 1、warn は警告を出して明示値を採用して続行する。
16
18
  //
@@ -18,7 +20,7 @@
18
20
  import { globalRepositoryHint, hinted, placeholder } from './command-hint.js';
19
21
  import { InvalidValueError } from './errors.js';
20
22
  import { pythonStringRepr } from './python-format.js';
21
- import { parseOwnerRepository, repositoryFullName } from './repository-resolver.js';
23
+ import { parseOwnerRepository, repositoryFullName, unreadableRemoteReason } from './repository-resolver.js';
22
24
  /**
23
25
  今の git remote からリポジトリを決められないときの 1 行目。branch delete の remote の確認も同じ行を出す
24
26
  */
@@ -42,13 +44,24 @@ function parseExplicit(explicit) {
42
44
  export function applyRepositoryPolicy(input) {
43
45
  const { explicit, resolved, mode } = input;
44
46
  if (explicit === undefined) {
45
- return resolved === undefined
46
- ? exitWith('git-unresolved', AMBIGUOUS_REPOSITORY_LINE, hinted ` give ${globalRepositoryHint(placeholder('owner/repo'))}`)
47
- : { kind: 'proceed', adopted: undefined, stderr: [] };
47
+ const giveRepository = hinted ` give ${globalRepositoryHint(placeholder('owner/repo'))}`;
48
+ if (resolved === undefined)
49
+ return exitWith('git-unresolved', AMBIGUOUS_REPOSITORY_LINE, giveRepository);
50
+ if (resolved.source === 'unreadable-remote') {
51
+ return exitWith('git-unresolved', AMBIGUOUS_REPOSITORY_LINE, ` ${unreadableRemoteReason(resolved)}`, giveRepository);
52
+ }
53
+ return { kind: 'proceed', adopted: undefined, stderr: [] };
48
54
  }
49
55
  const explicitReference = parseExplicit(explicit);
50
56
  if (explicitReference === undefined)
51
57
  return exitWith('invalid-input', hinted `error: ${globalRepositoryHint()} has an invalid form: ${pythonStringRepr(explicit)}`);
58
+ if (resolved?.source === 'unreadable-remote') {
59
+ return {
60
+ kind: 'proceed',
61
+ adopted: explicitReference,
62
+ stderr: [hinted `warning: using ${globalRepositoryHint()} ${repositoryFullName(explicitReference)} (${unreadableRemoteReason(resolved)})`],
63
+ };
64
+ }
52
65
  // Git 外 / remote 不在は比較対象が無いので、明示値を採用する
53
66
  if (resolved?.source !== 'current-git')
54
67
  return { kind: 'proceed', adopted: explicitReference, stderr: [] };
@@ -1,3 +1,4 @@
1
+ import type { HintedText } from './command-hint.js';
1
2
  import { PecotError } from './errors.js';
2
3
  import type { GitRunner } from './git-runner.js';
3
4
  export interface RepositoryReference {
@@ -42,16 +43,38 @@ remote 名の一覧から主の remote を選ぶ(origin、無ければ最初
42
43
  */
43
44
  export declare function pickPrimaryRemote(remotes: readonly string[]): string | undefined;
44
45
  /**
45
- 現在の git の remote からリポジトリを取り出す。git の外・remote 無しは undefined。
46
- URL の形式が不正なときは、InvalidValueError をそのまま伝える(バグ扱い)。
47
- Python の `_detect_current_git_repo` と同じで、不正なら undefined を返す infra/git.ts の remoteRepository とは契約が違う
46
+ 主の remote はあるが、その URL から `owner/repo` を読めないこと
48
47
  */
49
- export declare function detectCurrentGitRepository(git: GitRunner): {
50
- readonly repository: RepositoryReference;
48
+ export interface UnreadableRemote {
49
+ readonly source: 'unreadable-remote';
51
50
  readonly remoteName: string;
52
- } | undefined;
51
+ }
52
+ /**
53
+ remote の URL から owner/repo を読めない理由の文
54
+ */
55
+ export declare function unreadableRemoteReason(remote: UnreadableRemote): string;
56
+ /**
57
+ remote の URL から owner/repo を読めず、リポジトリを決められないこと。message は理由の文
58
+ */
59
+ export declare class UnreadableRemoteError extends PecotError {
60
+ }
61
+ /**
62
+ git の remote を読む。git の外・remote 無しは undefined、URL から `owner/repo` を読めなければ UnreadableRemote
63
+ */
64
+ export declare function readCurrentGitRemote(git: GitRunner): ResolvedRepository | UnreadableRemote | undefined;
65
+ /**
66
+ 短い参照を補うリポジトリ(決められなければ base は undefined)と、remote の URL を読めなかったこと。明示値の形が不正なら InvalidValueError
67
+ */
68
+ export declare function resolveShortReferenceBase(explicit: string | undefined, git: GitRunner): {
69
+ readonly base: RepositoryReference | undefined;
70
+ readonly unreadable: UnreadableRemote | undefined;
71
+ };
72
+ /**
73
+ 短い参照の案内に、remote の URL を読めなかった理由の行を足す
74
+ */
75
+ export declare function withUnreadableReason(text: string | HintedText, unreadable: UnreadableRemote | undefined): string | HintedText;
53
76
  /**
54
- リポジトリを解決する。明示値があれば git を呼ばずにそれを使う
77
+ リポジトリを解決する。明示値があれば git を呼ばずにそれを使う。remote の URL を読めなければ UnreadableRemoteError
55
78
  */
56
79
  export declare function resolveRepository(explicit: string | undefined, git: GitRunner): ResolvedRepository;
57
80
  //# sourceMappingURL=repository-resolver.d.ts.map
@@ -1,16 +1,8 @@
1
- // マルチリポ対応のリポジトリ解決。
2
- //
3
- // 決定木:
4
- // 1. 明示値(--repo)があれば、それを owner/repo として使う(source=explicit)。
5
- // 2. git のワークツリー内なら、origin の URL から取る(source=current-git)。
6
- // origin が無ければ、先頭の remote を使う。
7
- // 3. どちらも成り立たなければ、AmbiguousRepositoryError を投げる。
8
- //
9
- // 検証エラーの文は、Python の CLI の書式に揃える。
10
- // 表題は元のクラス名(RepoRef・ResolvedRepo)を使う。
1
+ // リポジトリ解決: --repo、無ければ git の origin(無ければ先頭の remote)、どちらも無ければ AmbiguousRepositoryError。
2
+ // 検証エラーの文は Python の CLI の書式(表題は RepoRef・ResolvedRepo)に揃える。
11
3
  import { formatHinted, globalRepositoryHint, hinted, placeholder } from './command-hint.js';
12
4
  import { PecotError, InvalidValueError } from './errors.js';
13
- import { parseRemoteUrl } from './git-url.js';
5
+ import { parseRemoteUrl, RemoteUrlFormatError } from './git-url.js';
14
6
  import { pythonStringRepr, ValidationFailure } from './python-format.js';
15
7
  const SEGMENT_PATTERN = /^[\w.-]+$/u;
16
8
  export class AmbiguousRepositoryError extends PecotError {
@@ -82,12 +74,8 @@ remote 名の一覧から主の remote を選ぶ(origin、無ければ最初
82
74
  export function pickPrimaryRemote(remotes) {
83
75
  return remotes.includes('origin') ? 'origin' : remotes[0];
84
76
  }
85
- /**
86
- 現在の git の remote からリポジトリを取り出す。git の外・remote 無しは undefined。
87
- URL の形式が不正なときは、InvalidValueError をそのまま伝える(バグ扱い)。
88
- Python の `_detect_current_git_repo` と同じで、不正なら undefined を返す infra/git.ts の remoteRepository とは契約が違う
89
- */
90
- export function detectCurrentGitRepository(git) {
77
+ // 主の remote の名前と URL。git の外・remote 無し・URL を取れないときは undefined
78
+ function readPrimaryRemoteUrl(git) {
91
79
  const inside = git(['rev-parse', '--is-inside-work-tree']);
92
80
  if (inside.exitCode !== 0 || inside.stdout.trim() !== 'true')
93
81
  return undefined;
@@ -99,22 +87,73 @@ export function detectCurrentGitRepository(git) {
99
87
  if (remoteName === undefined)
100
88
  return undefined;
101
89
  const url = git(['remote', 'get-url', remoteName]);
102
- if (url.exitCode !== 0)
90
+ return url.exitCode === 0 ? { remoteName, url: url.stdout.trim() } : undefined;
91
+ }
92
+ /**
93
+ remote の URL から owner/repo を読めない理由の文
94
+ */
95
+ export function unreadableRemoteReason(remote) {
96
+ return `could not read the repository from the URL of the Git remote ${remote.remoteName}`;
97
+ }
98
+ /**
99
+ remote の URL から owner/repo を読めず、リポジトリを決められないこと。message は理由の文
100
+ */
101
+ export class UnreadableRemoteError extends PecotError {
102
+ }
103
+ /**
104
+ git の remote を読む。git の外・remote 無しは undefined、URL から `owner/repo` を読めなければ UnreadableRemote
105
+ */
106
+ export function readCurrentGitRemote(git) {
107
+ const primary = readPrimaryRemoteUrl(git);
108
+ if (primary === undefined)
103
109
  return undefined;
104
- const { owner, repository } = parseRemoteUrl(url.stdout.trim());
105
- return { repository: createRepositoryReference(owner, repository), remoteName };
110
+ let location;
111
+ try {
112
+ location = parseRemoteUrl(primary.url);
113
+ }
114
+ catch (error) {
115
+ if (error instanceof RemoteUrlFormatError)
116
+ return { source: 'unreadable-remote', remoteName: primary.remoteName };
117
+ throw error;
118
+ }
119
+ return createResolvedRepository({
120
+ repository: createRepositoryReference(location.owner, location.repository),
121
+ source: 'current-git',
122
+ remoteName: primary.remoteName,
123
+ });
124
+ }
125
+ /**
126
+ 短い参照を補うリポジトリ(決められなければ base は undefined)と、remote の URL を読めなかったこと。明示値の形が不正なら InvalidValueError
127
+ */
128
+ export function resolveShortReferenceBase(explicit, git) {
129
+ if (explicit !== undefined)
130
+ return { base: parseOwnerRepository(explicit), unreadable: undefined };
131
+ const current = readCurrentGitRemote(git);
132
+ return current?.source === 'unreadable-remote'
133
+ ? { base: undefined, unreadable: current }
134
+ : { base: current?.repository, unreadable: undefined };
106
135
  }
107
136
  /**
108
- リポジトリを解決する。明示値があれば git を呼ばずにそれを使う
137
+ 短い参照の案内に、remote の URL を読めなかった理由の行を足す
138
+ */
139
+ export function withUnreadableReason(text, unreadable) {
140
+ if (unreadable === undefined)
141
+ return text;
142
+ const reason = `\n${unreadableRemoteReason(unreadable)}`;
143
+ return typeof text === 'string' ? text + reason : [...text, reason];
144
+ }
145
+ /**
146
+ リポジトリを解決する。明示値があれば git を呼ばずにそれを使う。remote の URL を読めなければ UnreadableRemoteError
109
147
  */
110
148
  export function resolveRepository(explicit, git) {
111
149
  if (explicit !== undefined) {
112
150
  return createResolvedRepository({ repository: parseOwnerRepository(explicit), source: 'explicit', remoteName: undefined });
113
151
  }
114
- const detected = detectCurrentGitRepository(git);
115
- if (detected !== undefined) {
116
- return createResolvedRepository({ repository: detected.repository, source: 'current-git', remoteName: detected.remoteName });
117
- }
152
+ const current = readCurrentGitRemote(git);
153
+ if (current?.source === 'unreadable-remote')
154
+ throw new UnreadableRemoteError(unreadableRemoteReason(current));
155
+ if (current !== undefined)
156
+ return current;
118
157
  // 文を出すのは CLI の最上位(src/cli.ts)だけ。ほかの呼び手は捕まえて undefined にする
119
158
  const repositoryHint = globalRepositoryHint(placeholder('owner/repo'));
120
159
  throw new AmbiguousRepositoryError(formatHinted(hinted `repository is ambiguous: pass ${repositoryHint}`, 'cli'));
@@ -8,7 +8,7 @@ import type { SetupResult } from './worktree-setup.js';
8
8
  /**
9
9
  WorktreeRuntimeError の原因の名前。commands の FailureKind の一部
10
10
  */
11
- export type WorktreeFailure = 'config-invalid' | 'no-active-project' | 'not-initialized' | 'other' | 'repo-not-in-project' | 'repo-setting-missing';
11
+ export type WorktreeFailure = 'config-invalid' | 'git-unresolved' | 'no-active-project' | 'not-initialized' | 'other' | 'repo-not-in-project' | 'repo-setting-missing';
12
12
  /**
13
13
  ワークツリー操作に失敗した(Python の RuntimeError に当たる)。メッセージは利用者に見せる文
14
14
  */
@@ -338,7 +338,7 @@ function loadCopyExcludeSpecOrRaise(mainWorktree, diagnostics) {
338
338
  function requireRegisteredRepository(cwd) {
339
339
  const candidates = readRemoteCandidates(cwd);
340
340
  if (candidates.length === 0)
341
- throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE);
341
+ throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE, { failure: 'git-unresolved' });
342
342
  const config = loadActiveConfig();
343
343
  if (config === undefined) {
344
344
  throw new WorktreeRuntimeError(hinted `project config not found\n hint: run ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })} to set the project`, { failure: 'no-active-project' });
@@ -350,7 +350,7 @@ function requireRegisteredRepository(cwd) {
350
350
  }
351
351
  const repository = candidates[0]?.repository;
352
352
  if (repository === undefined)
353
- throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE);
353
+ throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE, { failure: 'git-unresolved' });
354
354
  const registered = config.repositories.length > 0
355
355
  ? config.repositories.map(item => ` - ${item.owner}/${item.name}`).join('\n')
356
356
  : ' (none registered)';
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "7.0.1-dev.26",
3
+ "version": "7.0.1-dev.28",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@pecot/workflow-mcp",
9
- "version": "7.0.1-dev.26",
9
+ "version": "7.0.1-dev.28",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/server": "^2.4.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "7.0.1-dev.26",
3
+ "version": "7.0.1-dev.28",
4
4
  "type": "module",
5
5
  "description": "pecot-workflow MCP server (standalone distribution)",
6
6
  "license": "MIT",