@pecot/workflow-mcp 8.0.1-dev.67 → 8.0.1-dev.68

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": "8.0.1-dev.67",
3
+ "version": "8.0.1-dev.68",
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"
@@ -13,7 +13,7 @@ import { FrontmatterError } from '../domain/frontmatter.js';
13
13
  import { parseRemoteUrl } from '../domain/git-url.js';
14
14
  import { isEpicIssue } from '../domain/issue-kind.js';
15
15
  import { jsonField } from '../domain/json.js';
16
- import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBase, describeBaseStop, describePushStatus, DIVERGED_FIX_HINT, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, pickLowerPullRequest, pushFixHintOf, validatePullRequestContent } from '../domain/pull-request.js';
16
+ import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBase, describeBaseStop, describePushStatus, DIVERGED_FIX_HINT, forkPushFixHint, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, parseHeadReference, 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
19
  import { RESTACK_PATH } from '../domain/restack.js';
@@ -30,7 +30,7 @@ import { readBaseOrInfer, warnUnresolved } from './base-reading.js';
30
30
  import { readTextFile } from '../infra/text-file.js';
31
31
  import { commandHint, hinted, inputHint, inputNameHint, joinHinted, placeholder } from './command-hint.js';
32
32
  import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
33
- import { findConfigForRemotes } from '../infra/remote-config.js';
33
+ import { findConfigForRemotes, readRemoteLocations } from '../infra/remote-config.js';
34
34
  import { kindOfFailure } from './failure.js';
35
35
  import { directorySchema } from './directory-option.js';
36
36
  import { createGitHubClient } from './github-client.js';
