@pecot/workflow-mcp 8.0.1-dev.51 → 8.0.1-dev.52

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 (39) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/cli/dist/commands/board-add.js +5 -4
  3. package/cli/dist/commands/board-move.js +4 -3
  4. package/cli/dist/commands/board-sync.js +2 -26
  5. package/cli/dist/commands/branch.js +3 -2
  6. package/cli/dist/commands/command-stop.d.ts +13 -2
  7. package/cli/dist/commands/command-stop.js +31 -8
  8. package/cli/dist/commands/field-write-failure.d.ts +2 -1
  9. package/cli/dist/commands/field-write-failure.js +7 -11
  10. package/cli/dist/commands/issue-board.js +2 -2
  11. package/cli/dist/commands/issue-comment.js +8 -5
  12. package/cli/dist/commands/issue-create.js +49 -11
  13. package/cli/dist/commands/issue-dependency.js +7 -4
  14. package/cli/dist/commands/issue-reopen.js +4 -3
  15. package/cli/dist/commands/issue-shared.js +1 -1
  16. package/cli/dist/commands/issue-show.js +3 -2
  17. package/cli/dist/commands/pr-merge.js +3 -2
  18. package/cli/dist/commands/pr-restack.js +3 -2
  19. package/cli/dist/commands/pr.js +38 -24
  20. package/cli/dist/commands/release.js +11 -8
  21. package/cli/dist/commands/session-finish.js +3 -2
  22. package/cli/dist/commands/session-start.js +5 -4
  23. package/cli/dist/commands/session.js +10 -7
  24. package/cli/dist/commands/tracker-sync-dependabot.js +1 -1
  25. package/cli/dist/commands/tracker-sync-security.js +1 -1
  26. package/cli/dist/commands/tracker-sync.d.ts +3 -3
  27. package/cli/dist/commands/tracker-sync.js +4 -5
  28. package/cli/dist/commands/tracker.js +2 -0
  29. package/cli/dist/commands/worktree.js +4 -2
  30. package/cli/dist/domain/config.d.ts +0 -8
  31. package/cli/dist/domain/config.js +1 -15
  32. package/cli/dist/infra/config-store.d.ts +62 -15
  33. package/cli/dist/infra/config-store.js +99 -38
  34. package/cli/dist/infra/remote-config.d.ts +22 -0
  35. package/cli/dist/infra/remote-config.js +48 -0
  36. package/cli/dist/infra/worktree.d.ts +5 -1
  37. package/cli/dist/infra/worktree.js +16 -53
  38. package/npm-shrinkwrap.json +2 -2
  39. package/package.json +1 -1
@@ -6,7 +6,7 @@ import { createIssueReference, issueReferenceKey } from '../domain/reference-par
6
6
  import { createRepositoryReference, repositoryFullName } from '../domain/repository-resolver.js';
7
7
  import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
8
8
  import { defineCommand } from './command-definition.js';
9
- import { stopWith, requireActiveConfigPlain } from './command-stop.js';
9
+ import { stopWith, requireConfigFor, PROJECT_INPUT } from './command-stop.js';
10
10
  import { kindOfFailure } from './failure.js';
11
11
  import { createGitHubClient } from './github-client.js';
