ai-agentmanager 1.44.0 → 1.46.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/brief.js CHANGED
@@ -719,7 +719,74 @@ export const DEMO_FILE = 'DEMO.html';
719
719
  export const demoPath = (agentId) => path.join(briefDir(agentId), DEMO_FILE);
720
720
  export const BENCH_FILE = 'BENCHMARK.md';
721
721
  export const benchPath = (agentId) => path.join(briefDir(agentId), BENCH_FILE);
722
- export const SPEC_DOCS = { intent: intentPath, spec: specPath, plan: planPath, designdoc: designPath, benchmark: benchPath, demo: demoPath };
722
+ export const DEBUG_FILE = 'DEBUG.md';
723
+ export const debugPath = (agentId) => path.join(briefDir(agentId), DEBUG_FILE);
724
+ export const SPEC_DOCS = { intent: intentPath, spec: specPath, plan: planPath, designdoc: designPath, benchmark: benchPath, demo: demoPath, debug: debugPath };
725
+
726
+ // ------------------------------------------------------------------ debug
727
+
728
+ // Debug: you say what to debug (a failure, instability at scale, slowness under load); the agent
729
+ // investigates in its own session and keeps a report at DEBUG.md with animated diagrams of the code
730
+ // path and the data flow, what it found with evidence, the likely causes and the fixes it
731
+ // recommends. It changes no code until you ask for a fix. The Debug tab shows the report as it grows.
732
+
733
+ const DEBUG_SHAPE = [
734
+ '# Debug: <short name of the problem>',
735
+ '## Summary',
736
+ 'Two or three sentences: what goes wrong, the most likely cause, and how sure you are.',
737
+ '## Symptoms',
738
+ 'What is seen and when (scale, load, timing, environment), and how to reproduce it. Only numbers that were measured or given.',
739
+ '## Code path',
740
+ 'One ```mermaid flowchart of the path the failing request, job or test takes through the real files and functions, where it breaks marked.',
741
+ '## Data flow',
742
+ 'One ```mermaid flowchart LR or sequenceDiagram of the data on that path (payloads, queues, caches, connections, stores): where it grows, waits, is dropped or goes wrong.',
743
+ '## Findings',
744
+ 'Numbered. Each with its evidence (file:line, a log line, a metric, or a command and its output) and "confirmed" (reproduced or measured) or "suspected".',
745
+ '## Root cause',
746
+ 'The causes, most likely first, each with a confidence (high, medium, low) and what would confirm or rule it out.',
747
+ '## Recommended fixes',
748
+ 'Numbered. Each: the change, where (file and function), effort (S, M, L), the risk, and how to verify it worked.',
749
+ '## Next checks',
750
+ 'What to measure or try next, and what you need from the user (logs, numbers, access).',
751
+ ].join('\n');
752
+
753
+ const DEBUG_DIAGRAMS =
754
+ 'Diagrams: valid Mermaid, at most about 15 nodes each, labels of five words or fewer (quote labels with punctuation, e.g. A["Parse (JSON)"]), no HTML in labels, real names from the code. ' +
755
+ 'Animate the path in every flowchart: give its edges ids and animate them, e.g.\n' +
756
+ ' A e1@--> B\n B e2@-->|"rows"| C\n e1@{ animate: true }\n e2@{ animate: true }\n' +
757
+ 'Mark where it breaks and what is only suspected: `classDef fault stroke:#ef4444,stroke-width:3px` and `classDef suspect stroke:#f59e0b,stroke-width:3px,stroke-dasharray:4`, then `class X fault` and `class Y suspect`. ' +
758
+ 'When timing, concurrency or load is the issue, add a "## Interleaving" section after Data flow with a sequenceDiagram of the order of events that breaks.';
759
+
760
+ /** The message that starts (or continues) a debug investigation in the agent's session. */
761
+ export function debugPrompt(file, question, { again = false } = {}) {
762
+ const q = String(question ?? '').trim();
763
+ if (again) {
764
+ return (
765
+ `Debug, continued: ${q}\n` +
766
+ `Carry on the investigation and bring the report at ${file} up to date: same sections, diagrams redrawn where the picture changed, findings re-marked confirmed or suspected. ` +
767
+ 'Still no changes to the repository code unless I ask for a fix. Answer me here in a few lines, and say what changed in the report.'
768
+ );
769
+ }
770
+ return (
771
+ `Debug this: ${q}\n` +
772
+ 'Investigate before proposing anything: read the code on the path, the logs and the tests; reproduce it if you can (run the failing test, a small load or a script), and measure instead of guessing. ' +
773
+ 'Do not change the repository code yet: instrumentation or reproduction scripts go outside the repository or are reverted when you are done. ' +
774
+ 'If you need facts only I have (the environment, the scale it fails at, logs), ask me here in a line or two, but first write what you can.\n' +
775
+ `Keep a report at ${file} (Markdown; the file is outside the repository: never copy it in or commit it). Write a first version as soon as you have the code path, and update it as you learn. Short and specific, in these sections:\n` +
776
+ `${DEBUG_SHAPE}\n${DEBUG_DIAGRAMS}\n` +
777
+ 'When the report is written, tell me in a few lines what you found and which fix you recommend first.'
778
+ );
779
+ }
780
+
781
+ /** The message that asks for the report's fixes to be made. */
782
+ export function debugFixPrompt(file, which) {
783
+ const w = String(which ?? '').trim();
784
+ return (
785
+ `Apply the fixes from your debug report at ${file}: ${w || 'the ones you recommend, the safest first'}.\n` +
786
+ 'Make each change, then verify it the way the report says (run the test, the reproduction or the load again) and compare with what you measured before. ' +
787
+ 'Then update the report: add a "## Fixes applied" section (what changed, where, and the result before and after), and re-mark the findings. If a fix does not hold up, revert it and say why.'
788
+ );
789
+ }
723
790
 
