@veda-hq/niyam 0.6.22 → 0.6.23

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.
@@ -0,0 +1,193 @@
1
+ import { API, account, agentFrom, checkToken, keyBody, signingKeys, tokenInfo } from './agent.js';
2
+ import { SIGNING_KEY_VAR } from './cloud.js';
3
+ import { CLAUDE_CODE_WEB } from './onboard.js';
4
+ import { agentSession } from './push-identity.js';
5
+ import { tokenStore, unsupported } from './token-store.js';
6
+ import { GITHUB_WEB } from './host.js';
7
+ /** The title the cloud signing keys have on GitHub, so the agent's can be told apart from a Mac's. */
8
+ export const CLOUD_KEY_TITLE = 'niyam cloud signing';
9
+ /** Where the agent's signing keys are deleted, signed in as the agent. */
10
+ const KEYS_PAGE = `${GITHUB_WEB}/settings/keys`;
11
+ /** cloud-key's arguments: the agent, then `--yes`. */
12
+ export function cloudKeyArgs(args) {
13
+ let named;
14
+ let yes = false;
15
+ for (const arg of args) {
16
+ if (arg === '--yes')
17
+ yes = true;
18
+ else if (arg.startsWith('--'))
19
+ throw new Error(`unknown option ${arg}`);
20
+ else if (named === undefined)
21
+ named = arg;
22
+ else
23
+ throw new Error(`unexpected argument "${arg}"`);
24
+ }
25
+ return { ...(named === undefined ? {} : { named }), ...(yes ? { yes: true } : {}) };
26
+ }
27
+ /**
28
+ * Sets up the agent's cloud signing key from the owner's Mac (#405): a new
29
+ * ed25519 key, in a private temporary folder, registered as the agent's
30
+ * signing key with the token `machine` stored, titled CLOUD_KEY_TITLE; once
31
+ * GitHub lists it, `NIYAM_SIGNING_KEY=<the private key, base64>` goes on the
32
+ * clipboard, for the cloud environment's variables, and the folder is
33
+ * removed, a Ctrl-C included. The key is never printed. When the clipboard
34
+ * does not take it, the key just registered is deleted again, since no one
35
+ * holds it. It names the agent's other cloud signing keys, for the owner to
36
+ * delete one no environment uses; it deletes none itself. Refuses in an agent
37
+ * session or a cloud session, where the token is not the owner's to use, and
38
+ * asks once before it changes anything (`--yes` skips the question).
39
+ */
40
+ export async function cloudKey(sys, io, args = []) {
41
+ const { named, yes } = cloudKeyArgs(args);
42
+ if (agentSession(sys) || sys.env.CLAUDE_CODE_REMOTE === 'true') {
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
+ }
46
+ const store = tokenStore(sys);
47
+ if (!store) {
48
+ io.err(`cloud-key: ${unsupported(sys)}`);
49
+ return 1;
50
+ }
51
+ const { login: agent } = await account(sys, agentFrom(sys, named));
52
+ const token = store.read(sys, agent);
53
+ if (!token) {
54
+ io.err(`cloud-key: ${store.where} has no ${agent} token; run niyam machine ${agent} first`);
55
+ return 1;
56
+ }
57
+ const check = checkToken(token, await tokenInfo(sys, token), agent, sys.now());
58
+ if (check.problem !== undefined) {
59
+ io.err(`cloud-key: the stored ${agent} token cannot be used: ${check.problem}; run niyam machine ${agent}`);
60
+ return 1;
61
+ }
62
+ const before = await listedKeys(sys, agent, token);
63
+ if ('problem' in before) {
64
+ io.err(`cloud-key: ${before.problem}`);
65
+ return 1;
66
+ }
67
+ io.out(`cloud-key: a new signing key for ${agent}'s Claude cloud sessions, registered on GitHub as ${agent} ("${CLOUD_KEY_TITLE}"),`);
68
+ io.out(` its private key put on the clipboard as ${SIGNING_KEY_VAR}=…, for a cloud environment's variables. Nothing is printed.`);
69
+ const others = before.keys.filter((one) => one.title === CLOUD_KEY_TITLE);
70
+ if (!yes) {
71
+ if (!sys.tty) {
72
+ io.err('cloud-key: no terminal to ask in; pass --yes to go ahead without asking');
73
+ return 1;
74
+ }
75
+ if (!(await sys.choose('Go ahead?'))) {
76
+ io.out('Nothing changed.');
77
+ return 1;
78
+ }
79
+ }
80
+ const dir = sys.tempDir();
81
+ let removed = false;
82
+ const cleanUp = () => {
83
+ if (!removed) {
84
+ try {
85
+ sys.remove(dir);
86
+ }
87
+ catch {
88
+ // fail-open: said below, with the command that removes it.
89
+ }
90
+ removed = !sys.exists(dir);
91
+ }
92
+ return removed;
93
+ };
94
+ let interrupted = false;
95
+ const off = sys.onInterrupt(() => {
96
+ interrupted = true;
97
+ cleanUp();
98
+ });
99
+ let code = 1;
100
+ try {
101
+ code = await makeAndRegister(sys, io, agent, token, `${dir}/key`, others, () => interrupted);
102
+ }
103
+ finally {
104
+ 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
+ }
113
+ return code;
114
+ }
115
+ /**
116
+ * Makes the key at `key`, registers it, and puts it on the clipboard; each
117
+ * step one line. The key is read before it is registered, so a Ctrl-C that
118
+ * removes the files leaves it to delete from GitHub again, which it is.
119
+ */
120
+ async function makeAndRegister(sys, io, agent, token, key, others, interrupted) {
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')}`;
130
+ const posted = await sys.http(`${API}/user/ssh_signing_keys`, { method: 'POST', token, body: { title: CLOUD_KEY_TITLE, key: publicKey } });
131
+ const id = posted.json?.id;
132
+ if (posted.status !== 201 || typeof id !== 'number') {
133
+ io.out(`✗ GitHub did not register the key as ${agent}'s signing key (HTTP ${posted.status}); nothing is on the clipboard`);
134
+ return 1;
135
+ }
136
+ let listed = false;
137
+ try {
138
+ listed = (await signingKeys(sys, agent, token)).includes(keyBody(publicKey));
139
+ }
140
+ catch {
141
+ // fail-open: a list GitHub does not give counts as not listing it, and the key is deleted again.
142
+ }
143
+ if (interrupted()) {
144
+ await unregister(sys, io, token, id, 'stopped by Ctrl-C');
145
+ return 130;
146
+ }
147
+ if (!listed) {
148
+ await unregister(sys, io, token, id, 'GitHub does not list it');
149
+ return 1;
150
+ }
151
+ io.out(`✓ registered as ${agent}'s signing key "${CLOUD_KEY_TITLE}" (id ${id})`);
152
+ const copied = sys.exec('/usr/bin/pbcopy', [], { input: line });
153
+ if (copied.code !== 0) {
154
+ await unregister(sys, io, token, id, `the clipboard did not take the key (${copied.stderr.trim() || `exit ${copied.code}`})`);
155
+ return 1;
156
+ }
157
+ io.out(`✓ ${SIGNING_KEY_VAR}=… is on the clipboard`);
158
+ io.out(` Paste it as one line into the cloud environment's variables: ${CLAUDE_CODE_WEB} → the environment's settings.`);
159
+ io.out(` A new session there makes ${agent}'s commits its own; its first niyam line says so.`);
160
+ for (const other of others) {
161
+ 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
+ }
163
+ return 0;
164
+ }
165
+ function stopped(io) {
166
+ io.out('✗ stopped by Ctrl-C; nothing registered, and nothing on the clipboard');
167
+ return 130;
168
+ }
169
+ /** Deletes the key just registered, which no one holds, and says why. */
170
+ async function unregister(sys, io, token, id, why) {
171
+ let status = 0;
172
+ try {
173
+ ({ status } = await sys.http(`${API}/user/ssh_signing_keys/${id}`, { method: 'DELETE', token }));
174
+ }
175
+ catch {
176
+ // fail-open: said below, with where to delete the key by hand.
177
+ }
178
+ io.out(status === 204
179
+ ? `✗ ${why}, so the key was deleted from GitHub again; nothing is on the clipboard`
180
+ : `✗ ${why}, and deleting the key from GitHub again failed (HTTP ${status}) → delete signing key ${id} at ${KEYS_PAGE}`);
181
+ }
182
+ /** 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) {
184
+ const { status, json } = await sys.http(`${API}/user/ssh_signing_keys?per_page=100`, { token });
185
+ if (status !== 200 || !Array.isArray(json))
186
+ return { problem: `GitHub answered HTTP ${status} when asked for ${agent}'s signing keys` };
187
+ return {
188
+ keys: json.flatMap((entry) => {
189
+ const { id, title, created_at: created } = (entry ?? {});
190
+ return typeof id === 'number' ? [{ id, title: typeof title === 'string' ? title : '', created: typeof created === 'string' ? created : '' }] : [];
191
+ }),
192
+ };
193
+ }
package/dist/cloud.js CHANGED
@@ -1,4 +1,4 @@
1
- import { API, isNoToken } from './agent.js';
1
+ import { API, BASE_ENV, authorVars, configVars, isNoToken, keyBody, noreplyEmail, pathsFor, signingConfig } from './agent.js';
2
2
  import { CLAUDE_CODE_WEB, SETUP_FIRST, workflowPins } from './onboard.js';
3
3
  import { PRODUCT, tarballName } from './names.js';
4
4
  import { CLOUD_SETUP_PATH, WORKFLOW_PATH } from './onboard-pull.js';
@@ -14,17 +14,135 @@ export function cloudToken(sys) {
14
14
  const token = sys.env.GH_TOKEN;
15
15
  return token && !isNoToken(token) ? token : PROXY_TOKEN;
16
16
  }
17
- /** The account a cloud session reaches GitHub as, through its proxy, or why it cannot be told. */
17
+ /**
18
+ * The account a cloud session reaches GitHub as, through its proxy, or why it
19
+ * cannot be told; with the account's id from the same answer, when it names
20
+ * a valid one, for the agent's no-reply address.
21
+ */
18
22
  export async function cloudLogin(sys) {
19
23
  try {
20
24
  const { status, json } = await sys.http(`${API}/user`, { token: cloudToken(sys) });
21
- const login = json?.login;
22
- return status === 200 && typeof login === 'string' ? { login } : { problem: `GitHub answered HTTP ${status} when asked who this session is` };
25
+ const { login, id } = json ?? {};
26
+ if (status !== 200 || typeof login !== 'string')
27
+ return { problem: `GitHub answered HTTP ${status} when asked who this session is` };
28
+ return typeof id === 'number' && Number.isSafeInteger(id) && id > 0 ? { login, id } : { login };
23
29
  }
24
30
  catch (error) {
25
31
  return { problem: `GitHub could not be asked who this session is (${error instanceof Error ? error.message : String(error)})` };
26
32
  }
27
33
  }
