@agentled/cli
Version:
CLI for Agentled — manage workflows, apps, and knowledge from the command line. Zero context-window cost for AI agents.
79 lines • 3.79 kB
JavaScript
/**
* `agentled init [slug]` — bootstrap a local workspace folder for building,
* testing, and iterating on workflows without per-iteration credit cost.
*
* Creates agentled_<slug>/ in cwd with:
* - .agentled/workspace.json + cache/ (apps + models)
* - docs/ (SKILL.md + GOTCHAS.md)
* - examples/scaffolds/ (bundled JSON skeletons)
* - examples/live/, fixtures/, tests/, drafts/ (empty, agent fills these)
*
* See `agentled workspace sync` to refresh cached data.
* See `agentled workflows pull <id>` to import a live workflow.
* See `agentled fixture capture` + `agentled test` for the zero-credit
* iteration loop.
*/
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import { AgentledClient, resolveAuthContext } from '../client.js';
import { printOutput, printError } from '../utils/output.js';
import { createWorkspaceFolder, resolveWorkspaceMeta } from '../utils/workspace-folder.js';
export function registerInitCommand(program) {
program
.command('init')
.description('Scaffold a local agentled_<slug>/ workspace folder with docs, scaffolds, and cache. Foundation for the test/fixture iteration loop.')
.argument('[slug]', 'Override the workspace slug used for the folder name (defaults to remote workspace slug)')
.option('--force', 'Overwrite an existing folder', false)
.option('--format <fmt>', 'Output format', 'json')
.action(async (slugArg, opts) => {
try {
const client = new AgentledClient();
const [workspace, appsList, modelsList] = await Promise.allSettled([
client.getWorkspace(),
client.listApps(),
client.listModels(),
]);
if (workspace.status !== 'fulfilled') {
printError(`Failed to load workspace: ${workspace.reason?.message ?? 'unknown error'}`);
return;
}
const authContext = resolveAuthContext();
const meta = resolveWorkspaceMeta({
response: workspace.value,
authWorkspace: authContext.workspace,
slugOverride: slugArg,
apiBase: authContext.baseUrl,
});
const folderName = `agentled_${meta.slug}`;
const folderPath = resolve(process.cwd(), folderName);
if (existsSync(folderPath) && !opts.force) {
printError(`Folder already exists: ${folderPath}. Use --force to reinitialize, or "agentled workspace sync" to refresh the cache.`);
return;
}
createWorkspaceFolder(folderPath, meta, {
appsList: appsList.status === 'fulfilled' ? appsList.value : undefined,
modelsList: modelsList.status === 'fulfilled' ? modelsList.value : undefined,
});
printOutput({
folderPath,
folderName,
meta,
cached: {
apps: appsList.status === 'fulfilled',
models: modelsList.status === 'fulfilled',
},
nextSteps: [
`cd ${folderName}`,
'agentled workflows pull <workflowId> # import a workflow',
`agentled clients init ${meta.slug} --name "${meta.name}" # start the DFE client dossier`,
'agentled workflows lint examples/scaffolds/lead-scoring-kg.json',
'cat docs/GOTCHAS.md # read before building',
],
}, (opts.format ?? 'json'));
}
catch (e) {
printError(e instanceof Error ? e.message : String(e));
}
});
}
//# sourceMappingURL=init.js.map