724
791
  /** INTENT.md: the request as given, and where it came from. */
725
792
  export function intentMarkdown(agent) {
package/src/cli.js CHANGED
@@ -731,6 +731,40 @@ export async function main(argv) {
731
731
  for (const x of r.failed) console.log(`${red('!')} ${bold(x.key)}: ${x.reason}`);
732
732
  });
733
733
 
734
+ program
735
+ .command('news')
736
+ .description("AI News: the frontier labs' latest releases, each summarized, with links")
737
+ .option('-r, --refresh', 'read the release notes again now (and summarize what is new), then print')
738
+ .option('-s, --search', 'with --refresh: also search the web for the top 10 labs now')
739
+ .option('--lab <lab>', 'only this lab (Anthropic, OpenAI, Google, …)')
740
+ .option('--days <n>', 'only the last n days', '7')
741
+ .option('--json', 'print JSON')
742
+ .action(async (opts) => {
743
+ await daemon();
744
+ let v = await api('GET', '/news');
745
+ if (!v.enabled) return console.log(dim('AI News is off: "news": { "enabled": true } in config.json'));
746
+ if (opts.refresh) {
747
+ v = await api('POST', '/news/refresh', opts.search ? { search: true } : {});
748
+ process.stderr.write(dim(opts.search ? 'Reading the release notes and searching the web (a few minutes)…\n' : 'Reading the release notes…\n'));
749
+ for (let i = 0; v.refreshing && i < 900; i++) {
750
+ await new Promise((r) => setTimeout(r, 2000));
751
+ v = await api('GET', '/news');
752
+ }
753
+ }
754
+ const since = new Date(Date.now() - Number(opts.days || 7) * 86_400_000).toISOString().slice(0, 10);
755
+ const items = v.items.filter((i) => i.date >= since && (!opts.lab || i.lab.toLowerCase() === String(opts.lab).toLowerCase()));
756
+ if (opts.json) return console.log(JSON.stringify({ ...v, items }, null, 2));
757
+ for (const s of v.sources.filter((x) => x.error)) console.log(yellow(`! ${s.label}: ${s.error}`));
758
+ if (!items.length) return console.log(dim(v.items.length ? 'Nothing in that range. --days 30 looks further back.' : 'No news yet. agentmgr news --refresh reads the release notes now.'));
759
+ let day = null;
760
+ for (const i of items) {
761
+ if (i.date !== day) console.log(`\n${bold((day = i.date))}`);
762
+ console.log(`${i.isNew ? green('● ') : ' '}${bold(i.lab)} ${dim(i.label)} ${i.title}`);
763
+ console.log(` ${i.summary ?? dim(i.lead ?? '')}`);
764
+ console.log(dim(` ${i.url}`));
765
+ }
766
+ });
767
+
734
768
  const actionsCmd = program.command('actions').description("Your action items from Slack and meeting notes (the assistant finds them): decide on each one");
735
769
  actionsCmd
736
770
  .command('ls', { isDefault: true })
@@ -1421,6 +1455,30 @@ export async function main(argv) {
1421
1455
  console.log(`${green('✓')} queued for ${a.name}`);
1422
1456
  });
1423
1457
 
