@yasaswy.nagavolu/agents 0.26.0 → 0.26.1

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
@@ -82,6 +82,12 @@ agents-cli install
82
82
  `.gitlab-ci.yml`. Needs `GITLAB_RUNNER_PAT` (set it with `agents-cli
83
83
  secrets`). Add `--json` for a machine-readable result that never contains a
84
84
  token. Exit codes: 0 ok, 1 a step failed, 2 usage error.
85
+ - `agents-cli doctor [--fix] [--scan-root <dir>] [--json]` — report orphaned, missing and drifted
86
+ files under the install target, plus project hooks in the repo's `.claude/settings.json` and
87
+ `settings.local.json` whose script file is missing or that are bare `python <repo>/.claude/hooks/x.py`
88
+ commands (they exit 2 and block a PreToolUse call when the file goes missing). `--fix` rewrites the
89
+ bare ones to `sh ~/.claude/hooks/project_hook.sh .claude/hooks/x.py [args]` (fail-open launcher);
90
+ `--scan-root <dir>` checks every git repo directly under `<dir>` instead of the cwd repo.
85
91
  - `agents-cli --help` — show usage
86
92
 
87
93
  ### The interactive menu
package/bin/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const path = require('node:path');
5
+ const fs = require('node:fs');
5
6
  const { readFileSync } = require('node:fs');
6
7
 
