@veda-hq/niyam 0.7.12 → 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.12/veda-hq-niyam-0.7.12.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
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.12",
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": {