@tama-create/sf-tools 0.0.0-stage → 1.4.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +212 -2
  3. package/bin/sft.js +22 -0
  4. package/dist/cli.js +35 -0
  5. package/dist/commands/admin.js +46 -0
  6. package/dist/commands/check.js +20 -0
  7. package/dist/commands/ci.js +123 -0
  8. package/dist/commands/deploy.js +31 -0
  9. package/dist/commands/doctor.js +11 -0
  10. package/dist/commands/dryrun.js +17 -0
  11. package/dist/commands/hook.js +46 -0
  12. package/dist/commands/index.js +36 -0
  13. package/dist/commands/job.js +31 -0
  14. package/dist/commands/launcher.js +40 -0
  15. package/dist/commands/log.js +58 -0
  16. package/dist/commands/metasync.js +21 -0
  17. package/dist/commands/pr.js +32 -0
  18. package/dist/commands/project.js +93 -0
  19. package/dist/commands/push.js +16 -0
  20. package/dist/commands/release.js +19 -0
  21. package/dist/commands/start.js +19 -0
  22. package/dist/commands/switch-org.js +12 -0
  23. package/dist/commands/update-cli.js +11 -0
  24. package/dist/commands/version.js +18 -0
  25. package/dist/core/admin-clone.js +79 -0
  26. package/dist/core/ai-answers.js +40 -0
  27. package/dist/core/branches.js +88 -0
  28. package/dist/core/check-targets.js +170 -0
  29. package/dist/core/check.js +34 -0
  30. package/dist/core/ci-check-branch.js +150 -0
  31. package/dist/core/ci-login-steps.js +73 -0
  32. package/dist/core/ci-release-steps.js +193 -0
  33. package/dist/core/ci-sequence-steps.js +188 -0
  34. package/dist/core/ci-validate-steps.js +140 -0
  35. package/dist/core/command.js +25 -0
  36. package/dist/core/create-connect.js +519 -0
  37. package/dist/core/create-setup.js +314 -0
  38. package/dist/core/create-state.js +82 -0
  39. package/dist/core/delegate.js +45 -0
  40. package/dist/core/deploy.js +66 -0
  41. package/dist/core/diag.js +200 -0
  42. package/dist/core/doctor.js +211 -0
  43. package/dist/core/eca.js +259 -0
  44. package/dist/core/exit-codes.js +12 -0
  45. package/dist/core/gh-identity.js +46 -0
  46. package/dist/core/hook-install.js +130 -0
  47. package/dist/core/hook.js +116 -0
  48. package/dist/core/identity.js +48 -0
  49. package/dist/core/job.js +243 -0
  50. package/dist/core/launcher-status.js +184 -0
  51. package/dist/core/lines.js +25 -0
  52. package/dist/core/log-auto.js +56 -0
  53. package/dist/core/log-box.js +85 -0
  54. package/dist/core/log-collector.js +370 -0
  55. package/dist/core/log-format.js +44 -0
  56. package/dist/core/log-pull.js +565 -0
  57. package/dist/core/log-select.js +126 -0
  58. package/dist/core/log-session.js +362 -0
  59. package/dist/core/log-start.js +421 -0
  60. package/dist/core/log-status.js +223 -0
  61. package/dist/core/log-summarize.js +127 -0
  62. package/dist/core/logger.js +71 -0
  63. package/dist/core/login-url.js +50 -0
  64. package/dist/core/manifest-build.js +118 -0
  65. package/dist/core/mask.js +70 -0
  66. package/dist/core/metadata-types.js +79 -0
  67. package/dist/core/metasync.js +684 -0
  68. package/dist/core/org.js +115 -0
  69. package/dist/core/origin.js +62 -0
  70. package/dist/core/package-xml.js +157 -0
  71. package/dist/core/pr.js +199 -0
  72. package/dist/core/project-create.js +733 -0
  73. package/dist/core/project-reconnect.js +126 -0
  74. package/dist/core/project-status.js +235 -0
  75. package/dist/core/project-tier.js +374 -0
  76. package/dist/core/project-verify.js +517 -0
  77. package/dist/core/promote-check.js +368 -0
  78. package/dist/core/promote.js +141 -0
  79. package/dist/core/push.js +152 -0
  80. package/dist/core/release.js +256 -0
  81. package/dist/core/scoped-box.js +29 -0
  82. package/dist/core/start.js +155 -0
  83. package/dist/core/switch-org.js +49 -0
  84. package/dist/core/test-types.js +212 -0
  85. package/dist/core/toolbox.js +4 -0
  86. package/dist/core/update-cli.js +156 -0
  87. package/dist/core/update-secret.js +301 -0
  88. package/dist/core/update-workflows.js +132 -0
  89. package/dist/core/verify-gh.js +286 -0
  90. package/dist/core/verify-samples.js +152 -0
  91. package/dist/core/windows-shim.js +21 -0
  92. package/dist/io/capability-file.js +11 -0
  93. package/dist/io/create-deps.js +68 -0
  94. package/dist/io/doctor-deps.js +32 -0
  95. package/dist/io/hook-install-deps.js +11 -0
  96. package/dist/io/job-deps.js +31 -0
  97. package/dist/io/key-file.js +17 -0
  98. package/dist/io/keys.js +161 -0
  99. package/dist/io/log-deps.js +106 -0
  100. package/dist/io/metasync-deps.js +21 -0
  101. package/dist/io/open-browser.js +21 -0
  102. package/dist/io/package-version.js +10 -0
  103. package/dist/io/pinned-project.js +111 -0
  104. package/dist/io/promote-deps.js +27 -0
  105. package/dist/io/push-refs.js +20 -0
  106. package/dist/io/resolve.js +74 -0
  107. package/dist/io/run.js +201 -0
  108. package/dist/io/switch-org-deps.js +10 -0
  109. package/dist/io/temp-dir.js +10 -0
  110. package/dist/io/tool-versions.js +14 -0
  111. package/dist/io/toolbox.js +68 -0
  112. package/dist/io/update-cli-deps.js +75 -0
  113. package/dist/io/update-secret-deps.js +27 -0
  114. package/dist/launch.js +152 -0
  115. package/dist/ui/confirm.js +18 -0
  116. package/dist/ui/launcher.js +132 -0
  117. package/dist/ui/prompt.js +66 -0
  118. package/package.json +37 -4
