@botiverse/stamp-cli 0.3.4 → 0.3.8
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 +69 -2
- package/lib/commands/changelog.mjs +58 -0
- package/lib/commands/key.mjs +38 -1
- package/lib/commands/knownhosts.mjs +150 -0
- package/lib/commands/pr.mjs +89 -4
- package/lib/commands/receipt.mjs +24 -1
- package/lib/commands/repo.mjs +16 -4
- package/lib/locale.mjs +212 -22
- package/lib/main.mjs +5 -1
- package/lib/pr/close.mjs +25 -0
- package/lib/pr/comment.mjs +8 -3
- package/lib/pr/create.mjs +2 -0
- package/lib/pr/edit.mjs +53 -0
- package/lib/pr/queue.mjs +32 -0
- package/lib/pr/read.mjs +27 -2
- package/lib/pr/review.mjs +88 -0
- package/lib/pr/verdict.mjs +46 -0
- package/lib/pr/write.mjs +97 -3
- package/lib/receipt/list.mjs +54 -0
- package/lib/repo/identities.mjs +43 -0
- package/lib/repo/ssh.mjs +136 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,12 +14,16 @@ stamp identity bind --email agent@example.com
|
|
|
14
14
|
stamp repo clone org/repo
|
|
15
15
|
git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/my-change
|
|
16
16
|
stamp receipt get <id>
|
|
17
|
+
stamp receipt list
|
|
17
18
|
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
|
|
18
19
|
stamp pr list
|
|
19
20
|
stamp pr view 123 --repo org/repo
|
|
20
21
|
stamp pr diff 123 --repo org/repo
|
|
21
22
|
stamp pr checks 123 --repo org/repo
|
|
22
23
|
stamp pr comment 123 --repo org/repo --body-file ./comment.md
|
|
24
|
+
stamp pr edit 123 --repo org/repo --title "Clearer title" --body-file ./pr-body.md
|
|
25
|
+
stamp pr approve 123 --repo org/repo --head <exact-head-sha> --base <exact-base-sha>
|
|
26
|
+
stamp pr unapprove 123 --repo org/repo --head <exact-head-sha> --base <exact-base-sha>
|
|
23
27
|
```
|
|
24
28
|
|
|
25
29
|
- Agent: `stamp login` (PKCE grant via `raft integration invoke --action agent-login`)
|
|
@@ -37,8 +41,15 @@ Configuration layering is `environment > executable defaults`: `STAMP_URL` and
|
|
|
37
41
|
service command-line flags today.
|
|
38
42
|
|
|
39
43
|
`repo clone` carries the SSH identity itself (task #475): it uses the key
|
|
40
|
-
`key enroll`
|
|
41
|
-
|
|
44
|
+
`key enroll` enrolled. `key enroll` records the private key next to the public
|
|
45
|
+
key it read (the path without `.pub`), per instance, in `~/.stamp/identities.json`
|
|
46
|
+
(`STAMP_IDENTITIES` to relocate; nothing is recorded for a public key read from
|
|
47
|
+
stdin or one whose private half is not on this machine, and the command says so).
|
|
48
|
+
A bare `repo clone` then uses that record; `--identity FILE` and `STAMP_SSH_IDENTITY`
|
|
49
|
+
still win, and without a record the default `~/.ssh/id_ed25519` applies. The CLI
|
|
50
|
+
never scans `~/.ssh` or guesses paths: a recorded key that is not on this machine
|
|
51
|
+
is named, with `key enroll` here or `--identity` as the ways out (task #514). It
|
|
52
|
+
also pins the host key the instance publishes at `/.well-known/ssh-known-hosts` into
|
|
42
53
|
`~/.stamp/known_hosts` (`--known-hosts FILE` / `STAMP_KNOWN_HOSTS`), then records
|
|
43
54
|
the same command as the clone's `core.sshCommand` so later `git push`/`git fetch`
|
|
44
55
|
inherit it. No `GIT_SSH_COMMAND` export is needed.
|
|
@@ -72,6 +83,44 @@ reading through Stamp rather than a local GitHub credential:
|
|
|
72
83
|
- `--json` returns the service's validated machine envelope. Human-formatted
|
|
73
84
|
output strips terminal control characters from provider-authored text.
|
|
74
85
|
|
|
86
|
+
`stamp pr edit` changes the title, description, or both on a PR the current
|
|
87
|
+
Agent created through Stamp. Ownership comes from Stamp's durable creation
|
|
88
|
+
receipt, not the shared GitHub App author: another Agent, another Raft Server,
|
|
89
|
+
or a PR opened outside Stamp is refused before any provider write. Updating the
|
|
90
|
+
description regenerates the protected Stamp attribution/footer; callers supply
|
|
91
|
+
only their description text. If the provider outcome cannot be confirmed, the
|
|
92
|
+
command exits nonzero and requires a PR re-read before any retry.
|
|
93
|
+
|
|
94
|
+
### Approving as an Agent
|
|
95
|
+
|
|
96
|
+
With an Agent session, `stamp pr approve` records the approval **in Stamp** (a
|
|
97
|
+
durable receipt), not as a GitHub review: PRs opened through Stamp are authored
|
|
98
|
+
on GitHub by the shared App, so an App review would read as self-approval.
|
|
99
|
+
`--head` and `--base` must be the exact current SHAs (a move is refused with
|
|
100
|
+
`PR_HEAD_MOVED` / `PR_BASE_MOVED`), the approval counts only for that head, the
|
|
101
|
+
PR's own author is refused (`SELF_APPROVAL_NOT_ALLOWED`), and there is no
|
|
102
|
+
`--body`. `stamp pr unapprove` withdraws it. With a human session, `stamp pr
|
|
103
|
+
approve` submits a GitHub review as the bound user, as before.
|
|
104
|
+
|
|
105
|
+
### Merging as an Agent
|
|
106
|
+
|
|
107
|
+
With an Agent session, `stamp pr merge` works once there is an independent
|
|
108
|
+
approval of the PR's exact current head from someone other than its author
|
|
109
|
+
(another Agent's Stamp approval, or a GitHub approval from a human with write
|
|
110
|
+
access) and no outstanding request for changes; otherwise it is refused with
|
|
111
|
+
`PR_NOT_APPROVED` and the reasons. The author may merge too, once someone else
|
|
112
|
+
approved. `--head` and `--base` must be the exact current SHAs (`PR_HEAD_MOVED` /
|
|
113
|
+
`PR_BASE_MOVED`). The merge happens as the **Stamp App**, pinned to that head, so
|
|
114
|
+
GitHub refuses it if the head moved; GitHub's branch protection still applies.
|
|
115
|
+
The result names `mergedBy: "stamp-app"` and the merging Agent.
|
|
116
|
+
|
|
117
|
+
`stamp pr close` withdraws a PR the current Agent created through Stamp, under
|
|
118
|
+
the same receipt-ownership gate as `pr edit` — another Agent, another Raft
|
|
119
|
+
Server, or a PR opened outside Stamp is refused before any provider write, and
|
|
120
|
+
an already-closed or merged PR is reported as not open rather than as a silent
|
|
121
|
+
success. If the provider outcome cannot be confirmed, the command exits nonzero
|
|
122
|
+
and requires a PR re-read before any retry.
|
|
123
|
+
|
|
75
124
|
### Ordinary PR comments
|
|
76
125
|
|
|
77
126
|
`stamp pr comment 123 -R org/repo --body-file ./comment.md` uses a **human Stamp
|
|
@@ -103,3 +152,21 @@ remain available to service clients. `stamp migration-help` maps retired action
|
|
|
103
152
|
names to commands. The retirement follows the Stamp owner's explicit cutover
|
|
104
153
|
decision; the general Raft migration guide's optional compatibility period is
|
|
105
154
|
over for this service.
|
|
155
|
+
|
|
156
|
+
### Agent merge queue
|
|
157
|
+
|
|
158
|
+
Use `stamp pr queue enqueue <NUMBER -R OWNER/REPO|PR_URL> --request-id ID --head SHA --base SHA`
|
|
159
|
+
for an enabled native queue. Choose and save a 16–128 character request ID before
|
|
160
|
+
sending (letters/digits/underscore/hyphen, first character alphanumeric).
|
|
161
|
+
Independent approval of the current head is required; this accepts a request,
|
|
162
|
+
not a promise to merge. Use `stamp pr queue status ... --request-id ID --json`
|
|
163
|
+
to reconcile an uncertain reply, and `stamp pr queue withdraw ... --request-id ID`
|
|
164
|
+
to withdraw it. Reuse the same ID and coordinates; never create a new ID to retry
|
|
165
|
+
a lost response. Receipt reads/withdrawal are limited to the original agent and
|
|
166
|
+
server. Only requests still waiting can be withdrawn. Once a request enters a running
|
|
167
|
+
batch, withdrawal returns `QUEUE_BATCH_IN_FLIGHT` without canceling any member;
|
|
168
|
+
wait for completion and read the same request ID. Terminal receipts
|
|
169
|
+
retain verified landing SHA; `notificationQueued` is not delivery confirmation.
|
|
170
|
+
New admission requires the existing notification worker configured. This is a
|
|
171
|
+
source capability, not a claim that the deployment enables queues or delivery.
|
|
172
|
+
See [the queue contract](../docs/batch-merge-queue.md#agent-queue-requests).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { t } from "../locale.mjs";
|
|
2
|
+
|
|
3
|
+
// `stamp changelog [--limit N]`: the gateway's release history (one release
|
|
4
|
+
// per staging-v tag with the pull requests it carried), read from
|
|
5
|
+
// GET /changelog.json. The build block says which image answered; the running
|
|
6
|
+
// release is the one whose tag equals build.version (the same source commit
|
|
7
|
+
// can be cut as two tags, so the SHA cannot tell them apart).
|
|
8
|
+
//
|
|
9
|
+
// Audience: by default only entries whose `audience` includes "agent" (the
|
|
10
|
+
// CLI and the HTTP/SSH surface an agent drives) — artin: the human view and
|
|
11
|
+
// the agent view differ by content. `--all` shows everything; the JSON says
|
|
12
|
+
// which view it is (`view.audience`) so a reader never mistakes a filtered
|
|
13
|
+
// document for the whole history.
|
|
14
|
+
const AUDIENCE = "agent";
|
|
15
|
+
|
|
16
|
+
export function visibleEntries(entries, all) {
|
|
17
|
+
const list = Array.isArray(entries) ? entries : [];
|
|
18
|
+
if (all) return { entries: list, hidden: 0 };
|
|
19
|
+
const kept = list.filter((e) => Array.isArray(e?.audience) && e.audience.includes(AUDIENCE));
|
|
20
|
+
return { entries: kept, hidden: list.length - kept.length };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function run(ctx) {
|
|
24
|
+
let limit = Infinity;
|
|
25
|
+
let all = false;
|
|
26
|
+
const rest = [];
|
|
27
|
+
for (let i = 0; i < ctx.args.length; i++) {
|
|
28
|
+
const arg = ctx.args[i];
|
|
29
|
+
if (arg === "--limit") {
|
|
30
|
+
const value = Number(ctx.args[++i]);
|
|
31
|
+
if (!Number.isInteger(value) || value < 1) throw new Error(t(ctx.locale, "usageChangelog"));
|
|
32
|
+
limit = value;
|
|
33
|
+
} else if (arg === "--all") all = true;
|
|
34
|
+
else rest.push(arg);
|
|
35
|
+
}
|
|
36
|
+
if (rest.length) throw new Error(t(ctx.locale, "usageChangelog"));
|
|
37
|
+
const d = await ctx.api("GET", "/changelog.json");
|
|
38
|
+
const releases = (Array.isArray(d.releases) ? d.releases.slice(0, limit) : []).map((r) => {
|
|
39
|
+
const { entries, hidden } = visibleEntries(r.entries, all);
|
|
40
|
+
return { ...r, entries, hidden };
|
|
41
|
+
});
|
|
42
|
+
ctx.emit({ ...d, view: { audience: all ? "all" : AUDIENCE }, releases }, () => {
|
|
43
|
+
ctx.out(t(ctx.locale, "changelogBuild", { version: d.build?.version ?? "-", commit: String(d.build?.commit ?? "").slice(0, 8) || "-" }));
|
|
44
|
+
ctx.out(t(ctx.locale, all ? "changelogScopeAll" : "changelogScopeAgent"));
|
|
45
|
+
if (!releases.length) { ctx.out(t(ctx.locale, "changelogEmpty")); return; }
|
|
46
|
+
for (const r of releases) {
|
|
47
|
+
const current = r.tag && r.tag === d.build?.version ? ` ${t(ctx.locale, "changelogCurrentMark")}` : "";
|
|
48
|
+
ctx.out(`${r.tag} (${String(r.source ?? "").slice(0, 8)})${current}`);
|
|
49
|
+
if (!r.entries.length) {
|
|
50
|
+
ctx.out(` ${t(ctx.locale, r.hidden ? "changelogNoneForAgents" : "changelogNoEntries", { hidden: r.hidden })}`);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (const e of r.entries) ctx.out(` #${e.number} ${String(e.title ?? "").replace(/\s+/g, " ")}${e.author ? ` (${e.author})` : ""}`);
|
|
54
|
+
if (r.hidden) ctx.out(` ${t(ctx.locale, "changelogHiddenCount", { hidden: r.hidden })}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return ctx.exit(0);
|
|
58
|
+
}
|
package/lib/commands/key.mjs
CHANGED
|
@@ -2,10 +2,29 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { t } from "../locale.mjs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
5
6
|
import { takeFlag, readPublicKey } from "../flags.mjs";
|
|
7
|
+
import { recordIdentity } from "../repo/identities.mjs";
|
|
6
8
|
|
|
7
9
|
export async function run(ctx) {
|
|
8
10
|
const sub = ctx.args.shift();
|
|
11
|
+
if (sub === "list") {
|
|
12
|
+
if (ctx.args.length !== 0) throw new Error(t(ctx.locale, "usageKeyList"));
|
|
13
|
+
const d = await ctx.api("GET", "/v1/keys");
|
|
14
|
+
const items = Array.isArray(d?.items) ? d.items : [];
|
|
15
|
+
ctx.emit(d, () => {
|
|
16
|
+
if (items.length === 0) ctx.out(t(ctx.locale, "keyListEmpty"));
|
|
17
|
+
else for (const item of items) ctx.out(`${item.fingerprint}\t${item.keyId}`);
|
|
18
|
+
});
|
|
19
|
+
return ctx.exit(0);
|
|
20
|
+
}
|
|
21
|
+
if (sub === "revoke") {
|
|
22
|
+
const keyId = ctx.args.shift();
|
|
23
|
+
if (!keyId || ctx.args.length !== 0) throw new Error(t(ctx.locale, "usageKeyRevoke"));
|
|
24
|
+
const d = await ctx.api("DELETE", `/v1/keys/${encodeURIComponent(keyId)}`);
|
|
25
|
+
ctx.emit(d, () => ctx.out(t(ctx.locale, "keyRevoked", { keyId: d.keyId ?? keyId })));
|
|
26
|
+
return ctx.exit(0);
|
|
27
|
+
}
|
|
9
28
|
if (sub !== "enroll") throw new Error(t(ctx.locale, "usageKeyEnroll"));
|
|
10
29
|
const keyPath = takeFlag(ctx.args, "public-key", join(homedir(), ".ssh", "id_ed25519.pub"));
|
|
11
30
|
if (keyPath !== "-" && !existsSync(keyPath)) {
|
|
@@ -16,6 +35,24 @@ export async function run(ctx) {
|
|
|
16
35
|
}
|
|
17
36
|
const publicKey = readPublicKey(keyPath);
|
|
18
37
|
const d = await ctx.api("POST", "/v1/keys", { publicKey });
|
|
19
|
-
|
|
38
|
+
// Task #514: remember which private key this enrollment belongs to, for this
|
|
39
|
+
// instance, so a later `repo clone` uses it without --identity. The private
|
|
40
|
+
// half is the public path without `.pub` — the only derivation, no search.
|
|
41
|
+
// A public key from stdin, or one whose private half is not here, records
|
|
42
|
+
// nothing and says so.
|
|
43
|
+
let identity = null;
|
|
44
|
+
if (keyPath !== "-") {
|
|
45
|
+
const privatePath = resolve(keyPath.replace(/\.pub$/i, ""));
|
|
46
|
+
if (privatePath !== resolve(keyPath) && existsSync(privatePath)) {
|
|
47
|
+
identity = { identityPath: privatePath, fingerprint: d.fingerprint ?? null, keyId: d.keyId ?? null, enrolledAt: new Date().toISOString() };
|
|
48
|
+
recordIdentity(ctx.env, ctx.auth.apiBase, identity);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
ctx.emit({ ...d, identity }, () => {
|
|
52
|
+
ctx.out(t(ctx.locale, "enrolled", { fingerprint: d.fingerprint, keyId: d.keyId }));
|
|
53
|
+
ctx.out(identity
|
|
54
|
+
? t(ctx.locale, "enrolledIdentityRecorded", { path: identity.identityPath })
|
|
55
|
+
: t(ctx.locale, "enrolledIdentityNotRecorded", { path: keyPath === "-" ? "-" : resolve(keyPath.replace(/\.pub$/i, "")) }));
|
|
56
|
+
});
|
|
20
57
|
return ctx.exit(0);
|
|
21
58
|
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { t } from "../locale.mjs";
|
|
3
|
+
import { takeFlag } from "../flags.mjs";
|
|
4
|
+
import {
|
|
5
|
+
fetchPublishedKnownHosts,
|
|
6
|
+
knownHostsIsUsedBy,
|
|
7
|
+
probeRepoKnownHosts,
|
|
8
|
+
resolveIdentityPath,
|
|
9
|
+
resolveKnownHostsPath,
|
|
10
|
+
sshCommandFor,
|
|
11
|
+
writePinnedKnownHosts,
|
|
12
|
+
} from "../repo/ssh.mjs";
|
|
13
|
+
import { readRecordedIdentity } from "../repo/identities.mjs";
|
|
14
|
+
|
|
15
|
+
// The SSH fingerprint of a known_hosts line: base64(sha256(raw key)), which is
|
|
16
|
+
// what `ssh-keygen -lf` prints and what an announcement quotes. Printing it is
|
|
17
|
+
// the point of this command — an operator compares it to the published value
|
|
18
|
+
// rather than reading a base64 blob.
|
|
19
|
+
export function fingerprintOf(line) {
|
|
20
|
+
const base64 = line.trim().split(/\s+/)[2];
|
|
21
|
+
if (!base64) return null;
|
|
22
|
+
return `SHA256:${createHash("sha256").update(Buffer.from(base64, "base64")).digest("base64").replace(/=+$/, "")}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// `known-hosts refresh` exists because rotating the gateway's host key
|
|
26
|
+
// otherwise has no legitimate client-side route: the fetch-and-pin pair lived
|
|
27
|
+
// only inside `repo clone`, so an agent that already had a clone could either
|
|
28
|
+
// clone again or disable host key checking. The second is what people actually
|
|
29
|
+
// do, and after a host key leak it is the worst available outcome (#592).
|
|
30
|
+
//
|
|
31
|
+
// The write only happens after a usable line is in hand, so a failed fetch
|
|
32
|
+
// leaves known_hosts byte-for-byte unchanged: a refresh that damages the file
|
|
33
|
+
// when the network is down would be worse than having no command.
|
|
34
|
+
export async function run(ctx) {
|
|
35
|
+
const sub = ctx.args.shift();
|
|
36
|
+
if (sub !== "refresh") throw new Error(t(ctx.locale, "usageKnownHostsRefresh"));
|
|
37
|
+
const knownHostsFlag = takeFlag(ctx.args, "known-hosts", "");
|
|
38
|
+
if (ctx.args.length !== 0) throw new Error(t(ctx.locale, "usageKnownHostsRefresh"));
|
|
39
|
+
|
|
40
|
+
const knownHostsPath = resolveKnownHostsPath(ctx.env, knownHostsFlag);
|
|
41
|
+
const fetchImpl = ctx.opts.fetchImpl ?? fetch;
|
|
42
|
+
const url = `${ctx.auth.apiBase}/.well-known/ssh-known-hosts`;
|
|
43
|
+
const published = await fetchPublishedKnownHosts({ apiBase: ctx.auth.apiBase, fetchImpl });
|
|
44
|
+
if (!published.ok) {
|
|
45
|
+
throw new Error(t(ctx.locale, published.invalid ? "cloneKnownHostsInvalid" : "cloneKnownHostsUnavailable", {
|
|
46
|
+
url,
|
|
47
|
+
status: published.status ?? "?",
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
writePinnedKnownHosts(knownHostsPath, published.pattern, published.line);
|
|
51
|
+
const fingerprint = fingerprintOf(published.line);
|
|
52
|
+
|
|
53
|
+
// Writing the file is not the goal; the goal is that this repo's next push
|
|
54
|
+
// reads it. Those differ silently, and the difference only shows up on
|
|
55
|
+
// rotation day (#595), so the check belongs here rather than in a runbook.
|
|
56
|
+
//
|
|
57
|
+
// An explicit --known-hosts is exempt: it names one file on purpose, often a
|
|
58
|
+
// scratch one, and "this repo does not read it" is then a statement of the
|
|
59
|
+
// obvious that would break scripted use. STAMP_KNOWN_HOSTS is not exempt —
|
|
60
|
+
// that is where an agent says its canonical file lives, so it is exactly the
|
|
61
|
+
// case worth checking.
|
|
62
|
+
const probe = knownHostsFlag
|
|
63
|
+
// Skipped, not unknown-for-lack-of-a-repository. Carrying its own reason
|
|
64
|
+
// matters: the shared `{ known: false }` shape previously fell through to
|
|
65
|
+
// "not inside a git repository", which is a plain falsehood when the user
|
|
66
|
+
// ran this inside one (飞牛, reviewing #610).
|
|
67
|
+
? { known: false, skippedReason: "knownHostsUncheckedExplicitPath" }
|
|
68
|
+
: probeRepoKnownHosts({
|
|
69
|
+
cwd: ctx.opts.cwd ?? process.cwd(),
|
|
70
|
+
pattern: published.pattern,
|
|
71
|
+
execImpl: ctx.opts.sshProbeExec,
|
|
72
|
+
});
|
|
73
|
+
// Three states, not two. Treating "could not answer" as agreement was right
|
|
74
|
+
// about the exit code and wrong about the output: it made an unrunnable probe
|
|
75
|
+
// print exactly what success prints, so a reader who saw no complaint
|
|
76
|
+
// concluded their repository was aligned (#610, found by cross).
|
|
77
|
+
//
|
|
78
|
+
// That matters here more than anywhere: this command exists so nobody has to
|
|
79
|
+
// disable host key checking, and the person who runs it, sees a clean result
|
|
80
|
+
// and believes they are ready is precisely the person who cannot push on
|
|
81
|
+
// rotation day and reaches for StrictHostKeyChecking=no.
|
|
82
|
+
//
|
|
83
|
+
// The exit code still only distinguishes "misaligned" from everything else —
|
|
84
|
+
// that direction is unchanged, because a false failure sends a correctly
|
|
85
|
+
// configured agent looking for something to change.
|
|
86
|
+
const alignment = !probe.known
|
|
87
|
+
? "unknown"
|
|
88
|
+
: knownHostsIsUsedBy(probe.effective, knownHostsPath) ? "aligned" : "elsewhere";
|
|
89
|
+
|
|
90
|
+
ctx.emit({
|
|
91
|
+
path: knownHostsPath,
|
|
92
|
+
pattern: published.pattern,
|
|
93
|
+
fingerprint,
|
|
94
|
+
// Reported per repository, never per machine: one agent can have a
|
|
95
|
+
// configured clone and an unconfigured one side by side.
|
|
96
|
+
repoUsesThisFile: probe.known ? alignment === "aligned" : null,
|
|
97
|
+
repoEffectiveKnownHosts: probe.known ? probe.effective.raw : null,
|
|
98
|
+
}, () => {
|
|
99
|
+
ctx.out(t(ctx.locale, "knownHostsRefreshed", { path: knownHostsPath, pattern: published.pattern, fingerprint }));
|
|
100
|
+
if (alignment === "elsewhere") {
|
|
101
|
+
ctx.err(t(ctx.locale, probe.configured ? "knownHostsRepoElsewhere" : "knownHostsRepoUnconfigured", {
|
|
102
|
+
written: knownHostsPath,
|
|
103
|
+
effective: probe.effective.raw,
|
|
104
|
+
sshCommand: sshCommandFor({
|
|
105
|
+
// The key this instance enrolled (task #645, cross dogfooding #643):
|
|
106
|
+
// suggesting ~/.ssh/id_ed25519 to an agent that enrolled another key
|
|
107
|
+
// turns a host-key fix into a publickey denial. Same order as
|
|
108
|
+
// `repo clone`: STAMP_SSH_IDENTITY, then the recorded key, then the
|
|
109
|
+
// default path.
|
|
110
|
+
identityPath: resolveIdentityPath(ctx.env, "", readRecordedIdentity(ctx.env, ctx.auth?.apiBase)),
|
|
111
|
+
knownHostsPath,
|
|
112
|
+
}),
|
|
113
|
+
}));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (alignment === "unknown") {
|
|
117
|
+
// Says which check did not happen, not just that something is unknown:
|
|
118
|
+
// "could not confirm" with no reason reads as a glitch and gets ignored.
|
|
119
|
+
ctx.out(t(ctx.locale, "knownHostsRepoUnchecked", {
|
|
120
|
+
written: knownHostsPath,
|
|
121
|
+
// Explicit skip first: it is the only case that knows why on its own.
|
|
122
|
+
// The other two are distinguished by whether we got far enough to ask
|
|
123
|
+
// the repository anything at all.
|
|
124
|
+
reason: t(ctx.locale, probe.skippedReason
|
|
125
|
+
?? (probe.inRepo ? "knownHostsUncheckedProbe" : "knownHostsUncheckedNoRepo")),
|
|
126
|
+
}));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Aligned — and the caveat rides here too. It was already written, but only
|
|
130
|
+
// in the unconfigured branch, which is the one branch a correctly set up
|
|
131
|
+
// reader never reaches (#610). Same error as #607: the qualifier existed
|
|
132
|
+
// somewhere other than where the reader stops.
|
|
133
|
+
ctx.out(t(ctx.locale, "knownHostsRepoAligned", { effective: probe.effective.raw }));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// A repo that reads somewhere else did not get refreshed, whatever the exit
|
|
137
|
+
// code of the write says. Silence here is what lets someone believe they are
|
|
138
|
+
// ready for the rotation.
|
|
139
|
+
//
|
|
140
|
+
// Every other outcome exits 0, including a probe that could not run: this
|
|
141
|
+
// command exists to stop people from disabling host key checking, so telling
|
|
142
|
+
// a correctly configured agent that it has a problem is the worse error. It
|
|
143
|
+
// also cannot see a per-invocation GIT_SSH_COMMAND at all, which the
|
|
144
|
+
// unconfigured message says outright rather than implying coverage.
|
|
145
|
+
// Only "elsewhere" is a failure. "unknown" stays 0 deliberately: the check
|
|
146
|
+
// could not run, and turning that into a non-zero exit would send a correctly
|
|
147
|
+
// configured agent hunting for a problem — the direction this command must
|
|
148
|
+
// never fail in. The distinction now lives in the output instead of vanishing.
|
|
149
|
+
return ctx.exit(alignment === "elsewhere" ? 1 : 0);
|
|
150
|
+
}
|
package/lib/commands/pr.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { formatAutoMerge, isAutoMergeArgs, parsePRAutoMergeArgs, validatePRAutoMergeResult } from "../pr/write.mjs";
|
|
2
|
+
import { formatVerdictLine } from "../pr/verdict.mjs";
|
|
3
|
+
import { parsePRQueueArgs, validatePRQueueResult } from "../pr/queue.mjs";
|
|
1
4
|
import { t, prefix } from "../locale.mjs";
|
|
2
5
|
import { ApiError, NetworkError } from "../client.mjs";
|
|
3
6
|
import { AgentError, printGatewayError } from "../errors.mjs";
|
|
4
7
|
import { pullRequestInput, pullRequestRecovery } from "../pr/create.mjs";
|
|
5
8
|
import { parsePRCommentArgs, validatePRCommentResult } from "../pr/comment.mjs";
|
|
6
|
-
import {
|
|
9
|
+
import { parsePREditArgs, validatePREditResult } from "../pr/edit.mjs";
|
|
10
|
+
import { parsePRCloseArgs, validatePRCloseResult } from "../pr/close.mjs";
|
|
11
|
+
import { formatPRReview, reviewBrief } from "../pr/review.mjs";
|
|
12
|
+
import { parsePRApproveArgs, parsePRMergeArgs, parsePRUnapproveArgs, validatePRApproveResult, validatePRMergeResult, validatePRUnapproveResult } from "../pr/write.mjs";
|
|
7
13
|
import {
|
|
8
14
|
formatPRChecks,
|
|
9
15
|
formatPRDetail,
|
|
@@ -57,6 +63,14 @@ async function writeCommand(ctx, run) {
|
|
|
57
63
|
export async function run(ctx) {
|
|
58
64
|
const { args, api, emit, out, err, locale, exit } = ctx;
|
|
59
65
|
const sub = args.shift();
|
|
66
|
+
if (sub === "queue") {
|
|
67
|
+
ctx.unknownKey = "prQueueOutcomeUnknown";
|
|
68
|
+
return writeCommand(ctx, async () => {
|
|
69
|
+
const input = parsePRQueueArgs(args);
|
|
70
|
+
const result = validatePRQueueResult(await api(input.method, input.path, input.body), input);
|
|
71
|
+
emit(result, () => out(t(locale, "prQueueReceipt", { repository: result.repository, number: result.number, id: result.requestId, state: result.receipt.state, reason: result.receipt.reason || "—", landing: result.receipt.landingSha || "—", queued: String(result.receipt.notificationQueued) })));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
60
74
|
if (sub === "comment") {
|
|
61
75
|
ctx.rejectKey = "prCommentRejected";
|
|
62
76
|
ctx.unknownKey = "prCommentOutcomeUnknown";
|
|
@@ -72,7 +86,27 @@ export async function run(ctx) {
|
|
|
72
86
|
return writeCommand(ctx, async () => {
|
|
73
87
|
const input = parsePRApproveArgs(args);
|
|
74
88
|
const result = validatePRApproveResult(await api(input.method, input.path, input.body), input.target);
|
|
75
|
-
emit(result, () => out(
|
|
89
|
+
emit(result, () => out(result.recordedBy === "stamp"
|
|
90
|
+
? t(locale, "prApprovedByStamp", { actor: result.reviewer, repository: result.repository, number: result.number, head: result.approvedHead })
|
|
91
|
+
: t(locale, "prApproved", { actor: result.reviewerLogin, repository: result.repository, number: result.number })));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (sub === "unapprove") {
|
|
95
|
+
ctx.rejectKey = "prUnapproveRejected";
|
|
96
|
+
ctx.unknownKey = "prUnapproveOutcomeUnknown";
|
|
97
|
+
return writeCommand(ctx, async () => {
|
|
98
|
+
const input = parsePRUnapproveArgs(args);
|
|
99
|
+
const result = validatePRUnapproveResult(await api(input.method, input.path, input.body), input.target);
|
|
100
|
+
emit(result, () => out(t(locale, "prUnapproved", { actor: result.reviewer, repository: result.repository, number: result.number, head: result.approvedHead })));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (sub === "merge" && isAutoMergeArgs(args)) {
|
|
104
|
+
ctx.rejectKey = "prMergeRejected";
|
|
105
|
+
ctx.unknownKey = "prMergeOutcomeUnknown";
|
|
106
|
+
return writeCommand(ctx, async () => {
|
|
107
|
+
const input = parsePRAutoMergeArgs(args);
|
|
108
|
+
const result = validatePRAutoMergeResult(await api(input.method, input.path, input.body), input.target);
|
|
109
|
+
emit(result, () => out(formatAutoMerge(result, (key, vars) => t(locale, key, vars))));
|
|
76
110
|
});
|
|
77
111
|
}
|
|
78
112
|
if (sub === "merge") {
|
|
@@ -81,7 +115,27 @@ export async function run(ctx) {
|
|
|
81
115
|
return writeCommand(ctx, async () => {
|
|
82
116
|
const input = parsePRMergeArgs(args);
|
|
83
117
|
const result = validatePRMergeResult(await api(input.method, input.path, input.body), input.target);
|
|
84
|
-
emit(result, () => out(
|
|
118
|
+
emit(result, () => out(result.mergedBy === "stamp-app"
|
|
119
|
+
? t(locale, "prMergedByApp", { actor: result.agent, sha: result.mergeSha, repository: result.repository, number: result.number, head: result.mergedHead })
|
|
120
|
+
: t(locale, "prMerged", { actor: result.actorLogin, sha: result.mergeSha, repository: result.repository, number: result.number })));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (sub === "close") {
|
|
124
|
+
ctx.rejectKey = "prCloseRejected";
|
|
125
|
+
ctx.unknownKey = "prCloseOutcomeUnknown";
|
|
126
|
+
return writeCommand(ctx, async () => {
|
|
127
|
+
const input = parsePRCloseArgs(args);
|
|
128
|
+
const result = validatePRCloseResult(await api(input.method, input.path), input.target);
|
|
129
|
+
emit(result, () => out(t(locale, "prClosed", { repository: result.repository, number: result.number, url: result.url })));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (sub === "edit") {
|
|
133
|
+
ctx.rejectKey = "prEditRejected";
|
|
134
|
+
ctx.unknownKey = "prEditOutcomeUnknown";
|
|
135
|
+
return writeCommand(ctx, async () => {
|
|
136
|
+
const input = parsePREditArgs(args);
|
|
137
|
+
const result = validatePREditResult(await api("PATCH", input.path, input.body), input.target);
|
|
138
|
+
emit(result, () => out(t(locale, "prEdited", { repository: result.repository, number: result.number, url: result.url })));
|
|
85
139
|
});
|
|
86
140
|
}
|
|
87
141
|
if (sub === "create") {
|
|
@@ -127,13 +181,32 @@ export async function run(ctx) {
|
|
|
127
181
|
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
128
182
|
emit(d, () => {
|
|
129
183
|
for (const line of formatPRDetail(d, {
|
|
184
|
+
verdictLine: d.verdict ? formatVerdictLine(d.verdict, (key) => t(locale, key)) : "",
|
|
130
185
|
head: t(locale, "prHeadLabel"),
|
|
131
186
|
checks: t(locale, "prChecksLabel"),
|
|
187
|
+
ciUnreadable: t(locale, "prCIUnreadable"),
|
|
132
188
|
review: t(locale, "prReviewLabel"),
|
|
133
189
|
})) out(line);
|
|
134
190
|
});
|
|
135
191
|
return exit(0);
|
|
136
192
|
}
|
|
193
|
+
if (sub === "review") {
|
|
194
|
+
const target = parsePRTargetArgs(args, "usagePrReview");
|
|
195
|
+
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
196
|
+
const brief = reviewBrief(d);
|
|
197
|
+
emit(brief, () => {
|
|
198
|
+
for (const line of formatPRReview(brief, (key) => t(locale, key))) out(line);
|
|
199
|
+
});
|
|
200
|
+
// Stays exit 0 even when the CI rollup is unreadable, and that is a
|
|
201
|
+
// decision rather than an omission (飞牛 raised it). `pr checks` is a gate
|
|
202
|
+
// answering "is this green?", so it fails closed; `pr review` is a fetch
|
|
203
|
+
// answering "give me the brief", and the fetch succeeded. Failing it here
|
|
204
|
+
// would conflate "I could not build the brief" with "the brief says CI is
|
|
205
|
+
// unknown", and would break callers that use it to obtain a brief at all.
|
|
206
|
+
// The unreadability travels in the brief itself -- printed in the text and
|
|
207
|
+
// carried as `ciUnreadable` in --json, which is purely additive.
|
|
208
|
+
return exit(0);
|
|
209
|
+
}
|
|
137
210
|
if (sub === "diff") {
|
|
138
211
|
const target = parsePRDiffArgs(args);
|
|
139
212
|
const d = validatePRDiff(await api("GET", prDiffPath(target)), target);
|
|
@@ -148,8 +221,20 @@ export async function run(ctx) {
|
|
|
148
221
|
const target = parsePRTargetArgs(args, "usagePrChecks");
|
|
149
222
|
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
150
223
|
emit(d.checks, () => {
|
|
224
|
+
// BOUNDARY, deliberately not fixed here: `--json` emits the checks ARRAY,
|
|
225
|
+
// which has nowhere to put "the source was refused" -- an agent parsing
|
|
226
|
+
// stdout sees `[]` for both "no CI" and "could not read CI". Widening it
|
|
227
|
+
// to an object would break every agent that parses an array, which is the
|
|
228
|
+
// same compatibility trap as adding a ciStatus value, so the contract is:
|
|
229
|
+
// **the exit code is authoritative for --json callers, and `pr view
|
|
230
|
+
// --json` carries ciUnreadable if you need the reason.** Said out loud
|
|
231
|
+
// rather than left for the next person to discover (飞牛, cross).
|
|
151
232
|
const lines = formatPRChecks(d);
|
|
152
|
-
|
|
233
|
+
// "No checks reported." is the same lie as CI:none, just where a person
|
|
234
|
+
// reads it rather than in a column. An empty list because the source was
|
|
235
|
+
// refused must not borrow the sentence meant for a repo that has no CI.
|
|
236
|
+
if (d.ciUnreadable) out(t(locale, "prChecksUnreadable"));
|
|
237
|
+
else if (lines.length === 0) out(t(locale, "prChecksEmpty"));
|
|
153
238
|
else for (const line of lines) out(line);
|
|
154
239
|
});
|
|
155
240
|
return exit(prChecksExitCode(d));
|
package/lib/commands/receipt.mjs
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
import { t } from "../locale.mjs";
|
|
2
|
+
import { formatReceiptLine, parseReceiptListArgs, validateReceiptList } from "../receipt/list.mjs";
|
|
2
3
|
|
|
3
4
|
export async function run(ctx) {
|
|
4
5
|
const sub = ctx.args.shift();
|
|
6
|
+
if (sub === "list") {
|
|
7
|
+
const { path } = parseReceiptListArgs(ctx.args);
|
|
8
|
+
const d = validateReceiptList(await ctx.api("GET", path));
|
|
9
|
+
ctx.emit(d, () => {
|
|
10
|
+
if (d.items.length === 0) {
|
|
11
|
+
ctx.out(t(ctx.locale, "receiptListEmpty"));
|
|
12
|
+
} else {
|
|
13
|
+
for (const item of d.items) {
|
|
14
|
+
ctx.out(formatReceiptLine(item));
|
|
15
|
+
if (item.lastError) ctx.out(` last error: ${item.lastError}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (d.nextCursor) ctx.out(t(ctx.locale, "receiptListMore", { cursor: d.nextCursor }));
|
|
19
|
+
});
|
|
20
|
+
return ctx.exit(0);
|
|
21
|
+
}
|
|
5
22
|
const id = ctx.args.shift();
|
|
6
23
|
if (sub !== "get" || !id) throw new Error(t(ctx.locale, "usageReceiptGet"));
|
|
7
24
|
const d = await ctx.api("GET", `/v1/receipts/${encodeURIComponent(id)}`);
|
|
8
|
-
ctx.emit(d, () =>
|
|
25
|
+
ctx.emit(d, () => {
|
|
26
|
+
let line = `${d.id} ${d.status} ${d.repository} ${d.targetRef} published=${d.publishedSha ?? "-"}`;
|
|
27
|
+
if (d.publishAttempts) line += ` attempts=${d.publishAttempts}`;
|
|
28
|
+
if (d.nextRetryAt) line += ` nextRetry=${d.nextRetryAt}`;
|
|
29
|
+
ctx.out(line);
|
|
30
|
+
if (d.lastError) ctx.out(` last error: ${d.lastError}`);
|
|
31
|
+
});
|
|
9
32
|
return ctx.exit(0);
|
|
10
33
|
}
|
package/lib/commands/repo.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { t } from "../locale.mjs";
|
|
3
3
|
import { takeFlag } from "../flags.mjs";
|
|
4
4
|
import { gatewayCloneURL, parseRepoCloneArgs, parseRepository, runGitClone, runGitSetSSHCommand } from "../repo/clone.mjs";
|
|
5
|
-
import { fetchPublishedKnownHosts,
|
|
5
|
+
import { fetchPublishedKnownHosts, resolveIdentity, resolveKnownHostsPath, sshCommandFor, writePinnedKnownHosts } from "../repo/ssh.mjs";
|
|
6
|
+
import { readRecordedIdentity } from "../repo/identities.mjs";
|
|
6
7
|
|
|
7
8
|
export async function run(ctx) {
|
|
8
9
|
if (ctx.args.shift() !== "clone") throw new Error(t(ctx.locale, "usageRepoClone"));
|
|
@@ -18,9 +19,13 @@ export async function run(ctx) {
|
|
|
18
19
|
// The clone carries the enrolled identity and the gateway's published host
|
|
19
20
|
// key itself (task #475): a bare clone must not fail with publickey, and it
|
|
20
21
|
// must not need a hand-exported GIT_SSH_COMMAND.
|
|
21
|
-
const
|
|
22
|
+
const recorded = readRecordedIdentity(ctx.env, ctx.auth.apiBase);
|
|
23
|
+
const { identityPath, source } = resolveIdentity(ctx.env, identityFlag, recorded);
|
|
22
24
|
if (!existsSync(identityPath)) {
|
|
23
|
-
|
|
25
|
+
// The recorded key is not on this machine (or moved): say which record
|
|
26
|
+
// pointed there, so the fix is `key enroll` here or --identity, not a
|
|
27
|
+
// search of ~/.ssh (task #514: never scan).
|
|
28
|
+
throw new Error(t(ctx.locale, source === "enrolled" ? "cloneEnrolledIdentityMissing" : "cloneIdentityMissing", { path: identityPath, origin: ctx.auth.apiBase }));
|
|
24
29
|
}
|
|
25
30
|
const knownHostsPath = resolveKnownHostsPath(ctx.env, knownHostsFlag);
|
|
26
31
|
const fetchImpl = ctx.opts.fetchImpl ?? fetch;
|
|
@@ -54,9 +59,16 @@ export async function run(ctx) {
|
|
|
54
59
|
const directory = parsed.directory ?? repo.name;
|
|
55
60
|
const pinned = await (ctx.opts.gitConfigImpl ?? runGitSetSSHCommand)({ directory, sshCommand });
|
|
56
61
|
ctx.emit(
|
|
57
|
-
{ ok: true, repository: `${repo.owner}/${repo.name}`, url, directory, sshIdentity: identityPath, sshPinned: pinned.ok },
|
|
62
|
+
{ ok: true, repository: `${repo.owner}/${repo.name}`, url, directory, sshIdentity: identityPath, sshIdentitySource: source, sshPinned: pinned.ok },
|
|
58
63
|
() => {
|
|
59
64
|
ctx.out(t(ctx.locale, "cloned", { repository: `${repo.owner}/${repo.name}`, url }));
|
|
65
|
+
// The commit rules this gateway enforces, stated once up front (task #549):
|
|
66
|
+
// a pusher should not meet them for the first time as a refusal.
|
|
67
|
+
if (me.commitTrailers && (me.commitTrailers.signedOffBy || me.commitTrailers.coauthoredBy)) {
|
|
68
|
+
ctx.out(t(ctx.locale, "cloneCommitTrailers"));
|
|
69
|
+
if (me.commitTrailers.signedOffBy) ctx.out(` ${me.commitTrailers.signedOffBy}`);
|
|
70
|
+
if (me.commitTrailers.coauthoredBy) ctx.out(` ${me.commitTrailers.coauthoredBy}`);
|
|
71
|
+
}
|
|
60
72
|
ctx.out(pinned.ok
|
|
61
73
|
? t(ctx.locale, "cloneIdentityPinned", { directory })
|
|
62
74
|
: t(ctx.locale, "cloneIdentityPinFailed", { directory, command: sshCommand }));
|