34
+ /**
35
+ * The cloud environment's variable that holds the agent's cloud signing key:
36
+ * an OpenSSH private key, base64 on one line or as is. A key of its own, not
37
+ * a Mac's, registered as one of the agent's signing keys, so it is revoked
38
+ * on its own.
39
+ */
40
+ export const SIGNING_KEY_VAR = 'NIYAM_SIGNING_KEY';
41
+ /** The message of the probe commit `cloudSigning` signs. */
42
+ const PROBE_MESSAGE = 'niyam: a probe of the agent\'s signing, never on a branch';
43
+ /**
44
+ * What makes a cloud session's commits the agent's: its author and committer
45
+ * variables, with the address of the id GitHub gave with the login, and SSH
46
+ * 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` goes back to
48
+ * ssh-keygen). All of them or none, since a commit that claims the agent
49
+ * must be Verified as the agent (PR identity) and a signing setup that fails
50
+ * breaks every commit: each is given only when the key is one GitHub lists
51
+ * for the agent and a probe commit signed with exactly these settings, in
52
+ * the clone at `root`, verifies as that key's. The probe is an object on no
53
+ * branch, which git's housekeeping drops. Otherwise why not, and the session
54
+ * keeps the cloud image's identity.
55
+ */
56
+ export async function cloudSigning(sys, root, login, id) {
57
+ const given = sys.env[SIGNING_KEY_VAR]?.trim();
58
+ if (!given)
59
+ 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)` };
60
+ if (id === undefined)
61
+ return { problem: `GitHub named no account id for ${login}` };
62
+ const text = (given.includes(PEM_BEGIN) ? given.replaceAll('\\n', '\n') : Buffer.from(given, 'base64').toString('utf8')).trim();
63
+ if (!text.startsWith(`${PEM_BEGIN}\n`) || !text.endsWith(`\n${PEM_END}`)) {
64
+ return { problem: `${SIGNING_KEY_VAR} is not an OpenSSH private key, base64 on one line or as is` };
65
+ }
66
+ const { dir, key } = pathsFor(sys.home, login);
67
+ const pub = `${key}.pub`;
68
+ const signers = `${dir}/allowed-signers`;
69
+ const email = noreplyEmail(id, login);
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);
83
+ const listed = await listedSigningKeys(sys, login);
84
+ if ('problem' in listed)
85
+ return listed;
86
+ if (!listed.keys.includes(body))
87
+ return { problem: `GitHub does not list ${SIGNING_KEY_VAR}'s public half as one of ${login}'s signing keys` };
88
+ try {
89
+ sys.write(pub, `${body} ${login} cloud signing\n`, 0o644);
90
+ sys.write(signers, `${email} namespaces="git" ${body}\n`, 0o644);
91
+ }
92
+ catch (error) {
93
+ // fail-open: the session keeps the image's identity, which PR identity passes, and says why.
94
+ return { problem: `writing ${pub} failed (${messageOf(error)})` };
95
+ }
96
+ const vars = [...authorVars(login, id), ...configVars([['gpg.ssh.program', 'ssh-keygen'], ...signingConfig(pub)])];
97
+ const probe = probeSignature(sys, root, vars, signers);
98
+ return probe ? { problem: `a probe commit signed with ${SIGNING_KEY_VAR} did not verify as that key (${probe})` } : { vars };
99
+ }
100
+ const PEM_BEGIN = '-----BEGIN OPENSSH PRIVATE KEY-----';
101
+ const PEM_END = '-----END OPENSSH PRIVATE KEY-----';
102
+ /** The signing keys GitHub's public list names for `login`, asked through the proxy, or why they cannot be had. */
103
+ async function listedSigningKeys(sys, login) {
104
+ let answer;
105
+ try {
106
+ answer = await sys.http(`${API}/users/${encodeURIComponent(login)}/ssh_signing_keys?per_page=100`, { token: cloudToken(sys) });
107
+ }
108
+ catch (error) {
109
+ // fail-open: the session keeps the image's identity, which PR identity passes, and says why.
110
+ return { problem: `GitHub could not be asked for ${login}'s signing keys (${messageOf(error)})` };
111
+ }
112
+ if (answer.status !== 200 || !Array.isArray(answer.json))
113
+ return { problem: `GitHub answered HTTP ${answer.status} when asked for ${login}'s signing keys` };
114
+ return {
115
+ keys: answer.json.flatMap((entry) => {
116
+ const key = entry?.key;
117
+ return typeof key === 'string' ? [keyBody(key)] : [];
118
+ }),
119
+ };
120
+ }
121
+ /**
122
+ * Makes a commit object on no branch with the environment `vars` give, and
123
+ * verifies its signature against `signers`, the agent's key alone: undefined
124
+ * when it verifies, else what failed.
125
+ */
126
+ function probeSignature(sys, root, vars, signers) {
127
+ // The session's commands get the env file's lines, which unset the lock first: the probe does the same.
128
+ const base = Object.fromEntries(Object.entries(sys.env).filter(([name]) => !(name in BASE_ENV) && name !== SIGNING_KEY_VAR));
129
+ const env = { ...base, ...Object.fromEntries(vars) };
130
+ const tree = sys.exec('git', ['mktree'], { cwd: root, env, input: '' });
131
+ if (tree.code !== 0)
132
+ return `git mktree: ${lastLine(tree.stderr) || `exit ${tree.code}`}`;
133
+ // commit-tree reads no commit.gpgsign: -S signs as `git commit` would, with the key and program the settings name.
134
+ const commit = sys.exec('git', ['commit-tree', '-S', tree.stdout.trim(), '-m', PROBE_MESSAGE], { cwd: root, env, input: '' });
135
+ if (commit.code !== 0)
136
+ return `git commit-tree: ${lastLine(commit.stderr) || `exit ${commit.code}`}`;
137
+ const verified = sys.exec('git', ['-c', `gpg.ssh.allowedSignersFile=${signers}`, 'verify-commit', commit.stdout.trim()], { cwd: root, env, input: '' });
138
+ return verified.code === 0 ? undefined : `git verify-commit: ${lastLine(verified.stderr) || 'no signature by that key'}`;
139
+ }
140
+ function lastLine(text) {
141
+ return text.trim().split('\n').at(-1) ?? '';
142
+ }
143
+ function messageOf(error) {
144
+ return error instanceof Error ? error.message : String(error);
145
+ }
28
146
  /** The Node a Claude cloud session runs the CLI with: its image's own is older than the CLI needs. */
