@csmedeiros/codemax 1.0.3 → 1.0.6
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/README.md +4 -20
- package/launcher.js +28 -0
- package/package.json +15 -121
- package/LICENSE +0 -21
- package/dist/commands/cursorRules.d.ts +0 -15
- package/dist/commands/cursorRules.js +0 -118
- package/dist/commands/slashCommands.d.ts +0 -36
- package/dist/commands/slashCommands.js +0 -236
- package/dist/configuration/configManager.d.ts +0 -32
- package/dist/configuration/configManager.js +0 -71
- package/dist/configuration/modelContextWindows.d.ts +0 -3
- package/dist/configuration/modelContextWindows.js +0 -13
- package/dist/conversation/agentGraph.d.ts +0 -203
- package/dist/conversation/agentGraph.js +0 -433
- package/dist/conversation/agentTurn.d.ts +0 -40
- package/dist/conversation/agentTurn.js +0 -252
- package/dist/conversation/chatHistory.d.ts +0 -24
- package/dist/conversation/chatHistory.js +0 -251
- package/dist/conversation/compactionUtils.d.ts +0 -17
- package/dist/conversation/compactionUtils.js +0 -57
- package/dist/conversation/prompts/planPrompt.d.ts +0 -1
- package/dist/conversation/prompts/planPrompt.js +0 -12
- package/dist/conversation/prompts/systemPrompt.d.ts +0 -29
- package/dist/conversation/prompts/systemPrompt.js +0 -149
- package/dist/entry/cli.d.ts +0 -2
- package/dist/entry/cli.js +0 -24
- package/dist/observability/langfuseTracing.d.ts +0 -5
- package/dist/observability/langfuseTracing.js +0 -76
- package/dist/shared/types.d.ts +0 -25
- package/dist/shared/types.js +0 -1
- package/dist/terminal/app.d.ts +0 -2
- package/dist/terminal/app.js +0 -1236
- package/dist/terminal/components.d.ts +0 -18
- package/dist/terminal/components.js +0 -43
- package/dist/terminal/markdown.d.ts +0 -4
- package/dist/terminal/markdown.js +0 -47
- package/dist/terminal/screens/compactionSettings.d.ts +0 -6
- package/dist/terminal/screens/compactionSettings.js +0 -66
- package/dist/terminal/screens/modelSettings.d.ts +0 -10
- package/dist/terminal/screens/modelSettings.js +0 -76
- package/dist/terminal/textField.d.ts +0 -7
- package/dist/terminal/textField.js +0 -136
- package/dist/terminal/theme.d.ts +0 -23
- package/dist/terminal/theme.js +0 -23
- package/dist/tooling/mcpConfig.d.ts +0 -40
- package/dist/tooling/mcpConfig.js +0 -49
- package/dist/tooling/planControlChannel.d.ts +0 -2
- package/dist/tooling/planControlChannel.js +0 -21
- package/dist/tooling/toolConfig.d.ts +0 -42
- package/dist/tooling/toolConfig.js +0 -138
- package/dist/tooling/toolUiCallback.d.ts +0 -21
- package/dist/tooling/toolUiCallback.js +0 -268
- package/dist/tooling/tools.d.ts +0 -216
- package/dist/tooling/tools.js +0 -614
package/README.md
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CodeMax
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Install
|
|
3
|
+
AI CLI coding agent. Install globally:
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## CLI
|
|
12
|
-
|
|
6
|
+
npm i -g @csmedeiros/codemax
|
|
13
7
|
```
|
|
14
|
-
$ core --help
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
$ core
|
|
18
|
-
|
|
19
|
-
Options
|
|
20
|
-
--name Your name
|
|
21
|
-
|
|
22
|
-
Examples
|
|
23
|
-
$ core --name=Jane
|
|
24
|
-
Hello, Jane
|
|
25
|
-
```
|
|
9
|
+
The correct platform binary is installed automatically.
|
package/launcher.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const {spawnSync} = require('node:child_process');
|
|
4
|
+
const {createRequire} = require('node:module');
|
|
5
|
+
|
|
6
|
+
// Package names use `windows`, but process.platform reports `win32`.
|
|
7
|
+
const platform = process.platform === 'win32' ? 'windows' : process.platform;
|
|
8
|
+
const target = `${platform}-${process.arch}`;
|
|
9
|
+
const pkg = `@csmedeiros/codemax-cli-${target}`;
|
|
10
|
+
const binName = process.platform === 'win32' ? 'codemax.exe' : 'codemax';
|
|
11
|
+
let binPath;
|
|
12
|
+
try {
|
|
13
|
+
const require2 = createRequire(__filename);
|
|
14
|
+
binPath = require2.resolve(`${pkg}/bin/${binName}`);
|
|
15
|
+
} catch {
|
|
16
|
+
console.error(
|
|
17
|
+
`[codemax] No binary for your platform (${target}). Expected optional dependency ${pkg}.`,
|
|
18
|
+
);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const res = spawnSync(binPath, process.argv.slice(2), {stdio: 'inherit'});
|
|
23
|
+
if (res.error) {
|
|
24
|
+
console.error(`[codemax] Failed to launch binary: ${res.error.message}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
process.exit(res.status ?? 0);
|
package/package.json
CHANGED
|
@@ -1,132 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csmedeiros/codemax",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "CodeMax - AI CLI Coding Agent",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
7
|
-
"access": "
|
|
7
|
+
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"codemax": "
|
|
11
|
-
},
|
|
12
|
-
"type": "module",
|
|
13
|
-
"engines": {
|
|
14
|
-
"node": ">=16"
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "tsc",
|
|
18
|
-
"dev": "tsx src/entry/cli.tsx",
|
|
19
|
-
"dev:watch": "tsc --watch",
|
|
20
|
-
"test": "prettier --check . && xo && NODE_OPTIONS=--experimental-vm-modules jest",
|
|
21
|
-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
10
|
+
"codemax": "launcher.js"
|
|
22
11
|
},
|
|
23
12
|
"files": [
|
|
24
|
-
"
|
|
13
|
+
"launcher.js",
|
|
14
|
+
"README.md"
|
|
25
15
|
],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"@langchain/langgraph": "^1.2.9",
|
|
29
|
-
"@langchain/langgraph-checkpoint-sqlite": "^1.0.1",
|
|
30
|
-
"@langchain/mcp-adapters": "^1.1.3",
|
|
31
|
-
"@langchain/openai": "^1.4.5",
|
|
32
|
-
"@langfuse/langchain": "^5.2.0",
|
|
33
|
-
"@langfuse/otel": "^5.2.0",
|
|
34
|
-
"@langfuse/tracing": "^5.3.0",
|
|
35
|
-
"@opentelemetry/api": "^1.9.1",
|
|
36
|
-
"@opentelemetry/core": "^2.7.1",
|
|
37
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.218.0",
|
|
38
|
-
"@opentelemetry/sdk-node": "^0.218.0",
|
|
39
|
-
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
40
|
-
"better-sqlite3": "^12.9.0",
|
|
41
|
-
"diff": "^9.0.0",
|
|
42
|
-
"dotenv": "^16.4.5",
|
|
43
|
-
"ink": "^4.1.0",
|
|
44
|
-
"ink-text-input": "^5.0.1",
|
|
45
|
-
"langchain": "^1.3.5",
|
|
46
|
-
"marked": "^12.0.2",
|
|
47
|
-
"marked-terminal": "^7.1.0",
|
|
48
|
-
"meow": "^11.0.0",
|
|
49
|
-
"minimatch": "^10.2.5",
|
|
50
|
-
"react": "^18.2.0",
|
|
51
|
-
"zod": "^3.25.0"
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@sindresorhus/tsconfig": "^3.0.1",
|
|
55
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
56
|
-
"@types/diff": "^8.0.0",
|
|
57
|
-
"@types/jest": "^30.0.0",
|
|
58
|
-
"@types/react": "^18.0.32",
|
|
59
|
-
"@vdemedes/prettier-config": "^2.0.1",
|
|
60
|
-
"chalk": "^5.2.0",
|
|
61
|
-
"eslint-config-xo-react": "^0.27.0",
|
|
62
|
-
"eslint-plugin-react": "^7.32.2",
|
|
63
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
64
|
-
"ink-testing-library": "^3.0.0",
|
|
65
|
-
"jest": "^30.4.2",
|
|
66
|
-
"jest-environment-node": "^30.4.1",
|
|
67
|
-
"node-pty": "^1.1.0",
|
|
68
|
-
"prettier": "^2.8.7",
|
|
69
|
-
"ts-jest": "^29.4.11",
|
|
70
|
-
"ts-node": "^10.9.1",
|
|
71
|
-
"tsx": "^4.22.3",
|
|
72
|
-
"typescript": "^5.0.3",
|
|
73
|
-
"xo": "^0.53.1"
|
|
74
|
-
},
|
|
75
|
-
"xo": {
|
|
76
|
-
"extends": "xo-react",
|
|
77
|
-
"prettier": true,
|
|
78
|
-
"ignores": [
|
|
79
|
-
"jest.config.js",
|
|
80
|
-
"jest.setup.js",
|
|
81
|
-
".tests/**"
|
|
82
|
-
],
|
|
83
|
-
"envs": [
|
|
84
|
-
"node",
|
|
85
|
-
"browser",
|
|
86
|
-
"jest"
|
|
87
|
-
],
|
|
88
|
-
"rules": {
|
|
89
|
-
"react/prop-types": "off",
|
|
90
|
-
"unicorn/expiring-todo-comments": "off"
|
|
91
|
-
},
|
|
92
|
-
"overrides": [
|
|
93
|
-
{
|
|
94
|
-
"files": [
|
|
95
|
-
"tests/**"
|
|
96
|
-
],
|
|
97
|
-
"envs": [
|
|
98
|
-
"jest",
|
|
99
|
-
"node"
|
|
100
|
-
],
|
|
101
|
-
"rules": {
|
|
102
|
-
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
103
|
-
"@typescript-eslint/no-unsafe-call": "off",
|
|
104
|
-
"@typescript-eslint/no-unsafe-return": "off",
|
|
105
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
106
|
-
"@typescript-eslint/ban-types": "off",
|
|
107
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
108
|
-
"@typescript-eslint/no-extraneous-class": "off",
|
|
109
|
-
"@typescript-eslint/naming-convention": "off",
|
|
110
|
-
"@typescript-eslint/padding-line-between-statements": "off",
|
|
111
|
-
"import/no-unassigned-import": "off",
|
|
112
|
-
"n/file-extension-in-import": "off",
|
|
113
|
-
"no-constructor-return": "off",
|
|
114
|
-
"unicorn/expiring-todo-comments": "off",
|
|
115
|
-
"unicorn/filename-case": "off",
|
|
116
|
-
"unicorn/no-zero-fractions": "off",
|
|
117
|
-
"unicorn/prefer-code-point": "off",
|
|
118
|
-
"unicorn/prevent-abbreviations": "off",
|
|
119
|
-
"capitalized-comments": "off",
|
|
120
|
-
"no-promise-executor-return": "off",
|
|
121
|
-
"react/prefer-read-only-props": "off"
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
]
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepublishOnly": "node ../../scripts/check-tarball.cjs wrapper"
|
|
125
18
|
},
|
|
126
|
-
"
|
|
127
|
-
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
19
|
+
"optionalDependencies": {
|
|
20
|
+
"@csmedeiros/codemax-cli-darwin-arm64": "1.0.6",
|
|
21
|
+
"@csmedeiros/codemax-cli-darwin-x64": "1.0.6",
|
|
22
|
+
"@csmedeiros/codemax-cli-linux-x64": "1.0.6",
|
|
23
|
+
"@csmedeiros/codemax-cli-linux-arm64": "1.0.6",
|
|
24
|
+
"@csmedeiros/codemax-cli-windows-x64": "1.0.6"
|
|
131
25
|
}
|
|
132
|
-
}
|
|
26
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 LangChain
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
-
export type CursorRule = {
|
|
3
|
-
description: string;
|
|
4
|
-
alwaysApply: boolean;
|
|
5
|
-
globs: string[];
|
|
6
|
-
content: string;
|
|
7
|
-
filename: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function loadWorkspaceRules(cwd: string): CursorRule[];
|
|
10
|
-
export declare function loadCursorRules(cwd: string): CursorRule[];
|
|
11
|
-
export declare function matchRules(rules: CursorRule[], messages: BaseMessage[]): CursorRule[];
|
|
12
|
-
export declare function importCursorRules(cwd: string): {
|
|
13
|
-
imported: string[];
|
|
14
|
-
skipped: string[];
|
|
15
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { minimatch } from 'minimatch';
|
|
4
|
-
function parseFrontmatter(raw) {
|
|
5
|
-
const lines = raw.split('\n');
|
|
6
|
-
if (lines[0]?.trim() !== '---') {
|
|
7
|
-
return { frontmatter: {}, content: raw };
|
|
8
|
-
}
|
|
9
|
-
const frontmatter = {};
|
|
10
|
-
let closingIdx = -1;
|
|
11
|
-
for (let i = 1; i < lines.length; i++) {
|
|
12
|
-
if (lines[i]?.trim() === '---') {
|
|
13
|
-
closingIdx = i;
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
const match = /^([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/.exec(lines[i] ?? '');
|
|
17
|
-
if (match?.[1] && match[2] !== undefined) {
|
|
18
|
-
frontmatter[match[1].toLowerCase()] = match[2].trim();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const content = closingIdx === -1
|
|
22
|
-
? raw
|
|
23
|
-
: lines
|
|
24
|
-
.slice(closingIdx + 1)
|
|
25
|
-
.join('\n')
|
|
26
|
-
.trimStart();
|
|
27
|
-
return { frontmatter, content };
|
|
28
|
-
}
|
|
29
|
-
function loadRulesFromDir(rulesDir, rootDir) {
|
|
30
|
-
const root = rootDir ?? rulesDir;
|
|
31
|
-
if (!fs.existsSync(rulesDir))
|
|
32
|
-
return [];
|
|
33
|
-
let entries;
|
|
34
|
-
try {
|
|
35
|
-
entries = fs.readdirSync(rulesDir, { withFileTypes: true });
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
const rules = [];
|
|
41
|
-
for (const entry of entries) {
|
|
42
|
-
if (entry.isDirectory()) {
|
|
43
|
-
rules.push(...loadRulesFromDir(path.join(rulesDir, entry.name), root));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (!entry.isFile())
|
|
47
|
-
continue;
|
|
48
|
-
if (!entry.name.endsWith('.md') && !entry.name.endsWith('.mdc'))
|
|
49
|
-
continue;
|
|
50
|
-
const filePath = path.join(rulesDir, entry.name);
|
|
51
|
-
let raw;
|
|
52
|
-
try {
|
|
53
|
-
raw = fs.readFileSync(filePath, 'utf8');
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const { frontmatter, content } = parseFrontmatter(raw);
|
|
59
|
-
const globsRaw = frontmatter['globs'] ?? '';
|
|
60
|
-
const globs = globsRaw
|
|
61
|
-
? globsRaw
|
|
62
|
-
.split(',')
|
|
63
|
-
.map(g => g.trim())
|
|
64
|
-
.filter(Boolean)
|
|
65
|
-
: [];
|
|
66
|
-
rules.push({
|
|
67
|
-
description: frontmatter['description'] ?? entry.name,
|
|
68
|
-
alwaysApply: frontmatter['alwaysapply'] === 'true',
|
|
69
|
-
globs,
|
|
70
|
-
content,
|
|
71
|
-
filename: path.relative(root, filePath),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return rules;
|
|
75
|
-
}
|
|
76
|
-
export function loadWorkspaceRules(cwd) {
|
|
77
|
-
return loadRulesFromDir(path.join(cwd, '.codemax', 'rules'));
|
|
78
|
-
}
|
|
79
|
-
export function loadCursorRules(cwd) {
|
|
80
|
-
return loadRulesFromDir(path.join(cwd, '.cursor', 'rules'));
|
|
81
|
-
}
|
|
82
|
-
export function matchRules(rules, messages) {
|
|
83
|
-
const allText = messages
|
|
84
|
-
.map(m => typeof m.content === 'string' ? m.content : JSON.stringify(m.content))
|
|
85
|
-
.join('\n');
|
|
86
|
-
return rules.filter(rule => {
|
|
87
|
-
if (rule.alwaysApply)
|
|
88
|
-
return true;
|
|
89
|
-
if (rule.globs.length === 0)
|
|
90
|
-
return false;
|
|
91
|
-
return rule.globs.some(glob => {
|
|
92
|
-
const tokens = allText.match(/[\w./\\-]+/g) ?? [];
|
|
93
|
-
return tokens.some(token => minimatch(token, glob, { matchBase: true }));
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
export function importCursorRules(cwd) {
|
|
98
|
-
const sourceDir = path.join(cwd, '.cursor', 'rules');
|
|
99
|
-
const destDir = path.join(cwd, '.codemax', 'rules');
|
|
100
|
-
const rules = loadCursorRules(cwd);
|
|
101
|
-
if (rules.length === 0)
|
|
102
|
-
return { imported: [], skipped: [] };
|
|
103
|
-
const imported = [];
|
|
104
|
-
const skipped = [];
|
|
105
|
-
for (const rule of rules) {
|
|
106
|
-
const src = path.join(sourceDir, rule.filename);
|
|
107
|
-
const dest = path.join(destDir, rule.filename);
|
|
108
|
-
try {
|
|
109
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
110
|
-
fs.copyFileSync(src, dest);
|
|
111
|
-
imported.push(rule.filename);
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
skipped.push(rule.filename);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return { imported, skipped };
|
|
118
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export type CliCommand = {
|
|
2
|
-
name: string;
|
|
3
|
-
description: string;
|
|
4
|
-
};
|
|
5
|
-
export declare const CLI_COMMANDS: readonly CliCommand[];
|
|
6
|
-
export type CommandContext = {
|
|
7
|
-
threadId: string;
|
|
8
|
-
sessionId: string;
|
|
9
|
-
renderMarkdown: boolean;
|
|
10
|
-
screen: 'chat' | 'model' | 'compaction';
|
|
11
|
-
};
|
|
12
|
-
export type CommandResult = {
|
|
13
|
-
handled: boolean;
|
|
14
|
-
shouldExit?: boolean;
|
|
15
|
-
systemMessage?: string;
|
|
16
|
-
clearTranscript?: boolean;
|
|
17
|
-
nextState?: Partial<CommandContext>;
|
|
18
|
-
activateSkill?: string;
|
|
19
|
-
prompt?: string;
|
|
20
|
-
openMcpModal?: boolean;
|
|
21
|
-
openChatsModal?: boolean;
|
|
22
|
-
forceCompact?: boolean;
|
|
23
|
-
};
|
|
24
|
-
export type Skill = {
|
|
25
|
-
name: string;
|
|
26
|
-
description: string;
|
|
27
|
-
content: string;
|
|
28
|
-
};
|
|
29
|
-
export declare function loadProjectSkills(cwd: string): Skill[];
|
|
30
|
-
export declare function getSkillSuggestions(line: string, skills: Array<{
|
|
31
|
-
name: string;
|
|
32
|
-
description: string;
|
|
33
|
-
}>): readonly CliCommand[];
|
|
34
|
-
export declare function getCommandSuggestions(line: string): readonly CliCommand[];
|
|
35
|
-
export declare function formatCommandHelp(): string;
|
|
36
|
-
export declare function executeSlashCommand(line: string, state: CommandContext, skills?: Skill[]): CommandResult;
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { createCodemaxSessionId } from '../observability/langfuseTracing.js';
|
|
5
|
-
import { updateConfig } from '../configuration/configManager.js';
|
|
6
|
-
import { importCursorRules } from './cursorRules.js';
|
|
7
|
-
export const CLI_COMMANDS = [
|
|
8
|
-
{ name: 'help', description: 'Show help' },
|
|
9
|
-
{ name: 'quit', description: 'Exit' },
|
|
10
|
-
{ name: 'clear', description: 'Clear terminal and start new session' },
|
|
11
|
-
{ name: 'thread', description: 'Set thread id' },
|
|
12
|
-
{ name: 'markdown', description: 'Toggle Markdown rendering' },
|
|
13
|
-
{ name: 'md', description: 'Toggle Markdown rendering' },
|
|
14
|
-
{ name: 'model', description: 'Show current model info' },
|
|
15
|
-
{ name: 'chats', description: 'Browse previous conversations' },
|
|
16
|
-
{
|
|
17
|
-
name: 'import-cursor-rules',
|
|
18
|
-
description: 'Import rules from .cursor/rules/ into .codemax/rules/',
|
|
19
|
-
},
|
|
20
|
-
{ name: 'mcp', description: 'Manage MCP servers' },
|
|
21
|
-
{ name: 'compact', description: 'Compact conversation context now' },
|
|
22
|
-
{
|
|
23
|
-
name: 'compaction_threshold',
|
|
24
|
-
description: 'Set context compaction threshold (0–100% in 10% steps)',
|
|
25
|
-
},
|
|
26
|
-
];
|
|
27
|
-
function loadSkillsFromDir(skillsDir) {
|
|
28
|
-
if (!fs.existsSync(skillsDir))
|
|
29
|
-
return [];
|
|
30
|
-
let entries;
|
|
31
|
-
try {
|
|
32
|
-
entries = fs.readdirSync(skillsDir, { withFileTypes: true });
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const skills = [];
|
|
38
|
-
for (const entry of entries) {
|
|
39
|
-
if (!entry.isDirectory())
|
|
40
|
-
continue;
|
|
41
|
-
const skillFile = path.join(skillsDir, entry.name, 'SKILL.md');
|
|
42
|
-
if (!fs.existsSync(skillFile))
|
|
43
|
-
continue;
|
|
44
|
-
let raw;
|
|
45
|
-
try {
|
|
46
|
-
raw = fs.readFileSync(skillFile, 'utf8');
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const lines = raw.split('\n');
|
|
52
|
-
const frontmatter = {};
|
|
53
|
-
let contentStart = 0;
|
|
54
|
-
for (let i = 0; i < lines.length; i++) {
|
|
55
|
-
const line = lines[i];
|
|
56
|
-
const match = /^([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/.exec(line ?? '');
|
|
57
|
-
if (match?.[1] !== undefined && match?.[2] !== undefined) {
|
|
58
|
-
frontmatter[match[1].toLowerCase()] = match[2].trim();
|
|
59
|
-
contentStart = i + 1;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
contentStart = i;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const content = lines.slice(contentStart).join('\n').trimStart();
|
|
67
|
-
skills.push({
|
|
68
|
-
name: entry.name,
|
|
69
|
-
description: frontmatter['description'] ?? '',
|
|
70
|
-
content,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return skills;
|
|
74
|
-
}
|
|
75
|
-
export function loadProjectSkills(cwd) {
|
|
76
|
-
const globalDir = path.join(os.homedir(), '.codemax', 'skills');
|
|
77
|
-
const projectDir = path.join(cwd, '.codemax', 'skills');
|
|
78
|
-
const globalSkills = loadSkillsFromDir(globalDir);
|
|
79
|
-
const projectSkills = loadSkillsFromDir(projectDir);
|
|
80
|
-
const merged = new Map();
|
|
81
|
-
for (const s of globalSkills)
|
|
82
|
-
merged.set(s.name, s);
|
|
83
|
-
for (const s of projectSkills)
|
|
84
|
-
merged.set(s.name, s);
|
|
85
|
-
return [...merged.values()];
|
|
86
|
-
}
|
|
87
|
-
export function getSkillSuggestions(line, skills) {
|
|
88
|
-
const trimmed = line.trimStart();
|
|
89
|
-
if (!trimmed.startsWith('/'))
|
|
90
|
-
return [];
|
|
91
|
-
const query = trimmed.slice(1).trim().toLowerCase();
|
|
92
|
-
return skills
|
|
93
|
-
.filter(skill => skill.name.toLowerCase().startsWith(query))
|
|
94
|
-
.map(skill => ({ name: skill.name, description: skill.description }))
|
|
95
|
-
.slice(0, 5);
|
|
96
|
-
}
|
|
97
|
-
export function getCommandSuggestions(line) {
|
|
98
|
-
const trimmed = line.trimStart();
|
|
99
|
-
if (!trimmed.startsWith('/'))
|
|
100
|
-
return [];
|
|
101
|
-
const query = trimmed.slice(1).trim().toLowerCase();
|
|
102
|
-
const matches = CLI_COMMANDS.filter(command => command.name.toLowerCase().startsWith(query));
|
|
103
|
-
const deduped = Array.from(new Map(matches.map(command => [command.name, command])).values());
|
|
104
|
-
return deduped.slice(0, 5);
|
|
105
|
-
}
|
|
106
|
-
export function formatCommandHelp() {
|
|
107
|
-
return [
|
|
108
|
-
'',
|
|
109
|
-
'CodeMax interactive CLI',
|
|
110
|
-
'',
|
|
111
|
-
'Commands:',
|
|
112
|
-
' /help Show this help',
|
|
113
|
-
' /quit Exit',
|
|
114
|
-
' /clear Clear terminal and start new session',
|
|
115
|
-
' /thread <id> Set thread id',
|
|
116
|
-
' /markdown on|off Toggle Markdown rendering',
|
|
117
|
-
' /model Show current model info',
|
|
118
|
-
'',
|
|
119
|
-
].join('\n');
|
|
120
|
-
}
|
|
121
|
-
export function executeSlashCommand(line, state, skills = []) {
|
|
122
|
-
const trimmed = line.trim();
|
|
123
|
-
if (!trimmed.startsWith('/'))
|
|
124
|
-
return { handled: false };
|
|
125
|
-
const [cmdRaw, ...rest] = trimmed.slice(1).split(/\s+/);
|
|
126
|
-
const cmd = (cmdRaw || '').toLowerCase();
|
|
127
|
-
const arg = rest.join(' ').trim();
|
|
128
|
-
if (cmd === 'help') {
|
|
129
|
-
return { handled: true, systemMessage: formatCommandHelp() };
|
|
130
|
-
}
|
|
131
|
-
if (cmd === 'quit') {
|
|
132
|
-
return { handled: true, shouldExit: true };
|
|
133
|
-
}
|
|
134
|
-
if (cmd === 'clear') {
|
|
135
|
-
const threadId = createCodemaxSessionId('thread');
|
|
136
|
-
return {
|
|
137
|
-
handled: true,
|
|
138
|
-
clearTranscript: true,
|
|
139
|
-
nextState: {
|
|
140
|
-
threadId,
|
|
141
|
-
sessionId: createCodemaxSessionId('cli'),
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
if (cmd === 'thread') {
|
|
146
|
-
if (!arg) {
|
|
147
|
-
return {
|
|
148
|
-
handled: true,
|
|
149
|
-
systemMessage: `[CodeMax] thread_id=${state.threadId}`,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
handled: true,
|
|
154
|
-
systemMessage: `[CodeMax] thread_id set to ${arg}`,
|
|
155
|
-
nextState: { threadId: arg },
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
if (cmd === 'markdown' || cmd === 'md') {
|
|
159
|
-
if (!arg) {
|
|
160
|
-
const next = !state.renderMarkdown;
|
|
161
|
-
updateConfig({ renderMarkdown: next });
|
|
162
|
-
return {
|
|
163
|
-
handled: true,
|
|
164
|
-
systemMessage: `[CodeMax] markdown=${next ? 'on' : 'off'}`,
|
|
165
|
-
nextState: { renderMarkdown: next },
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const value = arg.toLowerCase();
|
|
169
|
-
if (value !== 'on' && value !== 'off') {
|
|
170
|
-
return {
|
|
171
|
-
handled: true,
|
|
172
|
-
systemMessage: '[CodeMax] Usage: /markdown [on|off]',
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
const next = value === 'on';
|
|
176
|
-
updateConfig({ renderMarkdown: next });
|
|
177
|
-
return {
|
|
178
|
-
handled: true,
|
|
179
|
-
systemMessage: `[CodeMax] markdown=${next ? 'on' : 'off'}`,
|
|
180
|
-
nextState: { renderMarkdown: next },
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
if (cmd === 'model') {
|
|
184
|
-
return {
|
|
185
|
-
handled: true,
|
|
186
|
-
nextState: { screen: 'model' },
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
if (cmd === 'mcp') {
|
|
190
|
-
return { handled: true, openMcpModal: true };
|
|
191
|
-
}
|
|
192
|
-
if (cmd === 'chats') {
|
|
193
|
-
return { handled: true, openChatsModal: true };
|
|
194
|
-
}
|
|
195
|
-
if (cmd === 'compact') {
|
|
196
|
-
return {
|
|
197
|
-
handled: true,
|
|
198
|
-
forceCompact: true,
|
|
199
|
-
systemMessage: '[CodeMax] Compacting conversation context…',
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
if (cmd === 'compaction_threshold') {
|
|
203
|
-
return { handled: true, nextState: { screen: 'compaction' } };
|
|
204
|
-
}
|
|
205
|
-
if (cmd === 'import-cursor-rules') {
|
|
206
|
-
const executionCwd = process.env['CODEMAX_SHELL_CWD'] ?? process.cwd();
|
|
207
|
-
const { imported, skipped } = importCursorRules(executionCwd);
|
|
208
|
-
if (imported.length === 0 && skipped.length === 0) {
|
|
209
|
-
return {
|
|
210
|
-
handled: true,
|
|
211
|
-
systemMessage: '[CodeMax] No rules found in .cursor/rules/',
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
const lines = ['[CodeMax] Cursor rules import complete.'];
|
|
215
|
-
if (imported.length > 0) {
|
|
216
|
-
lines.push(`Imported (${imported.length}): ${imported.join(', ')}`);
|
|
217
|
-
}
|
|
218
|
-
if (skipped.length > 0) {
|
|
219
|
-
lines.push(`Failed (${skipped.length}): ${skipped.join(', ')}`);
|
|
220
|
-
}
|
|
221
|
-
return { handled: true, systemMessage: lines.join('\n') };
|
|
222
|
-
}
|
|
223
|
-
const matchedSkill = skills.find(skill => skill.name.toLowerCase() === cmd);
|
|
224
|
-
if (matchedSkill) {
|
|
225
|
-
return {
|
|
226
|
-
handled: true,
|
|
227
|
-
activateSkill: matchedSkill.content,
|
|
228
|
-
systemMessage: `[CodeMax] Skill '${matchedSkill.name}' activated.`,
|
|
229
|
-
prompt: arg || undefined,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
handled: true,
|
|
234
|
-
systemMessage: `[CodeMax] Unknown command: /${cmd}`,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
declare const ConfigSchema: z.ZodObject<{
|
|
3
|
-
modelName: z.ZodDefault<z.ZodString>;
|
|
4
|
-
baseURL: z.ZodDefault<z.ZodString>;
|
|
5
|
-
apiKey: z.ZodDefault<z.ZodString>;
|
|
6
|
-
renderMarkdown: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
-
debugEvents: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
-
recursionLimit: z.ZodDefault<z.ZodNumber>;
|
|
9
|
-
compactionThreshold: z.ZodDefault<z.ZodNumber>;
|
|
10
|
-
}, "strip", z.ZodTypeAny, {
|
|
11
|
-
modelName: string;
|
|
12
|
-
baseURL: string;
|
|
13
|
-
apiKey: string;
|
|
14
|
-
renderMarkdown: boolean;
|
|
15
|
-
debugEvents: boolean;
|
|
16
|
-
recursionLimit: number;
|
|
17
|
-
compactionThreshold: number;
|
|
18
|
-
}, {
|
|
19
|
-
modelName?: string | undefined;
|
|
20
|
-
baseURL?: string | undefined;
|
|
21
|
-
apiKey?: string | undefined;
|
|
22
|
-
renderMarkdown?: boolean | undefined;
|
|
23
|
-
debugEvents?: boolean | undefined;
|
|
24
|
-
recursionLimit?: number | undefined;
|
|
25
|
-
compactionThreshold?: number | undefined;
|
|
26
|
-
}>;
|
|
27
|
-
export type CodeMaxConfig = z.infer<typeof ConfigSchema>;
|
|
28
|
-
export declare function loadConfig(): CodeMaxConfig;
|
|
29
|
-
export declare function saveConfig(config: Partial<CodeMaxConfig>): void;
|
|
30
|
-
export declare function getConfig(): CodeMaxConfig;
|
|
31
|
-
export declare function updateConfig(config: Partial<CodeMaxConfig>): void;
|
|
32
|
-
export {};
|