@botiverse/stamp-cli 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,16 +9,31 @@ npm i -g @botiverse/stamp-cli
9
9
  stamp login
10
10
  stamp key enroll
11
11
  stamp identity bind --email agent@example.com
12
- git push git@github.botiverse.dev:org/repo.git HEAD:refs/heads/agent/my-change
12
+ git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/my-change
13
13
  stamp receipt get <id>
14
14
  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
15
15
  ```
16
16
 
17
17
  - Agent: `stamp login` (PKCE grant via `raft integration invoke --action agent-login`)
18
18
  - Human / CI: `STAMP_TOKEN`
19
- - Instance: `STAMP_URL` (default `https://github.botiverse.dev`)
19
+ - Instance: `STAMP_URL` (default `https://staging.stamp.build`)
20
20
  - 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`)
21
21
 
22
+ Two installed bins, sharing one implementation:
23
+
24
+ - `stamp` — default service slug `stamp` (the future production registration)
25
+ - `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
26
+
27
+ Configuration layering is `environment > executable defaults`: `STAMP_URL` and
28
+ `STAMP_SERVICE` override either bin explicitly. There are no per-run URL or
29
+ service command-line flags today.
30
+
31
+ When `STAMP_URL` is not explicit, an existing Agent session stored against the
32
+ exact legacy staging origin `https://github-staging.botiverse.dev` or the
33
+ former CLI placeholder `https://github.botiverse.dev` is used against the new
34
+ default origin. This keeps the same service-bound token while the compatibility
35
+ DNS alias remains live; every other stored custom origin is preserved unchanged.
36
+
22
37
  `stamp pr create` calls the service directly using the Agent's service session.
23
38
  The receipt must belong to that Agent and be `PUBLISHED`; head/ref/repository/SHA
24
39
  must match it. Identical payloads derive a stable idempotency key, so rerunning
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ // stamp-staging — staging-pinned entry: the exact staging origin and the
3
+ // registered staging service slug work with zero environment configuration.
4
+ // STAMP_URL / STAMP_SERVICE still override explicitly.
5
+ import { main } from "../lib/main.mjs";
6
+ import { STAMP_DEFAULT_URL } from "../lib/agent-login.mjs";
7
+
8
+ const URL_BASE = process.env.STAMP_URL || STAMP_DEFAULT_URL;
9
+
10
+ await main(process.argv.slice(2), {
11
+ urlBase: URL_BASE,
12
+ urlExplicit: Boolean(process.env.STAMP_URL),
13
+ serviceDefault: "raft-git-gateway-staging",
14
+ });
package/bin/stamp.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
- // stamp — CLI for the Agent Git gateway (future origin stamp.build).
3
- // Default instance is the current SSH/HTTPS hostname.
2
+ // stamp — CLI for the Agent Git gateway.
3
+ // Default instance is the current staging HTTPS origin.
4
4
  import { main } from "../lib/main.mjs";
5
+ import { STAMP_DEFAULT_URL } from "../lib/agent-login.mjs";
5
6
 
6
- const URL_BASE = process.env.STAMP_URL || "https://github.botiverse.dev";
7
+ const URL_BASE = process.env.STAMP_URL || STAMP_DEFAULT_URL;
7
8
 
8
9
  await main(process.argv.slice(2), { urlBase: URL_BASE, urlExplicit: Boolean(process.env.STAMP_URL) });
@@ -13,6 +13,9 @@ import { writeAgentSession } from "@botiverse/agent-session-store";
13
13
  import { AgentError, agentFail } from "./errors.mjs";
14
14
 
15
15
  export const STAMP_SERVICE = "stamp";
16
+ export const STAMP_DEFAULT_URL = "https://staging.stamp.build";
17
+ export const STAMP_LEGACY_STAGING_URL = "https://github-staging.botiverse.dev";
18
+ export const STAMP_LEGACY_DEFAULT_URL = "https://github.botiverse.dev";
16
19
  export const TOKEN_DEADLINE_MS = 20_000;
17
20
 