@@ -117,7 +117,7 @@ async function titleScopeErrors(query, out) {
117
117
  const target = nxScopeTarget(config, owner, repository, base, directory, query.stacked);
118
118
  if (target === undefined)
119
119
  return [];
120
- const expected = await expectedTitleScope(target, head, out);
120
+ const expected = await expectedTitleScope(target, query.headBranch, out);
121
121
  if (expected === undefined || expected.length === 0)
122
122
  return [];
123
123
  const given = parseTitleScope(title);
@@ -130,7 +130,7 @@ async function titleScopeErrors(query, out) {
130
130
  const PR_CREATE_OUTPUT = z.strictObject({
131
131
  url: z.string().optional().describe('URL of the created PR (omitted on dry_run and prepare)'),
132
132
  number: z.int().optional().describe('Number of the created PR (omitted on dry_run and prepare, or when the response has none)'),
133
- head: z.string().optional().describe('Head branch of the PR (omitted on prepare)'),
133
+ head: z.string().optional().describe('Head branch of the PR, owner:branch for a branch of a fork (omitted on prepare)'),
134
134
  base: z.string().optional().describe('Base branch of the PR. On prepare, the base filled into the draft (omitted when it was not filled)'),
135
135
  title: z.string().optional().describe('Title of the PR (omitted on prepare)'),
136
136
  inReview: z.int().optional().describe('Issue number whose status was set to In Review (omitted when not set)'),
@@ -202,6 +202,9 @@ function resolveHeadBranch(head, directory, out) {
202
202
  const current = gitCurrentBranch(directory);
203
203
  return current === undefined || current === '' ? stopWith(out, 'cannot determine the head branch', 'git-unresolved') : current;
204
204
  }
205
+ function requireHeadReference(head, out) {
206
+ return parseHeadReference(head) ?? stopWith(out, `invalid head: ${head} (expected: branch or owner:branch)`, 'invalid-input');
207
+ }
205
208
  async function appendCloseUnlessEpic(config, location, body, issueNumber, out) {
206
209
  try {
207
210
  const kind = await createGitHubClient(out, config.host).getIssueKind(location.owner, location.repository, issueNumber);
@@ -290,10 +293,41 @@ async function pushFixHintFor(push, reading, target) {
290
293
  throw error;
291
294
  }
292
295
  }
293
- async function runPreflightChecksOrExit(directory, base, config, client, out) {
296
+ function isSameName(left, right) {
297
+ return left.toLowerCase() === right.toLowerCase();
298
+ }
299
+ // owner のある head は、host と owner の合う remote。owner が作り先と同じなら、作り先そのものを指す remote だけ(同じ org の fork は head_repo が要るので扱わない)
300
+ function pushRemoteFor(head, target, host, directory, primary) {
301
+ const { owner } = head;
302
+ if (owner === undefined)
303
+ return primary;
304
+ const isTargetOwner = isSameName(owner, target.owner);
305
+ return readRemoteLocations(directory).find(({ location }) => isSameName(location.host, host) && isSameName(location.owner, owner) && (!isTargetOwner || isSameName(location.repository, target.repository)))?.remote;
306
+ }
307
+ function hasLocalBranch(directory, branch) {
308
+ return gitStdout(['rev-parse', '--verify', '--quiet', `refs/heads/${branch}`], { cwd: directory }) !== undefined;
309
+ }
310
+ async function checkHeadPush(draft, context, input) {
311
+ const { directory, base, config, client, out } = input;
312
+ const head = draft.headReference;
313
+ const remote = pushRemoteFor(head, draft.location, config.host, directory, context.remoteName);
314
+ if (remote === undefined) {
315
+ const owner = head.owner ?? '';
316
+ return { push: { isPushed: false, message: `no git remote points to a repository of ${owner} on ${config.host}`, isDiverged: false }, fixHint: hinted `git remote add fork https://${config.host}/${owner}/${draft.location.repository}.git` };
317
+ }
318
+ if (!hasLocalBranch(directory, head.branch)) {
319
+ return { push: { isPushed: false, message: `local branch ${head.branch} does not exist`, isDiverged: false }, fixHint: hinted `git fetch ${remote} ${head.branch}:${head.branch}` };
320
+ }
321
+ const push = getPushStatus(head.branch, directory, remote);
322
+ if (push.isPushed)
323
+ return { push, fixHint: undefined };
324
+ if (head.owner !== undefined)
325
+ return { push, fixHint: forkPushFixHint(remote, head.branch, push.isDiverged) };
326
+ return { push, fixHint: await pushFixHintFor(push, base.reading, { config, location: context.location, directory, remote, client, lowerPullRequest: base.lowerPullRequest, signal: out.signal }) };
327
+ }
328
+ async function runPreflightChecksOrExit(directory, draft, base, config, client, out) {
294
329
  const context = validatePullRequestContext(directory, out);
295
- const push = getPushStatus(context.currentBranch, directory, context.remoteName);
296
- const pushFixHint = await pushFixHintFor(push, base.reading, { config, location: context.location, directory, remote: context.remoteName, client, lowerPullRequest: base.lowerPullRequest, signal: out.signal });
330
+ const { push, fixHint: pushFixHint } = await checkHeadPush(draft, context, { directory, base, config, client, out });
297
331
  const warnings = collectPreflightWarnings({ gitStatus: getGitStatus(directory), stashList: getStashList(directory), isPushed: push.isPushed, pushMessage: push.message, pushFixHint });
298
332
  if (warnings.length === 0)
299
333
  return;
@@ -356,7 +390,7 @@ async function moveWaitingIssuesSafely(client, config, location, issueNumber, pu
356
390
  }
357
391
  }
358
392
  async function submitPullRequest(config, client, directory, draft, stackOn, base, out) {
359
- await runPreflightChecksOrExit(directory, base, config, client, out);
393
+ await runPreflightChecksOrExit(directory, draft, base, config, client, out);
360
394
  let created;
361
395
  try {
362
396
  created = await client().createPullRequest(draft.location.owner, draft.location.repository, draft.title, draft.body, draft.head, draft.base, draft.isDraft);
@@ -374,12 +408,12 @@ async function submitPullRequest(config, client, directory, draft, stackOn, base
374
408
  out.result({ head: draft.head, base: draft.base, title: draft.title, ...pullRequest !== undefined && { number: pullRequest }, ...typeof url === 'string' && { url } });
375
409
  // in_review と待ちの Issue の書き込みで、選択肢の ID を読み直す案内を 1 回だけ出す
376
410
  const fieldHint = { hasHinted: false };
377
- const inReview = draft.isRelease ? undefined : await updateIssueStatusToInReview(config, client(), draft.location, draft.head, out, fieldHint);
411
+ const inReview = draft.isRelease ? undefined : await updateIssueStatusToInReview(config, client(), draft.location, draft.headReference.branch, out, fieldHint);
378
412
  if (inReview !== undefined)
379
413
  out.result({ inReview });
380
414
  if (stackOn !== undefined)
381
415
  out.result({ stack: await registerStack(client(), draft.location, stackOn, pullRequest, out) });
382
- const issueNumber = extractIssueNumberFromBranch(draft.head);
416
+ const issueNumber = extractIssueNumberFromBranch(draft.headReference.branch);
383
417
  const moves = [];
384
418
  try {
385
419
  if (!draft.isRelease && isPositive(issueNumber))
@@ -480,7 +514,7 @@ function stackedScopeOf(reading, use) {
480
514
  }
481
515
  // 検証して、dry-run なら計画を出し、そうでなければ投稿する。file と -m の両方がここを通る
482
516
  async function validateAndSubmit(input, out) {
483
- const { config, directory, template, location, title, head } = input;
517
+ const { config, directory, template, location, title, head, headReference } = input;
484
518
  const client = lazyClient(config, out);
485
519
  const developBranch = getDevelopBranch(config, location.owner, location.repository);
486
520
  const releaseBranch = getReleaseBranch(config, location.owner, location.repository);
@@ -504,17 +538,17 @@ async function validateAndSubmit(input, out) {
504
538
  stackedBase: use?.stackedBase,
505
539
  }),
506
540
  ...baseErrors,
507
- ...await titleScopeErrors({ config, owner: location.owner, repository: location.repository, title, base, head, directory, template, developBranch, releaseBranch, stacked }, out),
541
+ ...await titleScopeErrors({ config, owner: location.owner, repository: location.repository, title, base, head, headBranch: headReference.branch, directory, template, developBranch, releaseBranch, stacked }, out),
508
542
  ];
509
543
  exitOnValidationErrors(errors, out);
510
544
  const isRelease = template === 'release';
511
- const draft = { location, title, body: input.body, head, base, isDraft: input.isDraft, isRelease };
545
+ const draft = { location, title, body: input.body, head, headReference, base, isDraft: input.isDraft, isRelease };
512
546
  if (!input.dryRun) {
513
547
  await submitPullRequest(config, client, directory, draft, use?.stackOn, { reading: input.reading, lowerPullRequest: decided.lowerPullRequest }, out);
514
548
  return;
515
549
  }
516
550
  out.planned(createOperation(draft));
517
- const issueNumber = extractIssueNumberFromBranch(head);
551
+ const issueNumber = extractIssueNumberFromBranch(headReference.branch);
518
552
  if (!isRelease && issueNumber !== undefined)
519
553
  out.planned(inReviewOperation(issueNumber));
520
554
  if (use?.stackOn !== undefined)
@@ -540,9 +574,10 @@ async function createFromFile(input, directory, out) {
540
574
  const location = requireRepository(frontmatter.repository, out);
541
575
  const config = requireConfigFor(out, location, input.project, PR_CREATE_PATH).config;
542
576
  const head = resolveHeadBranch(frontmatter.head, directory, out);
577
+ const headReference = requireHeadReference(head, out);
543
578
  const reading = await readBaseRecordFor(head, input, directory, { config, location }, out);
544
579
  let body = parsed.body;
545
- const issueNumber = extractIssueNumberFromBranch(head);
580
+ const issueNumber = extractIssueNumberFromBranch(headReference.branch);
546
581
  if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
547
582
  body = await appendCloseUnlessEpic(config, location, body, issueNumber, out);
548
583
  }
@@ -556,6 +591,7 @@ async function createFromFile(input, directory, out) {
556
591
  title: frontmatter.title,
557
592
  base: frontmatter.base,
558
593
  head,
594
+ headReference,
559
595
  isDraft: frontmatter.draft,
560
596
  body,
561
597
  screenshot: frontmatter.screenshot,
@@ -579,9 +615,10 @@ function directTarget(input, directory, out) {
579
615
  async function createDirect(input, directory, out) {
580
616
  const { location, config } = directTarget(input, directory, out);
581
617
  const head = resolveHeadBranch(input.head, directory, out);
618
+ const headReference = requireHeadReference(head, out);
582
619
  const reading = await readBaseRecordFor(head, input, directory, { config, location }, out);
583
620
  let body = input.message;
584
- const issueNumber = extractIssueNumberFromBranch(head);
621
+ const issueNumber = extractIssueNumberFromBranch(headReference.branch);
585
622
  if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
586
623
  body = appendIssueCloseIfNeeded(body, issueNumber);
587
624
  }
@@ -595,6 +632,7 @@ async function createDirect(input, directory, out) {
595
632
  title: input.title,
596
633
  base: input.base,
597
634
  head,
635
+ headReference,
598
636
  isDraft: input.isDraft,
599
637
  body,
600
638
  screenshot: input.screenshot,
@@ -696,7 +734,7 @@ const CreateInputSchema = z.strictObject({
696
734
  message: z.string().optional().describe('PR body, given directly'),
697
735
  title: z.string().optional().describe('PR title (required with -m)'),
698
736
  base: z.string().optional().describe('Base branch (required with -m)'),
699
- head: z.string().optional().describe('Head branch (default: the current branch)'),
737
+ head: z.string().optional().describe('Head branch, or owner:branch for a branch of a fork (default: the current branch)'),
700
738
  draft: z.boolean().default(false).describe('Create as a draft PR'),
701
739
  prepare: z.boolean().default(false).describe('Copy the template to the work directory'),
702
740
  dry_run: z.boolean().default(false).describe('Validate only (skip the early preflight check, do not create the PR)'),
@@ -197,6 +197,25 @@ diverged の直し方。fast-forward でない push は拒まれるので、取
197
197
  */
198
198
  export declare const DIVERGED_FIX_HINT: HintedText;
199
199
  /**
200
+ PR の head。`owner:branch` は、同じネットワークの別のリポ(fork)のブランチ(GitHub の Pulls API の head の形)
201
+ */
202
+ export interface HeadReference {
203
+ /**
204
+ fork の owner。`:` の無い head では undefined
205
+ */
206
+ readonly owner: string | undefined;
207
+ readonly branch: string;
208
+ }
209
+ /**
210
+ head を owner とブランチ名に分ける。git のブランチ名に `:` は使えないので、最初の `:` で分ける。
211
+ owner かブランチ名が空なら undefined
212
+ */
213
+ export declare function parseHeadReference(head: string): HeadReference | undefined;
214
+ /**
215
+ fork のブランチの push の直し方。上流の無いブランチでも fork へ向くよう、remote とブランチ名を明示する
216
+ */
217
+ export declare function forkPushFixHint(remote: string, branch: string, isDiverged: boolean): HintedText;
218
+ /**
200
219
  積んだブランチが diverged のときの直し方。載せ直しが要るか、載せ直し済みで push と記録の書き直しが残れば pr restack、
201
220
  要らなければ diverged の直し方、決められなければ pr restack --check
202
221
  */
@@ -266,6 +266,26 @@ 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
+ head を owner とブランチ名に分ける。git のブランチ名に `:` は使えないので、最初の `:` で分ける。
270
+ owner かブランチ名が空なら undefined
271
+ */
272
+ export function parseHeadReference(head) {
273
+ const index = head.indexOf(':');
274
+ if (index === -1)
275
+ return head === '' ? undefined : { owner: undefined, branch: head };
276
+ const owner = head.slice(0, index);
277
+ const branch = head.slice(index + 1);
278
+ return owner === '' || branch === '' ? undefined : { owner, branch };
279
+ }
280
+ /**
281
+ fork のブランチの push の直し方。上流の無いブランチでも fork へ向くよう、remote とブランチ名を明示する
282
+ */
283
+ export function forkPushFixHint(remote, branch, isDiverged) {
284
+ return isDiverged
285
+ ? hinted `${PULL_REBASE_COMMAND} ${remote} ${branch}, or ${FORCE_PUSH_COMMAND} ${remote} ${branch} if you rewrote pushed commits`
286
+ : hinted `git push ${remote} ${branch}`;
287
+ }
288
+ /**
269
289
  積んだブランチが diverged のときの直し方。載せ直しが要るか、載せ直し済みで push と記録の書き直しが残れば pr restack、
270
290
  要らなければ diverged の直し方、決められなければ pr restack --check
271
291
  */
@@ -1,3 +1,4 @@
1
+ import type { RemoteLocation } from '../domain/git-url.js';
1
2
  import type { RepositoryReference } from '../domain/repository-resolver.js';
2
3
  import type { ConfigLookup, FoundConfig } from './config-store.js';
3
4
  export type RemoteConfigLookup = {
@@ -15,6 +16,13 @@ export type RemoteConfigLookup = {
15
16
  }>;
16
17
  };
17
18
  /**
19
+ URL を読める remote と、その host・owner・repository。origin を先に、残りを git remote の順に並べる
20
+ */
21
+ export declare function readRemoteLocations(cwd: string): readonly {
22
+ readonly remote: string;
23
+ readonly location: RemoteLocation;
24
+ }[];
25
+ /**
18
26
  remote のリポのうち、設定を選べた最初のもの。名前の誤りと、候補から選べないときは、ほかの remote を見ずに返す。
19
27
  どの remote でも選べなければ、最初の remote のリポと、そのときの結果を返す
20
28
  */
@@ -1,4 +1,3 @@
1
- // git の remote のリポから、プロジェクトの設定を選ぶ。origin を先に、残りの remote を git remote の順に当てる
2
1
  import { ValidationFailure } from '../domain/python-format.js';
3
2
  import { createRepositoryReference } from '../domain/repository-resolver.js';
4
3
  import { findConfigFor } from './config-store.js';
@@ -17,11 +16,25 @@ function repositoryOf(cwd, remote) {
17
16
  throw error;
18
17
  }
19
18
  }
20
- function readRemoteRepositories(cwd) {
19
+ function orderedRemotes(cwd) {
21
20
  const remotes = listRemotes(cwd) ?? [];
22
- const ordered = remotes.includes('origin') ? ['origin', ...remotes.filter(remote => remote !== 'origin')] : remotes;
21
+ return remotes.includes('origin') ? ['origin', ...remotes.filter(remote => remote !== 'origin')] : remotes;
22
+ }
23
+ /**
24
+ URL を読める remote と、その host・owner・repository。origin を先に、残りを git remote の順に並べる
25
+ */
26
+ export function readRemoteLocations(cwd) {
27
+ const read = [];
28
+ for (const remote of orderedRemotes(cwd)) {
29
+ const location = remoteRepository(cwd, remote);
30
+ if (location !== undefined)
31
+ read.push({ remote, location });
32
+ }
33
+ return read;
34
+ }
35
+ function readRemoteRepositories(cwd) {
23
36
  const read = [];
24
- for (const remote of ordered) {
37
+ for (const remote of orderedRemotes(cwd)) {
25
38
  const repository = repositoryOf(cwd, remote);
26
39
  if (repository !== undefined)
27
40
  read.push({ remote, repository });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "8.0.1-dev.67",
3
+ "version": "8.0.1-dev.68",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@pecot/workflow-mcp",
9
- "version": "8.0.1-dev.67",
9
+ "version": "8.0.1-dev.68",
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": "8.0.1-dev.67",
3
+ "version": "8.0.1-dev.68",
4
4
  "type": "module",
5
5
  "description": "pecot-workflow MCP server (standalone distribution)",
6
6
  "license": "MIT",