ai-agentmanager 1.37.0 → 1.39.0

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/src/rules.js CHANGED
@@ -2,12 +2,19 @@
2
2
  // ("npm test", three times), the inbox offers to always allow it there. Allowed rules go to every
3
3
  // agent in that repo at launch (Claude Code's --allowedTools) and answer its live prompts, so the
4
4
  // same question isn't asked again. Kept in ~/.agentmanager/rules.json, per repo (the repo-memory key).
5
+ // A rule allowed in two or more repos is offered for every repo ("*"), and a few read-only
6
+ // commands never ask anywhere (config.json "rules": { "readOnly": false } turns that off).
5
7
  import { EventEmitter } from 'node:events';
6
8
  import fs from 'node:fs';
7
9
  import path from 'node:path';
8
10
  import { paths } from './config.js';
9
11
 
10
12
  export const SUGGEST_AFTER = 3;
13
+ export const EVERY_REPO = '*';
14
+ // Repos that allow the same rule before it is offered for every repo.
15
+ const SUGGEST_EVERYWHERE_AFTER = 2;
16
+ // Commands that only look: allowed in every repo from the start.
17
+ export const READ_ONLY = ['ls', 'pwd', 'wc', 'git status', 'git diff', 'git log', 'git show', 'git blame', 'git rev-parse'].map((c) => `Bash(${c}:*)`);
11
18
  // Commands whose first words name a subcommand: "npm test" is a rule, "npm" alone would allow anything npm does.
12
19
  const SUBCOMMANDS = new Set(['npm', 'pnpm', 'yarn', 'bun', 'npx', 'node', 'deno', 'git', 'gh', 'cargo', 'go', 'make', 'python', 'python3', 'uv', 'pip', 'poetry', 'pytest', 'mvn', 'gradle', './gradlew', 'dotnet', 'swift', 'xcodebuild', 'bundle', 'rake', 'rails', 'mix', 'composer', 'php', 'docker', 'kubectl', 'terraform', 'just', 'task']);
13
20
  // Never offered as a standing rule, however often approved: they delete, escalate, publish or reach out.
@@ -69,16 +76,18 @@ export function describeTool(tool) {
69
76
  }
70
77
 