1458
+ program
1459
+ .command('debug')
1460
+ .description("Debug with an agent: say what to debug and it investigates in its session, keeping a report with diagrams of the code path and data flow, findings and recommended fixes. With no question: print the report")
1461
+ .argument('<agent>')
1462
+ .argument('[question...]', 'what to debug, or a follow-up once there is a report')
1463
+ .option('--fix [which]', "apply the report's fixes: which ones in words (\"1 and 3\"), or the ones it recommends")
1464
+ .action(async (ref, question, opts) => {
1465
+ await daemon();
1466
+ const a = await resolveAgent(ref);
1467
+ const q = question.join(' ').trim();
1468
+ if (opts.fix) {
1469
+ await api('POST', `/agents/${a.id}/debug`, { fix: opts.fix === true ? q || true : opts.fix });
1470
+ return console.log(`${green('✓')} asked ${a.name} to apply the fixes; it verifies each and records the result in the report`);
1471
+ }
1472
+ if (q) {
1473
+ await api('POST', `/agents/${a.id}/debug`, { question: q });
1474
+ return console.log(`${green('✓')} sent to ${a.name}; it investigates in its session. The report: agentmgr debug ${ref}`);
1475
+ }
1476
+ const r = await api('GET', `/agents/${a.id}/specs/debug`);
1477
+ if (!r.markdown) return console.log(dim(`No debug report yet. Start one: agentmgr debug ${ref} "what goes wrong"`));
1478
+ console.log(r.markdown.trimEnd());
1479
+ console.log(dim(`\n(updated ${new Date(r.updatedAt).toLocaleString()})`));
1480
+ });
1481
+
1424
1482
  program
1425
1483
  .command('fork')
1426
1484
  .description("A new agent with this one's code and conversation, in its own worktree")
package/src/config.js CHANGED
@@ -72,6 +72,8 @@ const DEFAULTS = {
72
72
  // and micro benchmarks of the code it changed, before and after. Per agent: demoPage, benchmarks.
73
73
  // Each morning (weekdays), a spoken standup of the agents' news; see standup.js.
74
74
  standup: { enabled: true, at: '09:00', weekends: false, ai: true, notify: true },
75
+ // AI News: the frontier labs' latest releases, summarized; see NEWS_DEFAULTS in news.js for every field.
76
+ news: { enabled: true },
75
77
  demoPage: false,
76
78
  benchmarks: false,
77
79
  // The AI judge (stuck, idle screens, reviews); see JUDGE_DEFAULTS in judge.js for every field.
@@ -119,6 +119,13 @@ export default {
119
119
  return args;
120
120
  },
121
121
 
122
+ /** A one-shot call that may use only these of Claude Code's own tools (WebSearch, WebFetch), no MCP servers. */
123
+ webArgs: (config, { model, tools } = {}) => {
124
+ const args = ['-p', '--tools', tools.join(','), '--allowedTools', tools.join(','), '--strict-mcp-config', '--no-session-persistence', '--output-format', 'text'];
125
+ if (model) args.push('--model', model);
126
+ return args;
127
+ },
128
+
122
129
  /** Variables a nested Claude session would otherwise inherit from a parent one. */
123
130
  stripEnv: ['CLAUDECODE', 'CLAUDE_CODE_CHILD_SESSION', 'CLAUDE_CODE_ENTRYPOINT'],
124
131
  };
