@pecot/workflow-mcp 7.0.0 → 7.0.1-dev.19

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 (41) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +1 -1
  3. package/cli/dist/commands/branch.js +1 -18
  4. package/cli/dist/commands/issue-board.d.ts +1 -1
  5. package/cli/dist/commands/issue-board.js +1 -1
  6. package/cli/dist/commands/issue-create.js +7 -11
  7. package/cli/dist/commands/issue-dependency.js +21 -12
  8. package/cli/dist/commands/issue-shared.d.ts +8 -2
  9. package/cli/dist/commands/issue-shared.js +22 -4
  10. package/cli/dist/commands/names.d.ts +1 -1
  11. package/cli/dist/commands/names.js +2 -3
  12. package/cli/dist/commands/pr-merge.js +9 -14
  13. package/cli/dist/commands/pr-restack.js +16 -18
  14. package/cli/dist/commands/pr.js +54 -44
  15. package/cli/dist/commands/project.js +2 -2
  16. package/cli/dist/commands/renamed-commands.js +0 -1
  17. package/cli/dist/commands/restack-reading.d.ts +45 -0
  18. package/cli/dist/commands/restack-reading.js +29 -0
  19. package/cli/dist/commands/session-finish.js +6 -18
  20. package/cli/dist/commands/session-start.js +10 -55
  21. package/cli/dist/commands/session.js +51 -168
  22. package/cli/dist/commands/work-target.d.ts +5 -8
  23. package/cli/dist/commands/work-target.js +17 -19
  24. package/cli/dist/domain/branch-name.d.ts +7 -0
  25. package/cli/dist/domain/branch-name.js +23 -1
  26. package/cli/dist/domain/command-hint.d.ts +1 -1
  27. package/cli/dist/domain/pull-request.d.ts +19 -2
  28. package/cli/dist/domain/pull-request.js +25 -9
  29. package/cli/dist/domain/restack.d.ts +4 -0
  30. package/cli/dist/domain/restack.js +4 -0
  31. package/cli/dist/domain/state.d.ts +2 -12
  32. package/cli/dist/domain/state.js +3 -14
  33. package/cli/dist/infra/git.d.ts +5 -0
  34. package/cli/dist/infra/git.js +7 -0
  35. package/cli/dist/infra/paths.d.ts +1 -3
  36. package/cli/dist/infra/paths.js +2 -45
  37. package/cli/dist/infra/state-store.d.ts +3 -8
  38. package/cli/dist/infra/state-store.js +6 -24
  39. package/cli/templates/workflow/pecot-board-sync.yml +3 -2
  40. package/npm-shrinkwrap.json +2 -2
  41. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pecot-w",
