ai-agentmanager 1.48.0 → 1.50.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/CHANGELOG.md +19 -0
- package/README.md +43 -0
- package/package.json +1 -1
- package/public/app.js +39 -3
- package/public/decide.js +301 -0
- package/public/index.html +6 -0
- package/public/keys.js +3 -2
- package/public/news.js +2 -1
- package/public/plan.js +18 -2
- package/public/runbooks.js +145 -0
- package/public/side.js +113 -52
- package/public/style.css +63 -1
- package/src/advisor.js +780 -0
- package/src/backlog.js +14 -0
- package/src/brief.js +76 -1
- package/src/cli.js +133 -0
- package/src/config.js +2 -0
- package/src/decisions.js +29 -3
- package/src/jira.js +75 -0
- package/src/manager.js +37 -1
- package/src/notify.js +1 -0
- package/src/rea.js +47 -0
- package/src/runbooks.js +371 -0
- package/src/server.js +68 -1
package/src/backlog.js
CHANGED
|
@@ -170,6 +170,8 @@ export class Backlog extends EventEmitter {
|
|
|
170
170
|
if (it.agentId && this.store.get(it.agentId)) this.manager.update(it.agentId, { priority: it.priority });
|
|
171
171
|
}
|
|
172
172
|
if ('notes' in fields) it.notes = String(fields.notes ?? '');
|
|
173
|
+
// Held back until a day (YYYY-MM-DD): cut from a date at risk, picked up again after it.
|
|
174
|
+
if ('heldUntil' in fields) it.heldUntil = /^\d{4}-\d{2}-\d{2}$/.test(String(fields.heldUntil ?? '')) ? fields.heldUntil : null;
|
|
173
175
|
this.changed();
|
|
174
176
|
return it;
|
|
175
177
|
}
|
|
@@ -190,6 +192,16 @@ export class Backlog extends EventEmitter {
|
|
|
190
192
|
return it;
|
|
191
193
|
}
|
|
192
194
|
|
|
195
|
+
/** Put the queued items named in this order (each keeps its priority, which still comes first). */
|
|
196
|
+
reorder(ids) {
|
|
197
|
+
const queued = this.items().filter((x) => x.status === 'queued');
|
|
198
|
+
const rank = new Map(ids.map((id, i) => [id, i]));
|
|
199
|
+
const slots = queued.map((x) => x.order).sort((x, y) => x - y);
|
|
200
|
+
[...queued].sort((x, y) => (rank.get(x.id) ?? 1e6) - (rank.get(y.id) ?? 1e6) || x.order - y.order).forEach((x, i) => (x.order = slots[i]));
|
|
201
|
+
this.changed();
|
|
202
|
+
return this.items();
|
|
203
|
+
}
|
|
204
|
+
|
|
193
205
|
remove(id) {
|
|
194
206
|
const it = this.get(id);
|
|
195
207
|
if (it.status === 'active') throw err(409, 'Cancel the item first (its agent is working on it)');
|
|
@@ -284,6 +296,7 @@ export class Backlog extends EventEmitter {
|
|
|
284
296
|
this.changed();
|
|
285
297
|
return it;
|
|
286
298
|
}
|
|
299
|
+
it.reopened = (it.reopened ?? 0) + 1;
|
|
287
300
|
// Only a brief update after this point counts as "done" again.
|
|
288
301
|
Object.assign(it, { status: 'active', reviewAt: null, doneAt: null, activeSince: now() });
|
|
289
302
|
this.changed();
|
|
@@ -436,6 +449,7 @@ export class Backlog extends EventEmitter {
|
|
|
436
449
|
for (const it of items) {
|
|
437
450
|
if (active >= max) break;
|
|
438
451
|
if (it.status !== 'queued') continue;
|
|
452
|
+
if (it.heldUntil && it.heldUntil > new Date().toISOString().slice(0, 10)) continue;
|
|
439
453
|
const busy = items.filter((x) => x.projectKey === it.projectKey && x.status === 'active').length;
|
|
440
454
|
if (busy >= this.limitFor(it.projectKey)) continue;
|
|
441
455
|
this.launch(it);
|
package/src/brief.js
CHANGED
|
@@ -721,7 +721,9 @@ export const BENCH_FILE = 'BENCHMARK.md';
|
|
|
721
721
|
export const benchPath = (agentId) => path.join(briefDir(agentId), BENCH_FILE);
|
|
722
722
|
export const DEBUG_FILE = 'DEBUG.md';
|
|
723
723
|
export const debugPath = (agentId) => path.join(briefDir(agentId), DEBUG_FILE);
|
|
724
|
-
export const
|
|
724
|
+
export const REVERSE_FILE = 'REVERSE.md';
|
|
725
|
+
export const reversePath = (agentId) => path.join(briefDir(agentId), REVERSE_FILE);
|
|
726
|
+
export const SPEC_DOCS = { intent: intentPath, spec: specPath, plan: planPath, designdoc: designPath, benchmark: benchPath, demo: demoPath, debug: debugPath, reverse: reversePath };
|
|
725
727
|
|
|
726
728
|
// ------------------------------------------------------------------ debug
|
|
727
729
|
|
|
@@ -788,6 +790,79 @@ export function debugFixPrompt(file, which) {
|
|
|
788
790
|
);
|
|
789
791
|
}
|
|
790
792
|
|
|
793
|
+
// ------------------------------------------------------------------ reverse engineering
|
|
794
|
+
|
|
795
|
+
// Reverse engineer: you name a target (an app's folder, a binary, a website) and what you want to
|
|
796
|
+
// understand about it; the agent investigates in its own session with REA's tools (the "Reverse
|
|
797
|
+
// Engineer Anything" MCP server, github.com/morluto/rea) and keeps a report at REVERSE.md: how the
|
|
798
|
+
// feature works with animated diagrams, the evidence behind each claim, what could not be
|
|
799
|
+
// determined, and a plan for building your own version. It changes nothing until you ask it to build.
|
|
800
|
+
|
|
801
|
+
const REVERSE_SHAPE = [
|
|
802
|
+
'# Reverse engineering: <the feature> in <the target>',
|
|
803
|
+
'## Summary',
|
|
804
|
+
'Two or three sentences: how it works, and how sure you are.',
|
|
805
|
+
'## Target',
|
|
806
|
+
'What it is (name, version, platform), what kind (Electron or JavaScript app, native binary, .NET assembly, website), and which tools and providers you used on it.',
|
|
807
|
+
'## How it works',
|
|
808
|
+
'One ```mermaid flowchart of the path the feature takes through the real modules, functions or components you found, from what the user does to the result.',
|
|
809
|
+
'## Data and interfaces',
|
|
810
|
+
'One ```mermaid flowchart LR or sequenceDiagram of the data on that path: what is stored and where, formats, the calls between processes, and the network requests. Then a short list of the formats and endpoints by name.',
|
|
811
|
+
'## Findings',
|
|
812
|
+
'Numbered. Each with its evidence (a module or file path, a function or symbol, an address, a string, a request) and "confirmed" (seen directly) or "inferred" (reasoned from what was seen).',
|
|
813
|
+
'## What could not be determined',
|
|
814
|
+
'What is obfuscated, missing, server-side or out of reach of the tools you had, and what would be needed to find out.',
|
|
815
|
+
'## Build it',
|
|
816
|
+
'A plan for our own version in this project, from the behaviour described above: the pieces, where they go in this codebase, the order, effort (S, M, L) for each, and what to do differently or better. No code, text or assets taken from the target.',
|
|
817
|
+
'## Next checks',
|
|
818
|
+
'What to look at next, and what you need from the user (another build of the app, a sample file, an account).',
|
|
819
|
+
].join('\n');
|
|
820
|
+
|
|
821
|
+
const REVERSE_DIAGRAMS =
|
|
822
|
+
'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 target. ' +
|
|
823
|
+
'Animate the path in every flowchart: give its edges ids and animate them, e.g.\n' +
|
|
824
|
+
' A e1@--> B\n B e2@-->|"rows"| C\n e1@{ animate: true }\n e2@{ animate: true }\n' +
|
|
825
|
+
'Mark what is only inferred: `classDef inferred stroke:#f59e0b,stroke-width:3px,stroke-dasharray:4`, then `class Y inferred`; and what could not be seen: `classDef unknown stroke:#9ca3af,stroke-dasharray:2`, then `class Z unknown`.';
|
|
826
|
+
|
|
827
|
+
const REVERSE_RULES =
|
|
828
|
+
'Rules: this is for understanding how something works so we can build our own. Analyse only: do not modify, patch or redistribute the target, and do not change this repository yet. ' +
|
|
829
|
+
'Do not work on getting around licence checks, copy protection, sign-in or other access controls, and do not collect credentials, keys or personal data you come across: if that is what is asked, or the only way forward, stop and tell me. ' +
|
|
830
|
+
'Say what you saw, not what you assume: every claim in the report names its evidence.';
|
|
831
|
+
|
|
832
|
+
/** The message that starts (or continues) a reverse-engineering investigation in the agent's session. */
|
|
833
|
+
export function reversePrompt(file, { target = '', question = '', again = false } = {}) {
|
|
834
|
+
const q = String(question ?? '').trim();
|
|
835
|
+
const t = String(target ?? '').trim();
|
|
836
|
+
if (again) {
|
|
837
|
+
return (
|
|
838
|
+
`Reverse engineering, continued: ${q}${t ? `\nTarget: ${t}` : ''}\n` +
|
|
839
|
+
`Carry on and bring the report at ${file} up to date: same sections, diagrams redrawn where the picture changed, findings re-marked confirmed or inferred. ` +
|
|
840
|
+
'Still analysis only, and no changes to this repository unless I ask you to build. Answer me here in a few lines, and say what changed in the report.'
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return (
|
|
844
|
+
`Reverse engineer this: ${q}\nTarget: ${t}\n` +
|
|
845
|
+
"Use REA's tools (the \"Reverse Engineer Anything\" MCP server) to inspect the target: start with what kind of target it is, then follow the feature from what the user does down to the code and data behind it. " +
|
|
846
|
+
"If REA's tools are not available in this session, say so in one line and stop: it is set up with `npx rea-agents setup` (which I run myself, then restart this session); do not install it or anything else yourself. " +
|
|
847
|
+
'For a native binary REA needs a provider (Hopper, Ghidra, IDA or Kuna): if none is configured, say which is missing rather than guessing from strings alone.\n' +
|
|
848
|
+
`${REVERSE_RULES}\n` +
|
|
849
|
+
`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 know the shape of the target, and update it as you learn. Short and specific, in these sections:\n` +
|
|
850
|
+
`${REVERSE_SHAPE}\n${REVERSE_DIAGRAMS}\n` +
|
|
851
|
+
'When the report is written, tell me in a few lines how it works and what you could not determine.'
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** The message that asks for our own version to be built from the report. */
|
|
856
|
+
export function reverseBuildPrompt(file, what) {
|
|
857
|
+
const w = String(what ?? '').trim();
|
|
858
|
+
return (
|
|
859
|
+
`Build our own version from your reverse-engineering report at ${file}: ${w || 'the plan under "Build it", the smallest useful piece first'}.\n` +
|
|
860
|
+
'Write it from the behaviour the report describes, in this project\'s own style: copy no code, text, names of internal symbols or assets from the target, and add no dependency on it. ' +
|
|
861
|
+
'Add tests for the behaviour, run them, and where the report says the target does something badly, do it better. ' +
|
|
862
|
+
'Then update the report: add a "## Built" section (what was built, where, how it was verified, and what differs from the target on purpose).'
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
|
|
791
866
|
/** INTENT.md: the request as given, and where it came from. */
|
|
792
867
|
export function intentMarkdown(agent) {
|
|
793
868
|
const by = agent.startedBy ? 'the assistant' : agent.trigger ? (agent.trigger.source === 'github' ? 'a labeled GitHub issue' : 'a webhook') : agent.playbook ? `the playbook ${agent.playbook.name}` : agent.team ? `team ${agent.team.id} (${agent.team.role})` : agent.raceId ? `race ${agent.raceId}` : 'you';
|
package/src/cli.js
CHANGED
|
@@ -823,6 +823,112 @@ export async function main(argv) {
|
|
|
823
823
|
}
|
|
824
824
|
});
|
|
825
825
|
|
|
826
|
+
program
|
|
827
|
+
.command('runbook [id]')
|
|
828
|
+
.description('Runbooks for the support team, written from a release ticket, an epic, or the code changes of a time frame')
|
|
829
|
+
.option('--ticket <key>', 'from a release ticket: it, what it links to, its sub-tasks and its fix versions')
|
|
830
|
+
.option('--epic <key>', 'from every ticket of an epic')
|
|
831
|
+
.option('--since <date>', "from a project's code changes since YYYY-MM-DD (with -p)")
|
|
832
|
+
.option('--until <date>', 'the end of the time frame (default: now)')
|
|
833
|
+
.option('-p, --project <project>', 'the project (needed with --since)')
|
|
834
|
+
.option('--title <title>', 'its title')
|
|
835
|
+
.option('--note <text>', 'what to cover in particular')
|
|
836
|
+
.option('-o, --out <file>', 'save the Markdown to a file instead of printing it')
|
|
837
|
+
.action(async (id, opts) => {
|
|
838
|
+
await daemon();
|
|
839
|
+
const source = opts.ticket ? 'ticket' : opts.epic ? 'epic' : opts.since ? 'code' : null;
|
|
840
|
+
if (!source && !id) {
|
|
841
|
+
const v = await api('GET', '/runbooks');
|
|
842
|
+
if (!v.items.length) return console.log(dim('No runbooks yet: agentmgr runbook --ticket REL-42 | --epic PROJ-100 | --since 2026-10-01 -p <project>'));
|
|
843
|
+
for (const r of v.items) console.log(`${r.id} ${(r.status === 'ready' ? green : r.status === 'failed' ? red : yellow)(r.status.padEnd(7))} ${r.title} ${dim(r.updatedAt.slice(0, 10))}${r.error ? `\n ${red(r.error)}` : ''}`);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (source) {
|
|
847
|
+
({ id } = await api('POST', '/runbooks', { source, key: opts.ticket ?? opts.epic, project: opts.project, since: opts.since, until: opts.until, title: opts.title, note: opts.note }));
|
|
848
|
+
process.stderr.write(dim('Gathering the facts and writing it (a few minutes)…\n'));
|
|
849
|
+
}
|
|
850
|
+
let r = await api('GET', `/runbooks/${id}`);
|
|
851
|
+
for (let i = 0; r.status === 'writing' && i < 400; i++) {
|
|
852
|
+
await new Promise((res) => setTimeout(res, 2000));
|
|
853
|
+
r = await api('GET', `/runbooks/${id}`);
|
|
854
|
+
}
|
|
855
|
+
if (r.status !== 'ready') {
|
|
856
|
+
console.error(red(r.error ?? 'It is still being written'));
|
|
857
|
+
process.exitCode = 1;
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
if (opts.out) {
|
|
861
|
+
fs.writeFileSync(opts.out, r.markdown);
|
|
862
|
+
return console.log(green(`Saved ${opts.out}`));
|
|
863
|
+
}
|
|
864
|
+
console.log(r.markdown);
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
program
|
|
868
|
+
.command('decide')
|
|
869
|
+
.description('What waits for your decision with its recommendation; standing decisions; the backlog by impact; dates at risk')
|
|
870
|
+
.option('--do <n>', 'carry out the recommendation of the nth item waiting')
|
|
871
|
+
.option('--handled', 'what was decided for you')
|
|
872
|
+
.option('--standing', 'your standing decisions, and the autonomy of each project')
|
|
873
|
+
.option('--autonomy <project=level>', 'how much may be decided without you: ask, standing, safe or most')
|
|
874
|
+
.option('--priority', 'the backlog by impact')
|
|
875
|
+
.option('--risk', 'dates at risk, as choices')
|
|
876
|
+
.option('--json', 'print JSON')
|
|
877
|
+
.action(async (opts) => {
|
|
878
|
+
await daemon();
|
|
879
|
+
if (opts.autonomy) {
|
|
880
|
+
const [project, level] = String(opts.autonomy).split('=');
|
|
881
|
+
await api('PUT', '/advisor/autonomy', { project, level });
|
|
882
|
+
}
|
|
883
|
+
let v = await api('GET', '/advisor?think=1');
|
|
884
|
+
if (opts.do) {
|
|
885
|
+
const b = v.briefs.filter((x) => x.options.length)[Number(opts.do) - 1];
|
|
886
|
+
if (!b) return console.log(red('No such item waiting with a recommendation'));
|
|
887
|
+
v = await api('POST', '/advisor/briefs/apply', { key: b.key, option: b.recommend });
|
|
888
|
+
console.log(green(`Done: ${b.options[b.recommend].label} on "${b.title}"`));
|
|
889
|
+
}
|
|
890
|
+
if (opts.json) return console.log(JSON.stringify(v, null, 2));
|
|
891
|
+
const pc = (c) => (c == null ? '' : dim(` ${Math.round(c * 100)}% sure`));
|
|
892
|
+
if (opts.handled) {
|
|
893
|
+
if (!v.handled.length) return console.log(dim('Nothing has been decided for you yet.'));
|
|
894
|
+
for (const h of v.handled) console.log(`${dim(h.at.slice(0, 16).replace('T', ' '))} ${bold(h.project)} ${h.title}\n ${h.did}${pc(h.confidence)}\n ${dim(h.why)}`);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (opts.standing) {
|
|
898
|
+
for (const o of v.offers) console.log(`${yellow('offered')} when ${o.when} -> ${o.action}${o.text ? `: ${o.text}` : ''} ${dim(`(seen ${o.count} times)`)}`);
|
|
899
|
+
for (const r of v.standing) console.log(`${r.on === false ? dim('off') : green('on ')} ${dim(r.projectName ?? 'every project')} when ${r.when} -> ${r.action}${r.text ? `: ${r.text}` : ''} ${dim(`(used ${r.uses ?? 0})`)}`);
|
|
900
|
+
if (!v.offers.length && !v.standing.length) console.log(dim('No standing decisions yet.'));
|
|
901
|
+
console.log(dim('Autonomy'));
|
|
902
|
+
for (const p of v.autonomy) console.log(` ${(p.shortcut ?? p.name).padEnd(14)} ${p.level.padEnd(9)} ${dim(v.levels.find((l) => l.id === p.level)?.label ?? '')}`);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (opts.priority) {
|
|
906
|
+
if (!v.impact.length) return console.log(dim('No open backlog items.'));
|
|
907
|
+
for (const p of v.impact) {
|
|
908
|
+
console.log(`${bold(p.project.name)} ${dim(p.by === 'judge' ? 'ranked by the AI judge' : 'ranked by plain rules')}`);
|
|
909
|
+
for (const i of p.items) console.log(` ${String(i.rank).padStart(2)}. ${i.level.padEnd(6)} ${i.title}\n ${dim(i.why)}`);
|
|
910
|
+
}
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
if (opts.risk) {
|
|
914
|
+
if (!v.tradeoffs.length) return console.log(dim('No date is at risk.'));
|
|
915
|
+
for (const t of v.tradeoffs) {
|
|
916
|
+
console.log(`${bold(`${t.project.name}: ${t.stage.label}`)} ${t.stage.date} ${yellow(t.stage.words)}`);
|
|
917
|
+
for (const o of t.options) console.log(` ${o.id === t.recommend ? green('*') : ' '} ${o.label}: ${o.what}${o.id === t.recommend ? `\n ${dim(t.why)}` : ''}`);
|
|
918
|
+
}
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
if (!v.judge.enabled) console.log(yellow('The AI judge is off, so nothing is recommended.'));
|
|
922
|
+
if (!v.briefs.length) return console.log(dim('Nothing is waiting for a decision.'));
|
|
923
|
+
v.briefs.forEach((b, i) => {
|
|
924
|
+
const rec = b.options[b.recommend];
|
|
925
|
+
console.log(`${String(i + 1).padStart(2)}. ${bold(b.title)} ${dim(`${b.kind} · ${b.project} · ${b.agentName}`)}`);
|
|
926
|
+
if (!rec) return console.log(` ${dim(b.none ?? 'No recommendation.')}`);
|
|
927
|
+
console.log(` ${green('Recommended:')} ${rec.label}${rec.action !== 'approve' && rec.text ? `: ${rec.text}` : ''}${pc(b.confidence)}${b.undo === 'hard' ? red(' hard to undo') : ''}\n ${b.why}${b.risk ? `\n ${dim(`Risk: ${b.risk}`)}` : ''}`);
|
|
928
|
+
});
|
|
929
|
+
console.log(dim('agentmgr decide --do <n> carries out a recommendation.'));
|
|
930
|
+
});
|
|
931
|
+
|
|
826
932
|
program
|
|
827
933
|
.command('os')
|
|
828
934
|
.description('This computer and its load right now: processor, memory, disks, and what each open agent session takes')
|
|
@@ -1592,6 +1698,33 @@ export async function main(argv) {
|
|
|
1592
1698
|
console.log(dim(`\n(updated ${new Date(r.updatedAt).toLocaleString()})`));
|
|
1593
1699
|
});
|
|
1594
1700
|
|
|
1701
|
+
program
|
|
1702
|
+
.command('reverse')
|
|
1703
|
+
.description("Reverse engineer with an agent and REA's tools: name a target and what to understand; it keeps a report with diagrams, the evidence, what could not be determined and a plan to build your own. With no question: print the report")
|
|
1704
|
+
.argument('<agent>')
|
|
1705
|
+
.argument('[question...]', 'what to understand, or a follow-up once there is a report')
|
|
1706
|
+
.option('-t, --target <target>', "the app's folder, the binary's path or the website's address (needed the first time)")
|
|
1707
|
+
.option('--build [what]', 'build your own version from the report: which part in words, or its plan')
|
|
1708
|
+
.action(async (ref, question, opts) => {
|
|
1709
|
+
await daemon();
|
|
1710
|
+
const a = await resolveAgent(ref);
|
|
1711
|
+
const q = question.join(' ').trim();
|
|
1712
|
+
if (opts.build) {
|
|
1713
|
+
await api('POST', `/agents/${a.id}/reverse`, { build: opts.build === true ? q || true : opts.build });
|
|
1714
|
+
return console.log(`${green('✓')} asked ${a.name} to build it from the report, in this project's own code`);
|
|
1715
|
+
}
|
|
1716
|
+
if (q) {
|
|
1717
|
+
const rea = await api('GET', `/agents/${a.id}/reverse/rea`);
|
|
1718
|
+
if (!rea.registered) console.log(yellow(`REA was not found in Claude Code's settings for this agent. If it isn't set up: ${rea.setup} (then restart the agent's session).`));
|
|
1719
|
+
await api('POST', `/agents/${a.id}/reverse`, { question: q, target: opts.target });
|
|
1720
|
+
return console.log(`${green('✓')} sent to ${a.name}; it investigates in its session. The report: agentmgr reverse ${ref}`);
|
|
1721
|
+
}
|
|
1722
|
+
const r = await api('GET', `/agents/${a.id}/specs/reverse`);
|
|
1723
|
+
if (!r.markdown) return console.log(dim(`No report yet. Start one: agentmgr reverse ${ref} -t /path/to/app "how does search work"`));
|
|
1724
|
+
console.log(r.markdown.trimEnd());
|
|
1725
|
+
console.log(dim(`\n(updated ${new Date(r.updatedAt).toLocaleString()})`));
|
|
1726
|
+
});
|
|
1727
|
+
|
|
1595
1728
|
program
|
|
1596
1729
|
.command('fork')
|
|
1597
1730
|
.description("A new agent with this one's code and conversation, in its own worktree")
|
package/src/config.js
CHANGED
|
@@ -75,6 +75,8 @@ const DEFAULTS = {
|
|
|
75
75
|
// Plan: the tech debt radar (see DEBT_DEFAULTS in debt.js) and the calendar Today is planned around
|
|
76
76
|
// (its private iCal addresses and the working day; see CALENDAR_DEFAULTS in calendar.js).
|
|
77
77
|
debt: { enabled: true },
|
|
78
|
+
// Decide: recommendations on what waits for you, standing decisions, impact and trade-offs (advisor.js).
|
|
79
|
+
decide: { enabled: true },
|
|
78
80
|
calendar: { ics: [], workStart: '09:00', workEnd: '18:00' },
|
|
79
81
|
// AI News: the frontier labs' latest releases, summarized; see NEWS_DEFAULTS in news.js for every field.
|
|
80
82
|
news: { enabled: true },
|
package/src/decisions.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import crypto from 'node:crypto';
|
|
8
8
|
|
|
9
9
|
const MAX = 2000;
|
|
10
|
-
export const DECISION_KINDS = { plan: 'Plan review', answer: 'Your answer', design: 'Design', manual: 'Added by you' };
|
|
10
|
+
export const DECISION_KINDS = { plan: 'Plan review', answer: 'Your answer', design: 'Design', tradeoff: 'Trade-off', manual: 'Added by you' };
|
|
11
11
|
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
12
12
|
const clip = (s, n) => {
|
|
13
13
|
const t = String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
@@ -143,6 +143,30 @@ export class Decisions {
|
|
|
143
143
|
return this.state.items[id];
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/** One made elsewhere in the app (a trade-off on a date at risk): logged as it is. */
|
|
147
|
+
record({ kind = 'manual', project, title, decision, why = null, agentId = null, agentName = null } = {}) {
|
|
148
|
+
if (!project?.key) throw err(400, 'Pick the project it belongs to');
|
|
149
|
+
const id = `${kind}:${crypto.randomBytes(4).toString('hex')}`;
|
|
150
|
+
this.state.items[id] = { id, kind, at: this.now(), project: { key: project.key, name: project.name }, agentId, agentName, title: clip(title, 300), decision: clip(decision, 1000), why: clip(why, 1000) || null, superseded: false };
|
|
151
|
+
this.store.save();
|
|
152
|
+
this.onChange();
|
|
153
|
+
return this.state.items[id];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** What is known about one beyond what was gathered: the reasoning it was made on, who made it, how it held up. */
|
|
157
|
+
annotate(id, fields = {}) {
|
|
158
|
+
const it = this.state.items[id];
|
|
159
|
+
if (!it) return null;
|
|
160
|
+
// `reason` is the recommendation's reasoning, beside `why` (your own note), which stays as gathered.
|
|
161
|
+
for (const k of ['reason', 'by', 'recommended', 'followed', 'confidence', 'standing', 'outcome', 'lesson']) {
|
|
162
|
+
if (!(k in fields)) continue;
|
|
163
|
+
it[k] = typeof fields[k] === 'string' ? clip(fields[k], 1000) : fields[k];
|
|
164
|
+
}
|
|
165
|
+
this.store.save();
|
|
166
|
+
this.onChange();
|
|
167
|
+
return it;
|
|
168
|
+
}
|
|
169
|
+
|
|
146
170
|
/** Take one off the log (it isn't gathered again). */
|
|
147
171
|
remove(id) {
|
|
148
172
|
const st = this.state;
|
|
@@ -163,7 +187,7 @@ export class Decisions {
|
|
|
163
187
|
const words = String(q ?? '').trim().toLowerCase();
|
|
164
188
|
const live = new Set(this.agents().map((a) => a.id));
|
|
165
189
|
const items = all
|
|
166
|
-
.filter((i) => (!project || i.project.key === project) && (!words || `${i.title} ${i.decision} ${i.why ?? ''} ${i.agentName ?? ''} ${i.project.name}`.toLowerCase().includes(words)))
|
|
190
|
+
.filter((i) => (!project || i.project.key === project) && (!words || `${i.title} ${i.decision} ${i.why ?? ''} ${i.reason ?? ''} ${i.agentName ?? ''} ${i.project.name}`.toLowerCase().includes(words)))
|
|
167
191
|
.map((i) => ({ ...i, kindLabel: DECISION_KINDS[i.kind] ?? i.kind, agentGone: Boolean(i.agentId) && !live.has(i.agentId) }));
|
|
168
192
|
return { items, total: all.length, projects: [...counts.values()].sort((a, b) => a.name.localeCompare(b.name)), kinds: DECISION_KINDS };
|
|
169
193
|
}
|
|
@@ -179,7 +203,9 @@ export class Decisions {
|
|
|
179
203
|
out.push(`## ${name}`, '');
|
|
180
204
|
for (const i of list) {
|
|
181
205
|
out.push(`### ${i.title}`, '', `- **Decided:** ${i.decision}`);
|
|
182
|
-
if (i.why) out.push(`- **Why:** ${i.why}`);
|
|
206
|
+
if (i.why || i.reason) out.push(`- **Why:** ${i.why || i.reason}`);
|
|
207
|
+
if (i.by === 'auto') out.push(`- **Decided for you:** ${i.standing ? 'by a standing decision of yours' : 'on the recommendation'}`);
|
|
208
|
+
if (i.outcome === 'revisit') out.push(`- **Worth another look:** ${i.lesson || 'what followed did not go as planned'}`);
|
|
183
209
|
out.push(`- **When:** ${String(i.at).slice(0, 10)} · ${i.kindLabel}${i.agentName ? ` · agent ${i.agentName}` : ''}${i.superseded ? ' · replaced since' : ''}`, '');
|
|
184
210
|
}
|
|
185
211
|
}
|
package/src/jira.js
CHANGED
|
@@ -267,3 +267,78 @@ export async function issueFields({ key, site }, { jira = loadJira(), fetchImpl
|
|
|
267
267
|
return null;
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
+
|
|
271
|
+
/** One issue as a runbook needs it: what it is, what it says, and what it is tied to. */
|
|
272
|
+
function detailOf(i, site) {
|
|
273
|
+
const f = i?.fields ?? {};
|
|
274
|
+
const names = (list) => (Array.isArray(list) ? list : []).map((x) => (typeof x === 'string' ? x : x?.name)).filter((n) => typeof n === 'string').map((n) => n.slice(0, 80));
|
|
275
|
+
const links = (Array.isArray(f.issuelinks) ? f.issuelinks : [])
|
|
276
|
+
.map((l) => {
|
|
277
|
+
const other = l?.outwardIssue ?? l?.inwardIssue;
|
|
278
|
+
return other?.key ? { key: other.key, how: String((l.outwardIssue ? l.type?.outward : l.type?.inward) ?? l.type?.name ?? 'relates to').slice(0, 40), summary: typeof other.fields?.summary === 'string' ? other.fields.summary.slice(0, 200) : null } : null;
|
|
279
|
+
})
|
|
280
|
+
.filter(Boolean);
|
|
281
|
+
const comments = (Array.isArray(f.comment?.comments) ? f.comment.comments : []).slice(-3).map((c) => descriptionText(c?.body).replace(/\s+/g, ' ').trim().slice(0, 500)).filter(Boolean);
|
|
282
|
+
return {
|
|
283
|
+
key: i.key,
|
|
284
|
+
url: `${site}/browse/${i.key}`,
|
|
285
|
+
summary: typeof f.summary === 'string' ? f.summary.trim().slice(0, 300) : '',
|
|
286
|
+
type: typeof f.issuetype?.name === 'string' ? f.issuetype.name.slice(0, 40) : null,
|
|
287
|
+
status: typeof f.status?.name === 'string' ? f.status.name.slice(0, 60) : null,
|
|
288
|
+
priority: typeof f.priority?.name === 'string' ? f.priority.name.slice(0, 30) : null,
|
|
289
|
+
resolution: typeof f.resolution?.name === 'string' ? f.resolution.name.slice(0, 40) : null,
|
|
290
|
+
labels: names(f.labels),
|
|
291
|
+
components: names(f.components),
|
|
292
|
+
fixVersions: names(f.fixVersions),
|
|
293
|
+
parent: typeof f.parent?.key === 'string' ? f.parent.key : null,
|
|
294
|
+
subtasks: (Array.isArray(f.subtasks) ? f.subtasks : []).map((s) => s?.key).filter((k) => typeof k === 'string'),
|
|
295
|
+
links,
|
|
296
|
+
description: descriptionText(f.description).trim().slice(0, 3000),
|
|
297
|
+
comments,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const DETAIL_FIELDS = ['summary', 'status', 'issuetype', 'priority', 'resolution', 'labels', 'components', 'fixVersions', 'parent', 'subtasks', 'issuelinks', 'description', 'comment'];
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The issues a JQL query finds, in full (see detailOf), up to `max`. Needs the site and token from
|
|
305
|
+
* Settings → Jira. Throws with the reason in words when Jira can't be asked or refuses the query.
|
|
306
|
+
*/
|
|
307
|
+
export async function searchIssues(jql, { jira = loadJira(), fetchImpl = fetch, timeoutMs = 20_000, max = 100 } = {}) {
|
|
308
|
+
if (!jira.site || !jira.token) throw Object.assign(new Error('Jira is not set up: add your site and API token in Settings → Jira'), { status: 400 });
|
|
309
|
+
const headers = { accept: 'application/json', 'content-type': 'application/json', authorization: authOf(jira) };
|
|
310
|
+
const out = [];
|
|
311
|
+
let next = null;
|
|
312
|
+
let startAt = 0;
|
|
313
|
+
// Jira Cloud pages with a token, Server and Data Center with startAt.
|
|
314
|
+
for (let page = 0; page < 5 && out.length < max; page++) {
|
|
315
|
+
const n = Math.min(100, max - out.length);
|
|
316
|
+
const q = new URLSearchParams({ jql, fields: DETAIL_FIELDS.join(','), maxResults: String(n), startAt: String(startAt) });
|
|
317
|
+
let res;
|
|
318
|
+
try {
|
|
319
|
+
res = await jiraGet(
|
|
320
|
+
fetchImpl,
|
|
321
|
+
jira.site,
|
|
322
|
+
{ path: '/rest/api/3/search/jql', init: { method: 'POST', body: JSON.stringify({ jql, fields: DETAIL_FIELDS, maxResults: n, ...(next ? { nextPageToken: next } : {}) }) } },
|
|
323
|
+
{ path: `/rest/api/2/search?${q}`, init: { method: 'GET' } },
|
|
324
|
+
{ headers, signal: AbortSignal.timeout(timeoutMs) },
|
|
325
|
+
);
|
|
326
|
+
} catch (e) {
|
|
327
|
+
throw Object.assign(new Error(reasonOf(jira.site, null, e)), { status: 502 });
|
|
328
|
+
}
|
|
329
|
+
if (!res.ok) {
|
|
330
|
+
let said = '';
|
|
331
|
+
try {
|
|
332
|
+
said = ((await res.json())?.errorMessages ?? []).join(' ').slice(0, 300);
|
|
333
|
+
} catch {}
|
|
334
|
+
throw Object.assign(new Error(res.status === 400 && said ? `Jira did not accept the query: ${said}` : reasonOf(jira.site, res)), { status: res.status === 400 ? 400 : 502, jql: res.status === 400 });
|
|
335
|
+
}
|
|
336
|
+
const body = await res.json();
|
|
337
|
+
const issues = (body?.issues ?? []).filter((i) => typeof i?.key === 'string' && /^[A-Z][A-Z0-9_]+-\d+$/.test(i.key));
|
|
338
|
+
out.push(...issues.map((i) => detailOf(i, jira.site)));
|
|
339
|
+
next = typeof body?.nextPageToken === 'string' ? body.nextPageToken : null;
|
|
340
|
+
startAt += issues.length;
|
|
341
|
+
if (!issues.length || (!next && (body?.isLast === true || body?.total === undefined || startAt >= body.total))) break;
|
|
342
|
+
}
|
|
343
|
+
return out;
|
|
344
|
+
}
|
package/src/manager.js
CHANGED
|
@@ -35,6 +35,9 @@ import {
|
|
|
35
35
|
debugPath,
|
|
36
36
|
debugPrompt,
|
|
37
37
|
debugFixPrompt,
|
|
38
|
+
reversePath,
|
|
39
|
+
reversePrompt,
|
|
40
|
+
reverseBuildPrompt,
|
|
38
41
|
specDocsInfo,
|
|
39
42
|
specPath,
|
|
40
43
|
specPrompt,
|
|
@@ -833,7 +836,7 @@ export class AgentManager extends EventEmitter {
|
|
|
833
836
|
/** One of an agent's intent, spec and plan files. */
|
|
834
837
|
specDoc(ref, name) {
|
|
835
838
|
const agent = this.mustGet(ref);
|
|
836
|
-
if (!['intent', 'spec', 'plan', 'designdoc', 'benchmark', 'debug'].includes(name)) throw Object.assign(new Error('Unknown file (intent, spec, plan, designdoc, benchmark or
|
|
839
|
+
if (!['intent', 'spec', 'plan', 'designdoc', 'benchmark', 'debug', 'reverse'].includes(name)) throw Object.assign(new Error('Unknown file (intent, spec, plan, designdoc, benchmark, debug or reverse)'), { status: 400 });
|
|
837
840
|
return readSpecDoc(agent.id, name) ?? { name, markdown: null };
|
|
838
841
|
}
|
|
839
842
|
|
|
@@ -859,6 +862,31 @@ export class AgentManager extends EventEmitter {
|
|
|
859
862
|
return this.view(this.patch(agent.id, { debug: { asks, startedAt: agent.debug?.startedAt ?? now() } }));
|
|
860
863
|
}
|
|
861
864
|
|
|
865
|
+
/**
|
|
866
|
+
* Reverse engineer: ask the agent to work out how something in a target (an app's folder, a
|
|
867
|
+
* binary, a website) works, with REA's tools, and keep a report (REVERSE.md) with diagrams, the
|
|
868
|
+
* evidence, what could not be determined and a plan to build our own. `question`: what to
|
|
869
|
+
* understand, or a follow-up once there is a report. `build`: build our own version from the
|
|
870
|
+
* report (which part, in words; true for its plan). The message waits in the agent's queue.
|
|
871
|
+
*/
|
|
872
|
+
reverse(ref, { target = '', question = '', build = null } = {}) {
|
|
873
|
+
const agent = this.mustGet(ref);
|
|
874
|
+
if (!agent.workdir || agent.status === 'preparing') throw Object.assign(new Error('The agent has no folder to work in yet'), { status: 409 });
|
|
875
|
+
const q = String(question ?? '').replace(/\s+/g, ' ').trim().slice(0, 2000);
|
|
876
|
+
const has = Boolean(readSpecDoc(agent.id, 'reverse')?.markdown?.trim());
|
|
877
|
+
// The target as given the first time stands for the follow-ups.
|
|
878
|
+
const t = String(target ?? '').replace(/\s+/g, ' ').trim().slice(0, 500) || agent.reverse?.target || '';
|
|
879
|
+
if (build && !has) throw Object.assign(new Error('There is no report yet: say what to reverse engineer first'), { status: 409 });
|
|
880
|
+
if (!build && q.length < 3) throw Object.assign(new Error('Say what you want to understand'), { status: 400 });
|
|
881
|
+
if (!build && !t) throw Object.assign(new Error("Name the target: an app's folder, a binary's path, or a website's address"), { status: 400 });
|
|
882
|
+
fs.mkdirSync(briefDir(agent.id), { recursive: true });
|
|
883
|
+
const file = path.join(fs.realpathSync(briefDir(agent.id)), path.basename(reversePath(agent.id)));
|
|
884
|
+
const which = build === true ? '' : String(build ?? '').replace(/\s+/g, ' ').trim().slice(0, 500);
|
|
885
|
+
this.tell(agent.id, build ? reverseBuildPrompt(file, which) : reversePrompt(file, { target: t, question: q, again: has }), { source: 'reverse' });
|
|
886
|
+
const asks = [...(agent.reverse?.asks ?? []), { text: build ? `Build it${which ? `: ${which}` : ''}` : q, kind: build ? 'build' : has ? 'follow-up' : 'reverse', at: now() }].slice(-20);
|
|
887
|
+
return this.view(this.patch(agent.id, { reverse: { ...agent.reverse, target: t, asks, startedAt: agent.reverse?.startedAt ?? now() } }));
|
|
888
|
+
}
|
|
889
|
+
|
|
862
890
|
/** The agent's sample demo page (HTML), once it has written one. */
|
|
863
891
|
demoPage(ref) {
|
|
864
892
|
const agent = this.mustGet(ref);
|
|
@@ -2357,6 +2385,14 @@ export class AgentManager extends EventEmitter {
|
|
|
2357
2385
|
} catch {}
|
|
2358
2386
|
if (at !== (agent.debug.reportAt ?? null)) this.patch(id, { debug: { ...this.store.get(id).debug, reportAt: at } });
|
|
2359
2387
|
}
|
|
2388
|
+
// The same for a reverse-engineering report.
|
|
2389
|
+
if (agent.reverse) {
|
|
2390
|
+
let at = null;
|
|
2391
|
+
try {
|
|
2392
|
+
at = fs.statSync(reversePath(id)).mtime.toISOString();
|
|
2393
|
+
} catch {}
|
|
2394
|
+
if (at !== (agent.reverse.reportAt ?? null)) this.patch(id, { reverse: { ...this.store.get(id).reverse, reportAt: at } });
|
|
2395
|
+
}
|
|
2360
2396
|
}
|
|
2361
2397
|
|
|
2362
2398
|
// -------------------------------------------------------------- plan review
|
package/src/notify.js
CHANGED
|
@@ -21,6 +21,7 @@ export const EVENT_DEFAULTS = {
|
|
|
21
21
|
standup: true, // the daily standup is ready to play
|
|
22
22
|
value: true, // a scheduled value report (week, month, quarter)
|
|
23
23
|
milestone: true, // a project's date (code complete, RC, GA) is coming up, at risk or late
|
|
24
|
+
decided: true, // something was decided for you (a standing decision, or within the autonomy you set)
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
// Alerts the AI judge may hold for the digest or drop; the rest are always sent at once.
|
package/src/rea.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Whether REA (the "Reverse Engineer Anything" MCP server, github.com/morluto/rea) is registered
|
|
2
|
+
// with Claude Code, read from Claude Code's own files: your settings (~/.claude.json, for every
|
|
3
|
+
// folder and for one), and a project's .mcp.json. Nothing is run and nothing is installed here:
|
|
4
|
+
// setup is `npx rea-agents setup`, which you run yourself. A plugin that brings REA is not seen
|
|
5
|
+
// here, so "not found" is said as that, not as "not installed".
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { claudeConfigFile } from './trust.js';
|
|
10
|
+
|
|
11
|
+
export const REA_SETUP = 'npx rea-agents setup';
|
|
12
|
+
const read = (file) => {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** A registered MCP server that is REA: by its name, or by the package it runs. */
|
|
21
|
+
export function isRea(name, server) {
|
|
22
|
+
if (/^rea([-_]agents)?$/i.test(String(name))) return true;
|
|
23
|
+
const words = [server?.command, ...(Array.isArray(server?.args) ? server.args : [])].filter((x) => typeof x === 'string').join(' ');
|
|
24
|
+
return /(^|[\s/\\@])rea-agents(\b|@)/.test(words);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** { registered, where, name } for a folder (an agent's workspace): where REA is registered, if it is. */
|
|
28
|
+
export function reaStatus(dir = null, { config = claudeConfigFile() } = {}) {
|
|
29
|
+
const c = read(config) ?? {};
|
|
30
|
+
const real = (() => {
|
|
31
|
+
try {
|
|
32
|
+
return dir ? fs.realpathSync(dir) : null;
|
|
33
|
+
} catch {
|
|
34
|
+
return dir;
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
const places = [
|
|
38
|
+
['your Claude Code settings', c.mcpServers],
|
|
39
|
+
...(real ? [['this folder, in your Claude Code settings', c.projects?.[real]?.mcpServers ?? c.projects?.[dir]?.mcpServers], ["the project's .mcp.json", read(path.join(real, '.mcp.json'))?.mcpServers]] : []),
|
|
40
|
+
];
|
|
41
|
+
for (const [where, servers] of places) {
|
|
42
|
+
for (const [name, server] of Object.entries(servers && typeof servers === 'object' ? servers : {})) {
|
|
43
|
+
if (isRea(name, server)) return { registered: true, where, name, setup: REA_SETUP };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { registered: false, where: null, name: null, setup: REA_SETUP };
|
|
47
|
+
}
|