@pecot/workflow-mcp 7.0.1-dev.29 → 7.0.1-dev.31
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/cli/dist/commands/base-reading.d.ts +37 -0
- package/cli/dist/commands/base-reading.js +70 -0
- package/cli/dist/commands/pr-restack.js +16 -8
- package/cli/dist/commands/pr.js +24 -10
- package/cli/dist/commands/session.js +10 -25
- package/cli/dist/domain/state.d.ts +8 -2
- package/cli/dist/domain/state.js +16 -8
- package/cli/dist/domain/work-start.d.ts +28 -1
- package/cli/dist/domain/work-start.js +19 -0
- package/cli/dist/infra/git.d.ts +15 -0
- package/cli/dist/infra/git.js +12 -0
- package/cli/dist/infra/state-store.d.ts +4 -0
- package/cli/dist/infra/state-store.js +9 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { BaseReading } from '../domain/state.js';
|
|
3
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
4
|
+
import type { IssueReadiness } from './issue-readiness.js';
|
|
5
|
+
import type { Output } from './output.js';
|
|
6
|
+
export interface BaseProject {
|
|
7
|
+
readonly config: Readonly<ProjectConfig>;
|
|
8
|
+
readonly client: () => Readonly<GitHubClient>;
|
|
9
|
+
}
|
|
10
|
+
export interface BaseQuery {
|
|
11
|
+
readonly directory: string;
|
|
12
|
+
/**
|
|
13
|
+
アクティブなプロジェクト。無ければ求めない
|
|
14
|
+
*/
|
|
15
|
+
readonly project: Readonly<BaseProject> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
求める前に一度だけ呼ぶ。pr restack が追跡参照を新しくするのに使う
|
|
18
|
+
*/
|
|
19
|
+
readonly beforeInfer?: (() => void) | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface BaseResult {
|
|
22
|
+
readonly reading: BaseReading;
|
|
23
|
+
/**
|
|
24
|
+
求めるときに読んだ作業中の Issue の判定。読まなければ undefined
|
|
25
|
+
*/
|
|
26
|
+
readonly readiness: IssueReadiness | undefined;
|
|
27
|
+
/**
|
|
28
|
+
積んだ先を求められなかった理由。求められたか、求めなかったときは undefined
|
|
29
|
+
*/
|
|
30
|
+
readonly unresolved: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
directory の worktree の .pecot-base を読む。無ければ、判定と git から求める
|
|
34
|
+
*/
|
|
35
|
+
export declare function readBaseOrInfer(query: Readonly<BaseQuery>): Promise<BaseResult>;
|
|
36
|
+
export declare function warnUnresolved(result: Readonly<BaseResult>, output: Readonly<Output>): void;
|
|
37
|
+
//# sourceMappingURL=base-reading.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// 積んだ記録(.pecot-base)を読む。無ければ、作業中の Issue の判定と git から積んだ先を求める。
|
|
2
|
+
import { getDevelopBranch } from '../domain/config.js';
|
|
3
|
+
import { inferStackedBase } from '../domain/work-start.js';
|
|
4
|
+
import { activeIssueOf, changesSharedWith, forkPoint, gitToplevel, mergeBase, primaryRemoteName, resolveCommit } from '../infra/git.js';
|
|
5
|
+
import { TransportFailure } from '../infra/github/client.js';
|
|
6
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
7
|
+
import { readBaseRecordAt } from '../infra/state-store.js';
|
|
8
|
+
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
9
|
+
const NO_RECORD = { kind: 'development', record: undefined };
|
|
10
|
+
function probeLower(directory, remote, developReference) {
|
|
11
|
+
return ({ branch }) => {
|
|
12
|
+
const lower = `${remote}/${branch}`;
|
|
13
|
+
const missing = [lower, developReference].find(reference => resolveCommit(directory, reference) === undefined);
|
|
14
|
+
if (missing !== undefined)
|
|
15
|
+
return { kind: 'untracked', reference: missing };
|
|
16
|
+
const shared = changesSharedWith(directory, 'HEAD', lower, developReference);
|
|
17
|
+
// pr restack の rebaseStartOf と同じく fork-point を先に使う。reflog の無い clone では、載せ直す前の下の段の先頭を patch-id で見つける
|
|
18
|
+
const sha = forkPoint(directory, lower, 'HEAD') ?? shared.lastEquivalent ?? mergeBase(directory, 'HEAD', lower);
|
|
19
|
+
return { kind: 'probed', isShared: shared.isShared, sha };
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function notInferred(readiness, unresolved) {
|
|
23
|
+
return { reading: NO_RECORD, readiness, unresolved };
|
|
24
|
+
}
|
|
25
|
+
async function inferBase(query) {
|
|
26
|
+
const { directory, project } = query;
|
|
27
|
+
const issue = activeIssueOf(directory);
|
|
28
|
+
const remote = primaryRemoteName(directory);
|
|
29
|
+
if (project === undefined || issue === undefined || remote === undefined)
|
|
30
|
+
return notInferred(undefined, undefined);
|
|
31
|
+
const { config } = project;
|
|
32
|
+
const developBranch = getDevelopBranch(config, issue.repository.owner, issue.repository.repository);
|
|
33
|
+
if (developBranch === undefined || developBranch === '')
|
|
34
|
+
return notInferred(undefined, undefined);
|
|
35
|
+
query.beforeInfer?.();
|
|
36
|
+
let readiness;
|
|
37
|
+
try {
|
|
38
|
+
readiness = await readIssueReadinessIfSupported(project.client(), config, issue, createReadinessCache());
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof GitHubAPIError || error instanceof TransportFailure)
|
|
42
|
+
return notInferred(undefined, error.message);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
if (readiness === undefined)
|
|
46
|
+
return notInferred(undefined, undefined);
|
|
47
|
+
if (readiness.kind === 'unreadable')
|
|
48
|
+
return notInferred(readiness, readiness.reason);
|
|
49
|
+
const inferred = inferStackedBase(readiness.readiness, readiness.prerequisites, issue, probeLower(directory, remote, `${remote}/${developBranch}`));
|
|
50
|
+
if (inferred.kind === 'stacked')
|
|
51
|
+
return { reading: { kind: 'stacked', record: inferred.record, stackedOn: inferred.stackedOn }, readiness, unresolved: undefined };
|
|
52
|
+
return notInferred(readiness, inferred.kind === 'unknown' ? inferred.reason : undefined);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
directory の worktree の .pecot-base を読む。無ければ、判定と git から求める
|
|
56
|
+
*/
|
|
57
|
+
export async function readBaseOrInfer(query) {
|
|
58
|
+
const toplevel = gitToplevel({ cwd: query.directory });
|
|
59
|
+
if (toplevel !== undefined) {
|
|
60
|
+
const reading = readBaseRecordAt(toplevel);
|
|
61
|
+
if (reading.kind !== 'development' || reading.record !== undefined)
|
|
62
|
+
return { reading, readiness: undefined, unresolved: undefined };
|
|
63
|
+
}
|
|
64
|
+
return await inferBase(query);
|
|
65
|
+
}
|
|
66
|
+
export function warnUnresolved(result, output) {
|
|
67
|
+
if (result.unresolved !== undefined)
|
|
68
|
+
output.warning(`cannot infer the stacked base: ${result.unresolved}`);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=base-reading.js.map
|
|
@@ -15,6 +15,7 @@ import { createGitHubClient } from './github-client.js';
|
|
|
15
15
|
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
16
16
|
import { stopOnMalformedRecord, validatePullRequestContext } from './pr.js';
|
|
17
17
|
import { readRestackDecision } from './restack-reading.js';
|
|
18
|
+
import { readBaseOrInfer, warnUnresolved } from './base-reading.js';
|
|
18
19
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
19
20
|
const CONFLICT_EXIT_CODE = 3;
|
|
20
21
|
const UNCOMMITTED_EXIT_CODE = 2;
|
|
@@ -53,8 +54,10 @@ function stopOnConflict(out, cwd, progress) {
|
|
|
53
54
|
}
|
|
54
55
|
// remote のブランチにだけあるコミット。patch-id は前後の行も含むので、載せ直しの前と後のどちらとも合わないものだけを数える
|
|
55
56
|
function remoteOnlyCommits(cwd, progress, remoteBranch) {
|
|
56
|
-
|
|
57
|
-
const
|
|
57
|
+
// 記録の位置は途中の記録から読む。積んだ先を求めて始めた載せ直しでは .pecot-base が無い。古い版の途中の記録は .pecot-base から読む
|
|
58
|
+
const reading = progress.recordSha === undefined ? readBaseRecord() : undefined;
|
|
59
|
+
const recordSha = progress.recordSha ?? (reading?.kind === 'stacked' ? reading.record.sha : undefined);
|
|
60
|
+
const excluded = [progress.ontoSha, ...recordSha === undefined ? [] : [recordSha]];
|
|
58
61
|
const before = remoteOnlyChanges(cwd, progress.originalSha, remoteBranch, excluded);
|
|
59
62
|
if (before.length === 0)
|
|
60
63
|
return [];
|
|
@@ -155,7 +158,7 @@ function progressOf(out, cwd, branch, target, decision) {
|
|
|
155
158
|
return stopWith(out, `branch ${remote}/${decision.base} does not exist\ncheck the remote branches with: git branch -r`, 'git-unresolved');
|
|
156
159
|
// 下の段の上に残るなら積んだ先を残す。rebased の base は、下の段(moved から)か開発ブランチ(merged から)
|
|
157
160
|
const isStillStacked = decision.kind === 'moved' || (decision.kind === 'rebased' && decision.base === record.branch);
|
|
158
|
-
return { remote, branch, originalSha, ontoBranch: decision.base, ontoSha, leaseSha: resolveCommit(cwd, `${remote}/${branch}`), stackedOn: isStillStacked ? record.stackedOn : undefined };
|
|
161
|
+
return { remote, branch, originalSha, ontoBranch: decision.base, ontoSha, leaseSha: resolveCommit(cwd, `${remote}/${branch}`), stackedOn: isStillStacked ? record.stackedOn : undefined, recordSha: record.sha };
|
|
159
162
|
}
|
|
160
163
|
// rebase の起点。記録の位置が HEAD に無いとき(push が拒まれた後に base が進んだときなど)は、別の点から求める。
|
|
161
164
|
// 下の段の追跡参照からの fork-point を先に使い、求まらなければ新しい base との merge-base にする。古い下の段のコミットを積み直さない
|
|
@@ -180,9 +183,14 @@ async function runRestack(input, io) {
|
|
|
180
183
|
if (isRebaseInProgress(cwd)) {
|
|
181
184
|
stopWith(out, hinted `a rebase is in progress\ncontinue the restack: ${commandHint(RESTACK_PATH, { continue: true })}\nor abort it: ${commandHint(RESTACK_PATH, { abort: true })}`, 'invalid-input', USAGE_EXIT_CODE);
|
|
182
185
|
}
|
|
183
|
-
const reading = readBaseRecord();
|
|
184
|
-
stopOnMalformedRecord(reading, out);
|
|
185
186
|
const config = requireActiveConfigPlain(out);
|
|
187
|
+
// 記録が無ければ、求める前に fetch して、手元に無い下の段も追跡参照で見る
|
|
188
|
+
let fetched;
|
|
189
|
+
const fetchOnce = () => (fetched ??= fetchRemote(cwd, remote));
|
|
190
|
+
const base = await readBaseOrInfer({ directory: cwd, project: { config, client: () => createGitHubClient(out, config.host) }, beforeInfer: fetchOnce });
|
|
191
|
+
warnUnresolved(base, out);
|
|
192
|
+
const { reading } = base;
|
|
193
|
+
stopOnMalformedRecord(reading, out);
|
|
186
194
|
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
187
195
|
if (developBranch === undefined || developBranch === '')
|
|
188
196
|
return stopWith(out, `develop_branch is not set for ${location.owner}/${location.repository}`, 'repo-setting-missing');
|
|
@@ -196,9 +204,9 @@ async function runRestack(input, io) {
|
|
|
196
204
|
}
|
|
197
205
|
if (!input.check && hasUncommittedChanges(cwd))
|
|
198
206
|
stopWith(out, 'working tree has uncommitted changes', 'preflight-failed', UNCOMMITTED_EXIT_CODE);
|
|
199
|
-
const
|
|
200
|
-
if (!
|
|
201
|
-
stopWith(out, `cannot fetch ${remote}: ${
|
|
207
|
+
const fetchResult = fetchOnce();
|
|
208
|
+
if (!fetchResult.succeeded)
|
|
209
|
+
stopWith(out, `cannot fetch ${remote}: ${fetchResult.stderr.trim()}`, 'git-unresolved');
|
|
202
210
|
const target = { remote, owner: location.owner, repository: location.repository, reading, developBranch };
|
|
203
211
|
const decision = await decideFor(out, cwd, config.host, target);
|
|
204
212
|
if (decision.kind === 'gone')
|
package/cli/dist/commands/pr.js
CHANGED
|
@@ -25,8 +25,8 @@ import { GitHubAPIError } from '../infra/github/errors.js';
|
|
|
25
25
|
import { changedFiles, expectedScope, nxProjects, parseTitleScope } from '../infra/nx-scope.js';
|
|
26
26
|
import { isFileNotFound } from '../infra/os-error.js';
|
|
27
27
|
import { outputDirectory, OutputPathReservationError, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
|
|
28
|
-
import { readBaseRecord } from '../infra/state-store.js';
|
|
29
28
|
import { readTemplateSections, templateFile } from '../infra/template-store.js';
|
|
29
|
+
import { readBaseOrInfer, warnUnresolved } from './base-reading.js';
|
|
30
30
|
import { readTextFile } from '../infra/text-file.js';
|
|
31
31
|
import { commandHint, hinted, inputHint, inputNameHint, joinHinted, placeholder } from './command-hint.js';
|
|
32
32
|
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
@@ -396,11 +396,21 @@ export function stopOnMalformedRecord(reading, out) {
|
|
|
396
396
|
stopWith(out, describeBaseStop({ kind: 'stop', reason: 'malformed', content: reading.content }).join('\n'), 'content-invalid');
|
|
397
397
|
}
|
|
398
398
|
// 記録を使うのは、head が今のブランチで、release のテンプレートでないときだけ。形が誤っていれば終了コード 1 で止める。
|
|
399
|
-
// 記録のコミットが head
|
|
400
|
-
|
|
401
|
-
|
|
399
|
+
// 記録のコミットが head の履歴に無ければ、別のブランチの記録か、手で載せ直した後の古い記録なので止める。開発ブランチ向けに作ると下の段の差分が入りうるため。
|
|
400
|
+
// 記録が無く積んだ先を求められないときも、同じ理由で投稿を止める
|
|
401
|
+
async function readBaseRecordFor(head, input, directory, target, out) {
|
|
402
|
+
if (input.template === 'release' || head !== gitCurrentBranch(directory))
|
|
402
403
|
return undefined;
|
|
403
|
-
const
|
|
404
|
+
const base = await readBaseOrInfer({ directory, project: { config: target.config, client: lazyClient(target.config, out) } });
|
|
405
|
+
if (base.unresolved !== undefined && !input.dryRun) {
|
|
406
|
+
return stopWith(out, joinHinted([
|
|
407
|
+
`cannot infer the stacked base: ${base.unresolved}`,
|
|
408
|
+
'the PR is not created, since a PR to the develop branch can include the changes of the layer below',
|
|
409
|
+
'fix the cause and run again, or run pr create in the work directory where session start wrote .pecot/state/.pecot-base',
|
|
410
|
+
]), 'git-unresolved');
|
|
411
|
+
}
|
|
412
|
+
warnUnresolved(base, out);
|
|
413
|
+
const { reading } = base;
|
|
404
414
|
stopOnMalformedRecord(reading, out);
|
|
405
415
|
if (reading.kind !== 'stacked')
|
|
406
416
|
return reading;
|
|
@@ -529,7 +539,7 @@ async function createFromFile(input, directory, out) {
|
|
|
529
539
|
return stopWith(out, 'repository is required (e.g. owner/repo)', 'content-invalid');
|
|
530
540
|
const location = requireRepository(frontmatter.repository, out);
|
|
531
541
|
const head = resolveHeadBranch(frontmatter.head, directory, out);
|
|
532
|
-
const reading = await readBaseRecordFor(head, input
|
|
542
|
+
const reading = await readBaseRecordFor(head, input, directory, { config, location }, out);
|
|
533
543
|
let body = parsed.body;
|
|
534
544
|
const issueNumber = extractIssueNumberFromBranch(head);
|
|
535
545
|
if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
|
|
@@ -564,7 +574,7 @@ async function createDirect(input, directory, out) {
|
|
|
564
574
|
location = requireRepository(input.repository, out);
|
|
565
575
|
}
|
|
566
576
|
const head = resolveHeadBranch(input.head, directory, out);
|
|
567
|
-
const reading = await readBaseRecordFor(head, input
|
|
577
|
+
const reading = await readBaseRecordFor(head, input, directory, { config, location }, out);
|
|
568
578
|
let body = input.message;
|
|
569
579
|
const issueNumber = extractIssueNumberFromBranch(head);
|
|
570
580
|
if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
|
|
@@ -636,11 +646,13 @@ async function prepareTemplate(directory, out, template) {
|
|
|
636
646
|
// release テンプレートは、base をテンプレートの既定(main)のままにする
|
|
637
647
|
if (template !== 'release') {
|
|
638
648
|
// 下の段の PR がマージ済みかは、準備と投稿の間に変わりうるので、ここでは読まずに投稿のときに見る
|
|
639
|
-
const
|
|
649
|
+
const config = loadActiveConfig();
|
|
650
|
+
const base = await readBaseOrInfer({ directory, project: config === undefined ? undefined : { config, client: lazyClient(config, out) } });
|
|
651
|
+
warnUnresolved(base, out);
|
|
652
|
+
const { reading } = base;
|
|
640
653
|
stopOnMalformedRecord(reading, out);
|
|
641
654
|
const record = reading.kind === 'stacked' ? reading.record : undefined;
|
|
642
655
|
const location = primaryRemote(directory)?.location;
|
|
643
|
-
const config = loadActiveConfig();
|
|
644
656
|
if (location !== undefined) {
|
|
645
657
|
const developBranch = config === undefined ? undefined : getDevelopBranch(config, location.owner, location.repository);
|
|
646
658
|
if (config !== undefined && developBranch !== undefined && developBranch !== '') {
|
|
@@ -894,7 +906,9 @@ async function runCheck(input, io) {
|
|
|
894
906
|
const config = loadActiveConfig();
|
|
895
907
|
if (config === undefined)
|
|
896
908
|
return stopWith(out, hinted `project config not found\nactivate a project with: ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`, 'no-active-project');
|
|
897
|
-
const
|
|
909
|
+
const base = await readBaseOrInfer({ directory, project: { config, client: lazyClient(config, out) } });
|
|
910
|
+
warnUnresolved(base, out);
|
|
911
|
+
const { reading } = base;
|
|
898
912
|
stopOnMalformedRecord(reading, out);
|
|
899
913
|
const baseBranch = determineBaseBranch(config, reading, context.location, directory, context.remoteName, out);
|
|
900
914
|
const gitStatus = getGitStatus(directory);
|
|
@@ -4,13 +4,11 @@ import { ConfigError, getDevelopBranch } from '../domain/config.js';
|
|
|
4
4
|
import { describeReadiness } from '../domain/readiness.js';
|
|
5
5
|
import { describeNeedsRestack, needsRestack } from '../domain/restack.js';
|
|
6
6
|
import { issueReferenceToCliReference, issueReferenceToString } from '../domain/reference-parser.js';
|
|
7
|
-
import { ProjectRootNotFoundError } from '../domain/errors.js';
|
|
8
7
|
import { describeStackBase } from '../domain/work-start.js';
|
|
9
8
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
10
|
-
import { activeIssueOf, gitCurrentBranch,
|
|
9
|
+
import { activeIssueOf, gitCurrentBranch, primaryRemoteName, primaryRemoteRepository } from '../infra/git.js';
|
|
11
10
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
12
|
-
import {
|
|
13
|
-
import { readBaseRecord } from '../infra/state-store.js';
|
|
11
|
+
import { readBaseOrInfer, warnUnresolved } from './base-reading.js';
|
|
14
12
|
import { defineCommand } from './command-definition.js';
|
|
15
13
|
import { directorySchema } from './directory-option.js';
|
|
16
14
|
import { createGitHubClient } from './github-client.js';
|
|
@@ -78,24 +76,11 @@ async function readActiveIssue(directory, output) {
|
|
|
78
76
|
lines.push('', issue.body);
|
|
79
77
|
return { label, data: { ...data, title: issue.title, state: issue.state }, read: { reference, config, client, lines } };
|
|
80
78
|
}
|
|
81
|
-
// -D の directory がプロジェクトルートの worktree か。積んだ記録(.pecot-base)はプロジェクトルートの状態にあるので、
|
|
82
|
-
// 別の worktree の作業には付けない
|
|
83
|
-
function isProjectRootWorktree(directory) {
|
|
84
|
-
const toplevel = gitToplevel({ cwd: directory });
|
|
85
|
-
if (toplevel === undefined)
|
|
86
|
-
return false;
|
|
87
|
-
try {
|
|
88
|
-
return resolveRealPath(toplevel) === resolveRealPath(projectRoot());
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
if (error instanceof ProjectRootNotFoundError)
|
|
92
|
-
return false;
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
79
|
// 積んで着手した作業ディレクトリの `## Stack` の節。積んでいなければ空
|
|
97
80
|
async function stackSection(active, origin, directory, output) {
|
|
98
|
-
const
|
|
81
|
+
const base = await readBaseOrInfer({ directory, project: { config: active.config, client: () => active.client } });
|
|
82
|
+
warnUnresolved(base, output);
|
|
83
|
+
const { reading, readiness: known } = base;
|
|
99
84
|
if (reading.kind === 'malformed')
|
|
100
85
|
output.warning(`.pecot-base is malformed: ${reading.content}`);
|
|
101
86
|
if (reading.kind !== 'stacked')
|
|
@@ -109,7 +94,7 @@ async function stackSection(active, origin, directory, output) {
|
|
|
109
94
|
output.warning(`cannot read the PR of the base branch: ${read.error.message}`);
|
|
110
95
|
const pullRequest = read.kind === 'pull-request-unreadable' ? 'unknown' : read.lowerPullRequest;
|
|
111
96
|
const restack = read.kind === 'decided' ? read.decision : undefined;
|
|
112
|
-
const readiness = await blockedReadiness(active, output);
|
|
97
|
+
const readiness = await blockedReadiness(active, known, output);
|
|
113
98
|
const needsLine = restack === undefined ? undefined : describeNeedsRestack(restack);
|
|
114
99
|
const needed = restack === undefined ? undefined : needsRestack(restack);
|
|
115
100
|
return {
|
|
@@ -143,9 +128,9 @@ function withStackedAbove(stackLines, above) {
|
|
|
143
128
|
const lines = above.map(pullRequest => `- stacked above: PR #${String(pullRequest.number)} (${pullRequest.branch})`);
|
|
144
129
|
return stackLines.length === 0 ? ['', '## Stack', ...lines] : [...stackLines, ...lines];
|
|
145
130
|
}
|
|
146
|
-
// 着手中の Issue の判定が blocked
|
|
147
|
-
async function blockedReadiness(active, output) {
|
|
148
|
-
const result = await readIssueReadinessIfSupported(active.client, active.config, active.reference, createReadinessCache());
|
|
131
|
+
// 着手中の Issue の判定が blocked のときだけ、判定の文を返す。積んだ先を求めるときに読んだ判定があれば、読み直さない
|
|
132
|
+
async function blockedReadiness(active, known, output) {
|
|
133
|
+
const result = known ?? await readIssueReadinessIfSupported(active.client, active.config, active.reference, createReadinessCache());
|
|
149
134
|
if (result === undefined)
|
|
150
135
|
return undefined;
|
|
151
136
|
if (result.kind === 'unreadable') {
|
|
@@ -169,7 +154,7 @@ const SESSION_SHOW = defineCommand({
|
|
|
169
154
|
const origin = primaryRemoteRepository(input.directory);
|
|
170
155
|
const reading = await readActiveIssue(input.directory, output);
|
|
171
156
|
const active = reading?.read;
|
|
172
|
-
const stack = active === undefined
|
|
157
|
+
const stack = active === undefined ? { lines: [] } : await stackSection(active, origin, input.directory, output);
|
|
173
158
|
const above = active === undefined || origin === undefined || branch === undefined ? undefined : await readStackedAbove(active, origin, branch, output);
|
|
174
159
|
output.result({
|
|
175
160
|
...branch !== undefined && { branch },
|
|
@@ -66,6 +66,10 @@ export interface RestackProgress {
|
|
|
66
66
|
載せ直した後も積んだ記録を保つなら、積んだ先の Issue。開発ブランチへ載せ直すなら undefined
|
|
67
67
|
*/
|
|
68
68
|
readonly stackedOn: IssueReference | undefined;
|
|
69
|
+
/**
|
|
70
|
+
載せ直す前の積んだ記録の位置。`--continue` が remote にだけある変更を数えるときに除く。古い版の途中の記録には無い
|
|
71
|
+
*/
|
|
72
|
+
readonly recordSha: string | undefined;
|
|
69
73
|
}
|
|
70
74
|
export type RestackProgressReading = {
|
|
71
75
|
readonly kind: 'none';
|
|
@@ -77,11 +81,13 @@ export type RestackProgressReading = {
|
|
|
77
81
|
readonly content: string;
|
|
78
82
|
};
|
|
79
83
|
/**
|
|
80
|
-
.pecot-restack の 1
|
|
84
|
+
.pecot-restack の 1 行。項目は `<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N> <recordSha>`。
|
|
85
|
+
無い項目は `-`
|
|
81
86
|
*/
|
|
82
87
|
export declare function formatRestackProgress(progress: Readonly<RestackProgress>): string;
|
|
83
88
|
/**
|
|
84
|
-
.pecot-restack
|
|
89
|
+
.pecot-restack を読む。ファイルが無ければ none、形が誤っていれば malformed。
|
|
90
|
+
古い版が書いた 7 項目の行も読み、recordSha を undefined にする
|
|
85
91
|
*/
|
|
86
92
|
export declare function interpretRestackProgress(content: string | undefined): RestackProgressReading;
|
|
87
93
|
//# sourceMappingURL=state.d.ts.map
|
package/cli/dist/domain/state.js
CHANGED
|
@@ -84,27 +84,35 @@ export function interpretBaseRecord(content) {
|
|
|
84
84
|
}
|
|
85
85
|
const ABSENT = '-';
|
|
86
86
|
/**
|
|
87
|
-
.pecot-restack の 1
|
|
87
|
+
.pecot-restack の 1 行。項目は `<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N> <recordSha>`。
|
|
88
|
+
無い項目は `-`
|
|
88
89
|
*/
|
|
89
90
|
export function formatRestackProgress(progress) {
|
|
90
91
|
const stackedOn = progress.stackedOn === undefined ? ABSENT : issueReferenceToString(progress.stackedOn);
|
|
91
|
-
return [progress.remote, progress.branch, progress.originalSha, progress.ontoBranch, progress.ontoSha, progress.leaseSha ?? ABSENT, stackedOn].join(' ');
|
|
92
|
+
return [progress.remote, progress.branch, progress.originalSha, progress.ontoBranch, progress.ontoSha, progress.leaseSha ?? ABSENT, stackedOn, progress.recordSha ?? ABSENT].join(' ');
|
|
93
|
+
}
|
|
94
|
+
// 無い項目の `-` か SHA
|
|
95
|
+
function optionalSha(text) {
|
|
96
|
+
if (text === undefined || text === ABSENT)
|
|
97
|
+
return { isValid: true, sha: undefined };
|
|
98
|
+
return BASE_SHA_PATTERN.test(text) ? { isValid: true, sha: text } : { isValid: false, sha: undefined };
|
|
92
99
|
}
|
|
93
100
|
/**
|
|
94
|
-
.pecot-restack
|
|
101
|
+
.pecot-restack を読む。ファイルが無ければ none、形が誤っていれば malformed。
|
|
102
|
+
古い版が書いた 7 項目の行も読み、recordSha を undefined にする
|
|
95
103
|
*/
|
|
96
104
|
export function interpretRestackProgress(content) {
|
|
97
105
|
if (content === undefined)
|
|
98
106
|
return { kind: 'none' };
|
|
99
107
|
const malformed = { kind: 'malformed', content };
|
|
100
|
-
const [remote, branch, originalSha, ontoBranch, ontoSha, lease, issue, ...rest] = content.split(' ');
|
|
108
|
+
const [remote, branch, originalSha, ontoBranch, ontoSha, lease, issue, record, ...rest] = content.split(' ');
|
|
101
109
|
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))
|
|
102
110
|
return malformed;
|
|
103
|
-
|
|
111
|
+
const leaseSha = optionalSha(lease);
|
|
112
|
+
const recordSha = optionalSha(record);
|
|
113
|
+
if (!leaseSha.isValid || !recordSha.isValid)
|
|
104
114
|
return malformed;
|
|
105
115
|
const stackedOn = issue === ABSENT ? undefined : parseStackedOn(issue);
|
|
106
|
-
|
|
107
|
-
return malformed;
|
|
108
|
-
return { kind: 'progress', progress: { remote, branch, originalSha, ontoBranch, ontoSha, leaseSha: lease === ABSENT ? undefined : lease, stackedOn } };
|
|
116
|
+
return issue !== ABSENT && stackedOn === undefined ? malformed : { kind: 'progress', progress: { remote, branch, originalSha, ontoBranch, ontoSha, leaseSha: leaseSha.sha, stackedOn, recordSha: recordSha.sha } };
|
|
109
117
|
}
|
|
110
118
|
//# sourceMappingURL=state.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { HintedText } from './command-hint.js';
|
|
2
2
|
import type { PullRequestReadout } from './issue-readout.js';
|
|
3
|
-
import type { Prerequisite, Readiness } from './readiness.js';
|
|
3
|
+
import type { Prerequisite, Readiness, StackTarget } from './readiness.js';
|
|
4
4
|
import type { IssueReference } from './reference-parser.js';
|
|
5
|
+
import type { BaseRecord } from './state.js';
|
|
5
6
|
export type StartDecision = {
|
|
6
7
|
readonly kind: 'start';
|
|
7
8
|
} | {
|
|
@@ -24,6 +25,32 @@ export declare function describeBaseMismatch(base: string | undefined, decision:
|
|
|
24
25
|
kind: 'blocked';
|
|
25
26
|
}>, target: IssueReference): HintedText | undefined;
|
|
26
27
|
/**
|
|
28
|
+
積んだ先の下の段を git で調べた結果。追跡参照が手元に無ければ untracked
|
|
29
|
+
*/
|
|
30
|
+
export type LowerProbe = {
|
|
31
|
+
readonly kind: 'untracked';
|
|
32
|
+
readonly reference: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'probed';
|
|
35
|
+
readonly isShared: boolean;
|
|
36
|
+
readonly sha: string | undefined;
|
|
37
|
+
};
|
|
38
|
+
export type StackInference = {
|
|
39
|
+
readonly kind: 'stacked';
|
|
40
|
+
readonly record: BaseRecord;
|
|
41
|
+
readonly stackedOn: IssueReference;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: 'development';
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'unknown';
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
.pecot-base が無いときに、判定と下の段の git の様子から積んだ先を求める。
|
|
50
|
+
判定が stackable でも下の段の変更を持たないのは、開発ブランチから着手した後に前提を足したとき
|
|
51
|
+
*/
|
|
52
|
+
export declare function inferStackedBase(readiness: Readiness | undefined, prerequisites: readonly Prerequisite[], target: IssueReference, probe: (stackOn: Readonly<StackTarget>) => LowerProbe): StackInference;
|
|
53
|
+
/**
|
|
27
54
|
session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
|
|
28
55
|
*/
|
|
29
56
|
export declare function describeStackBase(branch: string, issue: IssueReference, pullRequest: Readonly<PullRequestReadout> | undefined | 'unknown'): string;
|
|
@@ -33,6 +33,25 @@ 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
|
+
.pecot-base が無いときに、判定と下の段の git の様子から積んだ先を求める。
|
|
37
|
+
判定が stackable でも下の段の変更を持たないのは、開発ブランチから着手した後に前提を足したとき
|
|
38
|
+
*/
|
|
39
|
+
export function inferStackedBase(readiness, prerequisites, target, probe) {
|
|
40
|
+
if (readiness?.kind === 'blocked')
|
|
41
|
+
return { kind: 'unknown', reason: describeReadiness(readiness, prerequisites, target.repository) };
|
|
42
|
+
if (readiness?.kind !== 'stackable' || readiness.stackOn === undefined)
|
|
43
|
+
return { kind: 'development' };
|
|
44
|
+
const { branch, issue } = readiness.stackOn;
|
|
45
|
+
const probed = probe(readiness.stackOn);
|
|
46
|
+
if (probed.kind === 'untracked')
|
|
47
|
+
return { kind: 'unknown', reason: `${probed.reference} is not found; fetch it with: git fetch` };
|
|
48
|
+
if (!probed.isShared)
|
|
49
|
+
return { kind: 'development' };
|
|
50
|
+
if (probed.sha === undefined)
|
|
51
|
+
return { kind: 'unknown', reason: `cannot find where HEAD forked from ${branch}` };
|
|
52
|
+
return { kind: 'stacked', record: { branch, sha: probed.sha, stackedOn: issue }, stackedOn: issue };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
36
55
|
session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
|
|
37
56
|
*/
|
|
38
57
|
export function describeStackBase(branch, issue, pullRequest) {
|
package/cli/dist/infra/git.d.ts
CHANGED
|
@@ -141,6 +141,21 @@ export declare function conflictedFiles(cwd: string): readonly string[];
|
|
|
141
141
|
remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
|
|
142
142
|
*/
|
|
143
143
|
export declare function remoteOnlyChanges(cwd: string, local: string, remoteBranch: string, excluded: readonly string[]): readonly string[];
|
|
144
|
+
export interface SharedChanges {
|
|
145
|
+
/**
|
|
146
|
+
other にあって base に無いコミットのうち、head が同じコミットか同じ変更(patch-id)を持つものがある。
|
|
147
|
+
other にそのコミットが無ければ、other が head の祖先か
|
|
148
|
+
*/
|
|
149
|
+
readonly isShared: boolean;
|
|
150
|
+
/**
|
|
151
|
+
head の側で、other と同じ変更を持つ最も新しいコミット。同じコミットを共有するだけなら undefined
|
|
152
|
+
*/
|
|
153
|
+
readonly lastEquivalent: string | undefined;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
head が other の変更を持っているか。other を載せ直して force-push した後も、patch-id で見つける
|
|
157
|
+
*/
|
|
158
|
+
export declare function changesSharedWith(cwd: string, head: string, other: string, base: string): SharedChanges;
|
|
144
159
|
/**
|
|
145
160
|
2 つの ref の木が同じか
|
|
146
161
|
*/
|
package/cli/dist/infra/git.js
CHANGED
|
@@ -237,6 +237,18 @@ export function remoteOnlyChanges(cwd, local, remoteBranch, excluded) {
|
|
|
237
237
|
return runGit(arguments_, { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
|
+
head が other の変更を持っているか。other を載せ直して force-push した後も、patch-id で見つける
|
|
241
|
+
*/
|
|
242
|
+
export function changesSharedWith(cwd, head, other, base) {
|
|
243
|
+
const lines = (arguments_) => runGit(arguments_, { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
|
|
244
|
+
const own = lines(['rev-list', '--no-merges', other, `^${base}`, '--']);
|
|
245
|
+
if (own.length === 0)
|
|
246
|
+
return { isShared: isAncestor(cwd, other, head), lastEquivalent: undefined };
|
|
247
|
+
const unmatched = lines(['rev-list', '--right-only', '--cherry-pick', '--no-merges', `${head}...${other}`, `^${base}`, '--']);
|
|
248
|
+
const equivalent = lines(['rev-list', '--left-only', '--cherry-mark', '--no-merges', `${head}...${other}`, `^${base}`, '--']).find(line => line.startsWith('='));
|
|
249
|
+
return { isShared: unmatched.length < own.length, lastEquivalent: equivalent?.slice(1) };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
240
252
|
2 つの ref の木が同じか
|
|
241
253
|
*/
|
|
242
254
|
export function hasSameTree(cwd, a, b) {
|
|
@@ -42,6 +42,10 @@ export declare function writeBaseRecord(record: Readonly<BaseRecord>): void;
|
|
|
42
42
|
*/
|
|
43
43
|
export declare function readBaseRecord(): BaseReading;
|
|
44
44
|
/**
|
|
45
|
+
toplevel の worktree の .pecot-base を読む。無ければ開発ブランチから着手したものとして返す
|
|
46
|
+
*/
|
|
47
|
+
export declare function readBaseRecordAt(toplevel: string): BaseReading;
|
|
48
|
+
/**
|
|
45
49
|
セッション名のキャッシュ(.pecot-session-title)を書く。
|
|
46
50
|
issueReference の末尾が整数でなければ InvalidValueError で、何も書かない
|
|
47
51
|
*/
|
|
@@ -79,7 +79,9 @@ export function writeFlag(flagName, content) {
|
|
|
79
79
|
存在の確認と読み取りの間に hooks が消しても、読んだ結果が無ければ undefined になる
|
|
80
80
|
*/
|
|
81
81
|
export function readFlag(flagName) {
|
|
82
|
-
|
|
82
|
+
return readFlagFile(path.join(getStateDirectory(), flagName));
|
|
83
|
+
}
|
|
84
|
+
function readFlagFile(flagFile) {
|
|
83
85
|
try {
|
|
84
86
|
return pythonStrip(readTextFile(flagFile));
|
|
85
87
|
}
|
|
@@ -103,6 +105,12 @@ export function readBaseRecord() {
|
|
|
103
105
|
return interpretBaseRecord(readFlag(FLAG_PECOT_BASE));
|
|
104
106
|
}
|
|
105
107
|
/**
|
|
108
|
+
toplevel の worktree の .pecot-base を読む。無ければ開発ブランチから着手したものとして返す
|
|
109
|
+
*/
|
|
110
|
+
export function readBaseRecordAt(toplevel) {
|
|
111
|
+
return interpretBaseRecord(readFlagFile(path.join(toplevel, STATE_DIR, FLAG_PECOT_BASE)));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
106
114
|
セッション名のキャッシュ(.pecot-session-title)を書く。
|
|
107
115
|
issueReference の末尾が整数でなければ InvalidValueError で、何も書かない
|
|
108
116
|
*/
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pecot/workflow-mcp",
|
|
3
|
-
"version": "7.0.1-dev.
|
|
3
|
+
"version": "7.0.1-dev.31",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@pecot/workflow-mcp",
|
|
9
|
-
"version": "7.0.1-dev.
|
|
9
|
+
"version": "7.0.1-dev.31",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/server": "^2.4.0",
|