12
12
  import { ISSUE_REF_DESCRIPTION, issuePath, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
@@ -206,6 +206,7 @@ const ISSUE_SHOW = defineCommand({
206
206
  description: 'Fetch Issue details efficiently (GraphQL, only the needed fields)',
207
207
  input: z.object({
208
208
  issue_ref: z.string().describe(ISSUE_REF_DESCRIPTION),
209
+ project: PROJECT_INPUT,
209
210
  json: z.boolean().default(false).describe('Output as JSON'),
210
211
  comment_limit: z.int().min(0).max(MAX_COMMENT_LIMIT).default(DEFAULT_COMMENT_LIMIT).describe('Number of comments to show (0-20; 0 hides them)'),
211
212
  }),
@@ -216,8 +217,8 @@ const ISSUE_SHOW = defineCommand({
216
217
  run: async (input, io) => {
217
218
  const output = createOutput(false, io);
218
219
  return await runWithExit(async () => {
219
- const config = requireActiveConfigPlain(output);
220
220
  const { owner, repository, number } = parseIssueReferenceOrExit(output, input.repo, input.issue_ref);
221
+ const { config } = requireConfigFor(output, { owner, repository }, input.project, ['issue', 'show']);
221
222
  let issue;
222
223
  const client = createGitHubClient(output, config.host);
223
224
  try {
@@ -5,7 +5,7 @@ import { z } from 'zod';
5
5
  import { describeApiError } from '../domain/api-error-detail.js';
6
6
  import { jsonField, tryParseJsonText } from '../domain/json.js';
7
7
  import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
8
- import { requireActiveConfigPlain, stopWith } from './command-stop.js';
8
+ import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
9
9
  import { defineCommand } from './command-definition.js';
10
10
  import { kindOfFailure } from './failure.js';
11
11
  import { createGitHubClient } from './github-client.js';
@@ -22,6 +22,7 @@ const SYNC_MERGE_REJECTED_STATUSES = new Set([405, 409]);
22
22
  const MergeInputSchema = z.strictObject({
23
23
  pr_ref: z.string().describe(PR_REFERENCE_DESCRIPTION),
24
24
  dry_run: z.boolean().default(false).describe('Read the PR and its stack, and show what would happen without merging'),
25
+ project: PROJECT_INPUT,
25
26
  });
26
27
  const PR_MERGE_OUTPUT = z.strictObject({
27
28
  pullRequest: z.string().describe('PR (owner/repo/N)'),
@@ -206,8 +207,8 @@ export const PR_MERGE_COMMAND = defineCommand({
206
207
  interactive: false,
207
208
  run: async (input, io) => {
208
209
  const out = createOutput(input.dry_run, io);
209
- const config = requireActiveConfigPlain(out);
210
210
  const target = parseReference(input.pr_ref, input.repo, out);
211
+ const config = requireConfigFor(out, target, input.project, ['pr', 'merge']).config;
211
212
  const client = createGitHubClient(out, config.host);
212
213
  const name = `PR #${String(target.number)}`;
213
214
  const pullRequest = await readPullRequest(out, client, target);
@@ -9,7 +9,7 @@ import { abortRebase, conflictedFiles, continueRebase, fetchRemote, forkPoint, g
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';
12
- import { requireActiveConfigPlain, stopWith } from './command-stop.js';
12
+ import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
13
13
  import { kindOfFailure } from './failure.js';
14
14
  import { createGitHubClient } from './github-client.js';
15
15
  import { createOutput, DRY_RUN_FIELD } from './output.js';
@@ -36,6 +36,7 @@ const RestackInputSchema = z.strictObject({
36
36
  continue: z.boolean().default(false).describe('Continue a restack that stopped on conflicts, after resolving them'),
37
37
  abort: z.boolean().default(false).describe('Abort a restack that stopped on conflicts and go back to the position before it'),
38
38
  dry_run: z.boolean().default(false).describe('Show what would be done without rebasing, pushing or writing records'),
39
+ project: PROJECT_INPUT,
39
40
  });
40
41
  function causeOf(decision) {
41
42
  if (decision.kind === 'moved')
@@ -183,7 +184,7 @@ async function runRestack(input, io) {
183
184
  if (isRebaseInProgress(cwd)) {
184
185
  stopWith(out, hinted `a rebase is in progress\ncontinue the restack: ${commandHint(RESTACK_PATH, { continue: true })}\nor abort it: ${commandHint(RESTACK_PATH, { abort: true })}`, 'invalid-input', USAGE_EXIT_CODE);
185
186
  }
186
- const config = requireActiveConfigPlain(out);
187
+ const config = requireConfigFor(out, location, input.project, RESTACK_PATH).config;
187
188
  // 記録が無ければ、求める前に fetch して、手元に無い下の段も追跡参照で見る
188
189
  let fetched;
189
190
  const fetchOnce = () => (fetched ??= fetchRemote(cwd, remote));
@@ -17,7 +17,7 @@ import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBa
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';
20
- import { loadActiveConfig } from '../infra/config-store.js';
20
+ import { configLookupFailure, findConfigFor } from '../infra/config-store.js';
21
21
  import { parsePullRequestFile } from '../infra/frontmatter-file.js';
22
22
  import { gitCurrentBranch, gitRemoteUrl, gitStdout, gitToplevel, isAncestor, primaryRemoteName, remoteBranchHead, resolveCommit, runGit } from '../infra/git.js';
23
23
  import { TransportFailure } from '../infra/github/client.js';
@@ -29,7 +29,8 @@ import { readTemplateSections, templateFile } from '../infra/template-store.js';
29
29
  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
- import { requireActiveConfigPlain, stopWith } from './command-stop.js';
32
+ import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
33
+ import { findConfigForRemotes } from '../infra/remote-config.js';
33
34
  import { kindOfFailure } from './failure.js';
34
35
  import { directorySchema } from './directory-option.js';
35
36
  import { createGitHubClient } from './github-client.js';
@@ -178,7 +179,7 @@ async function updateIssueStatusToInReview(config, client, location, headBranch,
178
179
  }
179
180
  catch (error) {
180
181
  const message = `status update of ${label} failed: ${reasonOf(error)}`;
181
- out.warning(error instanceof GitHubAPIError ? fieldWriteFailure(message, error, hintState) : message);
182
+ out.warning(error instanceof GitHubAPIError ? fieldWriteFailure(message, error, config, hintState) : message);
182
183
  return;
183
184
  }
184
185
  out.done(inReviewOperation(issueNumber));
@@ -524,7 +525,6 @@ function requireRepository(value, out) {
524
525
  return splitOwnerRepository(value) ?? stopWith(out, `invalid repository format: ${value} (expected: owner/repo)`, 'invalid-input');
525
526
  }
526
527
  async function createFromFile(input, directory, out) {
527
- const config = requireActiveConfigPlain(out);
528
528
  let parsed;
529
529
  try {
530
530
  parsed = parsePullRequestFile(input.file);
@@ -538,6 +538,7 @@ async function createFromFile(input, directory, out) {
538
538
  if (frontmatter.repository === '' || !frontmatter.repository.includes('/'))
539
539
  return stopWith(out, 'repository is required (e.g. owner/repo)', 'content-invalid');
540
540
  const location = requireRepository(frontmatter.repository, out);
541
+ const config = requireConfigFor(out, location, input.project, PR_CREATE_PATH).config;
541
542
  const head = resolveHeadBranch(frontmatter.head, directory, out);
542
543
  const reading = await readBaseRecordFor(head, input, directory, { config, location }, out);
543
544
  let body = parsed.body;
@@ -561,18 +562,22 @@ async function createFromFile(input, directory, out) {
561
562
  reading,
562
563
  }, out);
563
564
  }
564
- async function createDirect(input, directory, out) {
565
- const config = requireActiveConfigPlain(out);
566
- let location;
567
- if (input.repository === undefined || input.repository === '') {
568
- const [only] = config.repositories;
569
- if (only === undefined || config.repositories.length !== 1)
570
- return stopWith(out, hinted `specify the repository (${inputHint(PR_CREATE_PATH, 'repo', placeholder('owner/repo'))})`, 'invalid-input');
571
- location = { owner: only.owner, repository: only.name };
572
- }
573
- else {
574
- location = requireRepository(input.repository, out);
565
+ // 作り先のリポと設定。--repo が無ければ、設定にあるリポを指す remote(origin を先に)を使う
566
+ function directTarget(input, directory, out) {
567
+ if (input.repository !== undefined && input.repository !== '') {
568
+ const location = requireRepository(input.repository, out);
569
+ return { location, config: requireConfigFor(out, location, input.project, PR_CREATE_PATH).config };
575
570
  }
571
+ const lookup = findConfigForRemotes(directory, input.project);
572
+ if (lookup.kind === 'found')
573
+ return { location: lookup.repository, config: lookup.found.config };
574
+ if (lookup.kind === 'no-remote')
575
+ return stopWith(out, hinted `specify the repository (${inputHint(PR_CREATE_PATH, 'repo', placeholder('owner/repo'))})`, 'invalid-input');
576
+ const { message, kind } = configLookupFailure(lookup.lookup, lookup.repository, PR_CREATE_PATH);
577
+ return stopWith(out, message, kind);
578
+ }
579
+ async function createDirect(input, directory, out) {
580
+ const { location, config } = directTarget(input, directory, out);
576
581
  const head = resolveHeadBranch(input.head, directory, out);
577
582
  const reading = await readBaseRecordFor(head, input, directory, { config, location }, out);
578
583
  let body = input.message;
@@ -638,7 +643,14 @@ async function fillClosesInTemplate(content, config, directory, location, out) {
638
643
  out.done({ verb: 'set', target: `Closes to #${String(target.number)}` });
639
644
  return content.replace(pattern, () => `Closes #${String(target.number)}`);
640
645
  }
641
- async function prepareTemplate(directory, out, template) {
646
+ function configForPrepare(location, project, out) {
647
+ const lookup = findConfigFor(location, project);
648
+ if (lookup.kind === 'found')
649
+ return lookup.found.config;
650
+ out.warning(configLookupFailure(lookup, location, PR_CREATE_PATH).message);
651
+ return undefined;
652
+ }
653
+ async function prepareTemplate(directory, out, template, project) {
642
654
  const templatePath = templateFile('pr', templateKindOf(template));
643
655
  if (!existsSync(templatePath))
644
656
  stopWith(out, `template not found: ${templatePath}`, 'other');
@@ -646,13 +658,13 @@ async function prepareTemplate(directory, out, template) {
646
658
  // release テンプレートは、base をテンプレートの既定(main)のままにする
647
659
  if (template !== 'release') {
648
660
  // 下の段の PR がマージ済みかは、準備と投稿の間に変わりうるので、ここでは読まずに投稿のときに見る
649
- const config = loadActiveConfig();
661
+ const location = primaryRemote(directory)?.location;
662
+ const config = location === undefined ? undefined : configForPrepare(location, project, out);
650
663
  const base = await readBaseOrInfer({ directory, project: config === undefined ? undefined : { config, client: lazyClient(config, out) } });
651
664
  warnUnresolved(base, out);
652
665
  const { reading } = base;
653
666
  stopOnMalformedRecord(reading, out);
654
667
  const record = reading.kind === 'stacked' ? reading.record : undefined;
655
- const location = primaryRemote(directory)?.location;
656
668
  if (location !== undefined) {
657
669
  const developBranch = config === undefined ? undefined : getDevelopBranch(config, location.owner, location.repository);
658
670
  if (config !== undefined && developBranch !== undefined && developBranch !== '') {
@@ -692,6 +704,7 @@ const CreateInputSchema = z.strictObject({
692
704
  no_issue_ref: z.boolean().default(false).describe('Skip the automatic related-Issue setup (extraction from the branch name, adding it to the body, and the validation check)'),
693
705
  template: z.string().default('default').describe('PR template kind (default / release)'),
694
706
  screenshot: z.string().optional().describe('Reason to omit an image from Summary (with -m)'),
707
+ project: PROJECT_INPUT,
695
708
  });
696
709
  async function runCreate(input, io) {
697
710
  const directory = process.cwd();
@@ -699,12 +712,12 @@ async function runCreate(input, io) {
699
712
  if (input.template !== 'default' && input.template !== 'release')
700
713
  stopWith(out, hinted `${inputNameHint(PR_CREATE_PATH, 'template')} must be 'default' or 'release' (given: ${input.template})`, 'invalid-input');
701
714
  if (input.prepare) {
702
- await prepareTemplate(directory, createOutput(false, io), input.template);
715
+ await prepareTemplate(directory, createOutput(false, io), input.template, input.project);
703
716
  }
704
717
  else if (input.file !== undefined) {
705
718
  if (input.screenshot !== undefined)
706
719
  stopWith(out, hinted `${inputNameHint(PR_CREATE_PATH, 'screenshot')} is for ${inputNameHint(PR_CREATE_PATH, 'message')}; write the reason in the \`screenshot\` frontmatter field instead`, 'invalid-input');
707
- await createFromFile({ file: input.file, template: input.template, noIssueRef: input.no_issue_ref, dryRun: input.dry_run }, directory, out);
720
+ await createFromFile({ file: input.file, template: input.template, noIssueRef: input.no_issue_ref, dryRun: input.dry_run, project: input.project }, directory, out);
708
721
  }
709
722
  else if (input.message === undefined) {
710
723
  stopWith(out, hinted `missing arguments\nusage:\n${commandHint(PR_CREATE_PATH, { prepare: true })}\n${commandHint(PR_CREATE_PATH, { file: placeholder('path') })}\n${commandHint(PR_CREATE_PATH, { message: placeholder('body'), title: placeholder('title'), base: placeholder('base-branch') })}`, 'invalid-input');
@@ -723,6 +736,7 @@ async function runCreate(input, io) {
723
736
  noIssueRef: input.no_issue_ref,
724
737
  template: input.template,
725
738
  screenshot: pythonStrip(input.screenshot ?? '') || undefined,
739
+ project: input.project,
726
740
  }, directory, out);
727
741
  }
728
742
  }
@@ -731,6 +745,7 @@ const ShowInputSchema = z.strictObject({
731
745
  pr_ref: z.string().describe(PR_REFERENCE_DESCRIPTION),
732
746
  json: z.boolean().default(false).describe('Output as JSON'),
733
747
  reviews: z.boolean().default(false).describe('Include review details (bodies and line comments)'),
748
+ project: PROJECT_INPUT,
734
749
  });
735
750
  const ISSUE_LINK_JSON = z.strictObject({
736
751
  number: z.int().describe('Issue number'),
@@ -791,8 +806,8 @@ function pullRequestJson(pr) {
791
806
  }
792
807
  async function runShow(input, io) {
793
808
  const out = createOutput(false, io);
794
- const config = requireActiveConfigPlain(out);
795
809
  const { owner, repository, number } = parseReference(input.pr_ref, input.repo, out);
810
+ const config = requireConfigFor(out, { owner, repository }, input.project, ['pr', 'show']).config;
796
811
  try {
797
812
  const client = createGitHubClient(out, config.host);
798
813
  if (input.reviews) {
@@ -898,14 +913,13 @@ function formatWorktreeInfo(info) {
898
913
  }
899
914
  const CheckInputSchema = z.strictObject({
900
915
  directory: directorySchema,
916
+ project: PROJECT_INPUT,
901
917
  });
902
918
  async function runCheck(input, io) {
903
919
  const out = createOutput(false, io);
904
920
  const directory = input.directory;
905
921
  const context = validatePullRequestContext(directory, out);
906
- const config = loadActiveConfig();
907
- if (config === undefined)
908
- return stopWith(out, hinted `project config not found\nactivate a project with: ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`, 'no-active-project');
922
+ const config = requireConfigFor(out, context.location, input.project, ['pr', 'check']).config;
909
923
  const base = await readBaseOrInfer({ directory, project: { config, client: lazyClient(config, out) } });
910
924
  warnUnresolved(base, out);
911
925
  const { reading } = base;
@@ -12,14 +12,13 @@ import { ReleaseError, runPreflight } from '../domain/release.js';
12
12
  import { splitOwnerRepository } from '../domain/repository-resolver.js';
13
13
  import { fetchCodeScanningStatus, fetchSecretScanningStatus, SecurityAlertError } from '../domain/security-alerts.js';
14
14
  import { extractReleaseNotesFromFile, readChangelogIfExists, resolveChangelogPath } from '../infra/changelog-file.js';
15
- import { loadActiveConfig } from '../infra/config-store.js';
16
15
  import { gitRunnerFor, gitToplevel, primaryRemoteName, primaryRemoteRepository } from '../infra/git.js';
17
16
  import { TransportFailure } from '../infra/github/client.js';
18
17
  import { createDependabotSource } from '../infra/github/dependabot-source.js';
19
18
  import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
20
19
  import { createScanAlertSource } from '../infra/github/security-alerts-source.js';
21
20
  import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
22
- import { NO_ACTIVE_PROJECT, stopWith } from './command-stop.js';
21
+ import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
23
22
  import { kindOfFailure } from './failure.js';
24
23
  import { createGitHubClient, makeClient } from './github-client.js';
25
24
  import { issuePath } from './issue-shared.js';
@@ -58,11 +57,12 @@ function resolvePackageContext(out, repositoryConfig, packageName, gitRoot, owne
58
57
  function requireBranchSetting(out, branch, kind, owner, repository) {
59
58
  return branch === undefined || branch === '' ? stopWith(out, hinted `${kind}_branch is not set for ${owner}/${repository}\nset it with: ${commandHint(['project', 'link'], { repo: `${owner}/${repository}`, [`${kind}_branch`]: placeholder('branch') })}`, 'repo-setting-missing') : branch;
60
59
  }
61
- function loadReleaseContext(out, adopted, explicit, packageName, options = {}) {
60
+ function loadReleaseContext(out, adopted, explicit, packageName, project, commandPath, options = {}) {
62
61
  const cwd = process.cwd();
63
62
  const gitRoot = gitToplevel({ cwd }) ?? stopWith(out, 'could not find the root directory of the git repository', 'git-unresolved');
64
- const { owner, repository } = requireReleaseTargetRepository(adopted, explicit, out);
65
- const config = loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
63
+ const target = requireReleaseTargetRepository(adopted, explicit, out);
64
+ const { owner, repository } = target;
65
+ const config = requireConfigFor(out, target, project, commandPath).config;
66
66
  const repositoryConfig = findRepository(config, owner, repository);
67
67
  if (repositoryConfig !== undefined && options.nxAlertsOnly === true && effectiveReleaseType(repositoryConfig) === 'nx') {
68
68
  if (packageName !== undefined || options.version !== undefined) {
@@ -191,6 +191,7 @@ const releaseCheckCommand = defineCommand({
191
191
  input: z.object({
192
192
  version: z.string().optional().describe('Release version (detected from the CHANGELOG when omitted)'),
193
193
  package: z.string().optional().describe('Package name in a monorepo (required for repositories with packages configured)'),
194
+ project: PROJECT_INPUT,
194
195
  }),
195
196
  output: RELEASE_CHECK_OUTPUT,
196
197
  positional: ['version'],
@@ -199,7 +200,7 @@ const releaseCheckCommand = defineCommand({
199
200
  const adopted = requireRepositoryMatch('warn', input.repo, io, process.cwd());
200
201
  const out = createOutput(false, io);
201
202
  const cwd = process.cwd();
202
- const context = loadReleaseContext(out, adopted, input.repo, input.package, { version: input.version, nxAlertsOnly: true });
203
+ const context = loadReleaseContext(out, adopted, input.repo, input.package, input.project, CHECK_PATH, { version: input.version, nxAlertsOnly: true });
203
204
  const { config, owner, repository } = context;
204
205
  const alerts = await checkAlerts(out, config, owner, repository);
205
206
  const { dependabot } = alerts;
@@ -253,6 +254,7 @@ const releaseCreateCommand = defineCommand({
253
254
  version: z.string().describe('Release version (for example 0.6.1)'),
254
255
  dry_run: z.boolean().default(false).describe('Show what would happen without changing anything'),
255
256
  package: z.string().optional().describe('Package name in a monorepo (required for repositories with packages configured)'),
257
+ project: PROJECT_INPUT,
256
258
  }),
257
259
  output: RELEASE_CREATE_OUTPUT,
258
260
  positional: ['version'],
@@ -268,7 +270,7 @@ const releaseCreateCommand = defineCommand({
268
270
  throw error;
269
271
  return stopWith(out, error.message, 'invalid-input');
270
272
  }
271
- const context = loadReleaseContext(out, adopted, input.repo, input.package);
273
+ const context = loadReleaseContext(out, adopted, input.repo, input.package, input.project, ['release', 'create']);
272
274
  const { config, owner, repository, tagPrefix } = context;
273
275
  let releaseNotes;
274
276
  try {
@@ -320,6 +322,7 @@ const releaseMergeCommand = defineCommand({
320
322
  dry_run: z.boolean().default(false).describe('Show what would happen without merging'),
321
323
  delete_branch: z.boolean().default(false).describe('Delete the branch after merging'),
322
324
  admin: z.boolean().default(false).describe('Merge with admin rights (skip the mergeability check)'),
325
+ project: PROJECT_INPUT,
323
326
  }),
324
327
  output: RELEASE_MERGE_OUTPUT,
325
328
  positional: ['pr_ref'],
@@ -328,7 +331,6 @@ const releaseMergeCommand = defineCommand({
328
331
  run: async (input, io) => {
329
332
  requireRepositoryMatch('reject', input.repo, io, process.cwd());
330
333
  const out = createOutput(input.dry_run, io);
331
- const config = loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
332
334
  let reference;
333
335
  try {
334
336
  reference = parsePullRequestReference(input.pr_ref);
@@ -341,6 +343,7 @@ const releaseMergeCommand = defineCommand({
341
343
  const { owner, repository } = reference.repository;
342
344
  const number = reference.number;
343
345
  const pullRequestName = issuePath(owner, repository, number);
346
+ const config = requireConfigFor(out, reference.repository, input.project, ['release', 'merge']).config;
344
347
  let client;
345
348
  let pullRequest;
346
349
  try {
@@ -17,7 +17,7 @@ import { isFileNotFound } from '../infra/os-error.js';
17
17
  import { removeFlag } from '../infra/state-store.js';
18
18
  import { getCurrentWorktreeName, isWorktreeEnvironment } from '../infra/worktree.js';
19
19
  import { commandHint, hinted } from './command-hint.js';
20
- import { requireActiveConfigPlain, stopWith } from './command-stop.js';
20
+ import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
21
21
  import { createReadinessCache, judgeAssuming } from './issue-readiness.js';
22
22
  import { moveIssuesWaitingFor, prerequisiteOf } from './pr-waiting.js';
23
23
  import { kindOfFailure } from './failure.js';
@@ -335,6 +335,7 @@ const FinishInputSchema = z.strictObject({
335
335
  dry_run: z.boolean().default(false).describe('Dry-run (do not actually clean up)'),
336
336
  delete_branch: z.boolean().default(false).describe('Delete the branch'),
337
337
  skip_local_cleanup: z.boolean().default(false).describe('Skip the local branch switch and deletion'),
338
+ project: PROJECT_INPUT,
338
339
  });
339
340
  async function runFinish(input, io) {
340
341
  const out = createOutput(input.dry_run, io);
@@ -350,9 +351,9 @@ async function runFinish(input, io) {
350
351
  }
351
352
  async function finish(input, context) {
352
353
  const { out } = context;
353
- const config = requireActiveConfigPlain(out);
354
354
  const reference = parseReference(input.pr_ref, input.repo, out);
355
355
  const location = { owner: reference.owner, repository: reference.repository };
356
+ const config = requireConfigFor(out, location, input.project, ['session', 'finish']).config;
356
357
  const { client, pr } = await fetchPullRequestForCleanup(config, reference, out);
357
358
  if (pr.state !== 'MERGED')
358
359
  stopWith(out, hinted `PR #${String(reference.number)} is not merged yet (state: ${pr.state}); merge it with ${commandHint(['pr', 'merge'])} first`, 'pr-state');
@@ -10,7 +10,7 @@ import { issuePath } from './issue-shared.js';
10
10
  import { createOutput, DRY_RUN_FIELD } from './output.js';
11
11
  import { defineCommand } from './command-definition.js';
12
12
  import { commandHint, hinted, joinHinted } from './command-hint.js';
13
- import { requireActiveConfig, stopWith } from './command-stop.js';
13
+ import { PROJECT_INPUT, requireConfigFor, stopWith } from './command-stop.js';
14
14
  import { kindOfFailure } from './failure.js';
15
15
  import { fieldWriteFailure } from './field-write-failure.js';
16
16
  import { createGitHubClient } from './github-client.js';
@@ -100,7 +100,7 @@ async function setIssueStatusActive(out, client, config, issue) {
100
100
  catch (error) {
101
101
  if (!(error instanceof GitHubAPIError))
102
102
  throw error;
103
- out.warning(fieldWriteFailure(`could not set ${target}: ${error.message}`, error));
103
+ out.warning(fieldWriteFailure(`could not set ${target}: ${error.message}`, error, config));
104
104
  return;
105
105
  }
106
106
  out.done({ verb: 'set', target });
@@ -130,6 +130,7 @@ const sessionStartCommand = defineCommand({
130
130
  base: z.string().optional().describe('Base branch (default: chosen by readiness, else develop_branch from the config)'),
131
131
  checkout: z.boolean().default(true).describe('Kept for compatibility; has no effect'),
132
132
  dry_run: z.boolean().default(false).describe('Show what would be created and recorded without writing anything'),
133
+ project: PROJECT_INPUT,
133
134
  }),
134
135
  output: SESSION_START_OUTPUT,
135
136
  positional: ['issue_ref', 'branch'],
@@ -139,8 +140,6 @@ const sessionStartCommand = defineCommand({
139
140
  run: async (input, io) => {
140
141
  requireRepositoryMatch('reject', input.repo, io, process.cwd());
141
142
  const out = createOutput(input.dry_run, io);
142
- // 1. 設定取得
143
- const config = requireActiveConfig(out);
144
143
  // 2. issue_ref をパース(フル形式必須、基準リポは渡さない)
145
144
  let issue;
146
145
  try {
@@ -155,6 +154,8 @@ const sessionStartCommand = defineCommand({
155
154
  const issueNumber = issue.number;
156
155
  // A-1. 作業ディレクトリと Issue ref のリポジトリの整合チェック
157
156
  rejectCwdRepositoryMismatch(out, owner, repository);
157
+ // 1. 設定取得(issue_ref のリポを含む設定)
158
+ const config = requireConfigFor(out, issue.repository, input.project, ['session', 'start']).config;
158
159
  const finalBranchName = `${input.branch}/${String(issueNumber)}`;
159
160
  try {
160
161
  const client = createGitHubClient(out, config.host);
@@ -5,11 +5,13 @@ 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';
7
7
  import { describeStackBase } from '../domain/work-start.js';
8
- import { loadActiveConfig } from '../infra/config-store.js';
8
+ import { configLookupFailure, findConfigFor } from '../infra/config-store.js';
9
9
  import { activeIssueOf, gitCurrentBranch, primaryRemoteName, primaryRemoteRepository } from '../infra/git.js';
10
10
  import { GitHubAPIError } from '../infra/github/errors.js';
11
11
  import { readBaseOrInfer, warnUnresolved } from './base-reading.js';
12
12
  import { defineCommand } from './command-definition.js';
13
+ import { joinHinted } from './command-hint.js';
14
+ import { PROJECT_INPUT } from './command-stop.js';
13
15
  import { directorySchema } from './directory-option.js';
14
16
  import { createGitHubClient } from './github-client.js';
15
17
  import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
@@ -46,7 +48,7 @@ const SESSION_SHOW_OUTPUT = z.strictObject({
46
48
  });
47
49
  // 作業中の Issue(remote とブランチ名から求める)を GitHub から読んで、Markdown の行にする。
48
50
  // 作業中の Issue が無ければ undefined。読めなければ warning を出し、参照だけを返す
49
- async function readActiveIssue(directory, output) {
51
+ async function readActiveIssue(directory, output, project) {
50
52
  const reference = activeIssueOf(directory);
51
53
  if (reference === undefined)
52
54
  return undefined;
@@ -56,11 +58,12 @@ async function readActiveIssue(directory, output) {
56
58
  let config;
57
59
  let client;
58
60
  try {
59
- config = loadActiveConfig();
60
- if (config === undefined) {
61
- output.warning('cannot read the active Issue: no active project');
61
+ const lookup = findConfigFor(reference.repository, project);
62
+ if (lookup.kind !== 'found') {
63
+ output.warning(joinHinted(['cannot read the active Issue: ', configLookupFailure(lookup, reference.repository, ['session', 'show']).message], ''));
62
64
  return { label, data };
63
65
  }
66
+ config = lookup.found.config;
64
67
  client = createGitHubClient(output, config.host);
65
68
  issue = await client.getIssueSlim(reference.repository.owner, reference.repository.repository, reference.number, 0);
66
69
  }
@@ -143,7 +146,7 @@ async function blockedReadiness(active, known, output) {
143
146
  const SESSION_SHOW = defineCommand({
144
147
  path: ['session', 'show'],
145
148
  description: 'Show the branch, repository and work Issue of the session',
146
- input: z.object({ directory: directorySchema }),
149
+ input: z.object({ directory: directorySchema, project: PROJECT_INPUT }),
147
150
  output: SESSION_SHOW_OUTPUT,
148
151
  positional: [],
149
152
  shortFlags: { directory: '-D' },
@@ -152,7 +155,7 @@ const SESSION_SHOW = defineCommand({
152
155
  const output = createOutput(false, io);
153
156
  const branch = gitCurrentBranch(input.directory);
154
157
  const origin = primaryRemoteRepository(input.directory);
155
- const reading = await readActiveIssue(input.directory, output);
158
+ const reading = await readActiveIssue(input.directory, output, input.project);
156
159
  const active = reading?.read;
157
160
  const stack = active === undefined ? { lines: [] } : await stackSection(active, origin, input.directory, output);
158
161
  const above = active === undefined || origin === undefined || branch === undefined ? undefined : await readStackedAbove(active, origin, branch, output);
@@ -116,7 +116,7 @@ tracker sync の source dependabot の本体。Tracker の Dependabot PRs waitin
116
116
  */
117
117
  export async function runDependabotSync(input, io) {
118
118
  const out = createOutput(input.dry_run, io);
119
- const { config, owner, repository } = loadTarget(out, input.repo);
119
+ const { config, owner, repository } = loadTarget(out, input.repo, input.project);
120
120
  const client = makeClient(out, config);
121
121
  let pullRequests;
122
122
  let issues;
@@ -125,7 +125,7 @@ tracker sync の source security の本体。Tracker の open security alerts
125
125
  */
126
126
  export async function runSecuritySync(input, io) {
127
127
  const out = createOutput(input.dry_run, io);
128
- const { config, owner, repository } = loadTarget(out, input.repo);
128
+ const { config, owner, repository } = loadTarget(out, input.repo, input.project);
129
129
  const client = makeClient(out, config);
130
130
  const sources = { scan: createScanAlertSource(client), dependabot: createDependabotSource(client) };
131
131
  const { alerts, failed, disabled } = await fetchOpenAlerts(out, sources, config.host, owner, repository);
@@ -42,6 +42,7 @@ tracker sync の各 source の本体が受ける入力
42
42
  export interface TrackerSyncInput {
43
43
  readonly dry_run: boolean;
44
44
  readonly repo?: string | undefined;
45
+ readonly project?: string | undefined;
45
46
  }
46
47
  export interface SyncTarget {
47
48
  readonly config: ProjectConfig;
@@ -49,10 +50,9 @@ export interface SyncTarget {
49
50
  readonly repository: string;
50
51
  }
51
52
  /**
52
- 対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
53
- 設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
53
+ 対象のリポ(--repo、主の remote の順)と、それを含むプロジェクトの設定を決める。決められなければ error の行を出して終了コード 1 で止める
54
54
  */
55
- export declare function loadTarget(out: Readonly<Output>, explicitRepository: string | undefined): SyncTarget;
55
+ export declare function loadTarget(out: Readonly<Output>, explicitRepository: string | undefined, project: string | undefined): SyncTarget;
56
56
  /**
57
57
  複数の Tracker が open のときに警告する(番号が最小のものを使い、ほかは閉じない)
58
58
  */
@@ -2,7 +2,7 @@
2
2
  import { z } from 'zod';
3
3
  import { TransportFailure } from '../infra/github/client.js';
4
4
  import { GitHubAPIError } from '../infra/github/errors.js';
5
- import { requireActiveConfigPlain } from './command-stop.js';
5
+ import { requireConfigFor } from './command-stop.js';
6
6
  import { DRY_RUN_FIELD } from './output.js';
7
7
  import { requireReleaseTargetRepository } from './release.js';
8
8
  /**
@@ -26,12 +26,11 @@ export const TRACKER_SYNC_OUTPUT = z.strictObject({
26
26
  dryRun: DRY_RUN_FIELD,
27
27
  });
28
28
  /**
29
- 対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
30
- 設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
29
+ 対象のリポ(--repo、主の remote の順)と、それを含むプロジェクトの設定を決める。決められなければ error の行を出して終了コード 1 で止める
31
30
  */
32
- export function loadTarget(out, explicitRepository) {
31
+ export function loadTarget(out, explicitRepository, project) {
33
32
  const target = requireReleaseTargetRepository(undefined, explicitRepository, out);
34
- const config = requireActiveConfigPlain(out);
33
+ const config = requireConfigFor(out, target, project, ['tracker', 'sync']).config;
35
34
  return { config, owner: target.owner, repository: target.repository };
36
35
  }
37
36
  /**
@@ -1,5 +1,6 @@
1
1
  // `pecot tracker sync <source>`。source ごとの本体(dependabot.ts・security.ts)を呼び分ける。
2
2
  import { z } from 'zod';
3
+ import { PROJECT_INPUT } from './command-stop.js';
3
4
  import { defineCommand } from './command-definition.js';
4
5
  import { runDependabotSync } from './tracker-sync-dependabot.js';
5
6
  import { runSecuritySync } from './tracker-sync-security.js';
@@ -10,6 +11,7 @@ const syncCommand = defineCommand({
10
11
  input: z.strictObject({
11
12
  source: z.enum(['dependabot', 'security']).describe('What to put into the Tracker: dependabot (Dependabot PRs waiting for a human decision) or security (open security alerts)'),
12
13
  dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
14
+ project: PROJECT_INPUT,
13
15
  }),
14
16
  output: TRACKER_SYNC_OUTPUT,
15
17
  positional: ['source'],
@@ -14,7 +14,7 @@ import { createSymlinksSafe, DEFAULT_WORKTREEIGNORE_CONTENT, decideOverwrite, ge
14
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
- import { stopWith } from './command-stop.js';
17
+ import { PROJECT_INPUT, stopWith } from './command-stop.js';
18
18
  import { directorySchema } from './directory-option.js';
19
19
  import { requireRepositoryMatch } from './repository-match.js';
20
20
  // click の realpath と同じく、解決できない所は字面のまま残して投げない
@@ -58,13 +58,14 @@ function countCopyResults(results, out) {
58
58
  }
59
59
  const worktreeAddInput = z.object({
60
60
  directory: directorySchema,
61
- base: z.string().optional().describe('Base branch (default: the develop_branch of the repository in the active project)'),
61
+ base: z.string().optional().describe('Base branch (default: the develop_branch of the repository in its project config)'),
62
62
  path: z.string().transform(lenientRealPath).optional().describe('Where to create the worktree (default: <project_root>/<auto-numbered>/<repository name>)'),
63
63
  no_copy: z.boolean().default(false).describe('Skip copying untracked files'),
64
64
  no_link: z.boolean().default(false).describe('Skip creating symlinks'),
65
65
  setup: z.string().optional().describe('Command to run after creation'),
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
+ project: PROJECT_INPUT,
68
69
  });
69
70
  const ADD_OUTPUT = z.strictObject({
70
71
  name: z.string().describe('Name of the worktree (the wtN it was numbered as)'),
@@ -98,6 +99,7 @@ function runAdd(input, io) {
98
99
  setupCommand: input.setup,
99
100
  isDryRun: input.dry_run,
100
101
  isExistingBranchAllowed: input.allow_existing_branch,
102
+ project: input.project,
101
103
  });
102
104
  const operation = { verb: 'create', target: `worktree ${result.name} at ${result.path} (branch ${result.branch} from ${result.baseBranch})` };
103
105
  out.planned(operation);
@@ -154,10 +154,6 @@ export interface RepositoryMembership {
154
154
  }
155
155
  export declare class ConfigError extends PecotError {
156
156
  }
157
- export declare class MultipleConfigsError extends ConfigError {
158
- readonly files: readonly string[];
159
- constructor(files: readonly string[]);
160
- }
161
157
  /**
162
158
  JSON の値からプロジェクト設定を作る。形が不正なら ValidationFailure(表題は ProjectConfig)
163
159
  */
@@ -177,10 +173,6 @@ export declare function getFieldId(config: ProjectConfig, fieldName: string): st
177
173
  export declare function getOptionId(config: ProjectConfig, fieldName: string, optionName: string): string | undefined;
178
174
  export declare function findRepository(config: ProjectConfig, owner: string, name: string): Repository | undefined;
179
175
  /**
180
- owner を指定せずに名前だけで探す(アクティブ設定内の検索用)
181
- */
182
- export declare function findRepositoryByName(config: ProjectConfig, name: string): Repository | undefined;
183
- /**
184
176
  設定の repositories の 1 件の `owner/name`
185
177
  */
186
178
  export declare function configuredRepositoryFullName(repository: Repository): string;