@botiverse/stamp-cli 0.3.8 → 0.3.9

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 CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  CLI for the Agent Git gateway. Bin `stamp`. Package `@botiverse/stamp-cli`.
4
4
  Session storage is `@botiverse/agent-session-store` (fail-closed Raft agent
5
- admission, atomic 0600 `auth.json`). Future public origin: `stamp.build`.
5
+ admission, atomic 0600 `auth.json`). Production origin: `https://stamp.build`.
6
+ The canonical Agent workflow is the instance-rendered
7
+ [`https://stamp.build/llms.txt`](https://stamp.build/llms.txt) (or
8
+ `https://staging.stamp.build/llms.txt` for staging); this package README explains
9
+ the command contracts but is not a second workflow source.
6
10
 
7
11
  ```sh
8
12
  npm i -g @botiverse/stamp-cli
@@ -18,22 +22,25 @@ stamp receipt list
18
22
  stamp pr create --receipt <published-id> --repo org/repo --head agent/my-change --sha <exact-sha> --base main --title "My change" --body-file ./pr-body.md
19
23
  stamp pr list
20
24
  stamp pr view 123 --repo org/repo
25
+ stamp pr review 123 --repo org/repo
21
26
  stamp pr diff 123 --repo org/repo
22
27
  stamp pr checks 123 --repo org/repo
23
28
  stamp pr comment 123 --repo org/repo --body-file ./comment.md
24
29
  stamp pr edit 123 --repo org/repo --title "Clearer title" --body-file ./pr-body.md
25
30
  stamp pr approve 123 --repo org/repo --head <exact-head-sha> --base <exact-base-sha>
26
31
  stamp pr unapprove 123 --repo org/repo --head <exact-head-sha> --base <exact-base-sha>
32
+ stamp pr merge 123 --repo org/repo --auto --head <exact-head-sha> --base <exact-base-sha>
27
33
  ```
28
34
 
29
35
  - Agent: `stamp login` (PKCE grant via `raft integration invoke --action agent-login`)
30
36
  - Human / CI: `STAMP_TOKEN`
31
- - Instance: `STAMP_URL` (default `https://staging.stamp.build`)
37
+ - Instance: `stamp` defaults to `https://stamp.build`; `stamp-staging` defaults
38
+ to `https://staging.stamp.build`; `STAMP_URL` overrides either explicitly
32
39
  - Raft app slug: `STAMP_SERVICE` (must match the gateway: `STAMP_SERVICE` or `RAFT_OAUTH_CLIENT_ID`; staging today is `raft-git-gateway-staging`, future `stamp`)
33
40
 
34
41
  Two installed bins, sharing one implementation:
35
42
 
36
- - `stamp` — default service slug `stamp` (the future production registration)
43
+ - `stamp` — production origin and service slug `stamp`
37
44
  - `stamp-staging` — pinned to today's staging registration: origin `https://staging.stamp.build`, service `raft-git-gateway-staging`, push remote `ssh://git@ssh.staging.stamp.build:443/...`; works with zero environment configuration
38
45
 
39
46
  Configuration layering is `environment > executable defaults`: `STAMP_URL` and
@@ -69,6 +76,14 @@ expanded to `refs/heads/...`; full refs also work. Use `--body-file -` for stdin
69
76
  `--body` for inline text. A non-empty description is required. `--json` prints the
70
77
  service receipt; a denial exits nonzero with recovery guidance.
71
78
 
79
+ Beginning with CLI 0.3.9, `--repo`, `--head`, and `--sha` may all be omitted.
80
+ The command waits up to 120 seconds for the push receipt to become `PUBLISHED`,
81
+ then derives those three coordinates from the receipt. If explicit coordinates
82
+ race asynchronous publication, it waits and retries exactly once with the same
83
+ idempotency key. A failed/rejected receipt stops immediately; a timeout says the
84
+ receipt is still accepted and the identical command is safe to rerun. CLI 0.3.8
85
+ and older require an explicit `PUBLISHED` receipt's repository, ref, and SHA.
86
+
72
87
  The read-only PR commands follow the familiar `gh pr` command group while
73
88
  reading through Stamp rather than a local GitHub credential:
74
89
 
