@botiverse/stamp-cli 0.3.14 → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Botiverse contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/launch.js ADDED
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher that picks the platform package holding the real stamp
3
+ // binary and forwards argv/stdio/exit status to it.
4
+
5
+ const { spawn } = require("node:child_process");
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+
9
+ const PLATFORM_PACKAGES = {
10
+ "linux-x64": "@botiverse/stamp-cli-linux-x64",
11
+ "linux-arm64": "@botiverse/stamp-cli-linux-arm64",
12
+ "darwin-x64": "@botiverse/stamp-cli-darwin-x64",
13
+ "darwin-arm64": "@botiverse/stamp-cli-darwin-arm64",
14
+ "win32-x64": "@botiverse/stamp-cli-win32-x64",
15
+ "win32-arm64": "@botiverse/stamp-cli-win32-arm64",
16
+ };
17
+
18
+ // Signals the launcher forwards to the child so Ctrl-C and external kills
19
+ // reach the real binary instead of only stopping this wrapper.
20
+ const FORWARD_SIGNALS = ["SIGHUP", "SIGINT", "SIGTERM"];
21
+
22
+ // Fallback exit codes (128 + signo) for when re-raising a signal on this
23
+ // process does not terminate it (e.g. the signal is blocked or ignored).
24
+ const SIGNAL_EXIT_CODES = { SIGHUP: 1, SIGINT: 2, SIGPIPE: 13, SIGTERM: 15 };
25
+
26
+ function resolveBinary({ platformKey = `${process.platform}-${process.arch}`, req = require } = {}) {
27
+ const pkgName = PLATFORM_PACKAGES[platformKey];
28
+ if (!pkgName) {
29
+ const supported = Object.keys(PLATFORM_PACKAGES).join(", ");
30
+ const err = new Error(
31
+ `stamp: unsupported platform "${platformKey}".\n` +
32
+ `Prebuilt binaries are published for: ${supported}.\n` +
33
+ "On other platforms install the 0.3-line JS implementation with " +
34
+ "`npm i -g @botiverse/stamp-cli@0.3`."
35
+ );
36
+ err.code = "UNSUPPORTED_PLATFORM";
37
+ throw err;
38
+ }
39
+ let pkgJson;
40
+ try {
41
+ pkgJson = req.resolve(`${pkgName}/package.json`);
42
+ } catch {
43
+ const err = new Error(
44
+ `stamp: platform package ${pkgName} is not installed.\n` +
45
+ `Install it with \`npm i -g ${pkgName}@<version>\` or reinstall ` +
46
+ "@botiverse/stamp-cli without `--omit=optional`."
47
+ );
48
+ err.code = "PLATFORM_PACKAGE_MISSING";
49
+ throw err;
50
+ }
51
+ const bin = path.join(
52
+ path.dirname(pkgJson),
53
+ "bin",
54
+ platformKey.startsWith("win32") ? "stamp.exe" : "stamp",
55
+ );
56
+ if (!fs.existsSync(bin)) {
57
+ const err = new Error(
58
+ `stamp: ${pkgName} did not ship a stamp binary for this platform.\n` +
59
+ "On Linux arm64 make sure you are not running under an x64 node/WSL " +
60
+ "shim; otherwise install the 0.3-line JS implementation with " +
61
+ "`npm i -g @botiverse/stamp-cli@0.3`."
62
+ );
63
+ err.code = "PLATFORM_BINARY_MISSING";
64
+ throw err;
65
+ }
66
+ return { bin, pkgName };
67
+ }
68
+
69
+ // spawnOptions is a single seam: callers that need a different argv[0] (e.g.
70
+ // the staging wrapper) pass it through; tests can assert on the option bag
71
+ // without depending on how the kernel interprets argv0.
72
+ function spawnOptions(argv0) {
73
+ return { stdio: "inherit", argv0 };
74
+ }
75
+
76
+ function signalExitCode(signal) {
77
+ return 128 + (SIGNAL_EXIT_CODES[signal] ?? 0);
78
+ }
79
+
80
+ async function run(argv0, opts = {}) {
81
+ let bin;
82
+ try {
83
+ ({ bin } = resolveBinary(opts));
84
+ } catch (error) {
85
+ // resolveBinary already writes user-facing messages; surface them on
86
+ // stderr instead of an unhandled rejection stack trace.
87
+ process.stderr.write(`${error.message}\n`);
88
+ process.exit(1);
89
+ }
90
+ const child = spawn(bin, process.argv.slice(2), spawnOptions(argv0));
91
+
92
+ const handlers = FORWARD_SIGNALS.map((signal) => [signal, () => child.kill(signal)]);
93
+ for (const [signal, handler] of handlers) process.on(signal, handler);
94
+
95
+ try {
96
+ const { code, signal } = await new Promise((resolve, reject) => {
97
+ child.once("error", reject);
98
+ child.once("exit", (code, signal) => resolve({ code, signal }));
99
+ });
100
+ if (signal) {
101
+ // Mirror the child's death-by-signal so callers observe the same
102
+ // termination status (signal under waitpid, 128+signo in shells).
103
+ // Detach our own forwarders first so the re-raised signal kills this
104
+ // process instead of being caught by them.
105
+ for (const [sig, handler] of handlers) {
106
+ process.off(sig, handler);
107
+ }
108
+ try {
109
+ process.kill(process.pid, signal);
110
+ } catch {
111
+ // Fall through to the numeric exit below.
112
+ }
113
+ process.exit(signalExitCode(signal));
114
+ }
115
+ process.exit(code ?? 1);
116
+ } catch (error) {
117
+ process.stderr.write(`stamp: failed to launch ${bin}: ${error.message}\n`);
118
+ process.exit(1);
119
+ } finally {
120
+ for (const [signal, handler] of handlers) process.off(signal, handler);
121
+ }
122
+ }
123
+
124
+ module.exports = { PLATFORM_PACKAGES, FORWARD_SIGNALS, SIGNAL_EXIT_CODES, resolveBinary, spawnOptions, run };
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ require("./launch.js").run("stamp-staging");
package/bin/stamp.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ require("./launch.js").run("stamp");
package/package.json CHANGED
@@ -1,30 +1,33 @@
1
1
  {
2
2
  "name": "@botiverse/stamp-cli",
3
- "version": "0.3.14",
4
- "description": "CLI for Stamp — Agent Git gateway in the Raft loop (bin stamp; future origin stamp.build)",
5
- "license": "MIT",
6
- "type": "module",
3
+ "version": "0.4.1",
4
+ "description": "Stamp CLI — prebuilt Go binary launcher",
7
5
  "bin": {
8
- "stamp": "bin/stamp.mjs",
9
- "stamp-staging": "bin/stamp-staging.mjs"
6
+ "stamp": "bin/stamp.js",
7
+ "stamp-staging": "bin/stamp-staging.js"
10
8
  },
11
9
  "files": [
12
- "bin",
13
- "lib"
10
+ "bin"
14
11
  ],
15
- "engines": {
16
- "node": ">=20"
17
- },
18
12
  "scripts": {
19
13
  "test": "node --test test/*.test.mjs"
20
14
  },
21
- "dependencies": {
22
- "@botiverse/agent-session-store": "^0.2.0"
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "optionalDependencies": {
19
+ "@botiverse/stamp-cli-linux-x64": "0.4.1",
20
+ "@botiverse/stamp-cli-linux-arm64": "0.4.1",
21
+ "@botiverse/stamp-cli-darwin-x64": "0.4.1",
22
+ "@botiverse/stamp-cli-darwin-arm64": "0.4.1",
23
+ "@botiverse/stamp-cli-win32-x64": "0.4.1",
24
+ "@botiverse/stamp-cli-win32-arm64": "0.4.1"
23
25
  },
24
26
  "repository": {
25
27
  "type": "git",
26
28
  "url": "git+https://github.com/botiverse/stamp.git"
27
29
  },
30
+ "license": "MIT",
28
31
  "publishConfig": {
29
32
  "access": "public"
30
33
  }
package/README.md DELETED
@@ -1,225 +0,0 @@
1
- # stamp
2
-
3
- CLI for the Agent Git gateway. Bin `stamp`. Package `@botiverse/stamp-cli`.
4
- Session storage is `@botiverse/agent-session-store` (fail-closed Raft agent
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.
10
-
11
- ```sh
12
- npm i -g @botiverse/stamp-cli
13
- # One-shot staging use must name the executable because the package has two bins.
14
- npx --yes --package @botiverse/stamp-cli stamp-staging --help
15
- stamp login
16
- stamp key enroll
17
- stamp identity bind --email agent@example.com
18
- stamp repo clone org/repo
19
- git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/my-change
20
- stamp receipt get <id>
21
- stamp receipt list
22
- stamp search "flaky test"
23
- 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
24
- stamp pr list
25
- stamp pr view 123 --repo org/repo
26
- stamp pr review 123 --repo org/repo
27
- stamp pr diff 123 --repo org/repo
28
- stamp pr checks 123 --repo org/repo
29
- stamp pr comment 123 --repo org/repo --body-file ./comment.md
30
- stamp pr edit 123 --repo org/repo --title "Clearer title" --body-file ./pr-body.md
31
- stamp pr approve 123 --repo org/repo --head <exact-head-sha> --base <exact-base-sha>
32
- stamp pr unapprove 123 --repo org/repo --head <exact-head-sha> --base <exact-base-sha>
33
- stamp pr merge 123 --repo org/repo --auto --head <exact-head-sha> --base <exact-base-sha>
34
- ```
35
-
36
- - Agent: `stamp login` (PKCE grant via `raft integration invoke --action agent-login`)
37
- - Human / CI: `STAMP_TOKEN`
38
- - Instance: `stamp` defaults to `https://stamp.build`; `stamp-staging` defaults
39
- to `https://staging.stamp.build`; `STAMP_URL` overrides either explicitly
40
- - 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`)
41
-
42
- Two installed bins, sharing one implementation:
43
-
44
- - `stamp` — production origin and service slug `stamp`
45
- - `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
46
-
47
- Configuration layering is `environment > executable defaults`: `STAMP_URL` and
48
- `STAMP_SERVICE` override either bin explicitly. There are no per-run URL or
49
- service command-line flags today.
50
-
51
- `repo clone` carries the SSH identity itself (task #475): it uses the key
52
- `key enroll` enrolled. `key enroll` records the private key next to the public
53
- key it read (the path without `.pub`), per instance, in `~/.stamp/identities.json`
54
- (`STAMP_IDENTITIES` to relocate; nothing is recorded for a public key read from
55
- stdin or one whose private half is not on this machine, and the command says so).
56
- A bare `repo clone` then uses that record; `--identity FILE` and `STAMP_SSH_IDENTITY`
57
- still win, and without a record the default `~/.ssh/id_ed25519` applies. The CLI
58
- never scans `~/.ssh` or guesses paths: a recorded key that is not on this machine
59
- is named, with `key enroll` here or `--identity` as the ways out (task #514). It
60
- also pins the host key the instance publishes at `/.well-known/ssh-known-hosts` into
61
- `~/.stamp/known_hosts` (`--known-hosts FILE` / `STAMP_KNOWN_HOSTS`), then records
62
- the same command as the clone's `core.sshCommand` so later `git push`/`git fetch`
63
- inherit it. No `GIT_SSH_COMMAND` export is needed.
64
-
65
- When `STAMP_URL` is not explicit, an existing Agent session stored against the
66
- exact legacy staging origin `https://github-staging.botiverse.dev` or the
67
- former CLI placeholder `https://github.botiverse.dev` is used against the new
68
- default origin. This keeps the same service-bound token while the compatibility
69
- DNS alias remains live; every other stored custom origin is preserved unchanged.
70
-
71
- `stamp pr create` calls the service directly using the Agent's service session.
72
- The receipt must belong to that Agent and be `PUBLISHED`; head/ref/repository/SHA
73
- must match it. Identical payloads derive a stable idempotency key, so rerunning
74
- the command after a lost response does not create a second PR. You can supply
75
- `--idempotency-key` explicitly (16–128 letters/digits/`._:-`). Branch names are
76
- expanded to `refs/heads/...`; full refs also work. Use `--body-file -` for stdin,
77
- `--body` for inline text. A non-empty description is required. `--json` prints the
78
- service receipt; a denial exits nonzero with recovery guidance.
79
-
80
- Beginning with CLI 0.3.9, `--repo`, `--head`, and `--sha` may all be omitted.
81
- The command waits up to 120 seconds for the push receipt to become `PUBLISHED`,
82
- then derives those three coordinates from the receipt. If explicit coordinates
83
- race asynchronous publication, it waits and retries exactly once with the same
84
- idempotency key. A failed/rejected receipt stops immediately; a timeout says the
85
- receipt is still accepted and the identical command is safe to rerun. CLI 0.3.8
86
- and older require an explicit `PUBLISHED` receipt's repository, ref, and SHA.
87
-
88
- The read-only PR commands follow the familiar `gh pr` command group while
89
- reading through Stamp rather than a local GitHub credential:
90
-
91
- - `stamp pr list` lists every PR that the current Agent created through Stamp.
92
- Filtering and pagination are intentionally not advertised until the service
93
- implements them.
94
- - `stamp pr view`, `stamp pr diff`, and `stamp pr checks` accept a PR URL or a
95
- number with `--repo OWNER/REPO` (`-R` also works).
96
- - `stamp pr diff --name-only` prints only paths. `stamp pr checks` exits `8`
97
- while checks are pending and `1` when a terminal check failed or no checks
98
- are reported, matching the useful `gh pr checks` automation convention.
99
- - `--json` returns the service's validated machine envelope. Human-formatted
100
- output strips terminal control characters from provider-authored text.
101
-
102
- `stamp pr edit` changes the title, description, or both on a PR the current
103
- Agent created through Stamp. Ownership comes from Stamp's durable creation
104
- receipt, not the shared GitHub App author: another Agent, another Raft Server,
105
- or a PR opened outside Stamp is refused before any provider write. Updating the
106
- description regenerates the protected Stamp attribution/footer; callers supply
107
- only their description text. If the provider outcome cannot be confirmed, the
108
- command exits nonzero and requires a PR re-read before any retry.
109
-
110
- ### Approving as an Agent
111
-
112
- With an Agent session, `stamp pr approve` records the approval **in Stamp** (a
113
- durable receipt), not as a GitHub review: PRs opened through Stamp are authored
114
- on GitHub by the shared App, so an App review would read as self-approval.
115
- `--head` and `--base` must be the exact current SHAs, `--base` being the PR's
116
- recorded base rather than the base branch's tip (a move is refused with
117
- `PR_HEAD_MOVED` / `PR_BASE_MOVED`, which print the current head and base to
118
- retry with), the approval counts only for that head, the
119
- PR's own author is refused (`SELF_APPROVAL_NOT_ALLOWED`), and there is no
120
- `--body`. `stamp pr unapprove` withdraws it. With a human session, `stamp pr
121
- approve` submits a GitHub review as the bound user, as before.
122
-
123
- ### Merging as an Agent
124
-
125
- With an Agent session, `stamp pr merge` works once there is an independent
126
- approval of the PR's exact current head from someone other than its author
127
- (another Agent's Stamp approval, or a GitHub approval from a human with write
128
- access) and no outstanding request for changes; otherwise it is refused with
129
- `PR_NOT_APPROVED` and the reasons. The author may merge too, once someone else
130
- approved. `--head` and `--base` must be the exact current SHAs (`PR_HEAD_MOVED` /
131
- `PR_BASE_MOVED`). The merge happens as the **Stamp App**, pinned to that head, so
132
- GitHub refuses it if the head moved; GitHub's branch protection still applies.
133
- The result names `mergedBy: "stamp-app"` and the merging Agent. Without `--method`
134
- the merge uses a method the repository allows (squash first, then a merge
135
- commit, then rebase); a `--method` it does not allow is refused with
136
- `PR_MERGE_METHOD_NOT_ALLOWED`, naming the allowed ones.
137
-
138
- The PR's author normally registers auto-merge immediately after creation:
139
-
140
- ```sh
141
- stamp pr merge 123 -R org/repo --auto --head <exact-head-sha> --base <exact-base-sha>
142
- ```
143
-
144
- This records intent; it is not approval. Stamp merges only when another
145
- principal approves that exact head and the pinned verdict is `READY`. A new push
146
- makes the registration `VOID`; re-read, get a new independent review, and have
147
- the author register the new coordinates. Read the current state with `--auto
148
- --status` and withdraw an unchanged registration with `--auto --cancel --head
149
- ... --base ...`.
150
-
151
- `stamp pr close` withdraws a PR the current Agent created through Stamp, under
152
- the same receipt-ownership gate as `pr edit` — another Agent, another Raft
153
- Server, or a PR opened outside Stamp is refused before any provider write, and
154
- an already-closed or merged PR is reported as not open rather than as a silent
155
- success. If the provider outcome cannot be confirmed, the command exits nonzero
156
- and requires a PR re-read before any retry.
157
-
158
- An Agent whose Raft role on the server is owner or admin may also close a
159
- stale PR that another Agent opened through Stamp **from the same Raft Server**,
160
- but only with a reason:
161
-
162
- ```sh
163
- stamp pr close 123 -R org/repo --reason "Stale for three weeks; superseded by #130."
164
- stamp pr close 123 -R org/repo --reason-file - # reason from stdin
165
- ```
166
-
167
- The reason (nonempty, at most 1000 characters) is posted on the PR first, as
168
- the Stamp App with the usual attribution block naming who closed it; only then
169
- is the PR closed, so a PR is never left closed without its explanation. Without
170
- a reason the admin close is refused with `PR_CLOSE_REASON_REQUIRED`; an admin of
171
- another server, or a non-admin who is not the author, is refused with
172
- `PULL_REQUEST_CLOSE_NOT_FOUND` / `PULL_REQUEST_CLOSE_NOT_OWNED` before any
173
- provider call. The author may pass `--reason` too, and it is posted the same
174
- way. Admin closes are recorded in Stamp's audit log. Human sessions cannot use
175
- this command yet.
176
-
177
- ### Ordinary PR comments
178
-
179
- `stamp pr comment 123 -R org/repo --body-file ./comment.md` uses a **human Stamp
180
- session with a bound GitHub account**, and posts as that GitHub user. Agent
181
- sessions are rejected; there is no fallback to an App or another person's token.
182
- The existing human session authentication applies; this command does not create
183
- a new login flow. The web inbox does not yet provide a comment composer.
184
-
185
- Use `--body TEXT` (`-b`) or `--body-file FILE` (`-F`); `--body-file -` reads stdin
186
- and preserves paragraphs. A PR URL can replace the number/repository pair.
187
- Comments must be nonempty and at most 64 KiB of UTF-8 text. Closed or merged PRs
188
- can still receive comments. This is an ordinary conversation comment, not a
189
- review, inline code comment, approval or merge.
190
-
191
- GitHub must permit the bound user's token to create comments; its
192
- [issue-comment API](https://docs.github.com/en/rest/issues/comments#create-an-issue-comment)
193
- accepts GitHub App user tokens with Issues or Pull requests write permission.
194
- Stamp's existing repository visibility checks also apply.
195
-
196
- Success prints the confirmed comment URL and GitHub actor; `--json` includes
197
- `repository`, `number`, `commentId`, `url` and `actorLogin`. Each explicit command
198
- is a new send, with no persistent deduplication. Neither CLI nor provider adapter
199
- automatically resends a comment. If a response is lost or cannot be validated,
200
- the command exits nonzero and asks you to inspect the PR before sending again.
201
-
202
- The Raft manifest exposes only `agent-login`. Key enrollment, identity binding,
203
- receipt reads, PR creation and subscriptions all use this CLI; the HTTP APIs
204
- remain available to service clients. `stamp migration-help` maps retired action
205
- names to commands. The retirement follows the Stamp owner's explicit cutover
206
- decision; the general Raft migration guide's optional compatibility period is
207
- over for this service.
208
-
209
- ### Agent merge queue
210
-
211
- Use `stamp pr queue enqueue <NUMBER -R OWNER/REPO|PR_URL> --request-id ID --head SHA --base SHA`
212
- for an enabled native queue. Choose and save a 16–128 character request ID before
213
- sending (letters/digits/underscore/hyphen, first character alphanumeric).
214
- Independent approval of the current head is required; this accepts a request,
215
- not a promise to merge. Use `stamp pr queue status ... --request-id ID --json`
216
- to reconcile an uncertain reply, and `stamp pr queue withdraw ... --request-id ID`
217
- to withdraw it. Reuse the same ID and coordinates; never create a new ID to retry
218
- a lost response. Receipt reads/withdrawal are limited to the original agent and
219
- server. Only requests still waiting can be withdrawn. Once a request enters a running
220
- batch, withdrawal returns `QUEUE_BATCH_IN_FLIGHT` without canceling any member;
221
- wait for completion and read the same request ID. Terminal receipts
222
- retain verified landing SHA; `notificationQueued` is not delivery confirmation.
223
- New admission requires the existing notification worker configured. This is a
224
- source capability, not a claim that the deployment enables queues or delivery.
225
- See [the queue contract](../docs/batch-merge-queue.md#agent-queue-requests).
@@ -1,15 +0,0 @@
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
- argv1: process.argv[1],
12
- urlBase: URL_BASE,
13
- urlExplicit: Boolean(process.env.STAMP_URL),
14
- serviceDefault: "raft-git-gateway-staging",
15
- });
package/bin/stamp.mjs DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env node
2
- // stamp — CLI for the Agent Git gateway, targeting the PRODUCTION instance.
3
- //
4
- // Task #439: the production service slug and the default origin used to be
5
- // resolved INDEPENDENTLY (lib/agent-login.mjs: STAMP_SERVICE="stamp" while the
6
- // default URL was the staging origin). Once the production `stamp` service was
7
- // registered, an unconfigured `stamp login` became a prod-slug + staging-origin
8
- // pair — a wrong-environment target.
9
- //
10
- // The instance is pinned as a COHERENT PAIR (prod slug + prod origin) and the
11
- // pair is defended. The defense compares the PARSED ORIGIN, not the raw string:
12
- // `https://staging.stamp.build/` (trailing slash), `HTTPS://STAGING.STAMP.BUILD`
13
- // and an explicit `:443` are the same origin and must be refused just the same.
14
- import { main } from "../lib/main.mjs";
15
-
16
- const PROD_URL = "https://stamp.build";
17
- const PROD_SERVICE = "stamp";
18
- const STAGING_URL = "https://staging.stamp.build";
19
- const STAGING_SERVICE = "raft-git-gateway-staging";
20
-
21
- // Canonical origin of a URL, or null when it is not an absolute http(s) URL.
22
- function originOf(value) {
23
- try {
24
- const parsed = new URL(value);
25
- if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
26
- return parsed.origin; // lowercases host, drops default port + path/query
27
- } catch {
28
- return null;
29
- }
30
- }
31
-
32
- // Canonical origin -> the service slug that owns it.
33
- //
34
- // SUPPORT BOUNDARY: this map lists the instances the CLI KNOWS. The pairing
35
- // invariant can only be enforced where the origin<->service mapping is known;
36
- // a self-hosted instance is not covered (the CLI has no general way to learn
37
- // its mapping). Do not describe the guarantee as universal.
38
- const KNOWN_INSTANCES = new Map([
39
- [originOf(PROD_URL), PROD_SERVICE],
40
- [originOf(STAGING_URL), STAGING_SERVICE],
41
- ]);
42
- const originService = KNOWN_INSTANCES;
43
-
44
- const url = process.env.STAMP_URL || PROD_URL;
45
- const urlOrigin = originOf(url);
46
- const owner = urlOrigin === null ? undefined : originService.get(urlOrigin);
47
-
48
- // The instance this invocation targets. An explicit STAMP_SERVICE must match the
49
- // origin's owner; otherwise derive it (a non-default origin needs its slug).
50
- const requested = process.env.STAMP_SERVICE;
51
- if (owner !== undefined && requested !== undefined && requested !== owner) {
52
- process.stderr.write(
53
- `stamp: STAMP_URL=${url} belongs to service ${owner}, not ${requested} — refusing to pair them (task #439).\n` +
54
- "Set both explicitly for a non-default instance, or use `stamp-staging` for staging.\n",
55
- );
56
- process.exit(2);
57
- }
58
- const service = requested ?? owner ?? PROD_SERVICE;
59
-
60
- await main(process.argv.slice(2), {
61
- argv1: process.argv[1],
62
- urlBase: url,
63
- urlExplicit: Boolean(process.env.STAMP_URL),
64
- serviceDefault: service,
65
- });