@kodly.dev/kodly-cli 1.0.16
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/dist/api/client.js +96 -0
- package/dist/bin/kodly.js +35 -0
- package/dist/commands/auth.js +89 -0
- package/dist/commands/completion.js +90 -0
- package/dist/commands/docs.js +152 -0
- package/dist/commands/man.js +96 -0
- package/dist/commands/org.js +105 -0
- package/dist/commands/project.js +93 -0
- package/dist/commands/push.js +51 -0
- package/dist/commands/scaffold.js +236 -0
- package/dist/commands/status.js +52 -0
- package/dist/commands/task.js +155 -0
- package/dist/utils/changes.js +90 -0
- package/dist/utils/checkout.js +168 -0
- package/dist/utils/config.js +22 -0
- package/dist/utils/org.js +138 -0
- package/dist/utils/project.js +21 -0
- package/dist/utils/session.js +28 -0
- package/dist/utils/task.js +25 -0
- package/llm.txt +90 -0
- package/package.json +46 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getAuthToken } from '../utils/config.js';
|
|
3
|
+
import { resolveOrgSlug, shouldSkipOrgHeader } from '../utils/org.js';
|
|
4
|
+
const BASE_URL = 'https://api.app.kodly.dev/api/v1';
|
|
5
|
+
// const BASE_URL = 'http://localhost:8081/api/v1';
|
|
6
|
+
export const apiClient = axios.create({
|
|
7
|
+
baseURL: BASE_URL,
|
|
8
|
+
});
|
|
9
|
+
apiClient.interceptors.request.use(async (config) => {
|
|
10
|
+
const token = getAuthToken();
|
|
11
|
+
if (token) {
|
|
12
|
+
config.headers['X-AUTH-TOKEN'] = token;
|
|
13
|
+
}
|
|
14
|
+
const skipOrgHeader = config.headers?.['X-Skip-Org-Header'];
|
|
15
|
+
delete config.headers['X-Skip-Org-Header'];
|
|
16
|
+
if (token && !skipOrgHeader && !shouldSkipOrgHeader(config.url)) {
|
|
17
|
+
const orgSlug = await resolveOrgSlug();
|
|
18
|
+
if (orgSlug) {
|
|
19
|
+
config.headers['X-ORG-SLUG'] = orgSlug;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return config;
|
|
23
|
+
});
|
|
24
|
+
// Mock Data
|
|
25
|
+
const MOCK_TASKS = [
|
|
26
|
+
{
|
|
27
|
+
id: '1',
|
|
28
|
+
slug: 'login-flow-update',
|
|
29
|
+
title: 'Update Login Flow UI',
|
|
30
|
+
taskType: 'FRONTEND_USE_CASE',
|
|
31
|
+
taskStatus: 'IN_PROGRESS',
|
|
32
|
+
complexity: 3,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '2',
|
|
36
|
+
slug: 'user-schema-migration',
|
|
37
|
+
title: 'Migrate User Schema',
|
|
38
|
+
taskType: 'SCHEMA',
|
|
39
|
+
taskStatus: 'TODO',
|
|
40
|
+
complexity: 5,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
const MOCK_FILES = [
|
|
44
|
+
{
|
|
45
|
+
packageName: 'com.example.auth',
|
|
46
|
+
fileName: 'LoginComponent',
|
|
47
|
+
extension: 'tsx',
|
|
48
|
+
basePath: 'frontend/src/components',
|
|
49
|
+
content: 'export const Login = () => <div>Login</div>;',
|
|
50
|
+
isBase64Encoded: false,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
packageName: 'com.example.auth',
|
|
54
|
+
fileName: 'auth.spec',
|
|
55
|
+
extension: 'ts',
|
|
56
|
+
basePath: 'frontend/src/tests',
|
|
57
|
+
content: 'describe("Auth", () => {});',
|
|
58
|
+
isBase64Encoded: false,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
const MOCK_TASK_DETAIL = {
|
|
62
|
+
id: '1',
|
|
63
|
+
slug: 'login-flow-update',
|
|
64
|
+
title: 'Update Login Flow UI',
|
|
65
|
+
description: 'Update the login flow to use the new design system.',
|
|
66
|
+
taskType: 'FRONTEND_USE_CASE',
|
|
67
|
+
taskStatus: 'IN_PROGRESS',
|
|
68
|
+
complexity: 3,
|
|
69
|
+
};
|
|
70
|
+
// API Methods
|
|
71
|
+
export const Api = {
|
|
72
|
+
auth: {
|
|
73
|
+
login: (email, password) => apiClient.post('/auth/user/login', { email, password }),
|
|
74
|
+
logout: () => apiClient.post('/auth/user/logout'),
|
|
75
|
+
validateToken: () => apiClient.post('/auth/user/validate-token'),
|
|
76
|
+
},
|
|
77
|
+
projects: {
|
|
78
|
+
list: () => apiClient.get('/my-project/'),
|
|
79
|
+
get: (slug) => apiClient.get(`/project/${slug}`),
|
|
80
|
+
checkout: (projectSlug) => apiClient.post('/project/cli/checkout', null, { params: { projectSlug } }),
|
|
81
|
+
},
|
|
82
|
+
tasks: {
|
|
83
|
+
list: (projectSlug) => apiClient.get('/task/cli/list', { params: { projectSlug } }),
|
|
84
|
+
get: (slug) => apiClient.get(`/task/${slug}`),
|
|
85
|
+
create: (projectSlug, title) => apiClient.post('/task/cli/create', { projectSlug, title }),
|
|
86
|
+
checkout: (taskSlug) => apiClient.post('/task/cli/checkout', null, { params: { taskSlug } }),
|
|
87
|
+
push: (taskSlug, files) => apiClient.post('/task/cli/push-files', files, { params: { taskSlug } }),
|
|
88
|
+
},
|
|
89
|
+
docs: {
|
|
90
|
+
checkout: (projectSlug) => apiClient.post('/llmdocs/cli/checkout', null, { params: { projectSlug } }),
|
|
91
|
+
push: (projectSlug, files) => apiClient.post('/llmdocs/cli/push-files', files, { params: { projectSlug } }),
|
|
92
|
+
},
|
|
93
|
+
org: {
|
|
94
|
+
listMemberships: () => apiClient.get('/me/memberships', { headers: { 'X-Skip-Org-Header': '1' } }),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
|
|
9
|
+
import { authCommands } from '../commands/auth.js';
|
|
10
|
+
import { taskCommands } from '../commands/task.js';
|
|
11
|
+
import { pushCommands } from '../commands/push.js';
|
|
12
|
+
import { statusCommands } from '../commands/status.js';
|
|
13
|
+
import { manCommands } from '../commands/man.js';
|
|
14
|
+
import { completionCommands } from '../commands/completion.js';
|
|
15
|
+
import { projectCommands } from '../commands/project.js';
|
|
16
|
+
import { docsCommands } from '../commands/docs.js';
|
|
17
|
+
import { orgCommands } from '../commands/org.js';
|
|
18
|
+
import { scaffoldCommands, normalizeScaffoldArgv } from '../commands/scaffold.js';
|
|
19
|
+
const program = new Command();
|
|
20
|
+
program
|
|
21
|
+
.name('kodly')
|
|
22
|
+
.description('CLI Agent for Kodly Platform')
|
|
23
|
+
.version(packageJson.version);
|
|
24
|
+
// Register Commands
|
|
25
|
+
authCommands(program);
|
|
26
|
+
taskCommands(program);
|
|
27
|
+
pushCommands(program);
|
|
28
|
+
statusCommands(program);
|
|
29
|
+
manCommands(program);
|
|
30
|
+
completionCommands(program);
|
|
31
|
+
projectCommands(program);
|
|
32
|
+
docsCommands(program);
|
|
33
|
+
orgCommands(program);
|
|
34
|
+
scaffoldCommands(program);
|
|
35
|
+
program.parse(normalizeScaffoldArgv(process.argv));
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import { Api } from '../api/client.js';
|
|
5
|
+
import { setAuthToken, clearAuthToken, getAuthToken, clearOrgSlug } from '../utils/config.js';
|
|
6
|
+
import { clearMembershipsCache, ensureDefaultOrg, printActiveOrg } from '../utils/org.js';
|
|
7
|
+
export const authCommands = (program) => {
|
|
8
|
+
program
|
|
9
|
+
.command('login')
|
|
10
|
+
.description('Login to Kodly')
|
|
11
|
+
.action(async () => {
|
|
12
|
+
const answers = await inquirer.prompt([
|
|
13
|
+
{
|
|
14
|
+
type: 'input',
|
|
15
|
+
name: 'email',
|
|
16
|
+
message: 'Enter your email:',
|
|
17
|
+
validate: (input) => input.includes('@') || 'Please enter a valid email',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'password',
|
|
21
|
+
name: 'password',
|
|
22
|
+
message: 'Enter your password:',
|
|
23
|
+
mask: '*',
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
const spinner = ora('Logging in...').start();
|
|
27
|
+
try {
|
|
28
|
+
const response = await Api.auth.login(answers.email, answers.password);
|
|
29
|
+
// API returns RestResponse: { status, message, data: { token, data: UserDetailDto } }
|
|
30
|
+
const { token, data: user } = response.data.data;
|
|
31
|
+
setAuthToken(token);
|
|
32
|
+
clearMembershipsCache();
|
|
33
|
+
const org = await ensureDefaultOrg();
|
|
34
|
+
spinner.succeed(chalk.green(`Successfully logged in as ${user.email}`));
|
|
35
|
+
if (org) {
|
|
36
|
+
printActiveOrg(org);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
spinner.fail(chalk.red('Login failed: ' + (error.message || 'Unknown error')));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
program
|
|
44
|
+
.command('logout')
|
|
45
|
+
.description('Logout from Kodly')
|
|
46
|
+
.action(async () => {
|
|
47
|
+
const spinner = ora('Logging out...').start();
|
|
48
|
+
try {
|
|
49
|
+
await Api.auth.logout();
|
|
50
|
+
clearAuthToken();
|
|
51
|
+
clearOrgSlug();
|
|
52
|
+
clearMembershipsCache();
|
|
53
|
+
spinner.succeed(chalk.green('Successfully logged out'));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// Even if API fails, clear local token
|
|
57
|
+
clearAuthToken();
|
|
58
|
+
clearOrgSlug();
|
|
59
|
+
clearMembershipsCache();
|
|
60
|
+
spinner.succeed(chalk.green('Logged out (local session cleared)'));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
program
|
|
64
|
+
.command('whoami')
|
|
65
|
+
.description('Check current logged in user')
|
|
66
|
+
.action(async () => {
|
|
67
|
+
const token = getAuthToken();
|
|
68
|
+
if (!token) {
|
|
69
|
+
console.log(chalk.yellow('Not logged in.'));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const spinner = ora('Checking session...').start();
|
|
73
|
+
try {
|
|
74
|
+
const response = await Api.auth.validateToken();
|
|
75
|
+
spinner.stop();
|
|
76
|
+
// Response structure: RestResponse -> AuthResponseDto -> UserDetailDto
|
|
77
|
+
const user = response.data.data.data;
|
|
78
|
+
console.log(chalk.green(`Logged in as: ${user.name} (${user.email})`));
|
|
79
|
+
const org = await ensureDefaultOrg();
|
|
80
|
+
if (org) {
|
|
81
|
+
printActiveOrg(org);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
spinner.fail(chalk.red('Session invalid or expired. Please login again.'));
|
|
86
|
+
clearAuthToken();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export const completionCommands = (program) => {
|
|
2
|
+
program
|
|
3
|
+
.command('completion [shell]')
|
|
4
|
+
.description('Generate shell completion script (options: zsh, bash, fish)')
|
|
5
|
+
.action((shell = 'zsh') => {
|
|
6
|
+
let script = '';
|
|
7
|
+
if (shell === 'fish') {
|
|
8
|
+
script = `
|
|
9
|
+
###-begin-kodly-completion-###
|
|
10
|
+
#
|
|
11
|
+
# kodly command completion script for fish
|
|
12
|
+
#
|
|
13
|
+
# Installation: kodly completion fish > ~/.config/fish/completions/kodly.fish
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
complete -c kodly -f -n '__fish_use_subcommand' -a 'login logout whoami task push status man help completion project docs org scaffold'
|
|
17
|
+
complete -c kodly -f -n '__fish_seen_subcommand_from scaffold' -a 'init create list cache'
|
|
18
|
+
complete -c kodly -f -n '__fish_seen_subcommand_from cache' -a 'list clear'
|
|
19
|
+
complete -c kodly -f -n '__fish_seen_subcommand_from task' -a 'list checkout create'
|
|
20
|
+
complete -c kodly -f -n '__fish_seen_subcommand_from project' -a 'checkout list'
|
|
21
|
+
complete -c kodly -f -n '__fish_seen_subcommand_from docs' -a 'checkout push status'
|
|
22
|
+
complete -c kodly -f -n '__fish_seen_subcommand_from org' -a 'list current switch unset'
|
|
23
|
+
|
|
24
|
+
###-end-kodly-completion-###
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// Default to Zsh/Bash compatible
|
|
29
|
+
script = `
|
|
30
|
+
###-begin-kodly-completion-###
|
|
31
|
+
#
|
|
32
|
+
# kodly command completion script
|
|
33
|
+
#
|
|
34
|
+
# Installation: kodly completion >> ~/.zshrc (or ~/.bashrc)
|
|
35
|
+
#
|
|
36
|
+
|
|
37
|
+
_kodly_completion() {
|
|
38
|
+
local cur prev opts
|
|
39
|
+
COMPREPLY=()
|
|
40
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
41
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
42
|
+
opts="login logout whoami task push status man help completion project docs org scaffold"
|
|
43
|
+
|
|
44
|
+
case "\${prev}" in
|
|
45
|
+
kodly)
|
|
46
|
+
COMPREPLY=( $(compgen -W "\${opts}" -- \${cur}) )
|
|
47
|
+
return 0
|
|
48
|
+
;;
|
|
49
|
+
task)
|
|
50
|
+
local task_opts="list checkout create"
|
|
51
|
+
COMPREPLY=( $(compgen -W "\${task_opts}" -- \${cur}) )
|
|
52
|
+
return 0
|
|
53
|
+
;;
|
|
54
|
+
project)
|
|
55
|
+
local project_opts="checkout list"
|
|
56
|
+
COMPREPLY=( $(compgen -W "\${project_opts}" -- \${cur}) )
|
|
57
|
+
return 0
|
|
58
|
+
;;
|
|
59
|
+
docs)
|
|
60
|
+
local docs_opts="checkout push status"
|
|
61
|
+
COMPREPLY=( $(compgen -W "\${docs_opts}" -- \${cur}) )
|
|
62
|
+
return 0
|
|
63
|
+
;;
|
|
64
|
+
org)
|
|
65
|
+
local org_opts="list current switch unset"
|
|
66
|
+
COMPREPLY=( $(compgen -W "\${org_opts}" -- \${cur}) )
|
|
67
|
+
return 0
|
|
68
|
+
;;
|
|
69
|
+
scaffold)
|
|
70
|
+
local scaffold_opts="init create list cache"
|
|
71
|
+
COMPREPLY=( $(compgen -W "\${scaffold_opts}" -- \${cur}) )
|
|
72
|
+
return 0
|
|
73
|
+
;;
|
|
74
|
+
cache)
|
|
75
|
+
local cache_opts="list clear"
|
|
76
|
+
COMPREPLY=( $(compgen -W "\${cache_opts}" -- \${cur}) )
|
|
77
|
+
return 0
|
|
78
|
+
;;
|
|
79
|
+
*)
|
|
80
|
+
;;
|
|
81
|
+
esac
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
complete -F _kodly_completion kodly
|
|
85
|
+
###-end-kodly-completion-###
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
console.log(script.trim());
|
|
89
|
+
});
|
|
90
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { Api } from '../api/client.js';
|
|
6
|
+
import { requireAuthAndOrg } from '../utils/session.js';
|
|
7
|
+
import { printActiveOrg } from '../utils/org.js';
|
|
8
|
+
export const docsCommands = (program) => {
|
|
9
|
+
const docsCmd = program.command('docs').description('Manage knowledge documentation');
|
|
10
|
+
docsCmd
|
|
11
|
+
.command('checkout <project-slug> [path]')
|
|
12
|
+
.description('Checkout knowledge docs to local environment')
|
|
13
|
+
.action(async (projectSlug, pathArg) => {
|
|
14
|
+
const org = await requireAuthAndOrg();
|
|
15
|
+
if (!org)
|
|
16
|
+
return;
|
|
17
|
+
const spinner = ora(`Checking out docs for ${projectSlug}...`).start();
|
|
18
|
+
try {
|
|
19
|
+
printActiveOrg(org);
|
|
20
|
+
let docsDir = pathArg ? path.resolve(process.cwd(), pathArg) : path.resolve(process.cwd(), `${projectSlug}-docs`);
|
|
21
|
+
spinner.text = `Checking out docs files...`;
|
|
22
|
+
// Get Files
|
|
23
|
+
const checkoutRes = await Api.docs.checkout(projectSlug);
|
|
24
|
+
const files = checkoutRes.data.data; // Array of SyncCodeResultDto
|
|
25
|
+
const { syncCheckoutFiles } = await import('../utils/checkout.js');
|
|
26
|
+
const success = await syncCheckoutFiles(docsDir, files, 'docs', spinner);
|
|
27
|
+
if (success) {
|
|
28
|
+
// Write .kodly-docs.json safely after successful sync
|
|
29
|
+
fs.writeFileSync(path.join(docsDir, '.kodly-docs.json'), JSON.stringify({ projectSlug }, null, 2));
|
|
30
|
+
spinner.succeed(chalk.green(`Knowledge docs checked out to ${docsDir}`));
|
|
31
|
+
console.log(`Files synchronized: ${files.length}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error.response) {
|
|
36
|
+
console.error('\nAPI Error Status:', error.response.status);
|
|
37
|
+
console.error('API Error Data:', JSON.stringify(error.response.data, null, 2));
|
|
38
|
+
}
|
|
39
|
+
spinner.fail(chalk.red(`Checkout failed: ${error.message || 'Unknown error'}`));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
docsCmd
|
|
43
|
+
.command('push')
|
|
44
|
+
.description('Push local knowledge docs changes to Kodly')
|
|
45
|
+
.action(async () => {
|
|
46
|
+
const org = await requireAuthAndOrg();
|
|
47
|
+
if (!org)
|
|
48
|
+
return;
|
|
49
|
+
const cwd = process.cwd();
|
|
50
|
+
const docsConfigPath = path.join(cwd, '.kodly-docs.json');
|
|
51
|
+
if (!fs.existsSync(docsConfigPath)) {
|
|
52
|
+
console.log(chalk.red('Error: Not a known docs directory. Missing .kodly-docs.json'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let projectSlug;
|
|
56
|
+
try {
|
|
57
|
+
const config = JSON.parse(fs.readFileSync(docsConfigPath, 'utf-8'));
|
|
58
|
+
projectSlug = config.projectSlug;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.log(chalk.red('Error reading .kodly-docs.json'));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!projectSlug) {
|
|
65
|
+
console.log(chalk.red('Error: Invalid .kodly-docs.json'));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const spinner = ora(`Scanning files in docs for ${projectSlug}...`).start();
|
|
69
|
+
try {
|
|
70
|
+
const { getChangedFiles, updateChecksums } = await import('../utils/changes.js');
|
|
71
|
+
let { filesToPush, newChecksums } = await getChangedFiles(cwd);
|
|
72
|
+
// Filter out .kodly-docs.json
|
|
73
|
+
filesToPush = filesToPush.filter((f) => !f.filepath.endsWith('.kodly-docs.json'));
|
|
74
|
+
if (filesToPush.length === 0) {
|
|
75
|
+
spinner.succeed(chalk.green('No changes detected. Everything is up to date!'));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
spinner.text = `Pushing ${filesToPush.length} changed files...`;
|
|
79
|
+
printActiveOrg(org);
|
|
80
|
+
// Map to API DTO { filepath, content, base64Encoded, status }
|
|
81
|
+
const payload = filesToPush.map(f => ({
|
|
82
|
+
filepath: f.filepath,
|
|
83
|
+
content: f.content,
|
|
84
|
+
base64Encoded: f.base64Encoded,
|
|
85
|
+
status: f.status === 'TO_BE_DELETED' ? 'TO_BE_DELETED' : null
|
|
86
|
+
}));
|
|
87
|
+
await Api.docs.push(projectSlug, payload);
|
|
88
|
+
updateChecksums(cwd, newChecksums);
|
|
89
|
+
spinner.succeed(chalk.green('Successfully pushed docs changes to cloud!'));
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.response) {
|
|
93
|
+
console.error('API Error Status:', error.response.status);
|
|
94
|
+
console.error('API Error Data:', JSON.stringify(error.response.data, null, 2));
|
|
95
|
+
}
|
|
96
|
+
spinner.fail(chalk.red('Push failed: ' + (error.message || 'Unknown error')));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
docsCmd
|
|
100
|
+
.command('status')
|
|
101
|
+
.description('Show the knowledge docs working tree status')
|
|
102
|
+
.action(async () => {
|
|
103
|
+
const org = await requireAuthAndOrg();
|
|
104
|
+
if (!org)
|
|
105
|
+
return;
|
|
106
|
+
const cwd = process.cwd();
|
|
107
|
+
const docsConfigPath = path.join(cwd, '.kodly-docs.json');
|
|
108
|
+
if (!fs.existsSync(docsConfigPath)) {
|
|
109
|
+
console.log(chalk.red('Error: Not a known docs directory. Missing .kodly-docs.json'));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
let projectSlug;
|
|
113
|
+
try {
|
|
114
|
+
const config = JSON.parse(fs.readFileSync(docsConfigPath, 'utf-8'));
|
|
115
|
+
projectSlug = config.projectSlug;
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
console.log(chalk.red('Error reading .kodly-docs.json'));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const spinner = ora('Checking status...').start();
|
|
122
|
+
try {
|
|
123
|
+
const { getChangedFiles } = await import('../utils/changes.js');
|
|
124
|
+
let { filesToPush } = await getChangedFiles(cwd);
|
|
125
|
+
// Filter out .kodly-docs.json
|
|
126
|
+
filesToPush = filesToPush.filter((f) => !f.filepath.endsWith('.kodly-docs.json'));
|
|
127
|
+
spinner.stop();
|
|
128
|
+
printActiveOrg(org);
|
|
129
|
+
console.log(chalk.bold(`Docs for project: ${chalk.cyan(projectSlug)}\n`));
|
|
130
|
+
if (filesToPush.length === 0) {
|
|
131
|
+
console.log(chalk.green('nothing to commit, working tree clean'));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.log('Changes not pushed to cloud:');
|
|
135
|
+
console.log(` (use "kodly docs push" to update cloud)\n`);
|
|
136
|
+
filesToPush.forEach(file => {
|
|
137
|
+
let color = chalk.yellow;
|
|
138
|
+
if (file.status === 'NEW')
|
|
139
|
+
color = chalk.green;
|
|
140
|
+
if (file.status === 'TO_BE_DELETED')
|
|
141
|
+
color = chalk.red;
|
|
142
|
+
// file.filepath includes base path relative to cwd
|
|
143
|
+
console.log(`\t${color(file.status.toLowerCase() + ': ' + file.filepath)}`);
|
|
144
|
+
});
|
|
145
|
+
console.log(''); // Newline
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
spinner.fail(chalk.red('Status check failed: ' + (error.message || 'Unknown error')));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export const manCommands = (program) => {
|
|
3
|
+
program
|
|
4
|
+
.command('man')
|
|
5
|
+
.description('Show the user manual')
|
|
6
|
+
.action(() => {
|
|
7
|
+
console.log(chalk.bold.blue('\nKodly CLI - User Manual\n'));
|
|
8
|
+
console.log(chalk.bold('1. Authentication'));
|
|
9
|
+
console.log(' Before starting, you must log in to your Kodly account.');
|
|
10
|
+
console.log(chalk.cyan(' $ kodly login'));
|
|
11
|
+
console.log(' Follow the prompts to enter your email and password.');
|
|
12
|
+
console.log(' To check your status: ' + chalk.cyan('$ kodly whoami'));
|
|
13
|
+
console.log(' To log out: ' + chalk.cyan('$ kodly logout'));
|
|
14
|
+
console.log(chalk.bold('\n2. Organizations'));
|
|
15
|
+
console.log(' List organizations you belong to.');
|
|
16
|
+
console.log(chalk.cyan(' $ kodly org list'));
|
|
17
|
+
console.log(' Show the currently active organization.');
|
|
18
|
+
console.log(chalk.cyan(' $ kodly org current'));
|
|
19
|
+
console.log(' Switch to a different organization.');
|
|
20
|
+
console.log(chalk.cyan(' $ kodly org switch <org-slug>'));
|
|
21
|
+
console.log(' Clear the org override and use your default.');
|
|
22
|
+
console.log(chalk.cyan(' $ kodly org unset'));
|
|
23
|
+
console.log(chalk.bold('\n3. Discovering and Creating Tasks'));
|
|
24
|
+
console.log(' List all tasks assigned to you across your projects.');
|
|
25
|
+
console.log(chalk.cyan(' $ kodly task list'));
|
|
26
|
+
console.log(' Identify the task you want to work on and note its ' + chalk.yellow('slug') + '.');
|
|
27
|
+
console.log(' Create a new task for a specific project.');
|
|
28
|
+
console.log(chalk.cyan(' $ kodly task create <project-slug> <task-title>'));
|
|
29
|
+
console.log(chalk.bold('\n4. Starting Work'));
|
|
30
|
+
console.log(' Checkout a task to download its code and context.');
|
|
31
|
+
console.log(chalk.cyan(' $ kodly task checkout <task-slug> [path]'));
|
|
32
|
+
console.log(' Downloads task files to the specified path or ./<slug> by default.');
|
|
33
|
+
console.log(' It also creates a ' + chalk.yellow('.kodlyspec') + ' file with task details.');
|
|
34
|
+
console.log(chalk.bold('\n5. Working Locally'));
|
|
35
|
+
console.log(' Navigate into the task directory.');
|
|
36
|
+
console.log(chalk.cyan(' $ cd <task-slug>'));
|
|
37
|
+
console.log(' Make your code changes using your preferred editor.');
|
|
38
|
+
console.log(' You can check which files have been modified locally:');
|
|
39
|
+
console.log(chalk.cyan(' $ kodly status'));
|
|
40
|
+
console.log(chalk.bold('\n6. Syncing to Cloud'));
|
|
41
|
+
console.log(' Once you are happy with your changes, push them back to Kodly.');
|
|
42
|
+
console.log(chalk.cyan(' $ kodly push'));
|
|
43
|
+
console.log(' Only modified files will be uploaded.');
|
|
44
|
+
console.log(' Note: ' + chalk.yellow('.kodly/') + ' directory stores checksums for change detection.');
|
|
45
|
+
console.log(' Do not modify files inside ' + chalk.yellow('.kodly/') + ' manually.');
|
|
46
|
+
console.log(chalk.bold('\n7. Project Management'));
|
|
47
|
+
console.log(' List all projects you have access to.');
|
|
48
|
+
console.log(chalk.cyan(' $ kodly project list'));
|
|
49
|
+
console.log(' Checkout a full project codebase.');
|
|
50
|
+
console.log(chalk.cyan(' $ kodly project checkout <project-slug> [path]'));
|
|
51
|
+
console.log(' Downloads project files to the specified path or ./<slug> by default.');
|
|
52
|
+
console.log(chalk.bold('\n8. Knowledge Management'));
|
|
53
|
+
console.log(' Manage documentation and knowledge context.');
|
|
54
|
+
console.log(chalk.cyan(' $ kodly docs checkout <project-slug> [path]'));
|
|
55
|
+
console.log(' Checkout project documentation to local environment.');
|
|
56
|
+
console.log(chalk.cyan(' $ kodly docs push'));
|
|
57
|
+
console.log(' Push local documentation changes back to the project.');
|
|
58
|
+
console.log(chalk.cyan(' $ kodly docs status'));
|
|
59
|
+
console.log(' Show the working tree status of documentation.');
|
|
60
|
+
console.log(chalk.bold('\n9. Scaffolding Recipes'));
|
|
61
|
+
console.log(' Generate Spring Boot projects and apply deterministic recipes.');
|
|
62
|
+
console.log(' Does not require login — operates on local files and cached recipes.');
|
|
63
|
+
console.log(chalk.cyan(' $ kodly scaffold create -g <group> -n <name> -p <dir> [recipes...]'));
|
|
64
|
+
console.log(' Example: ' +
|
|
65
|
+
chalk.cyan('kodly scaffold create -g com.acme.orders -n orders-app -p ./orders-app sql@1.0.0 redis-cache@1.0.0'));
|
|
66
|
+
console.log(chalk.cyan(' $ kodly scaffold init --group <group> --name <name>'));
|
|
67
|
+
console.log(' Generate skeleton only (no recipes).');
|
|
68
|
+
console.log(chalk.cyan(' $ kodly scaffold <recipe-name>@<version>'));
|
|
69
|
+
console.log(' Example: ' + chalk.cyan('kodly scaffold redis-cache@1.0.2'));
|
|
70
|
+
console.log(' Options: ' +
|
|
71
|
+
chalk.yellow('--path') +
|
|
72
|
+
', ' +
|
|
73
|
+
chalk.yellow('--group') +
|
|
74
|
+
', ' +
|
|
75
|
+
chalk.yellow('--prefix') +
|
|
76
|
+
', ' +
|
|
77
|
+
chalk.yellow('--dry-run') +
|
|
78
|
+
', ' +
|
|
79
|
+
chalk.yellow('--recipe'));
|
|
80
|
+
console.log(' List locally cached recipes:');
|
|
81
|
+
console.log(chalk.cyan(' $ kodly scaffold list'));
|
|
82
|
+
console.log(' Manage recipe cache:');
|
|
83
|
+
console.log(chalk.cyan(' $ kodly scaffold cache list'));
|
|
84
|
+
console.log(chalk.cyan(' $ kodly scaffold cache clear [recipe@version]'));
|
|
85
|
+
console.log(chalk.bold('\n10. Shell Autocompletion'));
|
|
86
|
+
console.log(' Enable tab completion for kodly commands.');
|
|
87
|
+
console.log(' ' + chalk.bold('Bash / Zsh:'));
|
|
88
|
+
console.log(chalk.cyan(' $ kodly completion >> ~/.zshrc'));
|
|
89
|
+
console.log(' (or ~/.bashrc, then restart shell)');
|
|
90
|
+
console.log(' ' + chalk.bold('Fish:'));
|
|
91
|
+
console.log(chalk.cyan(' $ kodly completion fish > ~/.config/fish/completions/kodly.fish'));
|
|
92
|
+
console.log(chalk.bold('\nNeed more help?'));
|
|
93
|
+
console.log(' Run ' + chalk.cyan('kodly help [command]') + ' for specific command usage.');
|
|
94
|
+
console.log('\n For web version, visit: ' + chalk.underline.blue('https://kodly.dev') + '\n');
|
|
95
|
+
});
|
|
96
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { fetchMemberships, getMembershipSlug, getMembershipName, isDefaultMembership, findMembership, formatActiveOrg, resetToDefaultOrg, ensureDefaultOrg, resolveActiveOrg, } from '../utils/org.js';
|
|
4
|
+
import { setOrgSlug } from '../utils/config.js';
|
|
5
|
+
import { requireAuth } from '../utils/session.js';
|
|
6
|
+
export const orgCommands = (program) => {
|
|
7
|
+
const orgCmd = program.command('org').description('Manage organizations');
|
|
8
|
+
orgCmd
|
|
9
|
+
.command('list')
|
|
10
|
+
.description('List organizations you belong to')
|
|
11
|
+
.action(async () => {
|
|
12
|
+
if (!(await requireAuth()))
|
|
13
|
+
return;
|
|
14
|
+
const spinner = ora('Fetching organizations...').start();
|
|
15
|
+
try {
|
|
16
|
+
const memberships = await fetchMemberships(true);
|
|
17
|
+
const activeOrg = await resolveActiveOrg();
|
|
18
|
+
const activeSlug = activeOrg?.slug;
|
|
19
|
+
if (memberships.length === 0) {
|
|
20
|
+
spinner.fail(chalk.yellow('No organizations found.'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
spinner.stop();
|
|
24
|
+
console.log(chalk.bold('\nYour Organizations:\n'));
|
|
25
|
+
memberships.forEach((membership) => {
|
|
26
|
+
const slug = getMembershipSlug(membership);
|
|
27
|
+
const name = getMembershipName(membership);
|
|
28
|
+
const role = membership.role ? chalk.dim(` (${membership.role})`) : '';
|
|
29
|
+
const isActive = slug === activeSlug;
|
|
30
|
+
const defaultLabel = isDefaultMembership(membership) ? chalk.dim(' [default]') : '';
|
|
31
|
+
const currentLabel = isActive ? chalk.green(' *') : '';
|
|
32
|
+
console.log(` ${chalk.cyan(slug)} - ${name}${role}${defaultLabel}${currentLabel}`);
|
|
33
|
+
});
|
|
34
|
+
console.log('');
|
|
35
|
+
if (activeOrg) {
|
|
36
|
+
console.log(chalk.dim(`Active organization: ${formatActiveOrg(activeOrg)}`));
|
|
37
|
+
}
|
|
38
|
+
console.log('');
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
spinner.fail(chalk.red('Failed to list organizations: ' + (error.message || 'Unknown error')));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
orgCmd
|
|
45
|
+
.command('current')
|
|
46
|
+
.description('Show the currently active organization')
|
|
47
|
+
.action(async () => {
|
|
48
|
+
if (!(await requireAuth()))
|
|
49
|
+
return;
|
|
50
|
+
const spinner = ora('Fetching organization...').start();
|
|
51
|
+
try {
|
|
52
|
+
const org = await ensureDefaultOrg();
|
|
53
|
+
spinner.stop();
|
|
54
|
+
if (org) {
|
|
55
|
+
console.log(chalk.green(`Active organization: ${formatActiveOrg(org)}`));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log(chalk.yellow('No active organization found.'));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
spinner.fail(chalk.red('Failed to fetch organization: ' + (error.message || 'Unknown error')));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
orgCmd
|
|
66
|
+
.command('switch <slug>')
|
|
67
|
+
.description('Switch to a different organization')
|
|
68
|
+
.action(async (slug) => {
|
|
69
|
+
if (!(await requireAuth()))
|
|
70
|
+
return;
|
|
71
|
+
const spinner = ora('Verifying organization...').start();
|
|
72
|
+
try {
|
|
73
|
+
const memberships = await fetchMemberships(true);
|
|
74
|
+
const membership = findMembership(memberships, slug);
|
|
75
|
+
if (!membership) {
|
|
76
|
+
spinner.fail(chalk.red(`Organization "${slug}" not found. Run "kodly org list" to see available organizations.`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
setOrgSlug(slug);
|
|
80
|
+
spinner.succeed(chalk.green(`Switched to organization: ${getMembershipName(membership)} (${slug})`));
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
spinner.fail(chalk.red('Failed to switch organization: ' + (error.message || 'Unknown error')));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
orgCmd
|
|
87
|
+
.command('unset')
|
|
88
|
+
.description('Reset to your default organization')
|
|
89
|
+
.action(async () => {
|
|
90
|
+
if (!(await requireAuth()))
|
|
91
|
+
return;
|
|
92
|
+
const spinner = ora('Resetting to default organization...').start();
|
|
93
|
+
try {
|
|
94
|
+
const org = await resetToDefaultOrg();
|
|
95
|
+
if (!org) {
|
|
96
|
+
spinner.fail(chalk.yellow('No default organization found.'));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
spinner.succeed(chalk.green(`Using default organization: ${formatActiveOrg(org)}`));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
spinner.fail(chalk.red('Failed to reset organization: ' + (error.message || 'Unknown error')));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|