3
- "version": "7.0.0",
3
+ "version": "7.0.1-dev.19",
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/README.md CHANGED
@@ -69,6 +69,7 @@ WSL 内の npx が非ログインシェルの PATH に無い場合は、`args`
69
69
  ```
70
70
 
71
71
  版を固定するときは、`@pecot/workflow-mcp@1.2.3` のように版を付けます。
72
+ `@pecot/workflow-mcp@next` は、次の正式版より前の開発版を取ります。
72
73
  依存は `npm-shrinkwrap.json` で固定されているため、同じ版なら同じ依存が入ります。
73
74
 
74
75
  ツールが対象にするリポジトリは、サーバを起動したディレクトリを含むリポジトリです。
@@ -104,7 +105,6 @@ Claude Code では、Claude Code がサーバを起動するディレクトリ
104
105
  | `issue_reopen` | 閉じた Issue を開き直す(ボードのステータスも戻す) |
105
106
  | `session_start` | Issue の作業を始める(ブランチを作り、ボードを Active にし、作業対象を記録する) |
106
107
  | `session_show` | セッションのフラグ、ブランチ、推定した Issue を表示する |
107
- | `session_restore` | 失われたセッションのフラグをブランチから復元する |
108
108
  | `session_finish` | 作業を終える(マージ後の後処理として、Issue のクローズ、ブランチ削除、ローカルの整理をする) |
109
109
  | `pr_create` | PR を作る |
110
110
  | `pr_show` | PR の詳細を必要な項目だけ取得する |
@@ -1,10 +1,9 @@
1
1
  // branch delete。Python の cli/commands/repo.py の delete_branch の移植。
2
2
  import { z } from 'zod';
3
- import { describeApiError } from '../domain/api-error-detail.js';
4
3
  import { findRepository } from '../domain/config.js';
5
4
  import { compareStrings } from '../domain/python-format.js';
6
5
  import { ReferenceParseError, parseRepositoryReference } from '../domain/reference-parser.js';
7
- import { GitHubAPIError, isMissingReferenceError } from '../infra/github/errors.js';
6
+ import { GitHubAPIError } from '../infra/github/errors.js';
8
7
  import { defineCommand } from './command-definition.js';
9
8
  import { requireActiveConfig, stopWith } from './command-stop.js';
10
9
  import { kindOfFailure } from './failure.js';
@@ -16,7 +15,6 @@ const BRANCH_DELETE_OUTPUT = z.strictObject({
16
15
  branch: z.string().describe('Name of the remote branch'),
17
16
  repository: z.string().describe('Repository of the branch (owner/repo)'),
18
17
  deleted: z.boolean().describe('Whether the remote branch was deleted (false on dry_run)'),
19
- wipBranch: z.string().optional().describe('Name of the wip branch that was deleted along with it (omitted when there was none or it could not be deleted)'),
20
18
  dryRun: DRY_RUN_FIELD,
21
19
  });
22
20
  const branchDeleteCommand = defineCommand({
@@ -89,21 +87,6 @@ const branchDeleteCommand = defineCommand({
89
87
  }
90
88
  out.done(operation);
91
89
  out.result({ branch: input.branch, repository: `${owner}/${repository}`, deleted: true });
92
- // wip ブランチも連動削除
93
- const wipBranch = `wip/${input.branch}`;
94
- try {
95
- await client.deleteBranch(owner, repository, wipBranch);
96
- }
97
- catch (error) {
98
- if (!(error instanceof GitHubAPIError))
99
- throw error;
100
- // wip ブランチの削除の失敗だけは、API の応答の本文の詳細も見せる(Python の describe_api_error と同じ)。存在しない場合は何も出さない
101
- if (!isMissingReferenceError(error))
102
- out.warning(`could not delete remote branch ${wipBranch} in ${owner}/${repository}: ${describeApiError(error)}`);
103
- return 0;
104
- }
105
- out.done({ verb: 'delete', target: `remote branch ${wipBranch} in ${owner}/${repository}` });
106
- out.result({ wipBranch });
107
90
  return 0;
108
91
  },
109
92
  });
@@ -57,7 +57,7 @@ export interface BoardMoveLine {
57
57
  readonly reason: string;
58
58
  }
59
59
  /**
60
- 列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync と pr create の data が使う
60
+ 列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync・pr create・issue block / unblock の data が使う
61
61
  */
62
62
  export declare const BOARD_MOVE_JSON: z.ZodObject<{
63
63
  issue: z.ZodString;
@@ -72,7 +72,7 @@ export async function putOnBoard(client, config, owner, repository, issueNumber,
72
72
  }
73
73
  }
74
74
  /**
75
- 列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync と pr create の data が使う
75
+ 列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync・pr create・issue block / unblock の data が使う
76
76
  */
77
77
  export const BOARD_MOVE_JSON = z.strictObject({
78
78
  issue: z.string().describe('Issue as shown in the moved line (#N, or owner/repo#N outside the home repository)'),
@@ -12,7 +12,7 @@ import { splitOwnerRepository, createRepositoryReference } from '../domain/repos
12
12
  import { FrontmatterError, stripFrontmatter, stripLeadingHtmlComment } from '../domain/frontmatter.js';
13
13
  import { findBatchDuplicate, planOrders } from '../domain/issue-order.js';
14
14
  import { upsertWaitsForMerge } from '../domain/prerequisites.js';
15
- import { FLAG_ISSUE_CREATE_SLASH_PENDING, FLAG_ISSUE_PENDING, FLAG_PECOT_QUICK_MODE } from '../domain/state.js';
15
+ import { FLAG_PECOT_QUICK_MODE } from '../domain/state.js';
16
16
  import { compareStrings, pythonRightStrip, pythonStrip, pythonStringRepr, truncateCodePoints } from '../domain/python-format.js';
17
17
  import { createIssueReference, issueReferenceKey, issueReferenceToCliReference } from '../domain/reference-parser.js';
18
18
  import { describeReadiness, displayReference, hasStarted, stackChains } from '../domain/readiness.js';
@@ -20,7 +20,7 @@ import { parseIssueFile } from '../infra/frontmatter-file.js';
20
20
  import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
21
21
  import { DEPENDENCIES_UNSUPPORTED } from '../infra/github/issues.js';
22
22
  import { OutputPathReservationError, normalizePath, outputDirectory, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
23
- import { consumeFlag, touchFlag } from '../infra/state-store.js';
23
+ import { touchFlag } from '../infra/state-store.js';
24
24
  import { templateFile } from '../infra/template-store.js';
25
25
  import { readTextFile } from '../infra/text-file.js';
26
26
  import { CommandExit, defineCommand } from './command-definition.js';
@@ -90,7 +90,7 @@ function validateRepositoryShape(output, repository) {
90
90
  return isValid ? [parts.owner, parts.repository] : stopWith(output, message, 'invalid-input', USAGE_EXIT_CODE);
91
91
  }
92
92
  function newSession() {
93
- return { failures: [], cache: createReadinessCache(), issues: [] };
93
+ return { failures: [], cache: createReadinessCache(), issues: [], fieldHint: { hasHinted: false } };
94
94
  }
95
95
  // 投稿中の Issue は常に末尾にある。isUpdate なら末尾を書き換え、そうでなければ足す
96
96
  function recordIssue(output, session, entry, isUpdate) {
@@ -183,9 +183,6 @@ async function postIssue(output, client, config, session, posting) {
183
183
  recordIssue(output, session, entry, false);
184
184
  const target = `Issue ${issuePath(owner, repository, number)}`;
185
185
  const reference = createIssueReference(createRepositoryReference(owner, repository), number);
186
- consumeFlag(FLAG_ISSUE_PENDING);
187
- if (posting.consumeSlashPending === true)
188
- consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
189
186
  // 応答に node_id が無いときだけ、ボードへの追加の結果から取るので、先にボードへ足す
190
187
  let added;
191
188
  let hasTriedBoard = false;
@@ -201,7 +198,7 @@ async function postIssue(output, client, config, session, posting) {
201
198
  let isMovedToReady = false;
202
199
  let status;
203
200
  if (added !== undefined) {
204
- const written = await setIssueFields(output, client, config, added.itemId, target, posting.fields);
201
+ const written = await setIssueFields(output, client, config, added.itemId, target, posting.fields, session.fieldHint);
205
202
  const option = written.includes('workflow') ? posting.fields.find(field => field.fieldName === 'workflow')?.optionName : undefined;
206
203
  if (option !== undefined && isCreatedStatus(option))
207
204
  status = option;
@@ -647,7 +644,6 @@ async function postFiles(output, context) {
647
644
  if (session.failures.length > 0)
648
645
  output.error(joinHinted(['could not add some blocked-by; add them again with:', ...session.failures.map(hint => [hint])]));
649
646
  }
650
- consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
651
647
  if (session.failures.length > 0)
652
648
  throw new CommandExit(1, 'partial-failure');
653
649
  output.result(chainsData(progressions, labels));
@@ -662,6 +658,9 @@ function isBatchReference(reference, posted) {
662
658
  async function createFromFiles(output, files, isDryRun) {
663
659
  const context = await prepareBatch(output, files);
664
660
  if (isDryRun) {
661
+ // 番号は投稿まで決まらないので、本番の created の行から番号を除いた対象にする
662
+ for (const local of context.locals)
663
+ output.planned({ verb: 'create', target: `Issue in ${local.owner}/${local.repository} from ${local.name}` });
665
664
  printPlan(output, context);
666
665
  return;
667
666
  }
@@ -787,7 +786,6 @@ async function createFreeform(output, input, isDryRun) {
787
786
  parentReference,
788
787
  prerequisites: [],
789
788
  settleColumn: false,
790
- consumeSlashPending: true,
791
789
  });
792
790
  if (posted.isOnBoard && !BACKLOG_TYPES.has(issueType))
793
791
  touchFlag(FLAG_PECOT_QUICK_MODE);
@@ -810,8 +808,6 @@ async function createFromMessage(output, input, message, isDryRun) {
810
808
  labels: input.label,
811
809
  order: input.order,
812
810
  }, target.config, isDryRun);
813
- if (!isDryRun)
814
- consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
815
811
  }
816
812
  const ISSUE_CREATE = defineCommand({
817
813
  path: ['issue', 'create'],
@@ -13,7 +13,7 @@ import { commandHint, hinted, inputHint, inputNameHint, joinHinted } from './com
13
13
  import { requireActiveConfigPlain, stopWith } from './command-stop.js';
14
14
  import { kindOfFailure } from './failure.js';
15
15
  import { apiFailureMessage, createGitHubClient } from './github-client.js';
16
- import { applyBoardMove } from './issue-board.js';
16
+ import { applyBoardMove, BOARD_MOVE_JSON, moveJson } from './issue-board.js';
17
17
  import { createReadinessCache, readIssueReadiness } from './issue-readiness.js';
18
18
  import { ensureRepositoryInProject, ISSUE_REF_DESCRIPTION, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
19
19
  import { createOutput, DRY_RUN_FIELD } from './output.js';
@@ -24,17 +24,20 @@ const MAX_CYCLE_ISSUES = 200;
24
24
  const BLOCK_PATH = ['issue', 'block'];
25
25
  const ISSUE_FIELD = z.string().describe('The waiting Issue (owner/repo/N)');
26
26
  const BY_FIELD = z.string().describe('The prerequisite Issue (owner/repo/N)');
27
+ const MOVES_FIELD = z.array(BOARD_MOVE_JSON).optional().describe('The waiting Issue when its column or Status was written (at most one; empty when nothing was written; omitted on dry_run)');
27
28
  const ISSUE_BLOCK_OUTPUT = z.strictObject({
28
29
  issue: ISSUE_FIELD,
29
30
  by: BY_FIELD,
30
31
  wait: z.enum(['stack', 'merge']).describe('Wait kind of the blocked-by after the command'),
31
32
  change: z.enum(['added', 'updated', 'unchanged']).describe('added (new blocked-by), updated (wait kind or reason changed), or unchanged'),
33
+ moves: MOVES_FIELD,
32
34
  dryRun: DRY_RUN_FIELD,
33
35
  });
34
36
  const ISSUE_UNBLOCK_OUTPUT = z.strictObject({
35
37
  issue: ISSUE_FIELD,
36
38
  by: BY_FIELD,
37
39
  change: z.enum(['removed', 'unchanged']).describe('removed, or unchanged when it was not a blocked-by'),
40
+ moves: MOVES_FIELD,
38
41
  dryRun: DRY_RUN_FIELD,
39
42
  });
40
43
  function toReference(target) {
@@ -88,21 +91,21 @@ async function readConfirmed(context, expected) {
88
91
  }
89
92
  return { failure: `could not confirm that GitHub reflects the blocked-by change of ${name}` };
90
93
  }
91
- // 書いた後の判定で、列と札を動かす。読めない・確かめられないときは動かさず warning にする(前提の変更は済んでいる)
94
+ // 書いた後の判定で、列と札を動かし、書けた列と札を返す。読めない・確かめられないときは動かさず warning にする(前提の変更は済んでいる)
92
95
  async function moveBoard(context, expected, hasPrerequisites) {
93
96
  const { out, client, config, home, target } = context;
94
97
  const name = displayReference(target, home);
95
98
  const read = await readConfirmed(context, expected);
96
99
  if ('failure' in read) {
97
100
  out.warning(`${read.failure}; the column and label of ${name} were not moved`);
98
- return;
101
+ return undefined;
99
102
  }
100
103
  const { judged } = read;
101
104
  if (judged.readiness === undefined)
102
- return;
105
+ return undefined;
103
106
  const move = decideBoardMove(boardMoveInput(judged, config, hasPrerequisites));
104
107
  if (move === undefined)
105
- return;
108
+ return undefined;
106
109
  const hasWrite = move.column !== undefined || move.label !== undefined;
107
110
  let itemId = '';
108
111
  try {
@@ -111,14 +114,18 @@ async function moveBoard(context, expected, hasPrerequisites) {
111
114
  }
112
115
  catch (error) {
113
116
  out.warning(`could not move ${name}: ${apiFailureMessage(error)}`);
114
- return;
117
+ return undefined;
115
118
  }
116
119
  if (hasWrite && itemId === '')
117
- return;
118
- const { missing } = await applyBoardMove(out, client, config, itemId, { ref: target, home }, move, describeReadiness(judged.readiness, judged.prerequisites, home));
120
+ return undefined;
121
+ const { missing, written } = await applyBoardMove(out, client, config, itemId, { ref: target, home }, move, describeReadiness(judged.readiness, judged.prerequisites, home));
119
122
  for (const value of missing) {
120
123
  out.warning(joinHinted([`the ${value} option is not on the board, so ${name} was not moved`, hintFor(value)]));
121
124
  }
125
+ return written;
126
+ }
127
+ function movesOf(written) {
128
+ return written === undefined ? [] : [moveJson(written)];
122
129
  }
123
130
  function keysOf(issues) {
124
131
  return new Set(issues.map(issue => issueReferenceKey({ repository: issue.repository, number: issue.number })));
@@ -179,7 +186,7 @@ async function runBlock(out, input) {
179
186
  stopWith(out, `Waits for merge of ${name} is malformed: ${decision.reason}; fix the section in the Issue body and run the command again`, 'content-invalid', CONTENT_EXIT_CODE);
180
187
  }
181
188
  else if (decision.kind === 'unchanged') {
182
- out.result({ ...result, change: 'unchanged' });
189
+ out.result({ ...result, change: 'unchanged', ...!input.dry_run && { moves: [] } });
183
190
  out.planned({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
184
191
  out.done({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
185
192
  return;
@@ -215,7 +222,8 @@ async function runBlock(out, input) {
215
222
  out.done(operation);
216
223
  out.result({ ...result, change });
217
224
  const keys = new Set([...keysOf(issues), issueReferenceKey(by)]);
218
- await moveBoard(context, { keys, by, wait: { wait: input.wait, reason } }, true);
225
+ const written = await moveBoard(context, { keys, by, wait: { wait: input.wait, reason } }, true);
226
+ out.result({ moves: movesOf(written) });
219
227
  }
220
228
  async function runUnblock(out, input) {
221
229
  const config = requireActiveConfigPlain(out);
@@ -239,7 +247,7 @@ async function runUnblock(out, input) {
239
247
  const decision = decideUnblock({ body: read.body, home, by, isLinked: linked !== undefined });
240
248
  const result = { issue: issueReferenceToCliReference(target), by: issueReferenceToCliReference(by) };
241
249
  if (linked === undefined || decision.kind === 'unchanged') {
242
- out.result({ ...result, change: 'unchanged' });
250
+ out.result({ ...result, change: 'unchanged', ...!input.dry_run && { moves: [] } });
243
251
  out.planned({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
244
252
  out.done({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
245
253
  return;
@@ -266,7 +274,8 @@ async function runUnblock(out, input) {
266
274
  const remaining = issues.filter(issue => issue.id !== linked.id);
267
275
  // 人が別の理由で付けた札を、最後の前提を外しただけで戻さない
268
276
  const hasPrerequisites = remaining.length > 0 || linked.state === 'CLOSED';
269
- await moveBoard(context, { keys: keysOf(remaining), by, wait: undefined }, hasPrerequisites);
277
+ const written = await moveBoard(context, { keys: keysOf(remaining), by, wait: undefined }, hasPrerequisites);
278
+ out.result({ moves: movesOf(written) });
270
279
  }
271
280
  const ISSUE_BLOCK = defineCommand({
272
281
  path: BLOCK_PATH,
@@ -135,9 +135,15 @@ export interface IssueField {
135
135
  readonly label: string;
136
136
  }
137
137
  /**
138
- カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。失敗したフィールドは、何も出さずに飛ばす。設定できたフィールドの名前を返す
138
+ 選択肢の ID を読み直す案内を 1 回の実行で 1 回だけ出すための印
139
139
  */
140
- export declare function setIssueFields(output: Output, client: GitHubClient, config: ProjectConfig, itemId: string, target: string, fields: readonly IssueField[]): Promise<readonly string[]>;
140
+ export interface FieldHintState {
141
+ hasHinted: boolean;
142
+ }
143
+ /**
144
+ カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。書き込みに失敗したフィールドは warning にして飛ばす。設定できたフィールドの名前を返す
145
+ */
146
+ export declare function setIssueFields(output: Output, client: GitHubClient, config: ProjectConfig, itemId: string, target: string, fields: readonly IssueField[], hintState: FieldHintState): Promise<readonly string[]>;
141
147
  /**
142
148
  親 Epic のサブ Issue にする。失敗は Issue の URL(issueUrl が undefined なら出し済みとして省く)、error の行の順に出して終了コード 1。issueNodeId は、無ければ取り直す関数。行に出した親の参照(owner/repo/N)を返す
143
149
  */
@@ -15,10 +15,11 @@ import { issueReferenceToCliReference, parseIssueReference, ReferenceParseError
15
15
  import { AmbiguousRepositoryError, createRepositoryReference, resolveRepository } 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 } from '../infra/github/errors.js';
18
+ import { GitHubAPIError, GitHubAuthError, GitHubRateLimitError } 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 { commandHint, hinted, inputHint, inputNameHint } from './command-hint.js';
21
+ import { getActiveConfigPath, projectsDirectory } from '../infra/config-store.js';
22
+ import { commandHint, hinted, inputHint, inputNameHint, joinHinted, placeholder } from './command-hint.js';
22
23
  import { stopWith } from './command-stop.js';
23
24
  import { kindOfFailure } from './failure.js';
24
25
  import { createGitHubClient } from './github-client.js';
@@ -305,10 +306,18 @@ export async function addToBoardOrWarn(output, client, config, owner, repository
305
306
  output.done({ verb: 'add', target: `Issue ${issuePath(owner, repository, issueNumber)} to project` });
306
307
  return added;
307
308
  }
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
+ }
308
317
  /**
309
- カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。失敗したフィールドは、何も出さずに飛ばす。設定できたフィールドの名前を返す
318
+ カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。書き込みに失敗したフィールドは warning にして飛ばす。設定できたフィールドの名前を返す
310
319
  */
311
- export async function setIssueFields(output, client, config, itemId, target, fields) {
320
+ export async function setIssueFields(output, client, config, itemId, target, fields, hintState) {
312
321
  const labels = [];
313
322
  const written = [];
314
323
  for (const { fieldName, optionName, label } of fields) {
@@ -321,6 +330,15 @@ export async function setIssueFields(output, client, config, itemId, target, fie
321
330
  catch (error) {
322
331
  if (!(error instanceof GitHubAPIError))
323
332
  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;
324
342
  }
325
343
  }
326
344
  if (labels.length > 0)
@@ -1,5 +1,5 @@
1
1
  /**
2
- 入力名を長いオプションの形にする。`force_overwrite_active` は `--force-overwrite-active`
2
+ 入力名を長いオプションの形にする。`dry_run` は `--dry-run`
3
3
  */
4
4
  export declare function flagOf(name: string): string;
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  // コマンドの名前まわりの小さな関数。help・バインド・定義書の書き出しが同じものを使う。
2
2
  /**
3
- 入力名を長いオプションの形にする。`force_overwrite_active` は `--force-overwrite-active`
3
+ 入力名を長いオプションの形にする。`dry_run` は `--dry-run`
4
4
  */
5
5
  export function flagOf(name) {
6
6
  return `--${name.replaceAll('_', '-')}`;
@@ -20,7 +20,7 @@ export const COMMAND_GROUPS = [
20
20
  { name: 'project', meaning: 'プロジェクトとの接続と設定ファイル。ボードの上の Issue には触らない', help: 'Connect to projects and manage the project config' },
21
21
  { name: 'board', meaning: 'ボードの上の Issue の置き場所。設定ファイルは書かない', help: 'Show the project board and place Issues on it' },
22
22
  { name: 'issue', meaning: 'Issue そのもの', help: 'Work with Issues' },
23
- { name: 'session', meaning: '1 つの Issue の作業の始まりから終わりまで', help: 'Start, show, restore and finish the work on an Issue' },
23
+ { name: 'session', meaning: '1 つの Issue の作業の始まりから終わりまで', help: 'Start, show and finish the work on an Issue' },
24
24
  { name: 'pr', meaning: 'PR そのもの', help: 'Work with PRs' },
25
25
  { name: 'release', meaning: 'リリース', help: 'Work with releases' },
26
26
  { name: 'tracker', meaning: 'Tracker の Issue の書き直し', help: 'Rewrite the list in a Tracker Issue' },
@@ -46,7 +46,6 @@ export const COMMAND_VERBS = [
46
46
  { name: 'link', meaning: 'リポジトリをプロジェクトにつなぐ' },
47
47
  { name: 'activate', meaning: '使うプロジェクトを切り替える' },
48
48
  { name: 'start', meaning: '作業を始める' },
49
- { name: 'restore', meaning: '作業の状態を戻す' },
50
49
  { name: 'finish', meaning: '作業を終えて片付ける' },
51
50
  { name: 'sync', meaning: '判定や一覧に合わせて書き直す' },
52
51
  { name: 'move', meaning: 'ボードの列を移す' },
@@ -4,9 +4,7 @@ import { setTimeout as delay } from 'node:timers/promises';
4
4
  import { z } from 'zod';
5
5
  import { describeApiError } from '../domain/api-error-detail.js';
6
6
  import { jsonField, tryParseJsonText } from '../domain/json.js';
7
- import { FLAG_MERGE_SLASH_PENDING } from '../domain/state.js';
8
7
  import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
9
- import { consumeFlag } from '../infra/state-store.js';
10
8
  import { requireActiveConfigPlain, stopWith } from './command-stop.js';
11
9
  import { defineCommand } from './command-definition.js';
12
10
  import { kindOfFailure } from './failure.js';
@@ -38,10 +36,7 @@ const PR_MERGE_OUTPUT = z.strictObject({
38
36
  function pathOf(target) {
39
37
  return `${target.owner}/${target.repository}/${String(target.number)}`;
40
38
  }
41
- // マージまで進まずに止まるので、/pecot-w:w-merge が立てた確認の免除を残さない。dry-run は状態を変えない
42
- function stopNotMergeable(out, message, isDryRun) {
43
- if (!isDryRun)
44
- consumeFlag(FLAG_MERGE_SLASH_PENDING);
39
+ function stopNotMergeable(out, message) {
45
40
  return stopWith(out, message, 'pr-state', NOT_MERGEABLE_EXIT_CODE);
46
41
  }
47
42
  // 印は残す。w-merge は必須チェックを待って同じ PR に pr_merge を呼び直す
@@ -60,16 +55,16 @@ async function readPullRequest(out, client, target) {
60
55
  return stopWith(out, `could not read PR ${pathOf(target)}: ${describeApiError(error)}`, kindOfFailure(error));
61
56
  }
62
57
  }
63
- function checkState(out, name, pullRequest, isDryRun) {
58
+ function checkState(out, name, pullRequest) {
64
59
  if (pullRequest.state === 'MERGED')
65
- stopNotMergeable(out, `${name} is already merged`, isDryRun);
60
+ stopNotMergeable(out, `${name} is already merged`);
66
61
  if (pullRequest.state !== 'OPEN')
67
- stopNotMergeable(out, `${name} is closed`, isDryRun);
62
+ stopNotMergeable(out, `${name} is closed`);
68
63
  if (pullRequest.isDraft)
69
- stopNotMergeable(out, `${name} is a draft`, isDryRun);
64
+ stopNotMergeable(out, `${name} is a draft`);
70
65
  }
71
66
  // 下の段に open の PR があれば止める。マージ済みで並びに残る PR は飛ばす。スタックの機能が無いリポは単独の PR として扱う
72
- async function bottomOfStack(out, client, target, isDryRun) {
67
+ async function bottomOfStack(out, client, target) {
73
68
  let stack;
74
69
  try {
75
70
  stack = await client.getStackOfPullRequest(target.owner, target.repository, target.number);
@@ -87,7 +82,7 @@ async function bottomOfStack(out, client, target, isDryRun) {
87
82
  for (const lower of stack.pullRequests.slice(0, index)) {
88
83
  const pullRequest = await readPullRequest(out, client, { ...target, number: lower });
89
84
  if (pullRequest.state === 'OPEN') {
90
- stopNotMergeable(out, `PR #${String(target.number)} is not the bottom of stack #${String(stack.number)}. Merge PR #${String(lower)} first`, isDryRun);
85
+ stopNotMergeable(out, `PR #${String(target.number)} is not the bottom of stack #${String(stack.number)}. Merge PR #${String(lower)} first`);
91
86
  }
