Skip to content

Commit 63a987b

Browse files
authored
feat: intelligent agent suggestion engine (v8.3.0) (#7)
1 parent ec2081b commit 63a987b

22 files changed

Lines changed: 3875 additions & 142 deletions

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ node_modules/
3333
bun.lock
3434

3535
# OpenCode working files
36-
.opencode/scratchpad.md
37-
.opencode/agents/.manifest-lock.json
36+
.opencode/*

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contribuer à OpenCode Agent Template
22

3-
Ce projet est un registre curé de **67 agents IA** pour [OpenCode](https://opencode.ai). Tous les agents sont manuellement évalués et maintenus — il n'y a pas de synchronisation automatique. Les scripts de sync existent encore comme outils de découverte, rien de plus.
3+
Ce projet est un registre curé de **69 agents IA** pour [OpenCode](https://opencode.ai). Tous les agents sont manuellement évalués et maintenus — il n'y a pas de synchronisation automatique. Les scripts de sync existent encore comme outils de découverte, rien de plus.
44

55
## Comment contribuer
66

@@ -25,7 +25,7 @@ Modifiez le prompt, ajustez les permissions, ou corrigez un problème. Consultez
2525
Deux sources d'inspiration :
2626

2727
- **Upstream** : `python3 scripts/sync-agents.py --list --tier=extended` pour voir ce qui existe sur [aitmpl.com](https://www.aitmpl.com/agents)
28-
- **Observation** : vous identifiez un gap dans les 67 agents existants
28+
- **Observation** : vous identifiez un gap dans les 69 agents existants
2929

3030
### 2 — Évaluation
3131

README.en.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[![CI](https://github.com/dmicheneau/opencode-template-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/dmicheneau/opencode-template-agent/actions/workflows/ci.yml)
66
![Agents](https://img.shields.io/badge/agents-69-blue)
7-
![Tests](https://img.shields.io/badge/tests-893%20passing-brightgreen)
7+
![Tests](https://img.shields.io/badge/tests-814%20passing-brightgreen)
88
![License](https://img.shields.io/badge/license-MIT-blue)
99
![Node](https://img.shields.io/badge/node-20%2B-green)
1010
![npm](https://img.shields.io/npm/v/opencode-agents?label=npm&color=cb3837)
@@ -18,9 +18,12 @@ Each agent follows an expert 4-section format: identity, decisions, examples, qu
1818
## 🚀 Quickstart
1919

2020
```bash
21-
# Interactive TUI (auto-detects TTY)
21+
# Interactive TUI with intelligent suggestions (auto-detects TTY)
2222
npx github:dmicheneau/opencode-template-agent
2323

24+
# Detect stack and suggest relevant agents
25+
npx github:dmicheneau/opencode-template-agent install
26+
2427
# Quick CLI — install a pack in one command
2528
npx github:dmicheneau/opencode-template-agent install --pack backend
2629
```
@@ -42,6 +45,7 @@ npx github:dmicheneau/opencode-template-agent tui
4245
**What it does:**
4346

4447
- Auto-detects TTY and launches the interactive interface
48+
- **Suggestion screen on startup**: if a stack is detected in the current project, the most relevant agents appear pre-selected — press `Space` to deselect, `Enter` to install, `B` to browse the full catalog
4549
- Browse categories with tabs (`` `` / `Tab`)
4650
- Navigate lists with `` ``
4751
- Select agents with `Space`, install with `Enter`
@@ -54,6 +58,9 @@ For automation or quick installation without a graphical interface.
5458
**Commands:**
5559

5660
```bash
61+
# Detect stack and suggest relevant agents
62+
npx github:dmicheneau/opencode-template-agent install
63+
5764
# Install a specific agent
5865
npx github:dmicheneau/opencode-template-agent install typescript-pro
5966

@@ -83,8 +90,8 @@ npx github:dmicheneau/opencode-template-agent search "machine learning"
8390

8491
| Option | Description |
8592
|--------|-------------|
86-
| `--force` | Overwrite existing files |
87-
| `--dry-run` | Preview without writing to disk |
93+
| `--force` | Overwrite existing files; with `install` (no args), re-suggests already-installed agents |
94+
| `--dry-run` | Preview without writing to disk (also works with the auto-suggest flow) |
8895

8996
> **Note:** `--pack` and `--category` are mutually exclusive.
9097
@@ -488,7 +495,7 @@ git push --tags
488495

489496
## 🧪 Tests
490497

491-
**893 tests** (560 JS + 23 plugin TS + 310 Python).
498+
**814 tests** (504 JS + 310 Python).
492499

493500
```bash
494501
# All JS tests (CLI + TUI)

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[![CI](https://github.com/dmicheneau/opencode-template-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/dmicheneau/opencode-template-agent/actions/workflows/ci.yml)
66
![Agents](https://img.shields.io/badge/agents-69-blue)
7-
![Tests](https://img.shields.io/badge/tests-893%20passing-brightgreen)
7+
![Tests](https://img.shields.io/badge/tests-814%20passing-brightgreen)
88
![License](https://img.shields.io/badge/license-MIT-blue)
99
![Node](https://img.shields.io/badge/node-20%2B-green)
1010
![npm](https://img.shields.io/npm/v/opencode-agents?label=npm&color=cb3837)
@@ -18,9 +18,12 @@ Chaque agent suit un format expert à 4 sections : identité, décisions, exempl
1818
## 🚀 Quickstart
1919

2020
```bash
21-
# TUI interactif (auto-détecte TTY)
21+
# TUI interactif avec suggestions intelligentes (auto-détecte TTY)
2222
npx github:dmicheneau/opencode-template-agent
2323

24+
# Détecte la stack et suggère les agents adaptés
25+
npx github:dmicheneau/opencode-template-agent install
26+
2427
# CLI rapide — installer un pack en une commande
2528
npx github:dmicheneau/opencode-template-agent install --pack backend
2629
```
@@ -42,6 +45,7 @@ npx github:dmicheneau/opencode-template-agent tui
4245
**Ce que ça fait :**
4346

4447
- Auto-détecte le TTY et lance l'interface interactive
48+
- **Écran de suggestions au démarrage** : si une stack est détectée dans le projet courant, les agents les plus pertinents apparaissent pré-sélectionnés — appuyez sur `Space` pour désélectionner, `Enter` pour installer, `B` pour parcourir tout le catalogue
4549
- Parcourir les catégories par onglets (`` `` / `Tab`)
4650
- Naviguer dans les listes avec `` ``
4751
- Sélectionner des agents avec `Space`, installer avec `Enter`
@@ -54,6 +58,9 @@ Pour l'automatisation ou une installation rapide sans interface graphique.
5458
**Commandes :**
5559

5660
```bash
61+
# Détecter la stack et suggérer les agents adaptés
62+
npx github:dmicheneau/opencode-template-agent install
63+
5764
# Installer un agent spécifique
5865
npx github:dmicheneau/opencode-template-agent install typescript-pro
5966

@@ -83,8 +90,8 @@ npx github:dmicheneau/opencode-template-agent search "machine learning"
8390

8491
| Option | Description |
8592
|--------|-------------|
86-
| `--force` | Écraser les fichiers existants |
87-
| `--dry-run` | Aperçu sans écriture sur le disque |
93+
| `--force` | Écraser les fichiers existants ; avec `install` sans argument, re-propose les agents déjà installés |
94+
| `--dry-run` | Aperçu sans écriture sur le disque (fonctionne aussi avec la suggestion automatique) |
8895

8996
> **Note :** `--pack` et `--category` sont mutuellement exclusifs.
9097
@@ -488,7 +495,7 @@ git push --tags
488495

489496
## 🧪 Tests
490497

491-
**893 tests** (560 JS + 23 plugin TS + 310 Python).
498+
**814 tests** (504 JS + 310 Python).
492499

493500
```bash
494501
# Tous les tests JS (CLI + TUI)

bin/cli.mjs

Lines changed: 149 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import { VERSION } from '../src/meta.mjs';
99

10+
import { createInterface } from 'node:readline';
11+
1012
import {
1113
getAgent,
1214
getCategory,
@@ -40,8 +42,11 @@ import {
4042
verifyLockIntegrity,
4143
rehashLock,
4244
bootstrapLock,
45+
detectInstalledSet,
4346
} from '../src/lock.mjs';
4447

48+
import { detectProjectProfile, scoreAgents } from '../src/recommender.mjs';
49+
4550
import { parsePermissionFlags } from '../src/permissions/cli.mjs';
4651
import { resolvePermissions } from '../src/permissions/resolve.mjs';
4752
import { loadPreferences, savePreferences } from '../src/permissions/persistence.mjs';
@@ -366,17 +371,157 @@ async function cmdInstall(parsed) {
366371
// install <agent-name>
367372
const agentName = parsed.args[0];
368373
if (!agentName) {
369-
errorMessage('Missing agent name. Usage: opencode-agents install <agent>');
370-
console.error(` Run ${cyan('opencode-agents list')} to see available agents.`);
371-
console.error();
372-
process.exit(1);
374+
// No arguments at all — run the smart suggestion flow
375+
const suggestedAgents = await runSuggestFlow(parsed, options, resolvedPerms);
376+
if (suggestedAgents === null) {
377+
console.log(`ℹ No agent suggestions available. Try ${cyan('opencode-agents list')} to browse all agents.`);
378+
return;
379+
}
380+
return;
373381
}
374382

375383
const agent = resolveAgentOrExit(agentName, 'install');
376384
const result = await installAgents([agent], { ...options, permissions: resolvedPerms });
377385
process.exit(result.failed > 0 ? 1 : 0);
378386
}
379387

388+
// ─── Smart Suggestion Flow ──────────────────────────────────────────────────────
389+
390+
/**
391+
* Detect project profile, score agents, prompt user, and install suggestions.
392+
* Returns the install result on success, or `null` to signal "fall through to help".
393+
*
394+
* @param {ParsedArgs} parsed
395+
* @param {{ force: boolean, dryRun: boolean }} options
396+
* @param {object|null} resolvedPerms
397+
* @returns {Promise<null | object>}
398+
*/
399+
async function runSuggestFlow(parsed, options, resolvedPerms) {
400+
const manifest = getManifest();
401+
402+
// 1. Detect project stack — bail gracefully on any error
403+
let profile;
404+
try {
405+
profile = detectProjectProfile(process.cwd());
406+
} catch {
407+
return null;
408+
}
409+
410+
// 2. Score agents
411+
const installed = options.force ? new Set() : detectInstalledSet(manifest, process.cwd());
412+
const suggestions = scoreAgents({ profile, installed, manifest });
413+
414+
// 3. No useful suggestions → fall through
415+
const useful = suggestions.filter((s) => s.score >= 0.1);
416+
if (useful.length === 0) return null;
417+
418+
const topN = useful.slice(0, 8);
419+
420+
// 4. Display detected stack
421+
const stackItems = [
422+
...profile.languages,
423+
...profile.tools,
424+
...(profile.frameworks ?? []),
425+
].slice(0, 5);
426+
427+
console.log();
428+
if (stackItems.length > 0) {
429+
console.log(bold('Detected stack:') + ' ' + stackItems.map((s) => cyan(s)).join(dim(' · ')));
430+
console.log();
431+
}
432+
433+
// 5. Display suggestions
434+
console.log(bold('Suggested agents for this project:'));
435+
console.log();
436+
437+
const maxNameLen = topN.reduce((m, s) => Math.max(m, s.agent.name.length), 0);
438+
const ANSI_OVERHEAD = cyan('').length;
439+
440+
topN.forEach((s, i) => {
441+
const idx = dim(String(i + 1).padStart(2) + '.');
442+
const name = padRight(cyan(s.agent.name), maxNameLen + ANSI_OVERHEAD);
443+
const pct = bold(String(Math.round(s.score * 100)).padStart(3) + '%');
444+
const desc = truncate(s.agent.description, 60);
445+
const reasons = s.reasons.slice(0, 4).join(dim(' · '));
446+
447+
console.log(` ${idx} ${name} ${pct} ${dim('—')} ${dim(desc)}`);
448+
if (reasons) {
449+
console.log(` ${dim(reasons)}`);
450+
}
451+
});
452+
453+
console.log();
454+
455+
// 6. Prompt Y/n (auto-confirm when --force or non-TTY)
456+
const autoConfirm = options.force || !process.stdin.isTTY;
457+
let confirmed;
458+
459+
if (autoConfirm) {
460+
confirmed = true;
461+
if (options.dryRun) {
462+
console.log(dim(` (auto-confirmed — dry run)`));
463+
} else if (!process.stdin.isTTY) {
464+
console.log(dim(` (auto-confirming in non-interactive mode)`));
465+
}
466+
} else {
467+
process.stdout.write(`Install these ${topN.length} agents? [Y/n] `);
468+
confirmed = await readYesNo();
469+
}
470+
471+
if (!confirmed) {
472+
console.log();
473+
showHelp();
474+
process.exit(0);
475+
}
476+
477+
// 7. Install
478+
console.log();
479+
header(`Installing ${topN.length} suggested agent(s)...`);
480+
const result = await installAgents(topN.map((s) => s.agent), { ...options, permissions: resolvedPerms });
481+
process.exit(result.failed > 0 ? 1 : 0);
482+
return result;
483+
}
484+
485+
// ─── Suggestion flow helpers ────────────────────────────────────────────────────
486+
487+
/**
488+
* Read a single line from stdin, return true for Y/y/o/enter, false for N/n.
489+
* @returns {Promise<boolean>}
490+
*/
491+
async function readYesNo() {
492+
const rl = createInterface({ input: process.stdin, output: process.stdout });
493+
return new Promise((resolve) => {
494+
rl.question('', (answer) => {
495+
rl.close();
496+
const a = answer.trim().toLowerCase();
497+
resolve(a === '' || a === 'y' || a === 'o');
498+
});
499+
});
500+
}
501+
502+
/**
503+
* Pad a string (which may contain ANSI codes) to `width` visible chars.
504+
* @param {string} s
505+
* @param {number} width
506+
* @returns {string}
507+
*/
508+
function padRight(s, width) {
509+
// Strip ANSI to measure visible length
510+
const visible = s.replace(/\x1b\[[0-9;]*m/g, '').length;
511+
return s + ' '.repeat(Math.max(0, width - visible));
512+
}
513+
514+
/**
515+
* Truncate a plain string to `max` chars, appending '…' if cut.
516+
* @param {string} s
517+
* @param {number} max
518+
* @returns {string}
519+
*/
520+
function truncate(s, max) {
521+
if (s.length <= max) return s;
522+
return s.slice(0, max - 1) + '…';
523+
}
524+
380525
// ─── Command: uninstall ─────────────────────────────────────────────────────────
381526

382527
/**

data/ecosystem-intent-tags.csv

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
agent_name,ecosystem,intent,related_agents
2+
accessibility,web,audit,"ui-designer,react-specialist,nextjs-developer,screenshot-ui-analyzer"
3+
ai-engineer,ai,build,"ml-engineer,llm-architect,mlops-engineer,data-scientist"
4+
angular-architect,javascript,build,"typescript-pro,react-specialist,vue-expert,nextjs-developer"
5+
api-architect,web,design,"graphql-architect,database-architect,microservices-architect,documentation-engineer"
6+
api-documenter,web,document,"technical-writer,api-architect,documentation-engineer,diagram-architect"
7+
aws-specialist,cloud,deploy,"terraform-specialist,platform-engineer,kubernetes-specialist,ci-cd-engineer"
8+
business-analyst,web,plan,"product-manager,prd,project-manager,ux-researcher"
9+
ci-cd-engineer,devops,deploy,"docker-specialist,kubernetes-specialist,platform-engineer,sre-engineer"
10+
code-reviewer,web,review,"refactoring-specialist,test-automator,debugger,typescript-pro"
11+
compliance-auditor,security,audit,"security-auditor,security-engineer,penetration-tester,mcp-security-auditor"
12+
cpp-pro,web,build,"rust-pro,performance-engineer,debugger,refactoring-specialist"
13+
csharp-developer,dotnet,build,"java-architect,typescript-pro,database-architect,api-architect"
14+
data-analyst,data,research,"data-scientist,data-engineer,sql-pro,postgres-pro"
15+
data-engineer,data,build,"data-scientist,ml-engineer,postgres-pro,database-architect"
16+
data-scientist,data,research,"ml-engineer,data-engineer,ai-engineer,data-analyst"
17+
database-architect,data,design,"postgres-pro,sql-pro,api-architect,data-engineer"
18+
debugger,web,debug,"code-reviewer,performance-engineer,test-automator,refactoring-specialist"
19+
diagram-architect,web,document,"documentation-engineer,microservices-architect,api-architect,technical-writer"
20+
docker-specialist,devops,deploy,"kubernetes-specialist,ci-cd-engineer,platform-engineer,sre-engineer"
21+
documentation-engineer,web,document,"technical-writer,api-documenter,diagram-architect,api-architect"
22+
fullstack-developer,javascript,build,"typescript-pro,react-specialist,nextjs-developer,postgres-pro"
23+
golang-pro,go,build,"rust-pro,microservices-architect,kubernetes-specialist,docker-specialist"
24+
graphql-architect,web,design,"api-architect,database-architect,react-specialist,nextjs-developer"
25+
incident-responder,devops,debug,"sre-engineer,kubernetes-specialist,platform-engineer,docker-specialist"
26+
java-architect,jvm,build,"kotlin-specialist,microservices-architect,database-architect,api-architect"
27+
kotlin-specialist,jvm,build,"java-architect,mobile-developer,microservices-architect,api-architect"
28+
kubernetes-specialist,devops,deploy,"docker-specialist,platform-engineer,ci-cd-engineer,sre-engineer"
29+
legacy-modernizer,web,migrate,"refactoring-specialist,code-reviewer,typescript-pro,test-automator"
30+
linux-admin,devops,deploy,"docker-specialist,sre-engineer,kubernetes-specialist,platform-engineer"
31+
llm-architect,ai,design,"ai-engineer,prompt-engineer,ml-engineer,search-specialist"
32+
mcp-developer,mcp,build,"mcp-security-auditor,typescript-pro,api-architect"
33+
mcp-security-auditor,mcp,audit,"mcp-developer,security-auditor,compliance-auditor,security-engineer"
34+
microservices-architect,cloud,design,"api-architect,docker-specialist,kubernetes-specialist,database-architect"
35+
ml-engineer,ai,build,"data-scientist,mlops-engineer,ai-engineer,llm-architect"
36+
mlops-engineer,ai,deploy,"ml-engineer,docker-specialist,kubernetes-specialist,ai-engineer"
37+
mobile-developer,mobile,build,"react-specialist,swift-expert,kotlin-specialist,ui-designer"
38+
nextjs-developer,javascript,build,"react-specialist,typescript-pro,ui-designer,fullstack-developer"
39+
penetration-tester,security,audit,"security-auditor,compliance-auditor,security-engineer,mcp-security-auditor"
40+
performance-engineer,web,optimize,"debugger,code-reviewer,test-automator,refactoring-specialist"
41+
php-pro,php,build,"database-architect,api-architect,code-reviewer,refactoring-specialist"
42+
platform-engineer,devops,deploy,"kubernetes-specialist,docker-specialist,ci-cd-engineer,sre-engineer"
43+
postgres-pro,data,optimize,"database-architect,sql-pro,data-engineer,redis-specialist"
44+
prd,web,plan,"product-manager,business-analyst,project-manager,ux-researcher"
45+
product-manager,web,plan,"prd,business-analyst,ux-researcher,scrum-master"
46+
project-manager,web,plan,"product-manager,scrum-master,business-analyst,prd"
47+
prompt-engineer,ai,optimize,"llm-architect,ai-engineer,search-specialist"
48+
python-pro,python,build,"data-scientist,ai-engineer,data-engineer,api-architect"
49+
qa-expert,web,test,"test-automator,code-reviewer,debugger,performance-engineer"
50+
rails-expert,ruby,build,"database-architect,api-architect,code-reviewer,refactoring-specialist"
51+
react-specialist,javascript,build,"nextjs-developer,typescript-pro,ui-designer,angular-architect"
52+
redis-specialist,data,optimize,"postgres-pro,database-architect,performance-engineer,api-architect"
53+
refactoring-specialist,web,migrate,"code-reviewer,legacy-modernizer,test-automator,debugger"
54+
rust-pro,rust,build,"cpp-pro,golang-pro,performance-engineer,debugger"
55+
screenshot-ui-analyzer,web,review,"ui-designer,accessibility,react-specialist,ux-researcher"
56+
scrum-master,web,plan,"product-manager,project-manager,business-analyst,prd"
57+
search-specialist,ai,research,"data-analyst,llm-architect,prompt-engineer"
58+
security-auditor,security,audit,"penetration-tester,compliance-auditor,security-engineer,mcp-security-auditor"
59+
security-engineer,security,audit,"security-auditor,compliance-auditor,penetration-tester,ci-cd-engineer"
60+
smart-contract-auditor,security,audit,"security-auditor,compliance-auditor,penetration-tester"
61+
sql-pro,data,optimize,"postgres-pro,database-architect,data-engineer,data-analyst"
62+
sre-engineer,devops,deploy,"kubernetes-specialist,platform-engineer,incident-responder,docker-specialist"
63+
swift-expert,mobile,build,"mobile-developer,kotlin-specialist,ui-designer"
64+
technical-writer,web,document,"documentation-engineer,api-documenter,diagram-architect"
65+
terraform-specialist,devops,deploy,"aws-specialist,platform-engineer,kubernetes-specialist,ci-cd-engineer"
66+
test-automator,web,test,"qa-expert,code-reviewer,debugger,ci-cd-engineer"
67+
typescript-pro,javascript,build,"react-specialist,nextjs-developer,code-reviewer,refactoring-specialist"
68+
ui-designer,web,design,"accessibility,react-specialist,nextjs-developer,screenshot-ui-analyzer"
69+
ux-researcher,web,research,"product-manager,business-analyst,ui-designer,accessibility"
70+
vue-expert,javascript,build,"angular-architect,react-specialist,typescript-pro,nextjs-developer"

0 commit comments

Comments
 (0)