@veda-hq/niyam 0.6.25 → 0.7.0
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 +49 -17
- package/dist/agent.js +36 -4
- package/dist/cloud-key.js +23 -10
- package/dist/cloud.js +16 -31
- package/dist/onboard.js +35 -4
- package/dist/pr-autocreate.js +48 -0
- package/dist/session-start.js +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -446,14 +446,18 @@ on any platform without a token store, `niyam env` prints the lock alone.
|
|
|
446
446
|
GitHub as the agent, once per claude.ai account. When the agent has no
|
|
447
447
|
signing key on GitHub titled `niyam cloud signing`, the plan's Claude
|
|
448
448
|
cloud group also lists one, "signing key for AGENT, on the clipboard":
|
|
449
|
-
as its last step, after the pull request opens, `onboard`
|
|
449
|
+
as its last step, after the pull request opens, `onboard` registers it as
|
|
450
450
|
`niyam cloud-key` does (below), and "By hand:" starts with the paste
|
|
451
|
-
into each cloud environment's variables.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
451
|
+
into each cloud environment's variables. It makes the key in memory when
|
|
452
|
+
it plans, so the pull request's `.github/niyam.json` pins the key's
|
|
453
|
+
public half among the agent's cloud signing keys, which cloud sessions
|
|
454
|
+
check theirs against (see Claude cloud sessions below). The key is the
|
|
455
|
+
agent's, not the repository's, so onboarding a second repository finds
|
|
456
|
+
it, pins it there and makes none. A key that fails only warns, leaving
|
|
457
|
+
the pull request and every step before it in place; no environment holds
|
|
458
|
+
the key it pins. "By hand:" then names `niyam cloud-key <agent>` and
|
|
459
|
+
another `onboard` run instead; so does a run where `cloud-key` would
|
|
460
|
+
refuse, in a Claude Code or cloud session. A dry run plans no key. Where the
|
|
457
461
|
repo still has `.github/process-rules/cloud-setup.sh`, which releases up
|
|
458
462
|
to 0.6.10 wrote beside it, the pull request deletes it, but only where it
|
|
459
463
|
leaves `.github/niyam/cloud-setup.sh` (one the run could not write, as
|
|
@@ -977,7 +981,11 @@ repeats that call at every `wrap_up` until the app confirms Auto-fix. The
|
|
|
977
981
|
ToolSearch step, the `<pr-created>` tag and `bind_pr` stay: without them the
|
|
978
982
|
app refuses `set_monitor` for a pull request a hook opened. When the row
|
|
979
983
|
cannot be written, or the session id cannot name a list, the whole
|
|
980
|
-
instruction goes out.
|
|
984
|
+
instruction goes out. With `"autofixList": true`, a pull request whose latest
|
|
985
|
+
state on the list is `on` (folded as sarathi does: `warned` rows skipped,
|
|
986
|
+
`opened` only adding the pull request) gets no instruction at all, and no
|
|
987
|
+
ack, so an `off` later is told at a later Stop. `opened`, `refused`, `off`,
|
|
988
|
+
or a list that cannot be read, gets the instruction as above.
|
|
981
989
|
|
|
982
990
|
**Started work runs to merge.** `niyam keep-going`, Claude Code's Stop hook,
|
|
983
991
|
sends a session back while its branch has commits the base lacks and its
|
|
@@ -1371,7 +1379,7 @@ address and signed with that key.
|
|
|
1371
1379
|
Once `session-start` confirms the login as the agent, it does four things:
|
|
1372
1380
|
|
|
1373
1381
|
- reads the account's id from the same GitHub answer;
|
|
1374
|
-
- writes the key to the agent's key file (`~/.ssh/<agent>_signing`, mode 0600)
|
|
1382
|
+
- checks its public half is one of the agent's cloud signing keys the repo's `.github/niyam.json` pins, then writes the key to the agent's key file (`~/.ssh/<agent>_signing`, mode 0600);
|
|
1375
1383
|
- makes a probe commit object, on no branch, with exactly the settings the session will get;
|
|
1376
1384
|
- checks that its signature verifies as that key's.
|
|
1377
1385
|
|
|
@@ -1386,20 +1394,43 @@ makes. `niyam ssh-sign` only signs, so `git log --show-signature` in the
|
|
|
1386
1394
|
session cannot check signatures; GitHub does. It also unsets the key's
|
|
1387
1395
|
variable there, so commands do not carry it in their environment.
|
|
1388
1396
|
|
|
1397
|
+
**The pin.** A cloud session cannot ask GitHub which signing keys the agent
|
|
1398
|
+
has: the proxy refuses every `users/…` path, and the session's API calls
|
|
1399
|
+
can reach only the repositories attached to it (veda-hq/niyam#447). So
|
|
1400
|
+
`onboard`, run on your Mac, asks GitHub instead. It writes the agent's
|
|
1401
|
+
cloud signing keys, those titled `niyam cloud signing`, into the settings
|
|
1402
|
+
as `"cloudSigningKeys"`, by agent, without their comments:
|
|
1403
|
+
|
|
1404
|
+
```json
|
|
1405
|
+
{ "owner": "example-owner", "agent": "ExampleBot",
|
|
1406
|
+
"cloudSigningKeys": { "ExampleBot": ["ssh-ed25519 AAAA…"] } }
|
|
1407
|
+
```
|
|
1408
|
+
|
|
1409
|
+
`session-start` checks the session's key against that list. Each
|
|
1410
|
+
`onboard` run writes it again from GitHub's list, so a key made or deleted
|
|
1411
|
+
since then needs an `onboard` run in each repository the agent works in.
|
|
1412
|
+
The plan names the change ("pin AGENT's cloud signing key"), and a run
|
|
1413
|
+
whose list GitHub does not give leaves the pin as it is. A key the pin
|
|
1414
|
+
still names after it was deleted from GitHub is caught only after the
|
|
1415
|
+
push: its commits fail PR identity until `onboard` runs again.
|
|
1416
|
+
|
|
1389
1417
|
When any step fails, nothing is set and the commits stay Claude's, which PR
|
|
1390
1418
|
identity passes. Steps that can fail: no key, one that is not an OpenSSH
|
|
1391
|
-
private key or not an ed25519 one with no passphrase,
|
|
1392
|
-
|
|
1419
|
+
private key or not an ed25519 one with no passphrase, settings that pin no
|
|
1420
|
+
cloud signing key for the agent, a key they do not pin, or a probe that
|
|
1421
|
+
does not verify. The
|
|
1393
1422
|
session's line says why and the session works on as the agent. A commit
|
|
1394
1423
|
claiming the agent without the agent's signature would fail PR identity, so
|
|
1395
1424
|
it is all or nothing. Nothing is installed: signing needs no `ssh-keygen`, no
|
|
1396
1425
|
network and no root, so no Setup script line either.
|
|
1397
1426
|
|
|
1398
1427
|
`niyam onboard` makes the key the first time it runs for an agent that has
|
|
1399
|
-
none (see Adopting above),
|
|
1400
|
-
yourself, as when the line was lost, run
|
|
1401
|
-
terminal on the Mac `niyam machine`
|
|
1402
|
-
|
|
1428
|
+
none (see Adopting above), and its pull request pins it, so all that is
|
|
1429
|
+
left is the paste. To make one yourself, as when the line was lost, run
|
|
1430
|
+
`niyam cloud-key [agent]` in your own terminal on the Mac `niyam machine`
|
|
1431
|
+
set up for the agent (`--yes` skips its one question), then `niyam onboard`
|
|
1432
|
+
in each repository the agent works in, which pins it; `cloud-key` says so.
|
|
1433
|
+
One line serves every cloud environment the agent works in.
|
|
1403
1434
|
`onboard` and `cloud-key` make the key alike, in three steps:
|
|
1404
1435
|
|
|
1405
1436
|
- makes a new ed25519 key in memory, with niyam's own code rather than `ssh-keygen`, never writing it to disk; it is for the agent's cloud sessions alone, apart from the Mac's signing key, so it can be revoked on its own;
|
|
@@ -1424,7 +1455,8 @@ command its sessions run. Claude's settings warn against keeping secrets
|
|
|
1424
1455
|
there. Whoever holds the key can sign commits that GitHub shows as Verified
|
|
1425
1456
|
for the agent, though pushing still needs the agent's GitHub connection,
|
|
1426
1457
|
which PR identity checks. To revoke the key, delete it from the agent's
|
|
1427
|
-
signing keys
|
|
1458
|
+
signing keys, then run `niyam onboard` in each repository, which drops it
|
|
1459
|
+
from the pin.
|
|
1428
1460
|
|
|
1429
1461
|
**Trailers and hooks.** The cloud image's git config sets Claude's identity
|
|
1430
1462
|
and signing and nothing else: no `core.hooksPath`, no hooks, no trailers.
|
|
@@ -1620,7 +1652,7 @@ tag and the commit. Install the attached package on each machine with pnpm,
|
|
|
1620
1652
|
once; nothing is built on install:
|
|
1621
1653
|
|
|
1622
1654
|
```bash
|
|
1623
|
-
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.
|
|
1655
|
+
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.0/veda-hq-niyam-0.7.0.tgz
|
|
1624
1656
|
```
|
|
1625
1657
|
|
|
1626
1658
|
The package puts one command on `PATH`, `niyam`. Since P-57 a release
|
package/dist/agent.js
CHANGED
|
@@ -49,14 +49,25 @@ export function anyLogin(logins, login) {
|
|
|
49
49
|
export function either(logins) {
|
|
50
50
|
return logins.length < 2 ? (logins[0] ?? '') : `${logins.slice(0, -1).join(', ')} or ${logins.at(-1)}`;
|
|
51
51
|
}
|
|
52
|
+
/** The settings' key for each agent's pinned cloud signing keys. */
|
|
53
|
+
export const CLOUD_SIGNING_KEYS = 'cloudSigningKeys';
|
|
54
|
+
/** The cloud signing keys `settings` pin for `login`, any case; none when they pin none. */
|
|
55
|
+
export function pinnedCloudKeys(settings, login) {
|
|
56
|
+
const pins = settings.cloudSigningKeys ?? {};
|
|
57
|
+
return Object.entries(pins).find(([agent]) => sameLogin(login, agent))?.[1] ?? [];
|
|
58
|
+
}
|
|
52
59
|
/** Reads and checks the settings file at `root`; throws with the reason. */
|
|
53
60
|
export function loadSettings(sys, root) {
|
|
54
|
-
const
|
|
55
|
-
const path = `${root}/${name}`;
|
|
61
|
+
const path = `${root}/${SETTINGS_PATH}`;
|
|
56
62
|
if (!sys.exists(path)) {
|
|
57
63
|
throw new Error(`${SETTINGS_PATH} not found in ${root}`);
|
|
58
64
|
}
|
|
59
|
-
|
|
65
|
+
return settingsIn(sys.read(path));
|
|
66
|
+
}
|
|
67
|
+
/** Reads and checks the settings file's text, `text`; throws with the reason. */
|
|
68
|
+
export function settingsIn(text) {
|
|
69
|
+
const name = SETTINGS_PATH;
|
|
70
|
+
const raw = JSON.parse(text);
|
|
60
71
|
const owners = logins(raw, 'owner', name);
|
|
61
72
|
const agents = logins(raw, 'agent', name);
|
|
62
73
|
const both = owners.find((owner) => anyLogin(agents, owner));
|
|
@@ -64,7 +75,28 @@ export function loadSettings(sys, root) {
|
|
|
64
75
|
throw new Error(`${name}: ${both} is named as both owner and agent; they must be different accounts`);
|
|
65
76
|
}
|
|
66
77
|
const approvals = approvalsIn(raw, name);
|
|
67
|
-
|
|
78
|
+
const cloudSigningKeys = cloudSigningKeysIn(raw, name);
|
|
79
|
+
return { owners, agents, ...(approvals === undefined ? {} : { approvals }), ...(cloudSigningKeys === undefined ? {} : { cloudSigningKeys }) };
|
|
80
|
+
}
|
|
81
|
+
/** An OpenSSH public key as "type body", as `onboard` pins one. */
|
|
82
|
+
const PUBLIC_KEY = /^(?:ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(?:256|384|521)|sk-ssh-ed25519@openssh\.com|sk-ecdsa-sha2-nistp256@openssh\.com) [A-Za-z0-9+/]+={0,2}$/;
|
|
83
|
+
/** The cloud signing keys the settings pin, by agent, or undefined when they pin none; anything else is refused. */
|
|
84
|
+
function cloudSigningKeysIn(raw, file) {
|
|
85
|
+
const value = typeof raw === 'object' && raw !== null ? raw[CLOUD_SIGNING_KEYS] : undefined;
|
|
86
|
+
if (value === undefined)
|
|
87
|
+
return undefined;
|
|
88
|
+
const refused = `${file}: "${CLOUD_SIGNING_KEYS}" must map each agent's login to a list of OpenSSH public keys, "type body", as niyam onboard writes it`;
|
|
89
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
90
|
+
throw new Error(refused);
|
|
91
|
+
const entries = Object.entries(value);
|
|
92
|
+
if (!entries.every(([login, keys]) => LOGIN.test(login) && Array.isArray(keys) && keys.every((key) => typeof key === 'string' && PUBLIC_KEY.test(key)))) {
|
|
93
|
+
throw new Error(refused);
|
|
94
|
+
}
|
|
95
|
+
// Logins are case-insensitive: one agent named twice would leave which pin counts to the file's order.
|
|
96
|
+
const twice = entries.find(([login], i) => entries.findIndex(([other]) => sameLogin(login, other)) !== i);
|
|
97
|
+
if (twice)
|
|
98
|
+
throw new Error(`${file}: "${CLOUD_SIGNING_KEYS}" names ${twice[0]} twice, in any case; keep one entry for each agent`);
|
|
99
|
+
return Object.fromEntries(entries);
|
|
68
100
|
}
|
|
69
101
|
/** The Approvals issue the settings name as `"approvals": N`, or undefined when they name none; anything but an issue number is refused. */
|
|
70
102
|
function approvalsIn(raw, file) {
|
package/dist/cloud-key.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { API, account, agentFrom, checkToken, keyBody, signingKeys, tokenInfo } from './agent.js';
|
|
1
|
+
import { API, SETTINGS_PATH, account, agentFrom, checkToken, keyBody, signingKeys, tokenInfo } from './agent.js';
|
|
2
2
|
import { SIGNING_KEY_VAR } from './cloud.js';
|
|
3
3
|
import { CLAUDE_CODE_WEB } from './onboard.js';
|
|
4
4
|
import { agentSession } from './push-identity.js';
|
|
@@ -75,7 +75,18 @@ export async function cloudKey(sys, io, args = []) {
|
|
|
75
75
|
return 1;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
const made = await makeCloudKey(sys, io, agent, token, { others, paste: true });
|
|
79
|
+
if (made === 0)
|
|
80
|
+
io.out(` ${repinLine(agent)}`);
|
|
81
|
+
return made;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What a key made outside onboard still needs: a cloud session checks the key
|
|
85
|
+
* against the ones the repo's settings pin, since its proxy cannot read the
|
|
86
|
+
* agent's list on GitHub (#447), and onboard writes the pin.
|
|
87
|
+
*/
|
|
88
|
+
export function repinLine(agent) {
|
|
89
|
+
return `Then run niyam onboard in each repository ${agent} works in: it pins the key in ${SETTINGS_PATH}, which cloud sessions check it against.`;
|
|
79
90
|
}
|
|
80
91
|
/**
|
|
81
92
|
* Why cloud-key cannot run here, or undefined: in an agent session or a cloud
|
|
@@ -100,25 +111,25 @@ export function pasteLines(agent, where = "the cloud environment's") {
|
|
|
100
111
|
* one line, the key never printed. A Ctrl-C once it is registered deletes it
|
|
101
112
|
* from GitHub again. `others` are the agent's cloud signing keys GitHub
|
|
102
113
|
* already lists, named for the owner to delete once unused; `paste` says what
|
|
103
|
-
* to do with the line, for a caller that does not say it itself.
|
|
104
|
-
*
|
|
114
|
+
* to do with the line, for a caller that does not say it itself. `key` is
|
|
115
|
+
* one made already, as onboard makes it to pin it in the pull request before
|
|
116
|
+
* it is registered (#447). 0 once the line is on the clipboard.
|
|
105
117
|
*/
|
|
106
|
-
export async function makeCloudKey(sys, io, agent, token, { others = [], paste = false } = {}) {
|
|
118
|
+
export async function makeCloudKey(sys, io, agent, token, { others = [], paste = false, key = newKey() } = {}) {
|
|
107
119
|
let interrupted = false;
|
|
108
120
|
const off = sys.onInterrupt(() => {
|
|
109
121
|
interrupted = true;
|
|
110
122
|
});
|
|
111
123
|
try {
|
|
112
|
-
return await makeAndRegister(sys, io, { agent, token, others, paste }, () => interrupted);
|
|
124
|
+
return await makeAndRegister(sys, io, { agent, token, others, paste, key }, () => interrupted);
|
|
113
125
|
}
|
|
114
126
|
finally {
|
|
115
127
|
off();
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
130
|
/** Makes the key, registers it, and puts it on the clipboard; each step one line. */
|
|
119
|
-
async function makeAndRegister(sys, io, { agent, token, others, paste }, interrupted) {
|
|
131
|
+
async function makeAndRegister(sys, io, { agent, token, others, paste, key }, interrupted) {
|
|
120
132
|
const comment = `${agent} cloud signing`;
|
|
121
|
-
const key = newKey();
|
|
122
133
|
const publicKey = `${publicLine(key)} ${comment}`;
|
|
123
134
|
const line = `${SIGNING_KEY_VAR}=${Buffer.from(privateKeyText(key, comment)).toString('base64')}`;
|
|
124
135
|
const posted = await sys.http(`${API}/user/ssh_signing_keys`, { method: 'POST', token, body: { title: CLOUD_KEY_TITLE, key: publicKey } });
|
|
@@ -177,8 +188,10 @@ export async function listedKeys(sys, agent, token) {
|
|
|
177
188
|
return { problem: `GitHub answered HTTP ${status} when asked for ${agent}'s signing keys` };
|
|
178
189
|
return {
|
|
179
190
|
keys: json.flatMap((entry) => {
|
|
180
|
-
const { id, title, created_at: created } = (entry ?? {});
|
|
181
|
-
return typeof id === 'number'
|
|
191
|
+
const { id, title, created_at: created, key } = (entry ?? {});
|
|
192
|
+
return typeof id === 'number'
|
|
193
|
+
? [{ id, title: typeof title === 'string' ? title : '', created: typeof created === 'string' ? created : '', key: typeof key === 'string' ? keyBody(key) : '' }]
|
|
194
|
+
: [];
|
|
182
195
|
}),
|
|
183
196
|
};
|
|
184
197
|
}
|
package/dist/cloud.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { API, BASE_ENV, authorVars, configVars, isNoToken,
|
|
1
|
+
import { API, BASE_ENV, CLOUD_SIGNING_KEYS, SETTINGS_PATH, authorVars, configVars, isNoToken, pathsFor, signingConfig } from './agent.js';
|
|
2
2
|
import { SSH_SIGN, signerScript } from './ssh-sign.js';
|
|
3
3
|
import { commitSignature, publicLine, readPrivateKey, signatureProblem } from './sshsig.js';
|
|
4
4
|
import { CLAUDE_CODE_WEB, SETUP_FIRST, workflowPins } from './onboard.js';
|
|
@@ -51,13 +51,16 @@ const PROBE_MESSAGE = 'niyam: a probe of the agent\'s signing, never on a branch
|
|
|
51
51
|
* ssh-keygen, #425, and installing one costs every session time and needs the
|
|
52
52
|
* network). All of them or none, since a commit that claims the agent
|
|
53
53
|
* must be Verified as the agent (PR identity) and a signing setup that fails
|
|
54
|
-
* breaks every commit: each is given only when the key is one
|
|
55
|
-
*
|
|
56
|
-
* the clone at `root`, verifies as
|
|
57
|
-
*
|
|
58
|
-
*
|
|
54
|
+
* breaks every commit: each is given only when the key is one of `pinned`,
|
|
55
|
+
* the agent's cloud signing keys the repo's settings pin, and a probe commit
|
|
56
|
+
* signed with exactly these settings, in the clone at `root`, verifies as
|
|
57
|
+
* that key's. The pin stands in for GitHub's list of the agent's signing
|
|
58
|
+
* keys, which `onboard` read on the owner's Mac: the session's proxy refuses
|
|
59
|
+
* every `users/…` path (#447). The probe is an object on no branch, which
|
|
60
|
+
* git's housekeeping drops. Otherwise why not, and the session keeps the
|
|
61
|
+
* cloud image's identity.
|
|
59
62
|
*/
|
|
60
|
-
export
|
|
63
|
+
export function cloudSigning(sys, root, login, id, pinned) {
|
|
61
64
|
const given = sys.env[SIGNING_KEY_VAR]?.trim();
|
|
62
65
|
if (!given)
|
|
63
66
|
return { problem: `the cloud environment's variables have no ${SIGNING_KEY_VAR}, ${login}'s cloud signing key (niyam's README, "Claude cloud sessions", says how to add one)` };
|
|
@@ -71,11 +74,12 @@ export async function cloudSigning(sys, root, login, id) {
|
|
|
71
74
|
if ('problem' in parsed)
|
|
72
75
|
return { problem: `${SIGNING_KEY_VAR} cannot be used: ${parsed.problem}` };
|
|
73
76
|
const body = publicLine(parsed);
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const pin = `${SETTINGS_PATH}'s "${CLOUD_SIGNING_KEYS}"`;
|
|
78
|
+
const repin = `niyam onboard on the owner's Mac pins the ones GitHub lists`;
|
|
79
|
+
if (pinned.length === 0)
|
|
80
|
+
return { problem: `${pin} pins no cloud signing key for ${login}, and this session cannot ask GitHub for ${login}'s signing keys; ${repin}` };
|
|
81
|
+
if (!pinned.includes(body))
|
|
82
|
+
return { problem: `${SIGNING_KEY_VAR}'s public half is not one of the cloud signing keys ${pin} pins for ${login}; ${repin}` };
|
|
79
83
|
const { dir, key } = pathsFor(sys.home, login);
|
|
80
84
|
const pub = `${key}.pub`;
|
|
81
85
|
const signer = `${dir}/${SSH_SIGN}`;
|
|
@@ -96,25 +100,6 @@ export async function cloudSigning(sys, root, login, id) {
|
|
|
96
100
|
}
|
|
97
101
|
const PEM_BEGIN = '-----BEGIN OPENSSH PRIVATE KEY-----';
|
|
98
102
|
const PEM_END = '-----END OPENSSH PRIVATE KEY-----';
|
|
99
|
-
/** The signing keys GitHub's public list names for `login`, asked through the proxy, or why they cannot be had. */
|
|
100
|
-
async function listedSigningKeys(sys, login) {
|
|
101
|
-
let answer;
|
|
102
|
-
try {
|
|
103
|
-
answer = await sys.http(`${API}/users/${encodeURIComponent(login)}/ssh_signing_keys?per_page=100`, { token: cloudToken(sys) });
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
// fail-open: the session keeps the image's identity, which PR identity passes, and says why.
|
|
107
|
-
return { problem: `GitHub could not be asked for ${login}'s signing keys (${messageOf(error)})` };
|
|
108
|
-
}
|
|
109
|
-
if (answer.status !== 200 || !Array.isArray(answer.json))
|
|
110
|
-
return { problem: `GitHub answered HTTP ${answer.status} when asked for ${login}'s signing keys` };
|
|
111
|
-
return {
|
|
112
|
-
keys: answer.json.flatMap((entry) => {
|
|
113
|
-
const key = entry?.key;
|
|
114
|
-
return typeof key === 'string' ? [keyBody(key)] : [];
|
|
115
|
-
}),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
103
|
/**
|
|
119
104
|
* Makes a commit object on no branch with the environment `vars` give, and
|
|
120
105
|
* checks its signature is the agent key's, `publicKey`, in git's namespace,
|
package/dist/onboard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AGENT_VAR, CLI, CONFIG_DIR, PRODUCT } from './names.js';
|
|
2
|
-
import { API, BASE_ENV, SETTINGS_PATH, account, agentHere, agentIn, agentsSetUp, anyLogin, checkToken, either, isLogin, keyPairProblem, loadSettings, pathsFor, readToken, repoAt, sameLogin, sessionEnv, tokenInfo, } from './agent.js';
|
|
2
|
+
import { API, BASE_ENV, CLOUD_SIGNING_KEYS, SETTINGS_PATH, account, agentHere, agentIn, agentsSetUp, anyLogin, checkToken, either, isLogin, keyPairProblem, loadSettings, pathsFor, readToken, repoAt, sameLogin, sessionEnv, settingsIn, tokenInfo, } from './agent.js';
|
|
3
3
|
import { setUpBoard } from './board.js';
|
|
4
4
|
import { BOARD_SECRETS, boardAppSteps, setUpBoardApp } from './board-app.js';
|
|
5
5
|
import { agentSession } from './push-identity.js';
|
|
@@ -11,6 +11,7 @@ import { DEFAULT_SCHEDULE, FEATURES, FIGMA_FILE_KEY, NEEDS_ISSUE_TYPES, features
|
|
|
11
11
|
import { CLOUD_SETUP_PATH, HOOKS_PATH, LEFTOVER_CLOUD_SETUP_PATH, ONBOARD_BRANCH, SARATHI_PATH, WORKFLOW_PATH, autoMerge, mergeQueue, openPull, remoteFile, } from './onboard-pull.js';
|
|
12
12
|
import { SIGNING_KEY_VAR, cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
|
|
13
13
|
import { CLOUD_KEY_TITLE, cloudKeyRefusal, listedKeys, makeCloudKey, pasteLines } from './cloud-key.js';
|
|
14
|
+
import { newKey, publicLine } from './sshsig.js';
|
|
14
15
|
import { detail } from './doc-numbers.js';
|
|
15
16
|
import { tagOnMain } from './release-tag.js';
|
|
16
17
|
import { secretNames, setSecret } from './secrets.js';
|
|
@@ -1597,7 +1598,7 @@ export async function onboard(sys, io, args = []) {
|
|
|
1597
1598
|
// The agent's cloud signing key (#417) is the agent's, not the repository's: one line serves every cloud
|
|
1598
1599
|
// environment it works in, so onboard makes one only when the agent's own list holds none, and the second repo
|
|
1599
1600
|
// onboarded leaves it alone. Where cloud-key would refuse, the owner runs it instead.
|
|
1600
|
-
const keyByHand = `Once for ${agent}: in your own terminal on your Mac, run niyam cloud-key ${agent},
|
|
1601
|
+
const keyByHand = `Once for ${agent}: in your own terminal on your Mac, run niyam cloud-key ${agent}, paste the line it puts on the clipboard into each Claude cloud environment's variables, then run niyam onboard here again, which pins the key in ${SETTINGS_PATH}.`;
|
|
1601
1602
|
const cloudKeys = await listedKeys(sys, agent, token).catch((error) => {
|
|
1602
1603
|
// fail-open: a list GitHub does not give is warned about below and makes no key.
|
|
1603
1604
|
return { problem: detail(error) };
|
|
@@ -1614,6 +1615,36 @@ export async function onboard(sys, io, args = []) {
|
|
|
1614
1615
|
makeKey = true;
|
|
1615
1616
|
}
|
|
1616
1617
|
}
|
|
1618
|
+
// A cloud session's proxy cannot read the agent's signing keys (#447), so the settings pin its cloud signing keys
|
|
1619
|
+
// as GitHub lists them now, with the one this run makes: made here, so the pull request pins it, and registered
|
|
1620
|
+
// last, as before. One that then fails to register reaches no clipboard, so no environment holds it; a later run
|
|
1621
|
+
// drops it once GitHub does not list it. A list GitHub does not give leaves the pin as it is.
|
|
1622
|
+
const fresh = makeKey ? newKey() : undefined;
|
|
1623
|
+
if (!('problem' in cloudKeys)) {
|
|
1624
|
+
const keys = [...cloudKeys.keys.filter((one) => one.title === CLOUD_KEY_TITLE && one.key !== '').map((one) => one.key), ...(fresh ? [publicLine(fresh)] : [])];
|
|
1625
|
+
const text = fileAt(SETTINGS_PATH);
|
|
1626
|
+
let pins;
|
|
1627
|
+
try {
|
|
1628
|
+
pins = text === undefined ? undefined : { ...settingsIn(text).cloudSigningKeys };
|
|
1629
|
+
}
|
|
1630
|
+
catch (error) {
|
|
1631
|
+
// fail-open: the pin stays as it is, and the plan says why.
|
|
1632
|
+
warnings.push(`cloud signing keys not pinned (${detail(error)})`);
|
|
1633
|
+
}
|
|
1634
|
+
if (text !== undefined && pins !== undefined) {
|
|
1635
|
+
const name = Object.keys(pins).find((login) => sameLogin(login, agent)) ?? agent;
|
|
1636
|
+
if (keys.join('\n') !== (pins[name] ?? []).join('\n')) {
|
|
1637
|
+
if (keys.length > 0)
|
|
1638
|
+
pins[name] = keys;
|
|
1639
|
+
else
|
|
1640
|
+
delete pins[name];
|
|
1641
|
+
const what = keys.length > 0 ? `pin ${agent}'s cloud signing ${keys.length === 1 ? 'key' : 'keys'}, which cloud sessions check theirs against` : `drop ${agent}'s cloud signing keys, which GitHub no longer lists`;
|
|
1642
|
+
// Written where it stands, the rest of the file as it is.
|
|
1643
|
+
change(SETTINGS_PATH, setMember(text, [], CLOUD_SIGNING_KEYS, pins), what);
|
|
1644
|
+
settingsItem(what);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1617
1648
|
let pullUrl;
|
|
1618
1649
|
// Whether the pull request merges itself once its checks pass.
|
|
1619
1650
|
let merging = false;
|
|
@@ -1716,7 +1747,7 @@ export async function onboard(sys, io, args = []) {
|
|
|
1716
1747
|
let made = false;
|
|
1717
1748
|
try {
|
|
1718
1749
|
({ ok: made } = await runStep(sys, io, paint, `cloud signing key for ${agent}`, async (out) => {
|
|
1719
|
-
const code = await makeCloudKey(sys, out, agent, token);
|
|
1750
|
+
const code = await makeCloudKey(sys, out, agent, token, fresh ? { key: fresh } : {});
|
|
1720
1751
|
if (code === 130)
|
|
1721
1752
|
exitCode = 130;
|
|
1722
1753
|
return code === 0;
|
|
@@ -1729,7 +1760,7 @@ export async function onboard(sys, io, args = []) {
|
|
|
1729
1760
|
if (made)
|
|
1730
1761
|
byHand.unshift(`Now: ${SIGNING_KEY_VAR}=… is on the clipboard. ${pasteLines(agent, "each Claude cloud environment's").join(' ')}`);
|
|
1731
1762
|
else {
|
|
1732
|
-
io.err(`onboard: ${agent} has no cloud signing key yet; everything before it is done`);
|
|
1763
|
+
io.err(`onboard: ${agent} has no cloud signing key yet; everything before it is done, and no environment holds the key the pull request pins`);
|
|
1733
1764
|
byHand.push(keyByHand);
|
|
1734
1765
|
}
|
|
1735
1766
|
}
|
package/dist/pr-autocreate.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { dirname, resolve } from 'node:path';
|
|
3
3
|
import { githubSlug, isNoToken, SETTINGS_PATH } from './agent.js';
|
|
4
4
|
import { agentEnv } from './as-agent.js';
|
|
5
|
+
import { schema } from './doc-numbers.js';
|
|
5
6
|
import { GITHUB_API, GITHUB_HOST } from './host.js';
|
|
6
7
|
import { commands } from './shell.js';
|
|
7
8
|
import { sessionToken } from './work.js';
|
|
@@ -588,6 +589,50 @@ export function listForAutofix(sys, session, url) {
|
|
|
588
589
|
return false;
|
|
589
590
|
}
|
|
590
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* The pull request's latest state on the session's sarathi Auto-fix list, folded as sarathi's `readRows` and
|
|
594
|
+
* `fold` do: rows whose `pr` and `event` are strings, the pull request matched in lower case, `warned` skipped,
|
|
595
|
+
* `opened` only adding it, any other event setting its state. Undefined when the list does not name it, or
|
|
596
|
+
* cannot be read.
|
|
597
|
+
*/
|
|
598
|
+
export function autofixState(sys, session, url) {
|
|
599
|
+
const pull = pullOf(url);
|
|
600
|
+
if (!session || !SARATHI_SESSION.test(session) || !pull)
|
|
601
|
+
return undefined;
|
|
602
|
+
const file = resolve(autofixDir(sys), `${session}.jsonl`);
|
|
603
|
+
let text;
|
|
604
|
+
try {
|
|
605
|
+
text = sys.read(file);
|
|
606
|
+
}
|
|
607
|
+
catch {
|
|
608
|
+
// fail-open: a list that cannot be read shows no state, and the whole instruction goes out
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
const key = pull.pr.toLowerCase();
|
|
612
|
+
let state;
|
|
613
|
+
for (const line of text.split('\n')) {
|
|
614
|
+
let row;
|
|
615
|
+
try {
|
|
616
|
+
row = ListRowSchema.parse(JSON.parse(line));
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
// fail-open: a blank or partial line, or one that is no row, as sarathi skips it
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
if (row.pr.toLowerCase() !== key || row.event === 'warned')
|
|
623
|
+
continue;
|
|
624
|
+
if (row.event !== 'opened' || state === undefined)
|
|
625
|
+
state = row.event;
|
|
626
|
+
}
|
|
627
|
+
return state;
|
|
628
|
+
}
|
|
629
|
+
/** A row of sarathi's Auto-fix list, as its `readRows` keeps one: `pr` and `event` strings. */
|
|
630
|
+
const ListRowSchema = schema((value) => {
|
|
631
|
+
const { pr, event } = (typeof value === 'object' && value !== null ? value : {});
|
|
632
|
+
if (typeof pr !== 'string' || typeof event !== 'string')
|
|
633
|
+
throw new Error('not a list row');
|
|
634
|
+
return { pr, event };
|
|
635
|
+
});
|
|
591
636
|
/** How the session replaces the placeholder body. */
|
|
592
637
|
function editHint(settings, pulls, number) {
|
|
593
638
|
return pulls.cloud ? `gh api -X PATCH repos/${pulls.slug}/pulls/${number} -F body=@FILE` : settings.describe;
|
|
@@ -601,6 +646,9 @@ async function autofixMessage(sys, root, settings, state, session, pulls, listed
|
|
|
601
646
|
const ack = `${stateDir(root)}/acks/${who}-${pr.number}`;
|
|
602
647
|
if (sys.exists(ack))
|
|
603
648
|
return '';
|
|
649
|
+
// sarathi's list shows Auto-fix on already: nothing to say, and no ack, so an `off` later is told at a later Stop.
|
|
650
|
+
if (listed && settings.autofixList && autofixState(sys, typeof session === 'string' ? session : undefined, pr.url) === 'on')
|
|
651
|
+
return '';
|
|
604
652
|
try {
|
|
605
653
|
sys.confine(root, ack);
|
|
606
654
|
sys.mkdir(dirname(ack));
|
package/dist/session-start.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BASE_ENV, agentHere, exportLines, anyLogin, either, loadSettings, lockScript, sameLogin, pathsFor, sessionNames, sessionRecord, sessionFileIs, } from './agent.js';
|
|
1
|
+
import { BASE_ENV, agentHere, exportLines, anyLogin, either, loadSettings, pinnedCloudKeys, lockScript, sameLogin, pathsFor, sessionNames, sessionRecord, sessionFileIs, } from './agent.js';
|
|
2
2
|
import { AGENT_VAR } from './names.js';
|
|
3
3
|
import { SIGNING_KEY_VAR, cloudLogin, cloudSigning, cloudToken, ranFromSetup, repoReleases } from './cloud.js';
|
|
4
4
|
import { CLOUD_SETUP_PATH } from './onboard-pull.js';
|
|
@@ -173,7 +173,7 @@ async function cloudStart(sys) {
|
|
|
173
173
|
: hook.state === 'outside'
|
|
174
174
|
? ` Its pre-push hook ${hook.path} is outside the repository and was not checked, so only the pull request's checks may hold the work rules.`
|
|
175
175
|
: '';
|
|
176
|
-
const signed =
|
|
176
|
+
const signed = cloudCommits(sys, root, envFile, asked, pinnedCloudKeys(settings, asked.login));
|
|
177
177
|
return { line: `niyam: this cloud session works as ${asked.login} on GitHub.${unchecked}${signed}`, agent: asked.login };
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
@@ -182,13 +182,14 @@ async function cloudStart(sys) {
|
|
|
182
182
|
* identity, Claude's: `cloudSigning`'s variables, appended to CLAUDE_ENV_FILE
|
|
183
183
|
* after the lock is lifted, which reaches every command Claude Code runs and
|
|
184
184
|
* leaves the clone's git config alone. The key's variable is unset there, so
|
|
185
|
-
* commands do not carry it in their environment.
|
|
185
|
+
* commands do not carry it in their environment. `pinned` are the agent's
|
|
186
|
+
* cloud signing keys the repo's settings pin. A warning only, said after
|
|
186
187
|
* the line: when any of it fails, the session works on as the agent and its
|
|
187
188
|
* commits keep the image's identity, which PR identity passes.
|
|
188
189
|
*/
|
|
189
|
-
|
|
190
|
+
function cloudCommits(sys, root, envFile, asked, pinned) {
|
|
190
191
|
const keeps = (why) => ` Its commits keep the cloud image's identity, Claude's: ${why}.`;
|
|
191
|
-
const signing =
|
|
192
|
+
const signing = cloudSigning(sys, root, asked.login, asked.id, pinned);
|
|
192
193
|
if ('problem' in signing)
|
|
193
194
|
return keeps(signing.problem);
|
|
194
195
|
try {
|