@veda-hq/niyam 0.7.15 → 0.7.16

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
@@ -740,9 +740,15 @@ an archive made on purpose from one made before the issue reopened. The
740
740
  repository is the clone's here when none is named, and the Project is the
741
741
  one `.github/niyam.json`'s `"project"` names, else "<repo> work". GitHub's
742
742
  API shows a workflow's name and whether it is on, not the repository or
743
- filter it adds from, so the audit says so. It runs with `GH_TOKEN`, which
744
- needs read access to the Project, and exits 0 when the board matches, 3 when
745
- something is to fix, and 1 when it could not check. A Claude cloud
743
+ filter it adds from, so the audit says so. It reads with `GH_TOKEN`, which
744
+ needs read access to the Project, as an agent session has it. Without one,
745
+ as in the owner's terminal, it reads as the agent, with the token `machine`
746
+ keeps in the keychain: the agent the clone's settings name, or outside a
747
+ clone the one `machine` set up on this Mac. So it needs no `gh` signed in,
748
+ and never the owner's own token. With no such token, or several agents and
749
+ none named, it says so and reads nothing; so it does in a locked session,
750
+ whose `GH_TOKEN` is the lock's placeholder. It exits 0 when the board matches,
751
+ 3 when something is to fix, and 1 when it could not check. A Claude cloud
746
752
  session's GitHub proxy refuses GraphQL and an organisation's Projects
