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

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 (96) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +5 -58
  3. package/cli/dist/commands/board-add.js +11 -1
  4. package/cli/dist/commands/board-judgment.d.ts +12 -3
  5. package/cli/dist/commands/board-judgment.js +12 -6
  6. package/cli/dist/commands/board-move.js +9 -1
  7. package/cli/dist/commands/board-readiness.d.ts +3 -3
  8. package/cli/dist/commands/board-show.js +5 -2
  9. package/cli/dist/commands/board-sync.js +14 -5
  10. package/cli/dist/commands/board-view.d.ts +94 -5
  11. package/cli/dist/commands/board-view.js +119 -17
  12. package/cli/dist/commands/branch.js +11 -17
  13. package/cli/dist/commands/command-definition.d.ts +19 -2
  14. package/cli/dist/commands/command-definition.js +9 -0
  15. package/cli/dist/commands/failure-kind.d.ts +1 -1
  16. package/cli/dist/commands/failure-kind.js +1 -0
  17. package/cli/dist/commands/issue-board.d.ts +31 -3
  18. package/cli/dist/commands/issue-board.js +28 -4
  19. package/cli/dist/commands/issue-comment.js +19 -2
  20. package/cli/dist/commands/issue-create.js +96 -17
  21. package/cli/dist/commands/issue-dependency.js +51 -14
  22. package/cli/dist/commands/issue-readiness.d.ts +30 -2
  23. package/cli/dist/commands/issue-readiness.js +35 -0
  24. package/cli/dist/commands/issue-reopen.js +18 -3
  25. package/cli/dist/commands/issue-shared.d.ts +11 -5
  26. package/cli/dist/commands/issue-shared.js +25 -6
  27. package/cli/dist/commands/issue-show.js +78 -8
  28. package/cli/dist/commands/names.d.ts +1 -1
  29. package/cli/dist/commands/names.js +3 -3
  30. package/cli/dist/commands/output.d.ts +18 -2
  31. package/cli/dist/commands/output.js +16 -3
  32. package/cli/dist/commands/pr-merge.d.ts +3 -0
  33. package/cli/dist/commands/pr-merge.js +225 -0
  34. package/cli/dist/commands/pr-reference.d.ts +8 -0
  35. package/cli/dist/commands/pr-reference.js +30 -0
  36. package/cli/dist/commands/pr-restack.d.ts +6 -0
  37. package/cli/dist/commands/pr-restack.js +231 -0
  38. package/cli/dist/commands/pr-waiting.d.ts +41 -2
  39. package/cli/dist/commands/pr-waiting.js +74 -37
  40. package/cli/dist/commands/pr.d.ts +10 -6
  41. package/cli/dist/commands/pr.js +214 -111
  42. package/cli/dist/commands/project-sync.d.ts +10 -2
  43. package/cli/dist/commands/project-sync.js +7 -6
  44. package/cli/dist/commands/project.js +174 -17
  45. package/cli/dist/commands/registry.js +2 -0
  46. package/cli/dist/commands/release.js +67 -18
  47. package/cli/dist/commands/renamed-commands.js +0 -1
  48. package/cli/dist/commands/repository-match.js +7 -2
  49. package/cli/dist/commands/restack-reading.d.ts +45 -0
  50. package/cli/dist/commands/restack-reading.js +29 -0
  51. package/cli/dist/commands/session-finish.js +132 -28
  52. package/cli/dist/commands/session-start.js +31 -60
  53. package/cli/dist/commands/session.js +119 -135
  54. package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
  55. package/cli/dist/commands/tracker-sync-security.js +22 -4
  56. package/cli/dist/commands/tracker-sync.d.ts +30 -0
  57. package/cli/dist/commands/tracker-sync.js +15 -0
  58. package/cli/dist/commands/tracker.js +2 -0
  59. package/cli/dist/commands/work-target.d.ts +14 -9
  60. package/cli/dist/commands/work-target.js +19 -19
  61. package/cli/dist/commands/worktree.js +71 -5
  62. package/cli/dist/domain/branch-name.d.ts +7 -0
  63. package/cli/dist/domain/branch-name.js +23 -1
  64. package/cli/dist/domain/command-hint.d.ts +1 -1
  65. package/cli/dist/domain/issue-readout.d.ts +0 -4
  66. package/cli/dist/domain/pull-request.d.ts +20 -3
  67. package/cli/dist/domain/pull-request.js +25 -9
  68. package/cli/dist/domain/readiness.d.ts +17 -0
  69. package/cli/dist/domain/readiness.js +39 -2
  70. package/cli/dist/domain/restack.d.ts +66 -0
  71. package/cli/dist/domain/restack.js +57 -0
  72. package/cli/dist/domain/state.d.ts +41 -12
  73. package/cli/dist/domain/state.js +30 -14
  74. package/cli/dist/domain/work-start.d.ts +0 -4
  75. package/cli/dist/domain/work-start.js +0 -7
  76. package/cli/dist/infra/git.d.ts +69 -0
  77. package/cli/dist/infra/git.js +117 -0
  78. package/cli/dist/infra/github/pulls.d.ts +81 -2
  79. package/cli/dist/infra/github/pulls.js +116 -5
  80. package/cli/dist/infra/github/queries.d.ts +4 -1
  81. package/cli/dist/infra/github/queries.js +47 -32
  82. package/cli/dist/infra/github/readout.js +0 -33
  83. package/cli/dist/infra/paths.d.ts +1 -3
  84. package/cli/dist/infra/paths.js +2 -45
  85. package/cli/dist/infra/state-store.d.ts +3 -8
  86. package/cli/dist/infra/state-store.js +6 -24
  87. package/cli/dist/mcp/result.d.ts +63 -16
  88. package/cli/dist/mcp/result.js +106 -30
  89. package/cli/dist/mcp/server.js +37 -4
  90. package/cli/templates/comment/plan.md +2 -2
  91. package/cli/templates/comment/review-findings.md +3 -2
  92. package/cli/templates/issue/bug.md +13 -4
  93. package/cli/templates/issue/task.md +13 -4
  94. package/cli/templates/workflow/pecot-board-sync.yml +3 -2
  95. package/npm-shrinkwrap.json +2 -2
  96. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { z } from 'zod';
