@veda-hq/niyam 0.6.22 → 0.6.23

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/dist/onboard.js CHANGED
@@ -9,7 +9,7 @@ import { DEFAULT_SCHEDULE, FEATURES, FIGMA_FILE_KEY, NEEDS_ISSUE_TYPES, features
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
10
  import { cloudRepoScript, cloudScriptVersion, releaseSha256 } from './cloud.js';
11
11
  import { tagOnMain } from './release-tag.js';
12
- import { setSecret } from './secrets.js';
12
+ import { secretNames, setSecret } from './secrets.js';
13
13
  import { UPGRADE } from './upgrade.js';
14
14
  import { isNewer, packageVersion } from './version.js';
15
15
  import { GITHUB_WEB } from './host.js';
@@ -442,12 +442,46 @@ function workflowHead(branch, version, comments, schedule = DEFAULT_SCHEDULE, ty
442
442
  const FIGMA_SECRETS = [' secrets:', ' FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}', ' FIGMA_LIBRARY: ${{ secrets.FIGMA_LIBRARY }}'];
443
443
  /** The secrets every job passed before P-23, whether figma was on or not. */
444
444
  const OLDER_SECRETS = [' secrets:', ' FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}'];
445
+ /** The board GitHub App's secrets, which the Slice started job makes its board token from (P-70). */
446
+ export const BOARD_SECRETS = ['NIYAM_BOARD_APP_ID', 'NIYAM_BOARD_APP_KEY'];
447
+ const BOARD_SECRET_LINES = BOARD_SECRETS.map((name) => ` ${name}: \${{ secrets.${name} }}`);
448
+ /** What each board app secret holds. */
449
+ const BOARD_SECRET_HOLDS = { NIYAM_BOARD_APP_ID: 'client id', NIYAM_BOARD_APP_KEY: 'private key' };
445
450
  /**
446
- * A job's `niyam-ref` line and the block of Figma secrets after it, as
447
- * either list writes it, or the line alone when no secrets follow: a block
448
- * with secrets of the client's own is left as it is.
451
+ * The owner's steps, once per organization, to give `slug`'s Slice started
452
+ * job the board app's token: make the app, install it, and set the secrets
453
+ * `missing`. `unknown` when GitHub would not list the secrets, so they may be
454
+ * set already.
449
455
  */
450
- const SECRETS_AFTER_REF = /^( {6}niyam-ref:[^\n]*\n)(?: {4}secrets:\n(?: {6}FIGMA_(?:TOKEN|LIBRARY): \$\{\{ secrets\.FIGMA_(?:TOKEN|LIBRARY) \}\}\n)+(?! {6})|(?! {4}secrets:))/gm;
456
+ export function boardAppSteps(slug, missing, unknown = false) {
457
+ const org = slug.split('/')[0];
458
+ const set = missing.map((name) => `its ${BOARD_SECRET_HOLDS[name]} as ${name}`).join(' and ');
459
+ return (`${unknown ? `Unless ${slug} has the Actions secrets ${BOARD_SECRETS.join(' and ')} already, once` : 'Once'} for ${org}: ` +
460
+ `make a GitHub App with organization Projects read and write and repository Issues read at ${GITHUB_WEB}/organizations/${org}/settings/apps/new, ` +
461
+ `install it on ${slug}, and set ${set}, Actions secrets of the organization or of ${GITHUB_WEB}/${slug}/settings/secrets/actions. ` +
462
+ 'Until then a slice moves to In Progress on the board only from a desktop push.');
463
+ }
464
+ /**
465
+ * The secrets block job `id` passes the shared checks: the Figma secrets on
466
+ * every job, and the board app's on the pull request job alone, since only
467
+ * its Slice started job uses them.
468
+ */
469
+ function secretsOf(id, { figma, board }) {
470
+ const lines = [...(figma ? FIGMA_SECRETS.slice(1) : []), ...(board && id === CLI ? BOARD_SECRET_LINES : [])];
471
+ return lines.length > 0 ? [' secrets:', ...lines] : [];
472
+ }
473
+ /** A secret onboard writes, by name, as a line of a job's block. */
474
+ const OWN_SECRET = String.raw `(?:FIGMA_(?:TOKEN|LIBRARY)|NIYAM_BOARD_APP_(?:ID|KEY))`;
475
+ /**
476
+ * A job's `niyam-ref` line and the block of onboard's secrets after it, as
477
+ * any release writes it, or the line alone when no secrets follow: a block
478
+ * with secrets of the client's own, or `secrets: inherit`, is left as it is.
479
+ */
480
+ const SECRETS_AFTER_REF = new RegExp(String.raw `^( {6}niyam-ref:[^\n]*\n)(?: {4}secrets:\n(?: {6}${OWN_SECRET}: \$\{\{ secrets\.${OWN_SECRET} \}\}\n)+(?! {6})|(?! {4}secrets:))`, 'gm');
481
+ /** The id of the job whose lines run through `offset` in workflow `text`: the last two-space key before it. */
482
+ function jobAt(text, offset) {
483
+ return [...text.slice(0, offset).matchAll(/^ {2}([\w-]+):[ \t]*$/gm)].at(-1)?.[1];
484
+ }
451
485
  /**
452
486
  * The jobs of a workflow that call the shared checks without passing them
453
487
  * FIGMA_LIBRARY, by name: each job's own block is read, so one job missing it
@@ -471,10 +505,11 @@ function callChecks(version, secrets) {
471
505
  * to the default branch and weekly, at the niyam release `version`.
472
506
  * Pull request and push runs are read-only; the weekly job alone writes to
473
507
  * issues. Upgrading is changing that version, which each job names twice.
474
- * The Figma secrets are passed only when the figma feature is on; the
508
+ * The Figma secrets are passed only when the figma feature is on, and the
509
+ * board app's, by the pull request job alone, only when `board` is; the
475
510
  * weekly job runs on the settings' `schedule`.
476
511
  */
477
- export function workflow(branch, version, figma, schedule = DEFAULT_SCHEDULE, settings = SETTINGS_PATH) {
512
+ export function workflow(branch, version, figma, schedule = DEFAULT_SCHEDULE, settings = SETTINGS_PATH, board = false) {
478
513
  const secrets = figma ? FIGMA_SECRETS : [];
479
514
  return [
480
515
  ...workflowHead(branch, version, [
@@ -485,7 +520,7 @@ export function workflow(branch, version, figma, schedule = DEFAULT_SCHEDULE, se
485
520
  ` ${CLI}:`,
486
521
  jobName(CLI),
487
522
  READ_ONLY_IF,
488
- ...callChecks(version, secrets),
523
+ ...callChecks(version, secretsOf(CLI, { figma, board })),
489
524
  '',
490
525
  ' # The weekly run alone writes to issues: it comments and opens undo issues.',
491
526
  ` ${CLI}-weekly:`,
@@ -537,17 +572,23 @@ function flowScalar(value, quote) {
537
572
  * already split into a read-only `niyam` job and a `niyam-weekly` job, move
538
573
  * the version pins, the one branch pushes run on when the default branch has
539
574
  * changed, the one cron the weekly job runs on when the settings' schedule
540
- * has changed, and each job's Figma secrets to what the figma feature needs,
575
+ * has changed, and each job's Figma secrets to what the figma feature needs
576
+ * and the pull request job's board app secrets to what `board` needs,
541
577
  * leaving the rest as the client has it; any other workflow is replaced.
542
578
  */
543
- export function workflowUpdate(before, branch, version, figma, schedule = DEFAULT_SCHEDULE, settings = SETTINGS_PATH) {
579
+ export function workflowUpdate(before, branch, version, figma, schedule = DEFAULT_SCHEDULE, settings = SETTINGS_PATH, board = false) {
544
580
  if (before === undefined)
545
- return { kind: 'write', text: workflow(branch, version, figma, schedule, settings) };
546
- return repinned(before, branch, version, figma, schedule, settings);
581
+ return { kind: 'write', text: workflow(branch, version, figma, schedule, settings, board) };
582
+ return repinned(before, branch, version, figma, schedule, settings, board);
583
+ }
584
+ /** The secrets of onboard's own a block of a job names, by what they are for. */
585
+ function ownSecrets(block) {
586
+ const names = [...block.matchAll(/^ {6}([\w-]+):/gm)].map((match) => match[1]);
587
+ return { figma: names.filter((name) => name.startsWith('FIGMA_')).join(','), board: names.filter((name) => name.startsWith('NIYAM_BOARD_')).join(',') };
547
588
  }
548
589
  /** workflowUpdate on a workflow that is there. */
549
- function repinned(before, branch, version, figma, schedule, settings) {
550
- const wanted = workflow(branch, version, figma, schedule, settings);
590
+ function repinned(before, branch, version, figma, schedule, settings, board) {
591
+ const wanted = workflow(branch, version, figma, schedule, settings, board);
551
592
  if (before === wanted)
552
593
  return { kind: 'same' };
553
594
  const pins = workflowPins(before);
@@ -558,13 +599,13 @@ function repinned(before, branch, version, figma, schedule, settings) {
558
599
  const merged = job(`${CLI}-merged`);
559
600
  const added = split && !merged && pins.length === 4 && from !== undefined ? addMergedJob(before, from, figma) : undefined;
560
601
  if (added !== undefined) {
561
- const update = repinned(added, branch, version, figma, schedule, settings);
602
+ const update = repinned(added, branch, version, figma, schedule, settings, board);
562
603
  return { ...(update.kind === 'repin' ? update : { text: added }), kind: 'repin', merged: true };
563
604
  }
564
605
  const asks = job(`${CLI}-asks`);
565
606
  const withAsks = split && merged && !asks && pins.length === 6 && from !== undefined ? addAsksJob(before, from, figma) : undefined;
566
607
  if (withAsks !== undefined) {
567
- const update = repinned(withAsks, branch, version, figma, schedule, settings);
608
+ const update = repinned(withAsks, branch, version, figma, schedule, settings, board);
568
609
  // The asks job it adds also types each new issue, so the plan says so.
569
610
  return { ...(update.kind === 'repin' ? update : { text: withAsks }), kind: 'repin', asks: true, types: true };
570
611
  }
@@ -590,12 +631,31 @@ function repinned(before, branch, version, figma, schedule, settings) {
590
631
  .replace(HEADER_PIN, (_, _head, _old, dot) => `# Written by ${CLI} onboard: the shared ${CLI} checks at v${version}${dot}`)
591
632
  .replace(PUSH_BRANCH, (line, head, quote, _old, tail) => moved ? `${head}${flowScalar(branch, quote)}${tail}` : line)
592
633
  .replace(SCHEDULE, (line, comment, head, quote, _old, tail) => rescheduled ? `${comment === undefined ? '' : `${scheduleComment(schedule, settings)}\n`}${head}${quote || "'"}${schedule}${quote || "'"}${tail}` : line);
593
- const secrets = figma ? `${FIGMA_SECRETS.join('\n')}\n` : '';
594
- const text = pinned.replace(SECRETS_AFTER_REF, (_, ref) => `${ref}${secrets}`);
634
+ // Each job's block as that job passes it; which part changed, Figma's or the board app's, is said apart.
635
+ const changed = { figma: false, board: false };
636
+ const text = pinned.replace(SECRETS_AFTER_REF, (block, ref, offset, whole) => {
637
+ const lines = secretsOf(jobAt(whole, offset) ?? '', { figma, board });
638
+ const now = `${ref}${lines.map((line) => `${line}\n`).join('')}`;
639
+ const had = ownSecrets(block);
640
+ const has = ownSecrets(now);
641
+ changed.figma ||= had.figma !== has.figma;
642
+ changed.board ||= had.board !== has.board;
643
+ return now;
644
+ });
595
645
  if (text === before)
596
646
  return { kind: 'same' };
597
647
  const stale = pins.find((pin) => pin !== version);
598
- return { kind: 'repin', text, ...(stale ? { from: stale } : {}), ...(moved ? { branch } : {}), ...(rescheduled ? { schedule } : {}), ...(text !== pinned ? { secrets: true } : {}), ...(authors ? { authors: true } : {}), ...(types ? { types: true } : {}) };
648
+ return {
649
+ kind: 'repin',
650
+ text,
651
+ ...(stale ? { from: stale } : {}),
652
+ ...(moved ? { branch } : {}),
653
+ ...(rescheduled ? { schedule } : {}),
654
+ ...(changed.figma ? { secrets: true } : {}),
655
+ ...(changed.board ? { board: true } : {}),
656
+ ...(authors ? { authors: true } : {}),
657
+ ...(types ? { types: true } : {}),
658
+ };
599
659
  }
600
660
  return { kind: 'replace', text: wanted };
601
661
  }
@@ -992,7 +1052,7 @@ export function onboardArgs(args) {
992
1052
  return { named, ...(features ? { features } : {}), ...(add ? { add } : {}), ...(yes ? { yes: true } : {}), ...(dryRun ? { dryRun: true } : {}) };
993
1053
  }
994
1054
  /** What a workflow update changes, in a few words for the plan. */
995
- function workflowDetail(update, version, figma) {
1055
+ function workflowDetail(update, version, { figma, board }) {
996
1056
  if (update.kind !== 'repin')
997
1057
  return { write: 'new', replace: 'replaced' }[update.kind];
998
1058
  return ([
@@ -1000,6 +1060,7 @@ function workflowDetail(update, version, figma) {
1000
1060
  ...(update.branch ? [`branch → ${update.branch}`] : []),
1001
1061
  ...(update.schedule ? [`schedule → ${update.schedule}`] : []),
1002
1062
  ...(update.secrets ? [figma ? 'Figma secrets' : 'no Figma secrets'] : []),
1063
+ ...(update.board ? [board ? 'board app secrets' : 'no board app secrets'] : []),
1003
1064
  ...(update.merged ? ['merged job'] : []),
1004
1065
  ...(update.asks ? ['needs-owner job'] : []),
1005
1066
  ...(update.authors ? ['needs-owner job only for owners, members and collaborators'] : []),
@@ -1007,7 +1068,7 @@ function workflowDetail(update, version, figma) {
1007
1068
  ].join(', ') || `header → v${version}`);
1008
1069
  }
1009
1070
  /** What a workflow update changes, in full for the pull request's description. */
1010
- function workflowWhat(update, version, figma, schedulePath, file = WORKFLOW_PATH) {
1071
+ function workflowWhat(update, version, { figma, board }, schedulePath, file = WORKFLOW_PATH) {
1011
1072
  if (update.kind !== 'repin') {
1012
1073
  return {
1013
1074
  write: `write ${WORKFLOW_PATH}, which runs the shared niyam checks`,
@@ -1019,6 +1080,9 @@ function workflowWhat(update, version, figma, schedulePath, file = WORKFLOW_PATH
1019
1080
  ...(update.branch ? [`run pushes on the default branch, ${update.branch}`] : []),
1020
1081
  ...(update.schedule ? [`run the weekly decisions job on the schedule ${schedulePath} sets, cron ${update.schedule} UTC`] : []),
1021
1082
  ...(update.secrets ? [figma ? 'pass the FIGMA_TOKEN and FIGMA_LIBRARY secrets' : 'stop passing Figma secrets, with figma off'] : []),
1083
+ ...(update.board
1084
+ ? [board ? `pass the pull request job's checks the board app's ${BOARD_SECRETS.join(' and ')} secrets, which move a slice to In Progress when its pull request opens` : 'stop passing the board app secrets, with board off']
1085
+ : []),
1022
1086
  ...(update.merged ? ['add a job that closes the slice a merged pull request names, the one pull request run that writes to issues'] : []),
1023
1087
  ...(update.asks ? ["add a job that labels an issue needs-owner where the agent asks the owner, and takes it off at the owner's approved label, Decision: comment or (hourly) 👍"] : []),
1024
1088
  ...(update.authors ? ['start the needs-owner job only on a comment by the owner, a member or a collaborator'] : []),
@@ -1369,14 +1433,26 @@ export async function onboard(sys, io, args = []) {
1369
1433
  }
1370
1434
  // The shared checks run only for features that need them.
1371
1435
  const workflowFrom = workflowPins(fileAt(WORKFLOW_PATH) ?? '')[0];
1436
+ const passed = { figma: on('figma'), board: on('board') };
1372
1437
  const workflowFor = (branch) => {
1373
- const update = workflowUpdate(fileAt(WORKFLOW_PATH), branch, version, on('figma'), schedule);
1438
+ const update = workflowUpdate(fileAt(WORKFLOW_PATH), branch, version, passed.figma, schedule, SETTINGS_PATH, passed.board);
1374
1439
  if (update.kind !== 'same')
1375
- change(WORKFLOW_PATH, update.text, workflowWhat(update, version, on('figma'), SETTINGS_PATH));
1440
+ change(WORKFLOW_PATH, update.text, workflowWhat(update, version, passed, SETTINGS_PATH));
1376
1441
  };
1442
+ // The Slice started job's board token comes from the board app's secrets, which only the owner can make (P-70).
1443
+ // A personal repository's checks skip the work rules, so it needs none.
1444
+ if (workflowNeeded && passed.board && (await byOrganisation())) {
1445
+ const names = await secretNames(sys, slug, token);
1446
+ const missing = BOARD_SECRETS.filter((name) => !names?.includes(name));
1447
+ if (missing.length > 0) {
1448
+ const steps = boardAppSteps(slug, missing, names === undefined);
1449
+ byHand.push(steps);
1450
+ later.push(steps);
1451
+ }
1452
+ }
1377
1453
  if (workflowNeeded) {
1378
- const update = planned === undefined ? undefined : workflowUpdate(fileAt(WORKFLOW_PATH), planned, version, on('figma'), schedule);
1379
- const detail = update === undefined ? (fileAt(WORKFLOW_PATH) === undefined ? 'new' : 'write or update') : update.kind === 'same' ? undefined : workflowDetail(update, version, on('figma'));
1454
+ const update = planned === undefined ? undefined : workflowUpdate(fileAt(WORKFLOW_PATH), planned, version, passed.figma, schedule, SETTINGS_PATH, passed.board);
1455
+ const detail = update === undefined ? (fileAt(WORKFLOW_PATH) === undefined ? 'new' : 'write or update') : update.kind === 'same' ? undefined : workflowDetail(update, version, passed);
1380
1456
  if (detail !== undefined)
1381
1457
  pull.push({ label: 'workflow', detail });
1382
1458
  }
package/dist/run.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { homedir } from 'node:os';
2
2
  import { LOCKED, asAgent, asAgentArgs } from './as-agent.js';
3
+ import { auditArgs, boardAudit } from './board-audit.js';
3
4
  import { cloudSetup } from './cloud.js';
5
+ import { cloudKey, cloudKeyArgs } from './cloud-key.js';
4
6
  import { needsOwner } from './asks.js';
5
7
  import { decisionsWeekly } from './decisions.js';
6
8
  import { prDesign } from './design.js';
@@ -24,7 +26,7 @@ import { onboard, onboardArgs } from './onboard.js';
24
26
  import { ownerStep, ownerStepArgs } from './owner-step.js';
25
27
  import { sessionStart } from './session-start.js';
26
28
  import { upgrade } from './upgrade.js';
27
- import { prMerged, prePush, prWorkRules, propose } from './work.js';
29
+ import { prMerged, prStarted, prePush, prWorkRules, propose } from './work.js';
28
30
  import { CLI } from './names.js';
29
31
  import { packageVersion } from './version.js';
30
32
  export { packageVersion, versionOf } from './version.js';
@@ -43,6 +45,9 @@ Commands:
43
45
  label <owner/repo> <number> <add|remove> <approved|do-not-merge>;
44
46
  required-checks <owner/repo> <ruleset id or name> [--check <name>]…
45
47
  cloud-setup Print an optional Setup snippet that makes Claude cloud sessions start faster
48
+ cloud-key [agent] [--yes]
49
+ In your own terminal: a new signing key for the agent's Claude cloud sessions, registered
50
+ as the agent, and NIYAM_SIGNING_KEY=… on the clipboard for the cloud environment's variables
46
51
  env [-- <command> [args...]]
47
52
  For agents run from any tool: the GitHub lock, then the agent identity where this Mac
48
53
  has it, as shell lines for eval "$(niyam env)", or with -- the command run under them
@@ -53,6 +58,7 @@ Commands:
53
58
  pr-identity Run by the shared workflow: agent commits Verified and pushed by the agent
54
59
  pr-work-rules Run by the shared workflow: an agent pull request builds one slice it may build
55
60
  pr-merged Run by the shared workflow: a merged pull request closes the slice and States it names
61
+ pr-started Run by the shared workflow: an opened pull request moves its slice to In Progress on the board
56
62
  pr-design Run by the shared workflow: each state of the slice links a frame from the design library
57
63
  decisions-weekly Run by the shared workflow weekly: decision checks, undo issues, expiring labels
58
64
  needs-owner Run by the shared workflow: an ask labels its issue needs-owner; the owner's answer takes it off
@@ -100,6 +106,10 @@ Commands:
100
106
  work-item-number [--issue <N>] [--apply]
101
107
  Run by a client's workflow on issue events: a Work item whose number something else
102
108
  holds is renumbered, with a comment; --apply writes
109
+ board-audit [owner/repo] [--project <title>]
110
+ Read only: the open issues not on the work board, items whose Status disagrees with
111
+ their issue, and whether the auto-add workflows are on; exit 3 when something is to fix.
112
+ Needs GH_TOKEN; cannot run in a Claude cloud session, whose proxy refuses Projects
103
113
  help Show this text
104
114
  version Print the installed version
105
115
 
@@ -141,17 +151,17 @@ export function proposeArgs(args) {
141
151
  /** Runs one command and returns its exit code: 0 done, 1 failed, 2 bad usage. */
142
152
  export async function run(args, io, sys) {
143
153
  const [command, ...rest] = args;
144
- const allowed = command === 'onboard' || command === 'machine' || command === 'review-thread' || command === 'as-agent' || command === 'env' || command === 'propose' || command === 'owner-step' || command === 'handoff' || command === 'brief' || command === 'cubic-dismiss' || command === 'pr-autocreate' || command === 'keep-going' || command === 'doc-number' || command === 'renumber-doc' || command === 'work-item-number' ? Infinity : command === 'pre-push' || command === 'pr-signals' ? 2 : command === 'doctor' ? 1 : 0;
154
+ const allowed = command === 'onboard' || command === 'machine' || command === 'cloud-key' || command === 'review-thread' || command === 'as-agent' || command === 'env' || command === 'propose' || command === 'owner-step' || command === 'handoff' || command === 'brief' || command === 'cubic-dismiss' || command === 'pr-autocreate' || command === 'keep-going' || command === 'doc-number' || command === 'renumber-doc' || command === 'work-item-number' || command === 'board-audit' ? Infinity : command === 'pre-push' || command === 'pr-signals' ? 2 : command === 'doctor' ? 1 : 0;
145
155
  const extra = rest[allowed];
146
156
  if (extra !== undefined) {
147
157
  io.err(`niyam: unexpected argument "${extra}"`);
148
158
  io.err(USAGE);
149
159
  return 2;
150
160
  }
151
- if (command === 'onboard' || command === 'machine' || command === 'review-thread' || command === 'as-agent' || command === 'env' || command === 'propose' || command === 'owner-step' || command === 'pr-signals' || command === 'handoff' || command === 'brief' || command === 'cubic-dismiss' || command === 'doc-number' || command === 'renumber-doc' || command === 'work-item-number') {
161
+ if (command === 'onboard' || command === 'machine' || command === 'cloud-key' || command === 'review-thread' || command === 'as-agent' || command === 'env' || command === 'propose' || command === 'owner-step' || command === 'pr-signals' || command === 'handoff' || command === 'brief' || command === 'cubic-dismiss' || command === 'doc-number' || command === 'renumber-doc' || command === 'work-item-number' || command === 'board-audit') {
152
162
  // Their options are checked here, so a bad one is bad usage (exit 2).
153
163
  try {
154
- (command === 'doc-number' ? docNumberArgs : command === 'renumber-doc' ? renumberArgs : command === 'work-item-number' ? workItemArgs : command === 'onboard' ? onboardArgs : command === 'machine' ? machineArgs : command === 'as-agent' ? asAgentArgs : command === 'env' ? envArgs : command === 'propose' ? proposeArgs : command === 'owner-step' ? ownerStepArgs : command === 'pr-signals' ? signalArgs : command === 'handoff' ? handoffArgs : command === 'brief' ? briefArgs : command === 'cubic-dismiss' ? dismissArgs : threadArgs)(rest);
164
+ (command === 'board-audit' ? auditArgs : command === 'cloud-key' ? cloudKeyArgs : command === 'doc-number' ? docNumberArgs : command === 'renumber-doc' ? renumberArgs : command === 'work-item-number' ? workItemArgs : command === 'onboard' ? onboardArgs : command === 'machine' ? machineArgs : command === 'as-agent' ? asAgentArgs : command === 'env' ? envArgs : command === 'propose' ? proposeArgs : command === 'owner-step' ? ownerStepArgs : command === 'pr-signals' ? signalArgs : command === 'handoff' ? handoffArgs : command === 'brief' ? briefArgs : command === 'cubic-dismiss' ? dismissArgs : threadArgs)(rest);
155
165
  }
156
166
  catch (error) {
157
167
  io.err(`niyam: ${error instanceof Error ? error.message : String(error)}`);
@@ -227,11 +237,13 @@ export async function run(args, io, sys) {
227
237
  }
228
238
  }
229
239
  case 'machine':
240
+ case 'cloud-key':
230
241
  case 'doctor':
231
242
  case 'onboard':
232
243
  case 'pr-identity':
233
244
  case 'pr-work-rules':
234
245
  case 'pr-merged':
246
+ case 'pr-started':
235
247
  case 'pr-design':
236
248
  case 'decisions-weekly':
237
249
  case 'needs-owner':
@@ -249,7 +261,10 @@ export async function run(args, io, sys) {
249
261
  case 'doc-number':
250
262
  case 'renumber-doc':
251
263
  case 'work-item-number':
264
+ case 'board-audit':
252
265
  try {
266
+ if (command === 'board-audit')
267
+ return await boardAudit(await sys(), io, rest);
253
268
  if (command === 'doc-number')
254
269
  return docNumber(await sys(), io, rest);
255
270
  if (command === 'renumber-doc')
@@ -290,6 +305,8 @@ export async function run(args, io, sys) {
290
305
  return await prWorkRules(await sys(), io);
291
306
  if (command === 'pr-merged')
292
307
  return await prMerged(await sys(), io);
308
+ if (command === 'pr-started')
309
+ return await prStarted(await sys(), io);
293
310
  if (command === 'pre-push') {
294
311
  const real = await sys();
295
312
  return await prePush(real, io, real.readStdin(), rest[1] ?? '');
@@ -298,6 +315,8 @@ export async function run(args, io, sys) {
298
315
  return await onboard(await sys(), io, rest);
299
316
  if (command === 'machine')
300
317
  return await machine(await sys(), io, rest);
318
+ if (command === 'cloud-key')
319
+ return await cloudKey(await sys(), io, rest);
301
320
  return await doctor(await sys(), io, rest[0]);
302
321
  }
303
322
  catch (error) {
package/dist/secrets.js CHANGED
@@ -1,4 +1,25 @@
1
1
  import { API } from './agent.js';
2
+ /**
3
+ * The names of the Actions secrets `slug`'s workflows can read, its own and
4
+ * its organization's shared with it, as the account `token` sees them; never
5
+ * a value, which GitHub does not list. Undefined when GitHub will not list
6
+ * either, so a caller can tell "not set" from "cannot tell".
7
+ */
8
+ export async function secretNames(sys, slug, token) {
9
+ const names = [];
10
+ for (const kind of ['secrets', 'organization-secrets']) {
11
+ for (let page = 1;; page++) {
12
+ const listed = await sys.http(`${API}/repos/${slug}/actions/${kind}?per_page=100&page=${page}`, { token });
13
+ const secrets = listed.json?.secrets;
14
+ if (listed.status !== 200 || !Array.isArray(secrets))
15
+ return undefined;
16
+ names.push(...secrets.flatMap((secret) => (typeof secret?.name === 'string' ? [secret.name] : [])));
17
+ if (secrets.length < 100)
18
+ break;
19
+ }
20
+ }
21
+ return names;
22
+ }
2
23
  /**
3
24
  * Sets the Actions secret `name` of `slug` to `value`, as the account `token`
4
25
  * is: GitHub takes a secret only sealed with the repository's Actions public
@@ -1,6 +1,6 @@
1
- import { BASE_ENV, agentHere, anyLogin, either, loadSettings, lockScript, sameLogin, pathsFor, sessionNames, sessionRecord, sessionFileIs, } from './agent.js';
1
+ import { BASE_ENV, agentHere, exportLines, anyLogin, either, loadSettings, lockScript, sameLogin, pathsFor, sessionNames, sessionRecord, sessionFileIs, } from './agent.js';
2
2
  import { AGENT_VAR } from './names.js';
3
- import { cloudLogin, cloudToken, ranFromSetup, repoReleases } from './cloud.js';
3
+ import { SIGNING_KEY_VAR, cloudLogin, cloudSigning, cloudToken, ranFromSetup, repoReleases } from './cloud.js';
4
4
  import { CLOUD_SETUP_PATH } from './onboard-pull.js';
5
5
  import { PRE_PUSH_HOOK, prePushHook } from './onboard.js';
6
6
  import { packageVersion } from './version.js';
@@ -117,7 +117,9 @@ function recordFor(sys) {
117
117
  * identity is the account claude.ai's GitHub connection uses, which GitHub
118
118
  * names through the session's proxy. When that is the agent, the lock the
119
119
  * settings' `env` gave the session is lifted, so gh and git reach GitHub
120
- * through the proxy, and the session is marked as the agent's for the guard
120
+ * through the proxy, the agent becomes the author, committer and signer of
121
+ * its commits when the environment holds its cloud signing key
122
+ * (`cloudCommits`), and the session is marked as the agent's for the guard
121
123
  * and the pre-push hook, which it writes, since a cloud clone has none of
122
124
  * the owner's. Otherwise GitHub stays locked out and the session is told to
123
125
  * stop: it would act as someone else.
@@ -171,7 +173,32 @@ async function cloudStart(sys) {
171
173
  : hook.state === 'outside'
172
174
  ? ` Its pre-push hook ${hook.path} is outside the repository and was not checked, so only the pull request's checks may hold the work rules.`
173
175
  : '';
174
- return { line: `niyam: this cloud session works as ${asked.login} on GitHub.${unchecked}`, agent: asked.login };
176
+ const signed = await cloudCommits(sys, root, envFile, asked);
177
+ return { line: `niyam: this cloud session works as ${asked.login} on GitHub.${unchecked}${signed}`, agent: asked.login };
178
+ }
179
+ /**
180
+ * Makes the agent the author, committer and signer of a cloud session's
181
+ * commits, as a local session's file does, over the cloud image's own
182
+ * identity, Claude's: `cloudSigning`'s variables, appended to CLAUDE_ENV_FILE
183
+ * after the lock is lifted, which reaches every command Claude Code runs and
184
+ * leaves the clone's git config alone. The key's variable is unset there, so
185
+ * commands do not carry it in their environment. A warning only, said after
186
+ * the line: when any of it fails, the session works on as the agent and its
187
+ * commits keep the image's identity, which PR identity passes.
188
+ */
189
+ async function cloudCommits(sys, root, envFile, asked) {
190
+ const keeps = (why) => ` Its commits keep the cloud image's identity, Claude's: ${why}.`;
191
+ const signing = await cloudSigning(sys, root, asked.login, asked.id);
192
+ if ('problem' in signing)
193
+ return keeps(signing.problem);
194
+ try {
195
+ sys.append(envFile, `unset ${SIGNING_KEY_VAR}\n${exportLines(signing.vars).join('\n')}\n`);
196
+ }
197
+ catch (error) {
198
+ // fail-open: nothing of the signing reached the env file, so the session keeps the image's identity, and says why.
199
+ return keeps(`writing ${asked.login}'s signing to CLAUDE_ENV_FILE failed (${message(error)})`);
200
+ }
201
+ return ` Its commits are ${asked.login}'s, signed with ${SIGNING_KEY_VAR}.`;
175
202
  }
176
203
  function start(sys) {
177
204
  let local;
package/dist/work.js CHANGED
@@ -527,11 +527,16 @@ export async function prePush(sys, io, refLines, url) {
527
527
  await moveBoard(sys, io, token, slug, slice);
528
528
  return report(io, 'pre-push', problems);
529
529
  }
530
+ /** How a Claude cloud session's GitHub proxy refuses a path outside `repos/{owner}/{repo}/…`, such as an org's Projects. */
531
+ const CLOUD_PROXY_REFUSAL = /sessions are bound to their configured repositories/i;
530
532
  /**
531
533
  * Moves the board on for slice `slice`, which a push is starting to build,
532
- * with the board feature on, through GitHub's REST API, which a Claude
533
- * cloud session's proxy lets through; a board it cannot read, or a move
534
- * GitHub refuses, is said and does not stop the push.
534
+ * with the board feature on, through GitHub's REST API; a board it cannot
535
+ * read, or a move GitHub refuses, is said and does not stop the push. A
536
+ * Claude cloud session's proxy lets through only `repos/{owner}/{repo}/…`,
537
+ * never an org's or a user's Projects, so there the push only says that the
538
+ * shared workflow's Slice started job moves the slice when its pull request
539
+ * opens.
535
540
  */
536
541
  async function moveBoard(sys, io, token, slug, slice) {
537
542
  try {
@@ -539,7 +544,10 @@ async function moveBoard(sys, io, token, slug, slice) {
539
544
  io.err(line);
540
545
  }
541
546
  catch (error) {
542
- io.err(`! board: could not read where #${slice} and its work item are on the board, so nothing moved (${error.message}); the push goes on`);
547
+ const message = error.message;
548
+ io.err(CLOUD_PROXY_REFUSAL.test(message)
549
+ ? `- board: this cloud session cannot reach the board; niyam's workflow moves #${slice} when its pull request opens`
550
+ : `! board: could not read where #${slice} and its work item are on the board, so nothing moved (${message}); the push goes on`);
543
551
  }
544
552
  }
545
553
  /** Throws for a write to an issue that GitHub refused, saying how to fix a workflow that grants no issues: write. */
@@ -651,6 +659,72 @@ export async function prMerged(sys, io) {
651
659
  }
652
660
  return 0;
653
661
  }
662
+ /**
663
+ * Moves the board on for the slice a pull request names as it opens or
664
+ * reopens, run by the shared workflow's Slice started job: the move a push
665
+ * makes from the desktop, which a Claude cloud session's push cannot, since
666
+ * its proxy never reaches an org's Projects. It moves nothing unless the
667
+ * pull request names one slice, the board and work-rules features are on,
668
+ * and the slice passes the work rules, which it reads with the workflow's
669
+ * GH_TOKEN. A workflow's GITHUB_TOKEN cannot write a Project, so the board
670
+ * moves with NIYAM_BOARD_TOKEN, minted from the board GitHub App. Without
671
+ * that token, or when GitHub refuses, it says so and passes: the board never
672
+ * fails a pull request.
673
+ */
674
+ export async function prStarted(sys, io) {
675
+ const { GITHUB_EVENT_PATH: eventPath, GITHUB_REPOSITORY: slug, GH_TOKEN: token, NIYAM_BOARD_TOKEN: board } = sys.env;
676
+ if (!eventPath || !slug || !token) {
677
+ throw new Error('pr-started runs in GitHub Actions: GITHUB_EVENT_PATH, GITHUB_REPOSITORY and GH_TOKEN must be set');
678
+ }
679
+ const event = JSON.parse(sys.read(eventPath));
680
+ const pull = event.pull_request;
681
+ if (!pull) {
682
+ io.out('pr-started: not a pull request; nothing to move');
683
+ return 0;
684
+ }
685
+ const notAdopted = notAdoptedLine(sys, sys.cwd, 'pr-started');
686
+ if (notAdopted) {
687
+ io.out(notAdopted);
688
+ return 0;
689
+ }
690
+ for (const feature of ['work-rules', 'board']) {
691
+ if (!isOn(sys, sys.cwd, feature)) {
692
+ io.out(offLine('pr-started', feature));
693
+ return 0;
694
+ }
695
+ }
696
+ if (await isPersonal(sys, slug, token)) {
697
+ io.out(offLine('pr-started', 'work-rules', PERSONAL_REPO));
698
+ return 0;
699
+ }
700
+ const slices = slicesNamed(pull.body ?? '');
701
+ if (slices.length !== 1) {
702
+ io.out(`pr-started: #${pull.number} names ${slices.length === 0 ? 'no slice' : `${slices.length} slices`}; nothing moves on the board`);
703
+ return 0;
704
+ }
705
+ const [slice] = slices;
706
+ if (!board) {
707
+ io.out(`pr-started: no board app token here (the NIYAM_BOARD_APP_ID and NIYAM_BOARD_APP_KEY secrets are not passed, or GitHub would not make the token), so #${slice} moves on the board only from a desktop push`);
708
+ return 0;
709
+ }
710
+ try {
711
+ const problems = await sliceProblems(sys, token, slug, slice, loadSettings(sys, sys.cwd), { pull: pull.number, states: statesNamed(pull.body ?? '') });
712
+ if (problems.length > 0) {
713
+ io.out(`pr-started: #${slice} may not be built yet (Work rules says why), so nothing moves on the board`);
714
+ return 0;
715
+ }
716
+ const moved = await boardStarted(sys, board, slug, slice);
717
+ for (const line of moved)
718
+ io.out(line);
719
+ if (moved.length === 0)
720
+ io.out(`pr-started: #${slice} and its work item are where they belong on the board already`);
721
+ }
722
+ catch (error) {
723
+ // fail-open: the board never fails a pull request; Work rules judges the slice, and the line says what GitHub refused.
724
+ io.out(`! board: nothing moved for #${slice} (${error.message}); the pull request's checks go on`);
725
+ }
726
+ return 0;
727
+ }
654
728
  /** The newest of `comments`, which is not empty: GitHub lists comments oldest first. */
655
729
  function newest(comments) {
656
730
  return comments[comments.length - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veda-hq/niyam",
3
- "version": "0.6.22",
3
+ "version": "0.6.23",
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": {