@swarmify/agents-cli 1.8.1 → 1.9.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 +31 -0
- package/README.md +9 -9
- package/dist/commands/daemon.js +1 -1
- package/dist/commands/daemon.js.map +1 -1
- package/dist/commands/routines.d.ts +3 -0
- package/dist/commands/routines.d.ts.map +1 -0
- package/dist/commands/{cron.js → routines.js} +23 -23
- package/dist/commands/routines.js.map +1 -0
- package/dist/commands/sessions.d.ts.map +1 -1
- package/dist/commands/sessions.js +135 -50
- package/dist/commands/sessions.js.map +1 -1
- package/dist/index.js +17 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/__tests__/bugfixes.test.js +1 -1
- package/dist/lib/__tests__/bugfixes.test.js.map +1 -1
- package/dist/lib/agents.d.ts.map +1 -1
- package/dist/lib/agents.js +116 -0
- package/dist/lib/agents.js.map +1 -1
- package/dist/lib/daemon.js +1 -1
- package/dist/lib/daemon.js.map +1 -1
- package/dist/lib/exec.d.ts.map +1 -1
- package/dist/lib/exec.js +75 -1
- package/dist/lib/exec.js.map +1 -1
- package/dist/lib/{cron.d.ts → routines.d.ts} +1 -1
- package/dist/lib/routines.d.ts.map +1 -0
- package/dist/lib/{cron.js → routines.js} +8 -8
- package/dist/lib/routines.js.map +1 -0
- package/dist/lib/runner.d.ts +1 -1
- package/dist/lib/runner.d.ts.map +1 -1
- package/dist/lib/runner.js +1 -1
- package/dist/lib/runner.js.map +1 -1
- package/dist/lib/sandbox.d.ts +1 -1
- package/dist/lib/sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox.js +2 -2
- package/dist/lib/sandbox.js.map +1 -1
- package/dist/lib/scheduler.d.ts +1 -1
- package/dist/lib/scheduler.d.ts.map +1 -1
- package/dist/lib/scheduler.js +1 -1
- package/dist/lib/scheduler.js.map +1 -1
- package/dist/lib/session/discover.d.ts +2 -1
- package/dist/lib/session/discover.d.ts.map +1 -1
- package/dist/lib/session/discover.js +266 -65
- package/dist/lib/session/discover.js.map +1 -1
- package/dist/lib/session/render.d.ts +3 -2
- package/dist/lib/session/render.d.ts.map +1 -1
- package/dist/lib/session/render.js +157 -33
- package/dist/lib/session/render.js.map +1 -1
- package/dist/lib/session/types.d.ts +3 -0
- package/dist/lib/session/types.d.ts.map +1 -1
- package/dist/lib/state.d.ts +3 -1
- package/dist/lib/state.d.ts.map +1 -1
- package/dist/lib/state.js +7 -5
- package/dist/lib/state.js.map +1 -1
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/commands/cron.d.ts +0 -3
- package/dist/commands/cron.d.ts.map +0 -1
- package/dist/commands/cron.js.map +0 -1
- package/dist/commands/jobs.d.ts +0 -3
- package/dist/commands/jobs.d.ts.map +0 -1
- package/dist/commands/jobs.js +0 -197
- package/dist/commands/jobs.js.map +0 -1
- package/dist/commands/memory.d.ts +0 -3
- package/dist/commands/memory.d.ts.map +0 -1
- package/dist/commands/memory.js +0 -428
- package/dist/commands/memory.js.map +0 -1
- package/dist/commands/repo.d.ts +0 -16
- package/dist/commands/repo.d.ts.map +0 -1
- package/dist/commands/repo.js +0 -159
- package/dist/commands/repo.js.map +0 -1
- package/dist/lib/__tests__/permissions.test.d.ts +0 -2
- package/dist/lib/__tests__/permissions.test.d.ts.map +0 -1
- package/dist/lib/__tests__/permissions.test.js +0 -120
- package/dist/lib/__tests__/permissions.test.js.map +0 -1
- package/dist/lib/agents.test.d.ts +0 -2
- package/dist/lib/agents.test.d.ts.map +0 -1
- package/dist/lib/agents.test.js +0 -29
- package/dist/lib/agents.test.js.map +0 -1
- package/dist/lib/cron.d.ts.map +0 -1
- package/dist/lib/cron.js.map +0 -1
- package/dist/lib/instructions.d.ts +0 -44
- package/dist/lib/instructions.d.ts.map +0 -1
- package/dist/lib/instructions.js +0 -280
- package/dist/lib/instructions.js.map +0 -1
- package/dist/lib/jobs.d.ts +0 -53
- package/dist/lib/jobs.d.ts.map +0 -1
- package/dist/lib/jobs.js +0 -242
- package/dist/lib/jobs.js.map +0 -1
package/dist/commands/jobs.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import ora from 'ora';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
import { isDaemonRunning, signalDaemonReload, } from '../lib/daemon.js';
|
|
6
|
-
import { listJobs as listAllJobs, readJob, validateJob, writeJob, setJobEnabled, getLatestRun, getRunDir, } from '../lib/jobs.js';
|
|
7
|
-
import { executeJob } from '../lib/runner.js';
|
|
8
|
-
import { JobScheduler } from '../lib/scheduler.js';
|
|
9
|
-
export function registerJobsCommands(program) {
|
|
10
|
-
const jobsCmd = program.command('jobs').description('Manage scheduled jobs');
|
|
11
|
-
jobsCmd
|
|
12
|
-
.command('list')
|
|
13
|
-
.description('List all jobs')
|
|
14
|
-
.action(() => {
|
|
15
|
-
const jobs = listAllJobs();
|
|
16
|
-
if (jobs.length === 0) {
|
|
17
|
-
console.log(chalk.gray('No jobs configured'));
|
|
18
|
-
console.log(chalk.gray(' Add a job: agents jobs add <path-to-job.yml>'));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const scheduler = new JobScheduler(async () => { });
|
|
22
|
-
scheduler.loadAll();
|
|
23
|
-
console.log(chalk.bold('Scheduled Jobs\n'));
|
|
24
|
-
const header = ` ${'Name'.padEnd(24)} ${'Agent'.padEnd(10)} ${'Schedule'.padEnd(20)} ${'Enabled'.padEnd(10)} ${'Next Run'.padEnd(24)} ${'Last Status'}`;
|
|
25
|
-
console.log(chalk.gray(header));
|
|
26
|
-
console.log(chalk.gray(' ' + '-'.repeat(110)));
|
|
27
|
-
for (const job of jobs) {
|
|
28
|
-
const nextRun = scheduler.getNextRun(job.name);
|
|
29
|
-
const nextStr = nextRun ? nextRun.toLocaleString() : '-';
|
|
30
|
-
const latestRun = getLatestRun(job.name);
|
|
31
|
-
const lastStatus = latestRun?.status || '-';
|
|
32
|
-
const enabledStr = job.enabled ? chalk.green('yes') : chalk.gray('no');
|
|
33
|
-
const statusColor = lastStatus === 'completed' ? chalk.green : lastStatus === 'failed' ? chalk.red : lastStatus === 'timeout' ? chalk.yellow : chalk.gray;
|
|
34
|
-
console.log(` ${chalk.cyan(job.name.padEnd(24))} ${job.agent.padEnd(10)} ${job.schedule.padEnd(20)} ${enabledStr.padEnd(10 + 10)} ${chalk.gray(nextStr.padEnd(24))} ${statusColor(lastStatus)}`);
|
|
35
|
-
}
|
|
36
|
-
scheduler.stopAll();
|
|
37
|
-
console.log();
|
|
38
|
-
});
|
|
39
|
-
jobsCmd
|
|
40
|
-
.command('add <path>')
|
|
41
|
-
.description('Add a job from a YAML file')
|
|
42
|
-
.action(async (filePath) => {
|
|
43
|
-
const resolved = path.resolve(filePath);
|
|
44
|
-
if (!fs.existsSync(resolved)) {
|
|
45
|
-
console.log(chalk.red(`File not found: ${resolved}`));
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
const content = fs.readFileSync(resolved, 'utf-8');
|
|
49
|
-
let parsed;
|
|
50
|
-
try {
|
|
51
|
-
const yamlMod = await import('yaml');
|
|
52
|
-
parsed = yamlMod.parse(content);
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
console.log(chalk.red(`Invalid YAML: ${err.message}`));
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
const name = parsed.name || path.basename(resolved).replace(/\.ya?ml$/, '');
|
|
59
|
-
parsed.name = name;
|
|
60
|
-
const errors = validateJob(parsed);
|
|
61
|
-
if (errors.length > 0) {
|
|
62
|
-
console.log(chalk.red('Validation errors:'));
|
|
63
|
-
for (const err of errors) {
|
|
64
|
-
console.log(chalk.red(` - ${err}`));
|
|
65
|
-
}
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
const config = {
|
|
69
|
-
mode: 'plan',
|
|
70
|
-
effort: 'default',
|
|
71
|
-
timeout: '30m',
|
|
72
|
-
enabled: true,
|
|
73
|
-
...parsed,
|
|
74
|
-
};
|
|
75
|
-
writeJob(config);
|
|
76
|
-
console.log(chalk.green(`Job '${name}' added`));
|
|
77
|
-
if (isDaemonRunning()) {
|
|
78
|
-
signalDaemonReload();
|
|
79
|
-
console.log(chalk.gray('Daemon reloaded'));
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
jobsCmd
|
|
83
|
-
.command('run <name>')
|
|
84
|
-
.description('Run a job immediately in the foreground')
|
|
85
|
-
.action(async (name) => {
|
|
86
|
-
const job = readJob(name);
|
|
87
|
-
if (!job) {
|
|
88
|
-
console.log(chalk.red(`Job '${name}' not found`));
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
console.log(chalk.bold(`Running job '${name}' (agent: ${job.agent}, mode: ${job.mode})\n`));
|
|
92
|
-
const spinner = ora('Executing...').start();
|
|
93
|
-
try {
|
|
94
|
-
const result = await executeJob(job);
|
|
95
|
-
if (result.meta.status === 'completed') {
|
|
96
|
-
spinner.succeed(`Job completed (exit code: ${result.meta.exitCode})`);
|
|
97
|
-
}
|
|
98
|
-
else if (result.meta.status === 'timeout') {
|
|
99
|
-
spinner.warn(`Job timed out after ${job.timeout}`);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
spinner.fail(`Job failed (exit code: ${result.meta.exitCode})`);
|
|
103
|
-
}
|
|
104
|
-
console.log(chalk.gray(` Run: ${result.meta.runId}`));
|
|
105
|
-
console.log(chalk.gray(` Log: ${getRunDir(name, result.meta.runId)}/stdout.log`));
|
|
106
|
-
if (result.reportPath) {
|
|
107
|
-
console.log(chalk.bold('\nReport:\n'));
|
|
108
|
-
console.log(fs.readFileSync(result.reportPath, 'utf-8'));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
spinner.fail('Execution failed');
|
|
113
|
-
console.error(chalk.red(err.message));
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
jobsCmd
|
|
118
|
-
.command('logs <name>')
|
|
119
|
-
.description('Show stdout from the latest (or specific) run')
|
|
120
|
-
.option('-r, --run <runId>', 'Specific run ID')
|
|
121
|
-
.action((name, options) => {
|
|
122
|
-
let runId = options.run;
|
|
123
|
-
if (!runId) {
|
|
124
|
-
const latest = getLatestRun(name);
|
|
125
|
-
if (!latest) {
|
|
126
|
-
console.log(chalk.yellow(`No runs found for job '${name}'`));
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
runId = latest.runId;
|
|
130
|
-
}
|
|
131
|
-
const logPath = path.join(getRunDir(name, runId), 'stdout.log');
|
|
132
|
-
if (!fs.existsSync(logPath)) {
|
|
133
|
-
console.log(chalk.yellow(`Log not found: ${logPath}`));
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
console.log(chalk.gray(`Run: ${runId}\n`));
|
|
137
|
-
console.log(fs.readFileSync(logPath, 'utf-8'));
|
|
138
|
-
});
|
|
139
|
-
jobsCmd
|
|
140
|
-
.command('report <name>')
|
|
141
|
-
.description('Show report from the latest (or specific) run')
|
|
142
|
-
.option('-r, --run <runId>', 'Specific run ID')
|
|
143
|
-
.action((name, options) => {
|
|
144
|
-
let runId = options.run;
|
|
145
|
-
if (!runId) {
|
|
146
|
-
const latest = getLatestRun(name);
|
|
147
|
-
if (!latest) {
|
|
148
|
-
console.log(chalk.yellow(`No runs found for job '${name}'`));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
runId = latest.runId;
|
|
152
|
-
}
|
|
153
|
-
const reportPath = path.join(getRunDir(name, runId), 'report.md');
|
|
154
|
-
if (!fs.existsSync(reportPath)) {
|
|
155
|
-
console.log(chalk.yellow(`No report found for run ${runId}`));
|
|
156
|
-
console.log(chalk.gray(` Reports are extracted from agent output on completion`));
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
console.log(chalk.gray(`Run: ${runId}\n`));
|
|
160
|
-
console.log(fs.readFileSync(reportPath, 'utf-8'));
|
|
161
|
-
});
|
|
162
|
-
jobsCmd
|
|
163
|
-
.command('enable <name>')
|
|
164
|
-
.description('Enable a job')
|
|
165
|
-
.action((name) => {
|
|
166
|
-
try {
|
|
167
|
-
setJobEnabled(name, true);
|
|
168
|
-
console.log(chalk.green(`Job '${name}' enabled`));
|
|
169
|
-
if (isDaemonRunning()) {
|
|
170
|
-
signalDaemonReload();
|
|
171
|
-
console.log(chalk.gray('Daemon reloaded'));
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
catch (err) {
|
|
175
|
-
console.log(chalk.red(err.message));
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
jobsCmd
|
|
180
|
-
.command('disable <name>')
|
|
181
|
-
.description('Disable a job')
|
|
182
|
-
.action((name) => {
|
|
183
|
-
try {
|
|
184
|
-
setJobEnabled(name, false);
|
|
185
|
-
console.log(chalk.green(`Job '${name}' disabled`));
|
|
186
|
-
if (isDaemonRunning()) {
|
|
187
|
-
signalDaemonReload();
|
|
188
|
-
console.log(chalk.gray('Daemon reloaded'));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (err) {
|
|
192
|
-
console.log(chalk.red(err.message));
|
|
193
|
-
process.exit(1);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
//# sourceMappingURL=jobs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/commands/jobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC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C,CAAC;AACP,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/commands/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoCzC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4c7D"}
|
package/dist/commands/memory.js
DELETED
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import ora from 'ora';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import * as os from 'os';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import { select, checkbox } from '@inquirer/prompts';
|
|
7
|
-
import { AGENTS, ALL_AGENT_IDS, resolveAgentName, formatAgentError, } from '../lib/agents.js';
|
|
8
|
-
import { cloneRepo } from '../lib/git.js';
|
|
9
|
-
import { discoverInstructionsFromRepo, discoverMemoryFilesFromRepo, installInstructionsCentrally, uninstallInstructions, listInstalledInstructionsWithScope, instructionsExists, getInstructionsContent, listCentralMemory, } from '../lib/memory.js';
|
|
10
|
-
import { listInstalledVersions, getGlobalDefault, syncResourcesToVersion, promptAgentVersionSelection, getVersionHomePath, } from '../lib/versions.js';
|
|
11
|
-
import { recordVersionResources } from '../lib/state.js';
|
|
12
|
-
import { isPromptCancelled, formatPath } from './utils.js';
|
|
13
|
-
export function registerMemoryCommands(program) {
|
|
14
|
-
const memoryCmd = program
|
|
15
|
-
.command('memory')
|
|
16
|
-
.description('Manage agent memory files');
|
|
17
|
-
memoryCmd
|
|
18
|
-
.command('list [agent]')
|
|
19
|
-
.description('List installed memory files. Use agent@version for specific version, agent@default for default only.')
|
|
20
|
-
.option('-a, --agent <agent>', 'Filter by agent')
|
|
21
|
-
.action(async (agentArg, options) => {
|
|
22
|
-
const cwd = process.cwd();
|
|
23
|
-
// Parse agent input - handle agent@version syntax
|
|
24
|
-
const agentInput = agentArg || options.agent;
|
|
25
|
-
let agentId = null;
|
|
26
|
-
let requestedVersion = null;
|
|
27
|
-
if (agentInput) {
|
|
28
|
-
const parts = agentInput.split('@');
|
|
29
|
-
const agentName = parts[0];
|
|
30
|
-
requestedVersion = parts[1] || null;
|
|
31
|
-
agentId = resolveAgentName(agentName);
|
|
32
|
-
if (!agentId) {
|
|
33
|
-
console.log(chalk.red(formatAgentError(agentName)));
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Helper to render memory for a specific version
|
|
38
|
-
const renderVersionMemory = (agentId, version, isDefault, home) => {
|
|
39
|
-
const agent = AGENTS[agentId];
|
|
40
|
-
const installed = listInstalledInstructionsWithScope(agentId, cwd, { home });
|
|
41
|
-
const userInstr = installed.find((i) => i.scope === 'user');
|
|
42
|
-
const projectInstr = installed.find((i) => i.scope === 'project');
|
|
43
|
-
const hasUser = userInstr?.exists;
|
|
44
|
-
const hasProject = projectInstr?.exists;
|
|
45
|
-
const defaultLabel = isDefault ? ' default' : '';
|
|
46
|
-
const versionStr = chalk.gray(` (${version}${defaultLabel})`);
|
|
47
|
-
console.log(` ${chalk.bold(agent.name)}${versionStr}:`);
|
|
48
|
-
if (hasUser) {
|
|
49
|
-
console.log(` ${chalk.gray('User:')}`);
|
|
50
|
-
console.log(` ${chalk.cyan(agent.instructionsFile.padEnd(20))} ${chalk.gray(formatPath(userInstr.path, cwd))}`);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
console.log(` ${chalk.gray('User:')} ${chalk.gray('none')}`);
|
|
54
|
-
}
|
|
55
|
-
if (hasProject) {
|
|
56
|
-
console.log(` ${chalk.gray('Project:')}`);
|
|
57
|
-
console.log(` ${chalk.yellow(agent.instructionsFile.padEnd(20))} ${chalk.gray(formatPath(projectInstr.path, cwd))}`);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
console.log(` ${chalk.gray('Project:')} ${chalk.gray('none')}`);
|
|
61
|
-
}
|
|
62
|
-
console.log();
|
|
63
|
-
};
|
|
64
|
-
// Single agent specified - show versions based on requestedVersion
|
|
65
|
-
if (agentId) {
|
|
66
|
-
const agent = AGENTS[agentId];
|
|
67
|
-
console.log(chalk.bold(`Installed Memory for ${agent.name}\n`));
|
|
68
|
-
const installedVersions = listInstalledVersions(agentId);
|
|
69
|
-
const defaultVer = getGlobalDefault(agentId);
|
|
70
|
-
if (installedVersions.length === 0) {
|
|
71
|
-
// Not version-managed
|
|
72
|
-
const installed = listInstalledInstructionsWithScope(agentId, cwd);
|
|
73
|
-
const userInstr = installed.find((i) => i.scope === 'user');
|
|
74
|
-
const projectInstr = installed.find((i) => i.scope === 'project');
|
|
75
|
-
const hasUser = userInstr?.exists;
|
|
76
|
-
const hasProject = projectInstr?.exists;
|
|
77
|
-
console.log(` ${chalk.bold(agent.name)}:`);
|
|
78
|
-
if (hasUser) {
|
|
79
|
-
console.log(` ${chalk.gray('User:')}`);
|
|
80
|
-
console.log(` ${chalk.cyan(agent.instructionsFile.padEnd(20))} ${chalk.gray(formatPath(userInstr.path, cwd))}`);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
console.log(` ${chalk.gray('User:')} ${chalk.gray('none')}`);
|
|
84
|
-
}
|
|
85
|
-
if (hasProject) {
|
|
86
|
-
console.log(` ${chalk.gray('Project:')}`);
|
|
87
|
-
console.log(` ${chalk.yellow(agent.instructionsFile.padEnd(20))} ${chalk.gray(formatPath(projectInstr.path, cwd))}`);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
console.log(` ${chalk.gray('Project:')} ${chalk.gray('none')}`);
|
|
91
|
-
}
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
let versionsToShow;
|
|
95
|
-
if (requestedVersion === 'default') {
|
|
96
|
-
if (!defaultVer) {
|
|
97
|
-
console.log(chalk.yellow(` No default version set for ${agent.name}. Run: agents use ${agentId}@<version>`));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
versionsToShow = [defaultVer];
|
|
101
|
-
}
|
|
102
|
-
else if (requestedVersion) {
|
|
103
|
-
if (!installedVersions.includes(requestedVersion)) {
|
|
104
|
-
console.log(chalk.red(` Version ${requestedVersion} not installed for ${agent.name}.`));
|
|
105
|
-
console.log(chalk.gray(` Installed versions: ${installedVersions.join(', ')}`));
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
versionsToShow = [requestedVersion];
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
versionsToShow = [...installedVersions].sort((a, b) => {
|
|
112
|
-
if (a === defaultVer)
|
|
113
|
-
return -1;
|
|
114
|
-
if (b === defaultVer)
|
|
115
|
-
return 1;
|
|
116
|
-
return 0;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
for (const version of versionsToShow) {
|
|
120
|
-
const home = getVersionHomePath(agentId, version);
|
|
121
|
-
renderVersionMemory(agentId, version, version === defaultVer, home);
|
|
122
|
-
}
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
// No agent specified - show default version for each agent
|
|
126
|
-
console.log(chalk.bold('Installed Memory\n'));
|
|
127
|
-
for (const aid of ALL_AGENT_IDS) {
|
|
128
|
-
const agent = AGENTS[aid];
|
|
129
|
-
const installedVersions = listInstalledVersions(aid);
|
|
130
|
-
const defaultVer = getGlobalDefault(aid);
|
|
131
|
-
if (installedVersions.length > 0 && defaultVer) {
|
|
132
|
-
const home = getVersionHomePath(aid, defaultVer);
|
|
133
|
-
renderVersionMemory(aid, defaultVer, true, home);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
// Not version-managed or no default
|
|
137
|
-
const installed = listInstalledInstructionsWithScope(aid, cwd);
|
|
138
|
-
const userInstr = installed.find((i) => i.scope === 'user');
|
|
139
|
-
const projectInstr = installed.find((i) => i.scope === 'project');
|
|
140
|
-
const hasUser = userInstr?.exists;
|
|
141
|
-
const hasProject = projectInstr?.exists;
|
|
142
|
-
console.log(` ${chalk.bold(agent.name)}:`);
|
|
143
|
-
if (hasUser) {
|
|
144
|
-
console.log(` ${chalk.gray('User:')}`);
|
|
145
|
-
console.log(` ${chalk.cyan(agent.instructionsFile.padEnd(20))} ${chalk.gray(formatPath(userInstr.path, cwd))}`);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
console.log(` ${chalk.gray('User:')} ${chalk.gray('none')}`);
|
|
149
|
-
}
|
|
150
|
-
if (hasProject) {
|
|
151
|
-
console.log(` ${chalk.gray('Project:')}`);
|
|
152
|
-
console.log(` ${chalk.yellow(agent.instructionsFile.padEnd(20))} ${chalk.gray(formatPath(projectInstr.path, cwd))}`);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
console.log(` ${chalk.gray('Project:')} ${chalk.gray('none')}`);
|
|
156
|
-
}
|
|
157
|
-
console.log();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
memoryCmd
|
|
162
|
-
.command('add [source]')
|
|
163
|
-
.description('Install memory files from a repo or local path')
|
|
164
|
-
.option('-a, --agents <list>', 'Comma-separated agents to install to')
|
|
165
|
-
.option('-y, --yes', 'Skip prompts and use defaults')
|
|
166
|
-
.action(async (source, options) => {
|
|
167
|
-
try {
|
|
168
|
-
let memoryNames;
|
|
169
|
-
if (!source) {
|
|
170
|
-
// Interactive mode: pick from central storage
|
|
171
|
-
const centralMemory = listCentralMemory();
|
|
172
|
-
if (centralMemory.length === 0) {
|
|
173
|
-
console.log(chalk.yellow('No memory files in ~/.agents/memory/'));
|
|
174
|
-
console.log(chalk.gray('\nTo add memory files from a repo:'));
|
|
175
|
-
console.log(chalk.cyan(' agents memory add gh:user/repo'));
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const choices = centralMemory.map((name) => ({
|
|
179
|
-
value: name,
|
|
180
|
-
name,
|
|
181
|
-
}));
|
|
182
|
-
const selected = await checkbox({
|
|
183
|
-
message: 'Select memory files to install',
|
|
184
|
-
choices: [
|
|
185
|
-
{ value: '__all__', name: chalk.bold('Select All') },
|
|
186
|
-
...choices,
|
|
187
|
-
],
|
|
188
|
-
});
|
|
189
|
-
if (selected.length === 0) {
|
|
190
|
-
console.log(chalk.gray('No memory files selected.'));
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
memoryNames = selected.includes('__all__')
|
|
194
|
-
? centralMemory
|
|
195
|
-
: selected.filter((s) => s !== '__all__');
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// Source provided: fetch from repo or local path
|
|
199
|
-
const spinner = ora('Fetching memory files...').start();
|
|
200
|
-
const isGitRepo = source.startsWith('gh:') || source.startsWith('git:') ||
|
|
201
|
-
source.startsWith('ssh:') || source.startsWith('https://') ||
|
|
202
|
-
source.startsWith('http://');
|
|
203
|
-
let localPath;
|
|
204
|
-
if (isGitRepo) {
|
|
205
|
-
const result = await cloneRepo(source);
|
|
206
|
-
localPath = result.localPath;
|
|
207
|
-
spinner.succeed('Repository cloned');
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
localPath = source.startsWith('~')
|
|
211
|
-
? path.join(os.homedir(), source.slice(1))
|
|
212
|
-
: path.resolve(source);
|
|
213
|
-
if (!fs.existsSync(localPath)) {
|
|
214
|
-
spinner.fail(`Path not found: ${localPath}`);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
spinner.succeed('Using local path');
|
|
218
|
-
}
|
|
219
|
-
const agentInstructions = discoverInstructionsFromRepo(localPath);
|
|
220
|
-
const memoryFiles = discoverMemoryFilesFromRepo(localPath);
|
|
221
|
-
const totalFiles = agentInstructions.length + memoryFiles.length;
|
|
222
|
-
console.log(chalk.bold(`\nFound ${totalFiles} memory file(s):`));
|
|
223
|
-
if (totalFiles === 0) {
|
|
224
|
-
console.log(chalk.yellow('No memory files found'));
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
for (const instr of agentInstructions) {
|
|
228
|
-
console.log(` ${chalk.cyan(AGENTS[instr.agentId].instructionsFile)} (${AGENTS[instr.agentId].name})`);
|
|
229
|
-
}
|
|
230
|
-
for (const file of memoryFiles) {
|
|
231
|
-
console.log(` ${chalk.cyan(file)} (shared)`);
|
|
232
|
-
}
|
|
233
|
-
// Install to central storage first
|
|
234
|
-
const installSpinner = ora('Installing memory files to central storage...').start();
|
|
235
|
-
const centralResult = installInstructionsCentrally(localPath);
|
|
236
|
-
if (centralResult.errors.length > 0) {
|
|
237
|
-
installSpinner.stop();
|
|
238
|
-
for (const error of centralResult.errors) {
|
|
239
|
-
console.log(chalk.yellow(`\n Warning: ${error}`));
|
|
240
|
-
}
|
|
241
|
-
installSpinner.start();
|
|
242
|
-
}
|
|
243
|
-
installSpinner.succeed(`Installed ${centralResult.installed.length} memory files to ~/.agents/memory/`);
|
|
244
|
-
memoryNames = centralResult.installed.map((p) => path.basename(p));
|
|
245
|
-
}
|
|
246
|
-
// Get agent and version selection
|
|
247
|
-
let selectedAgents;
|
|
248
|
-
let versionSelections;
|
|
249
|
-
if (options.agents) {
|
|
250
|
-
selectedAgents = options.agents.split(',');
|
|
251
|
-
versionSelections = new Map();
|
|
252
|
-
for (const agentId of selectedAgents) {
|
|
253
|
-
const versions = listInstalledVersions(agentId);
|
|
254
|
-
if (versions.length > 0) {
|
|
255
|
-
const defaultVer = getGlobalDefault(agentId);
|
|
256
|
-
versionSelections.set(agentId, defaultVer ? [defaultVer] : [versions[versions.length - 1]]);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
const result = await promptAgentVersionSelection(ALL_AGENT_IDS, { skipPrompts: options.yes });
|
|
262
|
-
selectedAgents = result.selectedAgents;
|
|
263
|
-
versionSelections = result.versionSelections;
|
|
264
|
-
}
|
|
265
|
-
if (selectedAgents.length === 0) {
|
|
266
|
-
console.log(chalk.yellow('\nNo agents selected.'));
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
// Sync to selected versions
|
|
270
|
-
const syncSpinner = ora('Syncing to agent versions...').start();
|
|
271
|
-
let synced = 0;
|
|
272
|
-
for (const [agentId, versions] of versionSelections) {
|
|
273
|
-
for (const version of versions) {
|
|
274
|
-
syncResourcesToVersion(agentId, version);
|
|
275
|
-
recordVersionResources(agentId, version, 'memory', memoryNames);
|
|
276
|
-
synced++;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (synced > 0) {
|
|
280
|
-
syncSpinner.succeed(`Synced to ${synced} agent version(s)`);
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
syncSpinner.info('No version-managed agents to sync');
|
|
284
|
-
}
|
|
285
|
-
console.log(chalk.green('\nMemory files installed.'));
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
288
|
-
if (isPromptCancelled(err)) {
|
|
289
|
-
console.log(chalk.gray('\nCancelled'));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
console.error(chalk.red('Failed to add memory files'));
|
|
293
|
-
console.error(chalk.red(err.message));
|
|
294
|
-
process.exit(1);
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
memoryCmd
|
|
298
|
-
.command('view [agent]')
|
|
299
|
-
.description('Show memory content for an agent. Use agent@version for specific version.')
|
|
300
|
-
.option('-s, --scope <scope>', 'Scope: user or project', 'user')
|
|
301
|
-
.action(async (agentArg, options) => {
|
|
302
|
-
const cwd = process.cwd();
|
|
303
|
-
let agentId;
|
|
304
|
-
let requestedVersion = null;
|
|
305
|
-
if (agentArg) {
|
|
306
|
-
const parts = agentArg.split('@');
|
|
307
|
-
const agentName = parts[0];
|
|
308
|
-
requestedVersion = parts[1] || null;
|
|
309
|
-
agentId = resolveAgentName(agentName) || undefined;
|
|
310
|
-
if (!agentId) {
|
|
311
|
-
console.log(chalk.red(formatAgentError(agentName)));
|
|
312
|
-
process.exit(1);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
const choices = ALL_AGENT_IDS.filter((id) => instructionsExists(id, 'user', cwd) || instructionsExists(id, 'project', cwd));
|
|
317
|
-
if (choices.length === 0) {
|
|
318
|
-
console.log(chalk.yellow('No memory files found.'));
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
agentId = await select({
|
|
322
|
-
message: 'Select agent:',
|
|
323
|
-
choices: choices.map((id) => ({ name: AGENTS[id].name, value: id })),
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
const scope = (options?.scope || 'user');
|
|
327
|
-
// Helper to format and display content
|
|
328
|
-
const displayContent = async (content, title, memPath) => {
|
|
329
|
-
const { renderMarkdown } = await import('../lib/markdown.js');
|
|
330
|
-
console.log(chalk.bold(`\n${title}`));
|
|
331
|
-
console.log(chalk.gray(`Path: ${memPath}\n`));
|
|
332
|
-
const rendered = renderMarkdown(content);
|
|
333
|
-
const contentLines = content.split('\n');
|
|
334
|
-
// Pipe through less for scrolling if content is large
|
|
335
|
-
if (contentLines.length > 40) {
|
|
336
|
-
const { spawnSync } = await import('child_process');
|
|
337
|
-
const less = spawnSync('less', ['-R'], {
|
|
338
|
-
input: rendered,
|
|
339
|
-
stdio: ['pipe', 'inherit', 'inherit'],
|
|
340
|
-
});
|
|
341
|
-
// Fallback to direct output if less fails
|
|
342
|
-
if (less.status !== 0) {
|
|
343
|
-
console.log(rendered);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
console.log(rendered);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
// Handle version-specific view
|
|
351
|
-
if (requestedVersion && scope === 'user') {
|
|
352
|
-
const installedVersions = listInstalledVersions(agentId);
|
|
353
|
-
if (!installedVersions.includes(requestedVersion)) {
|
|
354
|
-
console.log(chalk.red(`Version ${requestedVersion} not installed for ${AGENTS[agentId].name}`));
|
|
355
|
-
console.log(chalk.gray(`Installed versions: ${installedVersions.join(', ') || 'none'}`));
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
const home = getVersionHomePath(agentId, requestedVersion);
|
|
359
|
-
const memPath = path.join(home, `.${agentId}`, AGENTS[agentId].instructionsFile);
|
|
360
|
-
if (!fs.existsSync(memPath)) {
|
|
361
|
-
console.log(chalk.yellow(`No user memory found for ${AGENTS[agentId].name}@${requestedVersion}`));
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
const content = fs.readFileSync(memPath, 'utf-8');
|
|
365
|
-
await displayContent(content, `${AGENTS[agentId].name}@${requestedVersion} Memory (${scope})`, memPath);
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const content = getInstructionsContent(agentId, scope, cwd);
|
|
369
|
-
if (!content) {
|
|
370
|
-
console.log(chalk.yellow(`No ${scope} memory found for ${AGENTS[agentId].name}`));
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
// Get the path for display
|
|
374
|
-
const installed = listInstalledInstructionsWithScope(agentId, cwd);
|
|
375
|
-
const instr = installed.find((i) => i.scope === scope);
|
|
376
|
-
const memPath = instr?.path || '';
|
|
377
|
-
await displayContent(content, `${AGENTS[agentId].name} Memory (${scope})`, memPath);
|
|
378
|
-
});
|
|
379
|
-
memoryCmd
|
|
380
|
-
.command('remove <agent>')
|
|
381
|
-
.description('Remove user memory for an agent. Use agent@version for specific version.')
|
|
382
|
-
.action((agentArg) => {
|
|
383
|
-
const parts = agentArg.split('@');
|
|
384
|
-
const agentName = parts[0];
|
|
385
|
-
const requestedVersion = parts[1] || null;
|
|
386
|
-
const agentId = resolveAgentName(agentName);
|
|
387
|
-
if (!agentId) {
|
|
388
|
-
console.log(chalk.red(formatAgentError(agentName)));
|
|
389
|
-
process.exit(1);
|
|
390
|
-
}
|
|
391
|
-
// Handle version-specific remove
|
|
392
|
-
if (requestedVersion) {
|
|
393
|
-
const installedVersions = listInstalledVersions(agentId);
|
|
394
|
-
if (!installedVersions.includes(requestedVersion)) {
|
|
395
|
-
console.log(chalk.red(`Version ${requestedVersion} not installed for ${AGENTS[agentId].name}`));
|
|
396
|
-
console.log(chalk.gray(`Installed versions: ${installedVersions.join(', ') || 'none'}`));
|
|
397
|
-
process.exit(1);
|
|
398
|
-
}
|
|
399
|
-
const home = getVersionHomePath(agentId, requestedVersion);
|
|
400
|
-
const agent = AGENTS[agentId];
|
|
401
|
-
const memPath = path.join(home, `.${agentId}`, agent.instructionsFile);
|
|
402
|
-
if (fs.existsSync(memPath)) {
|
|
403
|
-
fs.unlinkSync(memPath);
|
|
404
|
-
console.log(chalk.green(`Removed ${agent.instructionsFile} from ${agent.name}@${requestedVersion}`));
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
console.log(chalk.yellow(`No memory file found for ${agent.name}@${requestedVersion}`));
|
|
408
|
-
}
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
const result = uninstallInstructions(agentId);
|
|
412
|
-
if (result) {
|
|
413
|
-
console.log(chalk.green(`Removed ${AGENTS[agentId].instructionsFile}`));
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
console.log(chalk.yellow(`No memory file found for ${AGENTS[agentId].name}`));
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
// Deprecated alias for 'view'
|
|
420
|
-
memoryCmd
|
|
421
|
-
.command('show [agent]', { hidden: true })
|
|
422
|
-
.action(async (agentArg) => {
|
|
423
|
-
console.log(chalk.yellow('Deprecated: Use "agents memory view" instead of "agents memory show"\n'));
|
|
424
|
-
// Re-execute view command logic
|
|
425
|
-
await memoryCmd.commands.find((c) => c.name() === 'view')?.parseAsync(['view', ...(agentArg ? [agentArg] : [])], { from: 'user' });
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
//# sourceMappingURL=memory.js.map
|