1
2
  import type { ProjectConfig } from '../domain/config.js';
2
3
  import type { TrackerIssue } from '../domain/tracker-body.js';
3
4
  import type { GitHubClient } from '../infra/github/index.js';
@@ -6,6 +7,35 @@ import type { Operation, Output } from './output.js';
6
7
  API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
7
8
  */
8
9
  export declare function settle(out: Output, operation: Operation): void;
10
+ export declare const TRACKER_SYNC_OUTPUT: z.ZodObject<{
11
+ source: z.ZodEnum<{
12
+ dependabot: "dependabot";
13
+ security: "security";
14
+ }>;
15
+ tracker: z.ZodOptional<z.ZodInt>;
16
+ created: z.ZodBoolean;
17
+ added: z.ZodArray<z.ZodObject<{
18
+ kind: z.ZodEnum<{
19
+ "code-scanning": "code-scanning";
20
+ dependabot: "dependabot";
21
+ "pull-request": "pull-request";
22
+ "secret-scanning": "secret-scanning";
23
+ }>;
24
+ number: z.ZodInt;
25
+ }, z.core.$strict>>;
26
+ removed: z.ZodArray<z.ZodObject<{
27
+ kind: z.ZodEnum<{
28
+ "code-scanning": "code-scanning";
29
+ dependabot: "dependabot";
30
+ "pull-request": "pull-request";
31
+ "secret-scanning": "secret-scanning";
32
+ }>;
33
+ number: z.ZodInt;
34
+ }, z.core.$strict>>;
35
+ closed: z.ZodBoolean;
36
+ dryRun: z.ZodOptional<z.ZodLiteral<true>>;
37
+ }, z.core.$strict>;
38
+ export type TrackerSyncData = z.input<typeof TRACKER_SYNC_OUTPUT>;
9
39
  /**
10
40
  tracker sync の各 source の本体が受ける入力
11
41
  */
@@ -1,7 +1,9 @@
1
1
  // tracker sync と session finish が共有する出力の補助。
2
+ import { z } from 'zod';
2
3
  import { TransportFailure } from '../infra/github/client.js';
3
4
  import { GitHubAPIError } from '../infra/github/errors.js';
4
5
  import { requireActiveConfigPlain } from './command-stop.js';
6
+ import { DRY_RUN_FIELD } from './output.js';
5
7
  import { requireReleaseTargetRepository } from './release.js';
6
8
  /**
7
9
  API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
@@ -10,6 +12,19 @@ export function settle(out, operation) {
10
12
  out.planned(operation);
11
13
  out.done(operation);
12
14
  }
15
+ const TRACKER_ENTRY_JSON = z.strictObject({
16
+ kind: z.enum(['pull-request', 'dependabot', 'code-scanning', 'secret-scanning']).describe('Kind of the row: a Dependabot PR, or the kind of security alert'),
17
+ number: z.int().describe('PR or alert number'),
18
+ });
19
+ export const TRACKER_SYNC_OUTPUT = z.strictObject({
20
+ source: z.enum(['dependabot', 'security']).describe('Source synced'),
21
+ tracker: z.int().optional().describe('Number of the Tracker used or created (omitted when there is none, or on dry_run before creation)'),
22
+ created: z.boolean().describe('Whether a new Tracker was created (on dry_run, would be created)'),
23
+ added: z.array(TRACKER_ENTRY_JSON).describe('Rows added to the Tracker list (on dry_run, to be added)'),
24
+ removed: z.array(TRACKER_ENTRY_JSON).describe('Rows removed from the Tracker list (on dry_run, to be removed)'),
25
+ closed: z.boolean().describe('Whether the Tracker was closed because its list became none (on dry_run, would be closed)'),
26
+ dryRun: DRY_RUN_FIELD,
27
+ });
13
28
  /**
14
29
  対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
15
30
  設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
@@ -3,6 +3,7 @@ import { z } from 'zod';
3
3
  import { defineCommand } from './command-definition.js';
4
4
  import { runDependabotSync } from './tracker-sync-dependabot.js';
5
5
  import { runSecuritySync } from './tracker-sync-security.js';
6
+ import { TRACKER_SYNC_OUTPUT } from './tracker-sync.js';
6
7
  const syncCommand = defineCommand({
7
8
  path: ['tracker', 'sync'],
8
9
  description: 'Rewrite the open Tracker\'s list for a source: Dependabot PRs waiting for a human decision, or open security alerts',
@@ -10,6 +11,7 @@ const syncCommand = defineCommand({
10
11
  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)'),
11
12
  dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
12
13
  }),
14
+ output: TRACKER_SYNC_OUTPUT,
13
15
  positional: ['source'],
14
16
  interactive: false,
15
17
  run: async (input, io) => await (input.source === 'dependabot' ? runDependabotSync(input, io) : runSecuritySync(input, io)),
@@ -1,22 +1,27 @@
1
1
  import type { BaseRecord } from '../domain/state.js';
2
2
  import type { Output } from './output.js';
3
3
  export interface RecordWorkTargetOptions {
4
- /**
5
- 真なら、記録の失敗を warning ではなく error の行で出し、終了コード 1 で止める
6
- */
7
- readonly failWithExit?: boolean;
8
4
  /**
9
5
  着手で選んだ base。作業対象を記録できたときに .pecot-base へ書く。省くと .pecot-base は消えたままになる
10
6
  */
