@botiverse/stamp-cli 0.3.10 → 0.3.12

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/lib/auth.mjs CHANGED
@@ -140,7 +140,14 @@ export function resolveAuth({ urlBase, urlExplicit, env = process.env, service,
140
140
  // store as absent so the caller must log in afresh.
141
141
  // No migration: a store issued for a DIFFERENT origin is not usable here.
142
142
  // The refusal names the origin so the reader knows why and what to do.
143
- const usableStore = storeMatchesOrigin(store, apiBase) ? store : undefined;
143
+ let usableStore = storeMatchesOrigin(store, apiBase) ? store : undefined;
144
+ // A session written after this resolve (`login` itself) becomes usable
145
+ // for the rest of the same command: login then enrolls the agent's key.
146
+ const refreshStore = () => {
147
+ if (usableStore) return;
148
+ const fresh = readStore(a, service);
149
+ if (storeMatchesOrigin(fresh, apiBase)) usableStore = fresh;
150
+ };
144
151
  const storedOriginElsewhere = !usableStore && storedOrigin !== null ? storedOrigin : null;
145
152
  return {
146
153
  mode: "agent",
@@ -152,6 +159,7 @@ export function resolveAuth({ urlBase, urlExplicit, env = process.env, service,
152
159
  // Never ~/.ssh or ~/.stamp, which every agent on a machine user shares.
153
160
  stateDir: dirname(agentAuthPath(a, service)),
154
161
  async token() {
162
+ refreshStore();
155
163
  if (!usableStore) {
156
164
  if (storedOriginElsewhere !== null) {
157
165
  const sibling = siblingBinaryFor(storedOriginElsewhere);
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { t } from "../locale.mjs";
3
3
  import { resolve } from "node:path";
4
4
  import { takeFlag, readPublicKey } from "../flags.mjs";
5
- import { recordIdentity } from "../repo/identities.mjs";
5
+ import { readRecordedIdentity, recordIdentity } from "../repo/identities.mjs";
6
6
  import { defaultIdentityPath } from "../repo/ssh.mjs";
7
7
  import { mkdirSync } from "node:fs";
8
8
  import { dirname } from "node:path";
@@ -18,6 +18,30 @@ function generateAgentKey(path, agentId) {
18
18
  }
19
19
  }
20
20
 
21
+ // ensureAgentKey gives an agent its own SSH key without being asked, as its
22
+ // commit email is (artin 09-28: "enroll should only be a hint"): when the
23
+ // agent has no key recorded for this instance, it creates one in the agent's
24
+ // own directory (or reuses the one already there), enrolls it and records it.
25
+ // It returns what it did, or null when there was nothing to do (a person, or
26
+ // a key already recorded). `key enroll --public-key` stays for a key the
27
+ // agent chooses itself.
28
+ export async function ensureAgentKey(ctx) {
29
+ if (!ctx.env.STAMP_AGENT_STATE_DIR) return null;
30
+ if (readRecordedIdentity(ctx.env, ctx.auth.apiBase)) return null;
31
+ const privatePath = defaultIdentityPath(ctx.env);
32
+ const publicPath = `${privatePath}.pub`;
33
+ let created = false;
34
+ if (!existsSync(publicPath)) {
35
+ await (ctx.opts.sshKeygenImpl ?? generateAgentKey)(privatePath, ctx.auth?.agentEnv?.agentId);
36
+ created = true;
37
+ }
38
+ const d = await ctx.api("POST", "/v1/keys", { publicKey: readPublicKey(publicPath) });
39
+ recordIdentity(ctx.env, ctx.auth.apiBase, {
40
+ identityPath: privatePath, fingerprint: d.fingerprint ?? null, keyId: d.keyId ?? null, enrolledAt: new Date().toISOString(),
41
+ });
42
+ return { path: privatePath, fingerprint: d.fingerprint ?? "", created };
43
+ }
44
+
21
45
  export async function run(ctx) {
22
46
  const sub = ctx.args.shift();
23
47
  if (sub === "list") {
@@ -1,9 +1,10 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { t } from "../locale.mjs";
3
3
  import { takeFlag } from "../flags.mjs";
4
- import { gatewayCloneURL, parseRepoCloneArgs, parseRepository, runGitClone, runGitSetSSHCommand } from "../repo/clone.mjs";
4
+ import { gatewayCloneURL, parseRepoCloneArgs, parseRepository, runGitClone, runGitSetSSHCommand, setCommitIdentity } from "../repo/clone.mjs";
5
5
  import { fetchPublishedKnownHosts, resolveIdentity, resolveKnownHostsPath, sshCommandFor, writePinnedKnownHosts } from "../repo/ssh.mjs";
6
6
  import { readRecordedIdentity } from "../repo/identities.mjs";
7
+ import { ensureAgentKey } from "./key.mjs";
7
8
 
8
9
  export async function run(ctx) {
9
10
  const sub = ctx.args.shift();
@@ -21,6 +22,10 @@ export async function run(ctx) {
21
22
  // The clone carries the enrolled identity and the gateway's published host
22
23
  // key itself (task #475): a bare clone must not fail with publickey, and it
23
24
  // must not need a hand-exported GIT_SSH_COMMAND.
25
+ if (!identityFlag && !String(ctx.env.STAMP_SSH_IDENTITY ?? "").trim()) {
26
+ const key = await ensureAgentKey(ctx);
27
+ if (key) ctx.err(t(ctx.locale, "keyEnsured", { path: key.path, fingerprint: key.fingerprint }));
28
+ }
24
29
  const recorded = readRecordedIdentity(ctx.env, ctx.auth.apiBase);
25
30
  const { identityPath, source } = resolveIdentity(ctx.env, identityFlag, recorded);
26
31
  if (!existsSync(identityPath)) {
@@ -60,9 +65,11 @@ export async function run(ctx) {
60
65
  // Make later git operations in this checkout work without any export.
61
66
  const directory = parsed.directory ?? repo.name;
62
67
  const pinned = await (ctx.opts.gitConfigImpl ?? runGitSetSSHCommand)({ directory, sshCommand });
68
+ const commitEmail = await setCommitIdentity(ctx, me, directory);
63
69
  ctx.emit(
64
- { ok: true, repository: `${repo.owner}/${repo.name}`, url, directory, sshIdentity: identityPath, sshIdentitySource: source, sshPinned: pinned.ok },
70
+ { ok: true, repository: `${repo.owner}/${repo.name}`, url, directory, sshIdentity: identityPath, sshIdentitySource: source, sshPinned: pinned.ok, commitEmail },
65
71
  () => {
72
+ if (commitEmail) ctx.out(t(ctx.locale, "repoCommitEmailSet", { email: commitEmail, directory }));
66
73
  ctx.out(t(ctx.locale, "cloned", { repository: `${repo.owner}/${repo.name}`, url }));
67
74
  // The commit rules this gateway enforces, stated once up front (task #549):
68
75
  // a pusher should not meet them for the first time as a refusal.
@@ -89,6 +96,10 @@ async function use(ctx) {
89
96
  const knownHostsFlag = takeFlag(ctx.args, "known-hosts");
90
97
  const directory = ctx.args.shift() ?? ".";
91
98
  if (ctx.args.length !== 0) throw new Error(t(ctx.locale, "usageRepoUse"));
99
+ if (!identityFlag && !String(ctx.env.STAMP_SSH_IDENTITY ?? "").trim()) {
100
+ const key = await ensureAgentKey(ctx);
101
+ if (key) ctx.err(t(ctx.locale, "keyEnsured", { path: key.path, fingerprint: key.fingerprint }));
102
+ }
92
103
  const recorded = readRecordedIdentity(ctx.env, ctx.auth.apiBase);
93
104
  const { identityPath, source } = resolveIdentity(ctx.env, identityFlag, recorded);
94
105
  if (!existsSync(identityPath)) {
@@ -109,8 +120,11 @@ async function use(ctx) {
109
120
  if (!pinned.ok) {
110
121
  throw new Error(t(ctx.locale, "repoUseFailed", { directory, detail: (pinned.stderr ?? "").trim() }));
111
122
  }
112
- ctx.emit({ directory, identityPath, knownHostsPath, sshCommand }, () => {
123
+ const me = await ctx.api("GET", "/v1/me").catch(() => null);
124
+ const commitEmail = await setCommitIdentity(ctx, me, directory);
125
+ ctx.emit({ directory, identityPath, knownHostsPath, sshCommand, commitEmail }, () => {
113
126
  ctx.out(t(ctx.locale, "repoUseDone", { directory, path: identityPath }));
127
+ if (commitEmail) ctx.out(t(ctx.locale, "repoCommitEmailSet", { email: commitEmail, directory }));
114
128
  });
115
129
  return ctx.exit(0);
116
130
  }
@@ -1,6 +1,7 @@
1
1
  import { runAgentLogin } from "../agent-login.mjs";
2
2
  import { humanExpiry } from "../expiry.mjs";
3
3
  import { t } from "../locale.mjs";
4
+ import { ensureAgentKey } from "./key.mjs";
4
5
 
5
6
  export async function login(ctx) {
6
7
  const { auth, opts, emit, out, locale, exit } = ctx;
@@ -19,6 +20,16 @@ export async function login(ctx) {
19
20
  () => out(t(locale, expiry.expired ? "loginTokenExpired" : "loginAgentReady", {
20
21
  service: auth.service, url: auth.apiBase, expires: expiry.text, remaining: expiry.remaining,
21
22
  })));
23
+ // The agent's own SSH key, without a separate step. A failure never costs
24
+ // the login: clone and `key enroll` try again.
25
+ if (!expiry.expired) {
26
+ try {
27
+ const key = await ensureAgentKey(ctx);
28
+ if (key) ctx.err(t(locale, "keyEnsured", { path: key.path, fingerprint: key.fingerprint }));
29
+ } catch (e) {
30
+ ctx.err(t(locale, "keyEnsureFailed", { reason: String(e?.message ?? e) }));
31
+ }
32
+ }
22
33
  return exit(0);
23
34
  }
24
35
 
@@ -45,7 +56,7 @@ export async function whoami(ctx) {
45
56
  export async function migrationHelp(ctx) {
46
57
  const fetchImpl = ctx.opts.fetchImpl ?? fetch;
47
58
  const res = await fetchImpl(`${ctx.auth.apiBase}/v1/migration-help`, {
48
- headers: { "accept-language": ctx.locale === "zh-CN" ? "zh-CN" : "en" },
59
+ headers: { "accept-language": "en" },
49
60
  });
50
61
  const d = await res.json();
51
62
  ctx.emit(d, () => {
package/lib/expiry.mjs CHANGED
@@ -3,8 +3,8 @@
3
3
  // reads as "already expired" (task #436). The human line gets a local time plus
4
4
  // how long is left; the JSON keeps the raw value for machines.
5
5
 
6
- function localeTag(locale) {
7
- return locale === "zh-CN" ? "zh-CN" : "en-US";
6
+ function localeTag() {
7
+ return "en-US";
8
8
  }
9
9
 
10
10
  // humanExpiry formats an RFC3339 instant for the reader: local time with its
package/lib/locale.mjs CHANGED
@@ -174,7 +174,7 @@ export const messages = {
174
174
  git clone ssh://git@ssh.staging.stamp.build:443/org/repo.git
175
175
  git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
176
176
 
177
- flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance), STAMP_SERVICE, STAMP_LANG
177
+ flags: --json env: STAMP_TOKEN (human/CI), STAMP_URL (instance), STAMP_SERVICE
178
178
  docs: {docs} (the agent workflow, step by step)`,
179
179
  usageRepoClone: "usage: {cli} repo clone <repository> [<directory>] [--identity FILE] [--known-hosts FILE] [-- <gitflags>...]",
180
180
  cloned: "Cloned {repository} from {url}",
@@ -209,6 +209,9 @@ docs: {docs} (the agent workflow, step by step)`,
209
209
  usageRepoUse: "usage: {cli} repo use [DIR] [--identity KEY] [--known-hosts FILE]",
210
210
  repoUseDone: "{directory}: git now reaches Stamp with this agent's key {path} (set in this repository only)",
211
211
  repoUseFailed: "could not set core.sshCommand in {directory}: {detail}",
212
+ keyEnsured: "this agent's own SSH key is ready: {path} ({fingerprint}); nothing to configure",
213
+ keyEnsureFailed: "could not set up this agent's SSH key yet ({reason}); `{cli} repo clone` and `{cli} key enroll` will try again",
214
+ repoCommitEmailSet: "commits in {directory} use this agent's commit email {email} (set in this repository only)",
212
215
  keyGenerated: "created this agent's own SSH key: {path} (kept in the agent's directory, not ~/.ssh)",
213
216
  enrolled: "enrolled {fingerprint} ({keyId})",
214
217
  enrolledIdentityRecorded: "`{cli} repo clone` on this machine will use {path}",
@@ -290,301 +293,12 @@ docs: {docs} (the agent workflow, step by step)`,
290
293
  refresh_deadline: "agent-login: token refresh exceeded the deadline",
291
294
  refresh_wait_timeout: "agent-login: timed out waiting for a concurrent token refresh",
292
295
  },
293
- "zh-CN": {
294
- usagePrQueue: "用法:{cli} pr queue <enqueue|status|withdraw> <NUMBER -R OWNER/REPO|PR_URL> --request-id ID [--head SHA --base SHA(仅 enqueue)];ID 为 16–128 位字母、数字、下划线或连字符,首位为字母或数字;发送前选定并保留",
295
- prQueueOutcomeUnknown: "队列操作结果未知。再次写入前,用同一 PR 和 --request-id 执行 pr queue status;不要生成新 ID 或自动重发。",
296
- prQueueReceipt: "队列 {repository}#{number},请求 {id}:{state};原因:{reason};落地:{landing};终态通知已入队:{queued}(不代表送达)",
297
- 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];省略 --repo/--head/--sha 时从已发布的 receipt 读取",
298
- usagePrRead: "用法:{cli} pr <list|view|review|diff|checks|comment|edit|approve|unapprove|merge|queue> [参数]",
299
- usagePrReview: "用法:{cli} pr review <编号|URL> [--repo OWNER/REPO] —— 要钉的 exact head、base、merge-base、检查,以及对 merge-base 做 diff/patch-id 的命令",
300
- prReviewExactHead: "Exact head",
301
- prReviewBase: "Base",
302
- prReviewMergeBase: "Merge-base",
303
- prReviewMergeBaseRule: "log/stat/diff/patch-id 一律对 merge-base,不要对当前 base:base 分支可能在分叉后已前进,那些提交会被当成这张 PR 的",
304
- prReviewCommands: "本地复核(经 Stamp clone 之后)",
305
- prReviewVerdict: "要贴的判词",
306
- usagePrApprove: "用法:{cli} pr approve <NUMBER -R OWNER/REPO|PR_URL> --head SHA --base SHA [--body TEXT](人类:GitHub review;Agent:由 Stamp 记录,不带 --body)",
307
- usagePrUnapprove: "用法:{cli} pr unapprove <NUMBER -R OWNER/REPO|PR_URL> --head SHA --base SHA(Agent:撤回你在该 head 上由 Stamp 记录的批准)",
308
- usagePrMerge: "用法:{cli} pr merge <NUMBER -R OWNER/REPO|PR_URL> --head SHA --base SHA [--method merge|squash|rebase](人类:以本人 GitHub 身份;agent:以 Stamp App 身份,前提是作者以外的人已批准该 exact head)\n {cli} pr merge <NUMBER -R OWNER/REPO|PR_URL> --auto --head SHA --base SHA [--method ...] | --auto --cancel --head SHA --base SHA | --auto --status (作者 agent:别人批准该 head 且判定为 READY 后由 Stamp 自动合入)",
309
- prApproved: "已以 {actor} 身份批准 {repository}#{number}",
310
- prApprovedByStamp: "已以 {actor} 身份批准 {repository}#{number} 的 {head}(由 Stamp 记录)",
311
- prUnapproved: "已以 {actor} 身份撤回对 {repository}#{number} 的 {head} 的批准(由 Stamp 记录)",
312
- prMerged: "已以 {actor} 身份合并 {repository}#{number}({sha})",
313
- prMergedByApp: "已代 {actor} 以 Stamp App 身份合并 {repository}#{number},head {head}({sha})",
314
- prAutoMerge_ARMED: "{repository}#{number} 已登记:一旦作者以外的人批准 head {head} 且判定为 READY,Stamp 就以 {method} 方式合入",
315
- prAutoMerge_VOID: "{repository}#{number}:自动合入登记针对的是 head {head},PR 已经不在这个 head 上了;请对当前 head 重新登记",
316
- prAutoMerge_CANCELLED: "{repository}#{number}:自动合入已撤销",
317
- prAutoMerge_NONE: "{repository}#{number}:没有登记自动合入",
318
- prAutoMerge_CLOSED: "{repository}#{number} 已关闭或已合入,自动合入登记无事可做",
319
- prAutoMerge_EXPIRED: "{repository}#{number}:自动合入登记已过期(超过 14 天),请重新登记",
320
- prAutoMergeUnchanged: "(没有变化)",
321
- prApproveRejected: "批准被拒绝。请检查会话、仓库权限,以及 --head/--base(人类还需要绑定 GitHub;Agent 不能批准自己开的 PR)。",
322
- prMergeRejected: "合并被拒绝。请检查会话、仓库权限、--head/--base、批准(agent 合并需要作者以外的人批准该 exact head)和可合并性(人类还需要 GitHub 绑定)。",
323
- prApproveOutcomeUnknown: "批准结果不明。请先重读 PR 的 reviews,不要自动重发。",
324
- prUnapproveRejected: "撤回批准被拒绝。请检查 Agent 会话、仓库权限,以及 --head/--base。",
325
- prUnapproveOutcomeUnknown: "撤回批准结果不明。可以原样重试,该操作是幂等的。",
326
- prMergeOutcomeUnknown: "合并结果不明。请先重读 PR,不要自动重发。",
327
- apiHumanPrincipal: "此操作需要人类 STAMP_TOKEN 会话。",
328
- apiWriteCoords: "请重读 PR,带上当前的 --head 和 --base 再试。",
329
- apiGitHubBinding: "请先在 Stamp 设置里绑定 GitHub,再重试。",
330
- usagePrComment: "用法:{cli} pr comment <NUMBER -R OWNER/REPO|PR_URL> (--body TEXT|--body-file FILE|-) [--expected-head SHA](人类以本人绑定的 GitHub 身份发表;agent 以 Stamp App 身份发表并附带署名行;带 --expected-head 时 PR 的 head 变了就拒绝发表)",
331
- prCommentExpectedHeadInvalid: "--expected-head 必须是你复核过的完整 40 位 commit SHA。",
332
- prCommentBodyInvalid: "评论不能为空,UTF-8 文本最多 64 KiB。",
333
- prCommentCreated: "已以 {actor} 身份发表评论:{url}",
334
- prCommentRejected: "评论请求被拒绝,请检查会话、GitHub 绑定(人类)、仓库权限和输入。",
335
- prCommentOutcomeUnknown: "评论结果不明。请先查看 PR 评论,不要自动重发。",
336
- usagePrEdit: "用法:{cli} pr edit <NUMBER -R OWNER/REPO|PR_URL> [--title TITLE] [--body TEXT|--body-file FILE|-](仅 Stamp 创建回执记录的 Agent 可改;标题、描述至少提供一项)",
337
- usagePrClose: "用法:{cli} pr close <NUMBER -R OWNER/REPO|PR_URL>(仅 Stamp 创建回执记录的 Agent 可关闭)",
338
- prClosed: "已关闭 {repository}#{number}:{url}",
339
- prCloseRejected: "PR 关闭被拒绝。请确认该 PR 由此 Agent 经 Stamp 创建,且此 Agent 仍有仓库权限。",
340
- prCloseOutcomeUnknown: "PR 关闭结果不明。请先重读 PR,再决定是否重发;不要自动重试。",
341
- prEditTitleInvalid: "PR 标题不能为空,UTF-8 文本最多 256 字节。",
342
- prEditBodyInvalid: "PR 描述不能为空,UTF-8 文本最多 64 KiB。",
343
- prEdited: "已更新 {repository}#{number}:{url}",
344
- prEditRejected: "PR 编辑被拒绝。请确认该 PR 由此 Agent 经 Stamp 创建,且此 Agent 仍有仓库权限。",
345
- prEditOutcomeUnknown: "PR 编辑结果不明。请先重读 PR,再决定是否重发;不要自动重试。",
346
- usagePrList: "用法:{cli} pr list",
347
- usagePrView: "用法:{cli} pr view <编号|URL> [--repo OWNER/REPO]",
348
- usagePrDiff: "用法:{cli} pr diff <编号|URL> [--repo OWNER/REPO] [--name-only]",
349
- usagePrChecks: "用法:{cli} pr checks <编号|URL> [--repo OWNER/REPO]",
350
- prReadInvalidResponse: "Stamp 返回了无效的 PR 读取响应;请检查服务版本后重试。",
351
- prReadCoordinateMismatch: "Stamp 返回的 PR 坐标与请求的仓库或编号不一致;已拒绝显示。",
352
- prListEmpty: "没有找到通过 Stamp 创建的 Pull Request。",
353
- prStatusUnavailable: "实时状态暂不可用",
354
- prCIShort: "CI",
355
- prAgentShort: "Agent",
356
- prHeadLabel: "Head",
357
- prChecksLabel: "检查",
358
- prReviewLabel: "审阅",
359
- prDiffUnavailable: "patch 不可用",
360
- prDiffEmpty: "没有变更文件。",
361
- prChecksEmpty: "没有检查记录。",
362
- prChecksUnreadable: "无法读取这个 PR 的检查结果,所以这不是\"没有检查\"——网关被 GitHub 拒绝了(通常是 App 缺少 Checks 权限)。请把 CI 当作未知。",
363
- prCIUnreadable: "无法读取",
364
- prVerdictCIUnreadable: "CI 无法读取——不能当作已通过",
365
- prVerdictLabel: "Stamp 判定",
366
- verdict_READY: "现在可以合入",
367
- verdict_QUEUE_READY: "已批准;通过 Stamp 的合并队列合入:`{cli} pr queue`",
368
- verdict_MERGED: "已合入",
369
- verdict_CLOSED: "已关闭",
370
- verdict_DRAFT: "草稿",
371
- verdict_CONFLICT: "与 base 有冲突",
372
- verdict_CI_UNREADABLE: "CI 无法读取——不能当作已通过",
373
- verdict_CI_FAILING: "有 required 检查失败",
374
- verdict_CI_NOT_EXECUTED: "有 required 检查没有运行",
375
- verdict_CI_PENDING: "required 检查仍在运行",
376
- verdict_REVIEW_UNREADABLE: "批准状态无法读取",
377
- verdict_CHANGES_REQUESTED: "有人要求修改",
378
- verdict_STALE_REVIEW: "现有批准针对的是别的 head 或 base",
379
- verdict_NEEDS_REVIEW: "需要非作者在这个 head 上批准",
380
- verdict_BEHIND: "落后于 base",
381
- verdict_BLOCKED: "GitHub 阻止合入,原因 Stamp 看不到",
382
- verdict_UNCONFIRMED: "GitHub 没有确认可以干净合入(有检查未通过,或还在计算)",
383
- prReadNotFound: "请检查仓库和 PR 编号,并确认该 PR 是此 Agent 通过 Stamp 创建的。",
384
- prReadHeadMoved: "Stamp 读取 diff 时 PR head 已变化;请重新运行命令并审阅新的 head。",
385
- prReadDiffIncomplete: "GitHub 未返回完整的 PR diff;请稍后重试,不要依赖部分文件。",
386
- prReadUnavailable: "PR 读取暂时不可用;请检查 Stamp 服务状态后重试。",
387
- prListMore: "还有更多结果;用 --limit 与 --cursor {cursor} 继续翻页。",
388
- prSection_drafts: "草稿",
389
- prSection_changes: "需修改",
390
- prSection_approved: "已批准",
391
- prSection_approvals: "有批准",
392
- prSection_waiting: "等待评审",
393
- prSection_history: "历史",
394
- prSection_unavailable: "状态暂不可用",
395
- prCursorScope: "该 cursor 不属于当前身份或范围;请从头重新运行 {cli} pr list。",
396
- prCursorInvalid: "cursor 无效或已过期;请从头重新运行 {cli} pr list。",
397
- prRequired: "缺少 {flag};用 {cli} receipt get <id> 获取已发表提交的信息。",
398
- prRepository: "--repo 必须为 OWNER/REPO。",
399
- prSHA: "--sha 必须是已发表提交的精确 40 位小写 SHA。",
400
- prBodyRequired: "请用 --body 或 --body-file 提供非空 PR 正文(用 - 从标准输入读取)。",
401
- prCheckArguments: "请用 {cli} pr create --help 检查参数,修正无效或空值后再重试。",
402
- prCheckConfiguration: "请先联系服务管理员修复 GitHub App 配置,再重试。",
403
- prBodyConflict: "--body 与 --body-file 只能选一个。",
404
- prBodyRead: "无法读取 --body-file;请检查路径,或用 - 从标准输入读取。",
405
- prIdempotency: "--idempotency-key 必须为 16–128 位字母、数字、点、下划线、冒号或连字符。",
406
- prCreated: "已创建 PR #{number}:{url}",
407
- prExisting: "已有 PR #{number}:{url}",
408
- prStampPage: " Stamp:{page}",
409
- prViewStampPage: "Stamp:{page}",
410
- whoamiCommitEmail: "提交邮箱:{email}(git config user.email {email})",
411
- whoamiCommitEmailDefault: "提交邮箱:{email}(Stamp 给 agent 的默认地址,不能收信。直接用:git config user.email {email}。有自己的邮箱?{cli} identity bind --email ADDR)",
412
- prNextAutoMerge: " 下一步:{cli} pr merge {number} --repo {repository} --auto --head {head} --base {base}\n (他人批准这个 head 且判定为 READY 后,Stamp 自动合并)",
413
- prWaitPublished: "请用 {cli} receipt get <id> 检查;只使用自己状态为 PUBLISHED 的 receipt。",
414
- prReceiptNotPublished: "Receipt {id} 的状态是 {status},不会发表到 GitHub,无法据此创建 PR。见 {cli} receipt get {id}。",
415
- prPublishTimeout: "等待 GitHub 发表后,receipt {id} 仍是 {status};稍后重跑同一命令,或查看 {cli} receipt get {id}。",
416
- prReceiptIncomplete: "Receipt {id} 已发表,但缺少仓库、ref 或提交;请显式传 --repo、--head 和 --sha。",
417
- prCheckReceipt: "请重新读取 receipt,并核对 --repo、--head 和 --sha 是否与已发表提交一致。",
418
- prCheckAccess: "请与仓库管理员核对仓库权限和允许的目标分支。",
419
- prCheckBase: "目标分支在 GitHub 上不存在;请用 --base 指定仓库里已存在的分支。",
420
- prCheckExisting: "请检查已有 PR;重试时保持 receipt、标题、正文和幂等键不变。",
421
- prRetry: "请检查 receipt 和服务状态,再原样重试命令;幂等键会保持不变。",
422
- apiBindIdentity: "请先运行 `{cli} whoami`(它会给这个 Agent 分配默认提交邮箱),再重试命令。",
423
- apiRepositoryNotInstalled: "请检查 OWNER/REPO 拼写,或请 Server Owner 为该仓库安装 Stamp GitHub App,再重试。",
424
- apiContributionDenied: "请让 Server Owner 为此 Agent 授予有效的 Write 或更高仓库角色,再重试。",
425
- apiRepositoryNotAuthorized: "请让 Server Owner 核对 Stamp GitHub App 安装与此 Agent 的身份绑定,再重试。",
426
-
427
- usage: `{cli} {version} — Agent Git 网关 CLI
428
-
429
- {cli} login Agent:经 raft 做 PKCE 登录(无浏览器);人类:如何设置 STAMP_TOKEN
430
- {cli} logout Agent:忘掉已存会话
431
- {cli} whoami 网关认为你是谁
432
- {cli} migration-help 旧 manifest action → CLI 对照
433
- {cli} key enroll [--public-key FILE|-] 绑定此 Agent 的 SSH 公钥(agent 默认用它自己的 key,没有就生成)
434
- {cli} key list 列出此 Agent 已登记的 SSH 公钥
435
- {cli} key revoke KEY_ID 撤销此 Agent 的一把已登记公钥
436
- {cli} known-hosts refresh 从 /.well-known 重新钉住本实例的 SSH 主机公钥
437
- {cli} identity bind --email ADDR 绑定提交作者邮箱(DCO)
438
- {cli} receipt get <id> 网关接受与 GitHub 发表状态
439
- {cli} receipt list [--repo OWNER/REPO] [--limit N] [--cursor CURSOR]
440
- 列出你自己的推送回执(新的在前)
441
- {cli} changelog [--limit N] [--all] 更新日志:每个版本的命令行/接口变化(--all 看全部)
442
- {cli} pr create --receipt ID [--repo OWNER/REPO --head BRANCH --sha SHA] --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
443
- {cli} pr list
444
- {cli} pr view <编号|URL> --repo OWNER/REPO
445
- {cli} pr diff <编号|URL> --repo OWNER/REPO [--name-only]
446
- {cli} pr checks <编号|URL> --repo OWNER/REPO
447
- {cli} pr comment <编号|URL> --repo OWNER/REPO --body-file FILE|- (人类用本人 GitHub 身份;agent 以 Stamp App 身份)
448
- {cli} pr edit <编号|URL> --repo OWNER/REPO [--title 标题] [--body-file 文件|-] (仅创建它的 Agent)
449
- {cli} pr approve <编号|URL> --repo OWNER/REPO --head SHA --base SHA [--body TEXT] (本人 GitHub 身份;Agent 不带 --body)
450
- {cli} pr unapprove <编号|URL> --repo OWNER/REPO --head SHA --base SHA (Agent)
451
- {cli} pr merge <编号|URL> --repo OWNER/REPO --head SHA --base SHA [--method squash] (本人 GitHub 身份;agent 需他人批准)
452
- {cli} pr merge <编号|URL> --repo OWNER/REPO --auto --head SHA --base SHA (作者 agent:他人批准后自动合入)
453
- {cli} pr queue enqueue|status|withdraw <编号|URL> --repo OWNER/REPO --request-id ID [--head SHA --base SHA] (agent;入队需 head/base)
454
- {cli} repo clone <repository> [<directory>] [-- <gitflags>...]
455
- {cli} repo use [目录] 让已有的 checkout 用这个 agent 自己的 key(只设在该仓库)
456
-
457
- {cli} follow <owner/repo> --kind issue|pull --number N
458
- {cli} unfollow <owner/repo> --kind issue|pull --number N
459
- {cli} subscription pause|resume <owner/repo> --kind issue|pull --number N
460
- {cli} subscriptions
461
- {cli} watch <owner/repo> --event TYPE
462
- {cli} unwatch <owner/repo> --event TYPE
463
-
464
- git clone ssh://git@ssh.staging.stamp.build:443/org/repo.git
465
- git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
466
-
467
- flags: --json --lang en|zh-CN env: STAMP_TOKEN(人类/CI)、STAMP_URL、STAMP_SERVICE、STAMP_LANG
468
- 文档:{docs}(Agent 工作流,逐步说明)`,
469
- usageRepoClone: "用法:{cli} repo clone <repository> [<directory>] [--identity FILE] [--known-hosts FILE] [-- <gitflags>...]",
470
- cloned: "已从 {url} 克隆 {repository}",
471
- cloneCommitTrailers: "推到这里的每个 commit 末尾都要带这两行 trailer(连成一块放在最末尾,中间不要空行;GitHub 只认最后一个连续块):",
472
- cloneFailed: "经 Stamp 网关克隆 {repository} 失败",
473
- networkUnreachable: "无法连接 {base}({cause});检查实例地址(STAMP_URL)和网络后重试",
474
- networkHostUnresolved: "{base} 解析不了({cause});检查实例地址(STAMP_URL)和 DNS 后重试",
475
- cloneIdentityMissing: "{path} 没有 SSH 私钥:用 `{cli} key enroll` 登记一把(它读 {path}.pub),或用 --identity FILE 指到已有私钥",
476
- cloneEnrolledIdentityMissing: "`{cli} key enroll` 为 {origin} 记录的私钥在这台机器上不在 {path}:在这里重新 `{cli} key enroll`,或用 --identity FILE 指到那把钥",
477
- cloneKnownHostsUnavailable: "{url} 返回 HTTP {status}:这个实例没有发布自己的 SSH 主机公钥,没有可钉的东西——用 --known-hosts FILE 指定,或设 STAMP_KNOWN_HOSTS",
478
- cloneKnownHostsInvalid: "{url} 返回的不是可用的 known_hosts 行;拒绝钉它——检查实例,或用 --known-hosts FILE",
479
- usageKnownHostsRefresh: "用法:known-hosts refresh [--known-hosts FILE]",
480
- knownHostsRefreshed: "已在 {path} 中钉住 {pattern}\n{fingerprint}",
481
- knownHostsRepoAligned: "这个仓库会读取该文件\n 注意:推送所在环境里设置的 GIT_SSH_COMMAND 会覆盖它,而本命令看不到,因此这不能为下一次推送背书",
482
- knownHostsRepoUnchecked: "未能确认这个仓库是否会读取刚刚刷新的那个文件\n 已刷新:{written}\n {reason}\n这既不是失败也不是确认:请把该仓库当作未检查",
483
- knownHostsUncheckedNoRepo: "不在 git 仓库内,没有仓库配置可问",
484
- knownHostsUncheckedExplicitPath: "--known-hosts 显式指定了这个文件,因此没有拿任何仓库去核对它",
485
- knownHostsUncheckedProbe: "无法运行该仓库的 ssh 命令,因此它实际使用的 known_hosts 未知",
486
- knownHostsRepoElsewhere: "这个仓库不会读取刚刚刷新的那个文件\n 已刷新:{written}\n 本仓库实际读取:{effective}\n两者不一致时,刷新对从这里发起的推送没有任何作用;请为本仓库设置 core.sshCommand:\n git config core.sshCommand \"{sshCommand}\"",
487
- knownHostsRepoUnconfigured: "这个仓库没有设置 core.sshCommand,因此不会读取刚刚刷新的那个文件\n 已刷新:{written}\n 本仓库实际读取:{effective}\n它通过 ssh 自己的配置连接,或依赖每次推送临时设置的 GIT_SSH_COMMAND——后者本命令看不到,也无法为它背书;请为本仓库设置 core.sshCommand:\n git config core.sshCommand \"{sshCommand}\"",
488
- clonePublicKeyRejected: "网关拒绝了 {path} 这把钥(publickey)。如果它还没登记,先登记它的公钥:`{cli} key enroll --public-key {publicKey}`",
489
- cloneIdentityPinned: "已把 Stamp 的 SSH 身份钉到 {directory}(git config core.sshCommand)",
490
- cloneIdentityPinFailed: "无法把 SSH 身份写入 {directory};可手动执行:git -C {directory} config --local core.sshCommand \"{command}\"",
491
- loginHumanIntro: "当前不是受管 Raft Agent。人类和 CI 使用 STAMP_TOKEN:",
492
- loginHumanBrowser: " 浏览器:{url}/login (把会话 cookie 值设为 STAMP_TOKEN)",
493
- loginHumanCI: " CI: 由负责人签发的窄范围部署令牌",
494
- loginAgentReady: "Agent 登录就绪({service} @ {url});访问令牌有效至 {expires}({remaining})",
495
- loginTokenExpired: "Agent 已登录({service} @ {url}),但访问令牌已于 {expires} 过期({remaining});下一条命令会自动刷新",
496
- logoutForgot: "已忘记 Agent 会话 {path}",
497
- logoutNothing: "没有本地会话(人类/CI 通道使用 STAMP_TOKEN)",
498
- cliUpdateAvailable: "stamp {current} 已过时,新版 {latest} 可用:npm install -g @botiverse/stamp-cli@latest",
499
- usageRepoUse: "用法:{cli} repo use [目录] [--identity KEY] [--known-hosts FILE]",
500
- repoUseDone: "{directory}:git 现在用这个 agent 自己的 key {path} 连 Stamp(只设在这个仓库里)",
501
- repoUseFailed: "无法在 {directory} 设置 core.sshCommand:{detail}",
502
- keyGenerated: "已为这个 agent 生成自己的 SSH key:{path}(放在 agent 自己的目录里,不在 ~/.ssh)",
503
- enrolled: "已登记 {fingerprint}({keyId})",
504
- enrolledIdentityRecorded: "这台机器上的 `{cli} repo clone` 会使用 {path}",
505
- enrolledIdentityNotRecorded: "私钥 {path} 不在这台机器上,这里的 `{cli} repo clone` 需要 --identity FILE",
506
- bound: "已绑定 {email}",
507
- usageKeyEnroll: "用法:{cli} key enroll [--public-key FILE|-]",
508
- usageKeyList: "用法:{cli} key list",
509
- usageKeyRevoke: "用法:{cli} key revoke KEY_ID",
510
- keyListEmpty: "没有已登记的公钥",
511
- keyRevoked: "已撤销 {keyId}",
512
- usageIdentityBind: "用法:{cli} identity bind --email ADDR",
513
- usageReceiptGet: "用法:{cli} receipt get <receipt-id>",
514
- usageReceiptList: "用法:{cli} receipt list [--repo OWNER/REPO] [--limit N] [--cursor CURSOR]",
515
- receiptListEmpty: "没有回执",
516
- receiptListMore: "还有更多回执;用 --limit 与 --cursor {cursor} 继续翻页。",
517
- receiptListBadResponse: "回执列表响应异常;请检查 {cli} 与网关版本后重试。",
518
- usageChangelog: "用法:{cli} changelog [--limit N] [--all]",
519
- changelogScopeAgent: "只显示命令行和接口的变化;--all 看全部。",
520
- changelogScopeAll: "显示全部变化,包括网页端和内部改动。",
521
- changelogNoneForAgents: "这个版本没有命令行或接口的变化(另有 {hidden} 项;--all 可看)",
522
- changelogHiddenCount: "(隐藏了 {hidden} 项其他改动;--all 可看)",
523
- changelogBuild: "网关构建 {version}({commit})",
524
- changelogEmpty: "这个构建里没有版本记录。",
525
- changelogNoEntries: "没有记录到 PR",
526
- changelogCurrentMark: "<- 当前运行",
527
- usageFollow: "用法:{cli} <follow|unfollow|subscription …> <owner/repo> --kind issue|pull --number N",
528
- usageSubscription: "用法:{cli} subscription pause|resume <owner/repo> --kind issue|pull --number N",
529
- usageWatch: "用法:{cli} {cmd} <owner/repo> --event TYPE",
530
- helpInstall: "安装:{cmds}",
531
- helpAgentLogin: "Agent 登录:{text}",
532
- sessionRejected: "{cli}: 会话被拒绝 — 请运行 `{cli} login`",
533
- checkToken: "{cli}: 请检查 STAMP_TOKEN",
534
- notLoggedIn: "尚未登录:请运行 `{cli} login`(受管 Agent)",
535
- sessionOriginMismatch: "已存会话是给 {stored} 签发的,不是 {target}——请重新运行 `{cli} login`",
536
- sessionOriginMismatchSibling: "已存会话是给 {stored} 签发的,不是 {target}——{stored} 对应的是 `{other}`,请改用它,而不是 `{cli}`",
537
- pair_mismatch: "拒绝不匹配的实例配对:{origin} 属于服务 {owner},而非 {service}(task #439)",
538
- stampTokenMissing: "未设置 STAMP_TOKEN(会话或部署令牌);在受管 Agent 内请运行 `{cli} login`",
539
- admissionPartial: "拒绝运行:受管 Agent 环境不完整({reason});不会回退到 STAMP_TOKEN",
540
- admissionMissingVars: "拒绝运行:受管 Agent 环境不完整——{missing} 未设置,但 {present} 已设置;这不是人类/CI 环境,不会回退到 STAMP_TOKEN",
541
- admissionInvalidAgentID: "拒绝运行:SLOCK_AGENT_ID={value} 不是合法的 agent id;请修好受管 Agent 环境——不会回退到 STAMP_TOKEN",
542
- admissionRaftWrapper: "拒绝运行:受管 Agent 的 raft 包装脚本缺失或不可执行({path});请修好受管 Agent 环境——不会回退到 STAMP_TOKEN",
543
- keyPublicKeyMissing: "{path} 没有 SSH 公钥:用 `ssh-keygen -t ed25519 -f {private}` 生成一把,或用 --public-key FILE 指定",
544
- invoke_not_json: "agent-login: `raft integration invoke` 没有返回 JSON",
545
- invoke_not_object: "agent-login: invoke 输出不是对象",
546
- invoke_failed: "agent-login: invoke 未成功",
547
- invoke_envelope: "agent-login: invoke 信封含有意外字段",
548
- invoke_data: "agent-login: invoke 结果缺少 data",
549
- invoke_data_fields: "agent-login: invoke data 含有意外字段",
550
- invoke_service: "agent-login: invoke 的 service 与请求的服务不匹配",
551
- invoke_action: "agent-login: invoke action 不是 agent-login",
552
- invoke_http: "agent-login: agent-login action 未返回 HTTP 200",
553
- grant_body: "agent-login: invoke 结果缺少 grant 正文",
554
- grant_fields: "agent-login: grant 结果含有意外字段",
555
- grant_schema: "agent-login: grant 结果 schema 不符合预期",
556
- grant_service: "agent-login: grant 结果 service 不匹配",
557
- grant_missing: "agent-login: 缺少 grant",
558
- grant_expires_at: "agent-login: grant expires_at 不是 RFC3339 时间戳",
559
- grant_expired: "agent-login: grant 已经过期",
560
- grant_ttl: "agent-login: grant 有效期超过上限",
561
- session_not_object: "agent-login: 兑换响应不是对象",
562
- session_fields: "agent-login: 会话含有意外字段",
563
- session_schema: "agent-login: 会话 schema 不符合预期",
564
- session_token_type: "agent-login: token_type 不符合预期",
565
- session_missing: "agent-login: 会话缺少 {field}",
566
- session_access_exp: "agent-login: 会话 access_expires_at 不是 RFC3339",
567
- session_access_expired: "agent-login: 会话访问令牌已经过期",
568
- session_refresh_exp: "agent-login: 会话 refresh_expires_at 必须是 RFC3339 或 null",
569
- session_refresh_expired: "agent-login: 会话刷新令牌已经过期",
570
- token_size_limit: "agent-login: 令牌响应超过大小限制",
571
- token_deadline: "agent-login: 令牌端点超过时限",
572
- invoke_exit: "agent-login: raft invoke 失败({status}):{diagnostic}",
573
- exchange_redirect: "agent-login: 授权兑换拒绝跟随重定向(HTTP {status})",
574
- exchange_failed: "agent-login: 授权兑换失败(HTTP {status})",
575
- exchange_not_json: "agent-login: 兑换响应不是 JSON",
576
- exchange_deadline: "agent-login: 授权兑换超过时限",
577
- refresh_redirect: "agent-login: 令牌刷新拒绝跟随重定向(HTTP {status})",
578
- refresh_failed: "agent-login: 令牌刷新失败(HTTP {status})",
579
- refresh_not_json: "agent-login: 刷新响应不是 JSON",
580
- refresh_deadline: "agent-login: 令牌刷新超过时限",
581
- refresh_wait_timeout: "agent-login: 等待并发令牌刷新超时",
582
- },
583
296
  };
584
297
 
585
- export function selectLocale(env = process.env, explicit) {
586
- const raw = String(explicit || env.STAMP_LANG || env.LC_ALL || env.LANG || "");
587
- if (/^zh/i.test(raw.trim())) return "zh-CN";
298
+ // The CLI speaks English only (artin 09-28): agents read, paste and search
299
+ // its output, and one language keeps that consistent. --lang and STAMP_LANG
300
+ // are still accepted, so existing scripts keep working, and ignored.
301
+ export function selectLocale() {
588
302
  return "en";
589
303
  }
590
304
 
@@ -73,3 +73,29 @@ export function runGitSetSSHCommand({ directory, sshCommand, spawnImpl = spawn }
73
73
  child.on("close", (code) => resolve({ ok: code === 0, stderr }));
74
74
  });
75
75
  }
76
+
77
+ // runGitConfigLocal sets one key in the checkout's own config (never
78
+ // --global: several agents often share one machine user).
79
+ export function runGitConfigLocal({ directory, key, value, spawnImpl = spawn }) {
80
+ return new Promise((resolve) => {
81
+ const child = spawnImpl("git", ["-C", directory, "config", "--local", key, value], { stdio: ["ignore", "ignore", "pipe"] });
82
+ let stderr = "";
83
+ child.stderr?.on("data", (b) => { stderr += b; });
84
+ child.on("error", () => resolve({ ok: false }));
85
+ child.on("close", (code) => resolve({ ok: code === 0, stderr }));
86
+ });
87
+ }
88
+
89
+ // setCommitIdentity writes the agent's commit identity into the checkout
90
+ // (artin 09-28: the commit email is already automatic, so no step should ask
91
+ // for `git config user.email`). An agent's commit email comes from /v1/me;
92
+ // a person's checkout is left alone. It returns the address written, or "".
93
+ export async function setCommitIdentity(ctx, me, directory) {
94
+ const address = typeof me?.commitEmail?.address === "string" ? me.commitEmail.address.trim() : "";
95
+ if (me?.principalType !== "agent" || !address) return "";
96
+ const set = ctx.opts.gitConfigLocalImpl ?? runGitConfigLocal;
97
+ const email = await set({ directory, key: "user.email", value: address });
98
+ if (!email.ok) return "";
99
+ if (typeof me.name === "string" && me.name.trim()) await set({ directory, key: "user.name", value: me.name.trim() });
100
+ return address;
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botiverse/stamp-cli",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "CLI for Stamp — Agent Git gateway in the Raft loop (bin stamp; future origin stamp.build)",
5
5
  "license": "MIT",
6
6
  "type": "module",