@veda-hq/niyam 0.7.13 → 0.7.15
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 +28 -7
- package/dist/agent.js +44 -2
- package/dist/doctor.js +2 -2
- package/dist/issue-types.js +1 -1
- package/dist/onboard.js +138 -10
- package/dist/owner-login.js +14 -8
- package/dist/release-tag.js +11 -5
- package/dist/session-start.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1207,7 +1207,16 @@ merges did not bring, as before. In an agent session, a push is refused when the
|
|
|
1207
1207
|
missing, or, with `work-rules` on, the session has no token. When the repository already has its own
|
|
1208
1208
|
pre-push hook, or git runs hooks from a folder outside the repository (a
|
|
1209
1209
|
global `core.hooksPath`), `onboard` leaves it alone and lists the line to add
|
|
1210
|
-
under "By hand:": `niyam pre-push "$@"`.
|
|
1210
|
+
under "By hand:": `niyam pre-push "$@"`. A hook that has the line, or one that
|
|
1211
|
+
hands its push to a body file through one `dvara run <file> "$@"` line whose
|
|
1212
|
+
body has it (#540), needs nothing. The line, and the variable's assignment
|
|
1213
|
+
if it names one, sit outside any `if`, `case`, loop or `{ }` block. The file
|
|
1214
|
+
is a literal path or one plain variable assigned once in the hook, before
|
|
1215
|
+
the hand-off, inside the repository and readable; any
|
|
1216
|
+
other hand-off still gets the By hand step, and a comment saying the line is
|
|
1217
|
+
elsewhere counts for nothing. A cloud session does not count such a body as
|
|
1218
|
+
checked, since a body may skip niyam there (athya-rules' does), and says only
|
|
1219
|
+
the pull request's checks may hold the work rules. The client workflow re-runs the checks when a
|
|
1211
1220
|
pull request's description is edited. After upgrading niyam, run
|
|
1212
1221
|
`onboard` again: it upgrades the hook entries in `.claude/settings.json` and
|
|
1213
1222
|
the workflow. An older release's workflow, one job that let every run write
|
|
@@ -1740,13 +1749,13 @@ the app's client id and private key are the `npm` environment's
|
|
|
1740
1749
|
package is on npm as `@veda-hq/niyam`, with provenance, for a repository that
|
|
1741
1750
|
pins it as an exact version; it publishes from the `npm` environment, which
|
|
1742
1751
|
only `main` may deploy to. A tag on any other commit is not a release:
|
|
1743
|
-
`niyam upgrade` and `niyam onboard` ask GitHub's compare API
|
|
1744
|
-
|
|
1745
|
-
|
|
1752
|
+
`niyam upgrade` and `niyam onboard` ask GitHub's compare API whether the
|
|
1753
|
+
tag's commit is on `main`, and refuse one that is not, naming the tag and the
|
|
1754
|
+
commit. `upgrade` asks with no token; `onboard` asks with the agent's. Install the attached package on each machine with pnpm,
|
|
1746
1755
|
once; nothing is built on install:
|
|
1747
1756
|
|
|
1748
1757
|
```bash
|
|
1749
|
-
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.
|
|
1758
|
+
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.15/veda-hq-niyam-0.7.15.tgz
|
|
1750
1759
|
```
|
|
1751
1760
|
|
|
1752
1761
|
The package puts one command on `PATH`, `niyam`. Since P-57 a release
|
|
@@ -1782,8 +1791,20 @@ CLI running, refuses and says to run `niyam upgrade` first.
|
|
|
1782
1791
|
|
|
1783
1792
|
`onboard` pins the client's workflow to one version, the release of the CLI
|
|
1784
1793
|
that ran it, and writes `.github/niyam/cloud-setup.sh` at the same one. First
|
|
1785
|
-
it asks GitHub's compare API
|
|
1786
|
-
|
|
1794
|
+
it asks GitHub's compare API whether that release's tag is on `main`; when it
|
|
1795
|
+
is not, or GitHub cannot say, it refuses and changes nothing.
|
|
1796
|
+
|
|
1797
|
+
onboard reads GitHub's public API (the release tag, who the owner and the
|
|
1798
|
+
agent are, whether an organisation owns the repository) with the agent's
|
|
1799
|
+
stored token (#546). Those reads then count against the token's 5,000 an hour.
|
|
1800
|
+
With no token they would share the 60 an hour every request from the Mac's
|
|
1801
|
+
address gets. Until the run knows its agent, it uses the agent named on the
|
|
1802
|
+
command line, else the agent the settings name, else any agent `machine` set
|
|
1803
|
+
up on the Mac. It never uses the owner's sign-in for these reads. When GitHub
|
|
1804
|
+
refuses the token (HTTP 401, and only then), the read is asked again with
|
|
1805
|
+
none, within the time the first ask had. When GitHub refuses a read for its
|
|
1806
|
+
rate limit (403 or 429 with `x-ratelimit-remaining: 0`), onboard names the
|
|
1807
|
+
limit, and when it resets if GitHub sends a valid `x-ratelimit-reset`.
|
|
1787
1808
|
Each job writes the pin twice, `checks.yml@vX.Y.Z` and, two lines
|
|
1788
1809
|
below it under `with:`, `niyam-ref: vX.Y.Z`, the one input `checks.yml`
|
|
1789
1810
|
declares; GitHub refuses a caller that passes an input the called workflow
|
package/dist/agent.js
CHANGED
|
@@ -407,18 +407,60 @@ export function quote(value) {
|
|
|
407
407
|
export function readToken(sys, agent) {
|
|
408
408
|
return tokenStore(sys)?.read(sys, agent);
|
|
409
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* What GitHub's refusal says when it is its rate limit, a 403 or 429 with
|
|
412
|
+
* `x-ratelimit-remaining: 0`, whose limit ran out, with no token the 60 an
|
|
413
|
+
* hour every request from this address shares (#546), and when it resets,
|
|
414
|
+
* from `x-ratelimit-reset` in UTC epoch seconds. Undefined for any other
|
|
415
|
+
* answer. GitHub's REST docs, "Rate limits for the REST API", section
|
|
416
|
+
* "Exceeding the rate limit" (read 2026-11-22; the link is on #546's PR).
|
|
417
|
+
*/
|
|
418
|
+
export function rateLimited(answer, token) {
|
|
419
|
+
const headers = answer.headers ?? {};
|
|
420
|
+
if ((answer.status !== 403 && answer.status !== 429) || headers['x-ratelimit-remaining'] !== '0')
|
|
421
|
+
return undefined;
|
|
422
|
+
const reset = Number(headers['x-ratelimit-reset']);
|
|
423
|
+
const until = Number.isInteger(reset) && reset > 0 ? ` until ${new Date(reset * 1000).toISOString().slice(11, 16)} UTC` : '';
|
|
424
|
+
const whose = token ? "GitHub's rate limit for the token" : "GitHub's limit for requests with no token, 60 an hour from this address,";
|
|
425
|
+
return `${whose} has run out${until} (HTTP ${answer.status})`;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* A read of GitHub's public API asked with `token`, so it counts against the
|
|
429
|
+
* token's limit rather than the one this address shares with no token (#546),
|
|
430
|
+
* and asked again with none only when GitHub refuses the token (401): a
|
|
431
|
+
* public read is answered without one. A `timeoutMs` bounds both asks
|
|
432
|
+
* together, the second getting what the first left, and none left gives the
|
|
433
|
+
* 401. Gives the token the answer came with.
|
|
434
|
+
*/
|
|
435
|
+
export async function publicRead(sys, url, token, options = {}) {
|
|
436
|
+
if (!token)
|
|
437
|
+
return { answer: await sys.http(url, options), token: undefined };
|
|
438
|
+
const started = sys.now().getTime();
|
|
439
|
+
const answer = await sys.http(url, { ...options, token });
|
|
440
|
+
if (answer.status !== 401)
|
|
441
|
+
return { answer, token };
|
|
442
|
+
if (options.timeoutMs === undefined)
|
|
443
|
+
return { answer: await sys.http(url, options), token: undefined };
|
|
444
|
+
const left = options.timeoutMs - (sys.now().getTime() - started);
|
|
445
|
+
return left > 0 ? { answer: await sys.http(url, { ...options, timeoutMs: left }), token: undefined } : { answer, token };
|
|
446
|
+
}
|
|
410
447
|
/**
|
|
411
448
|
* An account's numeric id and its login as GitHub spells it, from the public
|
|
412
449
|
* API. Logins are case-insensitive; the stored token's item, the session file and
|
|
413
450
|
* commits all use GitHub's spelling, whatever case the login was typed in.
|
|
414
451
|
* A refusal or a passing failure (403, 429, 5xx) is asked again after each of
|
|
415
|
-
* ACCOUNT_WAITS_MS; only a 404 says the account does not exist
|
|
452
|
+
* ACCOUNT_WAITS_MS; only a 404 says the account does not exist, and a rate
|
|
453
|
+
* limit run out, which no wait of seconds fixes, is said at once.
|
|
416
454
|
*/
|
|
417
455
|
export async function account(sys, login, token) {
|
|
418
456
|
for (let tries = 0;; tries++) {
|
|
419
|
-
const {
|
|
457
|
+
const { answer, token: used } = await publicRead(sys, `${API}/users/${login}`, token);
|
|
458
|
+
const { status, json } = answer;
|
|
420
459
|
if (status === 404)
|
|
421
460
|
throw new Error(`GitHub has no account "${login}" (HTTP 404)`);
|
|
461
|
+
const limited = rateLimited(answer, used);
|
|
462
|
+
if (limited)
|
|
463
|
+
throw new Error(`GitHub did not answer who account "${login}" is: ${limited}`);
|
|
422
464
|
const wait = ACCOUNT_WAITS_MS[tries];
|
|
423
465
|
if ((status === 403 || status === 429 || status >= 500) && wait !== undefined) {
|
|
424
466
|
await sys.sleep(wait);
|
package/dist/doctor.js
CHANGED
|
@@ -170,7 +170,7 @@ async function typesFindings(sys, token) {
|
|
|
170
170
|
const approvals = typeof named === 'number' ? named : undefined;
|
|
171
171
|
const org = slug.split('/')[0];
|
|
172
172
|
try {
|
|
173
|
-
return (await isOrganisation(sys, org)) ? [await typesDrift(sys, token, org, slug, approvals)] : [];
|
|
173
|
+
return (await isOrganisation(sys, org, token)) ? [await typesDrift(sys, token, org, slug, approvals)] : [];
|
|
174
174
|
}
|
|
175
175
|
catch (error) {
|
|
176
176
|
return [{ mark: '✗', text: `issue types: cannot ask GitHub (${message(error)})`, fix: 'niyam doctor again' }];
|
|
@@ -189,7 +189,7 @@ async function boardAppFindings(sys, token) {
|
|
|
189
189
|
return [];
|
|
190
190
|
const { slug } = here;
|
|
191
191
|
try {
|
|
192
|
-
if (!(await isOrganisation(sys, slug.split('/')[0])))
|
|
192
|
+
if (!(await isOrganisation(sys, slug.split('/')[0], token)))
|
|
193
193
|
return [];
|
|
194
194
|
const names = await secretNames(sys, slug, token);
|
|
195
195
|
if (names === undefined)
|
package/dist/issue-types.js
CHANGED
|
@@ -503,7 +503,7 @@ export async function issueType(sys, io) {
|
|
|
503
503
|
const event = JSON.parse(sys.read(eventPath));
|
|
504
504
|
const { approvals } = loadSettings(sys, sys.cwd);
|
|
505
505
|
if (name === 'schedule' && event.schedule === HOURLY) {
|
|
506
|
-
if (!(await isOrganisation(sys, slug.split('/')[0]))) {
|
|
506
|
+
if (!(await isOrganisation(sys, slug.split('/')[0], token))) {
|
|
507
507
|
io.out('issue-type: GitHub has issue types for organisations only; nothing to do');
|
|
508
508
|
return 0;
|
|
509
509
|
}
|
package/dist/onboard.js
CHANGED
|
@@ -127,11 +127,103 @@ export const OLDER_PRE_PUSH_HOOKS = [
|
|
|
127
127
|
'',
|
|
128
128
|
].join('\n'),
|
|
129
129
|
];
|
|
130
|
+
/** A line that runs the CLI's pre-push, in a hook or the body it hands off to. */
|
|
131
|
+
const RUNS_PRE_PUSH = /^\s*(?:exec\s+)?(?:"\$cli"|niyam)\s+pre-push\b/m;
|
|
132
|
+
/** A hook's hand-off to a body under dvara (`exec node_modules/.bin/dvara run "$B" "$@"`), the body as written. */
|
|
133
|
+
const DVARA_HANDOFF = /^\s*(?:exec\s+)?(?:\S*\/)?dvara\s+run\s+(\S+)\s+"\$@"\s*$/;
|
|
134
|
+
/** A plain assignment of a literal, `B=path` or `B="path"`. */
|
|
135
|
+
const ASSIGNMENT = /^\s*([A-Za-z_]\w*)=(\S+)\s*$/;
|
|
136
|
+
/** A word with its one pair of surrounding quotes taken off. */
|
|
137
|
+
function unquoted(word) {
|
|
138
|
+
const match = /^(["'])(.*)\1$/.exec(word);
|
|
139
|
+
return match ? match[2] : word;
|
|
140
|
+
}
|
|
141
|
+
/** A path inside `root` with its `.` and `..` read, lexically (pnpm's links stay as written), or undefined when it leaves `root`. */
|
|
142
|
+
function insideRoot(root, path) {
|
|
143
|
+
const parts = [];
|
|
144
|
+
for (const part of (path.startsWith('/') ? path : `${root}/${path}`).split('/')) {
|
|
145
|
+
if (part === '' || part === '.')
|
|
146
|
+
continue;
|
|
147
|
+
if (part === '..')
|
|
148
|
+
parts.pop();
|
|
149
|
+
else
|
|
150
|
+
parts.push(part);
|
|
151
|
+
}
|
|
152
|
+
const full = `/${parts.join('/')}`;
|
|
153
|
+
return full.startsWith(`${root}/`) ? full : undefined;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The body a hook hands its push to through `dvara run <file> "$@"`, when
|
|
157
|
+
* that body runs the CLI's pre-push (#540): one uncommented hand-off, its
|
|
158
|
+
* file a literal or one plain variable assigned once in the hook, inside the
|
|
159
|
+
* repository and there. dvara runs the file under bash with git's arguments
|
|
160
|
+
* and stdin, and skips nothing. Anything else is undefined, so the hook stays
|
|
161
|
+
* the client's own: a false "already wired" would leave an agent's push
|
|
162
|
+
* unchecked.
|
|
163
|
+
*/
|
|
164
|
+
/**
|
|
165
|
+
* How deep in the shell's blocks each line starts: `if`/`fi`, `case`/`esac`,
|
|
166
|
+
* `for`, `while` and `until` to `done`, and `{` to `}` (not `${`), counted as
|
|
167
|
+
* text. A line inside one may not run, so only depth 0 is taken as run.
|
|
168
|
+
*/
|
|
169
|
+
function blockDepths(lines) {
|
|
170
|
+
let depth = 0;
|
|
171
|
+
return lines.map((line) => {
|
|
172
|
+
const at = depth;
|
|
173
|
+
const count = (pattern, text) => text.match(pattern)?.length ?? 0;
|
|
174
|
+
const braces = line.replace(/\$\{[^}]*\}/g, '');
|
|
175
|
+
depth +=
|
|
176
|
+
count(/(?:^|[;&|(]\s*)(?:if|case|for|while|until)\b/g, line) -
|
|
177
|
+
count(/(?:^|[;&|]\s*)(?:fi|esac|done)\b/g, line) +
|
|
178
|
+
count(/\{/g, braces) -
|
|
179
|
+
count(/\}/g, braces);
|
|
180
|
+
return at;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function handedOffBody(sys, root, text) {
|
|
184
|
+
const lines = text.split('\n').filter((line) => !/^\s*#/.test(line));
|
|
185
|
+
const depths = blockDepths(lines);
|
|
186
|
+
const handoffs = lines.flatMap((line, at) => {
|
|
187
|
+
const word = DVARA_HANDOFF.exec(line)?.[1];
|
|
188
|
+
return word === undefined ? [] : [{ word, at }];
|
|
189
|
+
});
|
|
190
|
+
const handoff = handoffs.length === 1 ? handoffs[0] : undefined;
|
|
191
|
+
if (handoff === undefined || depths[handoff.at] !== 0)
|
|
192
|
+
return undefined;
|
|
193
|
+
let target = unquoted(handoff.word);
|
|
194
|
+
const variable = /^\$(?:([A-Za-z_]\w*)|\{([A-Za-z_]\w*)\})$/.exec(target);
|
|
195
|
+
if (variable) {
|
|
196
|
+
// Every line that sets the variable, in any form (`export B=`, `B+=`, `x && B=`), counts: one alone, plain, before the hand-off.
|
|
197
|
+
const name = variable[1] ?? variable[2];
|
|
198
|
+
const sets = new RegExp(`(?:^|[^\\w$])${name}\\+?=`);
|
|
199
|
+
const setting = lines.flatMap((line, at) => (sets.test(line) ? [{ line, at }] : []));
|
|
200
|
+
const only = setting.length === 1 ? setting[0] : undefined;
|
|
201
|
+
const match = only && only.at < handoff.at && depths[only.at] === 0 ? ASSIGNMENT.exec(only.line) : null;
|
|
202
|
+
if (!match || match[1] !== name)
|
|
203
|
+
return undefined;
|
|
204
|
+
target = unquoted(match[2]);
|
|
205
|
+
}
|
|
206
|
+
if (/[$`*?\\]/.test(target))
|
|
207
|
+
return undefined;
|
|
208
|
+
const body = insideRoot(root, target);
|
|
209
|
+
if (body === undefined || !sys.exists(body))
|
|
210
|
+
return undefined;
|
|
211
|
+
let bodyText;
|
|
212
|
+
try {
|
|
213
|
+
bodyText = sys.read(body);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
// fail-open: a folder or a file it cannot read is a hand-off it cannot check, so the hook stays the client's own.
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
return RUNS_PRE_PUSH.test(bodyText) ? body.slice(root.length + 1) : undefined;
|
|
220
|
+
}
|
|
130
221
|
/**
|
|
131
222
|
* The pre-push git hook git runs in the repository at `root`, and how it
|
|
132
223
|
* stands: outside the repository (a shared hooks folder, the owner's to
|
|
133
224
|
* change), missing, one an older release wrote, this release's or one that
|
|
134
|
-
* runs the CLI,
|
|
225
|
+
* runs the CLI, one that hands off to a body that runs it (`body`, #540), or
|
|
226
|
+
* the client's own.
|
|
135
227
|
*/
|
|
136
228
|
export function prePushHook(sys, root) {
|
|
137
229
|
const path = sys.exec('git', ['rev-parse', '--git-path', 'hooks/pre-push'], { cwd: root }).stdout.trim();
|
|
@@ -144,7 +236,10 @@ export function prePushHook(sys, root) {
|
|
|
144
236
|
const text = sys.read(file);
|
|
145
237
|
if (OLDER_PRE_PUSH_HOOKS.includes(text))
|
|
146
238
|
return { path, file, state: 'older' };
|
|
147
|
-
|
|
239
|
+
if (RUNS_PRE_PUSH.test(text))
|
|
240
|
+
return { path, file, state: 'ours' };
|
|
241
|
+
const body = handedOffBody(sys, root, text);
|
|
242
|
+
return body === undefined ? { path, file, state: 'own' } : { path, file, state: 'body', body };
|
|
148
243
|
}
|
|
149
244
|
/** How a hook finds the CLI: the launcher `machine` writes, else niyam on PATH. */
|
|
150
245
|
const FIND_CLI = `cli="${HOOK_LAUNCHER}"; [ -x "$cli" ] || cli=${CLI}; `;
|
|
@@ -1071,6 +1166,27 @@ export function claudeSettings(before, sarathiBefore) {
|
|
|
1071
1166
|
}
|
|
1072
1167
|
return { text, changes, labels, ...said };
|
|
1073
1168
|
}
|
|
1169
|
+
/** The agents the checkout's settings name; none when it has none, or settings onboard refuses later with the reason. */
|
|
1170
|
+
function settingsAgents(sys, root) {
|
|
1171
|
+
if (!sys.exists(`${root}/${SETTINGS_PATH}`))
|
|
1172
|
+
return [];
|
|
1173
|
+
try {
|
|
1174
|
+
return loadSettings(sys, root).agents;
|
|
1175
|
+
}
|
|
1176
|
+
catch {
|
|
1177
|
+
// fail-open: the settings branch reads them again and refuses them with the reason; here they only suggest a token.
|
|
1178
|
+
return [];
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
/** The token this Mac stores for the first of `agents` it has one for, or undefined. */
|
|
1182
|
+
function storedToken(sys, agents) {
|
|
1183
|
+
for (const agent of agents) {
|
|
1184
|
+
const token = readToken(sys, agent);
|
|
1185
|
+
if (token)
|
|
1186
|
+
return token;
|
|
1187
|
+
}
|
|
1188
|
+
return undefined;
|
|
1189
|
+
}
|
|
1074
1190
|
/** Who the run's sign-in is, the owner's likely login; undefined when it failed. */
|
|
1075
1191
|
async function signedInLogin(signIn) {
|
|
1076
1192
|
const signed = await signIn().catch(() => undefined);
|
|
@@ -1205,9 +1321,18 @@ export async function onboard(sys, io, args = []) {
|
|
|
1205
1321
|
const bar = paint.dim('│');
|
|
1206
1322
|
const say = (line) => io.out(`${bar} ${line}`);
|
|
1207
1323
|
const version = packageVersion();
|
|
1324
|
+
// The token onboard's public reads ask GitHub with, so they count against its limit and not the 60 an hour this
|
|
1325
|
+
// Mac's address shares with no token (#546), until the run knows its agent: the agent named, else the settings',
|
|
1326
|
+
// and only with neither any agent machine set up here. Never the owner's sign-in, whose scopes depend on whether an
|
|
1327
|
+
// organisation owns the repository.
|
|
1328
|
+
// The token's item is under the login as the session file spells it, whatever case it was typed or written in.
|
|
1329
|
+
const setUp = agentsSetUp(sys);
|
|
1330
|
+
const known = named[1] ? [named[1]] : settingsAgents(sys, root);
|
|
1331
|
+
const spelled = known.flatMap((login) => [login, ...setUp.filter((one) => one !== login && sameLogin(one, login))]);
|
|
1332
|
+
let readAs = storedToken(sys, known.length > 0 ? spelled : setUp);
|
|
1208
1333
|
// Whether an organisation owns the repository, asked of GitHub once in this run.
|
|
1209
1334
|
let organisation;
|
|
1210
|
-
const byOrganisation = () => (organisation ??= isOrganisation(sys, slug.split('/')[0]));
|
|
1335
|
+
const byOrganisation = () => (organisation ??= isOrganisation(sys, slug.split('/')[0], readAs));
|
|
1211
1336
|
const personal = `${slug} is owned by a personal account, and GitHub has issue types for organisations only`;
|
|
1212
1337
|
// The repository's files are changed only through the agent's pull request at the end: until then each
|
|
1213
1338
|
// change is held here, and read back from here, so the owner's checkout is never modified.
|
|
@@ -1244,7 +1369,7 @@ export async function onboard(sys, io, args = []) {
|
|
|
1244
1369
|
if (aheadHere !== undefined)
|
|
1245
1370
|
return refuseOlder(io, slug, aheadHere, version);
|
|
1246
1371
|
// The workflow and cloud-setup.sh pin this release: a tag off main is not one (P-61).
|
|
1247
|
-
const onMain = await tagOnMain(sys, version);
|
|
1372
|
+
const onMain = await tagOnMain(sys, version, readAs);
|
|
1248
1373
|
if ('problem' in onMain) {
|
|
1249
1374
|
io.err(`onboard: ${onMain.problem}; nothing changed`);
|
|
1250
1375
|
return 1;
|
|
@@ -1326,8 +1451,9 @@ export async function onboard(sys, io, args = []) {
|
|
|
1326
1451
|
notes.push(`- onboard signed in before showing its plan: ${SETTINGS_PATH} names several owners, and only the sign-in tells which one ran it.`);
|
|
1327
1452
|
}
|
|
1328
1453
|
// GitHub's spelling, which the keychain, the session file and commits use.
|
|
1329
|
-
owner = (await account(sys, chosenOwner)).login;
|
|
1330
|
-
agent = (await account(sys, here.agent)).login;
|
|
1454
|
+
owner = (await account(sys, chosenOwner, readAs)).login;
|
|
1455
|
+
agent = (await account(sys, here.agent, readAs)).login;
|
|
1456
|
+
readAs = readToken(sys, agent) ?? readAs;
|
|
1331
1457
|
// Before any change, so a refused --add leaves the settings as they were.
|
|
1332
1458
|
if (add && !features.includes(add) && NEEDS_ISSUE_TYPES.includes(add) && !(await byOrganisation())) {
|
|
1333
1459
|
io.err(`onboard: ${personal}, so ${add} cannot run here`);
|
|
@@ -1404,8 +1530,9 @@ export async function onboard(sys, io, args = []) {
|
|
|
1404
1530
|
if (!isLogin(login))
|
|
1405
1531
|
throw new Error(`"${login}" is not a GitHub login`);
|
|
1406
1532
|
}
|
|
1407
|
-
owner = (await account(sys, namedOwner)).login;
|
|
1408
|
-
agent = (await account(sys, namedAgent)).login;
|
|
1533
|
+
owner = (await account(sys, namedOwner, readAs)).login;
|
|
1534
|
+
agent = (await account(sys, namedAgent, readAs)).login;
|
|
1535
|
+
readAs = readToken(sys, agent) ?? readAs;
|
|
1409
1536
|
if (sameLogin(owner, agent)) {
|
|
1410
1537
|
io.err('onboard: the owner and the agent must be different accounts');
|
|
1411
1538
|
return 1;
|
|
@@ -1457,7 +1584,7 @@ export async function onboard(sys, io, args = []) {
|
|
|
1457
1584
|
io.err(`onboard: this Mac is not set up for ${agent} (${why}); run niyam machine ${agent}, then onboard again`);
|
|
1458
1585
|
return 1;
|
|
1459
1586
|
}
|
|
1460
|
-
const { id } = await account(sys, agent);
|
|
1587
|
+
const { id } = await account(sys, agent, token);
|
|
1461
1588
|
let reach = await access(sys, slug, token);
|
|
1462
1589
|
if (reach.kind === 'refused') {
|
|
1463
1590
|
io.err(`onboard: ${reach.reason}`);
|
|
@@ -1609,7 +1736,8 @@ export async function onboard(sys, io, args = []) {
|
|
|
1609
1736
|
},
|
|
1610
1737
|
});
|
|
1611
1738
|
}
|
|
1612
|
-
// Every adopter: the identity guard holds where the Claude Code hooks did not run.
|
|
1739
|
+
// Every adopter: the identity guard holds where the Claude Code hooks did not run. A hook that runs the CLI, or hands
|
|
1740
|
+
// off to a body that does (`body`, #540), needs nothing.
|
|
1613
1741
|
const hook = prePushHook(sys, root);
|
|
1614
1742
|
const hookLine = `${CLI} pre-push "$@"`;
|
|
1615
1743
|
if (hook.state === 'missing' || hook.state === 'older') {
|
package/dist/owner-login.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { API, sameLogin } from './agent.js';
|
|
1
|
+
import { API, publicRead, rateLimited, sameLogin } from './agent.js';
|
|
2
2
|
import { GITHUB_HOST } from './host.js';
|
|
3
3
|
/**
|
|
4
4
|
* The scopes beyond gh's own (repo, read:org, gist) that a run turning
|
|
@@ -10,13 +10,19 @@ export function ownerScopes(features, organisation) {
|
|
|
10
10
|
return [];
|
|
11
11
|
return organisation ? ['project', 'admin:org'] : ['project'];
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Whether GitHub names the account an organisation; throws when GitHub will
|
|
15
|
+
* not say, naming its rate limit when that is why. Asked with `token`, which
|
|
16
|
+
* every caller passes or says it has none of: with none, the read shares the
|
|
17
|
+
* 60 an hour every request from this address has (#546).
|
|
18
|
+
*/
|
|
19
|
+
export async function isOrganisation(sys, login, token) {
|
|
20
|
+
const { answer, token: used } = await publicRead(sys, `${API}/users/${login}`, token);
|
|
21
|
+
const type = answer.json?.type;
|
|
22
|
+
if (answer.status === 200 && typeof type === 'string')
|
|
23
|
+
return type === 'Organization';
|
|
24
|
+
const limited = rateLimited(answer, used);
|
|
25
|
+
throw new Error(`cannot tell whether ${login} is an organisation${limited ? `: ${limited}` : ` (HTTP ${answer.status})`}`);
|
|
20
26
|
}
|
|
21
27
|
/** gh's lines from a sign-in that tell the owner nothing they need: its sign-in tips and the setup it did in the temporary folder. */
|
|
22
28
|
const GH_CHATTER = [/Authentication complete/i, /git_protocol/, /Configured git protocol/i, /plain text/i, /Logged in as/i, /^Did you know/i, /^Tip\b/i];
|
package/dist/release-tag.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { API } from './agent.js';
|
|
1
|
+
import { API, publicRead, rateLimited } from './agent.js';
|
|
2
2
|
import { PRODUCT } from './names.js';
|
|
3
3
|
/** How long GitHub gets to compare a release tag with main. */
|
|
4
4
|
const COMPARE_MS = 15_000;
|
|
@@ -15,19 +15,25 @@ export const RELEASE_BRANCH = 'main';
|
|
|
15
15
|
* is on main. Both refs are written in full, so a branch named like the
|
|
16
16
|
* tag, or a tag named main, is never the one compared. Anything else is a
|
|
17
17
|
* refusal: a tag off main, no such tag, or no answer, each with its own
|
|
18
|
-
* words, so nothing is installed for want of one.
|
|
18
|
+
* words, so nothing is installed for want of one. `onboard` asks with the
|
|
19
|
+
* agent's token, so the compare does not share the 60 an hour this address
|
|
20
|
+
* has with no token (#546); a rate limit run out is named as one.
|
|
19
21
|
*/
|
|
20
|
-
export async function tagOnMain(sys, version) {
|
|
22
|
+
export async function tagOnMain(sys, version, token) {
|
|
21
23
|
const tag = `v${version}`;
|
|
22
|
-
let
|
|
24
|
+
let read;
|
|
23
25
|
try {
|
|
24
|
-
|
|
26
|
+
read = await publicRead(sys, `${API}/repos/${PRODUCT}/compare/refs/tags/${tag}...refs/heads/${RELEASE_BRANCH}?per_page=1`, token, { timeoutMs: COMPARE_MS });
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
29
|
return { problem: `GitHub could not be asked whether the ${tag} tag is on ${RELEASE_BRANCH} (${error instanceof Error ? error.message : String(error)})` };
|
|
28
30
|
}
|
|
31
|
+
const { answer } = read;
|
|
29
32
|
if (answer.status === 404)
|
|
30
33
|
return { problem: `${PRODUCT} has no ${tag} tag that GitHub can compare with ${RELEASE_BRANCH}` };
|
|
34
|
+
const limited = rateLimited(answer, read.token);
|
|
35
|
+
if (limited)
|
|
36
|
+
return { problem: `GitHub could not say whether the ${tag} tag is on ${RELEASE_BRANCH}: ${limited}` };
|
|
31
37
|
if (answer.status !== 200)
|
|
32
38
|
return { problem: `GitHub answered HTTP ${answer.status} when asked whether the ${tag} tag is on ${RELEASE_BRANCH}` };
|
|
33
39
|
const json = answer.json;
|
package/dist/session-start.js
CHANGED
|
@@ -172,7 +172,10 @@ async function cloudStart(sys) {
|
|
|
172
172
|
? ` Its pre-push hook ${hook.path} does not run niyam, so only the pull request's checks hold the work rules.`
|
|
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
|
+
: hook.state === 'body'
|
|
176
|
+
// A body may skip niyam in a cloud session (athya-rules' does), so its hand-off is not counted as checked here (#540).
|
|
177
|
+
? ` Its pre-push hook ${hook.path} hands off to ${hook.body}, which was not checked for a cloud session, so only the pull request's checks may hold the work rules.`
|
|
178
|
+
: '';
|
|
176
179
|
const signed = cloudCommits(sys, root, envFile, asked, pinnedCloudKeys(settings, asked.login));
|
|
177
180
|
return { line: `niyam: this cloud session works as ${asked.login} on GitHub.${unchecked}${signed}`, agent: asked.login };
|
|
178
181
|
}
|