11
7
  readonly base?: Readonly<BaseRecord>;
12
8
  }
13
9
  /**
14
- .pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
15
- 失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかを返す
10
+ recordWorkTarget の結果。workDirectory は作れた作業ディレクトリの絶対パス
11
+ */
12
+ export interface RecordedWorkTarget {
13
+ readonly status: 'recorded' | 'failed';
14
+ readonly issue: string;
15
+ readonly workDirectory?: string | undefined;
16
+ }
17
+ /**
18
+ .pecot-base を消してからセッション名のキャッシュを書き、作業ディレクトリを作って `create: work directory ...` の行を出す。
19
+ 作業ディレクトリがすでにあっても同じ行を出す。options.base があれば記録後に .pecot-base も書く。
20
+ 失敗は warning の行。記録できたかと、参照・作業ディレクトリを返す
16
21
  */
17
- export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>): 'recorded' | 'failed';
22
+ export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>): RecordedWorkTarget;
18
23
  /**
19
- 予行の行。recordWorkTarget が書く作業対象(.pecot-active・.pecot-session-title・.pecot-base)を書かずに出す
24
+ 予行の行。recordWorkTarget が作る作業ディレクトリ(と書く .pecot-session-title・.pecot-base)を作らずに出す
20
25
  */
21
- export declare function planWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number): void;
26
+ export declare function planWorkTarget(out: Readonly<Output>, issueNumber: number): void;
22
27
  //# sourceMappingURL=work-target.d.ts.map
@@ -1,10 +1,9 @@
1
- // 作業対象(.pecot-active と .pecot-session-title、作業ディレクトリ)を記録して、結果の行を出す。
1
+ // 作業対象のセッション名のキャッシュ(.pecot-session-title)と作業ディレクトリを作って、結果の行を出す。
2
2
  import { InvalidValueError, ProjectRootNotFoundError } from '../domain/errors.js';
3
3
  import { FLAG_PECOT_BASE } from '../domain/state.js';
4
4
  import { OsError, hasErrorCode, toOsError } from '../infra/os-error.js';
5
5
  import { WORK_DIR } from '../infra/paths.js';
6
- import { ensureWorkDirectory, removeFlag, writeBaseRecord, writeWorkTarget } from '../infra/state-store.js';
7
- import { stopWith } from './command-stop.js';
6
+ import { ensureWorkDirectory, removeFlag, writeBaseRecord, writeSessionTitle } from '../infra/state-store.js';
8
7
  /**
9
8
  記録の失敗として扱う例外か。OS の失敗・値の誤り・プロジェクトルート不明。プログラムの誤りは伝える
10
9
  */
@@ -16,32 +15,33 @@ function describeFailure(error) {
16
15
  return converted instanceof Error ? converted.message : error.message;
17
16
  }
18
17
  /**
19
- .pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
20
- 失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかを返す
18
+ .pecot-base を消してからセッション名のキャッシュを書き、作業ディレクトリを作って `create: work directory ...` の行を出す。
19
+ 作業ディレクトリがすでにあっても同じ行を出す。options.base があれば記録後に .pecot-base も書く。
20
+ 失敗は warning の行。記録できたかと、参照・作業ディレクトリを返す
21
21
  */
22
22
  export function recordWorkTarget(out, owner, repository, issueNumber, title, options = {}) {
23
23
  const issueReference = `${owner}/${repository}/${String(issueNumber)}`;
24
24
  clearBase(out);
25
- let target;
26
25
  try {
27
- writeWorkTarget(issueReference, title);
28
- target = `work target ${issueReference}`;
29
- if (ensureWorkDirectory(issueReference) !== undefined)
30
- target += ` (work directory ${WORK_DIR}/${String(issueNumber)}/)`;
26
+ writeSessionTitle(issueReference, title);
31
27
  }
32
28
  catch (error) {
33
29
  if (!isRecordingFailure(error))
34
30
  throw error;
35
- if (options.failWithExit === true) {
36
- stopWith(out, `could not record the work target: ${describeFailure(error)}`, 'other');
37
- }
38
31
  out.warning(`could not record the work target: ${describeFailure(error)}`);
39
- return 'failed';
32
+ return { status: 'failed', issue: issueReference };
40
33
  }
41
- out.done({ verb: 'set', target });
34
+ const workDirectory = ensureWorkDirectory(issueReference);
35
+ if (workDirectory === undefined)
36
+ out.warning(`could not create ${workDirectoryTarget(issueNumber)}`);
37
+ else
38
+ out.done({ verb: 'create', target: workDirectoryTarget(issueNumber) });
42
39
  if (options.base !== undefined)
43
40
  recordBase(options.base, out);
44
- return 'recorded';
41
+ return { status: 'recorded', issue: issueReference, workDirectory };
42
+ }
43
+ function workDirectoryTarget(issueNumber) {
44
+ return `work directory ${WORK_DIR}/${String(issueNumber)}/`;
45
45
  }
46
46
  function warnBase(out, error) {
47
47
  if (!isRecordingFailure(error))
@@ -74,9 +74,9 @@ function recordBase(record, out) {
74
74
  }
75
75
  }