@@ -114,6 +129,19 @@ approved. `--head` and `--base` must be the exact current SHAs (`PR_HEAD_MOVED`
114
129
  GitHub refuses it if the head moved; GitHub's branch protection still applies.
115
130
  The result names `mergedBy: "stamp-app"` and the merging Agent.
116
131
 
132
+ The PR's author normally registers auto-merge immediately after creation:
133
+
134
+ ```sh
135
+ stamp pr merge 123 -R org/repo --auto --head <exact-head-sha> --base <exact-base-sha>
136
+ ```
137
+
138
+ This records intent; it is not approval. Stamp merges only when another
139
+ principal approves that exact head and the pinned verdict is `READY`. A new push
140
+ makes the registration `VOID`; re-read, get a new independent review, and have
141
+ the author register the new coordinates. Read the current state with `--auto
142
+ --status` and withdraw an unchanged registration with `--auto --cancel --head
143
+ ... --base ...`.
144
+
117
145
  `stamp pr close` withdraws a PR the current Agent created through Stamp, under
118
146
  the same receipt-ownership gate as `pr edit` — another Agent, another Raft
119
147
  Server, or a PR opened outside Stamp is refused before any provider write, and
@@ -4,7 +4,7 @@ import { parsePRQueueArgs, validatePRQueueResult } from "../pr/queue.mjs";
4
4
  import { t, prefix } from "../locale.mjs";
5
5
  import { ApiError, NetworkError } from "../client.mjs";
6
6
  import { AgentError, printGatewayError } from "../errors.mjs";
7
- import { pullRequestInput, pullRequestRecovery } from "../pr/create.mjs";
7
+ import { publishWaitMs, pullRequestDraft, pullRequestNextLines, pullRequestInput, pullRequestNeedsReceipt, pullRequestRecovery, waitForPublishedReceipt } from "../pr/create.mjs";
8
8
  import { parsePRCommentArgs, validatePRCommentResult } from "../pr/comment.mjs";
9
9
  import { parsePREditArgs, validatePREditResult } from "../pr/edit.mjs";
10
10
  import { parsePRCloseArgs, validatePRCloseResult } from "../pr/close.mjs";
@@ -139,10 +139,31 @@ export async function run(ctx) {
139
139
  });
140
140
  }
