@pecot/workflow-mcp 8.0.1-dev.50 → 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 @@
6
6
  import { z } from 'zod';
7
7
  import { PecotError } from './errors.js';
8
8
  import { isJsonObject, jsonField } from './json.js';
9
- import { isJsonArray, pythonRepr, pythonStrip, pythonStringRepr, ValidationFailure } from './python-format.js';
9
+ import { isJsonArray, pythonStrip, pythonStringRepr, ValidationFailure } from './python-format.js';
10
10
  import { parseOwnerRepository, splitOwnerRepository } from './repository-resolver.js';
11
11
  const WorkflowStatusSchema = z.enum(['backlog', 'pending', 'blocked', 'ready', 'active', 'in_review', 'archived']);
12
12
  export const WORKFLOW_STATUSES = WorkflowStatusSchema.options;
@@ -106,14 +106,6 @@ const ProjectConfigSchema = model('ProjectConfig', {
106
106
  }).readonly();
107
107
  export class ConfigError extends PecotError {
108
108
  }
109
- export class MultipleConfigsError extends ConfigError {
110
- files;
111
- constructor(files) {
112
- const names = files.map(file => file.slice(file.lastIndexOf('/') + 1));
113
- super(`multiple config files found: ${pythonRepr(names)}`);
114
- this.files = files;
115
- }
116
- }
117
109
  // 検証エラーの変換
