@veda-hq/niyam 0.6.23 → 0.6.25
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 +109 -33
- package/dist/agent.js +2 -1
- package/dist/board-app.js +254 -0
- package/dist/cloud-key.js +49 -58
- package/dist/cloud.js +32 -29
- package/dist/doctor.js +15 -12
- package/dist/error-detail.js +12 -0
- package/dist/layout.js +43 -0
- package/dist/onboard.js +114 -35
- package/dist/pr-autocreate.js +87 -12
- package/dist/run.js +6 -1
- package/dist/secrets.js +73 -25
- package/dist/ssh-sign.js +84 -0
- package/dist/sshsig.js +218 -0
- package/dist/sys.js +25 -0
- package/package.json +1 -1
package/dist/cloud-key.js
CHANGED
|
@@ -4,6 +4,7 @@ import { CLAUDE_CODE_WEB } from './onboard.js';
|
|
|
4
4
|
import { agentSession } from './push-identity.js';
|
|
5
5
|
import { tokenStore, unsupported } from './token-store.js';
|
|
6
6
|
import { GITHUB_WEB } from './host.js';
|
|
7
|
+
import { newKey, privateKeyText, publicLine } from './sshsig.js';
|
|
7
8
|
/** The title the cloud signing keys have on GitHub, so the agent's can be told apart from a Mac's. */
|
|
8
9
|
export const CLOUD_KEY_TITLE = 'niyam cloud signing';
|
|
9
10
|
/** Where the agent's signing keys are deleted, signed in as the agent. */
|
|
@@ -26,11 +27,11 @@ export function cloudKeyArgs(args) {
|
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Sets up the agent's cloud signing key from the owner's Mac (#405): a new
|
|
29
|
-
* ed25519 key, in
|
|
30
|
-
* signing key with the token `machine` stored, titled
|
|
31
|
-
* GitHub lists it, `NIYAM_SIGNING_KEY=<the private key,
|
|
32
|
-
* clipboard, for the cloud environment's variables
|
|
33
|
-
*
|
|
30
|
+
* ed25519 key, made in memory and never written to disk (#437), registered as
|
|
31
|
+
* the agent's signing key with the token `machine` stored, titled
|
|
32
|
+
* CLOUD_KEY_TITLE; once GitHub lists it, `NIYAM_SIGNING_KEY=<the private key,
|
|
33
|
+
* base64>` goes on the clipboard, for the cloud environment's variables. The
|
|
34
|
+
* key is never printed. When the clipboard
|
|
34
35
|
* does not take it, the key just registered is deleted again, since no one
|
|
35
36
|
* holds it. It names the agent's other cloud signing keys, for the owner to
|
|
36
37
|
* delete one no environment uses; it deletes none itself. Refuses in an agent
|
|
@@ -39,13 +40,10 @@ export function cloudKeyArgs(args) {
|
|
|
39
40
|
*/
|
|
40
41
|
export async function cloudKey(sys, io, args = []) {
|
|
41
42
|
const { named, yes } = cloudKeyArgs(args);
|
|
42
|
-
|
|
43
|
-
io.err('cloud-key: run it in your own terminal on your Mac, not in an agent session; it registers a key as the agent');
|
|
44
|
-
return 1;
|
|
45
|
-
}
|
|
43
|
+
const refusal = cloudKeyRefusal(sys);
|
|
46
44
|
const store = tokenStore(sys);
|
|
47
|
-
if (!store) {
|
|
48
|
-
io.err(`cloud-key: ${unsupported(sys)}`);
|
|
45
|
+
if (refusal !== undefined || !store) {
|
|
46
|
+
io.err(`cloud-key: ${refusal ?? unsupported(sys)}`);
|
|
49
47
|
return 1;
|
|
50
48
|
}
|
|
51
49
|
const { login: agent } = await account(sys, agentFrom(sys, named));
|
|
@@ -77,56 +75,52 @@ export async function cloudKey(sys, io, args = []) {
|
|
|
77
75
|
return 1;
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
78
|
+
return makeCloudKey(sys, io, agent, token, { others, paste: true });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Why cloud-key cannot run here, or undefined: in an agent session or a cloud
|
|
82
|
+
* session the token is not the owner's to use, and a machine with no token
|
|
83
|
+
* store holds no token to register the key with.
|
|
84
|
+
*/
|
|
85
|
+
export function cloudKeyRefusal(sys) {
|
|
86
|
+
if (agentSession(sys) || sys.env.CLAUDE_CODE_REMOTE === 'true')
|
|
87
|
+
return 'run it in your own terminal on your Mac, not in an agent session; it registers a key as the agent';
|
|
88
|
+
return tokenStore(sys) ? undefined : unsupported(sys);
|
|
89
|
+
}
|
|
90
|
+
/** What the owner does with the line on the clipboard: paste it into `where`'s variables, and what it does then. */
|
|
91
|
+
export function pasteLines(agent, where = "the cloud environment's") {
|
|
92
|
+
return [
|
|
93
|
+
`Paste it as one line into ${where} variables: ${CLAUDE_CODE_WEB} → the environment's settings.`,
|
|
94
|
+
`A new session there makes ${agent}'s commits its own; its first niyam line says so.`,
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Makes the agent's cloud signing key in memory with niyam's own code (#437),
|
|
99
|
+
* never on disk, registers it, and puts its line on the clipboard; each step
|
|
100
|
+
* one line, the key never printed. A Ctrl-C once it is registered deletes it
|
|
101
|
+
* from GitHub again. `others` are the agent's cloud signing keys GitHub
|
|
102
|
+
* 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. 0 once the
|
|
104
|
+
* line is on the clipboard.
|
|
105
|
+
*/
|
|
106
|
+
export async function makeCloudKey(sys, io, agent, token, { others = [], paste = false } = {}) {
|
|
94
107
|
let interrupted = false;
|
|
95
108
|
const off = sys.onInterrupt(() => {
|
|
96
109
|
interrupted = true;
|
|
97
|
-
cleanUp();
|
|
98
110
|
});
|
|
99
|
-
let code = 1;
|
|
100
111
|
try {
|
|
101
|
-
|
|
112
|
+
return await makeAndRegister(sys, io, { agent, token, others, paste }, () => interrupted);
|
|
102
113
|
}
|
|
103
114
|
finally {
|
|
104
115
|
off();
|
|
105
|
-
if (cleanUp()) {
|
|
106
|
-
io.out('✓ deleted the key files');
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
io.out(`✗ could not delete ${dir}, which holds the private key → rm -rf ${dir}`);
|
|
110
|
-
code = 1;
|
|
111
|
-
}
|
|
112
116
|
}
|
|
113
|
-
return code;
|
|
114
117
|
}
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const made = sys.exec('ssh-keygen', ['-q', '-t', 'ed25519', '-C', `${agent} cloud signing`, '-N', '', '-f', key], { input: '' });
|
|
122
|
-
if (interrupted())
|
|
123
|
-
return stopped(io);
|
|
124
|
-
if (made.code !== 0) {
|
|
125
|
-
io.out(`✗ ssh-keygen failed: ${made.stderr.trim() || `exit ${made.code}`}`);
|
|
126
|
-
return 1;
|
|
127
|
-
}
|
|
128
|
-
const publicKey = sys.read(`${key}.pub`).trim();
|
|
129
|
-
const line = `${SIGNING_KEY_VAR}=${Buffer.from(`${sys.read(key).trim()}\n`).toString('base64')}`;
|
|
118
|
+
/** 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) {
|
|
120
|
+
const comment = `${agent} cloud signing`;
|
|
121
|
+
const key = newKey();
|
|
122
|
+
const publicKey = `${publicLine(key)} ${comment}`;
|
|
123
|
+
const line = `${SIGNING_KEY_VAR}=${Buffer.from(privateKeyText(key, comment)).toString('base64')}`;
|
|
130
124
|
const posted = await sys.http(`${API}/user/ssh_signing_keys`, { method: 'POST', token, body: { title: CLOUD_KEY_TITLE, key: publicKey } });
|
|
131
125
|
const id = posted.json?.id;
|
|
132
126
|
if (posted.status !== 201 || typeof id !== 'number') {
|
|
@@ -155,17 +149,14 @@ async function makeAndRegister(sys, io, agent, token, key, others, interrupted)
|
|
|
155
149
|
return 1;
|
|
156
150
|
}
|
|
157
151
|
io.out(`✓ ${SIGNING_KEY_VAR}=… is on the clipboard`);
|
|
158
|
-
|
|
159
|
-
|
|
152
|
+
if (paste)
|
|
153
|
+
for (const line of pasteLines(agent))
|
|
154
|
+
io.out(` ${line}`);
|
|
160
155
|
for (const other of others) {
|
|
161
156
|
io.out(`▲ ${agent} has another cloud signing key, added ${other.created.slice(0, 10)} (id ${other.id}); delete it once no environment uses it → ${KEYS_PAGE}, signed in as ${agent}`);
|
|
162
157
|
}
|
|
163
158
|
return 0;
|
|
164
159
|
}
|
|
165
|
-
function stopped(io) {
|
|
166
|
-
io.out('✗ stopped by Ctrl-C; nothing registered, and nothing on the clipboard');
|
|
167
|
-
return 130;
|
|
168
|
-
}
|
|
169
160
|
/** Deletes the key just registered, which no one holds, and says why. */
|
|
170
161
|
async function unregister(sys, io, token, id, why) {
|
|
171
162
|
let status = 0;
|
|
@@ -180,7 +171,7 @@ async function unregister(sys, io, token, id, why) {
|
|
|
180
171
|
: `✗ ${why}, and deleting the key from GitHub again failed (HTTP ${status}) → delete signing key ${id} at ${KEYS_PAGE}`);
|
|
181
172
|
}
|
|
182
173
|
/** The agent's signing keys as its own list gives them, with their titles, or why they cannot be had. */
|
|
183
|
-
async function listedKeys(sys, agent, token) {
|
|
174
|
+
export async function listedKeys(sys, agent, token) {
|
|
184
175
|
const { status, json } = await sys.http(`${API}/user/ssh_signing_keys?per_page=100`, { token });
|
|
185
176
|
if (status !== 200 || !Array.isArray(json))
|
|
186
177
|
return { problem: `GitHub answered HTTP ${status} when asked for ${agent}'s signing keys` };
|
package/dist/cloud.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { API, BASE_ENV, authorVars, configVars, isNoToken, keyBody,
|
|
1
|
+
import { API, BASE_ENV, authorVars, configVars, isNoToken, keyBody, pathsFor, signingConfig } from './agent.js';
|
|
2
|
+
import { SSH_SIGN, signerScript } from './ssh-sign.js';
|
|
3
|
+
import { commitSignature, publicLine, readPrivateKey, signatureProblem } from './sshsig.js';
|
|
2
4
|
import { CLAUDE_CODE_WEB, SETUP_FIRST, workflowPins } from './onboard.js';
|
|
3
5
|
import { PRODUCT, tarballName } from './names.js';
|
|
4
6
|
import { CLOUD_SETUP_PATH, WORKFLOW_PATH } from './onboard-pull.js';
|
|
@@ -44,8 +46,10 @@ const PROBE_MESSAGE = 'niyam: a probe of the agent\'s signing, never on a branch
|
|
|
44
46
|
* What makes a cloud session's commits the agent's: its author and committer
|
|
45
47
|
* variables, with the address of the id GitHub gave with the login, and SSH
|
|
46
48
|
* signing with the key in SIGNING_KEY_VAR, over the platform's own signing
|
|
47
|
-
* (Claude's, through a program of its own: `gpg.ssh.program`
|
|
48
|
-
*
|
|
49
|
+
* (Claude's, through a program of its own: `gpg.ssh.program` becomes niyam's
|
|
50
|
+
* own signer, `niyam ssh-sign`, in Node, since the hosted image has no
|
|
51
|
+
* ssh-keygen, #425, and installing one costs every session time and needs the
|
|
52
|
+
* network). All of them or none, since a commit that claims the agent
|
|
49
53
|
* must be Verified as the agent (PR identity) and a signing setup that fails
|
|
50
54
|
* breaks every commit: each is given only when the key is one GitHub lists
|
|
51
55
|
* for the agent and a probe commit signed with exactly these settings, in
|
|
@@ -63,38 +67,31 @@ export async function cloudSigning(sys, root, login, id) {
|
|
|
63
67
|
if (!text.startsWith(`${PEM_BEGIN}\n`) || !text.endsWith(`\n${PEM_END}`)) {
|
|
64
68
|
return { problem: `${SIGNING_KEY_VAR} is not an OpenSSH private key, base64 on one line or as is` };
|
|
65
69
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
try {
|
|
71
|
-
sys.mkdir(dir);
|
|
72
|
-
sys.mkdir(key.slice(0, key.lastIndexOf('/')));
|
|
73
|
-
sys.write(key, `${text}\n`, 0o600);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
// fail-open: the session keeps the image's identity, which PR identity passes, and says why.
|
|
77
|
-
return { problem: `writing ${SIGNING_KEY_VAR} to ${key} failed (${messageOf(error)})` };
|
|
78
|
-
}
|
|
79
|
-
const derived = sys.exec('ssh-keygen', ['-y', '-f', key], { input: '' });
|
|
80
|
-
if (derived.code !== 0)
|
|
81
|
-
return { problem: `ssh-keygen cannot read ${SIGNING_KEY_VAR} (${lastLine(derived.stderr) || `exit ${derived.code}`})` };
|
|
82
|
-
const body = keyBody(derived.stdout);
|
|
70
|
+
const parsed = readPrivateKey(text);
|
|
71
|
+
if ('problem' in parsed)
|
|
72
|
+
return { problem: `${SIGNING_KEY_VAR} cannot be used: ${parsed.problem}` };
|
|
73
|
+
const body = publicLine(parsed);
|
|
83
74
|
const listed = await listedSigningKeys(sys, login);
|
|
84
75
|
if ('problem' in listed)
|
|
85
76
|
return listed;
|
|
86
77
|
if (!listed.keys.includes(body))
|
|
87
78
|
return { problem: `GitHub does not list ${SIGNING_KEY_VAR}'s public half as one of ${login}'s signing keys` };
|
|
79
|
+
const { dir, key } = pathsFor(sys.home, login);
|
|
80
|
+
const pub = `${key}.pub`;
|
|
81
|
+
const signer = `${dir}/${SSH_SIGN}`;
|
|
88
82
|
try {
|
|
83
|
+
sys.mkdir(dir);
|
|
84
|
+
sys.mkdir(key.slice(0, key.lastIndexOf('/')));
|
|
85
|
+
sys.write(key, `${text}\n`, 0o600);
|
|
89
86
|
sys.write(pub, `${body} ${login} cloud signing\n`, 0o644);
|
|
90
|
-
sys.write(
|
|
87
|
+
sys.write(signer, signerScript(sys.runtime.node, sys.runtime.cli), 0o755);
|
|
91
88
|
}
|
|
92
89
|
catch (error) {
|
|
93
90
|
// fail-open: the session keeps the image's identity, which PR identity passes, and says why.
|
|
94
|
-
return { problem: `writing ${
|
|
91
|
+
return { problem: `writing ${SIGNING_KEY_VAR} to ${key} failed (${messageOf(error)})` };
|
|
95
92
|
}
|
|
96
|
-
const vars = [...authorVars(login, id), ...configVars([['gpg.ssh.program',
|
|
97
|
-
const probe = probeSignature(sys, root, vars,
|
|
93
|
+
const vars = [...authorVars(login, id), ...configVars([['gpg.ssh.program', signer], ...signingConfig(pub)])];
|
|
94
|
+
const probe = probeSignature(sys, root, vars, body);
|
|
98
95
|
return probe ? { problem: `a probe commit signed with ${SIGNING_KEY_VAR} did not verify as that key (${probe})` } : { vars };
|
|
99
96
|
}
|
|
100
97
|
const PEM_BEGIN = '-----BEGIN OPENSSH PRIVATE KEY-----';
|
|
@@ -120,10 +117,10 @@ async function listedSigningKeys(sys, login) {
|
|
|
120
117
|
}
|
|
121
118
|
/**
|
|
122
119
|
* Makes a commit object on no branch with the environment `vars` give, and
|
|
123
|
-
*
|
|
124
|
-
* when it
|
|
120
|
+
* checks its signature is the agent key's, `publicKey`, in git's namespace,
|
|
121
|
+
* in Node, as there is no ssh-keygen: undefined when it is, else what failed.
|
|
125
122
|
*/
|
|
126
|
-
function probeSignature(sys, root, vars,
|
|
123
|
+
function probeSignature(sys, root, vars, publicKey) {
|
|
127
124
|
// The session's commands get the env file's lines, which unset the lock first: the probe does the same.
|
|
128
125
|
const base = Object.fromEntries(Object.entries(sys.env).filter(([name]) => !(name in BASE_ENV) && name !== SIGNING_KEY_VAR));
|
|
129
126
|
const env = { ...base, ...Object.fromEntries(vars) };
|
|
@@ -134,8 +131,14 @@ function probeSignature(sys, root, vars, signers) {
|
|
|
134
131
|
const commit = sys.exec('git', ['commit-tree', '-S', tree.stdout.trim(), '-m', PROBE_MESSAGE], { cwd: root, env, input: '' });
|
|
135
132
|
if (commit.code !== 0)
|
|
136
133
|
return `git commit-tree: ${lastLine(commit.stderr) || `exit ${commit.code}`}`;
|
|
137
|
-
const
|
|
138
|
-
|
|
134
|
+
const raw = sys.exec('git', ['cat-file', 'commit', commit.stdout.trim()], { cwd: root, env, input: '' });
|
|
135
|
+
if (raw.code !== 0)
|
|
136
|
+
return `git cat-file: ${lastLine(raw.stderr) || `exit ${raw.code}`}`;
|
|
137
|
+
const signed = commitSignature(raw.stdout);
|
|
138
|
+
if (!signed)
|
|
139
|
+
return 'the probe commit has no signature';
|
|
140
|
+
const problem = signatureProblem(signed.signature, signed.payload, 'git', publicKey);
|
|
141
|
+
return problem ? `its signature: ${problem}` : undefined;
|
|
139
142
|
}
|
|
140
143
|
function lastLine(text) {
|
|
141
144
|
return text.trim().split('\n').at(-1) ?? '';
|
package/dist/doctor.js
CHANGED
|
@@ -8,7 +8,7 @@ import { closing, findingLines, heading, painter, tilde } from './layout.js';
|
|
|
8
8
|
import { exposure, exposureFindings, movedFindings, readDeclined, setAside } from './lockout.js';
|
|
9
9
|
import { CLOUD_SETUP_PATH, HOOKS_PATH, SARATHI_PATH } from './onboard-pull.js';
|
|
10
10
|
import { leftoverDir, leftoverToken } from './machine.js';
|
|
11
|
-
import { BOARD_SECRETS, GUARD_COMMAND, HOOK_COMMAND, OLDER_GUARD_COMMANDS, OLDER_HOOK_COMMANDS, missingAutoFixRules, sarathiRunner } from './onboard.js';
|
|
11
|
+
import { BOARD_SECRETS, GUARD_COMMAND, HOOK_COMMAND, OLDER_GUARD_COMMANDS, OLDER_HOOK_COMMANDS, missingArtifactRules, missingAutoFixRules, sarathiRunner } from './onboard.js';
|
|
12
12
|
import { secretNames } from './secrets.js';
|
|
13
13
|
import { isOrganisation } from './owner-login.js';
|
|
14
14
|
import { leftBehind } from './owner-step.js';
|
|
@@ -196,7 +196,7 @@ async function boardAppFindings(sys, token) {
|
|
|
196
196
|
const missing = BOARD_SECRETS.filter((name) => !names.includes(name));
|
|
197
197
|
return missing.length === 0
|
|
198
198
|
? [{ mark: '✓', text: 'board app secrets' }]
|
|
199
|
-
: [{ mark: '▲', text: `no ${missing.join(' or ')} secret, so a slice moves to In Progress only from a desktop push`, fix: `${ONBOARD}
|
|
199
|
+
: [{ mark: '▲', text: `no ${missing.join(' or ')} secret, so a slice moves to In Progress only from a desktop push`, fix: `${ONBOARD} at your own terminal, which sets up the board app` }];
|
|
200
200
|
}
|
|
201
201
|
catch (error) {
|
|
202
202
|
// fail-open: a read that failed is the one ▲ here, as a missing secret breaks nothing.
|
|
@@ -205,8 +205,8 @@ async function boardAppFindings(sys, token) {
|
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
207
|
* Client hooks that reach GitHub outside `as-agent` where doctor runs, a Mac
|
|
208
|
-
* or a cloud session, and the Auto-fix rules an onboarded repo's
|
|
209
|
-
* settings lack.
|
|
208
|
+
* or a cloud session, and the Auto-fix and artifact rules an onboarded repo's
|
|
209
|
+
* Claude Code settings lack.
|
|
210
210
|
*/
|
|
211
211
|
function repoFindings(sys) {
|
|
212
212
|
return [
|
|
@@ -215,7 +215,7 @@ function repoFindings(sys) {
|
|
|
215
215
|
text: `${hook} reaches GitHub outside as-agent, so gets 401`,
|
|
216
216
|
fix: `run its gh or git via niyam as-agent --session <session_id> -- (exit ${LOCKED} when not the agent)`,
|
|
217
217
|
})),
|
|
218
|
-
...
|
|
218
|
+
...allowFindings(sys),
|
|
219
219
|
...twiceFindings(sys),
|
|
220
220
|
];
|
|
221
221
|
}
|
|
@@ -261,11 +261,12 @@ function twiceFindings(sys) {
|
|
|
261
261
|
return found;
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
|
-
* Which of onboard's Auto-fix rules the repo's
|
|
265
|
-
* lacks, so the auto-mode classifier refuses an agent
|
|
266
|
-
* Auto-fix on
|
|
264
|
+
* Which of onboard's Auto-fix and artifact rules the repo's
|
|
265
|
+
* `.claude/settings.json` lacks, so the auto-mode classifier refuses an agent
|
|
266
|
+
* session turning Auto-fix on, or publishing the page an ask to the owner
|
|
267
|
+
* links: checked in an onboarded repo whose file doctor can read.
|
|
267
268
|
*/
|
|
268
|
-
function
|
|
269
|
+
function allowFindings(sys) {
|
|
269
270
|
let settings;
|
|
270
271
|
try {
|
|
271
272
|
// Where session-start looks, so a cloud session's CLI run from outside the clone still finds it.
|
|
@@ -279,9 +280,11 @@ function autoFixFindings(sys) {
|
|
|
279
280
|
return [];
|
|
280
281
|
}
|
|
281
282
|
const missing = missingAutoFixRules(settings);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
: [{ mark: '▲', text: `${HOOKS_PATH} does not allow ${missing.join(', ')}, so agent sessions cannot turn Auto-fix on`, fix: ONBOARD }]
|
|
283
|
+
const unpublished = missingArtifactRules(settings);
|
|
284
|
+
return [
|
|
285
|
+
...(missing.length === 0 ? [] : [{ mark: '▲', text: `${HOOKS_PATH} does not allow ${missing.join(', ')}, so agent sessions cannot turn Auto-fix on`, fix: ONBOARD }]),
|
|
286
|
+
...(unpublished.length === 0 ? [] : [{ mark: '▲', text: `${HOOKS_PATH} does not allow ${unpublished.join(', ')}, so agent sessions cannot publish the page an ask to the owner links`, fix: ONBOARD }]),
|
|
287
|
+
];
|
|
285
288
|
}
|
|
286
289
|
/** Prints the findings, grouped, and closes; exit 1 when any is broken. */
|
|
287
290
|
function report(sys, io, about, groups) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What a caught value says, never throwing itself: its message, else its text, else a stand-in. */
|
|
2
|
+
export function errorDetail(value) {
|
|
3
|
+
try {
|
|
4
|
+
if (value instanceof Error && typeof value.message === 'string')
|
|
5
|
+
return value.message;
|
|
6
|
+
return String(value);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
// fail-open: a value with a hostile toString is described, not rethrown from the handler.
|
|
10
|
+
return 'an error that cannot be described';
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/layout.js
CHANGED
|
@@ -35,6 +35,49 @@ export function findingLines(paint, title, findings) {
|
|
|
35
35
|
return [];
|
|
36
36
|
return [paint.dim('│'), `${paint.done('◇')} ${title}`, ...findings.map((finding) => findingLine(paint, finding))];
|
|
37
37
|
}
|
|
38
|
+
/** How wide a by-hand step's lines are, bar and number included: the narrowest terminal people keep. */
|
|
39
|
+
export const BY_HAND_WIDTH = 80;
|
|
40
|
+
/**
|
|
41
|
+
* `text` in lines of at most `width` characters, broken at spaces; a word
|
|
42
|
+
* longer than that, such as a link, has a line of its own. `width` is a
|
|
43
|
+
* count of UTF-16 code units, not of a terminal's columns, so a line with
|
|
44
|
+
* wide characters (in a path or a name) can run past it.
|
|
45
|
+
*/
|
|
46
|
+
export function wrap(text, width) {
|
|
47
|
+
const lines = [];
|
|
48
|
+
let line = '';
|
|
49
|
+
for (const word of text.split(/\s+/).filter(Boolean)) {
|
|
50
|
+
if (line && line.length + 1 + word.length > width) {
|
|
51
|
+
lines.push(line);
|
|
52
|
+
line = word;
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
line = line ? `${line} ${word}` : word;
|
|
56
|
+
}
|
|
57
|
+
if (line)
|
|
58
|
+
lines.push(line);
|
|
59
|
+
return lines;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The ◇ By hand group, after a bar: each step numbered, wrapped behind the
|
|
63
|
+
* bar to BY_HAND_WIDTH, a bar between steps; nothing when there are none.
|
|
64
|
+
*/
|
|
65
|
+
export function byHandLines(paint, steps) {
|
|
66
|
+
if (steps.length === 0)
|
|
67
|
+
return [];
|
|
68
|
+
const bar = paint.dim('│');
|
|
69
|
+
const lines = [bar, `${paint.warn('◇')} By hand`];
|
|
70
|
+
steps.forEach((step, index) => {
|
|
71
|
+
const number = `${index + 1}.`;
|
|
72
|
+
const indent = ' '.length + number.length + 1;
|
|
73
|
+
const [first = '', ...rest] = wrap(step, BY_HAND_WIDTH - 1 - indent);
|
|
74
|
+
if (index > 0)
|
|
75
|
+
lines.push(bar);
|
|
76
|
+
lines.push(`${bar} ${paint.accent(number)} ${first}`, ...rest.map((line) => `${bar}${' '.repeat(indent)}${line}`));
|
|
77
|
+
});
|
|
78
|
+
lines.push(bar);
|
|
79
|
+
return lines;
|
|
80
|
+
}
|
|
38
81
|
/** The run's last line. */
|
|
39
82
|
export function closing(paint, text) {
|
|
40
83
|
return `${paint.dim('└')} ${text}`;
|
package/dist/onboard.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { AGENT_VAR, CLI, CONFIG_DIR, PRODUCT } from './names.js';
|
|
2
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';
|
|
3
3
|
import { setUpBoard } from './board.js';
|
|
4
|
+
import { BOARD_SECRETS, boardAppSteps, setUpBoardApp } from './board-app.js';
|
|
5
|
+
import { agentSession } from './push-identity.js';
|
|
4
6
|
import { typesDetail, typesLines, typesPlan } from './issue-types.js';
|
|
5
7
|
import { asOwner, isOrganisation, ownerScopes, signInOnce } from './owner-login.js';
|
|
6
8
|
import { appendToArray, removeElements, replaceValues, setMember } from './jsonedit.js';
|
|
7
9
|
import { HOURLY } from './asks.js';
|
|
8
10
|
import { DEFAULT_SCHEDULE, FEATURES, FIGMA_FILE_KEY, NEEDS_ISSUE_TYPES, featuresIn, parseFeatures, renamedLines, scheduleIn } from './features.js';
|
|
9
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';
|
|
10
|
-
import { cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
|
|
12
|
+
import { SIGNING_KEY_VAR, cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
|
|
13
|
+
import { CLOUD_KEY_TITLE, cloudKeyRefusal, listedKeys, makeCloudKey, pasteLines } from './cloud-key.js';
|
|
14
|
+
import { detail } from './doc-numbers.js';
|
|
11
15
|
import { tagOnMain } from './release-tag.js';
|
|
12
16
|
import { secretNames, setSecret } from './secrets.js';
|
|
13
17
|
import { UPGRADE } from './upgrade.js';
|
|
14
18
|
import { isNewer, packageVersion } from './version.js';
|
|
15
19
|
import { GITHUB_WEB } from './host.js';
|
|
16
|
-
import { closing, heading, painter, planLines, runStep } from './layout.js';
|
|
20
|
+
import { byHandLines, closing, heading, painter, planLines, runStep } from './layout.js';
|
|
17
21
|
/** Where claude.ai connects the GitHub account its cloud sessions and routines work as. */
|
|
18
22
|
export const CLAUDE_CODE_WEB = 'https://claude.ai/code';
|
|
19
23
|
/** Where claude.ai changes that connection. */
|
|
@@ -206,14 +210,36 @@ export const AUTO_FIX_RULES = ['mcp__ccd_pr__bind_pr', 'mcp__ccd_pr__get_status'
|
|
|
206
210
|
/** The rules that allow every tool of the app's pull request server, AUTO_FIX_RULES among them. */
|
|
207
211
|
const PR_SERVER_RULES = ['mcp__ccd_pr', 'mcp__ccd_pr__*'];
|
|
208
212
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
213
|
+
* The permission rules that let agent sessions publish the claude.ai page
|
|
214
|
+
* every ask to the owner links (`Needs you:`, `Proposal:`, `niyam propose
|
|
215
|
+
* --page`): a new page, one from files, and a change to one. Without them
|
|
216
|
+
* the auto-mode classifier refuses the calls as communication. A new page
|
|
217
|
+
* is private to its owner, but a republish (`publish_version` or
|
|
218
|
+
* `edit_version` with a slug) to a page already shared with an organisation
|
|
219
|
+
* or the public changes what its readers see, with no prompt: a cost the
|
|
220
|
+
* owner accepted on veda-hq/niyam#432. Claude Code skips an `mcp__` allow
|
|
221
|
+
* rule with arguments, so no rule here can limit them to private pages.
|
|
211
222
|
*/
|
|
212
|
-
export
|
|
223
|
+
export const ARTIFACT_RULES = ['mcp__claude-artifacts__publish_version', 'mcp__claude-artifacts__publish_files', 'mcp__claude-artifacts__edit_version'];
|
|
224
|
+
/** The rules that allow every tool of the artifacts server, ARTIFACT_RULES among them. */
|
|
225
|
+
const ARTIFACT_SERVER_RULES = ['mcp__claude-artifacts', 'mcp__claude-artifacts__*'];
|
|
226
|
+
/**
|
|
227
|
+
* Which of `rules` a settings file's `permissions.allow` lacks, in their
|
|
228
|
+
* order: none when it allows the whole server, by one of `server`.
|
|
229
|
+
*/
|
|
230
|
+
function missingRules(settings, rules, server) {
|
|
213
231
|
const allow = settings?.permissions?.allow;
|
|
214
|
-
if (Array.isArray(allow) && allow.some((rule) =>
|
|
232
|
+
if (Array.isArray(allow) && allow.some((rule) => server.includes(rule)))
|
|
215
233
|
return [];
|
|
216
|
-
return
|
|
234
|
+
return rules.filter((rule) => !Array.isArray(allow) || !allow.includes(rule));
|
|
235
|
+
}
|
|
236
|
+
/** Which of AUTO_FIX_RULES a settings file's `permissions.allow` lacks. */
|
|
237
|
+
export function missingAutoFixRules(settings) {
|
|
238
|
+
return missingRules(settings, AUTO_FIX_RULES, PR_SERVER_RULES);
|
|
239
|
+
}
|
|
240
|
+
/** Which of ARTIFACT_RULES a settings file's `permissions.allow` lacks. */
|
|
241
|
+
export function missingArtifactRules(settings) {
|
|
242
|
+
return missingRules(settings, ARTIFACT_RULES, ARTIFACT_SERVER_RULES);
|
|
217
243
|
}
|
|
218
244
|
/** The hook commands older releases wrote, which onboard replaces with this release's. */
|
|
219
245
|
export const OLDER_HOOK_COMMANDS = [
|
|
@@ -443,24 +469,8 @@ const FIGMA_SECRETS = [' secrets:', ' FIGMA_TOKEN: ${{ secrets.FIGMA_TOK
|
|
|
443
469
|
/** The secrets every job passed before P-23, whether figma was on or not. */
|
|
444
470
|
const OLDER_SECRETS = [' secrets:', ' FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}'];
|
|
445
471
|
/** The board GitHub App's secrets, which the Slice started job makes its board token from (P-70). */
|
|
446
|
-
export const BOARD_SECRETS = ['NIYAM_BOARD_APP_ID', 'NIYAM_BOARD_APP_KEY'];
|
|
447
472
|
const BOARD_SECRET_LINES = BOARD_SECRETS.map((name) => ` ${name}: \${{ secrets.${name} }}`);
|
|
448
|
-
|
|
449
|
-
const BOARD_SECRET_HOLDS = { NIYAM_BOARD_APP_ID: 'client id', NIYAM_BOARD_APP_KEY: 'private key' };
|
|
450
|
-
/**
|
|
451
|
-
* The owner's steps, once per organization, to give `slug`'s Slice started
|
|
452
|
-
* job the board app's token: make the app, install it, and set the secrets
|
|
453
|
-
* `missing`. `unknown` when GitHub would not list the secrets, so they may be
|
|
454
|
-
* set already.
|
|
455
|
-
*/
|
|
456
|
-
export function boardAppSteps(slug, missing, unknown = false) {
|
|
457
|
-
const org = slug.split('/')[0];
|
|
458
|
-
const set = missing.map((name) => `its ${BOARD_SECRET_HOLDS[name]} as ${name}`).join(' and ');
|
|
459
|
-
return (`${unknown ? `Unless ${slug} has the Actions secrets ${BOARD_SECRETS.join(' and ')} already, once` : 'Once'} for ${org}: ` +
|
|
460
|
-
`make a GitHub App with organization Projects read and write and repository Issues read at ${GITHUB_WEB}/organizations/${org}/settings/apps/new, ` +
|
|
461
|
-
`install it on ${slug}, and set ${set}, Actions secrets of the organization or of ${GITHUB_WEB}/${slug}/settings/secrets/actions. ` +
|
|
462
|
-
'Until then a slice moves to In Progress on the board only from a desktop push.');
|
|
463
|
-
}
|
|
473
|
+
export { BOARD_SECRETS, boardAppSteps };
|
|
464
474
|
/**
|
|
465
475
|
* The secrets block job `id` passes the shared checks: the Figma secrets on
|
|
466
476
|
* every job, and the board app's on the pull request job alone, since only
|
|
@@ -820,7 +830,7 @@ function handlersOf(sarathi, event) {
|
|
|
820
830
|
/**
|
|
821
831
|
* The client's Claude Code settings with this release's hooks and lock: each
|
|
822
832
|
* entry an older release wrote swapped where it stands, a missing one added,
|
|
823
|
-
* the lock's variables set in `env`, and REVIEW_THREAD_RULE and
|
|
833
|
+
* the lock's variables set in `env`, and REVIEW_THREAD_RULE, AUTO_FIX_RULES and ARTIFACT_RULES allowed. Every edit is made in the text, so
|
|
824
834
|
* the rest of the file keeps its layout. Says what changed, for the question.
|
|
825
835
|
*
|
|
826
836
|
* Where the project keeps `.claude/sarathi.json` (`sarathiBefore`) and the
|
|
@@ -980,9 +990,16 @@ export function claudeSettings(before, sarathiBefore) {
|
|
|
980
990
|
if (lacking.length > 0) {
|
|
981
991
|
changes.push(`allow ${lacking.join(', ')} without a prompt, so agent sessions turn Auto-fix on for their own pull requests`);
|
|
982
992
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
993
|
+
const unpublished = missingArtifactRules(parsed());
|
|
994
|
+
for (const rule of unpublished)
|
|
995
|
+
text = appendToArray(text, ['permissions'], 'allow', rule);
|
|
996
|
+
if (unpublished.length > 0) {
|
|
997
|
+
changes.push(`allow ${unpublished.join(', ')} without a prompt, so agent sessions publish the page an ask to the owner links`);
|
|
998
|
+
}
|
|
999
|
+
// One group's own word, or one word for several, so the plan's line stays short.
|
|
1000
|
+
const groups = [review || renamed.replaced > 0 ? 'review rule' : '', lacking.length > 0 ? 'Auto-fix rules' : '', unpublished.length > 0 ? 'artifact rules' : ''].filter(Boolean);
|
|
1001
|
+
if (groups.length > 0)
|
|
1002
|
+
labels.push(groups.length === 1 ? groups[0] : 'allow rules');
|
|
986
1003
|
}
|
|
987
1004
|
catch (error) {
|
|
988
1005
|
throw new Error(`${HOOKS_PATH}: ${error.message}`);
|
|
@@ -1110,7 +1127,9 @@ function planHead(paint, head) {
|
|
|
1110
1127
|
* agent. It prints that as one plan and asks once (`--yes` skips the
|
|
1111
1128
|
* question, `--dry-run` stops at the plan); a no changes nothing. After the
|
|
1112
1129
|
* yes, one browser sign-in as the owner serves every step that acts as the
|
|
1113
|
-
* owner, and each step shows as one line.
|
|
1130
|
+
* owner, and each step shows as one line. Last, once the pull request is
|
|
1131
|
+
* open, it makes the agent's cloud signing key when the agent has none
|
|
1132
|
+
* (#417), a failure there only warning.
|
|
1114
1133
|
*/
|
|
1115
1134
|
export async function onboard(sys, io, args = []) {
|
|
1116
1135
|
const { named, features: chosen, add, yes, dryRun } = onboardArgs(args);
|
|
@@ -1444,7 +1463,25 @@ export async function onboard(sys, io, args = []) {
|
|
|
1444
1463
|
if (workflowNeeded && passed.board && (await byOrganisation())) {
|
|
1445
1464
|
const names = await secretNames(sys, slug, token);
|
|
1446
1465
|
const missing = BOARD_SECRETS.filter((name) => !names?.includes(name));
|
|
1447
|
-
|
|
1466
|
+
// The app is made from a manifest in the owner's browser (P-72): a run with no one at the terminal, or an agent's
|
|
1467
|
+
// or a cloud session, leaves it by hand.
|
|
1468
|
+
const browser = sys.tty && !agentSession(sys) && sys.env.CLAUDE_CODE_REMOTE !== 'true';
|
|
1469
|
+
if (missing.length > 0 && browser) {
|
|
1470
|
+
// An organisation's app already made is shared with the repository with no click.
|
|
1471
|
+
github.push({ label: 'board app', detail: 'two clicks in the browser, if it is new' });
|
|
1472
|
+
steps.push({
|
|
1473
|
+
label: 'board app',
|
|
1474
|
+
owner: true,
|
|
1475
|
+
async run(out, mine) {
|
|
1476
|
+
const left = await setUpBoardApp(sys, out, slug, mine);
|
|
1477
|
+
byHand.push(...left);
|
|
1478
|
+
later.push(...left);
|
|
1479
|
+
// fail-open: what GitHub refused, or a click that did not come, is left by hand; the run goes on.
|
|
1480
|
+
return true;
|
|
1481
|
+
},
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
else if (missing.length > 0) {
|
|
1448
1485
|
const steps = boardAppSteps(slug, missing, names === undefined);
|
|
1449
1486
|
byHand.push(steps);
|
|
1450
1487
|
later.push(steps);
|
|
@@ -1557,6 +1594,26 @@ export async function onboard(sys, io, args = []) {
|
|
|
1557
1594
|
later.push(`Claude cloud sessions: a Setup script pasted before niyam 0.6.10 runs ${LEFTOVER_CLOUD_SETUP_PATH}, which this pull request deletes; if yours is one, delete niyam's part of it, since sessions now install niyam themselves, or paste what niyam cloud-setup prints over it. ${SETUP_FIRST}`);
|
|
1558
1595
|
}
|
|
1559
1596
|
}
|
|
1597
|
+
// The agent's cloud signing key (#417) is the agent's, not the repository's: one line serves every cloud
|
|
1598
|
+
// environment it works in, so onboard makes one only when the agent's own list holds none, and the second repo
|
|
1599
|
+
// 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}, and paste the line it puts on the clipboard into each Claude cloud environment's variables.`;
|
|
1601
|
+
const cloudKeys = await listedKeys(sys, agent, token).catch((error) => {
|
|
1602
|
+
// fail-open: a list GitHub does not give is warned about below and makes no key.
|
|
1603
|
+
return { problem: detail(error) };
|
|
1604
|
+
});
|
|
1605
|
+
let makeKey = false;
|
|
1606
|
+
// A list GitHub does not give makes no key, which could be a second one: the warning says how to check.
|
|
1607
|
+
if ('problem' in cloudKeys)
|
|
1608
|
+
warnings.push(`cloud signing key not checked (${cloudKeys.problem}); niyam cloud-key ${agent} makes one`);
|
|
1609
|
+
else if (!cloudKeys.keys.some((one) => one.title === CLOUD_KEY_TITLE)) {
|
|
1610
|
+
if (dryRun || cloudKeyRefusal(sys) !== undefined)
|
|
1611
|
+
byHand.push(keyByHand);
|
|
1612
|
+
else {
|
|
1613
|
+
cloud.push({ label: 'signing key', detail: `for ${agent}, on the clipboard` });
|
|
1614
|
+
makeKey = true;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1560
1617
|
let pullUrl;
|
|
1561
1618
|
// Whether the pull request merges itself once its checks pass.
|
|
1562
1619
|
let merging = false;
|
|
@@ -1652,12 +1709,34 @@ export async function onboard(sys, io, args = []) {
|
|
|
1652
1709
|
if (log.length > 0)
|
|
1653
1710
|
notes.push(`- ${step.label}:`, ...log.map((line) => ` - ${line.trim().replace(/^[✓-] /, '')}`));
|
|
1654
1711
|
}
|
|
1712
|
+
// Last, once the pull request is open: a key that fails only warns, and nothing before it is undone.
|
|
1713
|
+
// A Ctrl-C that stops the key ends the run as one does.
|
|
1714
|
+
let exitCode = 0;
|
|
1715
|
+
if (makeKey) {
|
|
1716
|
+
let made = false;
|
|
1717
|
+
try {
|
|
1718
|
+
({ ok: made } = await runStep(sys, io, paint, `cloud signing key for ${agent}`, async (out) => {
|
|
1719
|
+
const code = await makeCloudKey(sys, out, agent, token);
|
|
1720
|
+
if (code === 130)
|
|
1721
|
+
exitCode = 130;
|
|
1722
|
+
return code === 0;
|
|
1723
|
+
}));
|
|
1724
|
+
}
|
|
1725
|
+
catch (error) {
|
|
1726
|
+
// fail-open: the pull request is open and every step before stands; the key's failure is said and left by hand below.
|
|
1727
|
+
io.err(`onboard: ${detail(error)}`);
|
|
1728
|
+
}
|
|
1729
|
+
if (made)
|
|
1730
|
+
byHand.unshift(`Now: ${SIGNING_KEY_VAR}=… is on the clipboard. ${pasteLines(agent, "each Claude cloud environment's").join(' ')}`);
|
|
1731
|
+
else {
|
|
1732
|
+
io.err(`onboard: ${agent} has no cloud signing key yet; everything before it is done`);
|
|
1733
|
+
byHand.push(keyByHand);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
for (const line of byHandLines(paint, byHand))
|
|
1737
|
+
io.out(line);
|
|
1655
1738
|
io.out(closing(paint, `${!pullUrl ? 'Done; no file changes, so no pull request.' : merging ? `${pullUrl} ${queue !== undefined ? 'the merge queue merges it' : 'merges itself'} when checks pass` : `Merge ${pullUrl}`}`));
|
|
1656
|
-
|
|
1657
|
-
io.out('By hand:');
|
|
1658
|
-
for (const line of byHand)
|
|
1659
|
-
io.out(` ${line}`);
|
|
1660
|
-
return 0;
|
|
1739
|
+
return exitCode;
|
|
1661
1740
|
}
|
|
1662
1741
|
/** How many times onboard asks GitHub about the test commit, waiting a little longer each time. */
|
|
1663
1742
|
export const COMMIT_ATTEMPTS = 5;
|