@@ -0,0 +1,188 @@
1
+ // wf-sequence.yml の中のシェルの移し先(sft ci sequence-branch・sequence-check・slack-sequence・sequence-comment)。
2
+ // 入力は環境変数(利用者が決められる値は、シェルに直接埋め込まず、環境変数で受け取る: 雛形の決まり)。
3
+ // 結果は GITHUB_OUTPUT に書く(なければ、画面に出す)。
4
+ // sequence-branch は、対象が空でも、環境ブランチと、版・ワークフローを変える PR(REPOSITORY・PR_NUMBER で変更の一覧を読む。読めなければ素通りさせない)は、
5
+ // 順序チェックを行う(skip=false。設計 4.3 の R1)
6
+ import { hasContent, toolingChange } from "./ci-check-branch.js";
7
+ import { jst, postSlack, slackEscape } from "./ci-release-steps.js";
8
+ import { EXIT } from "./exit-codes.js";
9
+ import { runPromoteCheck } from "./promote-check.js";
10
+ function setOutput(box, name, value) {
11
+ const file = box.env("GITHUB_OUTPUT");
12
+ const line = `${name}=${value}\n`;
13
+ if (file)
14
+ box.files.appendText(file, line);
15
+ else
16
+ box.output.out(line.trim());
17
+ }
18
+ /**
19
+ * 「デプロイ対象ファイルを確認」: 順序チェックを飛ばしてよいか(skip)を決める。
20
+ * 環境ブランチ(main の branches.txt のブランチ)から出された PR は、デプロイ対象がなくても、必ず確かめる。
21
+ * main を取得できなければ、判定できない。素通りさせないよう skip=false で終える(このジョブは失敗にしない。順序チェックが、自分で失敗にする)
22
+ */
23
+ export async function runSequenceBranch(box) {
24
+ const head = box.env("HEAD_REF") ?? "";
25
+ if (head === "") {
26
+ box.output.err("[ERROR] HEAD_REF(PR の元のブランチ)が空です。");
27
+ return EXIT.failure;
28
+ }
29
+ const fetched = await box.run("git", ["fetch", "origin", "main", "--depth=1", "-q"]).catch(() => null);
30
+ if (fetched === null || fetched.code !== 0) {
31
+ setOutput(box, "skip", "false");
32
+ box.output.out("::warning::main を取得できませんでした。環境ブランチかを判定できないため、順序チェックを実行します。");
33
+ return EXIT.ok;
34
+ }
35
+ const shown = await box.run("git", ["show", "FETCH_HEAD:sf-tools/config/branches.txt"]).catch(() => null);
36
+ const envBranches = (shown?.code === 0 ? shown.stdout : "")
37
+ .split("\n")
38
+ .map((l) => l.replace(/\r/g, ""))
39
+ .filter((l) => !/^\s*#/.test(l) && !/^\s*$/.test(l));
40
+ if (envBranches.includes(head)) {
41
+ setOutput(box, "skip", "false");
42
+ box.output.out(`環境ブランチ(${head})からの PR のため、デプロイ対象がなくても、順序チェックを実行します。`);
43
+ return EXIT.ok;
44
+ }
45
+ const deploy = `sf-tools/release/${head}/deploy-target.txt`;
46
+ const remove = `sf-tools/release/${head}/remove-target.txt`;
47
+ if (!hasContent(box, deploy) && !hasContent(box, remove)) {
48
+ // 対象が空でも、sft の版(package.json・ロックファイル)やワークフローを変える PR は、前の段階の印を求める(R1。設計 4.3)。
49
+ // 変更の一覧を読めなければ、素通りさせない(skip=false)
50
+ const tooling = await toolingChange(box);
51
+ if (tooling.state !== "no") {
52
+ setOutput(box, "skip", "false");
53
+ box.output.out(`デプロイ対象はありませんが、${tooling.state === "yes" ? `${tooling.path} を変える` : "変更の一覧を読めない"} PR のため、順序チェックを実行します。`);
54
+ return EXIT.ok;
55
+ }
56
+ setOutput(box, "skip", "true");
57
+ box.output.out(`デプロイ対象なし(${deploy} / ${remove} に内容なし)のためスキップします。`);
58
+ }
59
+ else {
60
+ setOutput(box, "skip", "false");
61
+ }
62
+ return EXIT.ok;
63
+ }
64
+ /** promote-check の --json(最後の 1 行)から、破った規則と理由を読む。読めなければ空 */
65
+ export function readViolations(json) {
66
+ try {
67
+ const j = JSON.parse(json);
68
+ const vs = j.violations ?? [];
69
+ const detail = (vs.map((v) => v.detail).join(" ") || j.error || "").replace(/[\r\n]/g, " ");
70
+ return { rules: vs.map((v) => v.rule), detail };
71
+ }
72
+ catch {
73
+ return { rules: [], detail: "" };
74
+ }
75
+ }
76
+ /** 「マージ順序を検証」: promote-check --only sequence を呼び、結果を出力(feature・detail・env_branch・out_of_order)に書く */
77
+ export async function runSequenceCheck(box, deps) {
78
+ setOutput(box, "feature", box.env("FEATURE_REF") ?? "");
79
+ const lines = [];
80
+ const capture = { ...box, output: { out: (l) => lines.push(l), err: (l) => box.output.err(l) } };
81
+ const code = await runPromoteCheck(["--pr", box.env("PR_NUMBER") ?? "", "--only", "sequence", "--json"], capture, deps);
82
+ const json = lines[lines.length - 1] ?? "";
83
+ box.output.out(`結果: ${json}`);
84
+ const { rules, detail } = readViolations(json);
85
+ setOutput(box, "detail", detail);
86
+ if (rules.includes("R3"))
87
+ setOutput(box, "env_branch", "true");
88
+ if (code === 0) {
89
+ setOutput(box, "out_of_order", "false");
90
+ box.output.out("::notice title=順序 OK::前の段階に出した、同じコミットです(または、確かめるものがありません)。");
91
+ return EXIT.ok;
92
+ }
93
+ if (rules.includes("R1"))
94
+ setOutput(box, "out_of_order", "true");
95
+ box.output.out(`::error title=一方通行の決まり::${detail === "" ? "判断できませんでした(ログを見てください)" : detail}`);
96
+ return EXIT.failure;
97
+ }
98
+ /** Slack に送る本文(順序未確認・環境ブランチからの PR) */
99
+ export function sequenceSlackText(input) {
100
+ const feature = slackEscape(input.feature);
101
+ const base = slackEscape(input.base);
102
+ const pr = `• PR: <${slackEscape(input.url)}|#${slackEscape(input.number)} ${slackEscape(input.title)}>\n• 対象: \`${feature}\` → \`${base}\`\n• 実行日時: ${jst(input.now)}`;
103
+ if (input.envBranch) {
104
+ return `:no_entry: *環境ブランチからの PR は許可されていません*\n• ブランチ \`${feature}\` は、環境ブランチです\n${pr}\n• この PR は却下し、feature ブランチから作り直してください`;
105
+ }
106
+ return `:no_entry: *一方通行の決まりにより、この PR はマージできません*\n• ${slackEscape(input.detail)}\n${pr}\n• 前の段階に、同じコミットを出してから、出し直してください`;
107
+ }
108
+ /** 「Slack に順序未確認を通知」: 失敗しても、ステップは失敗にしない */
109
+ export async function runSlackSequence(box) {
110
+ const text = sequenceSlackText({
111
+ envBranch: box.env("ENV_BRANCH") === "true",
112
+ feature: box.env("FEATURE_RAW") ?? "",
113
+ detail: box.env("DETAIL_RAW") ?? "",
114
+ title: box.env("PR_TITLE_RAW") ?? "",
115
+ number: box.env("PR_NUMBER_RAW") ?? "",
116
+ url: box.env("PR_URL_RAW") ?? "",
117
+ base: box.env("BASE_RAW") ?? "",
118
+ now: box.clock.now(),
119
+ });
120
+ await postSlack(box, box.env("SLACK_CHANNEL_ID") ?? "", box.env("SLACK_BOT_TOKEN") ?? "", text);
121
+ return EXIT.ok;
122
+ }
123
+ export const SEQUENCE_MARK = "<!-- sf-tools:sequence -->";
124
+ /** PR の会話欄に投稿する本文。何も投稿しない(既存もなく、問題もない)ときは null */
125
+ export function sequenceCommentBody(input) {
126
+ if (!input.outOfOrder && !input.envBranch && !input.hasExisting)
127
+ return null;
128
+ if (input.envBranch) {
129
+ return [
130
+ SEQUENCE_MARK,
131
+ "## ⛔ 環境ブランチからの PR は、許可されていません",
132
+ "",
133
+ `\`${input.feature}\` は、環境ブランチ(\`branches.txt\` に記載のブランチ)です。\`${input.base}\` への PR は、feature ブランチから作成してください。`,
134
+ "",
135
+ "**この PR は却下し、feature ブランチから作り直してください。**(通常は、`sf-pr.sh` が示す順序で、PR を出します)",
136
+ ].join("\n");
137
+ }
138
+ if (input.outOfOrder) {
139
+ return [
140
+ SEQUENCE_MARK,
141
+ "## ⛔ 一方通行の決まりにより、この PR はマージできません",
142
+ "",
143
+ input.detail,
144
+ "",
145
+ "開発物は develop → staging → main の順に、同じコミットのまま上げます(staging で問題が出たら、開発環境で直して develop から出し直します)。",
146
+ "**前の段階に、同じコミットを出してから、この PR を出し直してください。**(通常は、`sf-pr.sh` が示す順序で、PR を出します)。この PR をマージしても、組織へのリリース(wf-release)は止まります",
147
+ ].join("\n");
148
+ }
149
+ return [SEQUENCE_MARK, "## ✅ マージ順序は、問題ありません", "", "前の段階に出した、同じコミットであることを確認しました。"].join("\n");
150
+ }
151
+ /** 「順序の結果を PR に投稿」: 同じ PR では、既存のコメント(目印: sf-tools:sequence)を更新する */
152
+ export async function runSequenceComment(box) {
153
+ const repo = box.env("REPOSITORY") ?? "";
154
+ const number = box.env("PR_NUMBER") ?? "";
155
+ const listed = await box.run("gh", [
156
+ "api",
157
+ "--paginate",
158
+ `repos/${repo}/issues/${number}/comments?per_page=100`,
159
+ "--jq",
160
+ `.[] | select((.body // "") | contains("${SEQUENCE_MARK}")) | .id`,
161
+ ]);
162
+ if (listed.code !== 0) {
163
+ box.output.err("[ERROR] PR のコメントの一覧を読めません。");
164
+ return EXIT.failure;
165
+ }
166
+ const existing = listed.stdout
167
+ .split("\n")
168
+ .find((l) => l.trim() !== "")
169
+ ?.trim();
170
+ const body = sequenceCommentBody({
171
+ envBranch: box.env("ENV_BRANCH") === "true",
172
+ outOfOrder: box.env("OUT_OF_ORDER") === "true",
173
+ hasExisting: existing !== undefined,
174
+ feature: box.env("FEATURE") ?? "",
175
+ detail: box.env("DETAIL") ?? "",
176
+ base: box.env("BASE_REF") ?? "",
177
+ });
178
+ if (body === null)
179
+ return EXIT.ok;
180
+ const sent = existing === undefined
181
+ ? await box.run("gh", ["api", "-X", "POST", `repos/${repo}/issues/${number}/comments`, "-f", `body=${body}`])
182
+ : await box.run("gh", ["api", "-X", "PATCH", `repos/${repo}/issues/comments/${existing}`, "-f", `body=${body}`]);
183
+ if (sent.code !== 0) {
184
+ box.output.err("[ERROR] PR にコメントを投稿できません。");
185
+ return EXIT.failure;
186
+ }
187
+ return EXIT.ok;
188
+ }
@@ -0,0 +1,140 @@
1
+ // wf-validate.yml の中のシェルの移し先(sft ci validate-stack・validate-release・validate-comment・validate-gate)。
2
+ // 入力は環境変数(利用者が決められる値は、シェルに直接埋め込まず、環境変数で受け取る: 雛形の決まり)。
3
+ // 実行のログは、VALIDATE_LOG(既定 /tmp/sf_result.txt)に溜め、PR のコメントに載せる。
4
+ // validate-stack は、PR の先端のコミットを取得した作業ツリー(force-promote-check)の中で動かす(working-directory)
5
+ import { EXIT } from "./exit-codes.js";
6
+ import { runPromoteCheck } from "./promote-check.js";
7
+ import { runRelease } from "./release.js";
8
+ const DEFAULT_LOG = "/tmp/sf_result.txt";
9
+ const MAX_LOG_CHARS = 3000;
10
+ const logPath = (box) => box.env("VALIDATE_LOG") || DEFAULT_LOG;
11
+ function setOutput(box, name, value) {
12
+ const file = box.env("GITHUB_OUTPUT");
13
+ const line = `${name}=${value}\n`;
14
+ if (file)
15
+ box.files.appendText(file, line);
16
+ else
17
+ box.output.out(line.trim());
18
+ }
19
+ /** 出力(画面・エラー)をログに溜める箱。溜めた行は、あとで画面にも出す(シェル版は、ログに書いてから cat していた) */
20
+ function logging(box, lines) {
21
+ return { ...box, output: { out: (l) => lines.push(l), err: (l) => lines.push(l) } };
22
+ }
23
+ function flush(box, lines) {
24
+ if (lines.length === 0)
25
+ return;
26
+ box.files.appendText(logPath(box), `${lines.join("\n")}\n`);
27
+ for (const l of lines)
28
+ box.output.out(l);
29
+ }
30
+ /** 「一方通行の確認(積み重ね)」: promote-check --only stack。結果を、出力 stack_exit に残す。失敗でも、このステップは失敗にしない */
31
+ export async function runValidateStack(box, deps) {
32
+ box.files.writeText(logPath(box), "");
33
+ const lines = [];
34
+ const code = await runPromoteCheck(["--pr", box.env("PR_NUMBER") ?? "", "--only", "stack"], logging(box, lines), deps);
35
+ flush(box, lines);
36
+ setOutput(box, "stack_exit", String(code));
37
+ if (code !== 0) {
38
+ box.output.out("::error title=一方通行の決まり::積み重ねの確認(R2)で止めました。前に出した部品が、今回の一覧にありません(上のログ)。");
39
+ }
40
+ return EXIT.ok;
41
+ }
42
+ /**
43
+ * 「デプロイ検証(反映なし)」: 積み重ねの確認が 0 のときだけ、release --no-open を動かす。
44
+ * 終了コードを出力 exit_code に残す(どちらが失敗しても、このステップは失敗にしない。validate-gate が判定する)
45
+ */
46
+ export async function runValidateRelease(box, deps) {
47
+ const stack = (box.env("STACK_EXIT") ?? "").trim();
48
+ let code;
49
+ if (stack !== "0") {
50
+ // 積み重ねの確認で止めた(または、結果が空)。デプロイ検証はせず、その終了コードを使う
51
+ code = /^\d+$/.test(stack) ? Number(stack) : EXIT.failure;
52
+ }
53
+ else {
54
+ const lines = [];
55
+ code = await runRelease(["--no-open"], logging(box, lines), deps);
56
+ flush(box, lines);
57
+ }
58
+ setOutput(box, "exit_code", String(code));
59
+ return EXIT.ok;
60
+ }
61
+ /** 端末の色の指定(ANSI エスケープコード)を除く。残すと、PR のコメントや通知メールで化ける */
62
+ export function stripAnsi(text) {
63
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: ESC(0x1b)で始まる、端末の色の指定を除くため
64
+ return text.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "");
65
+ }
66
+ /** PR に投稿する本文。exitCode が空 = 検証が実行されなかった(⚠️)、0 = ✅、それ以外 = ❌ */
67
+ export function validateCommentBody(input) {
68
+ const code = input.exitCode.trim();
69
+ let icon;
70
+ let result;
71
+ if (code === "") {
72
+ icon = "⚠️";
73
+ result = "検証が実行されませんでした(sf-release.sh の終了コードを取得できません。前のステップの失敗、または取り消し・タイムアウト)";
74
+ }
75
+ else if (code === "0") {
76
+ icon = "✅";
77
+ result = "検証成功";
78
+ }
79
+ else {
80
+ icon = "❌";
81
+ result = `検証失敗(終了コード ${code})`;
82
+ }
83
+ const log = stripAnsi(input.log);
84
+ const shown = log.length > MAX_LOG_CHARS ? `...(前半省略)...\n${log.slice(-MAX_LOG_CHARS)}` : log;
85
+ return [
86
+ `## ${icon} Salesforce 検証結果: ${result}`,
87
+ "",
88
+ "| 項目 | 値 |",
89
+ "| --- | --- |",
90
+ `| ブランチ | \`${input.head}\` → \`${input.base}\` |`,
91
+ `| コミット | \`${input.sha}\` |`,
92
+ "| 実行モード | 検証のみ(反映なし) |",
93
+ "",
94
+ "<details>",
95
+ "<summary>実行ログ(クリックで展開)</summary>",
96
+ "",
97
+ "```",
98
+ shown,
99
+ "```",
100
+ "",
101
+ "</details>",
102
+ ].join("\n");
103
+ }
104
+ /** 「検証結果を PR に投稿」: 毎回、新しいコメントを追加する。投稿に失敗したら、ステップを失敗にする */
105
+ export async function runValidateComment(box) {
106
+ let log;
107
+ try {
108
+ log = box.files.readText(logPath(box));
109
+ }
110
+ catch {
111
+ log = "(ログファイルが見つかりません)";
112
+ }
113
+ const body = validateCommentBody({
114
+ head: box.env("HEAD_REF") ?? "",
115
+ base: box.env("BASE_REF") ?? "",
116
+ sha: box.env("HEAD_SHA") ?? "",
117
+ exitCode: box.env("EXIT_CODE") ?? "",
118
+ log,
119
+ });
120
+ const sent = await box.run("gh", [
121
+ "api",
122
+ "-X",
123
+ "POST",
124
+ `repos/${box.env("REPOSITORY") ?? ""}/issues/${box.env("PR_NUMBER") ?? ""}/comments`,
125
+ "-f",
126
+ `body=${body}`,
127
+ ]);
128
+ if (sent.code !== 0) {
129
+ box.output.err("[ERROR] PR にコメントを投稿できません。");
130
+ return EXIT.failure;
131
+ }
132
+ return EXIT.ok;
133
+ }
134
+ /** 「検証失敗時はマージをブロック」: 検証の終了コードで、ジョブを終える(0 以外・空(空は 1)なら失敗) */
135
+ export function runValidateGate(box) {
136
+ const raw = (box.env("EXIT_CODE") ?? "").trim();
137
+ if (raw === "")
138
+ return EXIT.failure;
139
+ return /^\d+$/.test(raw) ? Number(raw) : EXIT.failure;
140
+ }
@@ -0,0 +1,25 @@
1
+ /** 全体の --help */
2
+ export function helpText(version, commands) {
3
+ const width = Math.max(...commands.map((c) => c.name.length));
4
+ return [
5
+ `sft ${version}`,
6
+ "",
7
+ "使い方: sft <サブコマンド> [引数]",
8
+ "",
9
+ ...commands.map((c) => ` ${c.name.padEnd(width)} ${c.summary}`),
10
+ "",
11
+ " -h, --help 使い方を表示する",
12
+ " -v, --version 版を表示する",
13
+ ].join("\n");
14
+ }
15
+ /** サブコマンドの --help */
16
+ export function commandHelpText(command) {
17
+ const lines = [`使い方: sft ${command.name}`, "", command.summary];
18
+ if (command.options.length > 0) {
19
+ lines.push("", "オプション:", ...command.options.map((o) => ` ${o.flag} ${o.summary}`));
20
+ }
21
+ if (command.exitCodes.length > 0) {
22
+ lines.push("", "終了コード(0 成功・1 失敗のほか):", ...command.exitCodes.map((e) => ` ${e.code} ${e.summary}`));
23
+ }
24
+ return lines.join("\n");
25
+ }