package/src/manager.js CHANGED
@@ -32,6 +32,9 @@ import {
32
32
  intentMarkdown,
33
33
  intentPath,
34
34
  readSpecDoc,
35
+ debugPath,
36
+ debugPrompt,
37
+ debugFixPrompt,
35
38
  specDocsInfo,
36
39
  specPath,
37
40
  specPrompt,
@@ -830,10 +833,32 @@ export class AgentManager extends EventEmitter {
830
833
  /** One of an agent's intent, spec and plan files. */
831
834
  specDoc(ref, name) {
832
835
  const agent = this.mustGet(ref);
833
- if (!['intent', 'spec', 'plan', 'designdoc', 'benchmark'].includes(name)) throw Object.assign(new Error('Unknown file (intent, spec, plan, designdoc or benchmark)'), { status: 400 });
836
+ if (!['intent', 'spec', 'plan', 'designdoc', 'benchmark', 'debug'].includes(name)) throw Object.assign(new Error('Unknown file (intent, spec, plan, designdoc, benchmark or debug)'), { status: 400 });
834
837
  return readSpecDoc(agent.id, name) ?? { name, markdown: null };
835
838
  }
836
839
 
840
+ /**
841
+ * Debug: ask the agent to investigate something in its session and keep a report (DEBUG.md) with
842
+ * diagrams of the code path and data flow, findings and recommended fixes. `question`: what to
843
+ * debug, or a follow-up once there is a report. `fix`: apply the report's fixes (which ones, in
844
+ * words; true for the ones it recommends). The message waits in the agent's queue like any other.
845
+ */
846
+ debug(ref, { question = '', fix = null } = {}) {
847
+ const agent = this.mustGet(ref);
848
+ if (!agent.workdir || agent.status === 'preparing') throw Object.assign(new Error('The agent has no folder to debug in yet'), { status: 409 });
849
+ const q = String(question ?? '').replace(/\s+/g, ' ').trim().slice(0, 2000);
850
+ const has = Boolean(readSpecDoc(agent.id, 'debug')?.markdown?.trim());
851
+ if (fix && !has) throw Object.assign(new Error('There is no debug report yet: say what to debug first'), { status: 409 });
852
+ if (!fix && q.length < 3) throw Object.assign(new Error('Say what to debug'), { status: 400 });
853
+ fs.mkdirSync(briefDir(agent.id), { recursive: true });
854
+ const file = path.join(fs.realpathSync(briefDir(agent.id)), path.basename(debugPath(agent.id)));
855
+ const which = fix === true ? '' : String(fix ?? '').replace(/\s+/g, ' ').trim().slice(0, 500);
856
+ this.tell(agent.id, fix ? debugFixPrompt(file, which) : debugPrompt(file, q, { again: has }), { source: 'debug' });
857
+ // What was asked, newest last, for the Debug tab.
858
+ const asks = [...(agent.debug?.asks ?? []), { text: fix ? `Apply fixes${which ? `: ${which}` : ''}` : q, kind: fix ? 'fix' : has ? 'follow-up' : 'debug', at: now() }].slice(-20);
859
+ return this.view(this.patch(agent.id, { debug: { asks, startedAt: agent.debug?.startedAt ?? now() } }));
860
+ }
861
+
837
862
  /** The agent's sample demo page (HTML), once it has written one. */
838
863
  demoPage(ref) {
839
864
  const agent = this.mustGet(ref);
@@ -2324,6 +2349,14 @@ export class AgentManager extends EventEmitter {
2324
2349
  // A new or revised plan waits for review again, unless it was already approved (then it's a progress update).
2325
2350
  if (file) this.patch(id, { planReview: { ...agent.planReview, ...file, status: agent.planReview.status === 'approved' ? 'approved' : 'review' } });
2326
2351
  }
2352
+ // A debug report written or updated: the page hears, and draws it.
2353
+ if (agent.debug) {
2354
+ let at = null;
2355
+ try {
2356
+ at = fs.statSync(debugPath(id)).mtime.toISOString();
2357
+ } catch {}
2358
+ if (at !== (agent.debug.reportAt ?? null)) this.patch(id, { debug: { ...this.store.get(id).debug, reportAt: at } });
2359
+ }
2327
2360
  }
2328
2361
 
2329
2362
  // -------------------------------------------------------------- plan review
@@ -2522,13 +2555,17 @@ export class AgentManager extends EventEmitter {
2522
2555
  }
2523
2556
 
2524
2557
  /** One tool-less, read-only call to an engine; resolves to its text output. */
2525
- oneShot(agent, text, { engine, model, timeoutMs = 300_000, tools, cwd = paths.home }) {
2558
+ oneShot(agent, text, { engine, model, timeoutMs = 300_000, tools, web, cwd = paths.home }) {
2526
2559
  // Some engines take the prompt as an argument instead of on stdin, and some need their extra
2527
2560
  // arguments after a subcommand (oneShotExtra: they place them). `tools`: Claude Code only, a
2528
2561
  // call that may use just these connector tools (and none of its own). `cwd`: where it runs, which
2529
- // decides the project MCP servers it loads.
2562
+ // decides the project MCP servers it loads. `web`: Claude Code only, a call that may use just
2563
+ // these of its own tools (WebSearch, WebFetch).
2564
+ if (web && !engine.webArgs) return Promise.reject(new Error(`${engine.label} can't search the web here; Claude Code can`));
2530
2565
  const extra = engine.extraArgs(this.config);
2531
- const args = tools
2566
+ const args = web
2567
+ ? [...extra, ...engine.webArgs(this.config, { model, tools: web })]
2568
+ : tools
2532
2569
  ? [...extra, ...engine.connectorArgs(this.config, { model, tools })]
2533
2570
  : engine.oneShotExtra ? engine.oneShotArgs(this.config, { model, prompt: text, extra }) : [...extra, ...engine.oneShotArgs(this.config, { model, prompt: text })];
2534
2571
  return new Promise((resolve, reject) => {