7
8
  const pkg = JSON.parse(
@@ -32,6 +33,7 @@ const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMiss
32
33
  const { envPath, readSecrets, removeSecret } = require('../lib/secretsStore');
33
34
  const { runSelfProfilePostInstall } = require('../lib/selfProfile');
34
35
  const { checkHealth, DoctorError } = require('../lib/doctor');
36
+ const projectHooks = require('../lib/projectHooks');
35
37
  const { checkModVersions } = require('../lib/claudeVersion');
36
38
 
37
39
  const PACKAGE_ROOT = path.join(__dirname, '..');
@@ -63,7 +65,8 @@ Usage:
63
65
  agents-cli secrets Prompt for any missing secrets across all installed bundles
64
66
  agents-cli secrets --bundle <key> Prompt for missing secrets for one bundle
65
67
  agents-cli secrets --list Show which secrets are set/missing (names only — never values)
66
- agents-cli doctor Report orphaned/missing/drifted files under the install target
68
+ agents-cli doctor [--fix] [--scan-root <dir>] Report orphaned/missing/drifted files under the install target
69
+ and project hooks that would brick a session if their file went missing
67
70
  agents-cli runner <sub> [flags] Install and manage a self-hosted GitLab CI runner (see "Flags for runner")
68
71
  agents-cli --help Show this help
69
72
 
@@ -151,6 +154,15 @@ Flags for runner:
151
154
  Flags for doctor:
152
155
  --target-dir <path> Install target base, default ~/.claude (use for testing)
153
156
  --json Print a machine-readable report instead of prose
157
+ --scan-root <dir> Check the project hooks of every git repo directly under <dir> (default: the repo of the cwd)
158
+ --fix Rewrite bare "python <repo>/.claude/hooks/x.py" project hook commands into the fail-open
159
+ launcher form "sh ~/.claude/hooks/project_hook.sh .claude/hooks/x.py" (needs the launcher
160
+ installed under the target; edits only settings.json / settings.local.json hook commands)
161
+
162
+ doctor also checks the project hooks in .claude/settings.json and settings.local.json of the repo: a hook command
163
+ whose script file is missing, and a bare (non-launcher) project hook command, which exits 2 if its file goes missing
164
+ and so blocks every tool call when it is a PreToolUse hook. A launcher-form hook with a missing file fails open but is still
165
+ reported. Without --fix nothing is modified.
154
166
 
155
167
  doctor reports, without changing anything: orphans (files/directories sitting inside
156
168
  a path this CLI manages that the ledger does not claim — e.g. a stale file left behind
@@ -1056,7 +1068,7 @@ async function runUpdate(argv) {
1056
1068
  }
1057
1069
 
1058
1070
  function parseDoctorArgs(argv) {
1059
- const args = { targetDir: null, json: false };
1071
+ const args = { targetDir: null, json: false, fix: false, scanRoot: null };
1060
1072
  for (let i = 0; i < argv.length; i += 1) {
1061
1073
  const arg = argv[i];
1062
1074
  if (arg === '--target-dir') {
@@ -1064,6 +1076,12 @@ function parseDoctorArgs(argv) {
1064
1076
  i += 1;
1065
1077
  } else if (arg === '--json') {
1066
1078
  args.json = true;
1079
+ } else if (arg === '--fix') {
1080
+ args.fix = true;
1081
+ } else if (arg === '--scan-root') {
1082
+ args.scanRoot = argv[i + 1];
1083
+ if (!args.scanRoot) throw new DoctorError('--scan-root needs a directory');
1084
+ i += 1;
1067
1085
  } else {
1068
1086
  throw new DoctorError(`Unknown doctor flag: ${arg}`);
1069
1087
  }
@@ -1075,6 +1093,16 @@ function describeOrphan(o) {
1075
1093
  return o.type === 'dir' ? `${o.relTarget}/ (directory)` : o.relTarget;
1076
1094
  }
1077
1095
 
1096
+ function describeHookFinding(f) {
1097
+ const where = `${f.file} [${f.event || '-'}]`;
1098
+ if (f.kind === 'unparseable') return `${f.file}: not valid JSON, hooks not checked`;
1099
+ if (f.kind === 'bare-project-hook') {
1100
+ return `${where} bare project hook, exits 2 (blocks a PreToolUse call) if its file goes missing${f.fixable ? ' (fixable)' : ' (not auto-fixable)'}: ${f.command}`;
1101
+ }
1102
+ if (f.kind === 'missing-launcher') return `${where} launcher not found: ${f.script}`;
1103
+ return `${where} script missing${f.failsOpen ? ' (launcher: fails open, hook does not run)' : ' (FAILS CLOSED: blocks tool calls)'}: ${f.script}`;
1104
+ }
1105
+
1078
1106
  function runDoctor(argv) {
1079
1107
  let args;
1080
1108
  try {
@@ -1090,11 +1118,47 @@ function runDoctor(argv) {
1090
1118
  targetBase: args.targetDir,
1091
1119
  });
1092
1120
 
1121
+ const targetBase = args.targetDir || defaultTargetBase();
1122
+ const hookScope = { cwd: process.cwd(), scanRoot: args.scanRoot ? path.resolve(args.scanRoot) : null };
1123
+ let hooks = projectHooks.checkProjectHooks(hookScope);
1124
+ const fixed = [];
1125
+ if (args.fix && hooks.findings.some((f) => f.kind === 'bare-project-hook' && f.fixable)) {
1126
+ if (!fs.existsSync(path.join(targetBase, 'hooks', projectHooks.LAUNCHER_NAME))) {
1127
+ console.error(
1128
+ `Cannot fix: ${path.join(targetBase, 'hooks', projectHooks.LAUNCHER_NAME)} is not installed. ` +
1129
+ 'Run "agents-cli update" (or install the harness-hygiene bundle) first.'
1130
+ );
1131
+ return 1;
1132
+ }
1133
+ const launcherCommand = projectHooks.launcherCommandFor(targetBase);
1134
+ for (const repo of hooks.repos) fixed.push(...projectHooks.fixRepo(repo, { launcherCommand }));
1135
+ hooks = projectHooks.checkProjectHooks(hookScope);
1136
+ }
1137
+ result.projectHooks = { repos: hooks.repos, findings: hooks.findings, fixed };
1138
+ result.healthy = result.healthy && hooks.findings.length === 0;
1139
+
1093
1140
  if (args.json) {
1094
1141
  console.log(JSON.stringify(result, null, 2));
1095
1142
  return result.healthy ? 0 : 1;
1096
1143
  }
1097
1144
 
1145
+ const printProjectHooks = () => {
1146
+ if (fixed.length > 0) {
1147
+ console.log(`
1148
+ Rewrote ${fixed.length} bare project hook command(s) to the fail-open launcher:`);
1149
+ for (const c of fixed) console.log(` ${c.file}
1150
+ - ${c.from}
1151
+ + ${c.to}`);
1152
+ }
1153
+ if (hooks.findings.length === 0) return;
1154
+ console.log(`
1155
+ Project hooks (${hooks.findings.length} finding(s), ${hooks.repos.length} repo(s) checked):`);
1156
+ for (const f of hooks.findings) console.log(` ${describeHookFinding(f)}`);
1157
+ if (hooks.findings.some((f) => f.kind === 'bare-project-hook' && f.fixable) && !args.fix) {
1158
+ console.log(' Run "agents-cli doctor --fix" to rewrite the fixable ones.');
1159
+ }
1160
+ };
1161
+
1098
1162
  const printModVersions = () => {
1099
1163
  if (result.modVersions.length === 0) return;
1100
1164
  console.log('\nClaude Code version vs. installed mods:');
@@ -1121,6 +1185,7 @@ function runDoctor(argv) {
1121
1185
  for (const d of result.drifted) console.log(` ${d.relTarget} (bundle: ${d.bundle})`);
1122
1186
  }
1123
1187
  printModVersions();
1188
+ printProjectHooks();
1124
1189
  return 1;
1125
1190
  } catch (err) {
1126
1191
  if (err instanceof DoctorError || err instanceof ManifestError || err instanceof LedgerError) {