@pecot/workflow-mcp 0.0.0-stage → 5.0.0
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 +8 -0
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +12 -0
- package/cli/dist/commands/github-client.js +23 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +55 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +19 -0
- package/cli/dist/domain/errors.js +31 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-readout.d.ts +107 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +134 -0
- package/cli/dist/domain/pull-request.js +232 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +66 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +49 -0
- package/cli/dist/infra/config-store.js +121 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +74 -0
- package/cli/dist/infra/git.js +133 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +173 -0
- package/cli/dist/infra/github/client.js +576 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +47 -0
- package/cli/dist/infra/github/errors.js +42 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +129 -0
- package/cli/dist/infra/github/issues.js +273 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +45 -0
- package/cli/dist/infra/state-store.js +118 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +139 -0
- package/cli/dist/infra/worktree-links.js +433 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +128 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +181 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +67 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { PecotError } from '../domain/errors.js';
|
|
2
|
+
import type { JsonValue } from '../domain/python-format.js';
|
|
3
|
+
import type { Diagnostics } from './diagnostics.js';
|
|
4
|
+
import type { GitIgnoreSpec } from './gitignore-spec.js';
|
|
5
|
+
/**
|
|
6
|
+
`pecot worktree init` で生成される .worktreeignore のデフォルト内容
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_WORKTREEIGNORE_CONTENT = "# Git \u30E1\u30BF\u30C7\u30FC\u30BF\n.git/\n\n# Python \u30AD\u30E3\u30C3\u30B7\u30E5\u3002\n__pycache__/\n*.pyc\n*.pyo\n.venv/\nvenv/\n*.egg-info/\n.pytest_cache/\n.mypy_cache/\n.ruff_cache/\n.tox/\n\n# \u30AB\u30D0\u30EC\u30C3\u30B8\nhtmlcov/\n.coverage\n\n# \u30D3\u30EB\u30C9\u751F\u6210\u7269\ndist/\nbuild/\n\n# JS \u4F9D\u5B58\nnode_modules/\n\n# pecot \u306E\u5B9F\u884C\u6642\u72B6\u614B\u30FB\u4E00\u6642\u9818\u57DF\uFF08config \u306F worktree-config \u306E links \u7D4C\u7531\u3067 symlink\uFF09\n.pecot/\ntmp/\n\n# Nx \u30D3\u30EB\u30C9\u72B6\u614B\uFF08version-plans \u306F\u6B8B\u3059\u306E\u3067 .nx/ \u4E38\u3054\u3068\u306F\u9664\u5916\u3057\u306A\u3044\uFF09\n.nx/workspace-data/\n";
|
|
9
|
+
export interface SymlinkResult {
|
|
10
|
+
readonly symlinkPath: string;
|
|
11
|
+
/**
|
|
12
|
+
ターゲットの絶対パス
|
|
13
|
+
*/
|
|
14
|
+
readonly targetPath: string;
|
|
15
|
+
readonly action: 'created' | 'skipped' | 'error';
|
|
16
|
+
/**
|
|
17
|
+
追加メッセージ(エラー詳細など)。無ければ空
|
|
18
|
+
*/
|
|
19
|
+
readonly message: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
ワークツリー設定の操作に失敗した
|
|
23
|
+
*/
|
|
24
|
+
export declare class WorktreeConfigError extends PecotError {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
個別リンク定義。キーは設定ファイルの JSON と同じ
|
|
28
|
+
*/
|
|
29
|
+
export interface WorktreeLinkItem {
|
|
30
|
+
/**
|
|
31
|
+
wt 側リポジトリルートからの相対パス(symlink の配置先)
|
|
32
|
+
*/
|
|
33
|
+
readonly path: string;
|
|
34
|
+
/**
|
|
35
|
+
base 直下のリポジトリ名(symlink ターゲットの所在)
|
|
36
|
+
*/
|
|
37
|
+
readonly target_repo: string;
|
|
38
|
+
/**
|
|
39
|
+
`base/<target_repo>/` 配下の相対パス
|
|
40
|
+
*/
|
|
41
|
+
readonly target_path: string;
|
|
42
|
+
readonly description: string | undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
ワークツリー設定全体(v3)。キーの順は設定ファイルに保存する順
|
|
46
|
+
*/
|
|
47
|
+
export interface WorktreeConfig {
|
|
48
|
+
readonly version: 3;
|
|
49
|
+
readonly description: string | undefined;
|
|
50
|
+
readonly links: readonly WorktreeLinkItem[];
|
|
51
|
+
/**
|
|
52
|
+
WT 作成直後にサブ WT ルートで実行するコマンド(shell 経由)
|
|
53
|
+
*/
|
|
54
|
+
readonly setup_command: string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
setup_command の timeout 秒数。無ければ無制限
|
|
57
|
+
*/
|
|
58
|
+
readonly setup_command_timeout: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
JSON の値から WorktreeConfig を作る。形が不正なら ValidationFailure(表題は WorktreeConfig)。
|
|
62
|
+
未知のキーは無視する
|
|
63
|
+
*/
|
|
64
|
+
export declare function parseWorktreeConfig(data: JsonValue): WorktreeConfig;
|
|
65
|
+
/**
|
|
66
|
+
JSON ファイルから WorktreeConfig を読む。ファイルが無い・JSON が不正・検証に失敗したら WorktreeConfigError
|
|
67
|
+
*/
|
|
68
|
+
export declare function loadConfig(file: string): WorktreeConfig;
|
|
69
|
+
/**
|
|
70
|
+
WorktreeConfig を JSON ファイルに保存する。値の無い項目は出さず、非 ASCII の文字はそのまま出す。親ディレクトリが無ければ作る
|
|
71
|
+
*/
|
|
72
|
+
export declare function saveConfig(config: Readonly<WorktreeConfig>, file: string): void;
|
|
73
|
+
/**
|
|
74
|
+
メイン WT 配下の .worktreeignore を gitignore の仕様として読む。
|
|
75
|
+
空行と `#` 行は読み飛ばす。
|
|
76
|
+
|
|
77
|
+
不正な gitignore パターンのうち、範囲の記法が不正なものは何にも当たらない扱いで残る。
|
|
78
|
+
空行・コメント行を除いた有効行が 1 つ以上あるのに、何かに当たりうるパターンが 1 本も載らなかったときは warning を出す。
|
|
79
|
+
|
|
80
|
+
.worktreeignore が無ければ WorktreeConfigError
|
|
81
|
+
*/
|
|
82
|
+
export declare function loadCopyExcludeSpec(mainWorktree: string, diagnostics: Diagnostics): GitIgnoreSpec;
|
|
83
|
+
/**
|
|
84
|
+
デフォルト設定のテンプレート。CLAUDE.local.md / .env / .claude/settings.local.json の 3 リンクを含む。
|
|
85
|
+
selfRepository を指定すると、hooks-config.json / projects/.active / .pecot/work のリンク(自リポの main WT を指す)も含む
|
|
86
|
+
*/
|
|
87
|
+
export declare function getDefaultConfig(targetRepository: string, selfRepository?: string): WorktreeConfig;
|
|
88
|
+
/**
|
|
89
|
+
リアルファイル/ディレクトリが配置先にあるときの上書き可否の判定。既存の symlink は常に張り替えるので呼ばれない
|
|
90
|
+
*/
|
|
91
|
+
export type OverwriteStrategy = (symlinkPath: string, targetPath: string) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
1 本の link に対する判定値。副作用なしで求める
|
|
94
|
+
*/
|
|
95
|
+
export type LinkPlan = 'create' | 'update' | 'ask' | 'skip-missing' | 'skip-dangling' | 'skip-tracked' | 'skip-real-file';
|
|
96
|
+
/**
|
|
97
|
+
上書きの決め方。force は確認なしで上書きし、ask は確認してから上書きする
|
|
98
|
+
*/
|
|
99
|
+
export interface OverwriteDecision {
|
|
100
|
+
readonly force: boolean;
|
|
101
|
+
readonly ask: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
`--force` は確認なしで上書きする。`--all` は確認せずに飛ばす。1 つの worktree だけのときは確認する。
|
|
105
|
+
予定の表示と本番の両方がこれを使う
|
|
106
|
+
*/
|
|
107
|
+
export declare function decideOverwrite(options: Readonly<{
|
|
108
|
+
readonly force: boolean;
|
|
109
|
+
readonly allWorktrees: boolean;
|
|
110
|
+
}>): OverwriteDecision;
|
|
111
|
+
/**
|
|
112
|
+
1 本の link をどう扱うかを判定する(stat と `git ls-files` だけを行う)。
|
|
113
|
+
順は、リンク先なし → 既存の symlink → 実ファイル/ディレクトリ → 新規
|
|
114
|
+
*/
|
|
115
|
+
export declare function planLink(link: Readonly<WorktreeLinkItem>, projectRoot: string, worktreeRoot: string, decision?: Readonly<Partial<OverwriteDecision>>): LinkPlan;
|
|
116
|
+
/**
|
|
117
|
+
.pecot/.gitignore の生成スクリプトのパス。CLAUDE_PLUGIN_ROOT を起点にし、無ければソースツリーのルート。
|
|
118
|
+
スクリプトの有無は問わない(無ければ呼び出し側の警告に候補パスが出る)
|
|
119
|
+
*/
|
|
120
|
+
export declare function pecotGitignoreEnsureScript(): string;
|
|
121
|
+
/**
|
|
122
|
+
シンボリックリンクを作る(既存ファイル/ディレクトリは常に上書き)
|
|
123
|
+
*/
|
|
124
|
+
export declare function createSymlinks(config: Readonly<WorktreeConfig>, projectRoot: string, worktreeRoot: string, diagnostics: Diagnostics): readonly SymlinkResult[];
|
|
125
|
+
export interface SafeSymlinkOptions {
|
|
126
|
+
/**
|
|
127
|
+
true なら、リアルファイル/ディレクトリを上書きする
|
|
128
|
+
*/
|
|
129
|
+
readonly force?: boolean | undefined;
|
|
130
|
+
/**
|
|
131
|
+
force でないときの上書き可否の確認。無ければ上書きしない
|
|
132
|
+
*/
|
|
133
|
+
readonly confirm?: OverwriteStrategy | undefined;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
シンボリックリンクを安全に作る。リアルファイル/ディレクトリがあるとき、force または confirm で上書き可否を決める
|
|
137
|
+
*/
|
|
138
|
+
export declare function createSymlinksSafe(config: Readonly<WorktreeConfig>, projectRoot: string, worktreeRoot: string, diagnostics: Diagnostics, options?: Readonly<SafeSymlinkOptions>): readonly SymlinkResult[];
|
|
139
|
+
//# sourceMappingURL=worktree-links.d.ts.map
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側が渡すプロジェクトルート配下 */
|
|
2
|
+
// ワークツリー設定の管理。
|
|
3
|
+
//
|
|
4
|
+
// プロジェクト単位 wtN 構成(`<root>/base/<repo>` と `<root>/wtN/<repo>`)の設定を扱う。
|
|
5
|
+
// 次の 2 ファイルの読み書きを提供する。
|
|
6
|
+
// - `.pecot/config/worktree-config.json` は、シンボリックリンクと setup コマンドを保持する。
|
|
7
|
+
// - `.pecot/config/.worktreeignore`(gitignore 形式)は、コピー除外パターンを定義する。
|
|
8
|
+
// 設定ファイルは各リポジトリの main WT ルート(`<root>/base/<repo>/`)に置く。
|
|
9
|
+
//
|
|
10
|
+
// 検証エラーの文は、Python の CLI(pydantic)が出していた書式に合わせる。
|
|
11
|
+
// 不正な JSON の文だけは JSON パーサーのもので、Python の JSONDecodeError の文とは違う。
|
|
12
|
+
// main WT の探索(findWorktreeConfigFile)は worktree.ts にある。worktree.ts がこのファイルを読むため、相互の import を避けて置いた。
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
14
|
+
import { existsSync, lstatSync, mkdirSync, realpathSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { PecotError, InvalidValueError } from '../domain/errors.js';
|
|
17
|
+
import { isJsonObject, jsonField, parseJsonText } from '../domain/json.js';
|
|
18
|
+
import { isJsonArray, pythonStrip, ValidationFailure } from '../domain/python-format.js';
|
|
19
|
+
import { childStdin } from './child-stdin.js';
|
|
20
|
+
import { isFile } from './file-kind.js';
|
|
21
|
+
import { runGit } from './git.js';
|
|
22
|
+
import { hasErrorCode, OsError, toOsError } from './os-error.js';
|
|
23
|
+
import { ACTIVE_PROJECT_FILENAME, PECOT_DIR, PECOT_GITIGNORE_FILENAME, HOOKS_CONFIG_FILENAME, normalizePath, WORK_DIR, WORKTREE_IGNORE_FILENAME, } from './paths.js';
|
|
24
|
+
import { compileGitIgnoreSpec } from './gitignore-spec.js';
|
|
25
|
+
import { readTextFile } from './text-file.js';
|
|
26
|
+
import { pluginRoot } from '../version.js';
|
|
27
|
+
// 定数
|
|
28
|
+
/**
|
|
29
|
+
`pecot worktree init` で生成される .worktreeignore のデフォルト内容
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_WORKTREEIGNORE_CONTENT = `\
|
|
32
|
+
# Git メタデータ
|
|
33
|
+
.git/
|
|
34
|
+
|
|
35
|
+
# Python キャッシュ。
|
|
36
|
+
__pycache__/
|
|
37
|
+
*.pyc
|
|
38
|
+
*.pyo
|
|
39
|
+
.venv/
|
|
40
|
+
venv/
|
|
41
|
+
*.egg-info/
|
|
42
|
+
.pytest_cache/
|
|
43
|
+
.mypy_cache/
|
|
44
|
+
.ruff_cache/
|
|
45
|
+
.tox/
|
|
46
|
+
|
|
47
|
+
# カバレッジ
|
|
48
|
+
htmlcov/
|
|
49
|
+
.coverage
|
|
50
|
+
|
|
51
|
+
# ビルド生成物
|
|
52
|
+
dist/
|
|
53
|
+
build/
|
|
54
|
+
|
|
55
|
+
# JS 依存
|
|
56
|
+
node_modules/
|
|
57
|
+
|
|
58
|
+
# pecot の実行時状態・一時領域(config は worktree-config の links 経由で symlink)
|
|
59
|
+
.pecot/
|
|
60
|
+
tmp/
|
|
61
|
+
|
|
62
|
+
# Nx ビルド状態(version-plans は残すので .nx/ 丸ごとは除外しない)
|
|
63
|
+
.nx/workspace-data/
|
|
64
|
+
`;
|
|
65
|
+
// .pecot/.gitignore の生成スクリプト。中身の本体は hook 側に置き、CLI は複製せずに呼ぶ
|
|
66
|
+
const PECOT_GITIGNORE_ENSURE_RELATIVE = 'hooks/lib/core/pecot-gitignore-ensure.sh';
|
|
67
|
+
/**
|
|
68
|
+
ワークツリー設定の操作に失敗した
|
|
69
|
+
*/
|
|
70
|
+
export class WorktreeConfigError extends PecotError {
|
|
71
|
+
}
|
|
72
|
+
// 検証(pydantic の WorktreeConfig と同じ文を作る)
|
|
73
|
+
function issueOf(type, location, message, input) {
|
|
74
|
+
return { type, location, message, input };
|
|
75
|
+
}
|
|
76
|
+
function valueError(location, message, input) {
|
|
77
|
+
return issueOf('value_error', location, `Value error, ${message}`, input);
|
|
78
|
+
}
|
|
79
|
+
function validateRelativePath(value, fieldName) {
|
|
80
|
+
if (value === '' || pythonStrip(value) === '')
|
|
81
|
+
return `${fieldName} must not be empty`;
|
|
82
|
+
if (value.startsWith('/'))
|
|
83
|
+
return `absolute paths are not allowed: ${value}`;
|
|
84
|
+
if (value.split('/').includes('..'))
|
|
85
|
+
return `parent directory references are not allowed: ${value}`;
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
function validateTargetRepository(value) {
|
|
89
|
+
if (value === '' || pythonStrip(value) === '')
|
|
90
|
+
return 'target_repo must not be empty';
|
|
91
|
+
if (value.includes('/'))
|
|
92
|
+
return `target_repo must not contain a slash: ${value}`;
|
|
93
|
+
if (value === '..' || value === '.')
|
|
94
|
+
return `invalid target_repo: ${value}`;
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
// 文字列の項目。型が違えば string_type、validate が文を返せば value_error
|
|
98
|
+
function parseString(value, location, validate) {
|
|
99
|
+
if (typeof value !== 'string')
|
|
100
|
+
return { issues: [issueOf('string_type', location, 'Input should be a valid string', value)], value: undefined };
|
|
101
|
+
const message = validate?.(value);
|
|
102
|
+
return message === undefined ? { issues: [], value } : { issues: [valueError(location, message, value)], value: undefined };
|
|
103
|
+
}
|
|
104
|
+
function parseOptionalString(value, location) {
|
|
105
|
+
return value === undefined || value === null ? { issues: [], value: undefined } : parseString(value, location);
|
|
106
|
+
}
|
|
107
|
+
function parseRequiredString(object, key, location, validate) {
|
|
108
|
+
const value = jsonField(object, key);
|
|
109
|
+
if (value === undefined)
|
|
110
|
+
return { issues: [issueOf('missing', location, 'Field required', object)], value: '' };
|
|
111
|
+
const parsed = parseString(value, location, validate);
|
|
112
|
+
return { issues: parsed.issues, value: parsed.value ?? '' };
|
|
113
|
+
}
|
|
114
|
+
function parseLinkItem(item, index) {
|
|
115
|
+
const base = ['links', index];
|
|
116
|
+
const placeholder = { path: '', target_repo: '', target_path: '', description: undefined };
|
|
117
|
+
if (!isJsonObject(item)) {
|
|
118
|
+
return { issues: [issueOf('model_type', base, 'Input should be a valid dictionary or instance of WorktreeLinkItem', item)], link: placeholder };
|
|
119
|
+
}
|
|
120
|
+
const pathField = parseRequiredString(item, 'path', [...base, 'path'], text => validateRelativePath(text, 'path'));
|
|
121
|
+
const repositoryField = parseRequiredString(item, 'target_repo', [...base, 'target_repo'], validateTargetRepository);
|
|
122
|
+
const targetPathField = parseRequiredString(item, 'target_path', [...base, 'target_path'], text => validateRelativePath(text, 'target_path'));
|
|
123
|
+
const descriptionField = parseOptionalString(jsonField(item, 'description'), [...base, 'description']);
|
|
124
|
+
return {
|
|
125
|
+
issues: [...pathField.issues, ...repositoryField.issues, ...targetPathField.issues, ...descriptionField.issues],
|
|
126
|
+
link: { path: pathField.value, target_repo: repositoryField.value, target_path: targetPathField.value, description: descriptionField.value },
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function parseLinks(value) {
|
|
130
|
+
if (value === undefined)
|
|
131
|
+
return { issues: [], links: [] };
|
|
132
|
+
if (!isJsonArray(value))
|
|
133
|
+
return { issues: [issueOf('list_type', ['links'], 'Input should be a valid list', value)], links: [] };
|
|
134
|
+
const parsed = value.map((item, index) => parseLinkItem(item, index));
|
|
135
|
+
return { issues: parsed.flatMap(entry => entry.issues), links: parsed.map(entry => entry.link) };
|
|
136
|
+
}
|
|
137
|
+
// int の lax な変換。bool は 0・1、前後の空白・符号・数字の間の `_`・小数部が 0 だけの文字列は整数にする
|
|
138
|
+
function convertToInteger(value) {
|
|
139
|
+
if (typeof value === 'boolean')
|
|
140
|
+
return { value: value ? 1 : 0 };
|
|
141
|
+
if (typeof value === 'number') {
|
|
142
|
+
return Number.isSafeInteger(value) ? { value } : { type: 'int_from_float', message: 'Input should be a valid integer, got a number with a fractional part' };
|
|
143
|
+
}
|
|
144
|
+
if (typeof value === 'string') {
|
|
145
|
+
const text = pythonStrip(value);
|
|
146
|
+
if (text.replace(/^[+-]/u, '').split('_').every(group => /^\d+$/u.test(group)))
|
|
147
|
+
return { value: Number(text.replaceAll('_', '')) };
|
|
148
|
+
if (/^[+-]?\d+\.0*$/u.test(text))
|
|
149
|
+
return { value: Number(text.slice(0, text.indexOf('.'))) };
|
|
150
|
+
return { type: 'int_parsing', message: 'Input should be a valid integer, unable to parse string as an integer' };
|
|
151
|
+
}
|
|
152
|
+
return { type: 'int_type', message: 'Input should be a valid integer' };
|
|
153
|
+
}
|
|
154
|
+
function parseTimeout(value) {
|
|
155
|
+
if (value === undefined || value === null)
|
|
156
|
+
return { issues: [], value: undefined };
|
|
157
|
+
const location = ['setup_command_timeout'];
|
|
158
|
+
const converted = convertToInteger(value);
|
|
159
|
+
if ('type' in converted)
|
|
160
|
+
return { issues: [issueOf(converted.type, location, converted.message, value)], value: undefined };
|
|
161
|
+
if (converted.value <= 0)
|
|
162
|
+
return { issues: [valueError(location, `setup_command_timeout must be a positive integer: ${String(converted.value)}`, value)], value: undefined };
|
|
163
|
+
return { issues: [], value: converted.value };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
JSON の値から WorktreeConfig を作る。形が不正なら ValidationFailure(表題は WorktreeConfig)。
|
|
167
|
+
未知のキーは無視する
|
|
168
|
+
*/
|
|
169
|
+
export function parseWorktreeConfig(data) {
|
|
170
|
+
if (!isJsonObject(data)) {
|
|
171
|
+
throw new ValidationFailure('WorktreeConfig', [issueOf('model_type', [], 'Input should be a valid dictionary or instance of WorktreeConfig', data)]);
|
|
172
|
+
}
|
|
173
|
+
const version = jsonField(data, 'version');
|
|
174
|
+
const versionIssues = version === undefined || version === 3 ? [] : [issueOf('literal_error', ['version'], 'Input should be 3', version)];
|
|
175
|
+
const description = parseOptionalString(jsonField(data, 'description'), ['description']);
|
|
176
|
+
const links = parseLinks(jsonField(data, 'links'));
|
|
177
|
+
const setupCommand = parseOptionalString(jsonField(data, 'setup_command'), ['setup_command']);
|
|
178
|
+
const timeout = parseTimeout(jsonField(data, 'setup_command_timeout'));
|
|
179
|
+
const issues = [...versionIssues, ...description.issues, ...links.issues, ...setupCommand.issues, ...timeout.issues];
|
|
180
|
+
if (issues.length > 0)
|
|
181
|
+
throw new ValidationFailure('WorktreeConfig', issues);
|
|
182
|
+
return { version: 3, description: description.value, links: links.links, setup_command: setupCommand.value, setup_command_timeout: timeout.value };
|
|
183
|
+
}
|
|
184
|
+
// 設定操作関数
|
|
185
|
+
/**
|
|
186
|
+
JSON ファイルから WorktreeConfig を読む。ファイルが無い・JSON が不正・検証に失敗したら WorktreeConfigError
|
|
187
|
+
*/
|
|
188
|
+
export function loadConfig(file) {
|
|
189
|
+
const shown = normalizePath(file);
|
|
190
|
+
if (!existsSync(file))
|
|
191
|
+
throw new WorktreeConfigError(`config file not found: ${shown}`);
|
|
192
|
+
let data;
|
|
193
|
+
try {
|
|
194
|
+
data = parseJsonText(readTextFile(file));
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// 文言は JSON パーサーのもので、Python の JSONDecodeError の文とは違う
|
|
198
|
+
if (error instanceof InvalidValueError)
|
|
199
|
+
throw new WorktreeConfigError(`JSON parse error: ${shown}: ${error.message}`, { cause: error });
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
return parseWorktreeConfig(data);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (error instanceof InvalidValueError)
|
|
207
|
+
throw new WorktreeConfigError(`config file validation failed: ${shown}: ${error.message}`, { cause: error });
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
WorktreeConfig を JSON ファイルに保存する。値の無い項目は出さず、非 ASCII の文字はそのまま出す。親ディレクトリが無ければ作る
|
|
213
|
+
*/
|
|
214
|
+
export function saveConfig(config, file) {
|
|
215
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
216
|
+
writeFileSync(file, `${JSON.stringify(config, undefined, 2)}\n`);
|
|
217
|
+
}
|
|
218
|
+
// Python の str.splitlines() が行を分ける文字。読んだ後の改行は \n に揃っているが、これらでも分ける
|
|
219
|
+
const LINE_BREAKS = new Set(['\n', '\v', '\f', '\u{1C}', '\u{1D}', '\u{1E}', '\u{85}', '\u{2028}', '\u{2029}']);
|
|
220
|
+
function splitLines(text) {
|
|
221
|
+
const lines = [];
|
|
222
|
+
let current = '';
|
|
223
|
+
for (const character of text) {
|
|
224
|
+
if (LINE_BREAKS.has(character)) {
|
|
225
|
+
lines.push(current);
|
|
226
|
+
current = '';
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
current += character;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (current !== '')
|
|
233
|
+
lines.push(current);
|
|
234
|
+
return lines;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
メイン WT 配下の .worktreeignore を gitignore の仕様として読む。
|
|
238
|
+
空行と `#` 行は読み飛ばす。
|
|
239
|
+
|
|
240
|
+
不正な gitignore パターンのうち、範囲の記法が不正なものは何にも当たらない扱いで残る。
|
|
241
|
+
空行・コメント行を除いた有効行が 1 つ以上あるのに、何かに当たりうるパターンが 1 本も載らなかったときは warning を出す。
|
|
242
|
+
|
|
243
|
+
.worktreeignore が無ければ WorktreeConfigError
|
|
244
|
+
*/
|
|
245
|
+
export function loadCopyExcludeSpec(mainWorktree, diagnostics) {
|
|
246
|
+
const file = path.join(mainWorktree, WORKTREE_IGNORE_FILENAME);
|
|
247
|
+
if (!existsSync(file)) {
|
|
248
|
+
throw new WorktreeConfigError(`copy exclude config not found: ${WORKTREE_IGNORE_FILENAME}\n run pecot worktree init to generate the template`);
|
|
249
|
+
}
|
|
250
|
+
const rawLines = splitLines(readTextFile(file));
|
|
251
|
+
const effectiveLines = rawLines.filter(line => pythonStrip(line) !== '' && !pythonStrip(line).startsWith('#'));
|
|
252
|
+
const spec = compileGitIgnoreSpec(rawLines);
|
|
253
|
+
// `/` 単体や空白のみの行などは、何にも当たらないパターンになる。それしか残らなかったら意図通りではない可能性が高い
|
|
254
|
+
if (effectiveLines.length > 0 && spec.matchablePatternCount === 0) {
|
|
255
|
+
diagnostics.warning(`all patterns in ${normalizePath(file)} are invalid (${String(effectiveLines.length)} effective lines silently ignored): check the gitignore syntax`);
|
|
256
|
+
}
|
|
257
|
+
return spec;
|
|
258
|
+
}
|
|
259
|
+
function createLink(link) {
|
|
260
|
+
return link;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
デフォルト設定のテンプレート。CLAUDE.local.md / .env / .claude/settings.local.json の 3 リンクを含む。
|
|
264
|
+
selfRepository を指定すると、hooks-config.json / projects/.active / .pecot/work のリンク(自リポの main WT を指す)も含む
|
|
265
|
+
*/
|
|
266
|
+
export function getDefaultConfig(targetRepository, selfRepository) {
|
|
267
|
+
const links = [
|
|
268
|
+
createLink({ path: 'CLAUDE.local.md', target_repo: targetRepository, target_path: 'CLAUDE.local.md', description: 'ローカル向け CLAUDE 指示(Git 管理外)' }),
|
|
269
|
+
createLink({ path: '.env', target_repo: targetRepository, target_path: '.env', description: '環境変数(Git 管理外)' }),
|
|
270
|
+
createLink({ path: '.claude/settings.local.json', target_repo: targetRepository, target_path: '.claude/settings.local.json', description: 'Claude Code のローカル設定' }),
|
|
271
|
+
];
|
|
272
|
+
if (selfRepository !== undefined) {
|
|
273
|
+
links.push(createLink({ path: HOOKS_CONFIG_FILENAME, target_repo: selfRepository, target_path: HOOKS_CONFIG_FILENAME, description: 'pecot hooks 有効/無効設定(main WT と共有)' }), createLink({ path: ACTIVE_PROJECT_FILENAME, target_repo: selfRepository, target_path: ACTIVE_PROJECT_FILENAME, description: 'active project ポインタ(main WT と共有)' }), createLink({ path: WORK_DIR, target_repo: selfRepository, target_path: WORK_DIR, description: `作業ファイル置き場(main WT の ${WORK_DIR} を共有)` }));
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
version: 3,
|
|
277
|
+
description: 'wtN/<repo> から base/<target_repo>/<target_path> への相対 symlink 設定。 target_repo は WT 間で共有したいファイルを置くメインリポ名に置換し、 不要な link は削除してください。',
|
|
278
|
+
links,
|
|
279
|
+
setup_command: undefined,
|
|
280
|
+
setup_command_timeout: undefined,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
// Symlink 生成
|
|
284
|
+
// pathlib と同じく末尾の / を落とす。残すと lstat が symlink をたどり、実ディレクトリと誤判定する
|
|
285
|
+
function joinWithoutTrailingSlash(...segments) {
|
|
286
|
+
const joined = path.join(...segments);
|
|
287
|
+
return joined.length > 1 ? joined.replace(/\/+$/, '') : joined;
|
|
288
|
+
}
|
|
289
|
+
function resolveAbsoluteTarget(projectRoot, link) {
|
|
290
|
+
return joinWithoutTrailingSlash(projectRoot, 'base', link.target_repo, link.target_path);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
repositoryRoot のリポジトリで relativePath が tracked かどうか。対象がディレクトリでも、配下の tracked file が返るので拾える。
|
|
294
|
+
.git 不在・git CLI 不在・cwd 不在などの異常系は false(ガード無し)に倒す
|
|
295
|
+
*/
|
|
296
|
+
function isTrackedInRepository(repositoryRoot, relativePath) {
|
|
297
|
+
try {
|
|
298
|
+
const result = runGit(['ls-files', '--', relativePath], { cwd: repositoryRoot });
|
|
299
|
+
return result.exitCode === 0 && result.stdout.trim() !== '';
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
if (error instanceof OsError)
|
|
303
|
+
return false;
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function isSymbolicLink(target) {
|
|
308
|
+
try {
|
|
309
|
+
return lstatSync(target).isSymbolicLink();
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
`--force` は確認なしで上書きする。`--all` は確認せずに飛ばす。1 つの worktree だけのときは確認する。
|
|
317
|
+
予定の表示と本番の両方がこれを使う
|
|
318
|
+
*/
|
|
319
|
+
export function decideOverwrite(options) {
|
|
320
|
+
return options.force ? { force: true, ask: false } : { force: false, ask: !options.allWorktrees };
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
1 本の link をどう扱うかを判定する(stat と `git ls-files` だけを行う)。
|
|
324
|
+
順は、リンク先なし → 既存の symlink → 実ファイル/ディレクトリ → 新規
|
|
325
|
+
*/
|
|
326
|
+
export function planLink(link, projectRoot, worktreeRoot, decision = {}) {
|
|
327
|
+
const targetPath = resolveAbsoluteTarget(projectRoot, link);
|
|
328
|
+
if (!existsSync(targetPath))
|
|
329
|
+
return isSymbolicLink(targetPath) ? 'skip-dangling' : 'skip-missing';
|
|
330
|
+
const symlinkPath = joinWithoutTrailingSlash(worktreeRoot, link.path);
|
|
331
|
+
if (isSymbolicLink(symlinkPath))
|
|
332
|
+
return 'update';
|
|
333
|
+
if (!existsSync(symlinkPath))
|
|
334
|
+
return 'create';
|
|
335
|
+
if (isTrackedInRepository(worktreeRoot, link.path))
|
|
336
|
+
return 'skip-tracked';
|
|
337
|
+
if (decision.force === true)
|
|
338
|
+
return 'update';
|
|
339
|
+
return decision.ask === true ? 'ask' : 'skip-real-file';
|
|
340
|
+
}
|
|
341
|
+
// 再帰で消すのは lstat が実ディレクトリと答えたときだけ。symlink は共有先をたどらず unlink する
|
|
342
|
+
function removeExisting(target) {
|
|
343
|
+
let stats;
|
|
344
|
+
try {
|
|
345
|
+
stats = lstatSync(target);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (stats.isDirectory())
|
|
351
|
+
rmSync(target, { recursive: true });
|
|
352
|
+
else
|
|
353
|
+
unlinkSync(target);
|
|
354
|
+
}
|
|
355
|
+
// 1 本の link 定義を、実際のファイルシステム操作に変換する。判定は planLink と同じ
|
|
356
|
+
function processLink(link, projectRoot, worktreeRoot, overwrite, diagnostics) {
|
|
357
|
+
const symlinkPath = joinWithoutTrailingSlash(worktreeRoot, link.path);
|
|
358
|
+
const targetPath = resolveAbsoluteTarget(projectRoot, link);
|
|
359
|
+
const plan = planLink(link, projectRoot, worktreeRoot, { force: overwrite.force, ask: overwrite.confirm !== undefined });
|
|
360
|
+
if (plan === 'skip-missing' || plan === 'skip-dangling') {
|
|
361
|
+
const message = plan === 'skip-dangling' ? `target is a dangling symlink: ${targetPath}` : `target does not exist: ${targetPath}`;
|
|
362
|
+
diagnostics.warning(message);
|
|
363
|
+
return { symlinkPath, targetPath, action: 'skipped', message };
|
|
364
|
+
}
|
|
365
|
+
if (plan === 'skip-tracked') {
|
|
366
|
+
diagnostics.warning(`symlink creation skipped because the path is tracked by git: ${symlinkPath}`);
|
|
367
|
+
return { symlinkPath, targetPath, action: 'error', message: `symlink creation aborted because the path is tracked by git: ${link.path}` };
|
|
368
|
+
}
|
|
369
|
+
if (plan === 'skip-real-file' || (plan === 'ask' && overwrite.confirm?.(symlinkPath, targetPath) !== true)) {
|
|
370
|
+
return { symlinkPath, targetPath, action: 'skipped', message: `a real file exists: ${symlinkPath}` };
|
|
371
|
+
}
|
|
372
|
+
let relativeTarget = path.relative(path.dirname(symlinkPath), targetPath);
|
|
373
|
+
try {
|
|
374
|
+
mkdirSync(path.dirname(symlinkPath), { recursive: true });
|
|
375
|
+
// 親が symlink 経由でも解決できるよう、実体の親ディレクトリからの相対にする
|
|
376
|
+
relativeTarget = path.relative(realpathSync(path.dirname(symlinkPath)), targetPath);
|
|
377
|
+
removeExisting(symlinkPath);
|
|
378
|
+
symlinkSync(relativeTarget, symlinkPath);
|
|
379
|
+
return { symlinkPath, targetPath, action: 'created', message: '' };
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
if (!hasErrorCode(error))
|
|
383
|
+
throw error;
|
|
384
|
+
const converted = toOsError(error);
|
|
385
|
+
const message = converted instanceof Error ? converted.message : String(converted);
|
|
386
|
+
diagnostics.warning(`failed to create the symlink: ${symlinkPath} -> ${relativeTarget}: ${message}`);
|
|
387
|
+
return { symlinkPath, targetPath, action: 'error', message };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
.pecot/.gitignore の生成スクリプトのパス。CLAUDE_PLUGIN_ROOT を起点にし、無ければソースツリーのルート。
|
|
392
|
+
スクリプトの有無は問わない(無ければ呼び出し側の警告に候補パスが出る)
|
|
393
|
+
*/
|
|
394
|
+
export function pecotGitignoreEnsureScript() {
|
|
395
|
+
return path.join(pluginRoot(), PECOT_GITIGNORE_ENSURE_RELATIVE);
|
|
396
|
+
}
|
|
397
|
+
// .pecot/.gitignore は hook しか作らず、WT 作成直後は symlink が未追跡で出る(#1219)。symlink だと git が読まないので実ファイルで置く
|
|
398
|
+
// 生成に失敗しても link 作成は続ける
|
|
399
|
+
function ensurePecotGitignore(config, worktreeRoot, diagnostics) {
|
|
400
|
+
if (config.links.every(link => !link.path.startsWith(`${PECOT_DIR}/`)))
|
|
401
|
+
return;
|
|
402
|
+
const script = pecotGitignoreEnsureScript();
|
|
403
|
+
if (!isFile(script)) {
|
|
404
|
+
diagnostics.warning(`generation script for ${PECOT_GITIGNORE_FILENAME} not found: ${script}`);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const result = spawnSync('bash', [script], {
|
|
408
|
+
// interface-env: none
|
|
409
|
+
env: { ...process.env, CLAUDE_PROJECT_DIR: worktreeRoot },
|
|
410
|
+
encoding: 'utf8',
|
|
411
|
+
stdio: [childStdin(), 'pipe', 'pipe'],
|
|
412
|
+
});
|
|
413
|
+
if (result.error !== undefined)
|
|
414
|
+
throw toOsError(result.error);
|
|
415
|
+
if (result.status !== 0)
|
|
416
|
+
diagnostics.warning(`could not generate ${PECOT_GITIGNORE_FILENAME}: ${result.stderr.trim()}`);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
シンボリックリンクを作る(既存ファイル/ディレクトリは常に上書き)
|
|
420
|
+
*/
|
|
421
|
+
export function createSymlinks(config, projectRoot, worktreeRoot, diagnostics) {
|
|
422
|
+
ensurePecotGitignore(config, worktreeRoot, diagnostics);
|
|
423
|
+
return config.links.map(link => processLink(link, projectRoot, worktreeRoot, { force: true, confirm: undefined }, diagnostics));
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
シンボリックリンクを安全に作る。リアルファイル/ディレクトリがあるとき、force または confirm で上書き可否を決める
|
|
427
|
+
*/
|
|
428
|
+
export function createSymlinksSafe(config, projectRoot, worktreeRoot, diagnostics, options = {}) {
|
|
429
|
+
const overwrite = { force: options.force === true, confirm: options.confirm };
|
|
430
|
+
ensurePecotGitignore(config, worktreeRoot, diagnostics);
|
|
431
|
+
return config.links.map(link => processLink(link, projectRoot, worktreeRoot, overwrite, diagnostics));
|
|
432
|
+
}
|
|
433
|
+
//# sourceMappingURL=worktree-links.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SetupResult {
|
|
2
|
+
/**
|
|
3
|
+
実行したコマンド文字列
|
|
4
|
+
*/
|
|
5
|
+
readonly command: string;
|
|
6
|
+
/**
|
|
7
|
+
終了コード。timeout なら -1、シグナルで終わったなら -(シグナル番号)
|
|
8
|
+
*/
|
|
9
|
+
readonly exitCode: number;
|
|
10
|
+
readonly stdout: string;
|
|
11
|
+
readonly stderr: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
setup_command を shell 経由で実行して、結果を構造化して返す。
|
|
15
|
+
|
|
16
|
+
stdin は常に閉じて、対話プロンプトで stall しないようにする。
|
|
17
|
+
timeoutSeconds を超えた場合は子プロセスを kill し、exitCode -1 の SetupResult を返す(例外は投げない)。-1 は timeout 起因の目印。
|
|
18
|
+
timeoutSeconds が 0 なら、Python と同じくすぐ時間切れになる
|
|
19
|
+
*/
|
|
20
|
+
export declare function runSetupCommand(command: string, cwd: string, timeoutSeconds?: number): SetupResult;
|
|
21
|
+
//# sourceMappingURL=worktree-setup.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// ワークツリー作成後の setup_command の実行。Python の subprocess.run(shell=True)と同じ結果にする。
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { normalizeNewlines } from '../domain/python-format.js';
|
|
5
|
+
import { MAX_OUTPUT_BYTES } from './git.js';
|
|
6
|
+
import { hasErrorCode, toOsError } from './os-error.js';
|
|
7
|
+
const SIGNAL_NUMBERS = new Map(Object.entries(os.constants.signals));
|
|
8
|
+
function signalNumber(signal) {
|
|
9
|
+
return signal === null ? -1 : -(SIGNAL_NUMBERS.get(signal) ?? 1);
|
|
10
|
+
}
|
|
11
|
+
// Node の timeout は 0 が無期限。Python の timeout=0 はすぐ時間切れになるので、最短の 1 ミリ秒にする
|
|
12
|
+
function timeoutMilliseconds(timeoutSeconds) {
|
|
13
|
+
return timeoutSeconds === undefined ? undefined : Math.max(1, timeoutSeconds * 1000);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
setup_command を shell 経由で実行して、結果を構造化して返す。
|
|
17
|
+
|
|
18
|
+
stdin は常に閉じて、対話プロンプトで stall しないようにする。
|
|
19
|
+
timeoutSeconds を超えた場合は子プロセスを kill し、exitCode -1 の SetupResult を返す(例外は投げない)。-1 は timeout 起因の目印。
|
|
20
|
+
timeoutSeconds が 0 なら、Python と同じくすぐ時間切れになる
|
|
21
|
+
*/
|
|
22
|
+
export function runSetupCommand(command, cwd, timeoutSeconds) {
|
|
23
|
+
const result = spawnSync(command, {
|
|
24
|
+
cwd,
|
|
25
|
+
shell: true,
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
28
|
+
timeout: timeoutMilliseconds(timeoutSeconds),
|
|
29
|
+
killSignal: 'SIGKILL',
|
|
30
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
31
|
+
});
|
|
32
|
+
const isTimedOut = hasErrorCode(result.error) && result.error.code === 'ETIMEDOUT';
|
|
33
|
+
if (!isTimedOut && result.error !== undefined)
|
|
34
|
+
throw toOsError(result.error);
|
|
35
|
+
const stdout = normalizeNewlines(result.stdout);
|
|
36
|
+
const stderr = normalizeNewlines(result.stderr);
|
|
37
|
+
return isTimedOut
|
|
38
|
+
? { command, exitCode: -1, stdout, stderr: `${stderr}timeout after ${String(timeoutSeconds)} seconds`.trimStart() }
|
|
39
|
+
: { command, exitCode: result.status ?? signalNumber(result.signal), stdout, stderr };
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=worktree-setup.js.map
|