@pecot/workflow-mcp 6.0.0 → 7.0.0

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 (84) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +4 -57
  3. package/cli/dist/commands/board-add.js +11 -1
  4. package/cli/dist/commands/board-judgment.d.ts +12 -3
  5. package/cli/dist/commands/board-judgment.js +12 -6
  6. package/cli/dist/commands/board-move.js +9 -1
  7. package/cli/dist/commands/board-readiness.d.ts +3 -3
  8. package/cli/dist/commands/board-show.js +5 -2
  9. package/cli/dist/commands/board-sync.js +14 -5
  10. package/cli/dist/commands/board-view.d.ts +94 -5
  11. package/cli/dist/commands/board-view.js +119 -17
  12. package/cli/dist/commands/branch.js +12 -1
  13. package/cli/dist/commands/command-definition.d.ts +19 -2
  14. package/cli/dist/commands/command-definition.js +9 -0
  15. package/cli/dist/commands/failure-kind.d.ts +1 -1
  16. package/cli/dist/commands/failure-kind.js +1 -0
  17. package/cli/dist/commands/issue-board.d.ts +31 -3
  18. package/cli/dist/commands/issue-board.js +28 -4
  19. package/cli/dist/commands/issue-comment.js +19 -2
  20. package/cli/dist/commands/issue-create.js +90 -7
  21. package/cli/dist/commands/issue-dependency.js +32 -4
  22. package/cli/dist/commands/issue-readiness.d.ts +30 -2
  23. package/cli/dist/commands/issue-readiness.js +35 -0
  24. package/cli/dist/commands/issue-reopen.js +18 -3
  25. package/cli/dist/commands/issue-shared.d.ts +3 -3
  26. package/cli/dist/commands/issue-shared.js +3 -2
  27. package/cli/dist/commands/issue-show.js +78 -8
  28. package/cli/dist/commands/names.js +1 -0
  29. package/cli/dist/commands/output.d.ts +18 -2
  30. package/cli/dist/commands/output.js +16 -3
  31. package/cli/dist/commands/pr-merge.d.ts +3 -0
  32. package/cli/dist/commands/pr-merge.js +230 -0
  33. package/cli/dist/commands/pr-reference.d.ts +8 -0
  34. package/cli/dist/commands/pr-reference.js +30 -0
  35. package/cli/dist/commands/pr-restack.d.ts +6 -0
  36. package/cli/dist/commands/pr-restack.js +233 -0
  37. package/cli/dist/commands/pr-waiting.d.ts +41 -2
  38. package/cli/dist/commands/pr-waiting.js +74 -37
  39. package/cli/dist/commands/pr.d.ts +10 -6
  40. package/cli/dist/commands/pr.js +160 -67
  41. package/cli/dist/commands/project-sync.d.ts +10 -2
  42. package/cli/dist/commands/project-sync.js +7 -6
  43. package/cli/dist/commands/project.js +173 -16
  44. package/cli/dist/commands/registry.js +2 -0
  45. package/cli/dist/commands/release.js +67 -18
  46. package/cli/dist/commands/repository-match.js +7 -2
  47. package/cli/dist/commands/session-finish.js +128 -12
  48. package/cli/dist/commands/session-start.js +22 -6
  49. package/cli/dist/commands/session.js +121 -20
  50. package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
  51. package/cli/dist/commands/tracker-sync-security.js +22 -4
  52. package/cli/dist/commands/tracker-sync.d.ts +30 -0
  53. package/cli/dist/commands/tracker-sync.js +15 -0
  54. package/cli/dist/commands/tracker.js +2 -0
  55. package/cli/dist/commands/work-target.d.ts +10 -2
  56. package/cli/dist/commands/work-target.js +6 -4
  57. package/cli/dist/commands/worktree.js +71 -5
  58. package/cli/dist/domain/issue-readout.d.ts +0 -4
  59. package/cli/dist/domain/pull-request.d.ts +1 -1
  60. package/cli/dist/domain/readiness.d.ts +17 -0
  61. package/cli/dist/domain/readiness.js +39 -2
  62. package/cli/dist/domain/restack.d.ts +62 -0
  63. package/cli/dist/domain/restack.js +53 -0
  64. package/cli/dist/domain/state.d.ts +39 -0
  65. package/cli/dist/domain/state.js +28 -1
  66. package/cli/dist/domain/work-start.d.ts +0 -4
  67. package/cli/dist/domain/work-start.js +0 -7
  68. package/cli/dist/infra/git.d.ts +64 -0
  69. package/cli/dist/infra/git.js +110 -0
  70. package/cli/dist/infra/github/pulls.d.ts +81 -2
  71. package/cli/dist/infra/github/pulls.js +116 -5
  72. package/cli/dist/infra/github/queries.d.ts +4 -1
  73. package/cli/dist/infra/github/queries.js +47 -32
  74. package/cli/dist/infra/github/readout.js +0 -33
  75. package/cli/dist/mcp/result.d.ts +63 -16
  76. package/cli/dist/mcp/result.js +106 -30
  77. package/cli/dist/mcp/server.js +37 -4
  78. package/cli/templates/comment/plan.md +2 -2
  79. package/cli/templates/comment/review-findings.md +3 -2
  80. package/cli/templates/issue/bug.md +13 -4
  81. package/cli/templates/issue/task.md +13 -4
  82. package/cli/templates/workflow/pecot-board-sync.yml +1 -1
  83. package/npm-shrinkwrap.json +2 -2
  84. package/package.json +1 -1
