@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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +5 -58
- package/cli/dist/commands/board-add.js +11 -1
- package/cli/dist/commands/board-judgment.d.ts +12 -3
- package/cli/dist/commands/board-judgment.js +12 -6
- package/cli/dist/commands/board-move.js +9 -1
- package/cli/dist/commands/board-readiness.d.ts +3 -3
- package/cli/dist/commands/board-show.js +5 -2
- package/cli/dist/commands/board-sync.js +14 -5
- package/cli/dist/commands/board-view.d.ts +94 -5
- package/cli/dist/commands/board-view.js +119 -17
- package/cli/dist/commands/branch.js +11 -17
- package/cli/dist/commands/command-definition.d.ts +19 -2
- package/cli/dist/commands/command-definition.js +9 -0
- package/cli/dist/commands/failure-kind.d.ts +1 -1
- package/cli/dist/commands/failure-kind.js +1 -0
- package/cli/dist/commands/issue-board.d.ts +31 -3
- package/cli/dist/commands/issue-board.js +28 -4
- package/cli/dist/commands/issue-comment.js +19 -2
- package/cli/dist/commands/issue-create.js +96 -17
- package/cli/dist/commands/issue-dependency.js +51 -14
- package/cli/dist/commands/issue-readiness.d.ts +30 -2
- package/cli/dist/commands/issue-readiness.js +35 -0
- package/cli/dist/commands/issue-reopen.js +18 -3
- package/cli/dist/commands/issue-shared.d.ts +11 -5
- package/cli/dist/commands/issue-shared.js +25 -6
- package/cli/dist/commands/issue-show.js +78 -8
- package/cli/dist/commands/names.d.ts +1 -1
- package/cli/dist/commands/names.js +3 -3
- package/cli/dist/commands/output.d.ts +18 -2
- package/cli/dist/commands/output.js +16 -3
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +225 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +231 -0
- package/cli/dist/commands/pr-waiting.d.ts +41 -2
- package/cli/dist/commands/pr-waiting.js +74 -37
- package/cli/dist/commands/pr.d.ts +10 -6
- package/cli/dist/commands/pr.js +214 -111
- package/cli/dist/commands/project-sync.d.ts +10 -2
- package/cli/dist/commands/project-sync.js +7 -6
- package/cli/dist/commands/project.js +174 -17
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +67 -18
- package/cli/dist/commands/renamed-commands.js +0 -1
- package/cli/dist/commands/repository-match.js +7 -2
- package/cli/dist/commands/restack-reading.d.ts +45 -0
- package/cli/dist/commands/restack-reading.js +29 -0
- package/cli/dist/commands/session-finish.js +132 -28
- package/cli/dist/commands/session-start.js +31 -60
- package/cli/dist/commands/session.js +119 -135
- package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
- package/cli/dist/commands/tracker-sync-security.js +22 -4
- package/cli/dist/commands/tracker-sync.d.ts +30 -0
- package/cli/dist/commands/tracker-sync.js +15 -0
- package/cli/dist/commands/tracker.js +2 -0
- package/cli/dist/commands/work-target.d.ts +14 -9
- package/cli/dist/commands/work-target.js +19 -19
- package/cli/dist/commands/worktree.js +71 -5
- package/cli/dist/domain/branch-name.d.ts +7 -0
- package/cli/dist/domain/branch-name.js +23 -1
- package/cli/dist/domain/command-hint.d.ts +1 -1
- package/cli/dist/domain/issue-readout.d.ts +0 -4
- package/cli/dist/domain/pull-request.d.ts +20 -3
- package/cli/dist/domain/pull-request.js +25 -9
- package/cli/dist/domain/readiness.d.ts +17 -0
- package/cli/dist/domain/readiness.js +39 -2
- package/cli/dist/domain/restack.d.ts +66 -0
- package/cli/dist/domain/restack.js +57 -0
- package/cli/dist/domain/state.d.ts +41 -12
- package/cli/dist/domain/state.js +30 -14
- package/cli/dist/domain/work-start.d.ts +0 -4
- package/cli/dist/domain/work-start.js +0 -7
- package/cli/dist/infra/git.d.ts +69 -0
- package/cli/dist/infra/git.js +117 -0
- package/cli/dist/infra/github/pulls.d.ts +81 -2
- package/cli/dist/infra/github/pulls.js +116 -5
- package/cli/dist/infra/github/queries.d.ts +4 -1
- package/cli/dist/infra/github/queries.js +47 -32
- package/cli/dist/infra/github/readout.js +0 -33
- package/cli/dist/infra/paths.d.ts +1 -3
- package/cli/dist/infra/paths.js +2 -45
- package/cli/dist/infra/state-store.d.ts +3 -8
- package/cli/dist/infra/state-store.js +6 -24
- package/cli/dist/mcp/result.d.ts +63 -16
- package/cli/dist/mcp/result.js +106 -30
- package/cli/dist/mcp/server.js +37 -4
- package/cli/templates/comment/plan.md +2 -2
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +3 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -314,6 +314,43 @@ export function describeReadiness(readiness, prerequisites, targetRepository) {
|
|
|
314
314
|
return `blocked${unfinished.length === 0 ? '' : ` by ${unfinished.join(', ')}`}${reason}`;
|
|
315
315
|
}
|
|
316
316
|
/**
|
|
317
|
+
issues の前提と、その pullRequest を state にしたものとして置き換える。一覧に pullRequest が無ければ足す。
|
|
318
|
+
マージの後の読み取りから、マージの前(open)や閉じた後(merged)の判定を作るのに使う
|
|
319
|
+
*/
|
|
320
|
+
export function assumePullRequestState(prerequisites, issues, pullRequest, state) {
|
|
321
|
+
const keys = new Set(issues.map(issue => issueReferenceKey(issue)));
|
|
322
|
+
const assumed = { ...pullRequest, state };
|
|
323
|
+
const isSame = (other) => other.number === pullRequest.number && isSameRepository(other.repository, pullRequest.repository);
|
|
324
|
+
return prerequisites.map((prerequisite) => {
|
|
325
|
+
const { issue } = prerequisite;
|
|
326
|
+
if (!keys.has(issueReferenceKey(issue.ref)))
|
|
327
|
+
return prerequisite;
|
|
328
|
+
const pullRequests = issue.pullRequests.some(other => isSame(other))
|
|
329
|
+
? issue.pullRequests.map(other => (isSame(other) ? assumed : other))
|
|
330
|
+
: [...issue.pullRequests, assumed];
|
|
331
|
+
return { ...prerequisite, issue: { ...issue, state: state === 'open' ? 'open' : 'closed', pullRequests } };
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
判定の区分か積む先のブランチが違うか。理由と注記の違いは変化としない
|
|
336
|
+
*/
|
|
337
|
+
export function hasReadinessChanged(before, after) {
|
|
338
|
+
return before.kind !== after.kind || before.stackOn?.branch !== after.stackOn?.branch;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
判定の変化の行の文。blocked は理由を付けず、stackable は積む先を付ける
|
|
342
|
+
*/
|
|
343
|
+
export function describeReadinessChange(readiness, targetRepository) {
|
|
344
|
+
return readiness.kind === 'blocked' ? 'blocked' : describeReadiness(readiness, [], targetRepository);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
着手の跡があり、issues のどれかを stack で待つ(その上に積んだ段の)Issue か
|
|
348
|
+
*/
|
|
349
|
+
export function isStackedOn(target, prerequisites, issues) {
|
|
350
|
+
const keys = new Set(issues.map(issue => issueReferenceKey(issue)));
|
|
351
|
+
return hasStarted(target) && prerequisites.some(({ issue, wait }) => wait === 'stack' && keys.has(issueReferenceKey(issue.ref)));
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
317
354
|
読めなかった Issue の表示。列と札は動かさない
|
|
318
355
|
*/
|
|
319
356
|
export function describeUnknown(reason) {
|
|
@@ -331,12 +368,12 @@ function toPullRequest(readout) {
|
|
|
331
368
|
isCrossRepository: readout.isCrossRepository,
|
|
332
369
|
};
|
|
333
370
|
}
|
|
334
|
-
//
|
|
371
|
+
// 積んだ PR は開いている間 Development 欄に載らず、マージ済みの PR はブランチが消えるので、2 つの読み口を合わせる。
|
|
372
|
+
// 同じ PR は 1 本に数え、fork からの PR は、リンクしたブランチの読み口だけ捨てる
|
|
335
373
|
function collectPullRequests(readout) {
|
|
336
374
|
const sources = [
|
|
337
375
|
...readout.linkedBranches.flatMap(branch => branch.pullRequests).filter(pullRequest => !pullRequest.isCrossRepository),
|
|
338
376
|
...readout.closingPullRequests,
|
|
339
|
-
...readout.timelinePullRequests,
|
|
340
377
|
];
|
|
341
378
|
const seen = new Set();
|
|
342
379
|
return sources
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { PullRequestReadout } from './issue-readout.js';
|
|
2
|
+
import type { BaseReading } from './state.js';
|
|
3
|
+
/**
|
|
4
|
+
pr restack のコマンドの path。案内(commandHint)とコマンドの定義が共有する
|
|
5
|
+
*/
|
|
6
|
+
export declare const RESTACK_PATH: readonly string[];
|
|
7
|
+
export interface RestackInput {
|
|
8
|
+
/**
|
|
9
|
+
base の記録。形の誤りは呼び出し側が先に止める
|
|
10
|
+
*/
|
|
11
|
+
readonly reading: Exclude<BaseReading, {
|
|
12
|
+
kind: 'malformed';
|
|
13
|
+
}>;
|
|
14
|
+
readonly developBranch: string;
|
|
15
|
+
/**
|
|
16
|
+
下の段のブランチを head に持つ PR(pickLowerPullRequest で選んだもの)
|
|
17
|
+
*/
|
|
18
|
+
readonly lowerPullRequest: Readonly<PullRequestReadout> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
下の段のブランチの、remote の先頭の SHA。remote に無ければ undefined
|
|
21
|
+
*/
|
|
22
|
+
readonly lowerHead: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
export type RestackDecision = {
|
|
25
|
+
readonly kind: 'not-stacked';
|
|
26
|
+
readonly base: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: 'up-to-date';
|
|
29
|
+
readonly base: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: 'moved';
|
|
32
|
+
readonly base: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'merged';
|
|
35
|
+
readonly base: string;
|
|
36
|
+
readonly pullRequest: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'gone';
|
|
39
|
+
readonly base: string;
|
|
40
|
+
readonly pullRequest: number | undefined;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
|
|
44
|
+
*/
|
|
45
|
+
export declare function decideRestack(input: Readonly<RestackInput>): RestackDecision;
|
|
46
|
+
/**
|
|
47
|
+
`pr restack --check` の行
|
|
48
|
+
*/
|
|
49
|
+
export declare function describeRestackCheck(branch: string, decision: Exclude<RestackDecision, {
|
|
50
|
+
kind: 'gone';
|
|
51
|
+
}>): string;
|
|
52
|
+
/**
|
|
53
|
+
下の段のブランチが消えていて、マージもされていないときの文(`error: ` の前置きを含まない)
|
|
54
|
+
*/
|
|
55
|
+
export declare function describeGone(decision: Extract<RestackDecision, {
|
|
56
|
+
kind: 'gone';
|
|
57
|
+
}>): string;
|
|
58
|
+
/**
|
|
59
|
+
載せ直しが要るか。下の段が消えていて決められないときは undefined
|
|
60
|
+
*/
|
|
61
|
+
export declare function needsRestack(decision: Readonly<RestackDecision>): boolean | undefined;
|
|
62
|
+
/**
|
|
63
|
+
session show の `- needs restack:` の行。決められないときは undefined
|
|
64
|
+
*/
|
|
65
|
+
export declare function describeNeedsRestack(decision: Readonly<RestackDecision>): string | undefined;
|
|
66
|
+
//# sourceMappingURL=restack.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// 積んだブランチを載せ直す先の判断と、その表示。git と GitHub の読み取りは commands が行う。
|
|
2
|
+
/**
|
|
3
|
+
pr restack のコマンドの path。案内(commandHint)とコマンドの定義が共有する
|
|
4
|
+
*/
|
|
5
|
+
export const RESTACK_PATH = ['pr', 'restack'];
|
|
6
|
+
/**
|
|
7
|
+
載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
|
|
8
|
+
*/
|
|
9
|
+
export function decideRestack(input) {
|
|
10
|
+
const { reading, developBranch, lowerPullRequest, lowerHead } = input;
|
|
11
|
+
if (reading.kind === 'development')
|
|
12
|
+
return { kind: 'not-stacked', base: developBranch };
|
|
13
|
+
const { branch, sha } = reading.record;
|
|
14
|
+
if (lowerPullRequest?.state === 'MERGED')
|
|
15
|
+
return { kind: 'merged', base: developBranch, pullRequest: lowerPullRequest.number };
|
|
16
|
+
if (lowerHead === undefined)
|
|
17
|
+
return { kind: 'gone', base: branch, pullRequest: lowerPullRequest?.number };
|
|
18
|
+
return { kind: lowerHead === sha ? 'up-to-date' : 'moved', base: branch };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
`pr restack --check` の行
|
|
22
|
+
*/
|
|
23
|
+
export function describeRestackCheck(branch, decision) {
|
|
24
|
+
switch (decision.kind) {
|
|
25
|
+
case 'not-stacked':
|
|
26
|
+
case 'up-to-date': {
|
|
27
|
+
return `up to date: ${branch} on ${decision.base}`;
|
|
28
|
+
}
|
|
29
|
+
case 'moved': {
|
|
30
|
+
return `needs restack: ${branch} on ${decision.base} (base moved)`;
|
|
31
|
+
}
|
|
32
|
+
case 'merged': {
|
|
33
|
+
return `needs restack: ${branch} onto ${decision.base} (base #${String(decision.pullRequest)} merged)`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
下の段のブランチが消えていて、マージもされていないときの文(`error: ` の前置きを含まない)
|
|
39
|
+
*/
|
|
40
|
+
export function describeGone(decision) {
|
|
41
|
+
const pullRequest = decision.pullRequest === undefined ? 'it has no merged PR' : `PR #${String(decision.pullRequest)} was not merged`;
|
|
42
|
+
return `base branch ${decision.base} is gone and ${pullRequest}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
載せ直しが要るか。下の段が消えていて決められないときは undefined
|
|
46
|
+
*/
|
|
47
|
+
export function needsRestack(decision) {
|
|
48
|
+
return decision.kind === 'gone' ? undefined : decision.kind === 'moved' || decision.kind === 'merged';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
session show の `- needs restack:` の行。決められないときは undefined
|
|
52
|
+
*/
|
|
53
|
+
export function describeNeedsRestack(decision) {
|
|
54
|
+
const needed = needsRestack(decision);
|
|
55
|
+
return needed === undefined ? undefined : `- needs restack: ${needed ? 'yes' : 'no'}`;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=restack.js.map
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import type { IssueReference } from './reference-parser.js';
|
|
2
|
-
export declare const FLAG_PECOT_ACTIVE = ".pecot-active";
|
|
3
2
|
export declare const FLAG_PECOT_SESSION_TITLE = ".pecot-session-title";
|
|
4
3
|
export declare const FLAG_PECOT_BASE = ".pecot-base";
|
|
4
|
+
export declare const FLAG_PECOT_RESTACK = ".pecot-restack";
|
|
5
5
|
export declare const FLAG_PECOT_QUICK_MODE = ".pecot-quick-mode";
|
|
6
|
-
export declare const FLAG_WIP_BRANCH_LINKED = ".wip-branch-linked";
|
|
7
|
-
export declare const FLAG_PR_CREATE_SLASH_PENDING = "pr-create-slash-pending";
|
|
8
|
-
export declare const FLAG_ISSUE_CREATE_SLASH_PENDING = "issue-create-slash-pending";
|
|
9
|
-
export declare const FLAG_MERGE_SLASH_PENDING = "merge-slash-pending";
|
|
10
|
-
export declare const FLAG_ISSUE_PENDING = "issue-pending";
|
|
11
6
|
export declare const SESSION_TITLE_MAX_CHARS = 40;
|
|
12
7
|
/**
|
|
13
8
|
セッション名 `#<番号> <Issue タイトル>` を組み立てる。
|
|
@@ -20,14 +15,10 @@ export declare function formatSessionTitle(issueNumber: number, title: string):
|
|
|
20
15
|
`.pecot/work` の直下は Issue 番号の数字だけにする規約のため、全角数字などは通さない
|
|
21
16
|
*/
|
|
22
17
|
export declare function workDirectoryName(issueReference: string): string | undefined;
|
|
23
|
-
export interface WorkTarget {
|
|
24
|
-
readonly active: string;
|
|
25
|
-
readonly sessionTitle: string;
|
|
26
|
-
}
|
|
27
18
|
/**
|
|
28
|
-
|
|
19
|
+
作業対象のセッション名(.pecot-session-title に書く内容)を決める。参照の末尾が整数でなければ InvalidValueError
|
|
29
20
|
*/
|
|
30
|
-
export declare function planWorkTarget(issueReference: string, title: string):
|
|
21
|
+
export declare function planWorkTarget(issueReference: string, title: string): string;
|
|
31
22
|
export interface BaseRecord {
|
|
32
23
|
readonly branch: string;
|
|
33
24
|
readonly sha: string;
|
|
@@ -56,4 +47,42 @@ export declare function formatBaseRecord(record: Readonly<BaseRecord>): string;
|
|
|
56
47
|
形が誤っていれば malformed
|
|
57
48
|
*/
|
|
58
49
|
export declare function interpretBaseRecord(content: string | undefined): BaseReading;
|
|
50
|
+
export interface RestackProgress {
|
|
51
|
+
readonly remote: string;
|
|
52
|
+
/**
|
|
53
|
+
載せ直しているブランチ。rebase の途中は HEAD が detached なので、ここから読む
|
|
54
|
+
*/
|
|
55
|
+
readonly branch: string;
|
|
56
|
+
/**
|
|
57
|
+
載せ直す前のブランチの先頭。remote にだけある変更が見つかったときに、ここへ戻す
|
|
58
|
+
*/
|
|
59
|
+
readonly originalSha: string;
|
|
60
|
+
readonly ontoBranch: string;
|
|
61
|
+
readonly ontoSha: string;
|
|
62
|
+
/**
|
|
63
|
+
push の `--force-with-lease` に渡す、fetch した時点の remote の SHA。remote にブランチが無ければ undefined
|
|
64
|
+
*/
|
|
65
|
+
readonly leaseSha: string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
載せ直した後も積んだ記録を保つなら、積んだ先の Issue。開発ブランチへ載せ直すなら undefined
|
|
68
|
+
*/
|
|
69
|
+
readonly stackedOn: IssueReference | undefined;
|
|
70
|
+
}
|
|
71
|
+
export type RestackProgressReading = {
|
|
72
|
+
readonly kind: 'none';
|
|
73
|
+
} | {
|
|
74
|
+
readonly kind: 'progress';
|
|
75
|
+
readonly progress: RestackProgress;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'malformed';
|
|
78
|
+
readonly content: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
.pecot-restack の 1 行。`<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N>` で、無い項目は `-`
|
|
82
|
+
*/
|
|
83
|
+
export declare function formatRestackProgress(progress: Readonly<RestackProgress>): string;
|
|
84
|
+
/**
|
|
85
|
+
.pecot-restack の内容を読む。ファイルが無ければ none、形が誤っていれば malformed
|
|
86
|
+
*/
|
|
87
|
+
export declare function interpretRestackProgress(content: string | undefined): RestackProgressReading;
|
|
59
88
|
//# sourceMappingURL=state.d.ts.map
|
package/cli/dist/domain/state.js
CHANGED
|
@@ -4,22 +4,13 @@ import { parsePythonInteger, pythonRightStrip, pythonStrip, pythonStringRepr, tr
|
|
|
4
4
|
import { createIssueReference, issueReferenceToString } from './reference-parser.js';
|
|
5
5
|
import { createRepositoryReference } from './repository-resolver.js';
|
|
6
6
|
// フラグファイル名
|
|
7
|
-
|
|
8
|
-
// セッション名(hooks の session-title.sh が Claude Code の sessionTitle に流す)。.pecot-active と同じタイミングで書く
|
|
7
|
+
// セッション名のキャッシュ(hooks の session-title.sh が Claude Code の sessionTitle に流す)。session start がブランチを作るときに書く
|
|
9
8
|
export const FLAG_PECOT_SESSION_TITLE = '.pecot-session-title';
|
|
10
9
|
// 着手のときに選んだ base(ブランチ・位置・積んだ先の Issue)。session start が書き、session finish が消す
|
|
11
10
|
export const FLAG_PECOT_BASE = '.pecot-base';
|
|
11
|
+
// 衝突で止まった載せ直しの途中の記録。pr restack が書き、続行か取りやめで消す
|
|
12
|
+
export const FLAG_PECOT_RESTACK = '.pecot-restack';
|
|
12
13
|
export const FLAG_PECOT_QUICK_MODE = '.pecot-quick-mode';
|
|
13
|
-
export const FLAG_WIP_BRANCH_LINKED = '.wip-branch-linked';
|
|
14
|
-
// スラッシュコマンド起点の外部反映免除フラグ。
|
|
15
|
-
// 設置は hooks の create-slash-flag.sh が行う。
|
|
16
|
-
// 確認は mcp-handlers/pecot-post-ask.sh(merge は core/external-post-check.sh)が行う。
|
|
17
|
-
// MCP ツールが実投稿成功時に削除する。
|
|
18
|
-
export const FLAG_PR_CREATE_SLASH_PENDING = 'pr-create-slash-pending';
|
|
19
|
-
export const FLAG_ISSUE_CREATE_SLASH_PENDING = 'issue-create-slash-pending';
|
|
20
|
-
export const FLAG_MERGE_SLASH_PENDING = 'merge-slash-pending';
|
|
21
|
-
// 起票未完了のリマインド用フラグ。設置は hooks、確認は pecot-issue-pending-reminder.sh。MCP ツールが起票成功時に削除する
|
|
22
|
-
export const FLAG_ISSUE_PENDING = 'issue-pending';
|
|
23
14
|
export const SESSION_TITLE_MAX_CHARS = 40;
|
|
24
15
|
const ISSUE_TYPE_PREFIX_PATTERN = /^\[(?:Task|Bug|Epic)\]\s*/u;
|
|
25
16
|
/**
|
|
@@ -48,14 +39,14 @@ export function workDirectoryName(issueReference) {
|
|
|
48
39
|
return /^\d+$/u.test(number) ? number : undefined;
|
|
49
40
|
}
|
|
50
41
|
/**
|
|
51
|
-
|
|
42
|
+
作業対象のセッション名(.pecot-session-title に書く内容)を決める。参照の末尾が整数でなければ InvalidValueError
|
|
52
43
|
*/
|
|
53
44
|
export function planWorkTarget(issueReference, title) {
|
|
54
45
|
const text = lastSegment(issueReference);
|
|
55
46
|
const number = parsePythonInteger(text);
|
|
56
47
|
if (number === undefined)
|
|
57
48
|
throw new InvalidValueError(`invalid literal for int() with base 10: ${pythonStringRepr(text)}`);
|
|
58
|
-
return
|
|
49
|
+
return formatSessionTitle(number, title);
|
|
59
50
|
}
|
|
60
51
|
// ブランチ名に空白は入らないので、空白で区切る
|
|
61
52
|
const BASE_SHA_PATTERN = /^(?:[\da-f]{40}|[\da-f]{64})$/u;
|
|
@@ -92,4 +83,29 @@ export function interpretBaseRecord(content) {
|
|
|
92
83
|
const stackedOn = parseStackedOn(issue);
|
|
93
84
|
return stackedOn === undefined ? { kind: 'malformed', content } : { kind: 'stacked', record: { branch, sha, stackedOn }, stackedOn };
|
|
94
85
|
}
|
|
86
|
+
const ABSENT = '-';
|
|
87
|
+
/**
|
|
88
|
+
.pecot-restack の 1 行。`<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N>` で、無い項目は `-`
|
|
89
|
+
*/
|
|
90
|
+
export function formatRestackProgress(progress) {
|
|
91
|
+
const stackedOn = progress.stackedOn === undefined ? ABSENT : issueReferenceToString(progress.stackedOn);
|
|
92
|
+
return [progress.remote, progress.branch, progress.originalSha, progress.ontoBranch, progress.ontoSha, progress.leaseSha ?? ABSENT, stackedOn].join(' ');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
.pecot-restack の内容を読む。ファイルが無ければ none、形が誤っていれば malformed
|
|
96
|
+
*/
|
|
97
|
+
export function interpretRestackProgress(content) {
|
|
98
|
+
if (content === undefined)
|
|
99
|
+
return { kind: 'none' };
|
|
100
|
+
const malformed = { kind: 'malformed', content };
|
|
101
|
+
const [remote, branch, originalSha, ontoBranch, ontoSha, lease, issue, ...rest] = content.split(' ');
|
|
102
|
+
if (remote === undefined || branch === undefined || originalSha === undefined || ontoBranch === undefined || ontoSha === undefined || lease === undefined || issue === undefined || rest.length > 0 || [remote, branch, ontoBranch].includes('') || !BASE_SHA_PATTERN.test(ontoSha) || !BASE_SHA_PATTERN.test(originalSha))
|
|
103
|
+
return malformed;
|
|
104
|
+
if (lease !== ABSENT && !BASE_SHA_PATTERN.test(lease))
|
|
105
|
+
return malformed;
|
|
106
|
+
const stackedOn = issue === ABSENT ? undefined : parseStackedOn(issue);
|
|
107
|
+
if (issue !== ABSENT && stackedOn === undefined)
|
|
108
|
+
return malformed;
|
|
109
|
+
return { kind: 'progress', progress: { remote, branch, originalSha, ontoBranch, ontoSha, leaseSha: lease === ABSENT ? undefined : lease, stackedOn } };
|
|
110
|
+
}
|
|
95
111
|
//# sourceMappingURL=state.js.map
|
|
@@ -24,10 +24,6 @@ export declare function describeBaseMismatch(base: string | undefined, decision:
|
|
|
24
24
|
kind: 'blocked';
|
|
25
25
|
}>, target: IssueReference): HintedText | undefined;
|
|
26
26
|
/**
|
|
27
|
-
base のブランチを head に持つ PR のうち、表に出す 1 本。fork でない open のもの、無ければ fork でない最新のもの(新しい順に渡す)
|
|
28
|
-
*/
|
|
29
|
-
export declare function pickBasePullRequest(pullRequests: readonly PullRequestReadout[]): PullRequestReadout | undefined;
|
|
30
|
-
/**
|
|
31
27
|
session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
|
|
32
28
|
*/
|
|
33
29
|
export declare function describeStackBase(branch: string, issue: IssueReference, pullRequest: Readonly<PullRequestReadout> | undefined | 'unknown'): string;
|
|
@@ -33,13 +33,6 @@ export function describeBaseMismatch(base, decision, target) {
|
|
|
33
33
|
return isDifferent ? hinted `${inputHint(['session', 'start'], 'base', base)} differs from the base chosen by readiness: ${decision.branch} (stacked on ${displayReference(decision.issue, target.repository)})` : undefined;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
base のブランチを head に持つ PR のうち、表に出す 1 本。fork でない open のもの、無ければ fork でない最新のもの(新しい順に渡す)
|
|
37
|
-
*/
|
|
38
|
-
export function pickBasePullRequest(pullRequests) {
|
|
39
|
-
const own = pullRequests.filter(pullRequest => !pullRequest.isCrossRepository);
|
|
40
|
-
return own.find(pullRequest => pullRequest.state === 'OPEN') ?? own[0];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
36
|
session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
|
|
44
37
|
*/
|
|
45
38
|
export function describeStackBase(branch, issue, pullRequest) {
|
package/cli/dist/infra/git.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GitResult, GitRunner } from '../domain/git-runner.js';
|
|
2
2
|
import type { RemoteLocation } from '../domain/git-url.js';
|
|
3
3
|
import { BaseError } from '../domain/errors.js';
|
|
4
|
+
import type { IssueReference } from '../domain/reference-parser.js';
|
|
4
5
|
export interface GitOptions {
|
|
5
6
|
/**
|
|
6
7
|
作業ディレクトリ。省略すると呼び出し元の作業ディレクトリ
|
|
@@ -80,7 +81,75 @@ export declare function primaryRemoteRepository(cwd?: string): RemoteLocation |
|
|
|
80
81
|
*/
|
|
81
82
|
export declare function gitCurrentBranch(cwd?: string): string | undefined;
|
|
82
83
|
/**
|
|
84
|
+
作業中の Issue。主の remote のリポと現在のブランチ名の末尾の番号から決める。どちらかが読めなければ undefined
|
|
85
|
+
*/
|
|
86
|
+
export declare function activeIssueOf(directory?: string): IssueReference | undefined;
|
|
87
|
+
/**
|
|
83
88
|
指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
84
89
|
*/
|
|
85
90
|
export declare function remoteRepository(cwd: string | undefined, remote: string): RemoteLocation | undefined;
|
|
91
|
+
export declare const NON_INTERACTIVE_GIT: Readonly<Record<string, string>>;
|
|
92
|
+
export interface FetchResult {
|
|
93
|
+
readonly succeeded: boolean;
|
|
94
|
+
readonly stderr: string;
|
|
95
|
+
}
|
|
96
|
+
export type PushResult = {
|
|
97
|
+
readonly pushed: true;
|
|
98
|
+
} | {
|
|
99
|
+
readonly pushed: false;
|
|
100
|
+
readonly stderr: string;
|
|
101
|
+
};
|
|
102
|
+
export type RebaseOutcome = 'done' | 'conflict';
|
|
103
|
+
/**
|
|
104
|
+
`git fetch <remote>`。失敗・時間切れは succeeded が false
|
|
105
|
+
*/
|
|
106
|
+
export declare function fetchRemote(cwd: string, remote: string): FetchResult;
|
|
107
|
+
/**
|
|
108
|
+
ref の指すコミットの SHA。無ければ undefined
|
|
109
|
+
*/
|
|
110
|
+
export declare function resolveCommit(cwd: string, reference: string): string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
2 つの ref の merge-base の SHA。共通の祖先が無ければ undefined
|
|
113
|
+
*/
|
|
114
|
+
export declare function mergeBase(cwd: string, a: string, b: string): string | undefined;
|
|
115
|
+
/**
|
|
116
|
+
`git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
|
|
117
|
+
*/
|
|
118
|
+
export declare function rebaseOnto(cwd: string, newBase: string, oldBase: string): RebaseOutcome;
|
|
119
|
+
/**
|
|
120
|
+
衝突を解いた後の `git rebase --continue`。コミットの文の編集は開かない
|
|
121
|
+
*/
|
|
122
|
+
export declare function continueRebase(cwd: string): RebaseOutcome;
|
|
123
|
+
export declare function abortRebase(cwd: string): void;
|
|
124
|
+
/**
|
|
125
|
+
rebase の途中か。worktree では .git がファイルなので、git に場所を尋ねる
|
|
126
|
+
*/
|
|
127
|
+
export declare function isRebaseInProgress(cwd: string): boolean;
|
|
128
|
+
/**
|
|
129
|
+
衝突が残っているファイルの一覧
|
|
130
|
+
*/
|
|
131
|
+
export declare function conflictedFiles(cwd: string): readonly string[];
|
|
132
|
+
/**
|
|
133
|
+
remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
|
|
134
|
+
*/
|
|
135
|
+
export declare function remoteOnlyChanges(cwd: string, local: string, remoteBranch: string, excluded: readonly string[]): readonly string[];
|
|
136
|
+
/**
|
|
137
|
+
2 つの ref の木が同じか
|
|
138
|
+
*/
|
|
139
|
+
export declare function hasSameTree(cwd: string, a: string, b: string): boolean;
|
|
140
|
+
export declare function resetHardTo(cwd: string, reference: string): void;
|
|
141
|
+
/**
|
|
142
|
+
remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか失敗したら stderr を返す
|
|
143
|
+
*/
|
|
144
|
+
export declare function pushWithLease(cwd: string, remote: string, branch: string, expectedSha: string): PushResult;
|
|
145
|
+
export type RemoteHead = {
|
|
146
|
+
readonly isReachable: true;
|
|
147
|
+
readonly sha: string | undefined;
|
|
148
|
+
} | {
|
|
149
|
+
readonly isReachable: false;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
|
|
153
|
+
*/
|
|
154
|
+
export declare function remoteBranchHead(cwd: string, remote: string, branch: string): RemoteHead;
|
|
86
155
|
//# sourceMappingURL=git.d.ts.map
|
package/cli/dist/infra/git.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// git コマンド実行の唯一の窓口。git の subprocess 呼び出しはすべて runGit を経由する。
|
|
2
2
|
// 値を返す helper(gitToplevel 等)は、失敗時に undefined を返す。
|
|
3
3
|
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { activeIssueFromBranch } from '../domain/branch-name.js';
|
|
4
7
|
import { parseRemoteUrl } from '../domain/git-url.js';
|
|
5
8
|
import { BaseError, InvalidValueError } from '../domain/errors.js';
|
|
6
9
|
import { normalizeNewlines, pythonRepr, pythonStrip } from '../domain/python-format.js';
|
|
@@ -127,6 +130,12 @@ export function gitCurrentBranch(cwd) {
|
|
|
127
130
|
return runForValue(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd });
|
|
128
131
|
}
|
|
129
132
|
/**
|
|
133
|
+
作業中の Issue。主の remote のリポと現在のブランチ名の末尾の番号から決める。どちらかが読めなければ undefined
|
|
134
|
+
*/
|
|
135
|
+
export function activeIssueOf(directory) {
|
|
136
|
+
return activeIssueFromBranch(primaryRemoteRepository(directory), gitCurrentBranch(directory));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
130
139
|
指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
131
140
|
*/
|
|
132
141
|
export function remoteRepository(cwd, remote) {
|
|
@@ -142,4 +151,112 @@ export function remoteRepository(cwd, remote) {
|
|
|
142
151
|
throw error;
|
|
143
152
|
}
|
|
144
153
|
}
|
|
154
|
+
// 端末で尋ねさせない。ssh は GIT_SSH_COMMAND で BatchMode にすると利用者の GIT_SSH と core.sshCommand を上書きするので、askpass を失敗させる
|
|
155
|
+
export const NON_INTERACTIVE_GIT = { GIT_TERMINAL_PROMPT: '0', SSH_ASKPASS: 'false', SSH_ASKPASS_REQUIRE: 'force' };
|
|
156
|
+
// fetch・push は、認証の入力を待たずに、この時間で諦める
|
|
157
|
+
const REMOTE_TIMEOUT_MILLISECONDS = 60_000;
|
|
158
|
+
const PEEL_TO_COMMIT = '^{commit}';
|
|
159
|
+
/**
|
|
160
|
+
`git fetch <remote>`。失敗・時間切れは succeeded が false
|
|
161
|
+
*/
|
|
162
|
+
export function fetchRemote(cwd, remote) {
|
|
163
|
+
const result = runGit(['fetch', remote], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS });
|
|
164
|
+
return { succeeded: result.exitCode === 0, stderr: result.stderr };
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
ref の指すコミットの SHA。無ければ undefined
|
|
168
|
+
*/
|
|
169
|
+
export function resolveCommit(cwd, reference) {
|
|
170
|
+
return runForValue(['rev-parse', '--verify', '--quiet', `${reference}${PEEL_TO_COMMIT}`], { cwd });
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
2 つの ref の merge-base の SHA。共通の祖先が無ければ undefined
|
|
174
|
+
*/
|
|
175
|
+
export function mergeBase(cwd, a, b) {
|
|
176
|
+
return runForValue(['merge-base', a, b], { cwd });
|
|
177
|
+
}
|
|
178
|
+
// 失敗の後に rebase の途中なら衝突、ほかの失敗は GitCommandError
|
|
179
|
+
function rebaseOutcome(cwd, arguments_, environment) {
|
|
180
|
+
const result = runGit(arguments_, { cwd, env: environment });
|
|
181
|
+
if (result.exitCode === 0)
|
|
182
|
+
return 'done';
|
|
183
|
+
if (isRebaseInProgress(cwd))
|
|
184
|
+
return 'conflict';
|
|
185
|
+
throw new GitCommandError(arguments_, result);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
`git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
|
|
189
|
+
*/
|
|
190
|
+
export function rebaseOnto(cwd, newBase, oldBase) {
|
|
191
|
+
const arguments_ = ['rebase', '--no-update-refs', '--onto', newBase, oldBase];
|
|
192
|
+
// 既に途中なら git は始めずに失敗する。その失敗を衝突と読まない
|
|
193
|
+
if (isRebaseInProgress(cwd))
|
|
194
|
+
throw new GitCommandError(arguments_, runGit(arguments_, { cwd }));
|
|
195
|
+
return rebaseOutcome(cwd, arguments_);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
衝突を解いた後の `git rebase --continue`。コミットの文の編集は開かない
|
|
199
|
+
*/
|
|
200
|
+
export function continueRebase(cwd) {
|
|
201
|
+
return rebaseOutcome(cwd, ['rebase', '--continue'], { ...NON_INTERACTIVE_GIT, GIT_EDITOR: 'true' });
|
|
202
|
+
}
|
|
203
|
+
export function abortRebase(cwd) {
|
|
204
|
+
runGit(['rebase', '--abort'], { cwd, check: true });
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
rebase の途中か。worktree では .git がファイルなので、git に場所を尋ねる
|
|
208
|
+
*/
|
|
209
|
+
export function isRebaseInProgress(cwd) {
|
|
210
|
+
const output = runGit(['rev-parse', '--git-path', 'rebase-merge', '--git-path', 'rebase-apply'], { cwd, check: true }).stdout;
|
|
211
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- git が返した git ディレクトリの中のパス
|
|
212
|
+
return output.split('\n').filter(line => line !== '').some(line => existsSync(path.resolve(cwd, line)));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
衝突が残っているファイルの一覧
|
|
216
|
+
*/
|
|
217
|
+
export function conflictedFiles(cwd) {
|
|
218
|
+
return runGit(['diff', '--name-only', '--diff-filter=U'], { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
|
|
222
|
+
*/
|
|
223
|
+
export function remoteOnlyChanges(cwd, local, remoteBranch, excluded) {
|
|
224
|
+
const arguments_ = ['rev-list', '--right-only', '--cherry-pick', '--no-merges', `${local}...${remoteBranch}`, ...excluded.map(reference => `^${reference}`), '--'];
|
|
225
|
+
return runGit(arguments_, { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
2 つの ref の木が同じか
|
|
229
|
+
*/
|
|
230
|
+
export function hasSameTree(cwd, a, b) {
|
|
231
|
+
const arguments_ = ['diff', '--quiet', a, b, '--'];
|
|
232
|
+
const result = runGit(arguments_, { cwd });
|
|
233
|
+
if (result.exitCode === 0)
|
|
234
|
+
return true;
|
|
235
|
+
if (result.exitCode === 1)
|
|
236
|
+
return false;
|
|
237
|
+
throw new GitCommandError(arguments_, result);
|
|
238
|
+
}
|
|
239
|
+
export function resetHardTo(cwd, reference) {
|
|
240
|
+
runGit(['reset', '--quiet', '--hard', reference], { cwd, check: true });
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか失敗したら stderr を返す
|
|
244
|
+
*/
|
|
245
|
+
export function pushWithLease(cwd, remote, branch, expectedSha) {
|
|
246
|
+
const result = runGit(['push', `--force-with-lease=${branch}:${expectedSha}`, remote, branch], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS });
|
|
247
|
+
return result.exitCode === 0 ? { pushed: true } : { pushed: false, stderr: result.stderr };
|
|
248
|
+
}
|
|
249
|
+
// ls-remote は、ref が無いと終了コード 2 を返す
|
|
250
|
+
const LS_REMOTE_NOT_FOUND = 2;
|
|
251
|
+
const LS_REMOTE_TIMEOUT_MILLISECONDS = 10_000;
|
|
252
|
+
/**
|
|
253
|
+
remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
|
|
254
|
+
*/
|
|
255
|
+
export function remoteBranchHead(cwd, remote, branch) {
|
|
256
|
+
const listed = runGit(['ls-remote', '--exit-code', remote, `refs/heads/${branch}`], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: LS_REMOTE_TIMEOUT_MILLISECONDS });
|
|
257
|
+
if (listed.exitCode === LS_REMOTE_NOT_FOUND)
|
|
258
|
+
return { isReachable: true, sha: undefined };
|
|
259
|
+
const [sha] = listed.exitCode === 0 ? listed.stdout.split(/\s/u, 1) : [];
|
|
260
|
+
return sha === undefined || sha === '' ? { isReachable: false } : { isReachable: true, sha };
|
|
261
|
+
}
|
|
145
262
|
//# sourceMappingURL=git.js.map
|