71
78
  export class Rules extends EventEmitter {
72
- constructor({ file = path.join(paths.home, 'rules.json'), suggestAfter = SUGGEST_AFTER } = {}) {
79
+ constructor({ file = path.join(paths.home, 'rules.json'), suggestAfter = SUGGEST_AFTER, readOnly = true } = {}) {
73
80
  super();
74
81
  this.file = file;
75
82
  this.suggestAfter = suggestAfter;
83
+ this.readOnly = readOnly !== false;
76
84
  try {
77
85
  this.data = JSON.parse(fs.readFileSync(file, 'utf8'));
78
86
  } catch {
79
87
  this.data = {};
80
88
  }
81
89
  this.data.repos ??= {};
90
+ this.data.everywhere ??= { allow: [], dismissed: [] };
82
91
  }
83
92
 
84
93
  save() {
@@ -91,9 +100,16 @@ export class Rules extends EventEmitter {
91
100
  return (this.data.repos[key] ??= { allow: [], dismissed: [], seen: {} });
92
101
  }
93
102
 
94
- /** The rules allowed in a repo, as Claude Code allow rules. */
103
+ /** Where a repo key's rules live: a repo, or every repo. */
104
+ scope(key) {
105
+ return key === EVERY_REPO ? this.data.everywhere : this.data.repos[key];
106
+ }
107
+
108
+ /** The rules allowed in a repo (its own, every repo's, the read-only ones), as Claude Code allow rules. */
95
109
  allowed(key) {
96
- return (this.data.repos[key]?.allow ?? []).map((r) => r.rule);
110
+ const own = (this.data.repos[key]?.allow ?? []).map((r) => r.rule);
111
+ const all = this.data.everywhere.allow.map((r) => r.rule);
112
+ return [...new Set([...own, ...all, ...(this.readOnly ? READ_ONLY : [])])];
97
113
  }
98
114
 
99
115
  /** The allowed rule that covers this call in this repo, if any. */
@@ -103,7 +119,7 @@ export class Rules extends EventEmitter {
103
119
 
104
120
  /** An allowed rule answered a prompt by itself: count it, so the list shows what it saves. */
105
121
  used(key, rule) {
106
- const a = this.data.repos[key]?.allow.find((x) => x.rule === rule);
122
+ const a = this.data.repos[key]?.allow.find((x) => x.rule === rule) ?? this.data.everywhere.allow.find((x) => x.rule === rule);
107
123
  if (!a) return;
108
124
  a.uses = (a.uses ?? 0) + 1;
109
125
  a.lastUsedAt = new Date().toISOString();
@@ -114,8 +130,8 @@ export class Rules extends EventEmitter {
114
130
  approved(key, tool) {
115
131
  const r = ruleFor(tool);
116
132
  if (!r) return null;
133
+ if (this.allowed(key).includes(r.rule)) return null;
117
134
  const repo = this.repo(key);
118
- if (repo.allow.some((x) => x.rule === r.rule)) return null;
119
135
  const seen = (repo.seen[r.rule] ??= { label: r.label, n: 0 });
120
136
  seen.n++;
121
137
  seen.at = new Date().toISOString();
@@ -124,6 +140,20 @@ export class Rules extends EventEmitter {
124
140
  }
125
141
 
126
142
  accept(key, rule) {
143
+ if (key === EVERY_REPO) {
144
+ const e = this.data.everywhere;
145
+ const from = Object.values(this.data.repos).flatMap((r) => r.allow).find((x) => x.rule === rule);
146
+ if (!from && !e.allow.some((x) => x.rule === rule)) throw Object.assign(new Error('No such suggestion'), { status: 404 });
147
+ if (!e.allow.some((x) => x.rule === rule)) e.allow.push({ rule, label: from.label, at: new Date().toISOString(), uses: 0 });
148
+ // One rule for every repo replaces the repos' own copies (their uses carry over).
149
+ for (const r of Object.values(this.data.repos)) {
150
+ const own = r.allow.find((x) => x.rule === rule);
151
+ if (own) e.allow.find((x) => x.rule === rule).uses += own.uses ?? 0;
152
+ r.allow = r.allow.filter((x) => x.rule !== rule);
153
+ }
154
+ this.save();
155
+ return;
156
+ }
127
157
  const repo = this.data.repos[key];
128
158
  const seen = repo?.seen[rule];
129
159
  if (!seen && !repo?.allow.some((x) => x.rule === rule)) throw Object.assign(new Error('No such suggestion'), { status: 404 });
@@ -134,6 +164,12 @@ export class Rules extends EventEmitter {
134
164
 
135
165
  /** "Not now": stop suggesting it (it can still be allowed later from the list). */
136
166
  dismiss(key, rule) {
167
+ if (key === EVERY_REPO) {
168
+ if (!this.view().suggestions.some((s) => s.repo === EVERY_REPO && s.rule === rule)) throw Object.assign(new Error('No such suggestion'), { status: 404 });
169
+ this.data.everywhere.dismissed.push(rule);
170
+ this.save();
171
+ return;
172
+ }
137
173
  const repo = this.data.repos[key];
138
174
  if (!repo?.seen[rule]) throw Object.assign(new Error('No such suggestion'), { status: 404 });
139
175
  if (!repo.dismissed.includes(rule)) repo.dismissed.push(rule);
@@ -141,7 +177,7 @@ export class Rules extends EventEmitter {
141
177
  }
142
178
 
143
179
  remove(key, rule) {
144
- const repo = this.data.repos[key];
180
+ const repo = this.scope(key);
145
181
  if (!repo?.allow.some((x) => x.rule === rule)) throw Object.assign(new Error('No such rule'), { status: 404 });
146
182
  repo.allow = repo.allow.filter((x) => x.rule !== rule);
147
183
  repo.dismissed = repo.dismissed.filter((x) => x !== rule);
@@ -156,6 +192,15 @@ export class Rules extends EventEmitter {
156
192
  for (const a of r.allow) allowed.push({ repo, ...a });
157
193
  for (const [rule, s] of Object.entries(r.seen)) if (s.n >= this.suggestAfter && !r.dismissed.includes(rule)) suggestions.push({ repo, rule, label: s.label, n: s.n, at: s.at });
158
194
  }
159
- return { allowed, suggestions, suggestAfter: this.suggestAfter };
195
+ // Allowed in several repos: offer it for every repo.
196
+ const repos = new Map();
197
+ for (const a of allowed) repos.set(a.rule, [...(repos.get(a.rule) ?? []), a]);
198
+ for (const [rule, list] of repos) {
199
+ if (list.length >= SUGGEST_EVERYWHERE_AFTER && !this.data.everywhere.dismissed.includes(rule)) {
200
+ suggestions.push({ repo: EVERY_REPO, rule, label: list[0].label, n: list.length, everywhere: true, at: list.map((x) => x.at).sort().at(-1) });
201
+ }
202
+ }
203
+ for (const a of this.data.everywhere.allow) allowed.push({ repo: EVERY_REPO, ...a });
204
+ return { allowed, suggestions, suggestAfter: this.suggestAfter, readOnly: this.readOnly ? READ_ONLY.map((r) => r.slice(5, -3)) : [] };
160
205
  }
161
206
  }
package/src/server.js CHANGED
@@ -699,6 +699,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
699
699
  return { url: r.url ?? null, title };
700
700
  }));
701
701
  api.post('/agents/:id/fork', wrap((req) => manager.fork(req.params.id, req.body ?? {})));
702
+ api.post('/agents/:id/continue-on', wrap((req) => manager.continueOn(req.params.id, { engine: req.body?.engine })));
702
703
 
703
704
  api.get('/races', wrap(() => races.list()));
704
705
  // Attachments: copied once to a shared folder and listed in the request every attempt gets.