118
110
  function valueAt(root, location) {
119
111
  let current = root;
@@ -235,12 +227,6 @@ export function findRepository(config, owner, name) {
235
227
  return config.repositories.find(repository => repository.owner === owner && repository.name === name);
236
228
  }
237
229
  /**
238
- owner を指定せずに名前だけで探す(アクティブ設定内の検索用)
239
- */
240
- export function findRepositoryByName(config, name) {
241
- return config.repositories.find(repository => repository.name === name);
242
- }
243
- /**
244
230
  設定の repositories の 1 件の `owner/name`
245
231
  */
246
232
  export function configuredRepositoryFullName(repository) {
@@ -1,4 +1,6 @@
1
+ import type { HintedText } from '../domain/command-hint.js';
1
2
  import type { ProjectConfig } from '../domain/config.js';
3
+ import type { RepositoryReference } from '../domain/repository-resolver.js';
2
4
  /**
3
5
  設定ディレクトリ(`{プロジェクトルート}/.pecot/config`)
4
6
  */
@@ -8,6 +10,10 @@ export declare function configDirectory(): string;
8
10
  */
9
11
  export declare function projectsDirectory(): string;
10
12
  /**
13
+ loadConfig で読んだ設定のファイルの実パス。ファイルから読んでいない設定は undefined
14
+ */
15
+ export declare function configSourcePath(config: ProjectConfig): string | undefined;
16
+ /**
11
17
  JSON ファイルから設定を読む。無ければ ConfigError、JSON の構文や形が不正なら `invalid config file: {パス}: {詳細}` の ConfigError。
12
18
  詳細は、形の不正なら `場所: 本文` を `; ` でつないだもの(Python と同じ)、構文の不正なら JSON パーサーの文(Python の JSONDecodeError の文とは違う)
13
19
  */
@@ -30,24 +36,65 @@ export declare function listProjectConfigNames(): readonly string[];
30
36
  アクティブ設定を設定する。.active には .active のあるディレクトリ基準の相対パスを書く。ファイルが無ければ ConfigError
31
37
  */
32
38
  export declare function setActiveConfig(file: string): void;
33
- export interface FindConfigOptions {
34
- readonly host?: string | undefined;
35
- readonly owner?: string | undefined;
36
- }
37
39
  /**
38
- `{host}_{owner}_*.json` の設定ファイルを探す(プロジェクト名ベース)。host と owner の両方が要る。
39
- 複数見つかったら MultipleConfigsError(名前順)
40
+ 設定と、その名前・実パス。name は projects/ の中なら拡張子を除いたファイル名、外ならパス(project activate に渡せる形)
40
41
  */
41
- export declare function findConfigFile(options: Readonly<FindConfigOptions>): string | undefined;
42
- export interface ProjectConfigQuery extends FindConfigOptions {
43
- /**
44
- リポジトリ名(owner なし)。アクティブ設定の repositories に含まれるかを先に確かめる
45
- */
46
- readonly repository?: string | undefined;
42
+ export interface FoundConfig {
43
+ readonly name: string;
44
+ readonly path: string;
45
+ readonly config: ProjectConfig;
47
46
  }
48
47
  /**
49
- プロジェクト設定を取得する。引数なしはアクティブ設定。
50
- repository だけなら、アクティブ設定の repositories にあればそれを返し、無ければ検索する。見つからなければ undefined
48
+ project activate に渡せる設定の名前。projects/ の中なら拡張子を除いたファイル名、外ならパスそのもの
49
+ */
50
+ export declare function projectNameOf(configPath: string): string;
51
+ /**
52
+ projects/ の設定を名前で読む。`.json` は省ける。その名前の設定が無ければ undefined
53
+ */
54
+ export declare function loadNamedConfig(name: string): FoundConfig | undefined;
55
+ /**
56
+ 設定が対象のリポを含むか。repositories にあるか、aggregation_repo と一致すれば含む(aggregation_repo は repositories に無くてよい)
57
+ */
58
+ export declare function hasRepository(config: ProjectConfig, target: Readonly<RepositoryReference>): boolean;
59
+ /**
60
+ 対象のリポを含む設定(projects/ の *.json と、.active の指す設定)。名前順。形の誤った設定は、関係が無くても ConfigError
61
+ */
62
+ export declare function findConfigsForRepository(target: Readonly<RepositoryReference>): readonly FoundConfig[];
63
+ export type ConfigLookup = {
64
+ readonly kind: 'found';
65
+ readonly found: FoundConfig;
66
+ } | {
67
+ readonly kind: 'none';
68
+ } | {
69
+ readonly kind: 'ambiguous';
70
+ readonly candidates: readonly FoundConfig[];
71
+ } | {
72
+ readonly kind: 'unknown-project';
73
+ readonly project: string;
74
+ } | {
75
+ readonly kind: 'not-in-project';
76
+ readonly found: FoundConfig;
77
+ };
78
+ /**
79
+ 対象のリポから設定を決める。project を渡せばその名前の設定、無ければ対象のリポを含む設定。
80
+ 候補が 2 つ以上なら、.active の指す設定が候補にあればそれを使う
81
+ */
82
+ export declare function findConfigFor(target: Readonly<RepositoryReference>, project?: string): ConfigLookup;
83
+ /**
84
+ findConfigFor が設定を選べなかったときの文と失敗の名前。commandPath は `project` の入力の案内に使う
85
+ */
86
+ export declare function configLookupFailure(lookup: Exclude<ConfigLookup, {
87
+ readonly kind: 'found';
88
+ }>, target: Readonly<RepositoryReference>, commandPath: readonly string[]): {
89
+ readonly message: string | HintedText;
90
+ readonly kind: 'no-active-project' | 'project-not-found' | 'repo-not-in-project';
91
+ };
92
+ /**
93
+ 設定が 2 つ以上あって選べないときの文。`project` の入力の案内と候補の名前を添える
94
+ */
95
+ export declare function ambiguousMessage(headline: string, names: readonly string[], commandPath: readonly string[]): HintedText;
96
+ /**
97
+ `project` の名前の設定が無いときの文
51
98
  */
52
- export declare function getProjectConfig(query?: Readonly<ProjectConfigQuery>): ProjectConfig | undefined;
99
+ export declare function unknownProjectMessage(project: string): string;
53
100
  //# sourceMappingURL=config-store.d.ts.map
@@ -2,7 +2,8 @@
2
2
  // プロジェクト設定(`.pecot/config/projects/*.json`)の読み書き。モデルと判定は domain/config.ts にある。
3
3
  import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
4
4
  import path from 'node:path';
5
- import { ConfigError, findRepositoryByName, MultipleConfigsError, parseProjectConfig, serializeProjectConfig, } from '../domain/config.js';
5
+ import { hinted, inputHint, placeholder } from '../domain/command-hint.js';
6
+ import { ConfigError, findRepository, parseProjectConfig, serializeProjectConfig } from '../domain/config.js';
6
7
  import { InvalidValueError } from '../domain/errors.js';
7
8
  import { parseJsonText } from '../domain/json.js';
8
9
  import { compareStrings, pythonStrip, ValidationFailure } from '../domain/python-format.js';
@@ -21,6 +22,14 @@ export function configDirectory() {
21
22
  export function projectsDirectory() {
22
23
  return path.join(configDirectory(), 'projects');
23
24
  }
25
+ // 設定の値から、読んだファイルの実パスを引く。書き込みの失敗の案内(project activate <名前>)に使う
26
+ const SOURCE_PATHS = new WeakMap();
27
+ /**
28
+ loadConfig で読んだ設定のファイルの実パス。ファイルから読んでいない設定は undefined
29
+ */
30
+ export function configSourcePath(config) {
31
+ return SOURCE_PATHS.get(config);
32
+ }
24
33
  /**
25
34
  JSON ファイルから設定を読む。無ければ ConfigError、JSON の構文や形が不正なら `invalid config file: {パス}: {詳細}` の ConfigError。
26
35
  詳細は、形の不正なら `場所: 本文` を `; ` でつないだもの(Python と同じ)、構文の不正なら JSON パーサーの文(Python の JSONDecodeError の文とは違う)
@@ -29,7 +38,9 @@ export function loadConfig(file) {
29
38
  if (!existsSync(file))
30
39
  throw new ConfigError(`config file not found: ${file}`);
31
40
  try {
32
- return parseProjectConfig(parseJsonText(readTextFile(file)));
41
+ const config = parseProjectConfig(parseJsonText(readTextFile(file)));
42
+ SOURCE_PATHS.set(config, resolveRealPath(file));
43
+ return config;
33
44
  }
34
45
  catch (error) {
35
46
  if (error instanceof ValidationFailure) {
@@ -91,44 +102,94 @@ export function setActiveConfig(file) {
91
102
  writeFileSync(activeFile, `${relative}\n`);
92
103
  }
93
104
  /**
94
- `{host}_{owner}_*.json` の設定ファイルを探す(プロジェクト名ベース)。host と owner の両方が要る。
95
- 複数見つかったら MultipleConfigsError(名前順)
105
+ project activate に渡せる設定の名前。projects/ の中なら拡張子を除いたファイル名、外ならパスそのもの
96
106
  */
97
- export function findConfigFile(options) {
98
- const { host, owner } = options;
99
- if (host === undefined || host === '' || owner === undefined || owner === '')
100
- return undefined;
101
- const directory = projectsDirectory();
102
- const prefix = `${host}_${owner}_`;
103
- let names;
104
- try {
105
- names = readdirSync(directory);
106
- }
107
- catch (error) {
108
- if (isFileNotFound(error))
109
- return undefined;
110
- throw error;
107
+ export function projectNameOf(configPath) {
108
+ return path.dirname(configPath) === resolveRealPath(projectsDirectory()) ? path.basename(configPath, '.json') : configPath;
109
+ }
110
+ function foundAt(file) {
111
+ const config = loadConfig(file);
112
+ const realPath = configSourcePath(config) ?? resolveRealPath(file);
113
+ return { name: projectNameOf(realPath), path: realPath, config };
114
+ }
115
+ /**
116
+ projects/ の設定を名前で読む。`.json` は省ける。その名前の設定が無ければ undefined
117
+ */
118
+ export function loadNamedConfig(name) {
119
+ // 一覧は projects/ の *.json の名前なので、一致すれば ../ などの外のパスにならない
120
+ const bare = name.endsWith('.json') ? name.slice(0, -'.json'.length) : name;
121
+ return listProjectConfigNames().includes(bare) ? foundAt(path.join(projectsDirectory(), `${bare}.json`)) : undefined;
122
+ }
123
+ /**
124
+ 設定が対象のリポを含むか。repositories にあるか、aggregation_repo と一致すれば含む(aggregation_repo は repositories に無くてよい)
125
+ */
126
+ export function hasRepository(config, target) {
127
+ return findRepository(config, target.owner, target.repository) !== undefined || config.aggregation_repo === `${target.owner}/${target.repository}`;
128
+ }
129
+ /**
130
+ 対象のリポを含む設定(projects/ の *.json と、.active の指す設定)。名前順。形の誤った設定は、関係が無くても ConfigError
131
+ */
132
+ export function findConfigsForRepository(target) {
133
+ const all = listProjectConfigNames().map(name => foundAt(path.join(projectsDirectory(), `${name}.json`)));
134
+ const active = getActiveConfigPath();
135
+ if (active !== undefined && all.every(found => found.path !== active))
136
+ all.push(foundAt(active));
137
+ return all.filter(found => hasRepository(found.config, target));
138
+ }
139
+ /**
140
+ 対象のリポから設定を決める。project を渡せばその名前の設定、無ければ対象のリポを含む設定。
141
+ 候補が 2 つ以上なら、.active の指す設定が候補にあればそれを使う
142
+ */
143
+ export function findConfigFor(target, project) {
144
+ if (project !== undefined) {
145
+ const named = loadNamedConfig(project);
146
+ if (named === undefined)
147
+ return { kind: 'unknown-project', project };
148
+ return hasRepository(named.config, target) ? { kind: 'found', found: named } : { kind: 'not-in-project', found: named };
111
149
  }
112
- const matches = names.filter(name => name.startsWith(prefix) && name.endsWith('.json') && name.length >= prefix.length + '.json'.length).toSorted(compareStrings);
113
- const [only] = matches;
114
- if (matches.length > 1)
115
- throw new MultipleConfigsError(matches.map(name => path.join(directory, name)));
116
- return only === undefined ? undefined : path.join(directory, only);
117
- }
118
- /**
119
- プロジェクト設定を取得する。引数なしはアクティブ設定。
120
- repository だけなら、アクティブ設定の repositories にあればそれを返し、無ければ検索する。見つからなければ undefined
121
- */
122
- export function getProjectConfig(query = {}) {
123
- const { host, owner, repository } = query;
124
- if (host === undefined && owner === undefined && repository === undefined)
125
- return loadActiveConfig();
126
- if (host === undefined && owner === undefined && repository !== undefined) {
127
- const active = loadActiveConfig();
128
- if (active !== undefined && findRepositoryByName(active, repository) !== undefined)
129
- return active;
150
+ const candidates = findConfigsForRepository(target);
151
+ const [only] = candidates;
152
+ if (only === undefined)
153
+ return { kind: 'none' };
154
+ if (candidates.length === 1)
155
+ return { kind: 'found', found: only };
156
+ const active = getActiveConfigPath();
157
+ const chosen = candidates.find(found => found.path === active);
158
+ return chosen === undefined ? { kind: 'ambiguous', candidates } : { kind: 'found', found: chosen };
159
+ }
160
+ function availableLine(names) {
161
+ return `available: ${names.length === 0 ? '(none)' : names.join(', ')}`;
162
+ }
163
+ /**
164
+ findConfigFor が設定を選べなかったときの文と失敗の名前。commandPath は `project` の入力の案内に使う
165
+ */
166
+ export function configLookupFailure(lookup, target, commandPath) {
167
+ const repository = `${target.owner}/${target.repository}`;
168
+ switch (lookup.kind) {
169
+ case 'none': {
170
+ return { message: `${repository} is not in any project config\n${availableLine(listProjectConfigNames())}`, kind: 'repo-not-in-project' };
171
+ }
172
+ case 'ambiguous': {
173
+ return { message: ambiguousMessage(`${repository} is in ${String(lookup.candidates.length)} project configs`, lookup.candidates.map(found => found.name), commandPath), kind: 'no-active-project' };
174
+ }
175
+ case 'unknown-project': {
176
+ return { message: unknownProjectMessage(lookup.project), kind: 'project-not-found' };
177
+ }
178
+ case 'not-in-project': {
179
+ return { message: `${repository} is not in project config ${lookup.found.name}`, kind: 'repo-not-in-project' };
180
+ }
130
181
  }
131
- const configPath = findConfigFile({ host, owner });
132
- return configPath === undefined ? undefined : loadConfig(configPath);
182
+ }
183
+ /**
184
+ 設定が 2 つ以上あって選べないときの文。`project` の入力の案内と候補の名前を添える
185
+ */
186
+ export function ambiguousMessage(headline, names, commandPath) {
187
+ return hinted `${headline}\nchoose one with ${inputHint(commandPath, 'project', placeholder('NAME'))}\n${availableLine(names)}`;
188
+ }
189
+ /**
190
+ `project` の名前の設定が無いときの文
191
+ */
192
+ export function unknownProjectMessage(project) {
193
+ return `project config not found: ${project}\n${availableLine(listProjectConfigNames())}`;
133
194
  }
134
195
  //# sourceMappingURL=config-store.js.map
@@ -0,0 +1,22 @@
1
+ import type { RepositoryReference } from '../domain/repository-resolver.js';
2
+ import type { ConfigLookup, FoundConfig } from './config-store.js';
3
+ export type RemoteConfigLookup = {
4
+ readonly kind: 'no-remote';
5
+ } | {
6
+ readonly kind: 'found';
7
+ readonly remote: string;
8
+ readonly repository: RepositoryReference;
9
+ readonly found: FoundConfig;
10
+ } | {
11
+ readonly kind: 'failed';
12
+ readonly repository: RepositoryReference;
13
+ readonly lookup: Exclude<ConfigLookup, {
14
+ readonly kind: 'found';
15
+ }>;
16
+ };
17
+ /**
18
+ remote のリポのうち、設定を選べた最初のもの。名前の誤りと、候補から選べないときは、ほかの remote を見ずに返す。
19
+ どの remote でも選べなければ、最初の remote のリポと、そのときの結果を返す
20
+ */
21
+ export declare function findConfigForRemotes(cwd: string, project: string | undefined): RemoteConfigLookup;
22
+ //# sourceMappingURL=remote-config.d.ts.map
@@ -0,0 +1,48 @@
1
+ // git の remote のリポから、プロジェクトの設定を選ぶ。origin を先に、残りの remote を git remote の順に当てる
2
+ import { ValidationFailure } from '../domain/python-format.js';
3
+ import { createRepositoryReference } from '../domain/repository-resolver.js';
4
+ import { findConfigFor } from './config-store.js';
5
+ import { listRemotes, remoteRepository } from './git.js';
6
+ // URL を GitHub の owner/repo として読めない remote は undefined
7
+ function repositoryOf(cwd, remote) {
8
+ const location = remoteRepository(cwd, remote);
9
+ if (location === undefined)
10
+ return undefined;
11
+ try {
12
+ return createRepositoryReference(location.owner, location.repository);
13
+ }
14
+ catch (error) {
15
+ if (error instanceof ValidationFailure)
16
+ return undefined;
17
+ throw error;
18
+ }
19
+ }
20
+ function readRemoteRepositories(cwd) {
21
+ const remotes = listRemotes(cwd) ?? [];
22
+ const ordered = remotes.includes('origin') ? ['origin', ...remotes.filter(remote => remote !== 'origin')] : remotes;
23
+ const read = [];
24
+ for (const remote of ordered) {
25
+ const repository = repositoryOf(cwd, remote);
26
+ if (repository !== undefined)
27
+ read.push({ remote, repository });
28
+ }
29
+ return read;
30
+ }
31
+ /**
32
+ remote のリポのうち、設定を選べた最初のもの。名前の誤りと、候補から選べないときは、ほかの remote を見ずに返す。
33
+ どの remote でも選べなければ、最初の remote のリポと、そのときの結果を返す
34
+ */
35
+ export function findConfigForRemotes(cwd, project) {
36
+ const candidates = readRemoteRepositories(cwd);
37
+ let first;
38
+ for (const { remote, repository } of candidates) {
39
+ const lookup = findConfigFor(repository, project);
40
+ if (lookup.kind === 'found')
41
+ return { kind: 'found', remote, repository, found: lookup.found };
42
+ if (lookup.kind === 'unknown-project' || lookup.kind === 'ambiguous')
43
+ return { kind: 'failed', repository, lookup };
44
+ first ??= { kind: 'failed', repository, lookup };
45
+ }
46
+ return first ?? { kind: 'no-remote' };
47
+ }
48
+ //# sourceMappingURL=remote-config.js.map
@@ -8,7 +8,7 @@ import type { SetupResult } from './worktree-setup.js';
8
8
  /**
9
9
  WorktreeRuntimeError の原因の名前。commands の FailureKind の一部
10
10
  */
11
- export type WorktreeFailure = 'config-invalid' | 'git-unresolved' | 'no-active-project' | 'not-initialized' | 'other' | 'repo-not-in-project' | 'repo-setting-missing';
11
+ export type WorktreeFailure = 'config-invalid' | 'git-unresolved' | 'no-active-project' | 'not-initialized' | 'other' | 'project-not-found' | 'repo-not-in-project' | 'repo-setting-missing';
12
12
  /**
13
13
  ワークツリー操作に失敗した(Python の RuntimeError に当たる)。メッセージは利用者に見せる文
14
14
  */
@@ -160,6 +160,10 @@ export interface CreateWorktreeOptions {
160
160
  既存ブランチの upstream が develop_branch と異なる場合でも再利用を許可するか。既定は false
161
161
  */
162
162
  readonly isExistingBranchAllowed?: boolean | undefined;
163
+ /**
164
+ 使うプロジェクトの設定の名前。省略時は remote のリポを含む設定
165
+ */
166
+ readonly project?: string | undefined;
163
167
  }
164
168
  /**
165
169
  ワークツリーを作成する。cwd は対象 Git リポジトリのパス。
@@ -11,13 +11,13 @@
11
11
  import { BaseError } from '../domain/errors.js';
12
12
  import { existsSync, readdirSync, readFileSync, rmdirSync, writeFileSync } from 'node:fs';
13
13
  import path from 'node:path';
14
- import { commandHint, formatHinted, hinted, inputHint, inputNameHint, placeholder } from '../domain/command-hint.js';
15
- import { findRepository, getDevelopBranch } from '../domain/config.js';
16
- import { pythonStrip, ValidationFailure } from '../domain/python-format.js';
17
- import { createRepositoryReference } from '../domain/repository-resolver.js';
18
- import { loadActiveConfig } from './config-store.js';
14
+ import { commandHint, formatHinted, hinted, inputHint, inputNameHint } from '../domain/command-hint.js';
15
+ import { getDevelopBranch } from '../domain/config.js';
16
+ import { pythonStrip } from '../domain/python-format.js';
17
+ import { configLookupFailure } from './config-store.js';
18
+ import { findConfigForRemotes } from './remote-config.js';
19
19
  import { isDirectory } from './file-kind.js';
20
- import { GitCommandError, gitToplevel, listRemotes, preferredRemotes, remoteRepository, runGit } from './git.js';
20
+ import { GitCommandError, gitToplevel, runGit } from './git.js';
21
21
  import { toOsError } from './os-error.js';
22
22
  import { normalizePath, resolveRealPath, WORKTREE_CONFIG_FILENAME } from './paths.js';
23
23
  import { createSymlinks, loadConfig, loadCopyExcludeSpec, WorktreeConfigError, } from './worktree-links.js';
@@ -294,22 +294,6 @@ export function filterCopyableFiles(files, spec) {
294
294
  }
295
295
  // オーケストレーション
296
296
  const NO_REMOTE_MESSAGE = 'cannot get the repository information: check that a git remote is set to a GitHub repository URL';
297
- // remote 候補を優先順に返す。origin があれば origin だけ、無ければ git remote の順にすべて。URL を読めない remote の repository は undefined
298
- function readRemoteCandidates(cwd) {
299
- return preferredRemotes(listRemotes(cwd) ?? []).map((remote) => {
300
- const location = remoteRepository(cwd, remote);
301
- if (location === undefined)
302
- return { remote, repository: undefined };
303
- try {
304
- return { remote, repository: createRepositoryReference(location.owner, location.repository) };
305
- }
306
- catch (error) {
307
- if (error instanceof ValidationFailure)
308
- return { remote, repository: undefined };
309
- throw error;
310
- }
311
- });
312
- }
313
297
  // 必須設定ファイルの存在チェック(無ければ早期エラー、init を促す)。(ワークツリー設定ファイルのパス, コピー除外 spec) を返す
314
298
  function loadCopyExcludeSpecOrRaise(mainWorktree, diagnostics) {
315
299
  const configPath = path.join(mainWorktree, WORKTREE_CONFIG_FILENAME);
@@ -326,36 +310,15 @@ function loadCopyExcludeSpecOrRaise(mainWorktree, diagnostics) {
326
310
  throw error;
327
311
  }
328
312
  }
329
- // リポジトリ登録チェック。remote は origin、無ければ登録済みのリポを指す最初の remote、どれも未登録なら最初の remote(未登録として止まる)
330
- function requireRegisteredRepository(cwd) {
331
- const candidates = readRemoteCandidates(cwd);
332
- if (candidates.length === 0)
313
+ // リポジトリ登録チェック。設定にあるリポを指す remote(origin を先に)を選び、そのリポを含む設定を使う
314
+ function requireRegisteredRepository(cwd, project) {
315
+ const lookup = findConfigForRemotes(cwd, project);
316
+ if (lookup.kind === 'found')
317
+ return { repository: lookup.repository, config: lookup.found.config, remote: lookup.remote };
318
+ if (lookup.kind === 'no-remote')
333
319
  throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE, { failure: 'git-unresolved' });
334
- const config = loadActiveConfig();
335
- if (config === undefined) {
336
- throw new WorktreeRuntimeError(hinted `project config not found\n hint: run ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })} to set the project`, { failure: 'no-active-project' });
337
- }
338
- for (const candidate of candidates) {
339
- if (candidate.repository !== undefined && findRepository(config, candidate.repository.owner, candidate.repository.repository) !== undefined) {
340
- return { repository: candidate.repository, config, remote: candidate.remote };
341
- }
342
- }
343
- const repository = candidates[0]?.repository;
344
- if (repository === undefined)
345
- throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE, { failure: 'git-unresolved' });
346
- const registered = config.repositories.length > 0
347
- ? config.repositories.map(item => ` - ${item.owner}/${item.name}`).join('\n')
348
- : ' (none registered)';
349
- throw new WorktreeRuntimeError(hinted `repository ${repository.owner}/${repository.repository} is not registered in the active pecot project
350
-
351
- registered repositories:
352
- ${registered}
353
-
354
- to add this repository to the pecot project:
355
- ${commandHint(['project', 'link'], { repo: `${repository.owner}/${repository.repository}` })}
356
-
357
- to switch to another project:
358
- ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`, { failure: 'repo-not-in-project' });
320
+ const { message, kind } = configLookupFailure(lookup.lookup, lookup.repository, WORKTREE_ADD_PATH);
321
+ throw new WorktreeRuntimeError(message, { failure: kind });
359
322
  }
360
323
  // ベースブランチ決定(プロジェクト設定の develop_branch を使用)
361
324
  function defaultBaseBranch(config, repository) {
@@ -431,8 +394,8 @@ export function createWorktree(cwd, diagnostics, options = {}) {
431
394
  // 1.2 container rebuild 後の stale worktree メタデータを事前に掃除する。
432
395
  // `.git/worktrees/<name>/` だけ残って実体が消えているケース(rebuild や手動 rm -rf のあと)で、add が衝突エラーになるのを防ぐ
433
396
  runGit(['worktree', 'prune'], { cwd: mainWorktree });
434
- // 1.5 リポジトリ登録チェック(アクティブプロジェクト配下か確認)
435
- const { repository, config, remote } = requireRegisteredRepository(cwd);
397
+ // 1.5 リポジトリ登録チェック(remote のリポを含むプロジェクトの設定を選ぶ)
398
+ const { repository, config, remote } = requireRegisteredRepository(cwd, options.project);
436
399
  // 2. 名前決定(プロジェクトセットへの自動参加)
437
400
  const repositoryDirectoryName = path.basename(mainWorktree);
438
401
  const name = options.name ?? getNextSetName(projectRoot, repositoryDirectoryName, { claimed: claimedSetNames(mainWorktree) });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "8.0.1-dev.50",
3
+ "version": "8.0.1-dev.52",
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.50",
9
+ "version": "8.0.1-dev.52",
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.50",
3
+ "version": "8.0.1-dev.52",
4
4
  "type": "module",
5
5
  "description": "pecot-workflow MCP server (standalone distribution)",
6
6
  "license": "MIT",