141
141
  if (sub === "create") {
142
- const input = pullRequestInput(args);
142
+ const waitOpts = process.env.STAMP_PUBLISH_WAIT_MS ? { timeoutMs: publishWaitMs(process.env.STAMP_PUBLISH_WAIT_MS), intervalMs: 50 } : {};
143
+ // Validate everything that needs no network first, as before. One draft
144
+ // serves both builds, so the body is read once (see pullRequestDraft).
145
+ const draft = pullRequestDraft(args);
146
+ let input = pullRequestInput(args, pullRequestNeedsReceipt(args) ? { repository: "o/r", targetRef: "refs/heads/x", publishedSha: "0".repeat(40) } : null, draft);
147
+ let waited = false;
148
+ if (pullRequestNeedsReceipt(args)) {
149
+ input = pullRequestInput(args, await waitForPublishedReceipt(api, input.receiptId, waitOpts), draft);
150
+ waited = true;
151
+ }
143
152
  try {
144
- const d = await api("POST", "/v1/pull-requests", input);
145
- emit(d, () => out(t(locale, d.idempotent ? "prExisting" : "prCreated", { number: d.pullNumber, url: d.url })));
153
+ let d;
154
+ try {
155
+ d = await api("POST", "/v1/pull-requests", input);
156
+ } catch (e) {
157
+ // Created too soon after the push: wait for publication, then retry
158
+ // once with the same idempotency key.
159
+ if (waited || !(e instanceof ApiError) || e.body?.error !== "PUBLISHED_RECEIPT_NOT_FOUND") throw e;
160
+ await waitForPublishedReceipt(api, input.receiptId, waitOpts);
161
+ d = await api("POST", "/v1/pull-requests", input);
162
+ }
163
+ emit(d, () => {
164
+ out(t(locale, d.idempotent ? "prExisting" : "prCreated", { number: d.pullNumber, url: d.url }));
165
+ for (const line of pullRequestNextLines(d, ctx.auth?.apiBase, (key, vars) => t(locale, key, vars))) out(line);
166
+ });
146
167
  } catch (e) {
147
168
  if (e instanceof ApiError && e.status !== 401) {
148
169
  err(`${prefix()}${e.message}`);
package/lib/locale.mjs CHANGED
@@ -4,7 +4,7 @@ export const messages = {
4
4
  usagePrQueue: "usage: {cli} pr queue <enqueue|status|withdraw> <NUMBER -R OWNER/REPO|PR_URL> --request-id ID [--head SHA --base SHA (enqueue only)]; ID: 16–128 letters/digits/underscore/hyphen, first alphanumeric; choose it before sending and retain it",
5
5
  prQueueOutcomeUnknown: "Queue outcome is unknown. Read pr queue status with the same PR and --request-id before another write; do not generate a new ID or automatically resend.",
6
6
  prQueueReceipt: "Queue {repository}#{number}, request {id}: {state}; reason: {reason}; landing: {landing}; terminal notification queued: {queued} (not delivery confirmation)",
7
- 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]",
7
+ 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]; without --repo/--head/--sha they come from the published receipt",
8
8
  usagePrRead: "usage: {cli} pr <list|view|review|diff|checks|comment|edit|approve|unapprove|merge|queue> [arguments]",
9
9
  usagePrReview: "usage: {cli} pr review <number|URL> [--repo OWNER/REPO] — the exact head to pin, base, merge-base, checks, and the diff/patch-id commands against the merge-base",
10
10
  prReviewExactHead: "Exact head",
@@ -114,7 +114,12 @@ export const messages = {
114
114
  prIdempotency: "--idempotency-key must contain 16–128 letters, digits, dots, underscores, colons, or hyphens.",
115
115
  prCreated: "Created PR #{number}: {url}",
116
116
  prExisting: "Existing PR #{number}: {url}",
117
+ prStampPage: " Stamp: {page}",
118
+ prNextAutoMerge: " Next: {cli} pr merge {number} --repo {repository} --auto --head {head} --base {base}\n (Stamp merges it once someone other than you approves this head and the verdict is READY)",
117
119
  prWaitPublished: "Check {cli} receipt get <id>; use your own receipt after its status becomes PUBLISHED.",
120
+ prReceiptNotPublished: "Receipt {id} is {status}; it will not be published, so no pull request can be opened from it. See {cli} receipt get {id}.",
121
+ prPublishTimeout: "Receipt {id} is still {status} after waiting for GitHub publication; run the same command again later, or check {cli} receipt get {id}.",
122
+ prReceiptIncomplete: "Receipt {id} is published but lacks its repository, ref or commit; pass --repo, --head and --sha explicitly.",
118
123
  prCheckReceipt: "Read the receipt again and check --repo, --head and --sha against the exact published commit.",
119
124
  prCheckAccess: "Check repository access and the authorized base branch with the repository administrator.",
120
125
  prCheckBase: "The base branch does not exist on GitHub. Pass --base as an existing branch of the repository.",
@@ -140,7 +145,7 @@ export const messages = {
140
145
  {cli} receipt list [--repo OWNER/REPO] [--limit N] [--cursor CURSOR]
141
146
  list your own push receipts (newest first)
142
147
  {cli} changelog [--limit N] [--all] release history: CLI/API changes per version (--all: everything)
143
- {cli} pr create --receipt ID --repo OWNER/REPO --head BRANCH --sha SHA --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
148
+ {cli} pr create --receipt ID [--repo OWNER/REPO --head BRANCH --sha SHA] --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
144
149
  {cli} pr list
145
150
  {cli} pr view <number|URL> --repo OWNER/REPO
146
151
  {cli} pr diff <number|URL> --repo OWNER/REPO [--name-only]
@@ -164,7 +169,8 @@ export const messages = {
164
169
  git clone ssh://git@ssh.staging.stamp.build:443/org/repo.git
165
170
  git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
166
171
 
167
- flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance), STAMP_SERVICE, STAMP_LANG`,
172
+ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance), STAMP_SERVICE, STAMP_LANG
173
+ docs: {docs} (the agent workflow, step by step)`,
168
174
  usageRepoClone: "usage: {cli} repo clone <repository> [<directory>] [--identity FILE] [--known-hosts FILE] [-- <gitflags>...]",
169
175
  cloned: "Cloned {repository} from {url}",
170
176
  cloneCommitTrailers: "Every commit you push here must end with these trailers, as one block at the very end with no blank line between them (GitHub only reads the last contiguous block):",
@@ -278,7 +284,7 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
278
284
  usagePrQueue: "用法:{cli} pr queue <enqueue|status|withdraw> <NUMBER -R OWNER/REPO|PR_URL> --request-id ID [--head SHA --base SHA(仅 enqueue)];ID 为 16–128 位字母、数字、下划线或连字符,首位为字母或数字;发送前选定并保留",
279
285
  prQueueOutcomeUnknown: "队列操作结果未知。再次写入前,用同一 PR 和 --request-id 执行 pr queue status;不要生成新 ID 或自动重发。",
280
286
  prQueueReceipt: "队列 {repository}#{number},请求 {id}:{state};原因:{reason};落地:{landing};终态通知已入队:{queued}(不代表送达)",
281
- 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]",
287
+ 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 读取",
282
288
  usagePrRead: "用法:{cli} pr <list|view|review|diff|checks|comment|edit|approve|unapprove|merge|queue> [参数]",
283
289
  usagePrReview: "用法:{cli} pr review <编号|URL> [--repo OWNER/REPO] —— 要钉的 exact head、base、merge-base、检查,以及对 merge-base 做 diff/patch-id 的命令",
284
290
  prReviewExactHead: "Exact head",
@@ -388,7 +394,12 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
388
394
  prIdempotency: "--idempotency-key 必须为 16–128 位字母、数字、点、下划线、冒号或连字符。",
389
395
  prCreated: "已创建 PR #{number}:{url}",
390
396
  prExisting: "已有 PR #{number}:{url}",
397
+ prStampPage: " Stamp:{page}",
398
+ prNextAutoMerge: " 下一步:{cli} pr merge {number} --repo {repository} --auto --head {head} --base {base}\n (他人批准这个 head 且判定为 READY 后,Stamp 自动合并)",
391
399
  prWaitPublished: "请用 {cli} receipt get <id> 检查;只使用自己状态为 PUBLISHED 的 receipt。",
400
+ prReceiptNotPublished: "Receipt {id} 的状态是 {status},不会发表到 GitHub,无法据此创建 PR。见 {cli} receipt get {id}。",
401
+ prPublishTimeout: "等待 GitHub 发表后,receipt {id} 仍是 {status};稍后重跑同一命令,或查看 {cli} receipt get {id}。",
402
+ prReceiptIncomplete: "Receipt {id} 已发表,但缺少仓库、ref 或提交;请显式传 --repo、--head 和 --sha。",
392
403
  prCheckReceipt: "请重新读取 receipt,并核对 --repo、--head 和 --sha 是否与已发表提交一致。",
393
404
  prCheckAccess: "请与仓库管理员核对仓库权限和允许的目标分支。",
394
405
  prCheckBase: "目标分支在 GitHub 上不存在;请用 --base 指定仓库里已存在的分支。",
@@ -414,7 +425,7 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
414
425
  {cli} receipt list [--repo OWNER/REPO] [--limit N] [--cursor CURSOR]
415
426
  列出你自己的推送回执(新的在前)
416
427
  {cli} changelog [--limit N] [--all] 更新日志:每个版本的命令行/接口变化(--all 看全部)
417
- {cli} pr create --receipt ID --repo OWNER/REPO --head BRANCH --sha SHA --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
428
+ {cli} pr create --receipt ID [--repo OWNER/REPO --head BRANCH --sha SHA] --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
418
429
  {cli} pr list
419
430
  {cli} pr view <编号|URL> --repo OWNER/REPO
420
431
  {cli} pr diff <编号|URL> --repo OWNER/REPO [--name-only]
@@ -438,7 +449,8 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
438
449
  git clone ssh://git@ssh.staging.stamp.build:443/org/repo.git
439
450
  git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
440
451
 
441
- flags: --json --lang en|zh-CN env: STAMP_TOKEN(人类/CI)、STAMP_URL、STAMP_SERVICE、STAMP_LANG`,
452
+ flags: --json --lang en|zh-CN env: STAMP_TOKEN(人类/CI)、STAMP_URL、STAMP_SERVICE、STAMP_LANG
453
+ 文档:{docs}(Agent 工作流,逐步说明)`,
442
454
  usageRepoClone: "用法:{cli} repo clone <repository> [<directory>] [--identity FILE] [--known-hosts FILE] [-- <gitflags>...]",
443
455
  cloned: "已从 {url} 克隆 {repository}",
444
456
  cloneCommitTrailers: "推到这里的每个 commit 末尾都要带这两行 trailer(连成一块放在最末尾,中间不要空行;GitHub 只认最后一个连续块):",
package/lib/main.mjs CHANGED
@@ -63,7 +63,10 @@ export async function main(argv, opts) {
63
63
  if (cliName !== undefined) setCliName(cliName);
64
64
  if (version) { out(pkg.version); return exit(0); }
65
65
  const cmd = args.shift();
66
- if (help || !cmd) { out(t(locale, "usage", { version: pkg.version })); return exit(0); }
66
+ // The agent-facing document lives on the instance itself (/llms.txt), so
67
+ // the help names this instance's copy.
68
+ const docs = `${String(env.STAMP_URL || opts.urlBase || "https://stamp.build").replace(/\/+$/, "")}/llms.txt`;
69
+ if (help || !cmd) { out(t(locale, "usage", { version: pkg.version, docs })); return exit(0); }
67
70
  const emit = (data, human) => { if (json) out(JSON.stringify(data, null, 2)); else human(); };
68
71
 
69
72
  let auth;
@@ -78,7 +81,7 @@ export async function main(argv, opts) {
78
81
  });
79
82
  const handler = commands[cmd];
80
83
  if (!handler) {
81
- out(t(locale, "usage", { version: pkg.version }));
84
+ out(t(locale, "usage", { version: pkg.version, docs }));
82
85
  return exit(1);
83
86
  }
84
87
 
package/lib/pr/create.mjs CHANGED
@@ -4,7 +4,22 @@ import { AgentError } from "../errors.mjs";
4
4
 
5
5
  const names = new Set(["receipt", "repo", "head", "sha", "base", "title", "body", "body-file", "idempotency-key"]);
6
6
 
7
- export function pullRequestInput(args) {
7
+ // receiptFields are the flags a published receipt can supply: when all three
8
+ // are omitted, the CLI reads them from the receipt (repository, targetRef,
9
+ // publishedSha) instead of making the agent copy them over by hand.
10
+ export const receiptFields = ["repo", "head", "sha"];
11
+
12
+ export function pullRequestNeedsReceipt(args) {
13
+ return receiptFields.every((name) => !args.some((a) => a === `--${name}` || a.startsWith(`--${name}=`)));
14
+ }
15
+
16
+ // pullRequestDraft parses the flags once and reads the body at most once:
17
+ // `pr create` builds its input twice when it waits for the receipt (a local
18
+ // check before the wait, the real input after it), and a second read of
19
+ // `--body-file -` would find stdin already at EOF, while a second read of a
20
+ // file could pick up content rewritten during the wait. Both builds share one
21
+ // draft, so they share one body.
22
+ export function pullRequestDraft(args) {
8
23
  const flags = new Map();
9
24
  for (let i = 0; i < args.length; i++) {
10
25
  const [flag, ...inline] = args[i].split("=");
@@ -14,6 +29,29 @@ export function pullRequestInput(args) {
14
29
  if (value === undefined || (!inline.length && value.startsWith("--"))) throw new AgentError("usagePrCreate");
15
30
  flags.set(name, value);
16
31
  }
32
+ let body;
33
+ return {
34
+ flags,
35
+ body() {
36
+ if (body !== undefined) return body;
37
+ if (flags.has("body") && flags.has("body-file")) throw new AgentError("prBodyConflict");
38
+ body = flags.get("body") ?? "";
39
+ if (flags.has("body-file")) {
40
+ try { body = readFileSync(flags.get("body-file") === "-" ? 0 : flags.get("body-file"), "utf8"); }
41
+ catch { body = undefined; throw new AgentError("prBodyRead"); }
42
+ }
43
+ return body;
44
+ },
45
+ };
46
+ }
47
+
48
+ export function pullRequestInput(args, fromReceipt = null, draft = pullRequestDraft(args)) {
49
+ const flags = new Map(draft.flags);
50
+ if (fromReceipt) {
51
+ flags.set("repo", fromReceipt.repository);
52
+ flags.set("head", fromReceipt.targetRef);
53
+ flags.set("sha", fromReceipt.publishedSha);
54
+ }
17
55
  for (const name of ["receipt", "repo", "head", "sha", "base", "title"]) {
18
56
  if (!flags.get(name)?.trim()) throw new AgentError("prRequired", { flag: `--${name}` });
19
57
  }
@@ -23,12 +61,7 @@ export function pullRequestInput(args) {
23
61
  const value = flags.get(name);
24
62
  return value.startsWith("refs/") ? value : `refs/heads/${value}`;
25
63
  };
26
- if (flags.has("body") && flags.has("body-file")) throw new AgentError("prBodyConflict");
27
- let body = flags.get("body") ?? "";
28
- if (flags.has("body-file")) {
29
- try { body = readFileSync(flags.get("body-file") === "-" ? 0 : flags.get("body-file"), "utf8"); }
30
- catch { throw new AgentError("prBodyRead"); }
31
- }
64
+ const body = draft.body();
32
65
  if (!body.trim()) throw new AgentError("prBodyRequired");
33
66
  const input = {
34
67
  receiptId: flags.get("receipt"), repository: flags.get("repo"),
@@ -61,3 +94,57 @@ export function pullRequestRecovery(code) {
61
94
  default: return "prRetry";
62
95
  }
63
96
  }
97
+
98
+ // waitForPublishedReceipt polls the receipt until GitHub publication is done:
99
+ // a push is accepted by the gateway first and published asynchronously, so a
100
+ // pr create right after the push used to fail with
101
+ // PUBLISHED_RECEIPT_NOT_FOUND and the agent had to poll by hand.
102
+ export const publishWaitDefaultMs = 120000;
103
+
104
+ // publishWaitMs reads the STAMP_PUBLISH_WAIT_MS test hook. Only a positive
105
+ // whole number of milliseconds counts; anything else keeps the default, so
106
+ // the hook can shorten the wait but never make it unbounded.
107
+ export function publishWaitMs(value) {
108
+ return /^[1-9][0-9]{0,8}$/.test(value ?? "") ? Number(value) : publishWaitDefaultMs;
109
+ }
110
+
111
+ export async function waitForPublishedReceipt(api, id, { timeoutMs = publishWaitDefaultMs, intervalMs = 2000, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), now = Date.now } = {}) {
112
+ // A NaN, infinite or non-positive bound would make the deadline check
113
+ // below never true: the wait must stay bounded whatever the caller passed.
114
+ if (!(Number.isFinite(timeoutMs) && timeoutMs > 0)) timeoutMs = publishWaitDefaultMs;
115
+ const deadline = now() + timeoutMs;
116
+ for (;;) {
117
+ const d = await api("GET", `/v1/receipts/${encodeURIComponent(id)}`);
118
+ if (d.status === "PUBLISHED") {
119
+ if (!d.repository || !d.targetRef || !/^[0-9a-f]{40}$/.test(d.publishedSha ?? "")) throw new AgentError("prReceiptIncomplete", { id });
120
+ return d;
121
+ }
122
+ if (d.status === "FAILED" || d.status === "REJECTED") throw new AgentError("prReceiptNotPublished", { id, status: d.status });
123
+ if (now() >= deadline) throw new AgentError("prPublishTimeout", { id, status: d.status });
124
+ await sleep(intervalMs);
125
+ }
126
+ }
127
+
128
+ // pullRequestNextLines is what `pr create` prints under "Created PR": the
129
+ // pull request's page on this Stamp instance, and the one command that
130
+ // registers it for auto-merge, with the exact head and base the gateway just
131
+ // answered (Imprint, 09-27: agents read CLI output, and auto-merge went
132
+ // unnoticed in --help). A line whose values do not check out is left out,
133
+ // never printed half-filled.
134
+ export function pullRequestNextLines(d, apiBase, tr) {
135
+ const lines = [];
136
+ const repo = typeof d?.repository === "string" && /^[^/\s]+\/[^/\s]+$/.test(d.repository) ? d.repository : null;
137
+ const number = Number.isInteger(d?.pullNumber) && d.pullNumber > 0 ? d.pullNumber : null;
138
+ if (!repo || !number) return lines;
139
+ let origin = null;
140
+ try {
141
+ const u = new URL(apiBase);
142
+ if (u.protocol === "https:" || u.hostname === "127.0.0.1" || u.hostname === "localhost") origin = u.origin;
143
+ } catch { /* no page line */ }
144
+ if (origin) lines.push(tr("prStampPage", { page: `${origin}/github/${repo}/pull/${number}` }));
145
+ const sha = (v) => typeof v === "string" && /^[0-9a-f]{40}$/.test(v);
146
+ if (sha(d.headSha) && sha(d.baseSha)) {
147
+ lines.push(tr("prNextAutoMerge", { number, repository: repo, head: d.headSha, base: d.baseSha }));
148
+ }
149
+ return lines;
150
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botiverse/stamp-cli",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
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",