747
753
  (veda-hq/niyam#399), so there it says it cannot run and checks nothing.
748
754
 
@@ -1755,7 +1761,7 @@ commit. `upgrade` asks with no token; `onboard` asks with the agent's. Install t
1755
1761
  once; nothing is built on install:
1756
1762
 
1757
1763
  ```bash
1758
- pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.15/veda-hq-niyam-0.7.15.tgz
1764
+ pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.16/veda-hq-niyam-0.7.16.tgz
1759
1765
  ```
1760
1766
 
1761
1767
  The package puts one command on `PATH`, `niyam`. Since P-57 a release
@@ -1,5 +1,6 @@
1
- import { API, SETTINGS_PATH, repoAt } from './agent.js';
1
+ import { API, NO_TOKEN, SETTINGS_PATH, agentHere, agentsSetUp, hasSettings, isNoToken, loadSettings, readToken, repoAt, sameLogin } from './agent.js';
2
2
  import { AUTO_ADD, AUTO_ADD_FILTER, graphql } from './board.js';
3
+ import { tokenStore, unsupported } from './token-store.js';
3
4
  /** board-audit's options: the repository, and the Project's title. */
4
5
  export function auditArgs(args) {
5
6
  const parsed = {};
@@ -150,6 +151,55 @@ export function auditLines(audit, slug) {
150
151
  lines.push(wrong > 0 ? `board-audit: ${wrong} to fix` : audit.archived.length > 0 ? 'board-audit: nothing to fix but the archived issues above' : 'board-audit: the board matches the repository');
151
152
  return { lines, wrong };
152
153
  }
154
+ /**
155
+ * The token the audit reads with: `GH_TOKEN`, as an agent session has it,
156
+ * else the agent's own, which `machine` keeps in this Mac's keychain. The
157
+ * audit only reads, and the agent's token can read the board, so the owner
158
+ * runs it in a terminal with no `gh` signed in. It never asks for the
159
+ * owner's own token, which `machine` signs out of `gh` (veda-hq/niyam#548).
160
+ */
161
+ export function auditToken(sys) {
162
+ const given = sys.env.GH_TOKEN;
163
+ // A locked session's placeholder is no token, and the lock is never worked around with the keychain's.
164
+ if (isNoToken(given))
165
+ throw new Error(`board-audit has no token: GH_TOKEN is the lock's ${NO_TOKEN}, as in a session niyam has not given the agent identity, so nothing was read; run niyam doctor`);
166
+ if (given)
167
+ return given;
168
+ if (!tokenStore(sys))
169
+ throw new Error(`board-audit needs GH_TOKEN here, as an agent session has it: ${unsupported(sys)}`);
170
+ const agent = auditAgent(sys);
171
+ if ('problem' in agent)
172
+ throw new Error(`board-audit needs GH_TOKEN, as an agent session has it, or the agent's token from this Mac's keychain: ${agent.problem}`);
173
+ // The keychain item is under the login as `machine` spelled it, which the settings may spell in another case.
174
+ const login = agentsSetUp(sys).find((one) => sameLogin(one, agent.agent)) ?? agent.agent;
175
+ const token = readToken(sys, login);
176
+ if (!token)
177
+ throw new Error(`board-audit needs GH_TOKEN, as an agent session has it, or ${login}'s token from this Mac's keychain, which holds none; run niyam machine ${login}`);
178
+ return token;
179
+ }
180
+ /**
181
+ * The agent whose token the audit reads with outside an agent session: in a
182
+ * clone with settings, the one they name that sessions here work as
183
+ * (`agentHere`); elsewhere, the one `machine` set up on this Mac. A clone
184
+ * without settings counts as elsewhere: the audit takes any repository by
185
+ * name, so it needs no client clone. Never a guess.
186
+ */
187
+ function auditAgent(sys) {
188
+ const top = sys.exec('git', ['rev-parse', '--show-toplevel'], { cwd: sys.cwd });
189
+ const root = top.stdout.trim();
190
+ if (top.code === 0 && hasSettings(sys, root)) {
191
+ const here = agentHere(sys, loadSettings(sys, root).agents);
192
+ return 'problem' in here ? { problem: `${here.problem}; or run it in an agent session` } : here;
193
+ }
194
+ const setUp = agentsSetUp(sys);
195
+ if (setUp.length === 1)
196
+ return { agent: setUp[0] };
197
+ return {
198
+ problem: setUp.length === 0
199
+ ? 'niyam machine has set up no agent on this Mac; run niyam machine <agent>, or run it in an agent session'
200
+ : `niyam machine has set up ${setUp.join(' and ')} on this Mac, and no ${SETTINGS_PATH} here names one; run it in a clone of the repository, or in an agent session`,
201
+ };
202
+ }
153
203
  /**
154
204
  * `niyam board-audit [owner/repo] [--project <title>]`: lists where the
155
205
  * repository and its work board disagree, changing nothing. The repository
@@ -165,9 +215,7 @@ export async function boardAudit(sys, io, args) {
165
215
  return 1;
166
216
  }
167
217
  const parsed = auditArgs(args);
168
- const token = sys.env.GH_TOKEN;
169
- if (!token)
170
- throw new Error('board-audit needs GH_TOKEN, with read access to the Project: run it in an agent session, or GH_TOKEN="$(gh auth token)" niyam board-audit');
218
+ const token = auditToken(sys);
171
219
  const slug = parsed.slug ?? repoAt(sys).slug;
172
220
  const title = parsed.project ?? (await settingsTitle(sys, token, slug)) ?? `${slug.split('/')[1]} work`;
173
221
  const { lines, wrong } = auditLines(await auditBoard(sys, token, slug, title), slug);
package/dist/run.js CHANGED
@@ -112,7 +112,8 @@ Commands:
112
112
  board-audit [owner/repo] [--project <title>]
113
113
  Read only: the open issues not on the work board, items whose Status disagrees with
114
114
  their issue, and whether the auto-add workflows are on; exit 3 when something is to fix.
115
- Needs GH_TOKEN; cannot run in a Claude cloud session, whose proxy refuses Projects
115
+ Reads with GH_TOKEN, else the agent's token from this Mac's keychain; cannot run in
116
+ a Claude cloud session, whose proxy refuses Projects
116
117
  help Show this text
117
118
  version Print the installed version
118
119
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veda-hq/niyam",
3
- "version": "0.7.15",
3
+ "version": "0.7.16",
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": {