@kodly.dev/kodly-cli 1.0.18 → 2.0.0

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.
Files changed (52) hide show
  1. package/README.md +131 -39
  2. package/dist/bin/kodly.js +23 -38
  3. package/dist/commands/auth.js +73 -78
  4. package/dist/commands/code.js +238 -0
  5. package/dist/commands/completion.js +33 -76
  6. package/dist/commands/delivery.js +218 -0
  7. package/dist/commands/harness.js +68 -0
  8. package/dist/commands/local-qa.js +96 -0
  9. package/dist/commands/mcp.js +399 -0
  10. package/dist/commands/misc.js +58 -0
  11. package/dist/commands/org.js +43 -100
  12. package/dist/commands/plan.js +157 -0
  13. package/dist/commands/project.js +88 -86
  14. package/dist/commands/review.js +237 -0
  15. package/dist/commands/scaffold.js +20 -230
  16. package/dist/commands/story-write.js +210 -0
  17. package/dist/commands/story.js +154 -0
  18. package/dist/core/api.js +89 -0
  19. package/dist/core/browser.js +17 -0
  20. package/dist/core/checkout.js +58 -0
  21. package/dist/core/config.js +36 -0
  22. package/dist/core/confirm.js +36 -0
  23. package/dist/core/context.js +64 -0
  24. package/dist/core/credentials.js +62 -0
  25. package/dist/core/device-login.js +44 -0
  26. package/dist/core/errors.js +32 -0
  27. package/dist/core/format.js +32 -0
  28. package/dist/core/git.js +29 -0
  29. package/dist/core/keychain.js +9 -0
  30. package/dist/core/memberships.js +10 -0
  31. package/dist/core/output.js +31 -0
  32. package/dist/core/prompt.js +47 -0
  33. package/dist/core/push-checks.js +60 -0
  34. package/dist/core/story-file.js +120 -0
  35. package/dist/core/story.js +34 -0
  36. package/dist/program.js +48 -0
  37. package/dist/utils/update-check.js +9 -9
  38. package/llm.txt +47 -83
  39. package/package.json +21 -11
  40. package/dist/api/client.js +0 -96
  41. package/dist/commands/docs.js +0 -152
  42. package/dist/commands/man.js +0 -93
  43. package/dist/commands/push.js +0 -51
  44. package/dist/commands/status.js +0 -52
  45. package/dist/commands/task.js +0 -155
  46. package/dist/utils/changes.js +0 -90
  47. package/dist/utils/checkout.js +0 -168
  48. package/dist/utils/config.js +0 -34
  49. package/dist/utils/org.js +0 -138
  50. package/dist/utils/project.js +0 -21
  51. package/dist/utils/session.js +0 -28
  52. package/dist/utils/task.js +0 -25
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # @kodly.dev/kodly-cli
2
2
 
