agentlane 0.4.0-rc.3 → 0.4.1-rc.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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ Newest first.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ### Changed
8
+
9
+ - **`init` in a terminal is a proper TUI.** It asks which agents you use with an arrow-key picker (space toggles, Enter confirms), with the agents it found checked and the file that gave each away beside it. It shows the files it wrote with skills grouped by folder, streams the package manager's output inside the frame while it adds agentlane and collapses it when that succeeds, and ends with each agent's next step. Output that isn't a terminal, such as an agent or CI running `init`, is unchanged.
10
+
11
+ ## 0.4.0
12
+
7
13
  ### New
8
14
 
9
15
  - **`npx agentlane init` with no flags.** init wires the agents whose files the project has (`CLAUDE.md`, `.codex/`, `.cursor/`, `.github/copilot-instructions.md`, `GEMINI.md`, `.agents/rules/` and others) or whose session runs it, and prints the reason for each. In a terminal it lists all six agents, checks the ones it found, and takes Enter, numbers or names. With no terminal and nothing found, it exits 2 and names `--agents` and `--all`, which work as before.
@@ -10,8 +10,9 @@ import { UsageError } from "../registry/refusal.js";
10
10
  import { resolveFolder } from "../registry-cli.js";
11
11
  import { commandUsage, groupUsage } from "../usage.js";
12
12
  import { describePluginSource } from "./claude-plugin.js";
13
- import { chooseAgents, describeDetections, detectAgents } from "./detect.js";
13
+ import { describeDetections, detectAgents } from "./detect.js";
14
14
  import { applyInit, planInit } from "./init.js";
15
+ import { terminalScreen } from "./init-screen.js";
15
16
  import { addCommand, installedVersion, listedRange, nearestPackage, PACKAGE_SPEC_ENV, packageManagerOf, shellLine, toolVersion, } from "./package.js";
16
17
  import { listSkills, SKILLS_DIR } from "./skills.js";
17
18
  export const AGENT_COMMANDS = ['init', 'skills'];
@@ -73,19 +74,16 @@ function parseAgents(raw, all) {
73
74
  throw new UsageError(`'${unknown.join(',') || raw}' is not an agent`, `pass --agents with any of ${AGENTS.join(',')}`);
74
75
  return AGENTS.filter(agent => names.includes(agent));
75
76
  }
