@veda-hq/niyam 0.7.11 → 0.7.13

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 CHANGED
@@ -1408,7 +1408,12 @@ run in the client repo, warns under "This repo" about each hook in `.claude/sett
1408
1408
  calls `gh` or git's remote commands outside `as-agent`. A script that
1409
1409
  imports a Python module tracked in the repo whose code runs `as-agent` (a
1410
1410
  helper wrapping each `gh` call) counts as routed through it; the hook's
1411
- command is still judged. Outside a cloud session, a script is read only up
1411
+ command is still judged. So does a script that builds its gh in the
1412
+ positional parameters and runs it as `"$@"`: `set -- gh`, then, where
1413
+ niyam's launcher is, `set -- "$cli" as-agent --session "$sid" -- gh`. Its
1414
+ plain `set -- gh` is the cloud's, whose proxy authenticates it, so it is not
1415
+ counted; every other `gh` in the script still is, and `set -- gh` with no
1416
+ `as-agent` form beside it counts. Outside a cloud session, a script is read only up
1412
1417
  to a line, at column 0, that exits there,
1413
1418
  `[ "${CLAUDE_CODE_REMOTE:-}" = true ] || exit 0` or
1414
1419
  `[ "$CLAUDE_CODE_REMOTE" != true ] && exit`, when only blank lines, `set`,
@@ -1741,7 +1746,7 @@ tag and the commit. Install the attached package on each machine with pnpm,
1741
1746
  once; nothing is built on install:
1742
1747
 
1743
1748
  ```bash
1744
- pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.11/veda-hq-niyam-0.7.11.tgz
1749
+ pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.13/veda-hq-niyam-0.7.13.tgz
1745
1750
  ```
1746
1751
 
1747
1752
  The package puts one command on `PATH`, `niyam`. Since P-57 a release
@@ -1863,7 +1868,8 @@ goes on. Any other failure to read it fails closed.
1863
1868
  - opened as `mergify[bot]` on a `mergify/merge-queue/` branch of the repository;
1864
1869
  - titled `merge queue: checking #A on main (sha)`, or `#A + #B together` for a batch (#524);
1865
1870
  - with `, stacked on #B` when it tests several;
1866
- - or, from four ahead, `, stacked on N pull requests ahead`, whose numbers come from the body's `### Queued ahead of this batch` list, only when it names exactly N.
1871
+ - or, from four ahead, `, stacked on N pull requests ahead`, whose numbers come from the body's `### Queued ahead of this batch` list, only when it names exactly N;
1872
+ - once it has merged #A and closed the draft, retitled `merge queue: merged #A: <A's title>`, read as testing #A alone (#532). Only the number after `merged #` is read: the rest is #A's own title. That edit runs Guard and PR identity again, and they judge the closed draft as they did while it was checking #A.
1867
1873
 
1868
1874
  `scripts/merge-queue.mjs`, a guard file that imports nothing, reads this for Guard and for PR identity alike.
1869
1875
 
package/dist/as-agent.js CHANGED
@@ -129,8 +129,12 @@ const OWN_COMMANDS = new Set([HOOK_COMMAND, GUARD_COMMAND, ...OLDER_HOOK_COMMAND
129
129
  * reads text, so a script that runs another script is missed. Comments and
130
130
  * docstrings are left out, so prose that names gh or git push is not a call.
131
131
  * A script that loads a repo helper running `as-agent` is taken as routed
132
- * through it (`routedByHelper`). Outside a cloud session, a script is read
133
- * only up to a top-level line that exits there (`CLOUD_ONLY`).
132
+ * through it (`routedByHelper`). A script that sets its positional
133
+ * parameters to `as-agent` running gh and runs `"$@"` is taken as routed,
134
+ * its plain `set -- gh` being the cloud's (`withoutRoutedSetGh`); read as
135
+ * text, so which `"$@"` runs which is not followed. Outside a cloud session,
136
+ * a script is read only up to a top-level line that exits there
137
+ * (`CLOUD_ONLY`), before either form is looked for.
134
138
  */
135
139
  export function hooksHittingLock(sys) {
136
140
  const top = sys.exec('git', ['rev-parse', '--show-toplevel'], { cwd: sys.cwd });
@@ -147,7 +151,7 @@ export function hooksHittingLock(sys) {
147
151
  const judgedScript = script && !routedByHelper(sys, root, script.text) ? script : undefined;
148
152
  const [line, code] = [withoutComments(command), withoutComments(judgedScript?.text ?? '')];
149
153
  const judged = cloud ? `${line}\n${code}` : `${beforeCloudOnly(line)}\n${beforeCloudOnly(code)}`;
150
- if (reachesGitHub(withoutAsAgent(judged)))
154
+ if (reachesGitHub(withoutAsAgent(withoutRoutedSetGh(judged))))
151
155
  found.push(`${file} ${event} ${kind} ${judgedScript ? judgedScript.path : JSON.stringify(command)}`);
152
156
  }
153
157
  return found;
@@ -308,6 +312,27 @@ function routedByHelper(sys, root, script) {
308
312
  }
309
313
  });
310
314
  }