3
- Official CLI for the [Kodly](https://kodly.dev) platform: authenticate, check out tasks/projects/docs, sync changes, and scaffold Spring Boot apps from recipes.
3
+ The CLI for the [Kodly](https://kodly.dev) 2.0 story workflow. Version 2 replaces the task commands
4
+ of version 1. It signs in with your browser, so it never asks for your password.
4
5
 
5
6
  ## Install
6
7
 
@@ -9,22 +10,105 @@ npm install -g @kodly.dev/kodly-cli
9
10
  kodly --version
10
11
  ```
11
12
 
12
- ## Quick start
13
+ Node.js 20 or later is necessary.
14
+
15
+ ## Sign in
13
16
 
14
17
  ```bash
15
- # Authenticate
16
- kodly login
18
+ kodly login # opens the browser; approve the code that the terminal shows
17
19
  kodly whoami
20
+ kodly org list
21
+ kodly org switch <slug>
22
+ kodly sessions # your CLI sessions; revoke them in Settings > Security of the web app
23
+ kodly logout # revokes the session of this device
24
+ ```
25
+
26
+ The token goes in the OS keychain. When no keychain is available, it goes in a file that only
27
+ you can read, and the CLI tells you where.
28
+
29
+ ## Work on stories
30
+
31
+ ```bash
32
+ kodly project list
33
+ kodly project use <slug>
34
+ kodly backlog --mine # --lane, --search, --closed, --limit
35
+ kodly story show KOD-12 # where the story is, and what blocks the next step
36
+ kodly story activity KOD-12
37
+ kodly story claim KOD-12 # own the current stage
38
+
39
+ kodly plan show KOD-12
40
+ kodly plan approve KOD-12 # also: kodly test-plan show|approve, kodly scope approve
41
+ kodly run build KOD-12 # a build in the Kodly cloud; --checks-only for the checks
42
+ kodly watch KOD-12 # follow the runs until they end
43
+ kodly checks show KOD-12 # also: kodly checks logs KOD-12 --follow
44
+ kodly qa send KOD-12 # QA always runs in the Kodly sandbox
45
+ kodly qa show KOD-12
46
+ kodly review request KOD-12
47
+ kodly review show KOD-12
48
+ kodly review comment KOD-12 -m "Check the null case" --file src/Login.java --line 42
49
+ kodly review approve KOD-12
50
+ kodly release KOD-12 --notes "Login is live"
51
+ kodly brief KOD-12
52
+ kodly usage
53
+ kodly doctor
54
+ ```
55
+
56
+ ## Work on the code of a story
18
57
 
19
- # Work on a task
20
- kodly task list
21
- kodly task checkout <task-slug>
22
- cd <task-slug>
23
- # …edit code…
58
+ ```bash
59
+ kodly checkout KOD-12 # one git repository for each codebase, under ./KOD-12/
60
+ cd KOD-12/web
61
+ # edit, test and commit with your own tools and agents
62
+ kodly push # sends your commits as a new build; Kodly runs the build checks in its sandbox
63
+ kodly watch KOD-12
64
+ kodly qa send KOD-12 # when the checks pass
65
+ kodly pull # bring a newer story build into the checkout
24
66
  kodly status
25
- kodly push
67
+ kodly diff
26
68
  ```
27
69
 
70
+ - Kodly writes the generated dataType and skill files into the checkout, and git ignores them.
71
+ - git asks Kodly for a one-hour token each time it needs one. No token goes into a file.
72
+ - `kodly push` keeps your commit messages. It refuses merge commits, symbolic links, files of more
73
+ than 8 MiB, files that look like secrets (`.env`, keys), generated files and `Kodly-` trailers.
74
+ - A local test never replaces Kodly QA: QA always runs in the Kodly sandbox.
75
+ - A story with no build can be checked out too. Kodly gives you its story base: main, as a hosted
76
+ first build would read it. Your first `kodly push` becomes the first build of the story.
77
+
78
+ ## Use your own agent (Claude Code and others)
79
+
80
+ ```bash
81
+ kodly harness install # registers "kodly mcp" with Claude Code (--tool other prints the setting)
82
+ kodly project local on # optional: Kodly starts no automatic hosted plan, test plan or build runs
83
+ kodly story local KOD-12 local # or for one story (local, hosted, or project to follow the project)
84
+
85
+ kodly plan draft KOD-12 # checks out the story and tells you the next step
86
+ claude "/mcp__kodly__plan KOD-12"
87
+ kodly plan approve KOD-12 # you approve the plan in the browser
88
+ kodly test-plan draft KOD-12 # the same for the test plan: /mcp__kodly__test_plan
89
+
90
+ kodly implement KOD-12 # then implement it
91
+ cd KOD-12
92
+ claude "/mcp__kodly__implement KOD-12"
93
+ ```
94
+
95
+ `kodly mcp` gives the agent these tools: `story_context`, `plan_context`, `test_plan_context`,
96
+ `save_plan`, `save_test_plan`, `story_status`, `read_plan`, `read_test_plan`, `build_checks`,
97
+ `push` and `report_usage`. A context holds the story, the plans, the Kodly agent instructions for
98
+ the phase and the local rules, and only the names of the secrets. A plan that the agent saves is a
99
+ draft: you approve it in the browser. Under the project's independent review policy, another
100
+ member must approve a plan that you drafted; project admins can choose single-person review.
101
+ An agent without MCP can save a draft with `kodly plan submit KOD-12 --file plan.json`.
102
+
103
+ The agent has no tool to approve, review, release or merge: those steps stay yours. Kodly stores
104
+ the model use that the agent reports, for your own view, and never bills it.
105
+
106
+ ## Approval in the browser
107
+
108
+ Some steps are a person's decision, for example a plan approval, a review approval or a
109
+ release. When the CLI makes such a call, Kodly asks you to approve it in the browser. The CLI
110
+ prints the link and waits. A local agent can use the CLI, but it cannot approve these steps.
111
+
28
112
  ## Scaffolding (no login required)
29
113
 
30
114
  Recipes come from [kodly-scaffold-recipies-java](https://github.com/kodly-dev/kodly-scaffold-recipies-java). Override with `KODLY_RECIPES_REPO_URL`.
@@ -32,6 +116,7 @@ Recipes come from [kodly-scaffold-recipies-java](https://github.com/kodly-dev/ko
32
116
  ```bash
33
117
  # List available recipes (live catalog from the recipes repo)
34
118
  kodly scaffold list
119
+ kodly scaffold list --json # [{"name","version"}] for scripts
35
120
 
36
121
  # Create a project and apply recipes in one step
37
122
  kodly scaffold create \
@@ -49,36 +134,43 @@ kodly scaffold redis-cache
49
134
 
50
135
  Unversioned skeletons and recipes use the latest stable published Git tag.
51
136
  `--skeleton-version <version>` and `recipe@<version>` pin a specific release.
52
- The API delegates to this same resolver. New tags affect new projects only.
53
-
54
- ## Common commands
55
-
56
- | Area | Commands |
57
- |------|----------|
58
- | Auth | `kodly login`, `kodly whoami`, `kodly logout` |
59
- | Org | `kodly org list`, `kodly org switch <slug>` |
60
- | Tasks | `kodly task list`, `kodly task checkout <slug>`, `kodly task create …` |
61
- | Projects | `kodly project list`, `kodly project checkout [slug]` |
62
- | Docs | `kodly docs checkout <project-slug>`, `kodly docs status`, `kodly docs push` |
63
- | Sync | `kodly status`, `kodly push` |
64
- | Scaffold | `kodly scaffold list`, `kodly scaffold create …`, `kodly scaffold <recipe>@<version>` |
65
- | Help | `kodly man`, `kodly completion [zsh\|bash\|fish]` |
66
-
67
- ## Notes
68
-
69
- - Do **not** edit files under `.kodly/` — they hold sync checksums and context.
70
- - The CLI warns when a newer version is published on npm. Update with:
71
- ```bash
72
- npm install -g @kodly.dev/kodly-cli@latest
73
- ```
74
- Disable with `KODLY_DISABLE_UPDATE_CHECK=1`.
75
137
 
76
- ## Programmatic scaffolding
138
+ The scaffold commands load no keychain module and need no login, so servers can run them. They
139
+ run the same code as the `kodly-scaffold` bin of `@kodly.dev/scaffolder`, which servers should
140
+ install in place of the full CLI. The test `test/scaffold-contract.test.ts` pins the command lines
141
+ and the `list` output of both bins. Change them only together with kodly-api.
142
+ The scaffolder accepts only the recipe tags in its qualified catalog. See the scaffolder README.
77
143
 
78
- The Spring Boot recipe engine is also available as [`@kodly.dev/scaffolder`](https://www.npmjs.com/package/@kodly.dev/scaffolder).
144
+ ## Options and environment
145
+
146
+ | Option or variable | Use |
147
+ |---|---|
148
+ | `--api <url>`, `KODLY_API_URL` | Another Kodly API (https, or http for localhost) |
149
+ | `--org <slug>`, `KODLY_ORG` | The organisation for one command |
150
+ | `--project <slug>`, `KODLY_PROJECT` | The project for one command |
151
+ | `--json` | JSON output for scripts and agents. An error is `{"error": {...}}` |
152
+ | `--no-browser`, `KODLY_NO_BROWSER=1` | Print links, but do not open the browser |
153
+ | `KODLY_TOKEN` | Use this token, and do not read the stored one |
154
+ | `KODLY_CREDENTIALS=file` | Keep the token in a file, not in the keychain |
155
+ | `KODLY_CONFIG_DIR` | The folder of the settings and credentials files |
156
+ | `KODLY_DISABLE_UPDATE_CHECK=1` | No check for a newer version on npm |
157
+
158
+ Inside a checkout, `.kodly/story.json` gives the API, the organisation and the project of every
159
+ command. A flag or a variable that names another value stops the command with exit code 2. Before
160
+ a command changes data in a project, the CLI writes the target on stderr, for example
161
+ `Kodly target: org <org>, project <project>, story <story>`.
79
162
 
80
- ## More
163
+ Exit codes: 0 done, 1 error, 2 usage error, 3 a login or step was denied or expired, 4 the state
164
+ changed on the server (do the step that the message names, then try again).
81
165
 
82
- - Full manual: `kodly man`
83
- - Agent reference (shipped with the package): `llm.txt`
84
- - Website: [kodly.dev](https://kodly.dev)
166
+ ## Shell completion
167
+
168
+ ```bash
169
+ kodly completion bash >> ~/.bashrc
170
+ kodly completion zsh >> ~/.zshrc
171
+ kodly completion fish > ~/.config/fish/completions/kodly.fish
172
+ ```
173
+
174
+ ## Programmatic scaffolding
175
+
176
+ The Spring Boot recipe engine is also available as [`@kodly.dev/scaffolder`](https://www.npmjs.com/package/@kodly.dev/scaffolder).
package/dist/bin/kodly.js CHANGED
@@ -1,39 +1,24 @@
1
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
- import { warnIfCliOutdated } from '../utils/update-check.js';
20
- const program = new Command();
21
- program
22
- .name('kodly')
23
- .description('CLI Agent for Kodly Platform')
24
- .version(packageJson.version);
25
- // Register Commands
26
- authCommands(program);
27
- taskCommands(program);
28
- pushCommands(program);
29
- statusCommands(program);
30
- manCommands(program);
31
- completionCommands(program);
32
- projectCommands(program);
33
- docsCommands(program);
34
- orgCommands(program);
35
- scaffoldCommands(program);
36
- program.hook('preAction', async () => {
37
- await warnIfCliOutdated(packageJson.version);
38
- });
39
- await program.parseAsync(normalizeScaffoldArgv(process.argv));
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { runScaffold } from '../commands/scaffold.js';
6
+ async function runProgram() {
7
+ const { createProgram } = await import('../program.js');
8
+ const { warnIfCliOutdated } = await import('../utils/update-check.js');
9
+ const here = path.dirname(fileURLToPath(import.meta.url));
10
+ const { version } = JSON.parse(fs.readFileSync(path.join(here, '../../package.json'), 'utf-8'));
11
+ const program = createProgram(version);
12
+ program.hook('preAction', async () => {
13
+ await warnIfCliOutdated(version);
14
+ });
15
+ await program.parseAsync(process.argv);
16
+ }
17
+ if (process.argv[2] === 'scaffold') {
18
+ // Servers run `kodly scaffold`. This path loads only the scaffolder: no update check, no
19
+ // keychain and no other command.
20
+ process.exitCode = await runScaffold(process.argv.slice(3));
21
+ }
22
+ else {
23
+ await runProgram();
24
+ }
@@ -1,89 +1,84 @@
1
- import inquirer from 'inquirer';
2
1
  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) => {
2
+ import { Api } from '../core/api.js';
3
+ import { openBrowser } from '../core/browser.js';
4
+ import { settings } from '../core/config.js';
5
+ import { buildContext } from '../core/context.js';
6
+ import { deleteToken, saveToken } from '../core/credentials.js';
7
+ import { startDeviceLogin, waitForDeviceToken } from '../core/device-login.js';
8
+ import { fetchMemberships } from '../core/memberships.js';
9
+ import { emit, run } from '../core/output.js';
10
+ export const authCommands = (program, cliVersion) => {
8
11
  program
9
12
  .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')));
13
+ .description('Sign in with your browser. The CLI never asks for your password.')
14
+ .action(run(async (_options, command) => {
15
+ const ctx = buildContext(command, cliVersion);
16
+ const code = await startDeviceLogin(ctx.api, cliVersion);
17
+ process.stderr.write(`Open ${chalk.cyan(code.verification_uri)} and check this code: ${chalk.bold(code.user_code)}\n`);
18
+ if (ctx.openBrowser)
19
+ openBrowser(code.verification_uri_complete);
20
+ process.stderr.write(chalk.dim('Waiting for the approval in the browser...\n'));
21
+ const token = await waitForDeviceToken(ctx.api, code);
22
+ const saved = saveToken(ctx.apiUrl, token.access_token);
23
+ if (saved.path) {
24
+ process.stderr.write(chalk.yellow(`The token is in ${saved.path}, readable only by you, because the OS keychain is not in use.\n`));
41
25
  }
42
- });
26
+ const signedIn = new Api({ ...ctx.api.session, token: token.access_token });
27
+ const memberships = await fetchMemberships(signedIn);
28
+ const savedOrg = settings().get('orgSlug');
29
+ if (memberships.length === 1 && savedOrg !== memberships[0].orgSlug)
30
+ settings().set('orgSlug', memberships[0].orgSlug);
31
+ const org = settings().get('orgSlug');
32
+ emit(ctx.json, { sessionId: token.session_id, expiresIn: token.expires_in, tokenStorage: saved.source, org: org ?? null }, () => {
33
+ console.log(chalk.green(`Signed in to ${ctx.apiUrl}.`));
34
+ if (org)
35
+ console.log(`Organisation: ${chalk.cyan(org)}`);
36
+ else if (memberships.length > 1)
37
+ console.log('Choose an organisation: kodly org list, then kodly org switch <slug>.');
38
+ });
39
+ }));
43
40
  program
44
41
  .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'));
42
+ .description('Sign out and revoke the CLI session of this device')
43
+ .action(run(async (_options, command) => {
44
+ const ctx = buildContext(command, cliVersion);
45
+ if (ctx.tokenSource && ctx.tokenSource !== 'env') {
46
+ await ctx.api.request('/auth/user/logout', { method: 'POST' }).catch(() => undefined);
47
+ deleteToken(ctx.apiUrl);
54
48
  }
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
- });
49
+ emit(ctx.json, { signedOut: true }, () => console.log('Signed out.'));
50
+ }));
63
51
  program
64
52
  .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);
53
+ .description('Show the signed-in user and the active organisation')
54
+ .action(run(async (_options, command) => {
55
+ const ctx = buildContext(command, cliVersion);
56
+ ctx.requireLogin();
57
+ const identity = await ctx.api.request('/auth/user/validate-token', { method: 'POST' });
58
+ const user = identity?.data ?? {};
59
+ const result = { name: user.name ?? null, email: user.email ?? null, api: ctx.apiUrl, org: ctx.api.session.orgSlug ?? null, tokenStorage: ctx.tokenSource };
60
+ emit(ctx.json, result, () => {
61
+ console.log(`${chalk.bold(user.name ?? '')} <${user.email ?? ''}>`);
62
+ console.log(chalk.dim(`API: ${ctx.apiUrl}`));
63
+ console.log(chalk.dim(`Organisation: ${result.org ?? 'none (kodly org switch <slug>)'}`));
64
+ });
65
+ }));
66
+ program
67
+ .command('sessions')
68
+ .description('List your CLI sessions. Revoke them in the web app.')
69
+ .action(run(async (_options, command) => {
70
+ const ctx = buildContext(command, cliVersion);
71
+ ctx.requireLogin();
72
+ const sessions = (await ctx.api.request('/me/cli-sessions')) ?? [];
73
+ emit(ctx.json, sessions, () => {
74
+ if (sessions.length === 0)
75
+ console.log('You have no CLI sessions.');
76
+ for (const session of sessions) {
77
+ const marker = session.current ? chalk.green(' (this device)') : '';
78
+ const used = session.lastUsedAt ? new Date(session.lastUsedAt).toLocaleString() : 'never';
79
+ console.log(`${session.host ?? session.clientName ?? session.id}${marker} ${chalk.dim(`last used ${used}`)}`);
82
80
  }
83
- }
84
- catch (error) {
85
- spinner.fail(chalk.red('Session invalid or expired. Please login again.'));
86
- clearAuthToken();
87
- }
88
- });
81
+ console.log(chalk.dim(`Revoke a session: ${ctx.webUrl}/settings/security`));
82
+ });
83
+ }));
89
84
  };