@@ -11,7 +11,7 @@ import { hasErrorCode, OsError, toOsError } from '../infra/os-error.js';
11
11
  import { resolveRealPath, WORKTREE_CONFIG_FILENAME, WORKTREE_IGNORE_FILENAME } from '../infra/paths.js';
12
12
  import { createWorktree, detectProjectRoot, ensureDevcontainerEnvironment, findMainWorktree, findWorktreeConfigFile, getWorktreeDirectories, removeWorktree, WorktreeRuntimeError, } from '../infra/worktree.js';
13
13
  import { createSymlinksSafe, DEFAULT_WORKTREEIGNORE_CONTENT, decideOverwrite, getDefaultConfig, loadConfig, planLink, saveConfig, WorktreeConfigError, } from '../infra/worktree-links.js';
14
- import { createOutput, isConfirmed } from './output.js';
14
+ import { createOutput, DRY_RUN_FIELD, isConfirmed } from './output.js';
15
15
  import { defineCommand } from './command-definition.js';
16
16
  import { commandHint, hinted, hintedTextOf, inputHint, placeholder } from './command-hint.js';
17
17
  import { stopWith } from './command-stop.js';
@@ -66,10 +66,19 @@ const worktreeAddInput = z.object({
66
66
  dry_run: dryRunInput,
67
67
  allow_existing_branch: z.boolean().default(false).describe('Allow reusing an existing branch even if its upstream differs from develop_branch'),
68
68
  });
