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

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pecot-w",
3
- "version": "7.0.1-dev.19",
3
+ "version": "7.0.1-dev.21",
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"
@@ -9,7 +9,7 @@ import { requireActiveConfig, stopWith } from './command-stop.js';
9
9
  import { kindOfFailure } from './failure.js';
10
10
  import { createGitHubClient } from './github-client.js';
11
11
  import { createOutput, DRY_RUN_FIELD } from './output.js';
12
- import { requireRepositoryMatch } from './repository-match.js';
12
+ import { requireGitRemote } from './repository-match.js';
13
13
  import { USAGE_EXIT_CODE } from './usage-error.js';
14
14
  const BRANCH_DELETE_OUTPUT = z.strictObject({
15
15
  branch: z.string().describe('Name of the remote branch'),
@@ -33,7 +33,7 @@ const branchDeleteCommand = defineCommand({
33
33
  interactive: false,
34
34
  run: async (input, io) => {
35
35
  // 位置引数の repo は対象のリポで、cwd と比べる明示値ではない
36
- requireRepositoryMatch('reject', undefined, io, process.cwd());
36
+ requireGitRemote(io, process.cwd());
37
37
  const out = createOutput(input.dry_run, io);
38
38
  // 1. repo をパース
39
39
  let target;
@@ -12,7 +12,6 @@ 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_PECOT_QUICK_MODE } from '../domain/state.js';
16
15
  import { compareStrings, pythonRightStrip, pythonStrip, pythonStringRepr, truncateCodePoints } from '../domain/python-format.js';
17
16
  import { createIssueReference, issueReferenceKey, issueReferenceToCliReference } from '../domain/reference-parser.js';
18
17
  import { describeReadiness, displayReference, hasStarted, stackChains } from '../domain/readiness.js';
@@ -20,7 +19,6 @@ import { parseIssueFile } from '../infra/frontmatter-file.js';
20
19
  import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
21
20
  import { DEPENDENCIES_UNSUPPORTED } from '../infra/github/issues.js';
22
21
  import { OutputPathReservationError, normalizePath, outputDirectory, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
23
- import { touchFlag } from '../infra/state-store.js';
24
22
  import { templateFile } from '../infra/template-store.js';
25
23
  import { readTextFile } from '../infra/text-file.js';
26
24
  import { CommandExit, defineCommand } from './command-definition.js';
@@ -774,7 +772,7 @@ async function createFreeform(output, input, isDryRun) {
774
772
  planIssue(output, owner, repository, title);
775
773
  return;
776
774
  }
777
- const posted = await postIssue(output, client, config, newSession(), {
775
+ await postIssue(output, client, config, newSession(), {
778
776
  owner,
779
777
  repository,
780
778
  title,
@@ -787,8 +785,6 @@ async function createFreeform(output, input, isDryRun) {
787
785
  prerequisites: [],
788
786
  settleColumn: false,
789
787
  });
790
- if (posted.isOnBoard && !BACKLOG_TYPES.has(issueType))
791
- touchFlag(FLAG_PECOT_QUICK_MODE);
792
788
  }
793
789
  // -m の直接投稿。入力の確認から作成まで
794
790
  async function createFromMessage(output, input, message, isDryRun) {
@@ -30,7 +30,7 @@ export declare const VALID_STATUSES: ReadonlySet<string>;
30
30
  */
31
31
  export declare const TYPE_DEFAULT_STATUS: Readonly<Record<IssueType, string>>;
32
32
  /**
33
- Backlog に置く型(freeform の size と quick-mode フラグの扱いが Epic と同じ)
33
+ Backlog に置く型(freeform の size の扱いが Epic と同じ)
34
34
  */
35
35
  export declare const BACKLOG_TYPES: ReadonlySet<string>;
36
36
  /**
@@ -52,7 +52,7 @@ const TYPE_PREFIX_MAP = new Map([
52
52
  */
53
53
  export const TYPE_DEFAULT_STATUS = { epic: 'backlog', tracker: 'backlog', task: 'ready', bug: 'ready' };
54
54
  /**
55
- Backlog に置く型(freeform の size と quick-mode フラグの扱いが Epic と同じ)
55
+ Backlog に置く型(freeform の size の扱いが Epic と同じ)
56
56
  */
57
57
  export const BACKLOG_TYPES = new Set(['epic', 'tracker']);
58
58
  // --- 終了の表し方 ---
@@ -5,7 +5,7 @@ import { describeApiError } from '../domain/api-error-detail.js';
5
5
  import { getDevelopBranch } from '../domain/config.js';
6
6
  import { describeGone, describeRestackCheck, RESTACK_PATH } from '../domain/restack.js';
7
7
  import { FLAG_PECOT_RESTACK, formatRestackProgress, interpretRestackProgress } from '../domain/state.js';
8
- import { abortRebase, conflictedFiles, continueRebase, fetchRemote, gitStdout, hasSameTree, isRebaseInProgress, mergeBase, pushWithLease, rebaseOnto, remoteOnlyChanges, resetHardTo, resolveCommit, } from '../infra/git.js';
8
+ import { abortRebase, conflictedFiles, continueRebase, fetchRemote, forkPoint, gitStdout, hasSameTree, isAncestor, isRebaseInProgress, mergeBase, pushWithLease, rebaseOnto, remoteOnlyChanges, resetHardTo, resolveCommit, } from '../infra/git.js';
9
9
  import { readBaseRecord, readFlag, removeFlag, writeBaseRecord, writeFlag } from '../infra/state-store.js';
10
10
  import { defineCommand } from './command-definition.js';
11
11
  import { commandHint, hinted } from './command-hint.js';
@@ -61,6 +61,11 @@ function remoteOnlyCommits(cwd, progress, remoteBranch) {
61
61
  const after = new Set(remoteOnlyChanges(cwd, 'HEAD', remoteBranch, excluded));
62
62
  return before.filter(sha => after.has(sha));
63
63
  }
64
+ // remote のブランチが新しい base の上にあり、木が手元と同じか。木が同じでも、remote が新しい base の上に無ければ古い履歴のままなので合わせない
65
+ function isSyncedWithRemote(cwd, progress) {
66
+ const remoteBranch = `${progress.remote}/${progress.branch}`;
67
+ return progress.leaseSha !== undefined && mergeBase(cwd, progress.ontoSha, remoteBranch) === progress.ontoSha && hasSameTree(cwd, 'HEAD', remoteBranch);
68
+ }
64
69
  // rebase が終わった後。remote が載せ直し済みで木が同じなら合わせ、違えば push し、base の記録を書き直す
65
70
  function finishRestack(out, cwd, progress) {
66
71
  const { remote, branch, ontoBranch, leaseSha } = progress;
@@ -70,8 +75,7 @@ function finishRestack(out, cwd, progress) {
70
75
  removeFlag(FLAG_PECOT_RESTACK);
71
76
  stopWith(out, hinted `${remoteBranch} has commits that are not in ${branch}\n${branch} is back at the position before the restack\nrebase or merge them into ${branch} first, then run again: ${commandHint(RESTACK_PATH)}`, 'git-unresolved');
72
77
  }
73
- // 木が同じでも、remote が新しい base の上に無ければ、古い履歴のままなので合わせない
74
- const isSynced = leaseSha !== undefined && mergeBase(cwd, progress.ontoSha, remoteBranch) === progress.ontoSha && hasSameTree(cwd, 'HEAD', remoteBranch);
78
+ const isSynced = isSyncedWithRemote(cwd, progress);
75
79
  if (isSynced)
76
80
  resetHardTo(cwd, remoteBranch);
77
81
  else if (leaseSha !== undefined) {
@@ -149,7 +153,18 @@ function progressOf(out, cwd, branch, target, decision) {
149
153
  const originalSha = resolveCommit(cwd, 'HEAD');
150
154
  if (ontoSha === undefined || originalSha === undefined)
151
155
  return stopWith(out, `branch ${remote}/${decision.base} does not exist\ncheck the remote branches with: git branch -r`, 'git-unresolved');
152
- return { remote, branch, originalSha, ontoBranch: decision.base, ontoSha, leaseSha: resolveCommit(cwd, `${remote}/${branch}`), stackedOn: decision.kind === 'moved' ? record.stackedOn : undefined };
156
+ // 下の段の上に残るなら積んだ先を残す。rebased の base は、下の段(moved から)か開発ブランチ(merged から)
157
+ const isStillStacked = decision.kind === 'moved' || (decision.kind === 'rebased' && decision.base === record.branch);
158
+ return { remote, branch, originalSha, ontoBranch: decision.base, ontoSha, leaseSha: resolveCommit(cwd, `${remote}/${branch}`), stackedOn: isStillStacked ? record.stackedOn : undefined };
159
+ }
160
+ // rebase の起点。記録の位置が HEAD に無いとき(push が拒まれた後に base が進んだときなど)は、別の点から求める。
161
+ // 下の段の追跡参照からの fork-point を先に使い、求まらなければ新しい base との merge-base にする。古い下の段のコミットを積み直さない
162
+ function rebaseStartOf(out, cwd, target, ontoSha) {
163
+ const { sha, branch } = target.reading.record;
164
+ if (isAncestor(cwd, sha, 'HEAD'))
165
+ return sha;
166
+ const start = forkPoint(cwd, `${target.remote}/${branch}`, 'HEAD') ?? mergeBase(cwd, 'HEAD', ontoSha);
167
+ return start ?? stopWith(out, `cannot find where HEAD forked from ${branch}`, 'git-unresolved');
153
168
  }
154
169
  async function runRestack(input, io) {
155
170
  const out = createOutput(input.dry_run, io);
@@ -194,6 +209,18 @@ async function runRestack(input, io) {
194
209
  out.data(describeRestackCheck(branch, decision));
195
210
  return;
196
211
  }
212
+ if (decision.kind === 'rebased') {
213
+ // 載せ直し済みなので rebase をせず、push と記録の書き直しだけを行う
214
+ const progress = progressOf(out, cwd, branch, target, decision);
215
+ if (input.dry_run) {
216
+ const isSynced = isSyncedWithRemote(cwd, progress);
217
+ out.result({ branch, base: decision.base, outcome: isSynced ? 'synced' : 'restacked' });
218
+ out.planned({ verb: 'update', target: isSynced ? `${branch} synced with ${remote}/${branch}` : `${branch} restacked on ${decision.base}` });
219
+ return;
220
+ }
221
+ finishRestack(out, cwd, progress);
222
+ return;
223
+ }
197
224
  if (decision.kind !== 'moved' && decision.kind !== 'merged') {
198
225
  out.result({ branch, base: decision.base, outcome: 'up-to-date' });
199
226
  out.done({ verb: 'unchanged', target: `${branch} is up to date` });
@@ -205,7 +232,7 @@ async function runRestack(input, io) {
205
232
  out.planned({ verb: 'update', target: `${branch} restacked on ${decision.base}` });
206
233
  return;
207
234
  }
208
- if (rebaseOnto(cwd, progress.ontoSha, reading.record.sha) === 'conflict') {
235
+ if (rebaseOnto(cwd, progress.ontoSha, rebaseStartOf(out, cwd, target, progress.ontoSha)) === 'conflict') {
209
236
  writeFlag(FLAG_PECOT_RESTACK, formatRestackProgress(progress));
210
237
  stopOnConflict(out, cwd, progress);
211
238
  }
@@ -16,9 +16,10 @@ import { jsonField } from '../domain/json.js';
16
16
  import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBase, describeBaseStop, describePushStatus, DIVERGED_FIX_HINT, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, pickLowerPullRequest, pushFixHintOf, validatePullRequestContent } from '../domain/pull-request.js';
17
17
  import { parsePythonInteger, pythonStrip } from '../domain/python-format.js';
18
18
  import { splitOwnerRepository } from '../domain/repository-resolver.js';
19
+ import { RESTACK_PATH } from '../domain/restack.js';
19
20
  import { loadActiveConfig } from '../infra/config-store.js';
20
21
  import { parsePullRequestFile } from '../infra/frontmatter-file.js';
21
- import { gitCurrentBranch, gitRemoteUrl, gitStdout, gitToplevel, primaryRemoteName, remoteBranchHead, runGit } from '../infra/git.js';
22
+ import { gitCurrentBranch, gitRemoteUrl, gitStdout, gitToplevel, isAncestor, primaryRemoteName, remoteBranchHead, resolveCommit, runGit } from '../infra/git.js';
22
23
  import { TransportFailure } from '../infra/github/client.js';
23
24
  import { GitHubAPIError } from '../infra/github/errors.js';
24
25
  import { changedFiles, expectedScope, nxProjects, parseTitleScope } from '../infra/nx-scope.js';
@@ -27,7 +28,7 @@ import { outputDirectory, OutputPathReservationError, resolveRealPath, withReser
27
28
  import { readBaseRecord } from '../infra/state-store.js';
28
29
  import { readTemplateSections, templateFile } from '../infra/template-store.js';
29
30
  import { readTextFile } from '../infra/text-file.js';
30
- import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
31
+ import { commandHint, hinted, inputHint, inputNameHint, joinHinted, placeholder } from './command-hint.js';
31
32
  import { requireActiveConfigPlain, stopWith } from './command-stop.js';
32
33
  import { kindOfFailure } from './failure.js';
33
34
  import { directorySchema } from './directory-option.js';
@@ -390,11 +391,9 @@ export function stopOnMalformedRecord(reading, out) {
390
391
  if (reading.kind === 'malformed')
391
392
  stopWith(out, describeBaseStop({ kind: 'stop', reason: 'malformed', content: reading.content }).join('\n'), 'content-invalid');
392
393
  }
393
- // merge-base --is-ancestor は、祖先でなければ 1、コミットを知らなければ 128 を返す
394
- const NOT_ANCESTOR = 1;
395
394
  // 記録を使うのは、head が今のブランチで、release のテンプレートでないときだけ。形が誤っていれば終了コード 1 で止める。
396
- // 記録のコミットが head の履歴に無ければ、別のブランチの記録なので止める。開発ブランチ向けに作ると下の段の差分が入りうるため
397
- function readBaseRecordFor(head, template, directory, out) {
395
+ // 記録のコミットが head の履歴に無ければ、別のブランチの記録か、手で載せ直した後の古い記録なので止める。開発ブランチ向けに作ると下の段の差分が入りうるため
396
+ async function readBaseRecordFor(head, template, directory, target, out) {
398
397
  if (template === 'release' || head !== gitCurrentBranch(directory))
399
398
  return undefined;
400
399
  const reading = readBaseRecord();
@@ -402,10 +401,29 @@ function readBaseRecordFor(head, template, directory, out) {
402
401
  if (reading.kind !== 'stacked')
403
402
  return reading;
404
403
  const { branch, sha } = reading.record;
405
- const isForeign = runGit(['merge-base', '--is-ancestor', sha, head], { cwd: directory }).exitCode === NOT_ANCESTOR;
406
- return isForeign
407
- ? stopWith(out, hinted `.pecot-base records ${branch} at ${sha.slice(0, 7)}, which is not in the history of ${head}\nrun pr create on the branch the record was written for, or pass ${inputHint(PR_CREATE_PATH, 'head', head)} to create the PR without the record`, 'git-unresolved')
408
- : reading;
404
+ // 手元が知らないコミットは、履歴に無いと決められないので止めない
405
+ if (resolveCommit(directory, sha) === undefined || isAncestor(directory, sha, head))
406
+ return reading;
407
+ const isRestacked = await isRestackedLocally(reading, directory, target, out);
408
+ return stopWith(out, joinHinted([
409
+ `.pecot-base records ${branch} at ${sha.slice(0, 7)}, which is not in the history of ${head}`,
410
+ ...isRestacked ? [hinted `${head} is already restacked; rewrite the record with: ${commandHint(RESTACK_PATH)}`] : [],
411
+ hinted `run pr create on the branch the record was written for, or pass ${inputHint(PR_CREATE_PATH, 'head', head)} to create the PR without the record`,
412
+ ]), 'git-unresolved');
413
+ }
414
+ // pr restack と同じ判断で、載せ直し済み(rebased)か。下の段の PR か remote を読めなければ false
415
+ async function isRestackedLocally(reading, directory, target, out) {
416
+ const { config, location } = target;
417
+ const developBranch = getDevelopBranch(config, location.owner, location.repository) ?? '';
418
+ try {
419
+ const read = await readRestackDecision({ client: lazyClient(config, out), owner: location.owner, repository: location.repository, cwd: directory, remote: primaryRemoteName(directory), reading, developBranch });
420
+ return read.kind === 'decided' && read.decision.kind === 'rebased';
421
+ }
422
+ catch (error) {
423
+ if (error instanceof TransportFailure)
424
+ return false;
425
+ throw error;
426
+ }
409
427
  }
410
428
  // 積んだ記録なら、PR を作るリポで下の段の PR を読み、base を決める
411
429
  async function decideBase(input, client, developBranch, out) {
@@ -507,7 +525,7 @@ async function createFromFile(input, directory, out) {
507
525
  return stopWith(out, 'repository is required (e.g. owner/repo)', 'content-invalid');
508
526
  const location = requireRepository(frontmatter.repository, out);
509
527
  const head = resolveHeadBranch(frontmatter.head, directory, out);
510
- const reading = readBaseRecordFor(head, input.template, directory, out);
528
+ const reading = await readBaseRecordFor(head, input.template, directory, { config, location }, out);
511
529
  let body = parsed.body;
512
530
  const issueNumber = extractIssueNumberFromBranch(head);
513
531
  if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
@@ -542,7 +560,7 @@ async function createDirect(input, directory, out) {
542
560
  location = requireRepository(input.repository, out);
543
561
  }
544
562
  const head = resolveHeadBranch(input.head, directory, out);
545
- const reading = readBaseRecordFor(head, input.template, directory, out);
563
+ const reading = await readBaseRecordFor(head, input.template, directory, { config, location }, out);
546
564
  let body = input.message;
547
565
  const issueNumber = extractIssueNumberFromBranch(head);
548
566
  if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
@@ -11,4 +11,10 @@ export declare function resolveCurrentRepository(cwd: string): ResolvedRepositor
11
11
  止めるときは、stderr に行を書いて CommandExit(1) を投げる。warn の警告は stderr に書いて続ける
12
12
  */
13
13
  export declare function requireRepositoryMatch(mode: PolicyMode, explicit: string | undefined, io: Readonly<CommandIo>, cwd: string): RepositoryReference | undefined;
14
+ /**
15
+ 作業ディレクトリが remote を持つ git のリポジトリの中かだけを確かめる。remote の URL は読まない。
16
+ 削除の先を引数で決めるコマンド(branch delete)が、`--repo` を使わずに使う。
17
+ git の外・remote 無しなら、stderr に行を書いて CommandExit(1) を投げる
18
+ */
19
+ export declare function requireGitRemote(io: Readonly<CommandIo>, cwd: string): void;
14
20
  //# sourceMappingURL=repository-match.d.ts.map
@@ -1,9 +1,9 @@
1
1
  // グローバルの `--repo` と、今の git remote のリポジトリの食い違いを扱う(Python の `require_repo_match`)。
2
2
  // 判定は domain/repository-policy.ts の applyRepositoryPolicy に任せ、ここは git の解決と行の出力、止めるときの終了コードだけを行う。
3
3
  import { formatHinted } from '../domain/command-hint.js';
4
- import { applyRepositoryPolicy } from '../domain/repository-policy.js';
4
+ import { AMBIGUOUS_REPOSITORY_LINE, applyRepositoryPolicy } from '../domain/repository-policy.js';
5
5
  import { AmbiguousRepositoryError, resolveRepository } from '../domain/repository-resolver.js';
6
- import { gitRunnerFor } from '../infra/git.js';
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
  /**
@@ -26,14 +26,28 @@ export function resolveCurrentRepository(cwd) {
26
26
  */
27
27
  export function requireRepositoryMatch(mode, explicit, io, cwd) {
28
28
  const outcome = applyRepositoryPolicy({ explicit, resolved: resolveCurrentRepository(cwd), mode });
29
- for (const line of outcome.stderr) {
29
+ writeLines(io, outcome.stderr);
30
+ if (outcome.kind === 'exit')
31
+ throw new CommandExit(outcome.exitCode, outcome.failure);
32
+ return outcome.adopted;
33
+ }
34
+ /**
35
+ 作業ディレクトリが remote を持つ git のリポジトリの中かだけを確かめる。remote の URL は読まない。
36
+ 削除の先を引数で決めるコマンド(branch delete)が、`--repo` を使わずに使う。
37
+ git の外・remote 無しなら、stderr に行を書いて CommandExit(1) を投げる
38
+ */
39
+ export function requireGitRemote(io, cwd) {
40
+ if ((listRemotes(cwd) ?? []).length > 0)
41
+ return;
42
+ writeLines(io, [AMBIGUOUS_REPOSITORY_LINE, ' run inside a git repository that has a remote']);
43
+ throw new CommandExit(1, 'git-unresolved');
44
+ }
45
+ function writeLines(io, lines) {
46
+ for (const line of lines) {
30
47
  const text = formatHinted(line, io.surface ?? 'cli');
31
48
  io.stderr(`${text}\n`);
32
49
  if (text.startsWith(WARNING_PREFIX))
33
50
  io.warning?.(text.slice(WARNING_PREFIX.length));
34
51
  }
35
- if (outcome.kind === 'exit')
36
- throw new CommandExit(outcome.exitCode, outcome.failure);
37
- return outcome.adopted;
38
52
  }
39
53
  //# sourceMappingURL=repository-match.js.map
@@ -1,6 +1,6 @@
1
1
  import { pickLowerPullRequest } from '../domain/pull-request.js';
2
2
  import { decideRestack } from '../domain/restack.js';
3
- import { remoteBranchHead } from '../infra/git.js';
3
+ import { isAncestor, remoteBranchHead, resolveCommit } from '../infra/git.js';
4
4
  import { GitHubAPIError } from '../infra/github/errors.js';
5
5
  /**
6
6
  下の段の PR を読み、remote の先頭を尋ねて、載せ直す先を決める。PR を読めないか remote に届かなければ、その種類を返す
@@ -22,8 +22,22 @@ export async function readRestackDecision(target) {
22
22
  if (remote === undefined)
23
23
  return { kind: 'remote-unreachable', lowerPullRequest };
24
24
  const lowerHead = remoteBranchHead(target.cwd, remote, reading.record.branch);
25
- return lowerHead.isReachable
26
- ? { kind: 'decided', decision: decideRestack({ reading, developBranch: target.developBranch, lowerPullRequest, lowerHead: lowerHead.sha }), lowerPullRequest }
27
- : { kind: 'remote-unreachable', lowerPullRequest };
25
+ if (!lowerHead.isReachable)
26
+ return { kind: 'remote-unreachable', lowerPullRequest };
27
+ const decision = decideRestack({ reading, developBranch: target.developBranch, lowerPullRequest, lowerHead: lowerHead.sha });
28
+ return { kind: 'decided', decision: withRebased(target.cwd, remote, reading, decision, lowerHead.sha), lowerPullRequest };
29
+ }
30
+ // 新しい base の上に載り終えていれば rebased に替える。記録の位置が HEAD にあれば、それが新しい base の祖先であることも求める。
31
+ // merge で base を取り込んだブランチと、下の段が古い位置へ戻されたブランチを、載せ直し済みと見ないため
32
+ function withRebased(cwd, remote, reading, decision, lowerHead) {
33
+ if (decision.kind !== 'moved' && decision.kind !== 'merged')
34
+ return decision;
35
+ // moved は ls-remote の先頭を使う。fetch しない呼び出し元では、追跡参照が古い位置を指しうるため
36
+ const newBase = decision.kind === 'moved' ? lowerHead : resolveCommit(cwd, `${remote}/${decision.base}`);
37
+ if (newBase === undefined || !isAncestor(cwd, newBase, 'HEAD'))
38
+ return decision;
39
+ const { sha } = reading.record;
40
+ const isRecordLeftBehind = isAncestor(cwd, sha, 'HEAD') && !isAncestor(cwd, sha, newBase);
41
+ return isRecordLeftBehind ? decision : { kind: 'rebased', base: decision.base };
28
42
  }
29
43
  //# sourceMappingURL=restack-reading.js.map
@@ -9,7 +9,7 @@ import { extractClosingIssueNumbers } from '../domain/pull-request.js';
9
9
  import { assumePullRequestState, describeReadinessChange, displayReference, hasReadinessChanged, isDone, isStackedOn } from '../domain/readiness.js';
10
10
  import { createIssueReference } from '../domain/reference-parser.js';
11
11
  import { RESTACK_PATH } from '../domain/restack.js';
12
- import { FLAG_PECOT_BASE, FLAG_PECOT_QUICK_MODE, FLAG_PECOT_SESSION_TITLE } from '../domain/state.js';
12
+ import { FLAG_PECOT_BASE, FLAG_PECOT_SESSION_TITLE } from '../domain/state.js';
13
13
  import { gitCurrentBranch, GitCommandError, runGit } from '../infra/git.js';
14
14
  import { GitHubAPIError, GitHubNotFoundError, isClosedByAnotherRequest, isMissingReferenceError } from '../infra/github/errors.js';
15
15
  import { isFileNotFound } from '../infra/os-error.js';
@@ -303,7 +303,7 @@ function localCleanupAfterMerge(context, headBranch, config, location) {
303
303
  }
304
304
  function removeActiveFlags(out) {
305
305
  try {
306
- for (const flag of [FLAG_PECOT_BASE, FLAG_PECOT_SESSION_TITLE, FLAG_PECOT_QUICK_MODE])
306
+ for (const flag of [FLAG_PECOT_BASE, FLAG_PECOT_SESSION_TITLE])
307
307
  removeFlag(flag);
308
308
  }
309
309
  catch (error) {
@@ -1,6 +1,6 @@
1
1
  // session show。cli/commands/session.py の移植。
2
2
  import { z } from 'zod';
3
- import { ConfigError } from '../domain/config.js';
3
+ import { ConfigError, getDevelopBranch } from '../domain/config.js';
4
4
  import { describeReadiness } from '../domain/readiness.js';
5
5
  import { describeNeedsRestack, needsRestack } from '../domain/restack.js';
6
6
  import { issueReferenceToCliReference, issueReferenceToString } from '../domain/reference-parser.js';
@@ -104,7 +104,7 @@ async function stackSection(active, origin, directory, output) {
104
104
  // ブランチは作業ディレクトリのリポにあるので、PR もそこで探す(pr restack と同じ)
105
105
  const { owner, repository } = origin ?? stackedOn.repository;
106
106
  // 載せ直す先は、fetch せずに、下の段の remote の先頭を尋ねて記録と比べる
107
- const read = await readRestackDecision({ client: () => active.client, owner, repository, cwd: directory, remote: primaryRemoteName(directory), reading, developBranch: '' });
107
+ const read = await readRestackDecision({ client: () => active.client, owner, repository, cwd: directory, remote: primaryRemoteName(directory), reading, developBranch: getDevelopBranch(active.config, owner, repository) ?? '' });
108
108
  if (read.kind === 'pull-request-unreadable')
109
109
  output.warning(`cannot read the PR of the base branch: ${read.error.message}`);
110
110
  const pullRequest = read.kind === 'pull-request-unreadable' ? 'unknown' : read.lowerPullRequest;
@@ -194,7 +194,8 @@ diverged の直し方。fast-forward でない push は拒まれるので、取
194
194
  */
195
195
  export declare const DIVERGED_FIX_HINT: HintedText;
196
196
  /**
197
- 積んだブランチが diverged のときの直し方。載せ直しが要れば pr restack、要らなければ diverged の直し方、決められなければ pr restack --check
197
+ 積んだブランチが diverged のときの直し方。載せ直しが要るか、載せ直し済みで push と記録の書き直しが残れば pr restack、
198
+ 要らなければ diverged の直し方、決められなければ pr restack --check
198
199
  */
199
200
  export declare function pushFixHintOf(decision: Readonly<RestackDecision> | undefined): HintedText;
200
201
  export interface PreflightFacts {
@@ -266,12 +266,13 @@ diverged の直し方。fast-forward でない push は拒まれるので、取
266
266
  */
267
267
  export const DIVERGED_FIX_HINT = hinted `${PULL_REBASE_COMMAND}, or ${FORCE_PUSH_COMMAND} if you rewrote pushed commits`;
268
268
  /**
269
- 積んだブランチが diverged のときの直し方。載せ直しが要れば pr restack、要らなければ diverged の直し方、決められなければ pr restack --check
269
+ 積んだブランチが diverged のときの直し方。載せ直しが要るか、載せ直し済みで push と記録の書き直しが残れば pr restack、
270
+ 要らなければ diverged の直し方、決められなければ pr restack --check
270
271
  */
271
272
  export function pushFixHintOf(decision) {
272
273
  if (decision === undefined || decision.kind === 'gone')
273
274
  return hinted `${commandHint(RESTACK_PATH, { check: true })}`;
274
- return decision.kind === 'moved' || decision.kind === 'merged' ? hinted `${commandHint(RESTACK_PATH)}` : DIVERGED_FIX_HINT;
275
+ return decision.kind === 'moved' || decision.kind === 'merged' || decision.kind === 'rebased' ? hinted `${commandHint(RESTACK_PATH)}` : DIVERGED_FIX_HINT;
275
276
  }
276
277
  /**
277
278
  警告を、未 push・変更あり・stash ありの順で返す
@@ -1,6 +1,10 @@
1
1
  import type { HintedText } from './command-hint.js';
2
2
  import type { RepositoryReference, ResolvedRepository } from './repository-resolver.js';
3
3
  export type PolicyMode = 'reject' | 'warn';
4
+ /**
5
+ 今の git remote からリポジトリを決められないときの 1 行目。branch delete の remote の確認も同じ行を出す
6
+ */
7
+ export declare const AMBIGUOUS_REPOSITORY_LINE = "error: the repository is ambiguous";
4
8
  export interface PolicyInput {
5
9
  /**
6
10
  グローバル `--repo` の値。無ければ undefined
@@ -19,6 +19,10 @@ import { globalRepositoryHint, hinted, placeholder } from './command-hint.js';
19
19
  import { InvalidValueError } from './errors.js';
20
20
  import { pythonStringRepr } from './python-format.js';
21
21
  import { parseOwnerRepository, repositoryFullName } from './repository-resolver.js';
22
+ /**
23
+ 今の git remote からリポジトリを決められないときの 1 行目。branch delete の remote の確認も同じ行を出す
24
+ */
25
+ export const AMBIGUOUS_REPOSITORY_LINE = 'error: the repository is ambiguous';
22
26
  function exitWith(failure, ...stderr) {
23
27
  return { kind: 'exit', exitCode: 1, failure, stderr };
24
28
  }
@@ -39,7 +43,7 @@ export function applyRepositoryPolicy(input) {
39
43
  const { explicit, resolved, mode } = input;
40
44
  if (explicit === undefined) {
41
45
  return resolved === undefined
42
- ? exitWith('git-unresolved', 'error: the repository is ambiguous', hinted ` give ${globalRepositoryHint(placeholder('owner/repo'))}`)
46
+ ? exitWith('git-unresolved', AMBIGUOUS_REPOSITORY_LINE, hinted ` give ${globalRepositoryHint(placeholder('owner/repo'))}`)
43
47
  : { kind: 'proceed', adopted: undefined, stderr: [] };
44
48
  }
45
49
  const explicitReference = parseExplicit(explicit);
@@ -38,6 +38,13 @@ export type RestackDecision = {
38
38
  readonly kind: 'gone';
39
39
  readonly base: string;
40
40
  readonly pullRequest: number | undefined;
41
+ }
42
+ /**
43
+ ブランチは新しい base の上に載り終えていて、記録だけが古い。rebase は要らず、push と記録の書き直しだけが残る
44
+ */
45
+ | {
46
+ readonly kind: 'rebased';
47
+ readonly base: string;
41
48
  };
42
49
  /**
43
50
  載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
@@ -23,7 +23,8 @@ export function decideRestack(input) {
23
23
  export function describeRestackCheck(branch, decision) {
24
24
  switch (decision.kind) {
25
25
  case 'not-stacked':
26
- case 'up-to-date': {
26
+ case 'up-to-date':
27
+ case 'rebased': {
27
28
  return `up to date: ${branch} on ${decision.base}`;
28
29
  }
29
30
  case 'moved': {
@@ -2,7 +2,6 @@ import type { IssueReference } from './reference-parser.js';
2
2
  export declare const FLAG_PECOT_SESSION_TITLE = ".pecot-session-title";
3
3
  export declare const FLAG_PECOT_BASE = ".pecot-base";
4
4
  export declare const FLAG_PECOT_RESTACK = ".pecot-restack";
5
- export declare const FLAG_PECOT_QUICK_MODE = ".pecot-quick-mode";
6
5
  export declare const SESSION_TITLE_MAX_CHARS = 40;
7
6
  /**
8
7
  セッション名 `#<番号> <Issue タイトル>` を組み立てる。
@@ -10,7 +10,6 @@ export const FLAG_PECOT_SESSION_TITLE = '.pecot-session-title';
10
10
  export const FLAG_PECOT_BASE = '.pecot-base';
11
11
  // 衝突で止まった載せ直しの途中の記録。pr restack が書き、続行か取りやめで消す
12
12
  export const FLAG_PECOT_RESTACK = '.pecot-restack';
13
- export const FLAG_PECOT_QUICK_MODE = '.pecot-quick-mode';
14
13
  export const SESSION_TITLE_MAX_CHARS = 40;
15
14
  const ISSUE_TYPE_PREFIX_PATTERN = /^\[(?:Task|Bug|Epic)\]\s*/u;
16
15
  /**
@@ -113,6 +113,14 @@ export declare function resolveCommit(cwd: string, reference: string): string |
113
113
  */
114
114
  export declare function mergeBase(cwd: string, a: string, b: string): string | undefined;
115
115
  /**
116
+ ancestor が descendant の祖先(同じコミットを含む)か。どちらかのコミットを手元が知らなければ false
117
+ */
118
+ export declare function isAncestor(cwd: string, ancestor: string, descendant: string): boolean;
119
+ /**
120
+ `git merge-base --fork-point <upstream> <head>`。upstream の reflog から、head が分かれた点を求める。求まらなければ undefined
121
+ */
122
+ export declare function forkPoint(cwd: string, upstream: string, head: string): string | undefined;
123
+ /**
116
124
  `git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
117
125
  */
118
126
  export declare function rebaseOnto(cwd: string, newBase: string, oldBase: string): RebaseOutcome;
@@ -175,6 +175,18 @@ export function resolveCommit(cwd, reference) {
175
175
  export function mergeBase(cwd, a, b) {
176
176
  return runForValue(['merge-base', a, b], { cwd });
177
177
  }
178
+ /**
179
+ ancestor が descendant の祖先(同じコミットを含む)か。どちらかのコミットを手元が知らなければ false
180
+ */
181
+ export function isAncestor(cwd, ancestor, descendant) {
182
+ return runGit(['merge-base', '--is-ancestor', ancestor, descendant], { cwd }).exitCode === 0;
183
+ }
184
+ /**
185
+ `git merge-base --fork-point <upstream> <head>`。upstream の reflog から、head が分かれた点を求める。求まらなければ undefined
186
+ */
187
+ export function forkPoint(cwd, upstream, head) {
188
+ return runForValue(['merge-base', '--fork-point', upstream, head], { cwd });
189
+ }
178
190
  // 失敗の後に rebase の途中なら衝突、ほかの失敗は GitCommandError
179
191
  function rebaseOutcome(cwd, arguments_, environment) {
180
192
  const result = runGit(arguments_, { cwd, env: environment });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "7.0.1-dev.19",
3
+ "version": "7.0.1-dev.21",
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.19",
9
+ "version": "7.0.1-dev.21",
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.19",
3
+ "version": "7.0.1-dev.21",
4
4
  "type": "module",
5
5
  "description": "pecot-workflow MCP server (standalone distribution)",
6
6
  "license": "MIT",