315
+ /** A command that only puts gh in the positional parameters, for `"$@"` to run: `set -- gh …`, with no command substitution in it. */
316
+ const SET_GH = /^\s*(?:(?:then|else|do)\s+)?set\s+--\s+gh(?:\s(?:(?!\$\(|`).)*)?$/;
317
+ /** One that puts `as-agent` running gh there instead: `set -- "$cli" as-agent --session "$sid" -- gh …`. */
318
+ const SET_AS_AGENT_GH = /^\s*(?:(?:then|else|do)\s+)?set\s+--\s+.*\bas-agent\s.*\s--\s+gh(?:\s|$)/;
319
+ /**
320
+ * The text without its `set -- gh` commands, when it also has a
321
+ * `set -- … as-agent … -- gh`: a script that builds its gh in the
322
+ * positional parameters and runs it as `"$@"` has gh plain only where it
323
+ * finds no niyam to run `as-agent` with, which is the cloud, whose proxy
324
+ * authenticates it; a Mac with no launcher is `doctor`'s own ✗ already
325
+ * (`launcherFinding`). Each other command is kept, so a plain `gh` call in
326
+ * the same script is still judged, and so is a `set -- gh` that runs a
327
+ * command substitution. Without the `as-agent` form, `set -- gh` is kept:
328
+ * its `"$@"` runs gh plain.
329
+ */
330
+ function withoutRoutedSetGh(text) {
331
+ const commands = text.split(/[;&|\n]+/);
332
+ if (!commands.some((command) => SET_AS_AGENT_GH.test(command)))
333
+ return text;
334
+ return commands.filter((command) => !SET_GH.test(command)).join('\n');
335
+ }
311
336
  /** The text with each command that runs `as-agent` taken out, the rest of its line kept. */
312
337
  function withoutAsAgent(text) {
313
338
  return text.split(/[;&|\n]+/).filter((command) => !/\bas-agent\b/.test(command)).join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veda-hq/niyam",
3
- "version": "0.7.11",
3
+ "version": "0.7.13",
4
4
  "description": "Work rules for repos that track work in GitHub Issues: setup, agent identity, push and PR checks.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,6 +19,13 @@ export const MERGE_QUEUE_SIGNER = 'mergify-commit-signer';
19
19
  */
20
20
  const MERGE_QUEUE_TITLE =
21
21
  /^merge queue: checking (#\d+(?: \+ #\d+)*)(?: together)? on \S+ \([0-9a-f]+\)(?:, stacked on (?:(#\d+(?:(?:,\s*|\s+and\s+)#\d+)*)|(\d+) pull requests ahead))?$/;
22
+ /**
23
+ * The title Mergify gives the draft once it has merged the pull request it
24
+ * tested and closed the draft: `merge queue: merged #A: <A's title>`, as on
25
+ * athya_mono#3839. The group is the tested pull request; the rest is A's own
26
+ * title, which A's author writes, so nothing in it is read.
27
+ */
28
+ const MERGED_TITLE = /^merge queue: merged #(\d+): /;
22
29
  /** The body's list of the pull requests queued ahead, which a deep stack's title only counts. */
23
30
  const QUEUED_AHEAD = /^### Queued ahead of this batch\n([\s\S]*?)(?=^#{1,3} |^<details>|(?![\s\S]))/m;
24
31
  /** Mergify's merge of a tested pull request into its draft. */
@@ -46,6 +53,8 @@ export function isMergifyDraft(pull, repo) {
46
53
  */
47
54
  export function mergifyTests(pull, repo, pr) {
48
55
  if (!isMergifyDraft(pull, repo)) return undefined;
56
+ const merged = MERGED_TITLE.exec(pull.title ?? '')?.[1];
57
+ if (merged !== undefined) return Number(merged) === pr ? undefined : [Number(merged)];
49
58
  const title = MERGE_QUEUE_TITLE.exec(pull.title ?? '');
50
59
  if (!title) return undefined;
51
60
  const [, batch = '', stacked = '', ahead] = title;