76
76
  /**
77
- 予行の行。recordWorkTarget が書く作業対象(.pecot-active・.pecot-session-title・.pecot-base)を書かずに出す
77
+ 予行の行。recordWorkTarget が作る作業ディレクトリ(と書く .pecot-session-title・.pecot-base)を作らずに出す
78
78
  */
79
- export function planWorkTarget(out, owner, repository, issueNumber) {
80
- out.planned({ verb: 'set', target: `work target ${owner}/${repository}/${String(issueNumber)}` });
79
+ export function planWorkTarget(out, issueNumber) {
80
+ out.planned({ verb: 'create', target: workDirectoryTarget(issueNumber) });
81
81
  }
82
82
  //# sourceMappingURL=work-target.js.map
@@ -11,7 +11,7 @@ import { hasErrorCode, OsError, toOsError } from '../infra/os-error.js';
11
11
  import { resolveRealPath, WORKTREE_CONFIG_FILENAME, WORKTREE_IGNORE_FILENAME } from '../infra/paths.js';
12
12
  import { createWorktree, detectProjectRoot, ensureDevcontainerEnvironment, findMainWorktree, findWorktreeConfigFile, getWorktreeDirectories, removeWorktree, WorktreeRuntimeError, } from '../infra/worktree.js';
13
13
  import { createSymlinksSafe, DEFAULT_WORKTREEIGNORE_CONTENT, decideOverwrite, getDefaultConfig, loadConfig, planLink, saveConfig, WorktreeConfigError, } from '../infra/worktree-links.js';
14
- import { createOutput, isConfirmed } from './output.js';
14
+ import { createOutput, DRY_RUN_FIELD, isConfirmed } from './output.js';
15
15
  import { defineCommand } from './command-definition.js';
16
16
  import { commandHint, hinted, hintedTextOf, inputHint, placeholder } from './command-hint.js';
17
17
  import { stopWith } from './command-stop.js';
@@ -66,10 +66,19 @@ const worktreeAddInput = z.object({
66
66
  dry_run: dryRunInput,
67
67
  allow_existing_branch: z.boolean().default(false).describe('Allow reusing an existing branch even if its upstream differs from develop_branch'),
68
68
  });
69
+ const ADD_OUTPUT = z.strictObject({
70
+ name: z.string().describe('Name of the worktree (the wtN it was numbered as)'),
71
+ path: z.string().describe('Absolute path of the worktree (on dry_run, where it would be)'),
72
+ branch: z.string().describe('Branch checked out in the worktree'),
73
+ base: z.string().describe('Base branch the worktree branch starts from'),
74
+ setupFailed: z.boolean().optional().describe('true when the setup command failed or timed out, false when it succeeded or was not run (omitted on dry_run)'),
75
+ dryRun: DRY_RUN_FIELD,
76
+ });
69
77
  const worktreeAddCommand = defineCommand({
70
78
  path: ['worktree', 'add'],
71
79
  description: 'Create a new worktree',
72
80
  input: worktreeAddInput,
81
+ output: ADD_OUTPUT,
73
82
  positional: [],
74
83
  shortFlags: { directory: '-D' },
75
84
  aliases: { allow_existing_branch: '--force' },
@@ -94,6 +103,8 @@ function runAdd(input, io) {
94
103
  out.planned(operation);
95
104
  out.done(operation);
96
105
  out.data(result.path);
106
+ const created = { name: result.name, path: result.path, branch: result.branch, base: result.baseBranch };
107
+ out.result(input.dry_run ? created : { ...created, setupFailed: result.setupResult !== undefined && result.setupResult.exitCode !== 0 });
97
108
  if (result.linkedFiles.length > 0)
98
109
  countLinkResults(result.linkedFiles, out);
99
110
  if (result.copiedFiles.length > 0)
@@ -111,10 +122,16 @@ const worktreeRemoveInput = z.object({
111
122
  keep_branch: z.boolean().default(false).describe('Keep the branch'),
112
123
  dry_run: dryRunInput,
113
124
  });
125
+ const REMOVE_OUTPUT = z.strictObject({
126
+ name: z.string().describe('Name of the worktree that was (on dry_run, would be) removed, as given'),
127
+ deletedBranch: z.boolean().describe('Whether the local branch was deleted (false when kept, when the deletion failed, and on dry_run)'),
128
+ dryRun: DRY_RUN_FIELD,
129
+ });
114
130
  const worktreeRemoveCommand = defineCommand({
115
131
  path: ['worktree', 'remove'],
116
132
  description: 'Remove a worktree',
117
133
  input: worktreeRemoveInput,
134
+ output: REMOVE_OUTPUT,
118
135
  positional: ['name'],
119
136
  shortFlags: { directory: '-D', dry_run: '-n' },
120
137
  interactive: false,
@@ -132,14 +149,17 @@ function runRemove(input, io) {
132
149
  if (input.dry_run) {
133
150
  if (!input.keep_branch)
134
151
  out.planned({ verb: 'delete', target: `local branch ${input.name}` });
152
+ out.result({ name: input.name, deletedBranch: false });
135
153
  return 0;
136
154
  }
137
- if (!input.keep_branch) {
155
+ const shouldDelete = !input.keep_branch;
156
+ if (shouldDelete) {
138
157
  if (branchError === undefined)
139
158
  out.done({ verb: 'delete', target: `local branch ${input.name}` });
140
159
  else
141
160
  out.warning(`could not delete local branch ${input.name}: ${branchError}`);
142
161
  }
162
+ out.result({ name: input.name, deletedBranch: shouldDelete && branchError === undefined });
143
163
  return 0;
144
164
  }
145
165
  catch (error) {
@@ -147,10 +167,16 @@ function runRemove(input, io) {
147
167
  }
148
168
  }
149
169
  const worktreeInitInput = z.object({ directory: directorySchema, dry_run: dryRunInput });
170
+ const INIT_OUTPUT = z.strictObject({
171
+ configFile: z.string().describe('Absolute path of the worktree config file (on dry_run, where it would be)'),
172
+ ignoreFile: z.string().describe('Absolute path of the worktree ignore file (on dry_run, where it would be)'),
173
+ dryRun: DRY_RUN_FIELD,
174
+ });
150
175
  const worktreeInitCommand = defineCommand({
151
176
  path: ['worktree', 'init'],
152
177
  description: 'Create the worktree config files in the main worktree',
153
178
  input: worktreeInitInput,
179
+ output: INIT_OUTPUT,
154
180
  positional: [],
155
181
  shortFlags: { directory: '-D', dry_run: '-n' },
156
182
  interactive: false,
@@ -166,9 +192,11 @@ function writeInitFiles(configFile, ignoreFile, config, out) {
166
192
  try {
167
193
  saveConfig(config, configFile);
168
194
  out.done({ verb: 'create', target: `worktree config ${configFile}` });
195
+ out.result({ configFile });
169
196
  mkdirSync(path.dirname(ignoreFile), { recursive: true });
170
197
  writeFileSync(ignoreFile, DEFAULT_WORKTREEIGNORE_CONTENT);
171
198
  out.done({ verb: 'create', target: `worktree ignore file ${ignoreFile}` });
199
+ out.result({ ignoreFile });
172
200
  }
173
201
  catch (error) {
174
202
  throw hasErrorCode(error) ? toOsError(error) : error;
@@ -202,6 +230,7 @@ function runInit(input, io) {
202
230
  if (input.dry_run) {
203
231
  out.planned({ verb: 'create', target: `worktree config ${configFile}` });
204
232
  out.planned({ verb: 'create', target: `worktree ignore file ${ignoreFile}` });
233
+ out.result({ configFile, ignoreFile });
205
234
  return 0;
206
235
  }
207
236
  writeInitFiles(configFile, ignoreFile, getDefaultConfig(targetRepository, path.basename(mainWorktree)), out);
@@ -227,10 +256,21 @@ const worktreeLinkInput = z.object({
227
256
  all: z.boolean().default(false).describe('Apply to all sub-worktrees'),
228
257
  dry_run: dryRunInput,
229
258
  });
259
+ const LINK_ROW = z.strictObject({
260
+ path: z.string().describe('Absolute path of the symlink'),
261
+ destination: z.string().describe('Absolute path the symlink points to'),
262
+ change: z.enum(['create', 'update', 'skip', 'error']).describe('create: a new symlink; update: an existing one was replaced; skip: left as it was; error: could not be made'),
263
+ reason: z.string().optional().describe('Why the link was skipped or failed (omitted for create and update)'),
264
+ });
265
+ const LINK_OUTPUT = z.strictObject({
266
+ links: z.array(LINK_ROW).describe('One entry per link of the config in each target worktree (an empty array when there is no sub-worktree)'),
267
+ dryRun: DRY_RUN_FIELD,
268
+ });
230
269
  const worktreeLinkCommand = defineCommand({
231
270
  path: ['worktree', 'link'],
232
271
  description: 'Apply or update symlinks in existing worktrees',
233
272
  input: worktreeLinkInput,
273
+ output: LINK_OUTPUT,
234
274
  positional: [],
235
275
  shortFlags: { directory: '-D' },
236
276
  interactive: true,
@@ -268,18 +308,33 @@ function plannedOperation(plan, symlinkPath, destination) {
268
308
  return { verb: 'update', target: `symlink ${symlinkPath} -> ${destination} (real file, asks first)` };
269
309
  return { verb: 'skip', target: `symlink ${symlinkPath} (${skipReason(plan)})` };
270
310
  }
311
+ function plannedEntry(plan, symlinkPath, destination) {
312
+ if (plan === 'create')
313
+ return { path: symlinkPath, destination, change: 'create' };
314
+ if (plan === 'update')
315
+ return { path: symlinkPath, destination, change: 'update' };
316
+ if (plan === 'ask')
317
+ return { path: symlinkPath, destination, change: 'update', reason: 'a real file exists; it is replaced only after confirmation' };
318
+ return { path: symlinkPath, destination, change: 'skip', reason: skipReason(plan) };
319
+ }
271
320
  function previewLinks(targets, config, projectRoot, options, out) {
272
321
  const decision = decideOverwrite({ force: options.force, allWorktrees: options.all });
322
+ const links = [];
273
323
  for (const target of targets) {
274
324
  for (const link of config.links) {
275
325
  const destination = path.join(projectRoot, 'base', link.target_repo, link.target_path);
276
- out.planned(plannedOperation(planLink(link, projectRoot, target, decision), path.join(target, link.path), destination));
326
+ const plan = planLink(link, projectRoot, target, decision);
327
+ out.planned(plannedOperation(plan, path.join(target, link.path), destination));
328
+ links.push(plannedEntry(plan, path.join(target, link.path), destination));
277
329
  }
278
330
  }
331
+ out.result({ links });
279
332
  }
280
333
  // 1 つの worktree にリンクを作り、(作った数, 飛ばした数, 失敗した数) を返す
281
334
  function applyLinks(target, config, projectRoot, options, io, out) {
282
335
  const decision = decideOverwrite({ force: options.force, allWorktrees: options.all });
336
+ // 作る前の計画で、新しい symlink か置き換えかを分ける。結果は config.links と同じ順に返る
337
+ const plans = config.links.map(link => planLink(link, projectRoot, target, decision));
283
338
  const results = createSymlinksSafe(config, projectRoot, target, out, {
284
339
  force: decision.force,
285
340
  confirm: decision.ask ? symlinkPath => isConfirmed(io, `real file exists: ${symlinkPath}\noverwrite it?`) : undefined,
@@ -289,7 +344,13 @@ function applyLinks(target, config, projectRoot, options, io, out) {
289
344
  out.count(`symlinks created in ${target}`, created.length);
290
345
  for (const result of skipped)
291
346
  out.done({ verb: 'skip', target: `symlink ${result.symlinkPath} (${result.message})` });
292
- return [created.length, skipped.length, results.filter(result => result.action === 'error').length];
347
+ const links = results.map((result, index) => {
348
+ const base = { path: result.symlinkPath, destination: result.targetPath };
349
+ if (result.action === 'created')
350
+ return { ...base, change: plans.at(index) === 'create' ? 'create' : 'update' };
351
+ return { ...base, change: result.action === 'skipped' ? 'skip' : 'error', reason: result.message };
352
+ });
353
+ return { counts: [created.length, skipped.length, results.filter(result => result.action === 'error').length], links };
293
354
  }
294
355
  function runLink(input, io) {
295
356
  requireRepositoryMatch('reject', input.repo, io, process.cwd());
@@ -308,6 +369,7 @@ function runLink(input, io) {
308
369
  const targets = resolved.directories;
309
370
  if (targets.length === 0) {
310
371
  out.count('sub-worktrees', 0);
372
+ out.result({ links: [] });
311
373
  return 0;
312
374
  }
313
375
  const options = { force: input.force, all: input.all };
@@ -316,8 +378,12 @@ function runLink(input, io) {
316
378
  return 0;
317
379
  }
318
380
  let [created, skipped, failed] = [0, 0, 0];
381
+ const links = [];
319
382
  for (const target of targets) {
320
- const [targetCreated, targetSkipped, targetFailed] = applyLinks(target, config, projectRoot, options, io, out);
383
+ const applied = applyLinks(target, config, projectRoot, options, io, out);
384
+ const [targetCreated, targetSkipped, targetFailed] = applied.counts;
385
+ links.push(...applied.links);
386
+ out.result({ links: [...links] });
321
387
  created += targetCreated;
322
388
  skipped += targetSkipped;
323
389
  failed += targetFailed;
@@ -1,5 +1,12 @@
1
+ import type { IssueReference } from './reference-parser.js';
2
+ import type { RepositoryReference } from './repository-resolver.js';
1
3
  /**
2
4
  ブランチ名の末尾の Issue 番号。末尾が数字だけの区切りでなければ undefined
3
5
  */
4
6
  export declare function extractIssueNumberFromBranch(branch: string): number | undefined;
7
+ /**
8
+ 作業中の Issue。remote のリポとブランチ名の末尾の番号から決める。
9
+ remote かブランチが無いとき、末尾が数字だけの区切りでないとき、番号が 0 のときは undefined。detached HEAD の `HEAD` も undefined になる
10
+ */
11
+ export declare function activeIssueFromBranch(remote: Readonly<RepositoryReference> | undefined, branch: string | undefined): IssueReference | undefined;
5
12
  //# sourceMappingURL=branch-name.d.ts.map
@@ -1,5 +1,7 @@
1
1
  // ブランチ名の読み取り。pecot session start が作る名前は、末尾が `/Issue番号` になる。
2
- import { parsePythonInteger } from './python-format.js';
2
+ import { parsePythonInteger, ValidationFailure } from './python-format.js';
3
+ import { createIssueReference } from './reference-parser.js';
4
+ import { createRepositoryReference } from './repository-resolver.js';
3
5
  /**
4
6
  ブランチ名の末尾の Issue 番号。末尾が数字だけの区切りでなければ undefined
5
7
  */
@@ -7,4 +9,24 @@ export function extractIssueNumberFromBranch(branch) {
7
9
  const last = branch.split('/').at(-1) ?? '';
8
10
  return /^\p{Nd}+$/u.test(last) ? parsePythonInteger(last) : undefined;
9
11
  }
12
+ /**
13
+ 作業中の Issue。remote のリポとブランチ名の末尾の番号から決める。
14
+ remote かブランチが無いとき、末尾が数字だけの区切りでないとき、番号が 0 のときは undefined。detached HEAD の `HEAD` も undefined になる
15
+ */
16
+ export function activeIssueFromBranch(remote, branch) {
17
+ if (remote === undefined || branch === undefined)
18
+ return undefined;
19
+ const number = extractIssueNumberFromBranch(branch);
20
+ if (number === undefined || number <= 0)
21
+ return undefined;
22
+ try {
23
+ return createIssueReference(createRepositoryReference(remote.owner, remote.repository), number);
24
+ }
25
+ catch (error) {
26
+ // owner・repo に使えない文字が入った remote は、形の合わない remote として扱う
27
+ if (error instanceof ValidationFailure)
28
+ return undefined;
29
+ throw error;
30
+ }
31
+ }
10
32
  //# sourceMappingURL=branch-name.js.map
@@ -18,7 +18,7 @@ export interface CommandHint {
18
18
  readonly input: Readonly<Record<string, HintValue>>;
19
19
  }
20
20
  /**
21
- 入力 1 つだけの案内(`--allow-cross-repo` の形)
21
+ 入力 1 つだけの案内(`--dry-run` の形)
22
22
  */
23
23
  export interface InputHint {
24
24
  readonly kind: 'input';
@@ -58,10 +58,6 @@ export interface IssueReadout {
58
58
  closedByPullRequestsReferences(includeClosedPrs: true) の PR
59
59
  */
60
60
  readonly closingPullRequests: readonly PullRequestReadout[];
61
- /**
62
- timelineItems の PR。ConnectedEvent のうち後で外されていないものと、CrossReferencedEvent のうち閉じる参照か、head が `/<Issue 番号>` で終わるもの
63
- */
64
- readonly timelinePullRequests: readonly PullRequestReadout[];
65
61
  }
66
62
  export interface TargetIssueReadout extends IssueReadout {
67
63
  readonly body: string;
@@ -2,6 +2,7 @@ import type { HintedText } from './command-hint.js';
2
2
  import type { PullRequestReadout } from './issue-readout.js';
3
3
  import type { SectionHeading } from './sections.js';
4
4
  import type { BaseReading } from './state.js';
5
+ import type { RestackDecision } from './restack.js';
5
6
  export declare const SCREENSHOT_MISSING_ERROR: HintedText;
6
7
  /**
7
8
  本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
@@ -52,7 +53,7 @@ export interface PullRequestBaseInput {
52
53
  readonly base: string;
53
54
  readonly developBranch: string;
54
55
  /**
55
- 下の段のブランチを head に持つ PR(pickBasePullRequest で選んだもの)。積んだ記録のときだけ見る
56
+ 下の段のブランチを head に持つ PR(pickLowerPullRequest で選んだもの)。積んだ記録のときだけ見る
56
57
  */
57
58
  readonly lowerPullRequest?: Readonly<PullRequestReadout> | undefined;
58
59
  }
@@ -166,7 +167,7 @@ export declare function formatPullRequestWithReviewsMarkdown(pr: PullRequestWith
166
167
  export interface PreflightWarning {
167
168
  readonly label: string;
168
169
  readonly message: string;
169
- readonly fixHint: string;
170
+ readonly fixHint: HintedText;
170
171
  }
171
172
  /**
172
173
  `git status` の出力に変更があるか。空・取得失敗の印・「nothing to commit」かつ「working tree clean」は無し
@@ -179,16 +180,32 @@ export declare function hasStashEntries(stashList: string): boolean;
179
180
  export interface PushStatus {
180
181
  readonly isPushed: boolean;
181
182
  readonly message: string;
183
+ /**
184
+ 手元と remote の両方に、相手に無いコミットがあるか
185
+ */
186
+ readonly isDiverged: boolean;
182
187
  }
183
188
  /**
184
189
  ahead と behind のコミット数から、push の状態の文を作る
185
190
  */
186
191
  export declare function describePushStatus(remote: string, branch: string, ahead: number, behind: number): PushStatus;
192
+ /**
193
+ diverged の直し方。fast-forward でない push は拒まれるので、取り込むか、書き換えたなら lease 付きで上書きする
194
+ */
195
+ export declare const DIVERGED_FIX_HINT: HintedText;
196
+ /**
197
+ 積んだブランチが diverged のときの直し方。載せ直しが要れば pr restack、要らなければ diverged の直し方、決められなければ pr restack --check
198
+ */
199
+ export declare function pushFixHintOf(decision: Readonly<RestackDecision> | undefined): HintedText;
187
200
  export interface PreflightFacts {
188
201
  readonly gitStatus: string;
189
202
  readonly stashList: string;
190
203
  readonly isPushed: boolean;
191
204
  readonly pushMessage: string;
205
+ /**
206
+ Push Status の直し方。省くと git push
207
+ */
208
+ readonly pushFixHint?: HintedText | undefined;
192
209
  }
193
210
  /**
194
211
  警告を、未 push・変更あり・stash ありの順で返す
@@ -197,5 +214,5 @@ export declare function collectPreflightWarnings(facts: Readonly<PreflightFacts>
197
214
  /**
198
215
  警告 1 行の文
199
216
  */
200
- export declare function formatPreflightWarning(warning: PreflightWarning): string;
217
+ export declare function formatPreflightWarning(warning: PreflightWarning): HintedText;
201
218
  //# sourceMappingURL=pull-request.d.ts.map
@@ -1,8 +1,9 @@
1
1
  // PR コマンドの入出力を持たない関数。本文の検証、Closes の抽出と追記、`pr show` の Markdown の整形、preflight の警告の判定。
2
2
  // 引数の型は、infra/github/pulls.ts の返す値が構造として満たす形をここに持つ(domain は infra を import できない)。
3
- import { hinted, inputHint, inputNameHint } from './command-hint.js';
3
+ import { commandHint, hinted, inputHint, inputNameHint, joinHinted } from './command-hint.js';
4
4
  import { parsePythonInteger, pythonRightStrip, pythonStrip, splitCodePoints, truncateCodePoints } from './python-format.js';
5
5
  import { hasSummaryImage, validateBodyStyle, validateHeadingSummaries, validateSections } from './sections.js';
6
+ import { RESTACK_PATH } from './restack.js';
6
7
  // Issue 参照(`#N`、URL 内のフラグメントは除く)。`owner/repo#N` の形も受ける
7
8
  const ISSUE_REFERENCE_PATTERN = /(?:^|[^/])#\d+|[\w-]+\/[\w.-]+#\d+/u;
8
9
  // Python の `\s`(str.isspace)と同じ空白
@@ -250,12 +251,27 @@ ahead と behind のコミット数から、push の状態の文を作る
250
251
  */
251
252
  export function describePushStatus(remote, branch, ahead, behind) {
252
253
  if (ahead === 0 && behind === 0)
253
- return { isPushed: true, message: `in sync with ${remote}/${branch}` };
254
+ return { isPushed: true, message: `in sync with ${remote}/${branch}`, isDiverged: false };
254
255
  if (behind === 0)
255
- return { isPushed: false, message: `${String(ahead)} unpushed commits` };
256
+ return { isPushed: false, message: `${String(ahead)} unpushed commits`, isDiverged: false };
256
257
  if (ahead === 0)
257
- return { isPushed: true, message: `${remote}/${branch} is ${String(behind)} commits ahead (pull recommended)` };
258
- return { isPushed: false, message: `diverged: local is ${String(ahead)} commits ahead, ${remote}/${branch} is ${String(behind)} ahead` };
258
+ return { isPushed: true, message: `${remote}/${branch} is ${String(behind)} commits ahead (pull recommended)`, isDiverged: false };
259
+ return { isPushed: false, message: `diverged: local is ${String(ahead)} commits ahead, ${remote}/${branch} is ${String(behind)} ahead`, isDiverged: true };
260
+ }
261
+ // 文の中にロングオプションを書けない(lint)ので、git の引数から組む
262
+ const PULL_REBASE_COMMAND = ['git', 'pull', '--rebase'].join(' ');
263
+ const FORCE_PUSH_COMMAND = ['git', 'push', '--force-with-lease'].join(' ');
264
+ /**
265
+ diverged の直し方。fast-forward でない push は拒まれるので、取り込むか、書き換えたなら lease 付きで上書きする
266
+ */
267
+ export const DIVERGED_FIX_HINT = hinted `${PULL_REBASE_COMMAND}, or ${FORCE_PUSH_COMMAND} if you rewrote pushed commits`;
268
+ /**
269
+ 積んだブランチが diverged のときの直し方。載せ直しが要れば pr restack、要らなければ diverged の直し方、決められなければ pr restack --check
270
+ */
271
+ export function pushFixHintOf(decision) {
272
+ if (decision === undefined || decision.kind === 'gone')
273
+ return hinted `${commandHint(RESTACK_PATH, { check: true })}`;
274
+ return decision.kind === 'moved' || decision.kind === 'merged' ? hinted `${commandHint(RESTACK_PATH)}` : DIVERGED_FIX_HINT;
259
275
  }
260
276
  /**
261
277
  警告を、未 push・変更あり・stash ありの順で返す
@@ -263,12 +279,12 @@ export function describePushStatus(remote, branch, ahead, behind) {
263
279
  export function collectPreflightWarnings(facts) {
264
280
  const warnings = [];
265
281
  if (!facts.isPushed)
266
- warnings.push({ label: 'Push Status', message: facts.pushMessage, fixHint: 'git push' });
282
+ warnings.push({ label: 'Push Status', message: facts.pushMessage, fixHint: facts.pushFixHint ?? hinted `git push` });
267
283
  if (hasStatusChanges(facts.gitStatus))
268
- warnings.push({ label: 'Git Status', message: 'modified or untracked files', fixHint: 'commit' });
284
+ warnings.push({ label: 'Git Status', message: 'modified or untracked files', fixHint: hinted `commit` });
269
285
  if (hasStashEntries(facts.stashList)) {
270
286
  const count = facts.stashList.split(LINE_BREAK).filter(line => pythonStrip(line) !== '').length;
271
- warnings.push({ label: 'Stash List', message: `${String(count)} stash entries`, fixHint: 'check them' });
287
+ warnings.push({ label: 'Stash List', message: `${String(count)} stash entries`, fixHint: hinted `check them` });
272
288
  }
273
289
  return warnings;
274
290
  }
@@ -276,6 +292,6 @@ export function collectPreflightWarnings(facts) {
276
292
  警告 1 行の文
277
293
  */
278
294
  export function formatPreflightWarning(warning) {
279
- return `${warning.label}: ${warning.message} (fix: ${warning.fixHint})`;
295
+ return joinHinted([`${warning.label}: ${warning.message} (fix: `, warning.fixHint, ')'], '');
280
296
  }
281
297
  //# sourceMappingURL=pull-request.js.map
@@ -166,6 +166,23 @@ blocked by の後には、済んでいない前提をすべて並べる。別の
166
166
  */
167
167
  export declare function describeReadiness(readiness: Readiness, prerequisites: readonly Prerequisite[], targetRepository: RepositoryReference): string;
168
168
  /**
169
+ issues の前提と、その pullRequest を state にしたものとして置き換える。一覧に pullRequest が無ければ足す。
170
+ マージの後の読み取りから、マージの前(open)や閉じた後(merged)の判定を作るのに使う
171
+ */
172
+ export declare function assumePullRequestState(prerequisites: readonly Prerequisite[], issues: readonly IssueReference[], pullRequest: IssuePullRequest, state: 'open' | 'merged'): readonly Prerequisite[];
173
+ /**
174
+ 判定の区分か積む先のブランチが違うか。理由と注記の違いは変化としない
175
+ */
176
+ export declare function hasReadinessChanged(before: Readiness, after: Readiness): boolean;
177
+ /**
178
+ 判定の変化の行の文。blocked は理由を付けず、stackable は積む先を付ける
179
+ */
180
+ export declare function describeReadinessChange(readiness: Readiness, targetRepository: RepositoryReference): string;
181
+ /**
182
+ 着手の跡があり、issues のどれかを stack で待つ(その上に積んだ段の)Issue か
183
+ */
184
+ export declare function isStackedOn(target: IssueFacts, prerequisites: readonly Prerequisite[], issues: readonly IssueReference[]): boolean;
185
+ /**
169
186
  読めなかった Issue の表示。列と札は動かさない
170
187
  */
171
188
  export declare function describeUnknown(reason: string): string;