@veda-hq/niyam 0.7.0 → 0.7.2
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 +33 -8
- package/dist/board.js +7 -5
- package/dist/doctor.js +18 -6
- package/dist/onboard.js +77 -20
- package/dist/reviews.js +48 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -157,6 +157,13 @@ In auto mode the classifier refuses those calls unless the repo's
|
|
|
157
157
|
`mcp__ccd_pr__get_status` and `mcp__ccd_pr__set_monitor` to its
|
|
158
158
|
`permissions.allow`, and `doctor` warns under "This repo" (`▲`) about each
|
|
159
159
|
one an onboarded repo's file lacks. They reach the app only, not GitHub.
|
|
160
|
+
Claude Code applies deny before allow, so where the file's
|
|
161
|
+
`permissions.deny` matches one of the tools (by its name, `mcp__ccd_pr`,
|
|
162
|
+
`mcp__ccd_pr__*` or another glob after `mcp__ccd_pr__`, `mcp__*` or `*`),
|
|
163
|
+
`onboard` adds no rule for it and says so in its plan, and `doctor` marks it
|
|
164
|
+
denied on purpose (`✓`). A group denied whole leaves nothing to fix; in a
|
|
165
|
+
group denied in part, `doctor` still warns (`▲`) about each other rule the
|
|
166
|
+
file lacks.
|
|
160
167
|
|
|
161
168
|
Before each Bash command, the client's PreToolUse hook runs `niyam
|
|
162
169
|
guard`: a command running `gh` or a git command that reaches a remote (push,
|
|
@@ -187,7 +194,10 @@ allows it, so `onboard` adds `mcp__claude-artifacts__publish_version`,
|
|
|
187
194
|
`mcp__claude-artifacts__edit_version` to its `permissions.allow` (none
|
|
188
195
|
where `mcp__claude-artifacts` or `mcp__claude-artifacts__*` allows the whole
|
|
189
196
|
server), and `doctor` warns (`▲`) about each one an onboarded repo's file
|
|
190
|
-
lacks. A
|
|
197
|
+
lacks. A repo that publishes its pages another way may deny the artifacts
|
|
198
|
+
server on purpose. Where the file's `permissions.deny` matches one of the
|
|
199
|
+
three, as for the Auto-fix rules above, `onboard` adds no rule for it and
|
|
200
|
+
its plan says so, and `doctor` marks it denied on purpose (`✓`). A new page is private to its owner; a republish to a page already
|
|
191
201
|
shared changes what its readers see, with no prompt. A body the guard cannot read in full
|
|
192
202
|
(a variable, a command substitution other than `cat`) is judged by what it
|
|
193
203
|
spells out; where that asks the owner, or the body opens with the unknown
|
|
@@ -410,7 +420,8 @@ on any platform without a token store, `niyam env` prints the lock alone.
|
|
|
410
420
|
│ 1. Once for owner/repo: in Claude Code, run /schedule and create a
|
|
411
421
|
│ weekly routine on it, with claude.ai's GitHub connected as AGENT and
|
|
412
422
|
│ the prompt below the line in
|
|
413
|
-
│ https://github.com/veda-hq/niyam/blob/v0.6.15/routines/review.md
|
|
423
|
+
│ https://github.com/veda-hq/niyam/blob/v0.6.15/routines/review.md; skip
|
|
424
|
+
│ it if done.
|
|
414
425
|
│
|
|
415
426
|
│ 2. Once per claude.ai account: sign in at https://claude.ai/code and
|
|
416
427
|
│ connect GitHub as AGENT (or change it at
|
|
@@ -431,7 +442,8 @@ on any platform without a token store, `niyam env` prints the lock alone.
|
|
|
431
442
|
`mcp__claude-artifacts__publish_version`, `publish_files` and
|
|
432
443
|
`edit_version`, which publish the page an ask to the owner links (a
|
|
433
444
|
rerun adds only the ones missing; a file allowing a whole server gets
|
|
434
|
-
none of its rules
|
|
445
|
+
none of its rules, and a rule the file's `permissions.deny` overrides is
|
|
446
|
+
left out, the plan saying so), and
|
|
435
447
|
writes `.github/workflows/niyam.yml`, which calls this repository's
|
|
436
448
|
shared checks (`.github/workflows/checks.yml`) from two jobs: `niyam`
|
|
437
449
|
on pull requests and pushes, read-only, and `niyam-weekly` on the
|
|
@@ -648,9 +660,15 @@ A board it cannot read, or a move GitHub refuses, is said and does not stop
|
|
|
648
660
|
the push; a push for a closed slice, such as a fix, moves nothing. A Claude
|
|
649
661
|
cloud session's GitHub proxy lets through only `repos/{owner}/{repo}/…`, so
|
|
650
662
|
its push never reaches an organization's Projects and says only that the
|
|
651
|
-
workflow moves the slice.
|
|
652
|
-
|
|
653
|
-
the same conditions, with a token from the board GitHub App.
|
|
663
|
+
workflow moves the slice. Once Work rules passes for a pull request from the
|
|
664
|
+
repository, the shared workflow's Slice started job makes the same moves,
|
|
665
|
+
under the same conditions, with a token from the board GitHub App. It runs
|
|
666
|
+
after Work rules on every event Work rules runs on (the pull request opening
|
|
667
|
+
or reopening, a push to it, an edit of it) and again when a failed Work rules
|
|
668
|
+
is re-run, so a slice that could not be built when its pull request opened
|
|
669
|
+
moves once it can. A slice and work item already where they belong are not
|
|
670
|
+
written again, and a slice no open Project holds gets a line saying it is
|
|
671
|
+
not on the board. The client's
|
|
654
672
|
workflow passes it the app's client id and private key as the
|
|
655
673
|
`NIYAM_BOARD_APP_ID` and `NIYAM_BOARD_APP_KEY` secrets. With `board` on,
|
|
656
674
|
onboard writes them under the `niyam` job's secrets, the pull request job
|
|
@@ -1119,7 +1137,14 @@ or `/schedule`), with claude.ai's GitHub connected as the agent, and the
|
|
|
1119
1137
|
prompt from `routines/review.md` at the release in use. It cannot create the
|
|
1120
1138
|
routine itself: Claude's routines API answers only a Claude Code session's own
|
|
1121
1139
|
sign-in, not a command, and a routine works as claude.ai's GitHub connection,
|
|
1122
|
-
which no API names.
|
|
1140
|
+
which no API names. It takes the routine's trace as evidence it runs instead:
|
|
1141
|
+
once the agent has commented `Kept:`, `Settled:` or `Held for` on any issue of
|
|
1142
|
+
the repository in the last three weeks (onboard reads up to 1,000 of its
|
|
1143
|
+
newest comments, as the agent), the routine leaves "By hand" and the pull
|
|
1144
|
+
request names the verdict it found under "Done at the terminal". Any such
|
|
1145
|
+
comment by the agent counts, one from a session run by hand included. Where no
|
|
1146
|
+
verdict is found in those three weeks, or GitHub does not list the comments,
|
|
1147
|
+
the step stays, ending "skip it if done".
|
|
1123
1148
|
|
|
1124
1149
|
`onboard` also writes a pre-push git hook running `niyam pre-push`,
|
|
1125
1150
|
for every adopter. In a local agent session (one session-start set up, or
|
|
@@ -1652,7 +1677,7 @@ tag and the commit. Install the attached package on each machine with pnpm,
|
|
|
1652
1677
|
once; nothing is built on install:
|
|
1653
1678
|
|
|
1654
1679
|
```bash
|
|
1655
|
-
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.
|
|
1680
|
+
pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.7.2/veda-hq-niyam-0.7.2.tgz
|
|
1656
1681
|
```
|
|
1657
1682
|
|
|
1658
1683
|
The package puts one command on `PATH`, `niyam`. Since P-57 a release
|
package/dist/board.js
CHANGED
|
@@ -631,11 +631,13 @@ export async function boardStarted(sys, token, slug, slice) {
|
|
|
631
631
|
const parent = status === 200 && json?.type?.name === 'Work item' ? json.number : undefined;
|
|
632
632
|
const items = await projectItems(sys, token, slug);
|
|
633
633
|
const steps = stepMoves(items.step, parent);
|
|
634
|
-
const
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
634
|
+
const held = items.status.filter((item) => item.number === slice);
|
|
635
|
+
const moved = await move(sys, token, [...held.map((item) => ({ item, option: 'In Progress', name: `slice #${slice}`, what: `slice #${slice} is In Progress` })), ...steps.moves]);
|
|
636
|
+
// A slice on no Project has nothing to move: say so, rather than let "nothing moved" read as "in place".
|
|
637
|
+
const missing = held.length === 0
|
|
638
|
+
? [`! board: slice #${slice} is not on the board: no open Project of ${slug.split('/')[0]} with a Status field holds it unarchived, so it did not move to In Progress`]
|
|
639
|
+
: [];
|
|
640
|
+
return [...moved, ...missing, ...steps.lacking];
|
|
639
641
|
}
|
|
640
642
|
function stopped(io, step) {
|
|
641
643
|
io.err(`onboard: stopped at "${step}"; nothing after it was changed, and no pull request was opened`);
|
package/dist/doctor.js
CHANGED
|
@@ -8,7 +8,7 @@ import { closing, findingLines, heading, painter, tilde } from './layout.js';
|
|
|
8
8
|
import { exposure, exposureFindings, movedFindings, readDeclined, setAside } from './lockout.js';
|
|
9
9
|
import { CLOUD_SETUP_PATH, HOOKS_PATH, SARATHI_PATH } from './onboard-pull.js';
|
|
10
10
|
import { leftoverDir, leftoverToken } from './machine.js';
|
|
11
|
-
import { BOARD_SECRETS, GUARD_COMMAND, HOOK_COMMAND, OLDER_GUARD_COMMANDS, OLDER_HOOK_COMMANDS,
|
|
11
|
+
import { BOARD_SECRETS, GUARD_COMMAND, HOOK_COMMAND, OLDER_GUARD_COMMANDS, OLDER_HOOK_COMMANDS, ARTIFACT_RULES, AUTO_FIX_RULES, artifactRuleNeeds, autoFixRuleNeeds, sarathiRunner } from './onboard.js';
|
|
12
12
|
import { secretNames } from './secrets.js';
|
|
13
13
|
import { isOrganisation } from './owner-login.js';
|
|
14
14
|
import { leftBehind } from './owner-step.js';
|
|
@@ -264,7 +264,8 @@ function twiceFindings(sys) {
|
|
|
264
264
|
* Which of onboard's Auto-fix and artifact rules the repo's
|
|
265
265
|
* `.claude/settings.json` lacks, so the auto-mode classifier refuses an agent
|
|
266
266
|
* session turning Auto-fix on, or publishing the page an ask to the owner
|
|
267
|
-
* links: checked in an onboarded repo whose file doctor can read.
|
|
267
|
+
* links: checked in an onboarded repo whose file doctor can read. A rule the
|
|
268
|
+
* file's `permissions.deny` overrides is denied on purpose, not missing.
|
|
268
269
|
*/
|
|
269
270
|
function allowFindings(sys) {
|
|
270
271
|
let settings;
|
|
@@ -279,11 +280,22 @@ function allowFindings(sys) {
|
|
|
279
280
|
// Outside a clone, or a file doctor cannot read: onboard says what is wrong with it.
|
|
280
281
|
return [];
|
|
281
282
|
}
|
|
282
|
-
const missing = missingAutoFixRules(settings);
|
|
283
|
-
const unpublished = missingArtifactRules(settings);
|
|
284
283
|
return [
|
|
285
|
-
...(
|
|
286
|
-
...(
|
|
284
|
+
...groupFindings(autoFixRuleNeeds(settings), AUTO_FIX_RULES, 'agent sessions cannot turn Auto-fix on', 'agent sessions do not turn Auto-fix on'),
|
|
285
|
+
...groupFindings(artifactRuleNeeds(settings), ARTIFACT_RULES, 'agent sessions cannot publish the page an ask to the owner links', 'agent sessions do not publish pages'),
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* One group's findings: ▲ for the rules it lacks, and ✓ for those its deny
|
|
290
|
+
* rules override, which the owner chose and onboard leaves out, so nothing
|
|
291
|
+
* there is to fix. A whole group denied says what sessions then do not do;
|
|
292
|
+
* a part of one names the tools denied, since the others still work.
|
|
293
|
+
*/
|
|
294
|
+
function groupFindings(needs, rules, cannot, chosen) {
|
|
295
|
+
const so = needs.denied.length === rules.length ? chosen : `agent sessions do not use ${needs.denied.join(', ')}`;
|
|
296
|
+
return [
|
|
297
|
+
...(needs.missing.length === 0 ? [] : [{ mark: '▲', text: `${HOOKS_PATH} does not allow ${needs.missing.join(', ')}, so ${cannot}`, fix: ONBOARD }]),
|
|
298
|
+
...(needs.denied.length === 0 ? [] : [{ mark: '✓', text: `${HOOKS_PATH} denies ${needs.deniedBy.join(', ')} on purpose, so ${so}` }]),
|
|
287
299
|
];
|
|
288
300
|
}
|
|
289
301
|
/** Prints the findings, grouped, and closes; exit 1 when any is broken. */
|
package/dist/onboard.js
CHANGED
|
@@ -7,6 +7,7 @@ import { typesDetail, typesLines, typesPlan } from './issue-types.js';
|
|
|
7
7
|
import { asOwner, isOrganisation, ownerScopes, signInOnce } from './owner-login.js';
|
|
8
8
|
import { appendToArray, removeElements, replaceValues, setMember } from './jsonedit.js';
|
|
9
9
|
import { HOURLY } from './asks.js';
|
|
10
|
+
import { routineTrace } from './reviews.js';
|
|
10
11
|
import { DEFAULT_SCHEDULE, FEATURES, FIGMA_FILE_KEY, NEEDS_ISSUE_TYPES, featuresIn, parseFeatures, renamedLines, scheduleIn } from './features.js';
|
|
11
12
|
import { CLOUD_SETUP_PATH, HOOKS_PATH, LEFTOVER_CLOUD_SETUP_PATH, ONBOARD_BRANCH, SARATHI_PATH, WORKFLOW_PATH, autoMerge, mergeQueue, openPull, remoteFile, } from './onboard-pull.js';
|
|
12
13
|
import { SIGNING_KEY_VAR, cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
|
|
@@ -225,22 +226,61 @@ export const ARTIFACT_RULES = ['mcp__claude-artifacts__publish_version', 'mcp__c
|
|
|
225
226
|
/** The rules that allow every tool of the artifacts server, ARTIFACT_RULES among them. */
|
|
226
227
|
const ARTIFACT_SERVER_RULES = ['mcp__claude-artifacts', 'mcp__claude-artifacts__*'];
|
|
227
228
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
229
|
+
* Whether deny rule `by` matches MCP tool `tool` of the server named `bare`
|
|
230
|
+
* (`mcp__<server>`), as Claude Code's permissions page says rules match: the
|
|
231
|
+
* tool's own name, the bare server, `*` and `mcp__*` (every tool, every MCP
|
|
232
|
+
* tool), and a glob in the tool name after a literal `mcp__<server>__`, such
|
|
233
|
+
* as `mcp__<server>__*` or `mcp__<server>__publish_*`. A glob in the server's
|
|
234
|
+
* own name the page does not describe, so it matches nothing here.
|
|
230
235
|
*/
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
function deniesTool(by, tool, bare) {
|
|
237
|
+
if (by === tool || by === bare || by === '*' || by === 'mcp__*')
|
|
238
|
+
return true;
|
|
239
|
+
const prefix = `${bare}__`;
|
|
240
|
+
if (!by.startsWith(prefix) || !by.includes('*') || !tool.startsWith(prefix))
|
|
241
|
+
return false;
|
|
242
|
+
const glob = by.slice(prefix.length).split('*').map((part) => part.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*');
|
|
243
|
+
return new RegExp(`^${glob}$`).test(tool.slice(prefix.length));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Which of `rules` a settings file lacks, in their order: none lacks when
|
|
247
|
+
* its `permissions.allow` allows the whole server, by one of `server`. Claude
|
|
248
|
+
* Code applies deny before allow, so a rule that `permissions.deny` overrides
|
|
249
|
+
* (`deniesTool`) is denied, not missing: an allow rule for it would do
|
|
250
|
+
* nothing. A deny or allow that is not an array names nothing.
|
|
251
|
+
*/
|
|
252
|
+
function ruleNeeds(settings, rules, server) {
|
|
253
|
+
const permissions = settings?.permissions;
|
|
254
|
+
const listed = (value) => (Array.isArray(value) ? value.filter((rule) => typeof rule === 'string') : []);
|
|
255
|
+
const allow = listed(permissions?.allow);
|
|
256
|
+
const deny = listed(permissions?.deny);
|
|
257
|
+
const bare = server[0];
|
|
258
|
+
const deniedBy = deny.filter((by) => rules.some((rule) => deniesTool(by, rule, bare)));
|
|
259
|
+
const denied = rules.filter((rule) => deny.some((by) => deniesTool(by, rule, bare)));
|
|
260
|
+
if (allow.some((rule) => server.includes(rule)))
|
|
261
|
+
return { missing: [], denied, leftOut: [], deniedBy, leftOutBy: [] };
|
|
262
|
+
const lacking = rules.filter((rule) => !allow.includes(rule));
|
|
263
|
+
const leftOut = lacking.filter((rule) => denied.includes(rule));
|
|
264
|
+
const leftOutBy = deniedBy.filter((by) => leftOut.some((rule) => deniesTool(by, rule, bare)));
|
|
265
|
+
return { missing: lacking.filter((rule) => !denied.includes(rule)), denied, leftOut, deniedBy, leftOutBy };
|
|
266
|
+
}
|
|
267
|
+
/** Which of AUTO_FIX_RULES a settings file lacks, and which its deny rules override. */
|
|
268
|
+
export function autoFixRuleNeeds(settings) {
|
|
269
|
+
return ruleNeeds(settings, AUTO_FIX_RULES, PR_SERVER_RULES);
|
|
236
270
|
}
|
|
237
|
-
/** Which of
|
|
238
|
-
export function
|
|
239
|
-
return
|
|
271
|
+
/** Which of ARTIFACT_RULES a settings file lacks, and which its deny rules override. */
|
|
272
|
+
export function artifactRuleNeeds(settings) {
|
|
273
|
+
return ruleNeeds(settings, ARTIFACT_RULES, ARTIFACT_SERVER_RULES);
|
|
240
274
|
}
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
|
|
275
|
+
/**
|
|
276
|
+
* What a group's left-out rules come to, in a line for onboard's plan: the
|
|
277
|
+
* group's name when the deny leaves all of it out, else the rules it does.
|
|
278
|
+
* A denied rule the file allows already is not left out, and goes unsaid.
|
|
279
|
+
*/
|
|
280
|
+
function deniedLines(needs, rules, group) {
|
|
281
|
+
if (needs.leftOut.length === 0)
|
|
282
|
+
return [];
|
|
283
|
+
return [`${needs.leftOut.length === rules.length ? group : needs.leftOut.join(', ')} left out: ${HOOKS_PATH} denies ${needs.leftOutBy.join(', ')}`];
|
|
244
284
|
}
|
|
245
285
|
/** The hook commands older releases wrote, which onboard replaces with this release's. */
|
|
246
286
|
export const OLDER_HOOK_COMMANDS = [
|
|
@@ -833,6 +873,8 @@ function handlersOf(sarathi, event) {
|
|
|
833
873
|
* entry an older release wrote swapped where it stands, a missing one added,
|
|
834
874
|
* the lock's variables set in `env`, and REVIEW_THREAD_RULE, AUTO_FIX_RULES and ARTIFACT_RULES allowed. Every edit is made in the text, so
|
|
835
875
|
* the rest of the file keeps its layout. Says what changed, for the question.
|
|
876
|
+
* A rule the file's `permissions.deny` overrides is not allowed, since the
|
|
877
|
+
* allow would do nothing; `denied` says which, for the plan, only when any is.
|
|
836
878
|
*
|
|
837
879
|
* Where the project keeps `.claude/sarathi.json` (`sarathiBefore`) and the
|
|
838
880
|
* settings run sarathi for an event, with a matcher that lets niyam's hook
|
|
@@ -850,6 +892,7 @@ export function claudeSettings(before, sarathiBefore) {
|
|
|
850
892
|
let moved = false;
|
|
851
893
|
let timed = false;
|
|
852
894
|
const labels = [];
|
|
895
|
+
const denied = [];
|
|
853
896
|
const parsed = () => JSON.parse(text);
|
|
854
897
|
const first = parsed();
|
|
855
898
|
if (typeof first !== 'object' || first === null || Array.isArray(first))
|
|
@@ -985,18 +1028,22 @@ export function claudeSettings(before, sarathiBefore) {
|
|
|
985
1028
|
text = appendToArray(text, ['permissions'], 'allow', REVIEW_THREAD_RULE);
|
|
986
1029
|
changes.push('allow niyam review-thread without a prompt, so agent sessions answer review threads on their own pull requests');
|
|
987
1030
|
}
|
|
988
|
-
const
|
|
1031
|
+
const autoFix = autoFixRuleNeeds(parsed());
|
|
1032
|
+
const lacking = autoFix.missing;
|
|
989
1033
|
for (const rule of lacking)
|
|
990
1034
|
text = appendToArray(text, ['permissions'], 'allow', rule);
|
|
991
1035
|
if (lacking.length > 0) {
|
|
992
1036
|
changes.push(`allow ${lacking.join(', ')} without a prompt, so agent sessions turn Auto-fix on for their own pull requests`);
|
|
993
1037
|
}
|
|
994
|
-
const
|
|
1038
|
+
const artifacts = artifactRuleNeeds(parsed());
|
|
1039
|
+
const unpublished = artifacts.missing;
|
|
995
1040
|
for (const rule of unpublished)
|
|
996
1041
|
text = appendToArray(text, ['permissions'], 'allow', rule);
|
|
997
1042
|
if (unpublished.length > 0) {
|
|
998
1043
|
changes.push(`allow ${unpublished.join(', ')} without a prompt, so agent sessions publish the page an ask to the owner links`);
|
|
999
1044
|
}
|
|
1045
|
+
// A rule the file denies is the owner's choice: an allow rule for it would do nothing, so the plan says so instead.
|
|
1046
|
+
denied.push(...deniedLines(autoFix, AUTO_FIX_RULES, 'Auto-fix rules'), ...deniedLines(artifacts, ARTIFACT_RULES, 'artifact rules'));
|
|
1000
1047
|
// One group's own word, or one word for several, so the plan's line stays short.
|
|
1001
1048
|
const groups = [review || renamed.replaced > 0 ? 'review rule' : '', lacking.length > 0 ? 'Auto-fix rules' : '', unpublished.length > 0 ? 'artifact rules' : ''].filter(Boolean);
|
|
1002
1049
|
if (groups.length > 0)
|
|
@@ -1005,14 +1052,15 @@ export function claudeSettings(before, sarathiBefore) {
|
|
|
1005
1052
|
catch (error) {
|
|
1006
1053
|
throw new Error(`${HOOKS_PATH}: ${error.message}`);
|
|
1007
1054
|
}
|
|
1055
|
+
const said = denied.length > 0 ? { denied } : {};
|
|
1008
1056
|
if (sarathi !== undefined && sarathi.changes.length > 0) {
|
|
1009
1057
|
if (handlersChanged)
|
|
1010
1058
|
sarathi.labels.push(`hooks ${handlersChanged}`);
|
|
1011
1059
|
if (handlersTimed)
|
|
1012
1060
|
sarathi.labels.push('timeout');
|
|
1013
|
-
return { text, changes, labels, sarathi };
|
|
1061
|
+
return { text, changes, labels, ...said, sarathi };
|
|
1014
1062
|
}
|
|
1015
|
-
return { text, changes, labels };
|
|
1063
|
+
return { text, changes, labels, ...said };
|
|
1016
1064
|
}
|
|
1017
1065
|
/** Who the run's sign-in is, the owner's likely login; undefined when it failed. */
|
|
1018
1066
|
async function signedInLogin(signIn) {
|
|
@@ -1370,6 +1418,7 @@ export async function onboard(sys, io, args = []) {
|
|
|
1370
1418
|
const existing = fileAt(HOOKS_PATH);
|
|
1371
1419
|
// Worked out before the plan, so a file onboard cannot edit is refused before any question.
|
|
1372
1420
|
const claude = claudeSettings(existing, fileAt(SARATHI_PATH));
|
|
1421
|
+
warnings.push(...(claude.denied ?? []));
|
|
1373
1422
|
if (claude.changes.length > 0) {
|
|
1374
1423
|
pull.push({ label: 'settings.json', detail: existing === undefined ? 'new' : claude.labels.join(', ') });
|
|
1375
1424
|
change(HOOKS_PATH, claude.text, claude.changes.join('; '));
|
|
@@ -1557,11 +1606,19 @@ export async function onboard(sys, io, args = []) {
|
|
|
1557
1606
|
},
|
|
1558
1607
|
});
|
|
1559
1608
|
// Claude's routines API answers only a Claude Code session's own sign-in, and a routine works as claude.ai's GitHub
|
|
1560
|
-
// connection, so onboard cannot create one or check it.
|
|
1609
|
+
// connection, so onboard cannot create one or check it; it sees one runs by the agent's verdicts on the repository.
|
|
1561
1610
|
if (on('review')) {
|
|
1562
1611
|
const routine = `${GITHUB_WEB}/${PRODUCT}/blob/v${version}/routines/review.md`;
|
|
1563
|
-
|
|
1564
|
-
|
|
1612
|
+
const seen = await routineTrace(sys, slug, agent, token).catch(() => {
|
|
1613
|
+
// fail-open: comments GitHub does not give leave the routine by hand, which the owner skips if done.
|
|
1614
|
+
return undefined;
|
|
1615
|
+
});
|
|
1616
|
+
if (seen)
|
|
1617
|
+
notes.push(`- review routine: ${agent} gave a verdict on #${seen.number} on ${seen.date}, so it runs`);
|
|
1618
|
+
else {
|
|
1619
|
+
byHand.push(`Once for ${slug}: in Claude Code, run /schedule and create a weekly routine on it, with claude.ai's GitHub connected as ${agent} and the prompt below the line in ${routine}; skip it if done.`);
|
|
1620
|
+
later.push(`The review routine: create a weekly Claude routine on ${slug} (claude.ai/code/routines, or /schedule in Claude Code), with claude.ai's GitHub connected as ${agent}, and give it the prompt below the line in ${routine}. Until it gives its verdicts, the weekly job labels needs-owner each decision over a week past its review date.`);
|
|
1621
|
+
}
|
|
1565
1622
|
}
|
|
1566
1623
|
// Claude cloud sessions. Claude Code has no API for a cloud environment's Setup script, so the version lives in a
|
|
1567
1624
|
// file the repo owns, written at the pin on every run, and the SessionStart hook runs it when a session has no CLI.
|
package/dist/reviews.js
CHANGED
|
@@ -236,6 +236,54 @@ export async function watchReviews(sys, io, slug, token, settings) {
|
|
|
236
236
|
io.out(`#${issue.number}: its review, ${review}, is over a week past with no verdict from the agent; labeled needs-owner`);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
+
/** The verdicts in routines/review.md, holds included: a comment by the agent starting with one is the review routine's trace. */
|
|
240
|
+
const ROUTINE_VERDICT = /^\s*(?:Kept:|Settled:|Held for )/;
|
|
241
|
+
/** How far back onboard looks for the routine's trace: three of its weekly runs. */
|
|
242
|
+
export const TRACE_DAYS = 21;
|
|
243
|
+
/** The pages of 100 comments onboard reads at most, newest first. */
|
|
244
|
+
const TRACE_PAGES = 10;
|
|
245
|
+
/** GitHub's timestamps: UTC, to the second or finer. */
|
|
246
|
+
const INSTANT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?Z$/;
|
|
247
|
+
/** A GitHub timestamp in milliseconds, or undefined for one that is not such a time, or names no real date. */
|
|
248
|
+
function instant(text) {
|
|
249
|
+
const parts = INSTANT.exec(text ?? '');
|
|
250
|
+
if (!parts)
|
|
251
|
+
return undefined;
|
|
252
|
+
// Milliseconds count, so a verdict a moment after the cutoff, in its second, is not taken for one before it.
|
|
253
|
+
const milliseconds = (parts[7] ?? '').padEnd(3, '0').slice(0, 3);
|
|
254
|
+
const [year, month, day, hour, minute, second, ms] = [...parts.slice(1, 7), milliseconds].map(Number);
|
|
255
|
+
const time = Date.UTC(year, month - 1, day, hour, minute, second, ms);
|
|
256
|
+
// Date.UTC rolls 30 February into March: a time that does not read back the same was never a date.
|
|
257
|
+
return new Date(time).toISOString().slice(0, 19) === text.slice(0, 19) ? time : undefined;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The review routine's newest verdict on `slug` in the last three weeks, as
|
|
261
|
+
* the issue it is on and its date, or undefined when there is none: onboard
|
|
262
|
+
* cannot read Claude's routines, so a verdict by the agent is how it sees the
|
|
263
|
+
* routine runs. Reads at most ten pages of the repository's issue comments,
|
|
264
|
+
* newest first; throws where GitHub refuses them.
|
|
265
|
+
*/
|
|
266
|
+
export async function routineTrace(sys, slug, agent, token) {
|
|
267
|
+
const cutoff = sys.now().getTime() - TRACE_DAYS * DAY_MS;
|
|
268
|
+
const since = new Date(cutoff).toISOString();
|
|
269
|
+
for (let page = 1; page <= TRACE_PAGES; page++) {
|
|
270
|
+
const { status, json } = await sys.http(`${API}/repos/${slug}/issues/comments?since=${since}&sort=created&direction=desc&per_page=100&page=${page}`, { token });
|
|
271
|
+
if (status !== 200 || !Array.isArray(json))
|
|
272
|
+
throw new Error(`cannot list ${slug}'s issue comments (HTTP ${status})`);
|
|
273
|
+
for (const comment of json) {
|
|
274
|
+
// `since` is by last update: an older verdict edited lately is not a recent run.
|
|
275
|
+
const created = instant(comment.created_at);
|
|
276
|
+
const number = Number(/\/issues\/(\d+)$/.exec(comment.issue_url ?? '')?.[1]);
|
|
277
|
+
if (created === undefined || created < cutoff || !Number.isInteger(number))
|
|
278
|
+
continue;
|
|
279
|
+
if (anyLogin([agent], comment.user?.login ?? undefined) && ROUTINE_VERDICT.test(comment.body ?? ''))
|
|
280
|
+
return { number, date: comment.created_at.slice(0, 10) };
|
|
281
|
+
}
|
|
282
|
+
if (json.length < 100)
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
239
287
|
/**
|
|
240
288
|
* Removes `veto` labels the routine added more than a week ago: the owner's
|
|
241
289
|
* window to reverse that decision has closed. Part of the weekly job.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veda-hq/niyam",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@types/node": "24.19.2",
|
|
29
29
|
"@veda-hq/dvara": "0.5.16",
|
|
30
30
|
"@veda-hq/pariksha": "0.5.20",
|
|
31
|
-
"@veda-hq/sarathi": "0.
|
|
31
|
+
"@veda-hq/sarathi": "0.7.1",
|
|
32
32
|
"typescript": "7.0.2"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|