@veda-hq/niyam 0.6.23 → 0.6.24

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
@@ -421,7 +421,17 @@ on any platform without a token store, `niyam env` prints the lock alone.
421
421
  every run (see Claude cloud sessions below); a cloud session with no
422
422
  niyam runs it from the SessionStart hook, so there is nothing to paste,
423
423
  and the first time, the plan lists the one connection of claude.ai's
424
- GitHub as the agent, once per claude.ai account. Where the
424
+ GitHub as the agent, once per claude.ai account. When the agent has no
425
+ signing key on GitHub titled `niyam cloud signing`, the plan's Claude
426
+ cloud group also lists one, "signing key for AGENT, on the clipboard":
427
+ as its last step, after the pull request opens, `onboard` makes it as
428
+ `niyam cloud-key` does (below), and "By hand:" starts with the paste
429
+ into each cloud environment's variables. The key is the agent's, not the
430
+ repository's, so onboarding a second repository finds it and says nothing
431
+ about it. A key that fails only warns, leaving the pull request and every
432
+ step before it in place, and "By hand:" names `niyam cloud-key <agent>`
433
+ instead; so does a run where `cloud-key` would refuse, in a Claude Code
434
+ or cloud session. A dry run plans no key. Where the
425
435
  repo still has `.github/process-rules/cloud-setup.sh`, which releases up
426
436
  to 0.6.10 wrote beside it, the pull request deletes it, but only where it
