@latentforce/shift 1.0.0 → 1.0.2
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 +108 -64
- package/build/cli/commands/init.js +136 -0
- package/build/cli/commands/start.js +81 -0
- package/build/cli/commands/status.js +46 -0
- package/build/cli/commands/stop.js +18 -0
- package/build/daemon/daemon-manager.js +136 -0
- package/build/daemon/daemon.js +119 -0
- package/build/daemon/tools-executor.js +383 -0
- package/build/daemon/websocket-client.js +334 -0
- package/build/index.js +39 -126
- package/build/mcp-server.js +124 -0
- package/build/utils/api-client.js +50 -0
- package/build/utils/config.js +165 -0
- package/build/utils/prompts.js +50 -0
- package/build/utils/tree-scanner.js +148 -0
- package/package.json +5 -2
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
// Global config location: ~/.shift/config.json
|
|
5
|
+
const GLOBAL_SHIFT_DIR = path.join(os.homedir(), '.shift');
|
|
6
|
+
const GLOBAL_CONFIG_FILE = path.join(GLOBAL_SHIFT_DIR, 'config.json');
|
|
7
|
+
// Local config location: .shift/ in current directory
|
|
8
|
+
const LOCAL_SHIFT_DIR = '.shift';
|
|
9
|
+
const LOCAL_CONFIG_FILE = 'config.json'; // Changed from project.json to match extension
|
|
10
|
+
const DAEMON_PID_FILE = 'daemon.pid';
|
|
11
|
+
const DAEMON_STATUS_FILE = 'daemon.status.json';
|
|
12
|
+
// API URLs - matching extension's config.js
|
|
13
|
+
export const API_BASE_URL = process.env.SHIFT_API_URL || 'http://localhost:9000';
|
|
14
|
+
export const API_BASE_URL_ORCH = process.env.SHIFT_ORCH_URL || 'http://localhost:9999';
|
|
15
|
+
export const WS_URL = process.env.SHIFT_WS_URL || 'ws://localhost:9999';
|
|
16
|
+
// --- Global Config Functions ---
|
|
17
|
+
export function ensureGlobalShiftDir() {
|
|
18
|
+
if (!fs.existsSync(GLOBAL_SHIFT_DIR)) {
|
|
19
|
+
fs.mkdirSync(GLOBAL_SHIFT_DIR, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function readGlobalConfig() {
|
|
23
|
+
try {
|
|
24
|
+
if (fs.existsSync(GLOBAL_CONFIG_FILE)) {
|
|
25
|
+
const content = fs.readFileSync(GLOBAL_CONFIG_FILE, 'utf-8');
|
|
26
|
+
return JSON.parse(content);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Invalid config, treat as not existing
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
export function writeGlobalConfig(config) {
|
|
35
|
+
ensureGlobalShiftDir();
|
|
36
|
+
fs.writeFileSync(GLOBAL_CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
37
|
+
}
|
|
38
|
+
export function getApiKey() {
|
|
39
|
+
const config = readGlobalConfig();
|
|
40
|
+
return config?.api_key || null;
|
|
41
|
+
}
|
|
42
|
+
export function setApiKey(apiKey) {
|
|
43
|
+
const config = readGlobalConfig() || { api_key: '' };
|
|
44
|
+
config.api_key = apiKey;
|
|
45
|
+
writeGlobalConfig(config);
|
|
46
|
+
}
|
|
47
|
+
// --- Local Config Functions ---
|
|
48
|
+
export function getLocalShiftDir(projectRoot) {
|
|
49
|
+
const root = projectRoot || process.cwd();
|
|
50
|
+
return path.join(root, LOCAL_SHIFT_DIR);
|
|
51
|
+
}
|
|
52
|
+
export function ensureLocalShiftDir(projectRoot) {
|
|
53
|
+
const dir = getLocalShiftDir(projectRoot);
|
|
54
|
+
if (!fs.existsSync(dir)) {
|
|
55
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function readProjectConfig(projectRoot) {
|
|
59
|
+
try {
|
|
60
|
+
const filePath = path.join(getLocalShiftDir(projectRoot), LOCAL_CONFIG_FILE);
|
|
61
|
+
if (fs.existsSync(filePath)) {
|
|
62
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
63
|
+
return JSON.parse(content);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Invalid config, treat as not existing
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
export function writeProjectConfig(config, projectRoot) {
|
|
72
|
+
ensureLocalShiftDir(projectRoot);
|
|
73
|
+
const filePath = path.join(getLocalShiftDir(projectRoot), LOCAL_CONFIG_FILE);
|
|
74
|
+
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
|
75
|
+
// Also create .gitignore in .shift folder (matching extension)
|
|
76
|
+
const gitignorePath = path.join(getLocalShiftDir(projectRoot), '.gitignore');
|
|
77
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
78
|
+
fs.writeFileSync(gitignorePath, '*\n!.gitignore\n!config.json\n');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function getProjectId(projectRoot) {
|
|
82
|
+
const config = readProjectConfig(projectRoot);
|
|
83
|
+
return config?.project_id || null;
|
|
84
|
+
}
|
|
85
|
+
export function getProjectName(projectRoot) {
|
|
86
|
+
const config = readProjectConfig(projectRoot);
|
|
87
|
+
return config?.project_name || null;
|
|
88
|
+
}
|
|
89
|
+
export function setProject(projectId, projectName, projectRoot) {
|
|
90
|
+
const existing = readProjectConfig(projectRoot);
|
|
91
|
+
const config = {
|
|
92
|
+
project_id: projectId,
|
|
93
|
+
project_name: projectName,
|
|
94
|
+
agents: existing?.agents || [],
|
|
95
|
+
created_at: existing?.created_at || new Date().toISOString(),
|
|
96
|
+
};
|
|
97
|
+
writeProjectConfig(config, projectRoot);
|
|
98
|
+
}
|
|
99
|
+
// --- Daemon Status Functions ---
|
|
100
|
+
export function getDaemonPidPath(projectRoot) {
|
|
101
|
+
return path.join(getLocalShiftDir(projectRoot), DAEMON_PID_FILE);
|
|
102
|
+
}
|
|
103
|
+
export function getDaemonStatusPath(projectRoot) {
|
|
104
|
+
return path.join(getLocalShiftDir(projectRoot), DAEMON_STATUS_FILE);
|
|
105
|
+
}
|
|
106
|
+
export function readDaemonPid(projectRoot) {
|
|
107
|
+
try {
|
|
108
|
+
const filePath = getDaemonPidPath(projectRoot);
|
|
109
|
+
if (fs.existsSync(filePath)) {
|
|
110
|
+
const content = fs.readFileSync(filePath, 'utf-8').trim();
|
|
111
|
+
const pid = parseInt(content, 10);
|
|
112
|
+
return isNaN(pid) ? null : pid;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Error reading PID file
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
export function writeDaemonPid(pid, projectRoot) {
|
|
121
|
+
ensureLocalShiftDir(projectRoot);
|
|
122
|
+
const filePath = getDaemonPidPath(projectRoot);
|
|
123
|
+
fs.writeFileSync(filePath, String(pid));
|
|
124
|
+
}
|
|
125
|
+
export function removeDaemonPid(projectRoot) {
|
|
126
|
+
const filePath = getDaemonPidPath(projectRoot);
|
|
127
|
+
if (fs.existsSync(filePath)) {
|
|
128
|
+
fs.unlinkSync(filePath);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function readDaemonStatus(projectRoot) {
|
|
132
|
+
try {
|
|
133
|
+
const filePath = getDaemonStatusPath(projectRoot);
|
|
134
|
+
if (fs.existsSync(filePath)) {
|
|
135
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
136
|
+
return JSON.parse(content);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Invalid status file
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
export function writeDaemonStatus(status, projectRoot) {
|
|
145
|
+
ensureLocalShiftDir(projectRoot);
|
|
146
|
+
const filePath = getDaemonStatusPath(projectRoot);
|
|
147
|
+
fs.writeFileSync(filePath, JSON.stringify(status, null, 2));
|
|
148
|
+
}
|
|
149
|
+
export function removeDaemonStatus(projectRoot) {
|
|
150
|
+
const filePath = getDaemonStatusPath(projectRoot);
|
|
151
|
+
if (fs.existsSync(filePath)) {
|
|
152
|
+
fs.unlinkSync(filePath);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// --- Process Check ---
|
|
156
|
+
export function isProcessRunning(pid) {
|
|
157
|
+
try {
|
|
158
|
+
// Sending signal 0 checks if process exists without killing it
|
|
159
|
+
process.kill(pid, 0);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as readline from 'readline';
|
|
2
|
+
function createReadlineInterface() {
|
|
3
|
+
return readline.createInterface({
|
|
4
|
+
input: process.stdin,
|
|
5
|
+
output: process.stdout,
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export function prompt(question) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const rl = createReadlineInterface();
|
|
11
|
+
rl.question(question, (answer) => {
|
|
12
|
+
rl.close();
|
|
13
|
+
resolve(answer.trim());
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export async function promptApiKey() {
|
|
18
|
+
console.log('\nNo Shift API key found.');
|
|
19
|
+
const apiKey = await prompt('Please paste your Shift API key: ');
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
console.error('Error: API key is required.');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
return apiKey;
|
|
25
|
+
}
|
|
26
|
+
export async function promptProjectId() {
|
|
27
|
+
console.log('\nNo project configured for this directory.');
|
|
28
|
+
const projectId = await prompt('Please enter your Shift project ID: ');
|
|
29
|
+
if (!projectId) {
|
|
30
|
+
console.error('Error: Project ID is required.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
return projectId;
|
|
34
|
+
}
|
|
35
|
+
export async function promptSelectProject(projects) {
|
|
36
|
+
console.log('\nAvailable projects:');
|
|
37
|
+
console.log('-------------------');
|
|
38
|
+
projects.forEach((project, index) => {
|
|
39
|
+
const description = project.description ? ` - ${project.description}` : '';
|
|
40
|
+
console.log(` ${index + 1}. ${project.project_name}${description}`);
|
|
41
|
+
});
|
|
42
|
+
console.log('');
|
|
43
|
+
const answer = await prompt(`Select a project (1-${projects.length}): `);
|
|
44
|
+
const selection = parseInt(answer, 10);
|
|
45
|
+
if (isNaN(selection) || selection < 1 || selection > projects.length) {
|
|
46
|
+
console.error('Invalid selection.');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
return projects[selection - 1];
|
|
50
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
// Matching extension's file-tools.js exclude patterns
|
|
4
|
+
const DEFAULT_EXCLUDE_PATTERNS = [
|
|
5
|
+
'.git',
|
|
6
|
+
'node_modules',
|
|
7
|
+
'__pycache__',
|
|
8
|
+
'.vscode',
|
|
9
|
+
'dist',
|
|
10
|
+
'build',
|
|
11
|
+
'.shift',
|
|
12
|
+
'.next',
|
|
13
|
+
'.cache',
|
|
14
|
+
'coverage',
|
|
15
|
+
'.pytest_cache',
|
|
16
|
+
'venv',
|
|
17
|
+
'env',
|
|
18
|
+
'.env',
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Get project tree - matching extension's getProjectTree function
|
|
22
|
+
*/
|
|
23
|
+
export function getProjectTree(workspaceRoot, options = {}) {
|
|
24
|
+
const { depth = 0, exclude_patterns = DEFAULT_EXCLUDE_PATTERNS, } = options;
|
|
25
|
+
let file_count = 0;
|
|
26
|
+
let dir_count = 0;
|
|
27
|
+
let total_size = 0;
|
|
28
|
+
const max_depth = depth === 0 ? Infinity : depth;
|
|
29
|
+
function scanDirectory(dirPath, currentDepth, relativePath) {
|
|
30
|
+
if (currentDepth >= max_depth) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const items = [];
|
|
34
|
+
try {
|
|
35
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
// Check if should be excluded
|
|
38
|
+
if (exclude_patterns.some(pattern => entry.name.includes(pattern))) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const itemPath = path.join(dirPath, entry.name);
|
|
42
|
+
const itemRelativePath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
|
43
|
+
if (entry.isDirectory()) {
|
|
44
|
+
dir_count++;
|
|
45
|
+
const children = scanDirectory(itemPath, currentDepth + 1, itemRelativePath);
|
|
46
|
+
items.push({
|
|
47
|
+
name: entry.name,
|
|
48
|
+
type: 'directory',
|
|
49
|
+
path: itemRelativePath.replace(/\\/g, '/'), // Normalize to forward slashes
|
|
50
|
+
depth: currentDepth,
|
|
51
|
+
children: children,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (entry.isFile()) {
|
|
55
|
+
file_count++;
|
|
56
|
+
try {
|
|
57
|
+
const stats = fs.statSync(itemPath);
|
|
58
|
+
total_size += stats.size;
|
|
59
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
60
|
+
items.push({
|
|
61
|
+
name: entry.name,
|
|
62
|
+
type: 'file',
|
|
63
|
+
path: itemRelativePath.replace(/\\/g, '/'), // Normalize to forward slashes
|
|
64
|
+
depth: currentDepth,
|
|
65
|
+
size: stats.size,
|
|
66
|
+
extension: ext,
|
|
67
|
+
modified: stats.mtime,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Skip files we can't read
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(`Error scanning ${dirPath}:`, err.message);
|
|
78
|
+
}
|
|
79
|
+
return items;
|
|
80
|
+
}
|
|
81
|
+
const tree = scanDirectory(workspaceRoot, 0, '');
|
|
82
|
+
const total_size_mb = (total_size / (1024 * 1024)).toFixed(2);
|
|
83
|
+
return {
|
|
84
|
+
status: 'success',
|
|
85
|
+
tree: tree,
|
|
86
|
+
file_count: file_count,
|
|
87
|
+
dir_count: dir_count,
|
|
88
|
+
total_size_bytes: total_size,
|
|
89
|
+
total_size_mb: total_size_mb,
|
|
90
|
+
scanned_from: workspaceRoot,
|
|
91
|
+
depth_limit: depth,
|
|
92
|
+
actual_max_depth: depth === 0 ? 'unlimited' : String(depth),
|
|
93
|
+
excluded_patterns: exclude_patterns,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Extract all file paths from tree structure
|
|
98
|
+
* Matching extension's extractAllFilePaths function
|
|
99
|
+
*/
|
|
100
|
+
export function extractAllFilePaths(tree, basePath = '') {
|
|
101
|
+
let files = [];
|
|
102
|
+
for (const item of tree) {
|
|
103
|
+
const itemPath = basePath ? `${basePath}/${item.name}` : item.name;
|
|
104
|
+
if (item.type === 'file') {
|
|
105
|
+
files.push(itemPath);
|
|
106
|
+
}
|
|
107
|
+
else if (item.type === 'directory' && item.children) {
|
|
108
|
+
files = files.concat(extractAllFilePaths(item.children, itemPath));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return files;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Categorize files by type
|
|
115
|
+
* Matching extension's categorizeFiles function
|
|
116
|
+
*/
|
|
117
|
+
export function categorizeFiles(tree, basePath = '') {
|
|
118
|
+
const categories = {
|
|
119
|
+
source_files: [],
|
|
120
|
+
config_files: [],
|
|
121
|
+
asset_files: [],
|
|
122
|
+
};
|
|
123
|
+
const sourceExts = ['.js', '.jsx', '.ts', '.tsx', '.py', '.java', '.cpp', '.cs', '.go', '.c', '.h'];
|
|
124
|
+
const configExts = ['.json', '.yaml', '.yml', '.toml', '.ini', '.config', '.xml'];
|
|
125
|
+
const assetExts = ['.png', '.jpg', '.jpeg', '.svg', '.gif', '.css', '.scss', '.less', '.sass'];
|
|
126
|
+
for (const item of tree) {
|
|
127
|
+
const itemPath = basePath ? `${basePath}/${item.name}` : item.name;
|
|
128
|
+
if (item.type === 'file') {
|
|
129
|
+
const ext = path.extname(item.name).toLowerCase();
|
|
130
|
+
if (sourceExts.includes(ext)) {
|
|
131
|
+
categories.source_files.push(itemPath);
|
|
132
|
+
}
|
|
133
|
+
else if (configExts.includes(ext)) {
|
|
134
|
+
categories.config_files.push(itemPath);
|
|
135
|
+
}
|
|
136
|
+
else if (assetExts.includes(ext)) {
|
|
137
|
+
categories.asset_files.push(itemPath);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (item.type === 'directory' && item.children) {
|
|
141
|
+
const subCategories = categorizeFiles(item.children, itemPath);
|
|
142
|
+
categories.source_files.push(...subCategories.source_files);
|
|
143
|
+
categories.config_files.push(...subCategories.config_files);
|
|
144
|
+
categories.asset_files.push(...subCategories.asset_files);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return categories;
|
|
148
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latentforce/shift",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Shift CLI - AI-powered code intelligence with MCP support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -37,10 +37,13 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
40
|
+
"commander": "^12.0.0",
|
|
41
|
+
"ws": "^8.14.0",
|
|
40
42
|
"zod": "^3.25.76"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@types/node": "^25.0.9",
|
|
46
|
+
"@types/ws": "^8.5.10",
|
|
44
47
|
"typescript": "^5.9.3"
|
|
45
48
|
}
|
|
46
49
|
}
|