92
87
  }
93
88
  return { number: stack.number, size: stack.pullRequests.length - index };
@@ -216,8 +211,8 @@ export const PR_MERGE_COMMAND = defineCommand({
216
211
  const client = createGitHubClient(out, config.host);
217
212
  const name = `PR #${String(target.number)}`;
218
213
  const pullRequest = await readPullRequest(out, client, target);
219
- checkState(out, name, pullRequest, input.dry_run);
220
- const stack = await bottomOfStack(out, client, target, input.dry_run);
214
+ checkState(out, name, pullRequest);
215
+ const stack = await bottomOfStack(out, client, target);
221
216
  out.result({ pullRequest: pathOf(target), base: pullRequest.baseRefName, ...stack !== undefined && { stack } });
222
217
  const suffix = stack === undefined ? '' : ` (stack #${String(stack.number)}, 1 of ${String(stack.size)})`;
223
218
  if (input.dry_run) {
@@ -3,11 +3,9 @@
3
3
  import { z } from 'zod';
4
4
  import { describeApiError } from '../domain/api-error-detail.js';
5
5
  import { getDevelopBranch } from '../domain/config.js';
6
- import { pickLowerPullRequest } from '../domain/pull-request.js';
7
- import { decideRestack, describeGone, describeRestackCheck } from '../domain/restack.js';
6
+ import { describeGone, describeRestackCheck, RESTACK_PATH } from '../domain/restack.js';
8
7
  import { FLAG_PECOT_RESTACK, formatRestackProgress, interpretRestackProgress } from '../domain/state.js';
9
- import { abortRebase, conflictedFiles, continueRebase, fetchRemote, gitStdout, hasSameTree, isRebaseInProgress, mergeBase, pushWithLease, rebaseOnto, remoteBranchHead, remoteOnlyChanges, resetHardTo, resolveCommit, } from '../infra/git.js';
10
- import { GitHubAPIError } from '../infra/github/errors.js';
8
+ import { abortRebase, conflictedFiles, continueRebase, fetchRemote, gitStdout, hasSameTree, isRebaseInProgress, mergeBase, pushWithLease, rebaseOnto, remoteOnlyChanges, resetHardTo, resolveCommit, } from '../infra/git.js';
11
9
  import { readBaseRecord, readFlag, removeFlag, writeBaseRecord, writeFlag } from '../infra/state-store.js';
12
10
  import { defineCommand } from './command-definition.js';
13
11
  import { commandHint, hinted } from './command-hint.js';
@@ -16,8 +14,8 @@ import { kindOfFailure } from './failure.js';
16
14
  import { createGitHubClient } from './github-client.js';
17
15
  import { createOutput, DRY_RUN_FIELD } from './output.js';
18
16
  import { stopOnMalformedRecord, validatePullRequestContext } from './pr.js';
17
+ import { readRestackDecision } from './restack-reading.js';
19
18
  import { USAGE_EXIT_CODE } from './usage-error.js';
20
- const RESTACK_PATH = ['pr', 'restack'];
21
19
  const CONFLICT_EXIT_CODE = 3;
22
20
  const UNCOMMITTED_EXIT_CODE = 2;
23
21
  // 文の中にロングオプションを書けない(lint)ので、git の引数から組む
@@ -128,20 +126,20 @@ function hasUncommittedChanges(cwd) {
128
126
  }
129
127
  // 下の段の PR と、remote の先頭を読んで、載せ直す先を決める
130
128
  async function decideFor(out, cwd, host, target) {
131
- const { remote, owner, repository, developBranch } = target;
132
- const { record } = target.reading;
133
- let lowerPullRequest;
134
- try {
135
- const found = await createGitHubClient(out, host).listPullRequestsByHead(owner, repository, record.branch);
136
- lowerPullRequest = pickLowerPullRequest(found.pullRequests);
137
- }
138
- catch (error) {
139
- if (error instanceof GitHubAPIError)
140
- return stopWith(out, `cannot read the PR of the base branch ${record.branch}: ${describeApiError(error)}`, kindOfFailure(error));
141
- throw error;
129
+ const { remote, owner, repository, developBranch, reading } = target;
130
+ const { branch } = reading.record;
131
+ const read = await readRestackDecision({ client: () => createGitHubClient(out, host), owner, repository, cwd, remote, reading, developBranch });
132
+ switch (read.kind) {
133
+ case 'pull-request-unreadable': {
134
+ return stopWith(out, `cannot read the PR of the base branch ${branch}: ${describeApiError(read.error)}`, kindOfFailure(read.error));
135
+ }
136
+ case 'remote-unreachable': {
137
+ return stopWith(out, `cannot reach ${remote} to read the base branch ${branch}`, 'git-unresolved');
138
+ }
139
+ case 'decided': {
140
+ return read.decision;
141
+ }
142
142
  }
143
- const lowerHead = remoteBranchHead(cwd, remote, record.branch);
144
- return lowerHead.isReachable ? decideRestack({ reading: target.reading, developBranch, lowerPullRequest, lowerHead: lowerHead.sha }) : stopWith(out, `cannot reach ${remote} to read the base branch ${record.branch}`, 'git-unresolved');
145
143
  }
146
144
  // 載せ直す先の ref と SHA。開発ブランチへ載せ直すときは、積んだ先を記録から外す
147
145
  function progressOf(out, cwd, branch, target, decision) {