427
437
  leaves `.github/niyam/cloud-setup.sh` (one the run could not write, as
@@ -923,6 +933,21 @@ checked. The settings:
923
933
  `retire`, a command with `{number}` for the merged pull request, is the way out
924
934
  `refuse-retired` names; `footer` ends the placeholder body.
925
935
 
936
+ **On sarathi's Auto-fix list.** Outside a cloud session, `claude-hook` puts
937
+ the open pull request it opened or found on the session's sarathi Auto-fix
938
+ list (sarathi 0.6.15's `autofix-watch.sh`): an `opened` row
939
+ `{ "at", "pr": "owner/repo#N", "url", "event": "opened", "source": "niyam pr-autocreate" }`
940
+ in `<dir>/<session id>.jsonl`, where `<dir>` is `SARATHI_AUTOFIX_DIR`, else
941
+ `$XDG_STATE_HOME/sarathi/autofix`, else `~/.local/state/sarathi/autofix`. A
942
+ pull request the list names already gets no second row. With
943
+ `"autofixList": true`, for a repository whose sessions run that sarathi hook,
944
+ the instruction leaves out its `set_monitor` step, because sarathi's warning
945
+ repeats that call at every `wrap_up` until the app confirms Auto-fix. The
946
+ ToolSearch step, the `<pr-created>` tag and `bind_pr` stay: without them the
947
+ app refuses `set_monitor` for a pull request a hook opened. When the row
948
+ cannot be written, or the session id cannot name a list, the whole
949
+ instruction goes out.
950
+
926
951
  **Started work runs to merge.** `niyam keep-going`, Claude Code's Stop hook,
927
952
  sends a session back while its branch has commits the base lacks and its
928
953
  pull request has not merged at this commit, saying what is left (push, open
@@ -1331,9 +1356,12 @@ probe that does not verify. The session's line says why and the session
1331
1356
  works on as the agent. A commit claiming the agent without the agent's
1332
1357
  signature would fail PR identity, so it is all or nothing.
1333
1358
 
1334
- Set the key up once per cloud environment, in your own terminal on the Mac
1335
- `niyam machine` set up for the agent: run `niyam cloud-key [agent]` (`--yes`
1336
- skips its one question). It does four things:
1359
+ `niyam onboard` makes the key the first time it runs for an agent that has
1360
+ none (see Adopting above), so all that is left is the paste. To make one
1361
+ yourself, as when the line was lost, run `niyam cloud-key [agent]` in your own
1362
+ terminal on the Mac `niyam machine` set up for the agent (`--yes` skips its
1363
+ one question). One line serves every cloud environment the agent works in.
1364
+ `onboard` and `cloud-key` make the key alike, in four steps:
1337
1365
 
1338
1366
  - makes a new ed25519 key in a private temporary folder, for the agent's cloud sessions alone, apart from the Mac's signing key, so it can be revoked on its own;
1339
1367
  - registers it as the agent's signing key, titled `niyam cloud signing`, with the token `machine` stored, and checks GitHub lists it;
@@ -1544,7 +1572,7 @@ tag and the commit. Install the attached package on each machine with pnpm,
1544
1572
  once; nothing is built on install:
1545
1573
 
1546
1574
  ```bash
1547
- pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.23/veda-hq-niyam-0.6.23.tgz
1575
+ pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.24/veda-hq-niyam-0.6.24.tgz
1548
1576
  ```
1549
1577
 
1550
1578
  The package puts one command on `PATH`, `niyam`. Since P-57 a release
package/dist/cloud-key.js CHANGED
@@ -39,13 +39,10 @@ export function cloudKeyArgs(args) {
39
39
  */
40
40
  export async function cloudKey(sys, io, args = []) {
41
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
- }
42
+ const refusal = cloudKeyRefusal(sys);
46
43
  const store = tokenStore(sys);
47
- if (!store) {
48
- io.err(`cloud-key: ${unsupported(sys)}`);
44
+ if (refusal !== undefined || !store) {
45
+ io.err(`cloud-key: ${refusal ?? unsupported(sys)}`);
49
46
  return 1;
50
47
  }
51
48
  const { login: agent } = await account(sys, agentFrom(sys, named));
@@ -77,6 +74,34 @@ export async function cloudKey(sys, io, args = []) {
77
74
  return 1;
78
75
  }
79
76
  }
77
+ return makeCloudKey(sys, io, agent, token, { others, paste: true });
78
+ }
79
+ /**
80
+ * Why cloud-key cannot run here, or undefined: in an agent session or a cloud
81
+ * session the token is not the owner's to use, and a machine with no token
82
+ * store holds no token to register the key with.
83
+ */
84
+ export function cloudKeyRefusal(sys) {
85
+ if (agentSession(sys) || sys.env.CLAUDE_CODE_REMOTE === 'true')
86
+ return 'run it in your own terminal on your Mac, not in an agent session; it registers a key as the agent';
87
+ return tokenStore(sys) ? undefined : unsupported(sys);
88
+ }
89
+ /** What the owner does with the line on the clipboard: paste it into `where`'s variables, and what it does then. */
90
+ export function pasteLines(agent, where = "the cloud environment's") {
91
+ return [
92
+ `Paste it as one line into ${where} variables: ${CLAUDE_CODE_WEB} → the environment's settings.`,
93
+ `A new session there makes ${agent}'s commits its own; its first niyam line says so.`,
94
+ ];
95
+ }
96
+ /**
97
+ * Makes the agent's cloud signing key in a private temporary folder,
98
+ * registers it, puts its line on the clipboard, and removes the folder, a
99
+ * Ctrl-C included; each step one line, the key never printed. `others` are
100
+ * the agent's cloud signing keys GitHub already lists, named for the owner
101
+ * to delete once unused; `paste` says what to do with the line, for a caller
102
+ * that does not say it itself. 0 once the line is on the clipboard.
103
+ */
104
+ export async function makeCloudKey(sys, io, agent, token, { others = [], paste = false } = {}) {
80
105
  const dir = sys.tempDir();
81
106
  let removed = false;
82
107
  const cleanUp = () => {
@@ -98,7 +123,7 @@ export async function cloudKey(sys, io, args = []) {
98
123
  });
99
124
  let code = 1;
100
125
  try {
101
- code = await makeAndRegister(sys, io, agent, token, `${dir}/key`, others, () => interrupted);
126
+ code = await makeAndRegister(sys, io, { agent, token, key: `${dir}/key`, others, paste }, () => interrupted);
102
127
  }
103
128
  finally {
104
129
  off();
@@ -117,7 +142,7 @@ export async function cloudKey(sys, io, args = []) {
117
142
  * step one line. The key is read before it is registered, so a Ctrl-C that
118
143
  * removes the files leaves it to delete from GitHub again, which it is.
119
144
  */
120
- async function makeAndRegister(sys, io, agent, token, key, others, interrupted) {
145
+ async function makeAndRegister(sys, io, { agent, token, key, others, paste }, interrupted) {
121
146
  const made = sys.exec('ssh-keygen', ['-q', '-t', 'ed25519', '-C', `${agent} cloud signing`, '-N', '', '-f', key], { input: '' });
122
147
  if (interrupted())
123
148
  return stopped(io);
@@ -155,8 +180,9 @@ async function makeAndRegister(sys, io, agent, token, key, others, interrupted)
155
180
  return 1;
156
181
  }
157
182
  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.`);
183
+ if (paste)
184
+ for (const line of pasteLines(agent))
185
+ io.out(` ${line}`);
160
186
  for (const other of others) {
161
187
  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
188
  }
@@ -180,7 +206,7 @@ async function unregister(sys, io, token, id, why) {
180
206
  : `✗ ${why}, and deleting the key from GitHub again failed (HTTP ${status}) → delete signing key ${id} at ${KEYS_PAGE}`);
181
207
  }
182
208
  /** 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) {
209
+ export async function listedKeys(sys, agent, token) {
184
210
  const { status, json } = await sys.http(`${API}/user/ssh_signing_keys?per_page=100`, { token });
185
211
  if (status !== 200 || !Array.isArray(json))
186
212
  return { problem: `GitHub answered HTTP ${status} when asked for ${agent}'s signing keys` };
package/dist/onboard.js CHANGED
@@ -7,7 +7,9 @@ import { appendToArray, removeElements, replaceValues, setMember } from './jsone
7
7
  import { HOURLY } from './asks.js';
8
8
  import { DEFAULT_SCHEDULE, FEATURES, FIGMA_FILE_KEY, NEEDS_ISSUE_TYPES, featuresIn, parseFeatures, renamedLines, scheduleIn } from './features.js';
9
9
  import { CLOUD_SETUP_PATH, HOOKS_PATH, LEFTOVER_CLOUD_SETUP_PATH, ONBOARD_BRANCH, SARATHI_PATH, WORKFLOW_PATH, autoMerge, mergeQueue, openPull, remoteFile, } from './onboard-pull.js';
10
- import { cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
10
+ import { SIGNING_KEY_VAR, cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
11
+ import { CLOUD_KEY_TITLE, cloudKeyRefusal, listedKeys, makeCloudKey, pasteLines } from './cloud-key.js';
12
+ import { detail } from './doc-numbers.js';
11
13
  import { tagOnMain } from './release-tag.js';
12
14
  import { secretNames, setSecret } from './secrets.js';
13
15
  import { UPGRADE } from './upgrade.js';
@@ -1110,7 +1112,9 @@ function planHead(paint, head) {
1110
1112
  * agent. It prints that as one plan and asks once (`--yes` skips the
1111
1113
  * question, `--dry-run` stops at the plan); a no changes nothing. After the
1112
1114
  * yes, one browser sign-in as the owner serves every step that acts as the
1113
- * owner, and each step shows as one line.
1115
+ * owner, and each step shows as one line. Last, once the pull request is
1116
+ * open, it makes the agent's cloud signing key when the agent has none
1117
+ * (#417), a failure there only warning.
1114
1118
  */
1115
1119
  export async function onboard(sys, io, args = []) {
1116
1120
  const { named, features: chosen, add, yes, dryRun } = onboardArgs(args);
@@ -1557,6 +1561,26 @@ export async function onboard(sys, io, args = []) {
1557
1561
  later.push(`Claude cloud sessions: a Setup script pasted before niyam 0.6.10 runs ${LEFTOVER_CLOUD_SETUP_PATH}, which this pull request deletes; if yours is one, delete niyam's part of it, since sessions now install niyam themselves, or paste what niyam cloud-setup prints over it. ${SETUP_FIRST}`);
1558
1562
  }
1559
1563
  }
1564
+ // The agent's cloud signing key (#417) is the agent's, not the repository's: one line serves every cloud
1565
+ // environment it works in, so onboard makes one only when the agent's own list holds none, and the second repo
1566
+ // onboarded leaves it alone. Where cloud-key would refuse, the owner runs it instead.
1567
+ const keyByHand = `Once for ${agent}: in your own terminal on your Mac, run niyam cloud-key ${agent}, and paste the line it puts on the clipboard into each Claude cloud environment's variables.`;
1568
+ const cloudKeys = await listedKeys(sys, agent, token).catch((error) => {
1569
+ // fail-open: a list GitHub does not give is warned about below and makes no key.
1570
+ return { problem: detail(error) };
1571
+ });
1572
+ let makeKey = false;
1573
+ // A list GitHub does not give makes no key, which could be a second one: the warning says how to check.
1574
+ if ('problem' in cloudKeys)
1575
+ warnings.push(`cloud signing key not checked (${cloudKeys.problem}); niyam cloud-key ${agent} makes one`);
1576
+ else if (!cloudKeys.keys.some((one) => one.title === CLOUD_KEY_TITLE)) {
1577
+ if (dryRun || cloudKeyRefusal(sys) !== undefined)
1578
+ byHand.push(keyByHand);
1579
+ else {
1580
+ cloud.push({ label: 'signing key', detail: `for ${agent}, on the clipboard` });
1581
+ makeKey = true;
1582
+ }
1583
+ }
1560
1584
  let pullUrl;
1561
1585
  // Whether the pull request merges itself once its checks pass.
1562
1586
  let merging = false;
@@ -1652,12 +1676,36 @@ export async function onboard(sys, io, args = []) {
1652
1676
  if (log.length > 0)
1653
1677
  notes.push(`- ${step.label}:`, ...log.map((line) => ` - ${line.trim().replace(/^[✓-] /, '')}`));
1654
1678
  }
1679
+ // Last, once the pull request is open: a key that fails only warns, and nothing before it is undone.
1680
+ // A Ctrl-C that stops the key ends the run as one does.
1681
+ let exitCode = 0;
1682
+ if (makeKey) {
1683
+ let made = false;
1684
+ try {
1685
+ ({ ok: made } = await runStep(sys, io, paint, `cloud signing key for ${agent}`, async (out) => {
1686
+ const code = await makeCloudKey(sys, out, agent, token);
1687
+ if (code === 130)
1688
+ exitCode = 130;
1689
+ return code === 0;
1690
+ }));
1691
+ }
1692
+ catch (error) {
1693
+ // fail-open: the pull request is open and every step before stands; the key's failure is said and left by hand below.
1694
+ io.err(`onboard: ${detail(error)}`);
1695
+ }
1696
+ if (made)
1697
+ byHand.unshift(`Now: ${SIGNING_KEY_VAR}=… is on the clipboard. ${pasteLines(agent, "each Claude cloud environment's").join(' ')}`);
1698
+ else {
1699
+ io.err(`onboard: ${agent} has no cloud signing key yet; everything before it is done`);
1700
+ byHand.push(keyByHand);
1701
+ }
1702
+ }
1655
1703
  io.out(closing(paint, `${!pullUrl ? 'Done; no file changes, so no pull request.' : merging ? `${pullUrl} ${queue !== undefined ? 'the merge queue merges it' : 'merges itself'} when checks pass` : `Merge ${pullUrl}`}`));
1656
1704
  io.out('');
1657
1705
  io.out('By hand:');
1658
1706
  for (const line of byHand)
1659
1707
  io.out(` ${line}`);
1660
- return 0;
1708
+ return exitCode;
1661
1709
  }
1662
1710
  /** How many times onboard asks GitHub about the test commit, waiting a little longer each time. */
1663
1711
  export const COMMIT_ATTEMPTS = 5;
@@ -12,6 +12,7 @@ const DEFAULTS = {
12
12
  skip: ['mergify/', 'gh-readonly-queue/'],
13
13
  optOut: [],
14
14
  describe: '`gh pr edit --body-file`',
15
+ autofixList: false,
15
16
  };
16
17
  const where = `${SETTINGS_PATH} "prAutocreate"`;
17
18
  const BRANCH = /^(?!\/)(?!.*\/\/)(?!.*\.\.)[\w.\/+-]+$/;
@@ -35,17 +36,20 @@ export function autocreateSettings(raw) {
35
36
  return { ...DEFAULTS };
36
37
  if (typeof value !== 'object' || value === null || Array.isArray(value))
37
38
  throw new Error(`${where} must be an object`);
38
- const { base = DEFAULTS.base, draft = DEFAULTS.draft, protected: guarded = DEFAULTS.protected, skip = DEFAULTS.skip, optOut = DEFAULTS.optOut, describe, retired, retire, footer, ...rest } = value;
39
+ const { base = DEFAULTS.base, draft = DEFAULTS.draft, protected: guarded = DEFAULTS.protected, skip = DEFAULTS.skip, optOut = DEFAULTS.optOut, describe, retired, retire, footer, autofixList = DEFAULTS.autofixList, ...rest } = value;
39
40
  const extra = Object.keys(rest)[0];
40
41
  if (extra !== undefined)
41
- throw new Error(`${where} has an unknown key "${extra}"; it takes "base", "draft", "protected", "skip", "optOut", "describe", "retired", "retire" and "footer"`);
42
+ throw new Error(`${where} has an unknown key "${extra}"; it takes "base", "draft", "protected", "skip", "optOut", "describe", "retired", "retire", "footer" and "autofixList"`);
42
43
  if (typeof base !== 'string' || !BRANCH.test(base))
43
44
  throw new Error(`${where}.base must be a branch name`);
44
45
  if (typeof draft !== 'boolean')
45
46
  throw new Error(`${where}.draft must be true or false`);
47
+ if (typeof autofixList !== 'boolean')
48
+ throw new Error(`${where}.autofixList must be true or false`);
46
49
  const settings = {
47
50
  base,
48
51
  draft,
52
+ autofixList,
49
53
  protected: strings(guarded, 'protected', (item) => BRANCH.test(item)),
50
54
  skip: strings(skip, 'skip', (item) => item.length > 0 && BRANCH.test(item)),
51
55
  optOut: strings(optOut, 'optOut', (item) => ENV_NAME.test(item)),
@@ -499,29 +503,97 @@ export function pushTarget(command, cwd, home) {
499
503
  }
500
504
  return undefined;
501
505
  }
502
- /** The instruction a session in the desktop app gets: switch Autofix on for the pull request. */
503
- export function reminder(pr, opened, created, cloud) {
506
+ /**
507
+ * The instruction a session in the desktop app gets: switch Autofix on for the pull request. `listed`: the pull
508
+ * request is on the session's sarathi Auto-fix list and the repository says sarathi warns from it, so the
509
+ * `set_monitor` step is sarathi's and left out here. The tag and `bind_pr` stay: without them the app refuses
510
+ * `set_monitor` for a pull request a hook opened, and sarathi goes quiet once it records the refusal.
511
+ */
512
+ export function reminder(pr, opened, created, cloud, listed = false) {
504
513
  if (cloud) {
505
514
  return `PR #${pr.number} (${pr.url}) ${opened}\nThis cloud session has no Autofix: CI, conflicts and review comments reach no one until a session reads them (gh api; GraphQL is refused here).`;
506
515
  }
507
516
  // The tag claims the session opened the pull request, so one merely found
508
517
  // on the branch gets it only when the session knows it ran that create.
509
518
  const claim = created ? 'Write' : 'Only if this session itself ran the `gh pr create` that opened this PR (in a background command, say), write';
510
- return (`PR #${pr.number} (${pr.url}) ${opened}\n` +
511
- 'Standing instruction from the user: Autofix must be ON for every PR a session pushes. Do this now, before anything else:\n' +
512
- '1. If mcp__ccd_pr__get_status is not yet a callable tool, it may only be deferred: run ToolSearch with query "select:mcp__ccd_pr__get_status,mcp__ccd_pr__bind_pr,mcp__ccd_pr__set_monitor" to load its schema before concluding it is unavailable.\n' +
519
+ const steps = '1. If mcp__ccd_pr__get_status is not yet a callable tool, it may only be deferred: run ToolSearch with query "select:mcp__ccd_pr__get_status,mcp__ccd_pr__bind_pr,mcp__ccd_pr__set_monitor" to load its schema before concluding it is unavailable.\n' +
513
520
  `2. ${claim} this line in your reply text, exactly: <pr-created>${pr.url}</pr-created>\n` +
514
521
  'The app lets a session turn Autofix on only for a PR it is sure the session opened, and it learns that only from a FOREGROUND `gh pr create` result or this tag; a PR opened by this hook or inside a background command has neither. Never write the tag for a PR this session did not open.\n' +
515
- `3. Call mcp__ccd_pr__get_status. If it reports no bound PR, call mcp__ccd_pr__bind_pr with url ${pr.url}.\n` +
522
+ `3. Call mcp__ccd_pr__get_status. If it reports no bound PR, call mcp__ccd_pr__bind_pr with url ${pr.url}.\n`;
523
+ const why = "tell the user in one line that Autofix could not be enabled and why, quoting the app's reason (the tag counts only within 15 minutes of the PR's creation, from the PR's own branch, and when the app's gh login authored it) — never fail silently and leave it off unreported.";
524
+ if (listed) {
525
+ return (`PR #${pr.number} (${pr.url}) ${opened}\n` +
526
+ "Standing instruction from the user: Autofix must be ON for every PR a session pushes. This PR is on this session's sarathi Auto-fix list, and sarathi's warning gives the mcp__ccd_pr__set_monitor call that switches it on. Do this now, before anything else, so that call is not refused:\n" +
527
+ steps +
528
+ `If ToolSearch cannot find mcp__ccd_pr__* at all (truly not the desktop app), or get_status/bind_pr still fails, ${why}`);
529
+ }
530
+ return (`PR #${pr.number} (${pr.url}) ${opened}\n` +
531
+ 'Standing instruction from the user: Autofix must be ON for every PR a session pushes. Do this now, before anything else:\n' +
532
+ steps +
516
533
  `4. If auto_fix is not true, call mcp__ccd_pr__set_monitor with {"auto_fix": true, "address_comments": true, "url": "${pr.url}"}. If it says the app is not sure this session opened the PR, or has not read it yet, call get_status once more and retry set_monitor once.\n` +
517
- "If ToolSearch cannot find mcp__ccd_pr__* at all (truly not the desktop app), or get_status/bind_pr/set_monitor still fails, tell the user in one line that Autofix could not be enabled and why, quoting the app's reason (the tag counts only within 15 minutes of the PR's creation, from the PR's own branch, and when the app's gh login authored it) — never fail silently and leave it off unreported.");
534
+ `If ToolSearch cannot find mcp__ccd_pr__* at all (truly not the desktop app), or get_status/bind_pr/set_monitor still fails, ${why}`);
535
+ }
536
+ /** A Claude session id sarathi lets name a list file (its `SESSION`). */
537
+ const SARATHI_SESSION = /^[\w.-]{1,128}$/;
538
+ const NAME = /^[\w.-]+$/;
539
+ export const AUTOFIX_SOURCE = 'niyam pr-autocreate';
540
+ /** owner/repo#N and the bare URL of https://<host>/<owner>/<repo>/pull/<N>, as sarathi's `fromUrl` reads one. */
541
+ function pullOf(url) {
542
+ let parsed;
543
+ try {
544
+ parsed = new URL(url);
545
+ }
546
+ catch {
547
+ // fail-open: what is not a URL names no pull request, and the whole instruction goes out
548
+ return undefined;
549
+ }
550
+ const [, owner = '', repo = '', kind, number = ''] = parsed.pathname.split('/');
551
+ if (parsed.protocol !== 'https:' || kind !== 'pull' || !NAME.test(owner) || !NAME.test(repo) || !/^\d+$/.test(number))
552
+ return undefined;
553
+ return { pr: `${owner}/${repo}#${number}`, url: `https://${parsed.host}/${owner}/${repo}/pull/${number}` };
554
+ }
555
+ /** sarathi's Auto-fix list folder: SARATHI_AUTOFIX_DIR, else $XDG_STATE_HOME/sarathi/autofix, else ~/.local/state/sarathi/autofix. */
556
+ export function autofixDir(sys) {
557
+ const override = sys.env.SARATHI_AUTOFIX_DIR;
558
+ if (override)
559
+ return override;
560
+ const state = sys.env.XDG_STATE_HOME;
561
+ return resolve(state || resolve(sys.home, '.local', 'state'), 'sarathi', 'autofix');
562
+ }
563
+ /**
564
+ * Puts the pull request on the session's sarathi Auto-fix list (sarathi
565
+ * 0.6.15's `<dir>/<session id>.jsonl`, one JSON row per fact), as `sarathi
566
+ * autofix add` does: an `opened` row, unless the list names it already, so a
567
+ * Stop after every turn adds no more. True once it is on the list; false when
568
+ * the session id cannot name a list or the row could not be written.
569
+ */
570
+ export function listForAutofix(sys, session, url) {
571
+ const pull = pullOf(url);
572
+ if (!session || !SARATHI_SESSION.test(session) || !pull)
573
+ return false;
574
+ const file = resolve(autofixDir(sys), `${session}.jsonl`);
575
+ // sarathi writes its rows with JSON.stringify, so a row for the pull request holds this text; sarathi folds two
576
+ // spellings of one together by lower case. A row this misses only adds an `opened` row sarathi ignores.
577
+ const named = JSON.stringify({ pr: pull.pr }).slice(1, -1).toLowerCase();
578
+ try {
579
+ if (sys.exists(file) && sys.read(file).toLowerCase().includes(named))
580
+ return true;
581
+ sys.mkdir(dirname(file));
582
+ // The leading newline ends a partial row a short append left, as sarathi's appendRows does.
583
+ sys.append(file, `\n${JSON.stringify({ at: sys.now().toISOString(), ...pull, event: 'opened', source: AUTOFIX_SOURCE })}\n`);
584
+ return true;
585
+ }
586
+ catch {
587
+ // fail-open: a list that cannot be read or written leaves the pull request off it, and the whole instruction goes out
588
+ return false;
589
+ }
518
590
  }
519
591
  /** How the session replaces the placeholder body. */
520
592
  function editHint(settings, pulls, number) {
521
593
  return pulls.cloud ? `gh api -X PATCH repos/${pulls.slug}/pulls/${number} -F body=@FILE` : settings.describe;
522
594
  }
523
595
  /** The instruction for the record's open pull request, once per session and pull request; empty when there is nothing to say. */
524
- async function autofixMessage(sys, root, settings, state, session, pulls) {
596
+ async function autofixMessage(sys, root, settings, state, session, pulls, listed) {
525
597
  const pr = state.pr;
526
598
  if (!pr || pr.state !== 'OPEN' || !pr.url)
527
599
  return '';
@@ -547,7 +619,7 @@ async function autofixMessage(sys, root, settings, state, session, pulls) {
547
619
  else if (body.includes(MARKER))
548
620
  opened += ` Its body is still the automatic placeholder: ${replace}`;
549
621
  }
550
- return reminder(pr, opened, state.created, pulls.cloud);
622
+ return reminder(pr, opened, state.created, pulls.cloud, listed && settings.autofixList);
551
623
  }
552
624
  /**
553
625
  * The transport with the token GitHub is asked with: a session's hook acts
@@ -672,7 +744,10 @@ export async function claudeHook(sys, io, stdin, pullsOf = pullsFor) {
672
744
  }
673
745
  if ('problem' in state)
674
746
  return bail(state.problem);
675
- let message = await autofixMessage(sys, root, settings, state, session, pulls);
747
+ // On the session's sarathi Auto-fix list, every time and before the once-only instruction, so a pull request
748
+ // told about before this release joins it too. A cloud session has no set_monitor, and sarathi is quiet there.
749
+ const listed = !pulls.cloud && state.pr?.state === 'OPEN' && Boolean(state.pr.url) && listForAutofix(sys, session, state.pr.url);
750
+ let message = await autofixMessage(sys, root, settings, state, session, pulls, listed);
676
751
  if (typeof message !== 'string')
677
752
  return bail(message.problem);
678
753
  if (!message && state.notes.length > 0 && event === 'PostToolUse') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veda-hq/niyam",
3
- "version": "0.6.23",
3
+ "version": "0.6.24",
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": {