@veda-hq/niyam 0.6.25 → 0.6.26

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
@@ -977,7 +977,11 @@ repeats that call at every `wrap_up` until the app confirms Auto-fix. The
977
977
  ToolSearch step, the `<pr-created>` tag and `bind_pr` stay: without them the
978
978
  app refuses `set_monitor` for a pull request a hook opened. When the row
979
979
  cannot be written, or the session id cannot name a list, the whole
980
- instruction goes out.
980
+ instruction goes out. With `"autofixList": true`, a pull request whose latest
981
+ state on the list is `on` (folded as sarathi does: `warned` rows skipped,
982
+ `opened` only adding the pull request) gets no instruction at all, and no
983
+ ack, so an `off` later is told at a later Stop. `opened`, `refused`, `off`,
984
+ or a list that cannot be read, gets the instruction as above.
981
985
 
982
986
  **Started work runs to merge.** `niyam keep-going`, Claude Code's Stop hook,
983
987
  sends a session back while its branch has commits the base lacks and its
@@ -1620,7 +1624,7 @@ tag and the commit. Install the attached package on each machine with pnpm,
1620
1624
  once; nothing is built on install:
1621
1625
 
1622
1626
  ```bash
1623
- pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.25/veda-hq-niyam-0.6.25.tgz
1627
+ pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.26/veda-hq-niyam-0.6.26.tgz
1624
1628
  ```
1625
1629
 
1626
1630
  The package puts one command on `PATH`, `niyam`. Since P-57 a release
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
2
2
  import { dirname, resolve } from 'node:path';
3
3
  import { githubSlug, isNoToken, SETTINGS_PATH } from './agent.js';
4
4
  import { agentEnv } from './as-agent.js';
5
+ import { schema } from './doc-numbers.js';
5
6
  import { GITHUB_API, GITHUB_HOST } from './host.js';
6
7
  import { commands } from './shell.js';
7
8
  import { sessionToken } from './work.js';
@@ -588,6 +589,50 @@ export function listForAutofix(sys, session, url) {
588
589
  return false;
589
590
  }
590
591
  }
592
+ /**
593
+ * The pull request's latest state on the session's sarathi Auto-fix list, folded as sarathi's `readRows` and
594
+ * `fold` do: rows whose `pr` and `event` are strings, the pull request matched in lower case, `warned` skipped,
595
+ * `opened` only adding it, any other event setting its state. Undefined when the list does not name it, or
596
+ * cannot be read.
597
+ */
598
+ export function autofixState(sys, session, url) {
599
+ const pull = pullOf(url);
600
+ if (!session || !SARATHI_SESSION.test(session) || !pull)
601
+ return undefined;
602
+ const file = resolve(autofixDir(sys), `${session}.jsonl`);
603
+ let text;
604
+ try {
605
+ text = sys.read(file);
606
+ }
607
+ catch {
608
+ // fail-open: a list that cannot be read shows no state, and the whole instruction goes out
609
+ return undefined;
610
+ }
611
+ const key = pull.pr.toLowerCase();
612
+ let state;
613
+ for (const line of text.split('\n')) {
614
+ let row;
615
+ try {
616
+ row = ListRowSchema.parse(JSON.parse(line));
617
+ }
618
+ catch {
619
+ // fail-open: a blank or partial line, or one that is no row, as sarathi skips it
620
+ continue;
621
+ }
622
+ if (row.pr.toLowerCase() !== key || row.event === 'warned')
623
+ continue;
624
+ if (row.event !== 'opened' || state === undefined)
625
+ state = row.event;
626
+ }
627
+ return state;
628
+ }
629
+ /** A row of sarathi's Auto-fix list, as its `readRows` keeps one: `pr` and `event` strings. */
630
+ const ListRowSchema = schema((value) => {
631
+ const { pr, event } = (typeof value === 'object' && value !== null ? value : {});
632
+ if (typeof pr !== 'string' || typeof event !== 'string')
633
+ throw new Error('not a list row');
634
+ return { pr, event };
635
+ });
591
636
  /** How the session replaces the placeholder body. */
592
637
  function editHint(settings, pulls, number) {
593
638
  return pulls.cloud ? `gh api -X PATCH repos/${pulls.slug}/pulls/${number} -F body=@FILE` : settings.describe;
@@ -601,6 +646,9 @@ async function autofixMessage(sys, root, settings, state, session, pulls, listed
601
646
  const ack = `${stateDir(root)}/acks/${who}-${pr.number}`;
602
647
  if (sys.exists(ack))
603
648
  return '';
649
+ // sarathi's list shows Auto-fix on already: nothing to say, and no ack, so an `off` later is told at a later Stop.
650
+ if (listed && settings.autofixList && autofixState(sys, typeof session === 'string' ? session : undefined, pr.url) === 'on')
651
+ return '';
604
652
  try {
605
653
  sys.confine(root, ack);
606
654
  sys.mkdir(dirname(ack));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veda-hq/niyam",
3
- "version": "0.6.25",
3
+ "version": "0.6.26",
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": {