@botiverse/stamp-cli 0.3.1 → 0.3.3
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/README.md +47 -0
- package/bin/stamp-staging.mjs +1 -0
- package/bin/stamp.mjs +61 -5
- package/lib/agent-refresh.mjs +17 -4
- package/lib/auth.mjs +103 -4
- package/lib/errors.mjs +43 -0
- package/lib/locale.mjs +182 -59
- package/lib/main.mjs +174 -20
- package/lib/pr-comment.mjs +39 -0
- package/lib/pr-read.mjs +429 -0
- package/lib/repo-clone.mjs +60 -0
- package/package.json +2 -2
package/lib/locale.mjs
CHANGED
|
@@ -1,45 +1,95 @@
|
|
|
1
1
|
/** User-visible copy. Machine protocol fields and stable error codes stay English. */
|
|
2
2
|
export const messages = {
|
|
3
3
|
en: {
|
|
4
|
-
usagePrCreate: "usage:
|
|
5
|
-
|
|
4
|
+
usagePrCreate: "usage: {cli} pr create --receipt ID --repo OWNER/REPO --head BRANCH --sha SHA --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]",
|
|
5
|
+
usagePrRead: "usage: {cli} pr <list|view|diff|checks|comment> [arguments]",
|
|
6
|
+
usagePrComment: "usage: {cli} pr comment <NUMBER -R OWNER/REPO|PR_URL> (--body TEXT|--body-file FILE|-) (human GitHub identity required)",
|
|
7
|
+
prCommentBodyInvalid: "Comment must be nonempty and at most 64 KiB of UTF-8 text.",
|
|
8
|
+
prCommentCreated: "Comment posted as {actor}: {url}",
|
|
9
|
+
prCommentRejected: "Comment request was rejected. Check your human session, GitHub binding, repository access and input.",
|
|
10
|
+
prCommentOutcomeUnknown: "Comment outcome is unknown. Check the PR comments before sending again; do not automatically resend.",
|
|
11
|
+
usagePrList: "usage: {cli} pr list",
|
|
12
|
+
usagePrView: "usage: {cli} pr view <number|URL> [--repo OWNER/REPO]",
|
|
13
|
+
usagePrDiff: "usage: {cli} pr diff <number|URL> [--repo OWNER/REPO] [--name-only]",
|
|
14
|
+
usagePrChecks: "usage: {cli} pr checks <number|URL> [--repo OWNER/REPO]",
|
|
15
|
+
prReadInvalidResponse: "Stamp returned an invalid PR read response; retry after checking the service version.",
|
|
16
|
+
prReadCoordinateMismatch: "Stamp returned PR coordinates different from the requested repository or number; refusing to display them.",
|
|
17
|
+
prListEmpty: "No Stamp-created pull requests found.",
|
|
18
|
+
prStatusUnavailable: "status unavailable",
|
|
19
|
+
prCIShort: "CI",
|
|
20
|
+
prAgentShort: "Agent",
|
|
21
|
+
prHeadLabel: "Head",
|
|
22
|
+
prChecksLabel: "Checks",
|
|
23
|
+
prReviewLabel: "Review",
|
|
24
|
+
prDiffUnavailable: "patch unavailable",
|
|
25
|
+
prDiffEmpty: "No changed files reported.",
|
|
26
|
+
prChecksEmpty: "No checks reported.",
|
|
27
|
+
prReadNotFound: "Check the repository and PR number, and confirm this Agent created the PR through Stamp.",
|
|
28
|
+
prReadHeadMoved: "The PR head changed while Stamp read the diff; rerun the command and review the new head.",
|
|
29
|
+
prReadDiffIncomplete: "GitHub did not return the complete PR diff; retry later instead of relying on partial files.",
|
|
30
|
+
prReadUnavailable: "The PR read is temporarily unavailable; retry after checking Stamp service status.",
|
|
31
|
+
prListMore: "More results available; rerun with --limit and --cursor {cursor}.",
|
|
32
|
+
prSection_drafts: "Drafts",
|
|
33
|
+
prSection_changes: "Changes requested",
|
|
34
|
+
prSection_approved: "Approved",
|
|
35
|
+
prSection_approvals: "Has approvals",
|
|
36
|
+
prSection_waiting: "Waiting for review",
|
|
37
|
+
prSection_history: "History",
|
|
38
|
+
prSection_unavailable: "Status unavailable",
|
|
39
|
+
prCursorScope: "This cursor does not belong to the current identity or scope; rerun {cli} pr list from the start.",
|
|
40
|
+
prCursorInvalid: "The cursor is invalid or expired; rerun {cli} pr list from the start.",
|
|
41
|
+
prRequired: "Missing {flag}; use {cli} receipt get <id> to obtain the published coordinates.",
|
|
6
42
|
prRepository: "--repo must be OWNER/REPO.",
|
|
7
43
|
prSHA: "--sha must be the exact 40-character lowercase published commit SHA.",
|
|
8
44
|
prBodyRequired: "Provide a non-empty PR description with --body or --body-file (use - for stdin).",
|
|
9
|
-
prCheckArguments: "Check the PR arguments with
|
|
45
|
+
prCheckArguments: "Check the PR arguments with {cli} pr create --help; correct invalid or empty values before retrying.",
|
|
10
46
|
prCheckConfiguration: "Ask the service administrator to repair the GitHub App configuration before retrying.",
|
|
11
47
|
prBodyConflict: "Use either --body or --body-file, not both.",
|
|
12
48
|
prBodyRead: "Cannot read --body-file; check the file path or pass - for stdin.",
|
|
13
49
|
prIdempotency: "--idempotency-key must contain 16–128 letters, digits, dots, underscores, colons, or hyphens.",
|
|
14
50
|
prCreated: "Created PR #{number}: {url}",
|
|
15
51
|
prExisting: "Existing PR #{number}: {url}",
|
|
16
|
-
prWaitPublished: "Check
|
|
52
|
+
prWaitPublished: "Check {cli} receipt get <id>; use your own receipt after its status becomes PUBLISHED.",
|
|
17
53
|
prCheckReceipt: "Read the receipt again and check --repo, --head and --sha against the exact published commit.",
|
|
18
54
|
prCheckAccess: "Check repository access and the authorized base branch with the repository administrator.",
|
|
19
55
|
prCheckExisting: "Check the existing PR and keep the same receipt, title, body and idempotency key when retrying.",
|
|
20
56
|
prRetry: "Check the receipt and service status, then retry the identical command; its idempotency key stays unchanged.",
|
|
57
|
+
apiBindIdentity: "Bind this agent first with `{cli} identity bind --email <agent-email>`, then retry the command.",
|
|
58
|
+
apiRepositoryNotInstalled: "Check OWNER/REPO spelling, or ask a server owner to install the Stamp GitHub App on that repository, then retry.",
|
|
59
|
+
apiContributionDenied: "Ask a server owner to grant this agent an active Write-or-higher repository role, then retry.",
|
|
60
|
+
apiRepositoryNotAuthorized: "Ask a server owner to verify the Stamp GitHub App installation and this agent's identity binding, then retry.",
|
|
21
61
|
|
|
22
|
-
usage: `
|
|
62
|
+
usage: `{cli} {version} — Agent Git gateway CLI
|
|
23
63
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
64
|
+
{cli} login agent: PKCE login via raft (no browser); human: how to set STAMP_TOKEN
|
|
65
|
+
{cli} logout agent: forget the stored session
|
|
66
|
+
{cli} whoami who the gateway thinks you are
|
|
67
|
+
{cli} migration-help old manifest actions → CLI mapping
|
|
68
|
+
{cli} key enroll [--public-key FILE|-] bind this agent's SSH public key (default ~/.ssh/id_ed25519.pub)
|
|
69
|
+
{cli} identity bind --email ADDR bind commit-author email (DCO)
|
|
70
|
+
{cli} receipt get <id> gateway acceptance + GitHub publication status
|
|
71
|
+
{cli} pr create --receipt ID --repo OWNER/REPO --head BRANCH --sha SHA --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
|
|
72
|
+
{cli} pr list
|
|
73
|
+
{cli} pr view <number|URL> --repo OWNER/REPO
|
|
74
|
+
{cli} pr diff <number|URL> --repo OWNER/REPO [--name-only]
|
|
75
|
+
{cli} pr checks <number|URL> --repo OWNER/REPO
|
|
76
|
+
{cli} pr comment <number|URL> --repo OWNER/REPO --body-file FILE|- (human)
|
|
77
|
+
{cli} repo clone <repository> [<directory>] [-- <gitflags>...]
|
|
32
78
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
79
|
+
{cli} follow <owner/repo> --kind issue|pull --number N
|
|
80
|
+
{cli} unfollow <owner/repo> --kind issue|pull --number N
|
|
81
|
+
{cli} subscription pause|resume <owner/repo> --kind issue|pull --number N
|
|
82
|
+
{cli} subscriptions
|
|
83
|
+
{cli} watch <owner/repo> --event TYPE
|
|
84
|
+
{cli} unwatch <owner/repo> --event TYPE
|
|
39
85
|
|
|
86
|
+
git clone ssh://git@ssh.staging.stamp.build:443/org/repo.git
|
|
40
87
|
git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
|
|
41
88
|
|
|
42
89
|
flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance), STAMP_SERVICE, STAMP_LANG`,
|
|
90
|
+
usageRepoClone: "usage: {cli} repo clone <repository> [<directory>] [-- <gitflags>...]",
|
|
91
|
+
cloned: "Cloned {repository} from {url}",
|
|
92
|
+
cloneFailed: "clone of {repository} via the Stamp gateway failed",
|
|
43
93
|
loginHumanIntro: "Not a managed Raft agent. Humans and CI use STAMP_TOKEN:",
|
|
44
94
|
loginHumanBrowser: " browser: {url}/login (reuse the session cookie value as STAMP_TOKEN)",
|
|
45
95
|
loginHumanCI: " CI: a narrowly scoped deploy token",
|
|
@@ -48,18 +98,20 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
|
|
|
48
98
|
logoutNothing: "nothing stored (human/CI lane uses STAMP_TOKEN)",
|
|
49
99
|
enrolled: "enrolled {fingerprint} ({keyId})",
|
|
50
100
|
bound: "bound {email}",
|
|
51
|
-
usageKeyEnroll: "usage:
|
|
52
|
-
usageIdentityBind: "usage:
|
|
53
|
-
usageReceiptGet: "usage:
|
|
54
|
-
usageFollow: "usage:
|
|
55
|
-
usageSubscription: "usage:
|
|
56
|
-
usageWatch: "usage:
|
|
101
|
+
usageKeyEnroll: "usage: {cli} key enroll [--public-key FILE|-]",
|
|
102
|
+
usageIdentityBind: "usage: {cli} identity bind --email ADDR",
|
|
103
|
+
usageReceiptGet: "usage: {cli} receipt get <receipt-id>",
|
|
104
|
+
usageFollow: "usage: {cli} <follow|unfollow|subscription …> <owner/repo> --kind issue|pull --number N",
|
|
105
|
+
usageSubscription: "usage: {cli} subscription pause|resume <owner/repo> --kind issue|pull --number N",
|
|
106
|
+
usageWatch: "usage: {cli} {cmd} <owner/repo> --event TYPE",
|
|
57
107
|
helpInstall: "install: {cmds}",
|
|
58
108
|
helpAgentLogin: "agent login: {text}",
|
|
59
|
-
sessionRejected: "
|
|
60
|
-
checkToken: "
|
|
61
|
-
notLoggedIn: "not logged in: run `
|
|
62
|
-
|
|
109
|
+
sessionRejected: "{cli}: session rejected — run `{cli} login`",
|
|
110
|
+
checkToken: "{cli}: check STAMP_TOKEN",
|
|
111
|
+
notLoggedIn: "not logged in: run `{cli} login` (managed agent)",
|
|
112
|
+
sessionOriginMismatch: "the stored session was issued for {stored}, not {target} — run `{cli} login` again",
|
|
113
|
+
pair_mismatch: "refusing a mismatched instance pair: {origin} belongs to service {owner}, not {service} (task #439)",
|
|
114
|
+
stampTokenMissing: "STAMP_TOKEN is not set (session or deploy token); inside a managed agent run `{cli} login`",
|
|
63
115
|
admission_partial: "refusing to run: partial managed-agent environment ({reason}); not falling back to STAMP_TOKEN",
|
|
64
116
|
invoke_not_json: "agent-login: `raft integration invoke` did not return JSON",
|
|
65
117
|
invoke_not_object: "agent-login: invoke output is not an object",
|
|
@@ -101,45 +153,95 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
|
|
|
101
153
|
refresh_wait_timeout: "agent-login: timed out waiting for a concurrent token refresh",
|
|
102
154
|
},
|
|
103
155
|
"zh-CN": {
|
|
104
|
-
usagePrCreate: "用法:
|
|
105
|
-
|
|
156
|
+
usagePrCreate: "用法:{cli} pr create --receipt ID --repo OWNER/REPO --head BRANCH --sha SHA --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]",
|
|
157
|
+
usagePrRead: "用法:{cli} pr <list|view|diff|checks|comment> [参数]",
|
|
158
|
+
usagePrComment: "用法:{cli} pr comment <NUMBER -R OWNER/REPO|PR_URL> (--body TEXT|--body-file FILE|-)(需要本人 GitHub 身份)",
|
|
159
|
+
prCommentBodyInvalid: "评论不能为空,UTF-8 文本最多 64 KiB。",
|
|
160
|
+
prCommentCreated: "已以 {actor} 身份发表评论:{url}",
|
|
161
|
+
prCommentRejected: "评论请求被拒绝,请检查人类会话、GitHub 绑定、仓库权限和输入。",
|
|
162
|
+
prCommentOutcomeUnknown: "评论结果不明。请先查看 PR 评论,不要自动重发。",
|
|
163
|
+
usagePrList: "用法:{cli} pr list",
|
|
164
|
+
usagePrView: "用法:{cli} pr view <编号|URL> [--repo OWNER/REPO]",
|
|
165
|
+
usagePrDiff: "用法:{cli} pr diff <编号|URL> [--repo OWNER/REPO] [--name-only]",
|
|
166
|
+
usagePrChecks: "用法:{cli} pr checks <编号|URL> [--repo OWNER/REPO]",
|
|
167
|
+
prReadInvalidResponse: "Stamp 返回了无效的 PR 读取响应;请检查服务版本后重试。",
|
|
168
|
+
prReadCoordinateMismatch: "Stamp 返回的 PR 坐标与请求的仓库或编号不一致;已拒绝显示。",
|
|
169
|
+
prListEmpty: "没有找到通过 Stamp 创建的 Pull Request。",
|
|
170
|
+
prStatusUnavailable: "实时状态暂不可用",
|
|
171
|
+
prCIShort: "CI",
|
|
172
|
+
prAgentShort: "Agent",
|
|
173
|
+
prHeadLabel: "Head",
|
|
174
|
+
prChecksLabel: "检查",
|
|
175
|
+
prReviewLabel: "审阅",
|
|
176
|
+
prDiffUnavailable: "patch 不可用",
|
|
177
|
+
prDiffEmpty: "没有变更文件。",
|
|
178
|
+
prChecksEmpty: "没有检查记录。",
|
|
179
|
+
prReadNotFound: "请检查仓库和 PR 编号,并确认该 PR 是此 Agent 通过 Stamp 创建的。",
|
|
180
|
+
prReadHeadMoved: "Stamp 读取 diff 时 PR head 已变化;请重新运行命令并审阅新的 head。",
|
|
181
|
+
prReadDiffIncomplete: "GitHub 未返回完整的 PR diff;请稍后重试,不要依赖部分文件。",
|
|
182
|
+
prReadUnavailable: "PR 读取暂时不可用;请检查 Stamp 服务状态后重试。",
|
|
183
|
+
prListMore: "还有更多结果;用 --limit 与 --cursor {cursor} 继续翻页。",
|
|
184
|
+
prSection_drafts: "草稿",
|
|
185
|
+
prSection_changes: "需修改",
|
|
186
|
+
prSection_approved: "已批准",
|
|
187
|
+
prSection_approvals: "有批准",
|
|
188
|
+
prSection_waiting: "等待评审",
|
|
189
|
+
prSection_history: "历史",
|
|
190
|
+
prSection_unavailable: "状态暂不可用",
|
|
191
|
+
prCursorScope: "该 cursor 不属于当前身份或范围;请从头重新运行 {cli} pr list。",
|
|
192
|
+
prCursorInvalid: "cursor 无效或已过期;请从头重新运行 {cli} pr list。",
|
|
193
|
+
prRequired: "缺少 {flag};用 {cli} receipt get <id> 获取已发表提交的信息。",
|
|
106
194
|
prRepository: "--repo 必须为 OWNER/REPO。",
|
|
107
195
|
prSHA: "--sha 必须是已发表提交的精确 40 位小写 SHA。",
|
|
108
196
|
prBodyRequired: "请用 --body 或 --body-file 提供非空 PR 正文(用 - 从标准输入读取)。",
|
|
109
|
-
prCheckArguments: "请用
|
|
197
|
+
prCheckArguments: "请用 {cli} pr create --help 检查参数,修正无效或空值后再重试。",
|
|
110
198
|
prCheckConfiguration: "请先联系服务管理员修复 GitHub App 配置,再重试。",
|
|
111
199
|
prBodyConflict: "--body 与 --body-file 只能选一个。",
|
|
112
200
|
prBodyRead: "无法读取 --body-file;请检查路径,或用 - 从标准输入读取。",
|
|
113
201
|
prIdempotency: "--idempotency-key 必须为 16–128 位字母、数字、点、下划线、冒号或连字符。",
|
|
114
202
|
prCreated: "已创建 PR #{number}:{url}",
|
|
115
203
|
prExisting: "已有 PR #{number}:{url}",
|
|
116
|
-
prWaitPublished: "请用
|
|
204
|
+
prWaitPublished: "请用 {cli} receipt get <id> 检查;只使用自己状态为 PUBLISHED 的 receipt。",
|
|
117
205
|
prCheckReceipt: "请重新读取 receipt,并核对 --repo、--head 和 --sha 是否与已发表提交一致。",
|
|
118
206
|
prCheckAccess: "请与仓库管理员核对仓库权限和允许的目标分支。",
|
|
119
207
|
prCheckExisting: "请检查已有 PR;重试时保持 receipt、标题、正文和幂等键不变。",
|
|
120
208
|
prRetry: "请检查 receipt 和服务状态,再原样重试命令;幂等键会保持不变。",
|
|
209
|
+
apiBindIdentity: "请先运行 `{cli} identity bind --email <agent-email>` 绑定此 Agent,再重试命令。",
|
|
210
|
+
apiRepositoryNotInstalled: "请检查 OWNER/REPO 拼写,或请 Server Owner 为该仓库安装 Stamp GitHub App,再重试。",
|
|
211
|
+
apiContributionDenied: "请让 Server Owner 为此 Agent 授予有效的 Write 或更高仓库角色,再重试。",
|
|
212
|
+
apiRepositoryNotAuthorized: "请让 Server Owner 核对 Stamp GitHub App 安装与此 Agent 的身份绑定,再重试。",
|
|
121
213
|
|
|
122
|
-
usage: `
|
|
214
|
+
usage: `{cli} {version} — Agent Git 网关 CLI
|
|
123
215
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
216
|
+
{cli} login Agent:经 raft 做 PKCE 登录(无浏览器);人类:如何设置 STAMP_TOKEN
|
|
217
|
+
{cli} logout Agent:忘掉已存会话
|
|
218
|
+
{cli} whoami 网关认为你是谁
|
|
219
|
+
{cli} migration-help 旧 manifest action → CLI 对照
|
|
220
|
+
{cli} key enroll [--public-key FILE|-] 绑定此 Agent 的 SSH 公钥(默认 ~/.ssh/id_ed25519.pub)
|
|
221
|
+
{cli} identity bind --email ADDR 绑定提交作者邮箱(DCO)
|
|
222
|
+
{cli} receipt get <id> 网关接受与 GitHub 发表状态
|
|
223
|
+
{cli} pr create --receipt ID --repo OWNER/REPO --head BRANCH --sha SHA --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
|
|
224
|
+
{cli} pr list
|
|
225
|
+
{cli} pr view <编号|URL> --repo OWNER/REPO
|
|
226
|
+
{cli} pr diff <编号|URL> --repo OWNER/REPO [--name-only]
|
|
227
|
+
{cli} pr checks <编号|URL> --repo OWNER/REPO
|
|
228
|
+
{cli} pr comment <编号|URL> --repo OWNER/REPO --body-file FILE|- (本人 GitHub 身份)
|
|
229
|
+
{cli} repo clone <repository> [<directory>] [-- <gitflags>...]
|
|
132
230
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
231
|
+
{cli} follow <owner/repo> --kind issue|pull --number N
|
|
232
|
+
{cli} unfollow <owner/repo> --kind issue|pull --number N
|
|
233
|
+
{cli} subscription pause|resume <owner/repo> --kind issue|pull --number N
|
|
234
|
+
{cli} subscriptions
|
|
235
|
+
{cli} watch <owner/repo> --event TYPE
|
|
236
|
+
{cli} unwatch <owner/repo> --event TYPE
|
|
139
237
|
|
|
238
|
+
git clone ssh://git@ssh.staging.stamp.build:443/org/repo.git
|
|
140
239
|
git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
|
|
141
240
|
|
|
142
241
|
flags: --json --lang en|zh-CN env: STAMP_TOKEN(人类/CI)、STAMP_URL、STAMP_SERVICE、STAMP_LANG`,
|
|
242
|
+
usageRepoClone: "用法:{cli} repo clone <repository> [<directory>] [-- <gitflags>...]",
|
|
243
|
+
cloned: "已从 {url} 克隆 {repository}",
|
|
244
|
+
cloneFailed: "经 Stamp 网关克隆 {repository} 失败",
|
|
143
245
|
loginHumanIntro: "当前不是受管 Raft Agent。人类和 CI 使用 STAMP_TOKEN:",
|
|
144
246
|
loginHumanBrowser: " 浏览器:{url}/login (把会话 cookie 值设为 STAMP_TOKEN)",
|
|
145
247
|
loginHumanCI: " CI: 由负责人签发的窄范围部署令牌",
|
|
@@ -148,18 +250,20 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN(人类/CI)、STAMP_URL、ST
|
|
|
148
250
|
logoutNothing: "没有本地会话(人类/CI 通道使用 STAMP_TOKEN)",
|
|
149
251
|
enrolled: "已登记 {fingerprint}({keyId})",
|
|
150
252
|
bound: "已绑定 {email}",
|
|
151
|
-
usageKeyEnroll: "用法:
|
|
152
|
-
usageIdentityBind: "用法:
|
|
153
|
-
usageReceiptGet: "用法:
|
|
154
|
-
usageFollow: "用法:
|
|
155
|
-
usageSubscription: "用法:
|
|
156
|
-
usageWatch: "用法:
|
|
253
|
+
usageKeyEnroll: "用法:{cli} key enroll [--public-key FILE|-]",
|
|
254
|
+
usageIdentityBind: "用法:{cli} identity bind --email ADDR",
|
|
255
|
+
usageReceiptGet: "用法:{cli} receipt get <receipt-id>",
|
|
256
|
+
usageFollow: "用法:{cli} <follow|unfollow|subscription …> <owner/repo> --kind issue|pull --number N",
|
|
257
|
+
usageSubscription: "用法:{cli} subscription pause|resume <owner/repo> --kind issue|pull --number N",
|
|
258
|
+
usageWatch: "用法:{cli} {cmd} <owner/repo> --event TYPE",
|
|
157
259
|
helpInstall: "安装:{cmds}",
|
|
158
260
|
helpAgentLogin: "Agent 登录:{text}",
|
|
159
|
-
sessionRejected: "
|
|
160
|
-
checkToken: "
|
|
161
|
-
notLoggedIn: "尚未登录:请运行 `
|
|
162
|
-
|
|
261
|
+
sessionRejected: "{cli}: 会话被拒绝 — 请运行 `{cli} login`",
|
|
262
|
+
checkToken: "{cli}: 请检查 STAMP_TOKEN",
|
|
263
|
+
notLoggedIn: "尚未登录:请运行 `{cli} login`(受管 Agent)",
|
|
264
|
+
sessionOriginMismatch: "已存会话是给 {stored} 签发的,不是 {target}——请重新运行 `{cli} login`",
|
|
265
|
+
pair_mismatch: "拒绝不匹配的实例配对:{origin} 属于服务 {owner},而非 {service}(task #439)",
|
|
266
|
+
stampTokenMissing: "未设置 STAMP_TOKEN(会话或部署令牌);在受管 Agent 内请运行 `{cli} login`",
|
|
163
267
|
admission_partial: "拒绝运行:受管 Agent 环境不完整({reason});不会回退到 STAMP_TOKEN",
|
|
164
268
|
invoke_not_json: "agent-login: `raft integration invoke` 没有返回 JSON",
|
|
165
269
|
invoke_not_object: "agent-login: invoke 输出不是对象",
|
|
@@ -208,9 +312,28 @@ export function selectLocale(env = process.env, explicit) {
|
|
|
208
312
|
return "en";
|
|
209
313
|
}
|
|
210
314
|
|
|
315
|
+
// The binary that targets THIS instance. Set once by the entry point (main());
|
|
316
|
+
// every command reference in the tables uses `{cli}` so user-visible copy names
|
|
317
|
+
// the binary the reader actually invoked — a staging user must never be told to
|
|
318
|
+
// run `stamp` (@phage: the error surface reaches users before the docs).
|
|
319
|
+
// Product names ("Stamp"), the package id and historical facts are NOT `{cli}`.
|
|
320
|
+
let cliName = "stamp";
|
|
321
|
+
|
|
322
|
+
export function setCliName(name) {
|
|
323
|
+
if (typeof name === "string" && name.length > 0) cliName = name;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The `<binary>:` banner that prefixes user-facing diagnostics. It names the
|
|
327
|
+
* binary the user actually ran, so a staging user sees `stamp-staging:` and not
|
|
328
|
+
* the production name (task #444 / #439). */
|
|
329
|
+
export function prefix() {
|
|
330
|
+
return `${cliName}: `;
|
|
331
|
+
}
|
|
332
|
+
|
|
211
333
|
export function t(locale, key, vars = {}) {
|
|
212
334
|
const table = messages[locale] || messages.en;
|
|
213
335
|
let s = table[key] || messages.en[key] || key;
|
|
214
|
-
|
|
336
|
+
const all = { cli: cliName, ...vars };
|
|
337
|
+
for (const [k, v] of Object.entries(all)) s = s.replaceAll(`{${k}}`, String(v));
|
|
215
338
|
return s;
|
|
216
339
|
}
|
package/lib/main.mjs
CHANGED
|
@@ -5,9 +5,37 @@ import { createRequire } from "node:module";
|
|
|
5
5
|
import { resolveAuth } from "./auth.mjs";
|
|
6
6
|
import { makeClient, ApiError } from "./client.mjs";
|
|
7
7
|
import { runAgentLogin } from "./agent-login.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { basename } from "node:path";
|
|
9
|
+
import { selectLocale, t, setCliName, prefix } from "./locale.mjs";
|
|
9
10
|
import { pullRequestInput, pullRequestRecovery } from "./pull-request.mjs";
|
|
10
|
-
import {
|
|
11
|
+
import { parsePRCommentArgs, validatePRCommentResult } from "./pr-comment.mjs";
|
|
12
|
+
import {
|
|
13
|
+
formatPRChecks,
|
|
14
|
+
formatPRDetail,
|
|
15
|
+
formatPRDiff,
|
|
16
|
+
formatPRList,
|
|
17
|
+
formatPRListSections,
|
|
18
|
+
parsePRDiffArgs,
|
|
19
|
+
parsePRListArgs,
|
|
20
|
+
parsePRTargetArgs,
|
|
21
|
+
prChecksExitCode,
|
|
22
|
+
prDetailPath,
|
|
23
|
+
PR_SECTIONS,
|
|
24
|
+
prDiffPath,
|
|
25
|
+
prSection,
|
|
26
|
+
safeInline,
|
|
27
|
+
validatePRDetail,
|
|
28
|
+
validatePRDiff,
|
|
29
|
+
validatePRListResponse,
|
|
30
|
+
} from "./pr-read.mjs";
|
|
31
|
+
import { gatewayCloneURL, parseRepoCloneArgs, parseRepository, runGitClone } from "./repo-clone.mjs";
|
|
32
|
+
import { apiErrorGuidance, presentError } from "./errors.mjs";
|
|
33
|
+
|
|
34
|
+
function sectionLabels(locale) {
|
|
35
|
+
const labels = {};
|
|
36
|
+
for (const name of Object.values(PR_SECTIONS)) labels[`prSection_${name}`] = t(locale, `prSection_${name}`);
|
|
37
|
+
return labels;
|
|
38
|
+
}
|
|
11
39
|
|
|
12
40
|
const require = createRequire(import.meta.url);
|
|
13
41
|
const pkg = require("../package.json");
|
|
@@ -27,14 +55,27 @@ function readPublicKey(path) {
|
|
|
27
55
|
|
|
28
56
|
function objectArgs(args, locale) {
|
|
29
57
|
const repository = args.shift();
|
|
30
|
-
const
|
|
58
|
+
const rawKind = takeFlag(args, "kind");
|
|
59
|
+
// Keep the concise user-facing `pull` spelling while sending the gateway's
|
|
60
|
+
// canonical GitHubObjectKind on the wire. Also accept the canonical spelling
|
|
61
|
+
// for scripts that already learned it from a response/event payload.
|
|
62
|
+
const kind = rawKind === "pull" ? "pull_request" : rawKind;
|
|
31
63
|
const number = Number(takeFlag(args, "number"));
|
|
32
|
-
if (!repository || !kind || !Number.isInteger(number) || number <= 0) {
|
|
64
|
+
if (!repository || !["issue", "pull_request"].includes(kind) || !Number.isInteger(number) || number <= 0) {
|
|
33
65
|
throw new Error(t(locale, "usageFollow"));
|
|
34
66
|
}
|
|
35
67
|
return { repository, kind, number };
|
|
36
68
|
}
|
|
37
69
|
|
|
70
|
+
function emitApiGuidance(error, locale, write) {
|
|
71
|
+
const guidance = apiErrorGuidance(locale, error.body);
|
|
72
|
+
if (guidance.code && guidance.code !== error.body?.error) write(`${prefix()}${guidance.code}`);
|
|
73
|
+
if (guidance.action) write(`${prefix()}${guidance.action}`);
|
|
74
|
+
// A typed code without a known/bounded action is not enough to suppress a
|
|
75
|
+
// command-specific fallback (for example PR head-drift guidance).
|
|
76
|
+
return Boolean(guidance.action);
|
|
77
|
+
}
|
|
78
|
+
|
|
38
79
|
export async function main(argv, opts) {
|
|
39
80
|
const args = [...argv];
|
|
40
81
|
const out = opts.stdout ?? ((s) => console.log(s));
|
|
@@ -42,7 +83,7 @@ export async function main(argv, opts) {
|
|
|
42
83
|
const env = opts.env ?? process.env;
|
|
43
84
|
const exit = opts.exit ?? ((code) => process.exit(code));
|
|
44
85
|
// Global flags are options, never values of --title/--body/etc.
|
|
45
|
-
const localValues = new Set(["--public-key", "--email", "--kind", "--number", "--event", "--receipt", "--repo", "--head", "--sha", "--base", "--title", "--body", "--body-file", "--idempotency-key"]);
|
|
86
|
+
const localValues = new Set(["--public-key", "--email", "--kind", "--number", "--event", "--receipt", "--repo", "--head", "--sha", "--base", "--title", "--body", "--body-file", "--idempotency-key", "-b", "-F", "-R"]);
|
|
46
87
|
let json = false, langFlag, help = false, version = false;
|
|
47
88
|
const commandArgs = [];
|
|
48
89
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -58,6 +99,12 @@ export async function main(argv, opts) {
|
|
|
58
99
|
}
|
|
59
100
|
args.splice(0, args.length, ...commandArgs);
|
|
60
101
|
const locale = selectLocale(env, langFlag);
|
|
102
|
+
// The binary that targets THIS instance; every user-visible command reference
|
|
103
|
+
// follows it (usage, guidance, recovery). Derived from the invoked file so
|
|
104
|
+
// `stamp-staging` names itself — the error surface reaches users before docs.
|
|
105
|
+
const cliName = opts.cliName
|
|
106
|
+
?? (opts.argv1 ? basename(opts.argv1).replace(/\.mjs$/, "") : "stamp");
|
|
107
|
+
setCliName(cliName);
|
|
61
108
|
if (version) { out(pkg.version); return exit(0); }
|
|
62
109
|
const cmd = args.shift();
|
|
63
110
|
if (help || !cmd) { out(t(locale, "usage", { version: pkg.version })); return exit(0); }
|
|
@@ -65,9 +112,9 @@ export async function main(argv, opts) {
|
|
|
65
112
|
|
|
66
113
|
let auth;
|
|
67
114
|
try {
|
|
68
|
-
auth = resolveAuth({ urlBase: opts.urlBase, urlExplicit: opts.urlExplicit, env, locale, service: env.STAMP_SERVICE || opts.serviceDefault || undefined });
|
|
115
|
+
auth = resolveAuth({ urlBase: opts.urlBase, urlExplicit: opts.urlExplicit, env, locale, service: env.STAMP_SERVICE || opts.serviceDefault || undefined, cliName });
|
|
69
116
|
} catch (e) {
|
|
70
|
-
err(
|
|
117
|
+
err(`${prefix()}${presentError(locale, e)}`);
|
|
71
118
|
return exit(1);
|
|
72
119
|
}
|
|
73
120
|
const api = makeClient(auth, opts.fetchImpl);
|
|
@@ -139,21 +186,127 @@ export async function main(argv, opts) {
|
|
|
139
186
|
emit(d, () => out(`${d.id} ${d.status} ${d.repository} ${d.targetRef} published=${d.publishedSha ?? "-"}`));
|
|
140
187
|
return exit(0);
|
|
141
188
|
}
|
|
189
|
+
case "repo": {
|
|
190
|
+
if (args.shift() !== "clone") throw new Error(t(locale, "usageRepoClone"));
|
|
191
|
+
const parsed = parseRepoCloneArgs(args);
|
|
192
|
+
if (!parsed) throw new Error(t(locale, "usageRepoClone"));
|
|
193
|
+
const me = await api("GET", "/v1/me");
|
|
194
|
+
const defaultOwner = me?.github?.login;
|
|
195
|
+
const repo = parseRepository(parsed.repository, defaultOwner);
|
|
196
|
+
if (!repo) throw new Error(t(locale, "usageRepoClone"));
|
|
197
|
+
const url = gatewayCloneURL(me.sshHost, me.sshPort, repo.owner, repo.name);
|
|
198
|
+
const git = opts.gitCloneImpl ?? runGitClone;
|
|
199
|
+
const result = await git({
|
|
200
|
+
url,
|
|
201
|
+
directory: parsed.directory,
|
|
202
|
+
gitFlags: parsed.gitFlags,
|
|
203
|
+
env: opts.gitEnv ?? env,
|
|
204
|
+
});
|
|
205
|
+
if (result.code !== 0) {
|
|
206
|
+
if (result.stderr) err(result.stderr.trimEnd());
|
|
207
|
+
throw new Error(t(locale, "cloneFailed", { repository: `${repo.owner}/${repo.name}` }));
|
|
208
|
+
}
|
|
209
|
+
if (result.stderr) err(result.stderr.trimEnd());
|
|
210
|
+
emit(
|
|
211
|
+
{ ok: true, repository: `${repo.owner}/${repo.name}`, url, directory: parsed.directory ?? repo.name },
|
|
212
|
+
() => out(t(locale, "cloned", { repository: `${repo.owner}/${repo.name}`, url })),
|
|
213
|
+
);
|
|
214
|
+
return exit(0);
|
|
215
|
+
}
|
|
142
216
|
case "pr": {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
217
|
+
const sub = args.shift();
|
|
218
|
+
if (sub === "comment") {
|
|
219
|
+
const input = parsePRCommentArgs(args);
|
|
220
|
+
try {
|
|
221
|
+
const result = validatePRCommentResult(await api("POST", input.path, input.body), input.target);
|
|
222
|
+
emit(result, () => out(t(locale, "prCommentCreated", { url: result.url, actor: result.actorLogin })));
|
|
223
|
+
} catch (e) {
|
|
224
|
+
// A lost/malformed success response may conceal a completed write.
|
|
225
|
+
// Never retry this command automatically or print submitted body.
|
|
226
|
+
err(`${prefix()}${t(locale, e instanceof ApiError && e.status >= 400 && e.status < 500 ? "prCommentRejected" : "prCommentOutcomeUnknown")}`);
|
|
227
|
+
if (e instanceof ApiError) emitApiGuidance(e, locale, err);
|
|
152
228
|
return exit(1);
|
|
153
229
|
}
|
|
154
|
-
|
|
230
|
+
return exit(0);
|
|
231
|
+
}
|
|
232
|
+
if (sub === "create") {
|
|
233
|
+
const input = pullRequestInput(args);
|
|
234
|
+
try {
|
|
235
|
+
const d = await api("POST", "/v1/pull-requests", input);
|
|
236
|
+
emit(d, () => out(t(locale, d.idempotent ? "prExisting" : "prCreated", { number: d.pullNumber, url: d.url })));
|
|
237
|
+
} catch (e) {
|
|
238
|
+
if (e instanceof ApiError && e.status !== 401) {
|
|
239
|
+
err(`${prefix()}${e.message}`);
|
|
240
|
+
if (!emitApiGuidance(e, locale, err)) err(t(locale, pullRequestRecovery(e.body?.error)));
|
|
241
|
+
return exit(1);
|
|
242
|
+
}
|
|
243
|
+
throw e;
|
|
244
|
+
}
|
|
245
|
+
return exit(0);
|
|
155
246
|
}
|
|
156
|
-
|
|
247
|
+
if (sub === "list" || sub === "ls") {
|
|
248
|
+
const { path, sections } = parsePRListArgs(args);
|
|
249
|
+
const paged = path.includes("limit=");
|
|
250
|
+
const d = validatePRListResponse(await api("GET", path), paged);
|
|
251
|
+
const labels = {
|
|
252
|
+
statusUnavailable: t(locale, "prStatusUnavailable"),
|
|
253
|
+
ci: t(locale, "prCIShort"),
|
|
254
|
+
agent: t(locale, "prAgentShort"),
|
|
255
|
+
...sectionLabels(locale),
|
|
256
|
+
};
|
|
257
|
+
emit(
|
|
258
|
+
// The derived section is OPT-IN: a bare `--json` stays byte/structure
|
|
259
|
+
// back-compatible with the pre-section envelope, so a strict consumer
|
|
260
|
+
// never meets an unknown key. Only an explicit `--sections` adds it.
|
|
261
|
+
sections
|
|
262
|
+
? { ...d, items: d.items.map((item) => ({ ...item, section: prSection(item) })) }
|
|
263
|
+
: d,
|
|
264
|
+
() => {
|
|
265
|
+
const lines = sections ? formatPRListSections(d, labels) : formatPRList(d, labels);
|
|
266
|
+
if (lines.length === 0) out(t(locale, "prListEmpty"));
|
|
267
|
+
else for (const line of lines) out(line);
|
|
268
|
+
// Surface the pagination continuation (a present cursor is never
|
|
269
|
+
// an error — it means "there is more"). The cursor is an untrusted
|
|
270
|
+
// wire string: strip terminal control sequences before writing it
|
|
271
|
+
// (the JSON path keeps the verified raw value).
|
|
272
|
+
if (d.nextCursor) out(t(locale, "prListMore", { cursor: safeInline(d.nextCursor) }));
|
|
273
|
+
},
|
|
274
|
+
);
|
|
275
|
+
return exit(0);
|
|
276
|
+
}
|
|
277
|
+
if (sub === "view") {
|
|
278
|
+
const target = parsePRTargetArgs(args, "usagePrView");
|
|
279
|
+
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
280
|
+
emit(d, () => {
|
|
281
|
+
for (const line of formatPRDetail(d, {
|
|
282
|
+
head: t(locale, "prHeadLabel"),
|
|
283
|
+
checks: t(locale, "prChecksLabel"),
|
|
284
|
+
review: t(locale, "prReviewLabel"),
|
|
285
|
+
})) out(line);
|
|
286
|
+
});
|
|
287
|
+
return exit(0);
|
|
288
|
+
}
|
|
289
|
+
if (sub === "diff") {
|
|
290
|
+
const target = parsePRDiffArgs(args);
|
|
291
|
+
const d = validatePRDiff(await api("GET", prDiffPath(target)), target);
|
|
292
|
+
emit(d, () => {
|
|
293
|
+
const chunks = formatPRDiff(d, target.nameOnly, t(locale, "prDiffUnavailable"));
|
|
294
|
+
if (chunks.length === 0) out(t(locale, "prDiffEmpty"));
|
|
295
|
+
else out(chunks.join("\n"));
|
|
296
|
+
});
|
|
297
|
+
return exit(0);
|
|
298
|
+
}
|
|
299
|
+
if (sub === "checks") {
|
|
300
|
+
const target = parsePRTargetArgs(args, "usagePrChecks");
|
|
301
|
+
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
302
|
+
emit(d.checks, () => {
|
|
303
|
+
const lines = formatPRChecks(d);
|
|
304
|
+
if (lines.length === 0) out(t(locale, "prChecksEmpty"));
|
|
305
|
+
else for (const line of lines) out(line);
|
|
306
|
+
});
|
|
307
|
+
return exit(prChecksExitCode(d));
|
|
308
|
+
}
|
|
309
|
+
throw new Error(t(locale, "usagePrRead"));
|
|
157
310
|
}
|
|
158
311
|
case "follow":
|
|
159
312
|
case "unfollow": {
|
|
@@ -192,11 +345,12 @@ export async function main(argv, opts) {
|
|
|
192
345
|
}
|
|
193
346
|
} catch (e) {
|
|
194
347
|
if (e instanceof ApiError) {
|
|
195
|
-
err(
|
|
348
|
+
err(`${prefix()}${e.message}`);
|
|
349
|
+
emitApiGuidance(e, locale, err);
|
|
196
350
|
if (e.status === 401) err(auth.mode === "agent" ? t(locale, "sessionRejected") : t(locale, "checkToken"));
|
|
197
351
|
return exit(1);
|
|
198
352
|
}
|
|
199
|
-
err(
|
|
353
|
+
err(`${prefix()}${presentError(locale, e)}`);
|
|
200
354
|
return exit(1);
|
|
201
355
|
}
|
|
202
356
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { AgentError } from "./errors.mjs";
|
|
3
|
+
import { parsePRTargetArgs, prDetailPath } from "./pr-read.mjs";
|
|
4
|
+
|
|
5
|
+
export function parsePRCommentArgs(input) {
|
|
6
|
+
const targetArgs = [], flags = new Map();
|
|
7
|
+
for (let i = 0; i < input.length; i++) {
|
|
8
|
+
const arg = input[i];
|
|
9
|
+
const match = arg.match(/^(--body|--body-file)(?:=(.*))?$/s);
|
|
10
|
+
const name = match?.[1] ?? ({ "-b": "--body", "-F": "--body-file" })[arg];
|
|
11
|
+
if (!name) { targetArgs.push(arg); continue; }
|
|
12
|
+
if (flags.has(name)) throw new AgentError("usagePrComment");
|
|
13
|
+
const value = match?.[2] ?? input[++i];
|
|
14
|
+
if (value === undefined) throw new AgentError("usagePrComment");
|
|
15
|
+
flags.set(name, value);
|
|
16
|
+
}
|
|
17
|
+
const target = parsePRTargetArgs(targetArgs, "usagePrComment");
|
|
18
|
+
if (flags.size !== 1) throw new AgentError("usagePrComment");
|
|
19
|
+
let body = flags.get("--body");
|
|
20
|
+
if (flags.has("--body-file")) {
|
|
21
|
+
const file = flags.get("--body-file");
|
|
22
|
+
try { body = readFileSync(file === "-" ? 0 : file, "utf8"); }
|
|
23
|
+
catch { throw new AgentError("prBodyRead"); }
|
|
24
|
+
}
|
|
25
|
+
if (!body?.trim() || Buffer.byteLength(body, "utf8") > 65536) throw new AgentError("prCommentBodyInvalid");
|
|
26
|
+
return { target, path: `${prDetailPath(target)}/comments`, body: { body } };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function validatePRCommentResult(result, target) {
|
|
30
|
+
const expectedRepo = `${target.owner}/${target.repo}`;
|
|
31
|
+
const valid = result && typeof result === "object" && !Array.isArray(result)
|
|
32
|
+
&& typeof result.repository === "string" && result.repository.toLowerCase() === expectedRepo.toLowerCase()
|
|
33
|
+
&& result.number === target.number && Number.isSafeInteger(result.commentId) && result.commentId > 0
|
|
34
|
+
&& typeof result.actorLogin === "string" && /^[A-Za-z0-9-]+$/.test(result.actorLogin)
|
|
35
|
+
&& typeof result.url === "string"
|
|
36
|
+
&& result.url.toLowerCase() === `https://github.com/${expectedRepo}/pull/${target.number}#issuecomment-${result.commentId}`.toLowerCase();
|
|
37
|
+
if (!valid) throw new AgentError("prCommentOutcomeUnknown");
|
|
38
|
+
return result;
|
|
39
|
+
}
|