29
147
  export const CLOUD_NODE = '24.21.0';
30
148
  /** The sha256 of CLOUD_NODE's Linux builds, from nodejs.org's SHASUMS256.txt for that release. */
package/dist/doctor.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import { EXPIRY_WARNING_DAYS, SETTINGS_PATH, account, agentFrom, agentIn, anyLogin, either, hasSettings, loadSettings, repoAt, sameLogin, checkToken, keyBody, keyPairProblem, launcherPath, pathsFor, sessionFileIs, signingKeys, tokenInfo, } from './agent.js';
2
2
  import { LOCKED, clientHooks, hooksHittingLock } from './as-agent.js';
3
- import { FROM_SETUP, cloudLogin, fileFromSetup, ranFromSetup, repoReleases } from './cloud.js';
3
+ import { FROM_SETUP, SIGNING_KEY_VAR, cloudLogin, fileFromSetup, ranFromSetup, repoReleases } from './cloud.js';
4
+ import { GITHUB_NOREPLY } from './host.js';
4
5
  import { featuresIn } from './features.js';
5
6
  import { typesDrift } from './issue-types.js';
6
7
  import { closing, findingLines, heading, painter, tilde } from './layout.js';
7
8
  import { exposure, exposureFindings, movedFindings, readDeclined, setAside } from './lockout.js';