76
- async function agentsToWire(values, root, deps) {
77
- if (values.agents !== undefined)
78
- return parseAgents(values.agents, values.all);
79
- if (values.all)
80
- return [...AGENTS];
77
+ async function agentsToWire(values, root, deps, screen) {
78
+ if (values.agents !== undefined || values.all) {
79
+ const agents = values.agents !== undefined ? parseAgents(values.agents, values.all) : [...AGENTS];
80
+ screen?.wiring(agents);
81
+ return agents;
82
+ }
81
83
  const detected = detectAgents(root, deps.env);
82
84
  const choose = `pass --agents with the ones you use (${AGENTS.join(',')}), or --all`;
83
- if (deps.terminal) {
84
- const chosen = await chooseAgents(detected, deps.terminal);
85
- if (chosen === null)
86
- throw new UsageError('no agents chosen, so init wrote nothing', choose);
87
- return chosen;
88
- }
85
+ if (screen)
86
+ return screen.chooseAgents(detected);
89
87
  if (detected.length === 0)
90
88
  throw new UsageError(`found no agent's files in ${root} and no agent's variable in this shell, so init doesn't know which agents to wire`, choose);
91
89
  deps.stdout(`${TOOL} init: found these agents (pass --agents to pick others):\n${describeDetections(detected)}`);
@@ -94,7 +92,7 @@ async function agentsToWire(values, root, deps) {
94
92
  function ignoredByGit(dir, name) {
95
93
  return spawnSync('git', ['-C', dir, 'check-ignore', '-q', name]).status === 0;
96
94
  }
97
- function provideToolkit(root, env, install) {
95
+ async function provideToolkit(root, env, installer, present) {
98
96
  const top = resolveFolder(root).worktree;
99
97
  const own = toolVersion();
100
98
  const override = env[PACKAGE_SPEC_ENV];
@@ -113,7 +111,7 @@ function provideToolkit(root, env, install) {
113
111
  notes.push(`${manifest} lists ${TOOL} ${range}, but it isn't installed: run ${choice.manager} install there, so ${CLI} exists.`);
114
112
  else if (installed !== own)
115
113
  notes.push(`${manifest} lists ${TOOL} ${range}, with ${installed} installed; init left it as it is. This init is ${own}: ${shellLine(addCommand(choice, dir, `${TOOL}@${own}`))} moves the project to it.`);
116
- return { notes, failed: null };
114
+ return { notes, added: null, failed: null };
117
115
  }
118
116
  }
119
117
  else {
@@ -122,11 +120,15 @@ function provideToolkit(root, env, install) {
122
120
  if (!ignoredByGit(dir, 'node_modules'))
123
121
  notes.push('node_modules/ is not in .gitignore: add it before you commit.');
124
122
  }
125
- const result = install(command, dir);
123
+ const result = await present({
124
+ title: `Adding ${spec} with ${choice.manager}`,
125
+ done: `Added ${spec} to ${manifest} with ${choice.manager}`,
126
+ run: onOutput => installer(command, dir, onOutput),
127
+ });
126
128
  if (!result.ok)
127
- return { notes, failed: { command: shellLine(command), dir, problem: result.problem } };
128
- notes.push(`Added ${spec} to ${manifest} as a dev dependency with ${choice.manager}, because ${choice.source}: ${shellLine(command)}`);
129
- return { notes, failed: null };
129
+ return { notes, added: null, failed: { command: shellLine(command), dir, problem: result.problem } };
130
+ const added = `Added ${spec} to ${manifest} as a dev dependency with ${choice.manager}, because ${choice.source}: ${shellLine(command)}`;
131
+ return { notes, added, failed: null };
130
132
  }
131
133
  function projectRoot(cwd, dir) {
132
134
  if (dir !== undefined) {
@@ -172,26 +174,54 @@ async function init(args, deps) {
172
174
  },
173
175
  });
174
176
  const root = projectRoot(deps.cwd, values.dir);
175
- const agents = await agentsToWire(values, root, deps);
177
+ const screen = deps.terminal ? terminalScreen(deps.terminal) : null;
178
+ const agents = await agentsToWire(values, root, deps, screen);
179
+ if (agents === null) {
180
+ screen?.stop('No agents chosen, so init wrote nothing.');
181
+ return 2;
182
+ }
176
183
  const plan = planInit(root, agents, listSkills(deps.skillsDir ?? SKILLS_DIR), deps.env);
177
- deps.stdout(report(plan, values.check));
184
+ if (screen)
185
+ screen.files(plan, values.check);
186
+ else
187
+ deps.stdout(report(plan, values.check));
178
188
  const refusals = plan.files.filter(f => f.status === 'refused');
179
189
  if (refusals.length > 0) {
180
- for (const file of refusals)
181
- deps.stderr(`${TOOL} init: ${file.reason ?? file.file}\n`);
182
- deps.stderr(`${TOOL} init: wrote nothing; fix ${refusals.length === 1 ? 'that file' : 'those files'} and run ${CLI} init again\n`);
190
+ if (screen)
191
+ screen.refused(refusals);
192
+ else {
193
+ for (const file of refusals)
194
+ deps.stderr(`${TOOL} init: ${file.reason ?? file.file}\n`);
195
+ deps.stderr(`${TOOL} init: wrote nothing; fix ${refusals.length === 1 ? 'that file' : 'those files'} and run ${CLI} init again\n`);
196
+ }
183
197
  return 1;
184
198
  }
185
199
  const changes = plan.files.filter(f => f.status === 'create' || f.status === 'update' || f.status === 'remove');
186
200
  if (values.check) {
187
- if (changes.length > 0)
201
+ if (screen)
202
+ screen.checked(changes.length);
203
+ else if (changes.length > 0)
188
204
  deps.stderr(`${TOOL} init --check: ${String(changes.length)} file(s) would change\n`);
189
205
  return changes.length > 0 ? 1 : 0;
190
206
  }
191
207
  const stamp = new Date((deps.now ?? Date.now)()).toISOString().replace(/[:.]/g, '-');
192
208
  const { backups } = applyInit(plan, path.join(stateDir(deps.env), 'init-backups', `${stamp}-${path.basename(root)}`));
193
- const toolkit = provideToolkit(root, deps.env, deps.install);
209
+ const toolkit = await provideToolkit(root, deps.env, deps.install, screen ? step => screen.install(step) : step => step.run(deps.stderr));
210
+ const askForSetup = findConfigFile(root) === null;
211
+ if (screen) {
212
+ screen.end({
213
+ notes: toolkit.notes,
214
+ backups: backups ?? null,
215
+ changed: changes.length > 0,
216
+ next: agents.map(agent => ({ agent, text: NEXT[agent](plan.claudePlugin) })),
217
+ askForSetup,
218
+ failed: toolkit.failed,
219
+ });
220
+ return toolkit.failed === null ? 0 : 1;
221
+ }
194
222
  const out = [...toolkit.notes];
223
+ if (toolkit.added)
224
+ out.push(toolkit.added);
195
225
  if (backups)
196
226
  out.push(`Backed up the files it changed in ${backups}.`);
197
227
  if (changes.length > 0)
@@ -201,7 +231,7 @@ async function init(args, deps) {
201
231
  out.push('Next:');
202
232
  for (const agent of agents)
203
233
  out.push(` ${agent}: ${NEXT[agent](plan.claudePlugin)}.`);
204
- if (findConfigFile(root) === null)
234
+ if (askForSetup)
205
235
  out.push(`Then ask your agent: "Set this project up with ${TOOL}." Its setup skill writes ${CONFIG_FILE}.`);
206
236
  deps.stdout(`${out.join('\n')}\n`);
207
237
  if (toolkit.failed === null)
@@ -1,6 +1,5 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { createInterface } from 'node:readline';
4
3
  import { agentMarker, AGENTS } from "../registry/owner.js";
5
4
  export const AGENT_NAMES = {
6
5
  claude: 'Claude Code',
@@ -30,59 +29,12 @@ export function detectAgents(root, env) {
30
29
  return AGENTS.flatMap((agent) => {
31
30
  const variable = agentMarker(env, agent);
32
31
  if (variable !== null)
33
- return [{ agent, signal: `${variable} is set, so ${AGENT_NAMES[agent]} runs this command` }];
32
+ return [{ agent, signal: `${variable} is set, so ${AGENT_NAMES[agent]} runs this command`, found: 'this session' }];
34
33
  const file = fileSignal(root, agent);
35
- return file === null ? [] : [{ agent, signal: file }];
34
+ return file === null ? [] : [{ agent, signal: file, found: file }];
36
35
  });
37
36
  }
38
37
  export function describeDetections(detected) {
39
38
  const width = Math.max(...detected.map(d => d.agent.length));
40
39
  return detected.map(d => ` ${d.agent.padEnd(width)} ${d.signal}\n`).join('');
41
40
  }
42
- function menu(detected) {
43
- const width = Math.max(...AGENTS.map(agent => agent.length));
44
- const lines = AGENTS.map((agent, i) => {
45
- const found = detected.find(d => d.agent === agent);
46
- return ` ${String(i + 1)}. [${found ? 'x' : ' '}] ${agent.padEnd(width)} ${found?.signal ?? ''}`.trimEnd();
47
- });
48
- return `Which agents do you use in this project?\n${lines.join('\n')}\n`;
49
- }
50
- function question(detected) {
51
- const example = '(such as 1,3 or claude,codex)';
52
- return detected.length > 0
53
- ? `Press Enter to wire ${detected.map(d => d.agent).join(', ')}, or type the numbers or names to wire instead ${example}: `
54
- : `Type the numbers or names of the agents to wire ${example}: `;
55
- }
56
- function parseChoice(line, detected) {
57
- const words = line
58
- .trim()
59
- .split(/[\s,]+/)
60
- .filter(word => word !== '');
61
- if (words.length === 0)
62
- return detected.length > 0 ? detected.map(d => d.agent) : 'Nothing is checked, so name at least one agent.';
63
- const chosen = new Set();
64
- for (const word of words) {
65
- const agent = /^\d+$/.test(word) ? AGENTS[Number(word) - 1] : AGENTS.find(name => name === word.toLowerCase());
66
- if (agent === undefined)
67
- return `'${word}' is not one of the agents above.`;
68
- chosen.add(agent);
69
- }
70
- return AGENTS.filter(agent => chosen.has(agent));
71
- }
72
- export async function chooseAgents(detected, terminal) {
73
- const lines = createInterface({ input: terminal.input, terminal: false });
74
- const answers = lines[Symbol.asyncIterator]();
75
- try {
76
- terminal.output.write(`${menu(detected)}${question(detected)}`);
77
- for (let next = await answers.next(); next.done !== true; next = await answers.next()) {
78
- const answer = parseChoice(next.value, detected);
79
- if (typeof answer !== 'string')
80
- return answer;
81
- terminal.output.write(`${answer}\n${question(detected)}`);
82
- }
83
- return null;
84
- }
85
- finally {
86
- lines.close();
87
- }
88
- }
@@ -0,0 +1,124 @@
1
+ import { styleText } from 'node:util';
2
+ import { cancel, intro, isCancel, log, multiselect, note, outro, taskLog } from '@clack/prompts';
3
+ import { CONFIG_FILE, TOOL } from "../name.js";
4
+ import { AGENTS } from "../registry/owner.js";
5
+ import { AGENT_NAMES } from "./detect.js";
6
+ import { toolVersion } from "./package.js";
7
+ const VERBS = {
8
+ create: ['created', 'would create', 'green'],
9
+ update: ['updated', 'would update', 'yellow'],
10
+ remove: ['removed', 'would remove', 'red'],
11
+ unchanged: ['unchanged', 'unchanged', 'dim'],
12
+ refused: ['refused', 'refused', 'red'],
13
+ };
14
+ function agentNames(agents) {
15
+ return agents.map(agent => AGENT_NAMES[agent]).join(', ');
16
+ }
17
+ function role(file) {
18
+ return [...new Set(file.edits.map(edit => edit.part))].join(', ');
19
+ }
20
+ function nextLine(agent, text) {
21
+ const name = AGENT_NAMES[agent];
22
+ return text.startsWith(name) ? `${text}.` : `${name}: ${text}.`;
23
+ }
24
+ export function terminalScreen(terminal) {
25
+ const io = { input: terminal.input, output: terminal.output };
26
+ intro(styleText('inverse', ` ${TOOL} ${toolVersion()} `), io);
27
+ return {
28
+ async chooseAgents(detected) {
29
+ const found = new Map(detected.map(d => [d.agent, d.found]));
30
+ const chosen = await multiselect({
31
+ ...io,
32
+ message: 'Which agents do you use in this project?',
33
+ options: AGENTS.map(agent => {
34
+ const where = found.get(agent);
35
+ return { value: agent, label: where ? `${AGENT_NAMES[agent]} ${styleText('dim', `(${where})`)}` : AGENT_NAMES[agent] };
36
+ }),
37
+ initialValues: detected.map(d => d.agent),
38
+ required: true,
39
+ });
40
+ return isCancel(chosen) ? null : chosen;
41
+ },
42
+ wiring(agents) {
43
+ log.step(`Wiring ${agentNames(agents)}`, io);
44
+ },
45
+ files(plan, check) {
46
+ const touched = plan.files.filter(file => file.status !== 'unchanged');
47
+ const rows = new Map();
48
+ for (const file of touched) {
49
+ const folder = role(file) === 'skills' ? /^(.*\bskills)\//.exec(file.file)?.[1] : undefined;
50
+ const key = folder === undefined ? `${file.status} ${file.file}` : `${file.status} ${folder}/`;
51
+ const row = rows.get(key) ?? {
52
+ status: file.status,
53
+ file: folder ? `${folder}/` : file.file,
54
+ what: role(file),
55
+ skills: 0,
56
+ };
57
+ if (folder !== undefined) {
58
+ row.skills += 1;
59
+ row.what = `${String(row.skills)} ${row.skills === 1 ? 'skill' : 'skills'}`;
60
+ }
61
+ rows.set(key, row);
62
+ }
63
+ const width = Math.max(0, ...[...rows.values()].map(row => row.file.length));
64
+ const lines = [...rows.values()].map(row => {
65
+ const [done, would, colour] = VERBS[row.status];
66
+ const verb = styleText(colour, (check ? would : done).padEnd(check ? 12 : 9));
67
+ return `${verb} ${row.file.padEnd(width)} ${styleText('dim', row.what)}`;
68
+ });
69
+ const kept = plan.files.length - touched.length;
70
+ if (kept > 0)
71
+ lines.push(styleText('dim', `${String(kept)} ${kept === 1 ? 'file' : 'files'} already up to date`));
72
+ const title = touched.length === 0
73
+ ? `The files for ${agentNames(plan.agents)} are up to date`
74
+ : `${check ? 'Would change' : 'Wrote'} the files for ${agentNames(plan.agents)}`;
75
+ log.success([title, ...lines].join('\n'), io);
76
+ },
77
+ refused(files) {
78
+ for (const file of files)
79
+ log.error(file.reason ?? file.file, io);
80
+ cancel(`Wrote nothing. Fix ${files.length === 1 ? 'that file' : 'those files'} and run init again.`, io);
81
+ },
82
+ checked(changes) {
83
+ outro(changes > 0 ? `${String(changes)} file(s) would change.` : 'Nothing would change.', io);
84
+ },
85
+ async install(step) {
86
+ const shown = taskLog({ ...io, title: step.title, limit: 6, retainLog: true });
87
+ let pending = '';
88
+ const result = await step.run(text => {
89
+ const lines = (pending + text).split(/\r?\n/);
90
+ pending = lines.pop() ?? '';
91
+ for (const line of lines)
92
+ if (line.trim() !== '')
93
+ shown.message(line);
94
+ });
95
+ if (pending.trim() !== '')
96
+ shown.message(pending);
97
+ if (result.ok)
98
+ shown.success(step.done);
99
+ else
100
+ shown.error(`${step.title} failed (${result.problem})`, { showLog: true });
101
+ return result;
102
+ },
103
+ end(ending) {
104
+ for (const text of ending.notes)
105
+ log.info(text, io);
106
+ if (ending.backups)
107
+ log.info(styleText('dim', `Backed up the files it changed in ${ending.backups}`), io);
108
+ if (ending.failed) {
109
+ const { command, dir, problem } = ending.failed;
110
+ log.error(`${command} failed (${problem}), so the hooks and the MCP server can't start yet.\nRun it in ${dir}, then you're set.`, io);
111
+ }
112
+ const steps = ending.next.map(({ agent, text }) => nextLine(agent, text));
113
+ if (ending.changed)
114
+ steps.push('Commit the files above: each agent reads them from the repository.');
115
+ note(steps.join('\n'), 'Next', io);
116
+ outro(ending.askForSetup
117
+ ? `Then ask your agent: ${styleText('bold', `"Set this project up with ${TOOL}."`)} It writes ${CONFIG_FILE}.`
118
+ : 'Done.', io);
119
+ },
120
+ stop(message) {
121
+ cancel(message, io);
122
+ },
123
+ };
124
+ }
@@ -1,4 +1,4 @@
1
- import { spawnSync } from 'node:child_process';
1
+ import { spawn } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { envName, TOOL } from "../name.js";
@@ -109,11 +109,21 @@ export function installedVersion(packageDir) {
109
109
  const version = jsonObjectAt(path.join(packageDir, 'node_modules', TOOL, 'package.json'))?.version;
110
110
  return typeof version === 'string' ? version : null;
111
111
  }
112
- export const realInstaller = (command, cwd) => {
113
- const result = spawnSync(command.program, command.args, { cwd, stdio: ['ignore', process.stderr, process.stderr] });
114
- if (result.error)
115
- return { ok: false, problem: result.error.message };
116
- if (result.status !== 0)
117
- return { ok: false, problem: result.signal ? `killed by ${result.signal}` : `exit ${String(result.status)}` };
118
- return { ok: true };
119
- };
112
+ export const realInstaller = (command, cwd, onOutput) => new Promise(resolve => {
113
+ const child = spawn(command.program, command.args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
114
+ child.stdout.on('data', (chunk) => {
115
+ onOutput(chunk.toString());
116
+ });
117
+ child.stderr.on('data', (chunk) => {
118
+ onOutput(chunk.toString());
119
+ });
120
+ child.on('error', error => {
121
+ resolve({ ok: false, problem: error.message });
122
+ });
123
+ child.on('close', (code, signal) => {
124
+ if (code === 0)
125
+ resolve({ ok: true });
126
+ else
127
+ resolve({ ok: false, problem: signal ? `killed by ${signal}` : `exit ${String(code)}` });
128
+ });
129
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentlane",
3
- "version": "0.4.0-rc.3",
3
+ "version": "0.4.1-rc.1",
4
4
  "description": "Gives each coding agent its own lane: a running copy of your app with its own ports, dev servers, database, and a simulator, emulator or browser to drive it.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -58,6 +58,7 @@
58
58
  "typescript-eslint": "^8.71.1"
59
59
  },
60
60
  "dependencies": {
61
+ "@clack/prompts": "1.8.1",
61
62
  "yaml": "2.9.1"
62
63
  }
63
64
  }