18
21
  function base64url(buf) {
@@ -35,11 +35,12 @@ export function refreshLockPath(a, service = STAMP_SERVICE) {
35
35
  return join(dirname(agentAuthPath(a, service)), ".auth.refresh.lock");
36
36
  }
37
37
 
38
- async function rotate(a, service, store, now, fetchImpl, deadlineMs) {
38
+ async function rotate(a, service, store, now, fetchImpl, deadlineMs, apiBase) {
39
+ const targetBase = apiBase ?? store.api_base;
39
40
  const controller = new AbortController();
40
41
  const timer = setTimeout(() => controller.abort(), deadlineMs);
41
42
  try {
42
- const res = await fetchImpl(new URL("/api/auth/agent/refresh", store.api_base).toString(), {
43
+ const res = await fetchImpl(new URL("/api/auth/agent/refresh", targetBase).toString(), {
43
44
  method: "POST",
44
45
  headers: { "content-type": "application/json", accept: "application/json" },
45
46
  body: JSON.stringify({ schema: "raft-cli-agent-refresh.v1", refresh_token: store.refresh_token }),
@@ -55,7 +56,7 @@ async function rotate(a, service, store, now, fetchImpl, deadlineMs) {
55
56
  let body;
56
57
  try { body = JSON.parse(text); } catch { agentFail("refresh_not_json"); }
57
58
  const session = parseAgentSession(body, now);
58
- writeAgentSession(a, service, session, store.api_base, () => new Date(now).toISOString());
59
+ writeAgentSession(a, service, session, targetBase, () => new Date(now).toISOString());
59
60
  return session;
60
61
  } catch (e) {
61
62
  if (e instanceof AgentError) throw e;
@@ -78,7 +79,7 @@ export async function getFreshAgentAccessToken(a, opts = {}) {
78
79
  const store = readStore(a, service);
79
80
  if (!store) return null;
80
81
  if (!accessExpiresWithinSkew(store, now)) return store.access_token;
81
- return singleFlightRefresh(a, service, store, now, opts.fetchImpl ?? fetch, opts.sleepImpl ?? sleep, false, opts.deadlineMs ?? REFRESH_DEADLINE_MS);
82
+ return singleFlightRefresh(a, service, store, now, opts.fetchImpl ?? fetch, opts.sleepImpl ?? sleep, false, opts.deadlineMs ?? REFRESH_DEADLINE_MS, undefined, opts.apiBase);
82
83
  }
83
84
 
84
85
  export async function forceRefreshAgentToken(a, opts = {}) {
@@ -88,10 +89,10 @@ export async function forceRefreshAgentToken(a, opts = {}) {
88
89
  if (!store) return null;
89
90
  const reused = successorIfRejected(store, opts.rejectedAccess);
90
91
  if (reused) return reused;
91
- return singleFlightRefresh(a, service, store, now, opts.fetchImpl ?? fetch, opts.sleepImpl ?? sleep, true, opts.deadlineMs ?? REFRESH_DEADLINE_MS, opts.rejectedAccess);
92
+ return singleFlightRefresh(a, service, store, now, opts.fetchImpl ?? fetch, opts.sleepImpl ?? sleep, true, opts.deadlineMs ?? REFRESH_DEADLINE_MS, opts.rejectedAccess, opts.apiBase);
92
93
  }
93
94
 
94
- async function singleFlightRefresh(a, service, baseline, now, fetchImpl, sleepImpl, force, deadlineMs, rejectedAccess) {
95
+ async function singleFlightRefresh(a, service, baseline, now, fetchImpl, sleepImpl, force, deadlineMs, rejectedAccess, apiBase) {
95
96
  const lock = refreshLockPath(a, service);
96
97
  const ownerId = newOwnerId();
97
98
  let acquired;
@@ -110,7 +111,7 @@ async function singleFlightRefresh(a, service, baseline, now, fetchImpl, sleepIm
110
111
  const reused = successorIfRejected(fresh, rejectedAccess);
111
112
  if (reused) return reused;
112
113
  if (!force && !accessExpiresWithinSkew(fresh, now)) return fresh.access_token;
113
- const session = await rotate(a, service, fresh, now, fetchImpl, deadlineMs);
114
+ const session = await rotate(a, service, fresh, now, fetchImpl, deadlineMs, apiBase);
114
115
  return session.access_token;
115
116
  } finally {
116
117
  releaseOwnLock(lock, ownerId);
package/lib/auth.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { unlinkSync, existsSync } from "node:fs";
2
2
  import { admitAgent, agentAuthPath } from "@botiverse/agent-session-store";
3
- import { STAMP_SERVICE } from "./agent-login.mjs";
3
+ import { STAMP_LEGACY_DEFAULT_URL, STAMP_LEGACY_STAGING_URL, STAMP_SERVICE } from "./agent-login.mjs";
4
4
  import { getFreshAgentAccessToken, forceRefreshAgentToken, readStore } from "./agent-refresh.mjs";
5
5
  import { AgentError, agentFail } from "./errors.mjs";
6
6
 
@@ -12,18 +12,21 @@ export function resolveAuth({ urlBase, urlExplicit, env = process.env, service =
12
12
  if (admission.kind === "agent") {
13
13
  const a = admission.env;
14
14
  const store = readStore(a, service);
15
- const apiBase = urlExplicit ? urlBase : (store?.api_base ?? urlBase);
15
+ const storedBase = store?.api_base;
16
+ const apiBase = urlExplicit
17
+ ? urlBase
18
+ : ([STAMP_LEGACY_STAGING_URL, STAMP_LEGACY_DEFAULT_URL].includes(storedBase) ? urlBase : (storedBase ?? urlBase));
16
19
  return {
17
20
  mode: "agent",
18
21
  apiBase,
19
22
  agentEnv: a,
20
23
  service,
21
24
  async token() {
22
- const tok = await getFreshAgentAccessToken(a, { service });
25
+ const tok = await getFreshAgentAccessToken(a, { service, apiBase });
23
26
  if (!tok) throw new AgentError("notLoggedIn");
24
27
  return tok;
25
28
  },
26
- async retryToken(rejectedAccess) { return forceRefreshAgentToken(a, { service, rejectedAccess }); },
29
+ async retryToken(rejectedAccess) { return forceRefreshAgentToken(a, { service, apiBase, rejectedAccess }); },
27
30
  logout() {
28
31
  const p = agentAuthPath(a, service);
29
32
  if (existsSync(p)) unlinkSync(p);
package/lib/locale.mjs CHANGED
@@ -37,7 +37,7 @@ export const messages = {
37
37
  stamp watch <owner/repo> --event TYPE
38
38
  stamp unwatch <owner/repo> --event TYPE
39
39
 
40
- git push git@github.botiverse.dev:org/repo.git HEAD:refs/heads/agent/…
40
+ git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
41
41
 
42
42
  flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance), STAMP_SERVICE, STAMP_LANG`,
43
43
  loginHumanIntro: "Not a managed Raft agent. Humans and CI use STAMP_TOKEN:",
@@ -137,7 +137,7 @@ flags: --json --lang en|zh-CN env: STAMP_TOKEN (human/CI), STAMP_URL (instance
137
137
  stamp watch <owner/repo> --event TYPE
138
138
  stamp unwatch <owner/repo> --event TYPE
139
139
 
140
- git push git@github.botiverse.dev:org/repo.git HEAD:refs/heads/agent/…
140
+ git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/…
141
141
 
142
142
  flags: --json --lang en|zh-CN env: STAMP_TOKEN(人类/CI)、STAMP_URL、STAMP_SERVICE、STAMP_LANG`,
143
143
  loginHumanIntro: "当前不是受管 Raft Agent。人类和 CI 使用 STAMP_TOKEN:",
package/lib/main.mjs CHANGED
@@ -65,7 +65,7 @@ export async function main(argv, opts) {
65
65
 
66
66
  let auth;
67
67
  try {
68
- auth = resolveAuth({ urlBase: opts.urlBase, urlExplicit: opts.urlExplicit, env, locale });
68
+ auth = resolveAuth({ urlBase: opts.urlBase, urlExplicit: opts.urlExplicit, env, locale, service: env.STAMP_SERVICE || opts.serviceDefault || undefined });
69
69
  } catch (e) {
70
70
  err(`stamp: ${presentError(locale, e)}`);
71
71
  return exit(1);
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@botiverse/stamp-cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",
7
7
  "bin": {
8
- "stamp": "bin/stamp.mjs"
8
+ "stamp": "bin/stamp.mjs",
9
+ "stamp-staging": "bin/stamp-staging.mjs"
9
10
  },
10
11
  "files": [
11
12
  "bin",