8
9
  import { CLOUD_SETUP_PATH, HOOKS_PATH, SARATHI_PATH } from './onboard-pull.js';
9
10
  import { leftoverDir, leftoverToken } from './machine.js';
10
- import { 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, missingAutoFixRules, sarathiRunner } from './onboard.js';
12
+ import { secretNames } from './secrets.js';
11
13
  import { isOrganisation } from './owner-login.js';
12
14
  import { leftBehind } from './owner-step.js';
13
15
  import { repoRoot } from './session-start.js';
@@ -88,6 +90,7 @@ export async function doctor(sys, io, named) {
88
90
  return registered ? { mark: '✓', text: 'signing key registered' } : { mark: '✗', text: 'signing key not registered', fix: MACHINE };
89
91
  }),
90
92
  ...(await typesFindings(sys, token)),
93
+ ...(await boardAppFindings(sys, token)),
91
94
  ];
92
95
  return report(sys, io, agent, [
93
96
  ['This Mac', mac],
@@ -134,30 +137,36 @@ function leftoverFindings(sys, store, agent) {
134
137
  ];
135
138
  }
136
139
  /**
137
- * Whether the organisation's enabled issue types are the work model's, no
138
- * issue here holds another, and every open one here has one but the
139
- * Approvals issue: checked in a repository whose settings turn the board on,
140
- * in an organisation, since onboard keeps them so there.
140
+ * The repository doctor runs in and its settings, parsed, where they turn
141
+ * the board on and doctor has a token to ask GitHub with; else undefined.
141
142
  */
142
- async function typesFindings(sys, token) {
143
- let slug;
144
- let approvals;
143
+ function boardRepo(sys, token) {
145
144
  try {
146
145
  const found = repoAt(sys);
147
146
  const path = `${found.root}/${SETTINGS_PATH}`;
148
147
  if (!token || !sys.exists(path))
149
- return [];
148
+ return undefined;
150
149
  const settings = JSON.parse(sys.read(path));
151
- if (!featuresIn(settings).includes('board'))
152
- return [];
153
- slug = found.slug;
154
- const named = settings?.approvals;
155
- approvals = typeof named === 'number' ? named : undefined;
150
+ return featuresIn(settings).includes('board') ? { slug: found.slug, settings } : undefined;
156
151
  }
157
152
  catch {
158
153
  // Outside a client's clone, or settings doctor cannot read: onboard says what is wrong with them.
159
- return [];
154
+ return undefined;
160
155
  }
156
+ }
157
+ /**
158
+ * Whether the organisation's enabled issue types are the work model's, no
159
+ * issue here holds another, and every open one here has one but the
160
+ * Approvals issue: checked in a repository whose settings turn the board on,
161
+ * in an organisation, since onboard keeps them so there.
162
+ */
163
+ async function typesFindings(sys, token) {
164
+ const here = boardRepo(sys, token);
165
+ if (!here || !token)
166
+ return [];
167
+ const { slug, settings } = here;
168
+ const named = settings?.approvals;
169
+ const approvals = typeof named === 'number' ? named : undefined;
161
170
  const org = slug.split('/')[0];
162
171
  try {
163
172
  return (await isOrganisation(sys, org)) ? [await typesDrift(sys, token, org, slug, approvals)] : [];
@@ -166,6 +175,34 @@ async function typesFindings(sys, token) {
166
175
  return [{ mark: '✗', text: `issue types: cannot ask GitHub (${message(error)})`, fix: 'niyam doctor again' }];
167
176
  }
168
177
  }
178
+ /**
179
+ * Whether the repository has the board app's secrets, which the Slice started
180
+ * job moves a slice to In Progress with when its pull request opens (P-70):
181
+ * checked where the settings turn the board on, in an organisation. A missing
182
+ * one is worth fixing, never broken, since the desktop push still moves the
183
+ * board; secrets GitHub will not list say nothing.
184
+ */
185
+ async function boardAppFindings(sys, token) {
186
+ const here = boardRepo(sys, token);
187
+ if (!here || !token)
188
+ return [];
189
+ const { slug } = here;
190
+ try {
191
+ if (!(await isOrganisation(sys, slug.split('/')[0])))
192
+ return [];
193
+ const names = await secretNames(sys, slug, token);
194
+ if (names === undefined)
195
+ return [];
196
+ const missing = BOARD_SECRETS.filter((name) => !names.includes(name));
197
+ return missing.length === 0
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}, which says how to set up the board app` }];
200
+ }
201
+ catch (error) {
202
+ // fail-open: a read that failed is the one ▲ here, as a missing secret breaks nothing.
203
+ return [{ mark: '▲', text: `board app secrets: cannot ask GitHub (${message(error)})`, fix: 'niyam doctor again' }];
204
+ }
205
+ }
169
206
  /**
170
207
  * Client hooks that reach GitHub outside `as-agent` where doctor runs, a Mac
171
208
  * or a cloud session, and the Auto-fix rules an onboarded repo's Claude Code
@@ -343,6 +380,9 @@ async function cloudDoctor(sys, io, named) {
343
380
  text: 'session-start did not give this session the agent identity, so gh and git stay locked out',
344
381
  fix: 'a new session; its first niyam line says why',
345
382
  });
383
+ const agent = given ?? ('login' in asked ? asked.login : undefined);
384
+ if (agent !== undefined)
385
+ github.push(cloudCommits(sys, agent));
346
386
  const about = 'login' in asked ? asked.login : agents !== undefined ? either(agents) : 'this cloud session';
347
387
  return report(sys, io, about, [
348
388
  ['This cloud session', session],
@@ -350,6 +390,27 @@ async function cloudDoctor(sys, io, named) {
350
390
  ['This repo', repoFindings(sys)],
351
391
  ]);
352
392
  }
393
+ /**
394
+ * Whose a cloud session's commits are: the agent's when session-start gave it
395
+ * the agent's author and signing (the key in SIGNING_KEY_VAR), else Claude's,
396
+ * which PR identity passes, so a warning only, with what makes them the
397
+ * agent's.
398
+ */
399
+ function cloudCommits(sys, agent) {
400
+ const name = sys.env.GIT_AUTHOR_NAME;
401
+ const email = sys.env.GIT_AUTHOR_EMAIL?.toLowerCase() ?? '';
402
+ if (name !== undefined && sameLogin(name, agent) && /^\d+\+/.test(email) && email.endsWith(`+${agent.toLowerCase()}@${GITHUB_NOREPLY}`)) {
403
+ return { mark: '✓', text: `this session's commits are ${agent}'s, signed with ${SIGNING_KEY_VAR}` };
404
+ }
405
+ if (sys.env[SIGNING_KEY_VAR]) {
406
+ return { mark: '▲', text: `${SIGNING_KEY_VAR} is set, but session-start could not use it, so this session's commits are Claude's`, fix: 'a new session; its first niyam line says why' };
407
+ }
408
+ return {
409
+ mark: '▲',
410
+ text: `this session's commits are Claude's: the cloud environment's variables have no ${SIGNING_KEY_VAR}`,
411
+ fix: `niyam cloud-key ${agent} on your Mac, then paste it into the environment's variables`,
412
+ };
413
+ }
353
414
  function message(error) {
354
415
  return error instanceof Error ? error.message : String(error);
355
416
  }