69
+ const ADD_OUTPUT = z.strictObject({
70
+ name: z.string().describe('Name of the worktree (the wtN it was numbered as)'),
71
+ path: z.string().describe('Absolute path of the worktree (on dry_run, where it would be)'),
72
+ branch: z.string().describe('Branch checked out in the worktree'),
73
+ base: z.string().describe('Base branch the worktree branch starts from'),
74
+ setupFailed: z.boolean().optional().describe('true when the setup command failed or timed out, false when it succeeded or was not run (omitted on dry_run)'),
75
+ dryRun: DRY_RUN_FIELD,
76
+ });
69
77
  const worktreeAddCommand = defineCommand({
70
78
  path: ['worktree', 'add'],
71
79
  description: 'Create a new worktree',
72
80
  input: worktreeAddInput,
81
+ output: ADD_OUTPUT,
73
82
  positional: [],
74
83
  shortFlags: { directory: '-D' },
75
84
  aliases: { allow_existing_branch: '--force' },
@@ -94,6 +103,8 @@ function runAdd(input, io) {
94
103
  out.planned(operation);
95
104
  out.done(operation);
96
105
  out.data(result.path);
106
+ const created = { name: result.name, path: result.path, branch: result.branch, base: result.baseBranch };
107
+ out.result(input.dry_run ? created : { ...created, setupFailed: result.setupResult !== undefined && result.setupResult.exitCode !== 0 });
97
108
  if (result.linkedFiles.length > 0)
98
109
  countLinkResults(result.linkedFiles, out);
99
110
  if (result.copiedFiles.length > 0)
@@ -111,10 +122,16 @@ const worktreeRemoveInput = z.object({
111
122
  keep_branch: z.boolean().default(false).describe('Keep the branch'),
112
123
  dry_run: dryRunInput,
113
124
  });
125
+ const REMOVE_OUTPUT = z.strictObject({
126
+ name: z.string().describe('Name of the worktree that was (on dry_run, would be) removed, as given'),
127
+ deletedBranch: z.boolean().describe('Whether the local branch was deleted (false when kept, when the deletion failed, and on dry_run)'),
128
+ dryRun: DRY_RUN_FIELD,
129
+ });
114
130
  const worktreeRemoveCommand = defineCommand({
115
131
  path: ['worktree', 'remove'],
116
132
  description: 'Remove a worktree',
117
133
  input: worktreeRemoveInput,
134
+ output: REMOVE_OUTPUT,
118
135
  positional: ['name'],
119
136
  shortFlags: { directory: '-D', dry_run: '-n' },
120
137
  interactive: false,
@@ -132,14 +149,17 @@ function runRemove(input, io) {
132
149
  if (input.dry_run) {
133
150
  if (!input.keep_branch)
134
151
  out.planned({ verb: 'delete', target: `local branch ${input.name}` });
152
+ out.result({ name: input.name, deletedBranch: false });
135
153
  return 0;
136
154
  }
137
- if (!input.keep_branch) {
155
+ const shouldDelete = !input.keep_branch;
156
+ if (shouldDelete) {
138
157
  if (branchError === undefined)
139
158
  out.done({ verb: 'delete', target: `local branch ${input.name}` });
140
159
  else
141
160
  out.warning(`could not delete local branch ${input.name}: ${branchError}`);
142
161
  }
162
+ out.result({ name: input.name, deletedBranch: shouldDelete && branchError === undefined });
143
163
  return 0;
144
164
  }
145
165
  catch (error) {
@@ -147,10 +167,16 @@ function runRemove(input, io) {
147
167
  }
148
168
  }
149
169
  const worktreeInitInput = z.object({ directory: directorySchema, dry_run: dryRunInput });
170
+ const INIT_OUTPUT = z.strictObject({
171
+ configFile: z.string().describe('Absolute path of the worktree config file (on dry_run, where it would be)'),
172
+ ignoreFile: z.string().describe('Absolute path of the worktree ignore file (on dry_run, where it would be)'),
173
+ dryRun: DRY_RUN_FIELD,
174
+ });
150
175
  const worktreeInitCommand = defineCommand({
151
176
  path: ['worktree', 'init'],
152
177
  description: 'Create the worktree config files in the main worktree',
153
178
  input: worktreeInitInput,
179
+ output: INIT_OUTPUT,
154
180
  positional: [],
155
181
  shortFlags: { directory: '-D', dry_run: '-n' },
156
182
  interactive: false,
@@ -166,9 +192,11 @@ function writeInitFiles(configFile, ignoreFile, config, out) {
166
192
  try {
167
193
  saveConfig(config, configFile);
168
194
  out.done({ verb: 'create', target: `worktree config ${configFile}` });
195
+ out.result({ configFile });
169
196
  mkdirSync(path.dirname(ignoreFile), { recursive: true });
170
197
  writeFileSync(ignoreFile, DEFAULT_WORKTREEIGNORE_CONTENT);
171
198
  out.done({ verb: 'create', target: `worktree ignore file ${ignoreFile}` });
199
+ out.result({ ignoreFile });
172
200
  }
173
201
  catch (error) {
174
202
  throw hasErrorCode(error) ? toOsError(error) : error;
@@ -202,6 +230,7 @@ function runInit(input, io) {
202
230
  if (input.dry_run) {
203
231
  out.planned({ verb: 'create', target: `worktree config ${configFile}` });
204
232
  out.planned({ verb: 'create', target: `worktree ignore file ${ignoreFile}` });
233
+ out.result({ configFile, ignoreFile });
205
234
  return 0;
206
235
  }
207
236
  writeInitFiles(configFile, ignoreFile, getDefaultConfig(targetRepository, path.basename(mainWorktree)), out);
@@ -227,10 +256,21 @@ const worktreeLinkInput = z.object({
227
256
  all: z.boolean().default(false).describe('Apply to all sub-worktrees'),
228
257
  dry_run: dryRunInput,
229
258
  });
259
+ const LINK_ROW = z.strictObject({
260
+ path: z.string().describe('Absolute path of the symlink'),
261
+ destination: z.string().describe('Absolute path the symlink points to'),
262
+ change: z.enum(['create', 'update', 'skip', 'error']).describe('create: a new symlink; update: an existing one was replaced; skip: left as it was; error: could not be made'),
263
+ reason: z.string().optional().describe('Why the link was skipped or failed (omitted for create and update)'),
264
+ });
265
+ const LINK_OUTPUT = z.strictObject({
266
+ links: z.array(LINK_ROW).describe('One entry per link of the config in each target worktree (an empty array when there is no sub-worktree)'),
267
+ dryRun: DRY_RUN_FIELD,
268
+ });
230
269
  const worktreeLinkCommand = defineCommand({
231
270
  path: ['worktree', 'link'],
232
271
  description: 'Apply or update symlinks in existing worktrees',
233
272
  input: worktreeLinkInput,
273
+ output: LINK_OUTPUT,
234
274
  positional: [],
235
275
  shortFlags: { directory: '-D' },
236
276
  interactive: true,
@@ -268,18 +308,33 @@ function plannedOperation(plan, symlinkPath, destination) {
268
308
  return { verb: 'update', target: `symlink ${symlinkPath} -> ${destination} (real file, asks first)` };
269
309
  return { verb: 'skip', target: `symlink ${symlinkPath} (${skipReason(plan)})` };
270
310
  }
311
+ function plannedEntry(plan, symlinkPath, destination) {
312
+ if (plan === 'create')
313
+ return { path: symlinkPath, destination, change: 'create' };
314
+ if (plan === 'update')
315
+ return { path: symlinkPath, destination, change: 'update' };
316
+ if (plan === 'ask')
317
+ return { path: symlinkPath, destination, change: 'update', reason: 'a real file exists; it is replaced only after confirmation' };
318
+ return { path: symlinkPath, destination, change: 'skip', reason: skipReason(plan) };
319
+ }
271
320
  function previewLinks(targets, config, projectRoot, options, out) {
272
321
  const decision = decideOverwrite({ force: options.force, allWorktrees: options.all });
322
+ const links = [];
273
323
  for (const target of targets) {
274
324
  for (const link of config.links) {
275
325
  const destination = path.join(projectRoot, 'base', link.target_repo, link.target_path);
276
- out.planned(plannedOperation(planLink(link, projectRoot, target, decision), path.join(target, link.path), destination));
326
+ const plan = planLink(link, projectRoot, target, decision);
327
+ out.planned(plannedOperation(plan, path.join(target, link.path), destination));
328
+ links.push(plannedEntry(plan, path.join(target, link.path), destination));
277
329
  }
278
330
  }
331
+ out.result({ links });
279
332
  }
280
333
  // 1 つの worktree にリンクを作り、(作った数, 飛ばした数, 失敗した数) を返す
281
334
  function applyLinks(target, config, projectRoot, options, io, out) {
282
335
  const decision = decideOverwrite({ force: options.force, allWorktrees: options.all });
336
+ // 作る前の計画で、新しい symlink か置き換えかを分ける。結果は config.links と同じ順に返る
337
+ const plans = config.links.map(link => planLink(link, projectRoot, target, decision));
283
338
  const results = createSymlinksSafe(config, projectRoot, target, out, {
284
339
  force: decision.force,
285
340
  confirm: decision.ask ? symlinkPath => isConfirmed(io, `real file exists: ${symlinkPath}\noverwrite it?`) : undefined,
@@ -289,7 +344,13 @@ function applyLinks(target, config, projectRoot, options, io, out) {
289
344
  out.count(`symlinks created in ${target}`, created.length);
290
345
  for (const result of skipped)
291
346
  out.done({ verb: 'skip', target: `symlink ${result.symlinkPath} (${result.message})` });
292
- return [created.length, skipped.length, results.filter(result => result.action === 'error').length];
347
+ const links = results.map((result, index) => {
348
+ const base = { path: result.symlinkPath, destination: result.targetPath };
349
+ if (result.action === 'created')
350
+ return { ...base, change: plans.at(index) === 'create' ? 'create' : 'update' };
351
+ return { ...base, change: result.action === 'skipped' ? 'skip' : 'error', reason: result.message };
352
+ });
353
+ return { counts: [created.length, skipped.length, results.filter(result => result.action === 'error').length], links };
293
354
  }
294
355
  function runLink(input, io) {
295
356
  requireRepositoryMatch('reject', input.repo, io, process.cwd());
@@ -308,6 +369,7 @@ function runLink(input, io) {
308
369
  const targets = resolved.directories;
309
370
  if (targets.length === 0) {
310
371
  out.count('sub-worktrees', 0);
372
+ out.result({ links: [] });
311
373
  return 0;
312
374
  }
313
375
  const options = { force: input.force, all: input.all };
@@ -316,8 +378,12 @@ function runLink(input, io) {
316
378
  return 0;
317
379
  }
318
380
  let [created, skipped, failed] = [0, 0, 0];
381
+ const links = [];
319
382
  for (const target of targets) {
320
- const [targetCreated, targetSkipped, targetFailed] = applyLinks(target, config, projectRoot, options, io, out);
383
+ const applied = applyLinks(target, config, projectRoot, options, io, out);
384
+ const [targetCreated, targetSkipped, targetFailed] = applied.counts;
385
+ links.push(...applied.links);
386
+ out.result({ links: [...links] });
321
387
  created += targetCreated;
322
388
  skipped += targetSkipped;
323
389
  failed += targetFailed;
@@ -58,10 +58,6 @@ export interface IssueReadout {
58
58
  closedByPullRequestsReferences(includeClosedPrs: true) の PR
59
59
  */
60
60
  readonly closingPullRequests: readonly PullRequestReadout[];
61
- /**
62
- timelineItems の PR。ConnectedEvent のうち後で外されていないものと、CrossReferencedEvent のうち閉じる参照か、head が `/<Issue 番号>` で終わるもの
63
- */
64
- readonly timelinePullRequests: readonly PullRequestReadout[];
65
61
  }
66
62
  export interface TargetIssueReadout extends IssueReadout {
67
63
  readonly body: string;
@@ -52,7 +52,7 @@ export interface PullRequestBaseInput {
52
52
  readonly base: string;
53
53
  readonly developBranch: string;
54
54
  /**
55
- 下の段のブランチを head に持つ PR(pickBasePullRequest で選んだもの)。積んだ記録のときだけ見る
55
+ 下の段のブランチを head に持つ PR(pickLowerPullRequest で選んだもの)。積んだ記録のときだけ見る
56
56
  */
57
57
  readonly lowerPullRequest?: Readonly<PullRequestReadout> | undefined;
58
58
  }
@@ -166,6 +166,23 @@ blocked by の後には、済んでいない前提をすべて並べる。別の
166
166
  */
167
167
  export declare function describeReadiness(readiness: Readiness, prerequisites: readonly Prerequisite[], targetRepository: RepositoryReference): string;
168
168
  /**
169
+ issues の前提と、その pullRequest を state にしたものとして置き換える。一覧に pullRequest が無ければ足す。
170
+ マージの後の読み取りから、マージの前(open)や閉じた後(merged)の判定を作るのに使う
171
+ */
172
+ export declare function assumePullRequestState(prerequisites: readonly Prerequisite[], issues: readonly IssueReference[], pullRequest: IssuePullRequest, state: 'open' | 'merged'): readonly Prerequisite[];
173
+ /**
174
+ 判定の区分か積む先のブランチが違うか。理由と注記の違いは変化としない
175
+ */
176
+ export declare function hasReadinessChanged(before: Readiness, after: Readiness): boolean;
177
+ /**
178
+ 判定の変化の行の文。blocked は理由を付けず、stackable は積む先を付ける
179
+ */
180
+ export declare function describeReadinessChange(readiness: Readiness, targetRepository: RepositoryReference): string;
181
+ /**
182
+ 着手の跡があり、issues のどれかを stack で待つ(その上に積んだ段の)Issue か
183
+ */
184
+ export declare function isStackedOn(target: IssueFacts, prerequisites: readonly Prerequisite[], issues: readonly IssueReference[]): boolean;
185
+ /**
169
186
  読めなかった Issue の表示。列と札は動かさない
170
187
  */
171
188
  export declare function describeUnknown(reason: string): string;
@@ -314,6 +314,43 @@ export function describeReadiness(readiness, prerequisites, targetRepository) {
314
314
  return `blocked${unfinished.length === 0 ? '' : ` by ${unfinished.join(', ')}`}${reason}`;
315
315
  }
316
316
  /**
317
+ issues の前提と、その pullRequest を state にしたものとして置き換える。一覧に pullRequest が無ければ足す。
318
+ マージの後の読み取りから、マージの前(open)や閉じた後(merged)の判定を作るのに使う
319
+ */
320
+ export function assumePullRequestState(prerequisites, issues, pullRequest, state) {
321
+ const keys = new Set(issues.map(issue => issueReferenceKey(issue)));
322
+ const assumed = { ...pullRequest, state };
323
+ const isSame = (other) => other.number === pullRequest.number && isSameRepository(other.repository, pullRequest.repository);
324
+ return prerequisites.map((prerequisite) => {
325
+ const { issue } = prerequisite;
326
+ if (!keys.has(issueReferenceKey(issue.ref)))
327
+ return prerequisite;
328
+ const pullRequests = issue.pullRequests.some(other => isSame(other))
329
+ ? issue.pullRequests.map(other => (isSame(other) ? assumed : other))
330
+ : [...issue.pullRequests, assumed];
331
+ return { ...prerequisite, issue: { ...issue, state: state === 'open' ? 'open' : 'closed', pullRequests } };
332
+ });
333
+ }
334
+ /**
335
+ 判定の区分か積む先のブランチが違うか。理由と注記の違いは変化としない
336
+ */
337
+ export function hasReadinessChanged(before, after) {
338
+ return before.kind !== after.kind || before.stackOn?.branch !== after.stackOn?.branch;
339
+ }
340
+ /**
341
+ 判定の変化の行の文。blocked は理由を付けず、stackable は積む先を付ける
342
+ */
343
+ export function describeReadinessChange(readiness, targetRepository) {
344
+ return readiness.kind === 'blocked' ? 'blocked' : describeReadiness(readiness, [], targetRepository);
345
+ }
346
+ /**
347
+ 着手の跡があり、issues のどれかを stack で待つ(その上に積んだ段の)Issue か
348
+ */
349
+ export function isStackedOn(target, prerequisites, issues) {
350
+ const keys = new Set(issues.map(issue => issueReferenceKey(issue)));
351
+ return hasStarted(target) && prerequisites.some(({ issue, wait }) => wait === 'stack' && keys.has(issueReferenceKey(issue.ref)));
352
+ }
353
+ /**
317
354
  読めなかった Issue の表示。列と札は動かさない
318
355
  */
319
356
  export function describeUnknown(reason) {
@@ -331,12 +368,12 @@ function toPullRequest(readout) {
331
368
  isCrossRepository: readout.isCrossRepository,
332
369
  };
333
370
  }
334
- // 3 つの読み口で同じ PR を 1 本に数える。fork からの PR は、リンクしたブランチの読み口だけ捨てる
371
+ // 積んだ PR は開いている間 Development 欄に載らず、マージ済みの PR はブランチが消えるので、2 つの読み口を合わせる。
372
+ // 同じ PR は 1 本に数え、fork からの PR は、リンクしたブランチの読み口だけ捨てる
335
373
  function collectPullRequests(readout) {
336
374
  const sources = [
337
375
  ...readout.linkedBranches.flatMap(branch => branch.pullRequests).filter(pullRequest => !pullRequest.isCrossRepository),
338
376
  ...readout.closingPullRequests,
339
- ...readout.timelinePullRequests,
340
377
  ];
341
378
  const seen = new Set();
342
379
  return sources
@@ -0,0 +1,62 @@
1
+ import type { PullRequestReadout } from './issue-readout.js';
2
+ import type { BaseReading } from './state.js';
3
+ export interface RestackInput {
4
+ /**
5
+ base の記録。形の誤りは呼び出し側が先に止める
6
+ */
7
+ readonly reading: Exclude<BaseReading, {
8
+ kind: 'malformed';
9
+ }>;
10
+ readonly developBranch: string;
11
+ /**
12
+ 下の段のブランチを head に持つ PR(pickLowerPullRequest で選んだもの)
13
+ */
14
+ readonly lowerPullRequest: Readonly<PullRequestReadout> | undefined;
15
+ /**
16
+ 下の段のブランチの、remote の先頭の SHA。remote に無ければ undefined
17
+ */
18
+ readonly lowerHead: string | undefined;
19
+ }
20
+ export type RestackDecision = {
21
+ readonly kind: 'not-stacked';
22
+ readonly base: string;
23
+ } | {
24
+ readonly kind: 'up-to-date';
25
+ readonly base: string;
26
+ } | {
27
+ readonly kind: 'moved';
28
+ readonly base: string;
29
+ } | {
30
+ readonly kind: 'merged';
31
+ readonly base: string;
32
+ readonly pullRequest: number;
33
+ } | {
34
+ readonly kind: 'gone';
35
+ readonly base: string;
36
+ readonly pullRequest: number | undefined;
37
+ };
38
+ /**
39
+ 載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
40
+ */
41
+ export declare function decideRestack(input: Readonly<RestackInput>): RestackDecision;
42
+ /**
43
+ `pr restack --check` の行
44
+ */
45
+ export declare function describeRestackCheck(branch: string, decision: Exclude<RestackDecision, {
46
+ kind: 'gone';
47
+ }>): string;
48
+ /**
49
+ 下の段のブランチが消えていて、マージもされていないときの文(`error: ` の前置きを含まない)
50
+ */
51
+ export declare function describeGone(decision: Extract<RestackDecision, {
52
+ kind: 'gone';
53
+ }>): string;
54
+ /**
55
+ 載せ直しが要るか。下の段が消えていて決められないときは undefined
56
+ */
57
+ export declare function needsRestack(decision: Readonly<RestackDecision>): boolean | undefined;
58
+ /**
59
+ session show の `- needs restack:` の行。決められないときは undefined
60
+ */
61
+ export declare function describeNeedsRestack(decision: Readonly<RestackDecision>): string | undefined;
62
+ //# sourceMappingURL=restack.d.ts.map
@@ -0,0 +1,53 @@
1
+ // 積んだブランチを載せ直す先の判断と、その表示。git と GitHub の読み取りは commands が行う。
2
+ /**
3
+ 載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
4
+ */
5
+ export function decideRestack(input) {
6
+ const { reading, developBranch, lowerPullRequest, lowerHead } = input;
7
+ if (reading.kind === 'development')
8
+ return { kind: 'not-stacked', base: developBranch };
9
+ const { branch, sha } = reading.record;
10
+ if (lowerPullRequest?.state === 'MERGED')
11
+ return { kind: 'merged', base: developBranch, pullRequest: lowerPullRequest.number };
12
+ if (lowerHead === undefined)
13
+ return { kind: 'gone', base: branch, pullRequest: lowerPullRequest?.number };
14
+ return { kind: lowerHead === sha ? 'up-to-date' : 'moved', base: branch };
15
+ }
16
+ /**
17
+ `pr restack --check` の行
18
+ */
19
+ export function describeRestackCheck(branch, decision) {
20
+ switch (decision.kind) {
21
+ case 'not-stacked':
22
+ case 'up-to-date': {
23
+ return `up to date: ${branch} on ${decision.base}`;
24
+ }
25
+ case 'moved': {
26
+ return `needs restack: ${branch} on ${decision.base} (base moved)`;
27
+ }
28
+ case 'merged': {
29
+ return `needs restack: ${branch} onto ${decision.base} (base #${String(decision.pullRequest)} merged)`;
30
+ }
31
+ }
32
+ }
33
+ /**
34
+ 下の段のブランチが消えていて、マージもされていないときの文(`error: ` の前置きを含まない)
35
+ */
36
+ export function describeGone(decision) {
37
+ const pullRequest = decision.pullRequest === undefined ? 'it has no merged PR' : `PR #${String(decision.pullRequest)} was not merged`;
38
+ return `base branch ${decision.base} is gone and ${pullRequest}`;
39
+ }
40
+ /**
41
+ 載せ直しが要るか。下の段が消えていて決められないときは undefined
42
+ */
43
+ export function needsRestack(decision) {
44
+ return decision.kind === 'gone' ? undefined : decision.kind === 'moved' || decision.kind === 'merged';
45
+ }
46
+ /**
47
+ session show の `- needs restack:` の行。決められないときは undefined
48
+ */
49
+ export function describeNeedsRestack(decision) {
50
+ const needed = needsRestack(decision);
51
+ return needed === undefined ? undefined : `- needs restack: ${needed ? 'yes' : 'no'}`;
52
+ }
53
+ //# sourceMappingURL=restack.js.map
@@ -2,6 +2,7 @@ import type { IssueReference } from './reference-parser.js';
2
2
  export declare const FLAG_PECOT_ACTIVE = ".pecot-active";
3
3
  export declare const FLAG_PECOT_SESSION_TITLE = ".pecot-session-title";
4
4
  export declare const FLAG_PECOT_BASE = ".pecot-base";
5
+ export declare const FLAG_PECOT_RESTACK = ".pecot-restack";
5
6
  export declare const FLAG_PECOT_QUICK_MODE = ".pecot-quick-mode";
6
7
  export declare const FLAG_WIP_BRANCH_LINKED = ".wip-branch-linked";
7
8
  export declare const FLAG_PR_CREATE_SLASH_PENDING = "pr-create-slash-pending";
@@ -56,4 +57,42 @@ export declare function formatBaseRecord(record: Readonly<BaseRecord>): string;
56
57
  形が誤っていれば malformed
57
58
  */
58
59
  export declare function interpretBaseRecord(content: string | undefined): BaseReading;
60
+ export interface RestackProgress {
61
+ readonly remote: string;
62
+ /**
63
+ 載せ直しているブランチ。rebase の途中は HEAD が detached なので、ここから読む
64
+ */
65
+ readonly branch: string;
66
+ /**
67
+ 載せ直す前のブランチの先頭。remote にだけある変更が見つかったときに、ここへ戻す
68
+ */
69
+ readonly originalSha: string;
70
+ readonly ontoBranch: string;
71
+ readonly ontoSha: string;
72
+ /**
73
+ push の `--force-with-lease` に渡す、fetch した時点の remote の SHA。remote にブランチが無ければ undefined
74
+ */
75
+ readonly leaseSha: string | undefined;
76
+ /**
77
+ 載せ直した後も積んだ記録を保つなら、積んだ先の Issue。開発ブランチへ載せ直すなら undefined
78
+ */
79
+ readonly stackedOn: IssueReference | undefined;
80
+ }
81
+ export type RestackProgressReading = {
82
+ readonly kind: 'none';
83
+ } | {
84
+ readonly kind: 'progress';
85
+ readonly progress: RestackProgress;
86
+ } | {
87
+ readonly kind: 'malformed';
88
+ readonly content: string;
89
+ };
90
+ /**
91
+ .pecot-restack の 1 行。`<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N>` で、無い項目は `-`
92
+ */
93
+ export declare function formatRestackProgress(progress: Readonly<RestackProgress>): string;
94
+ /**
95
+ .pecot-restack の内容を読む。ファイルが無ければ none、形が誤っていれば malformed
96
+ */
97
+ export declare function interpretRestackProgress(content: string | undefined): RestackProgressReading;
59
98
  //# sourceMappingURL=state.d.ts.map
@@ -9,11 +9,13 @@ export const FLAG_PECOT_ACTIVE = '.pecot-active';
9
9
  export const FLAG_PECOT_SESSION_TITLE = '.pecot-session-title';
10
10
  // 着手のときに選んだ base(ブランチ・位置・積んだ先の Issue)。session start が書き、session finish が消す
11
11
  export const FLAG_PECOT_BASE = '.pecot-base';
12
+ // 衝突で止まった載せ直しの途中の記録。pr restack が書き、続行か取りやめで消す
13
+ export const FLAG_PECOT_RESTACK = '.pecot-restack';
12
14
  export const FLAG_PECOT_QUICK_MODE = '.pecot-quick-mode';
13
15
  export const FLAG_WIP_BRANCH_LINKED = '.wip-branch-linked';
14
16
  // スラッシュコマンド起点の外部反映免除フラグ。
15
17
  // 設置は hooks の create-slash-flag.sh が行う。
16
- // 確認は mcp-handlers/pecot-post-ask.sh(merge は core/external-post-check.sh)が行う。
18
+ // 確認は mcp-handlers/pecot-post-ask.sh(merge は pr_merge も。gh pr merge は core/external-post-check.sh)が行う。
17
19
  // MCP ツールが実投稿成功時に削除する。
18
20
  export const FLAG_PR_CREATE_SLASH_PENDING = 'pr-create-slash-pending';
19
21
  export const FLAG_ISSUE_CREATE_SLASH_PENDING = 'issue-create-slash-pending';
@@ -92,4 +94,29 @@ export function interpretBaseRecord(content) {
92
94
  const stackedOn = parseStackedOn(issue);
93
95
  return stackedOn === undefined ? { kind: 'malformed', content } : { kind: 'stacked', record: { branch, sha, stackedOn }, stackedOn };
94
96
  }
97
+ const ABSENT = '-';
98
+ /**
99
+ .pecot-restack の 1 行。`<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N>` で、無い項目は `-`
100
+ */
101
+ export function formatRestackProgress(progress) {
102
+ const stackedOn = progress.stackedOn === undefined ? ABSENT : issueReferenceToString(progress.stackedOn);
103
+ return [progress.remote, progress.branch, progress.originalSha, progress.ontoBranch, progress.ontoSha, progress.leaseSha ?? ABSENT, stackedOn].join(' ');
104
+ }
105
+ /**
106
+ .pecot-restack の内容を読む。ファイルが無ければ none、形が誤っていれば malformed
107
+ */
108
+ export function interpretRestackProgress(content) {
109
+ if (content === undefined)
110
+ return { kind: 'none' };
111
+ const malformed = { kind: 'malformed', content };
112
+ const [remote, branch, originalSha, ontoBranch, ontoSha, lease, issue, ...rest] = content.split(' ');
113
+ if (remote === undefined || branch === undefined || originalSha === undefined || ontoBranch === undefined || ontoSha === undefined || lease === undefined || issue === undefined || rest.length > 0 || [remote, branch, ontoBranch].includes('') || !BASE_SHA_PATTERN.test(ontoSha) || !BASE_SHA_PATTERN.test(originalSha))
114
+ return malformed;
115
+ if (lease !== ABSENT && !BASE_SHA_PATTERN.test(lease))
116
+ return malformed;
117
+ const stackedOn = issue === ABSENT ? undefined : parseStackedOn(issue);
118
+ if (issue !== ABSENT && stackedOn === undefined)
119
+ return malformed;
120
+ return { kind: 'progress', progress: { remote, branch, originalSha, ontoBranch, ontoSha, leaseSha: lease === ABSENT ? undefined : lease, stackedOn } };
121
+ }
95
122
  //# sourceMappingURL=state.js.map
@@ -24,10 +24,6 @@ export declare function describeBaseMismatch(base: string | undefined, decision:
24
24
  kind: 'blocked';
25
25
  }>, target: IssueReference): HintedText | undefined;
26
26
  /**
27
- base のブランチを head に持つ PR のうち、表に出す 1 本。fork でない open のもの、無ければ fork でない最新のもの(新しい順に渡す)
28
- */
29
- export declare function pickBasePullRequest(pullRequests: readonly PullRequestReadout[]): PullRequestReadout | undefined;
30
- /**
31
27
  session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
32
28
  */
33
29
  export declare function describeStackBase(branch: string, issue: IssueReference, pullRequest: Readonly<PullRequestReadout> | undefined | 'unknown'): string;
@@ -33,13 +33,6 @@ export function describeBaseMismatch(base, decision, target) {
33
33
  return isDifferent ? hinted `${inputHint(['session', 'start'], 'base', base)} differs from the base chosen by readiness: ${decision.branch} (stacked on ${displayReference(decision.issue, target.repository)})` : undefined;
34
34
  }
35
35
  /**
36
- base のブランチを head に持つ PR のうち、表に出す 1 本。fork でない open のもの、無ければ fork でない最新のもの(新しい順に渡す)
37
- */
38
- export function pickBasePullRequest(pullRequests) {
39
- const own = pullRequests.filter(pullRequest => !pullRequest.isCrossRepository);
40
- return own.find(pullRequest => pullRequest.state === 'OPEN') ?? own[0];
41
- }
42
- /**
43
36
  session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
44
37
  */
45
38
  export function describeStackBase(branch, issue, pullRequest) {
@@ -83,4 +83,68 @@ export declare function gitCurrentBranch(cwd?: string): string | undefined;
83
83
  指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
84
84
  */
85
85
  export declare function remoteRepository(cwd: string | undefined, remote: string): RemoteLocation | undefined;
86
+ export declare const NON_INTERACTIVE_GIT: Readonly<Record<string, string>>;
87
+ export interface FetchResult {
88
+ readonly succeeded: boolean;
89
+ readonly stderr: string;
90
+ }
91
+ export type PushResult = {
92
+ readonly pushed: true;
93
+ } | {
94
+ readonly pushed: false;
95
+ readonly stderr: string;
96
+ };
97
+ export type RebaseOutcome = 'done' | 'conflict';
98
+ /**
99
+ `git fetch <remote>`。失敗・時間切れは succeeded が false
100
+ */
101
+ export declare function fetchRemote(cwd: string, remote: string): FetchResult;
102
+ /**
103
+ ref の指すコミットの SHA。無ければ undefined
104
+ */
105
+ export declare function resolveCommit(cwd: string, reference: string): string | undefined;
106
+ /**
107
+ 2 つの ref の merge-base の SHA。共通の祖先が無ければ undefined
108
+ */
109
+ export declare function mergeBase(cwd: string, a: string, b: string): string | undefined;
110
+ /**
111
+ `git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
112
+ */
113
+ export declare function rebaseOnto(cwd: string, newBase: string, oldBase: string): RebaseOutcome;
114
+ /**
115
+ 衝突を解いた後の `git rebase --continue`。コミットの文の編集は開かない
116
+ */
117
+ export declare function continueRebase(cwd: string): RebaseOutcome;
118
+ export declare function abortRebase(cwd: string): void;
119
+ /**
120
+ rebase の途中か。worktree では .git がファイルなので、git に場所を尋ねる
121
+ */
122
+ export declare function isRebaseInProgress(cwd: string): boolean;
123
+ /**
124
+ 衝突が残っているファイルの一覧
125
+ */
126
+ export declare function conflictedFiles(cwd: string): readonly string[];
127
+ /**
128
+ remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
129
+ */
130
+ export declare function remoteOnlyChanges(cwd: string, local: string, remoteBranch: string, excluded: readonly string[]): readonly string[];
131
+ /**
132
+ 2 つの ref の木が同じか
133
+ */
134
+ export declare function hasSameTree(cwd: string, a: string, b: string): boolean;
135
+ export declare function resetHardTo(cwd: string, reference: string): void;
136
+ /**
137
+ remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか失敗したら stderr を返す
138
+ */
139
+ export declare function pushWithLease(cwd: string, remote: string, branch: string, expectedSha: string): PushResult;
140
+ export type RemoteHead = {
141
+ readonly isReachable: true;
142
+ readonly sha: string | undefined;
143
+ } | {
144
+ readonly isReachable: false;
145
+ };
146
+ /**
147
+ remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
148
+ */
149
+ export declare function remoteBranchHead(cwd: string, remote: string, branch: string): RemoteHead;
86
150
  //# sourceMappingURL=git.d.ts.map