@sylix/coworker 1.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.
- package/README.md +191 -0
- package/dist/api/sylix.d.ts +51 -0
- package/dist/api/sylix.d.ts.map +1 -0
- package/dist/api/sylix.js +234 -0
- package/dist/api/sylix.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +235 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/ask.d.ts +2 -0
- package/dist/commands/ask.d.ts.map +1 -0
- package/dist/commands/ask.js +55 -0
- package/dist/commands/ask.js.map +1 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +292 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/commit.d.ts +2 -0
- package/dist/commands/commit.d.ts.map +1 -0
- package/dist/commands/commit.js +163 -0
- package/dist/commands/commit.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +101 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/edit.d.ts +2 -0
- package/dist/commands/edit.d.ts.map +1 -0
- package/dist/commands/edit.js +112 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/explain.d.ts +2 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +99 -0
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +151 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/review.d.ts +2 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +137 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +136 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/context/reader.d.ts +24 -0
- package/dist/context/reader.d.ts.map +1 -0
- package/dist/context/reader.js +209 -0
- package/dist/context/reader.js.map +1 -0
- package/dist/memory/loader.d.ts +41 -0
- package/dist/memory/loader.d.ts.map +1 -0
- package/dist/memory/loader.js +249 -0
- package/dist/memory/loader.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +7 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +23 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +40 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/chrome.d.ts +10 -0
- package/dist/tools/chrome.d.ts.map +1 -0
- package/dist/tools/chrome.js +228 -0
- package/dist/tools/chrome.js.map +1 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +67 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/ls.d.ts +2 -0
- package/dist/tools/ls.d.ts.map +1 -0
- package/dist/tools/ls.js +75 -0
- package/dist/tools/ls.js.map +1 -0
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +72 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/registry.d.ts +2 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +64 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/utils/output.d.ts +62 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +487 -0
- package/dist/utils/output.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.commitCommand = commitCommand;
|
|
37
|
+
const sylix_1 = require("../api/sylix");
|
|
38
|
+
const output_1 = require("../utils/output");
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
async function commitCommand(customMessage, verbose = false) {
|
|
41
|
+
const timer = new output_1.Timer();
|
|
42
|
+
try {
|
|
43
|
+
// Get git status
|
|
44
|
+
let gitStatus;
|
|
45
|
+
let gitDiff;
|
|
46
|
+
try {
|
|
47
|
+
gitStatus = (0, child_process_1.execSync)('git status --porcelain', { encoding: 'utf-8' });
|
|
48
|
+
gitDiff = (0, child_process_1.execSync)('git diff --cached', { encoding: 'utf-8' });
|
|
49
|
+
if (!gitStatus.trim()) {
|
|
50
|
+
(0, output_1.printWarning)('No changes to commit');
|
|
51
|
+
console.log();
|
|
52
|
+
console.log(output_1.theme.dim('Stage changes first with:'));
|
|
53
|
+
console.log(output_1.theme.code(' git add <file>'));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!gitDiff.trim()) {
|
|
57
|
+
(0, output_1.printWarning)('No staged changes to commit');
|
|
58
|
+
console.log();
|
|
59
|
+
console.log(output_1.theme.dim('Stage changes first with:'));
|
|
60
|
+
console.log(output_1.theme.code(' git add <file>'));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
(0, output_1.printError)('Not a git repository');
|
|
66
|
+
process.exit(1);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// If custom message provided, use it directly
|
|
70
|
+
if (customMessage) {
|
|
71
|
+
try {
|
|
72
|
+
(0, child_process_1.execSync)(`git commit -m "${customMessage}"`, { encoding: 'utf-8' });
|
|
73
|
+
(0, output_1.printSuccess)('Committed:', customMessage);
|
|
74
|
+
(0, output_1.printResponseStats)(timer.elapsed());
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
(0, output_1.printError)('Failed to commit');
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
(0, output_1.startLoadingAnimation)();
|
|
82
|
+
// Get recent commits for context
|
|
83
|
+
let recentCommits = '';
|
|
84
|
+
try {
|
|
85
|
+
recentCommits = (0, child_process_1.execSync)('git log --oneline -5', { encoding: 'utf-8' });
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Ignore if no commits yet
|
|
89
|
+
}
|
|
90
|
+
const messages = [
|
|
91
|
+
{
|
|
92
|
+
role: 'system',
|
|
93
|
+
content: `You are CoWorker, an AI coding assistant by Sylix. Generate concise git commit messages.
|
|
94
|
+
Follow conventional commit format:
|
|
95
|
+
- feat: for new features
|
|
96
|
+
- fix: for bug fixes
|
|
97
|
+
- docs: for documentation
|
|
98
|
+
- style: for formatting
|
|
99
|
+
- refactor: for code refactoring
|
|
100
|
+
- test: for tests
|
|
101
|
+
- chore: for maintenance
|
|
102
|
+
|
|
103
|
+
Return ONLY the commit message, nothing else. Keep it under 72 characters.`
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
role: 'user',
|
|
107
|
+
content: `Generate a commit message for these staged changes:
|
|
108
|
+
|
|
109
|
+
Recent commits (for style reference):
|
|
110
|
+
${recentCommits || 'No commits yet'}
|
|
111
|
+
|
|
112
|
+
Staged changes:
|
|
113
|
+
${gitDiff}`
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
const response = await (0, sylix_1.chat)(messages);
|
|
117
|
+
(0, output_1.stopLoadingAnimation)();
|
|
118
|
+
// Clean up the response
|
|
119
|
+
let commitMessage = response.content.trim();
|
|
120
|
+
// Remove quotes if wrapped
|
|
121
|
+
if (commitMessage.startsWith('"') && commitMessage.endsWith('"')) {
|
|
122
|
+
commitMessage = commitMessage.slice(1, -1);
|
|
123
|
+
}
|
|
124
|
+
// Remove markdown code blocks if present
|
|
125
|
+
commitMessage = commitMessage.replace(/^```\w*\n?/g, '').replace(/\n?```$/g, '');
|
|
126
|
+
commitMessage = commitMessage.trim();
|
|
127
|
+
// Show commit box
|
|
128
|
+
(0, output_1.printCommitBox)(commitMessage);
|
|
129
|
+
// Prompt for confirmation
|
|
130
|
+
const prompts = await Promise.resolve().then(() => __importStar(require('prompts')));
|
|
131
|
+
const { confirm } = await prompts.default({
|
|
132
|
+
type: 'confirm',
|
|
133
|
+
name: 'confirm',
|
|
134
|
+
message: 'Use this commit message?',
|
|
135
|
+
initial: true
|
|
136
|
+
});
|
|
137
|
+
if (confirm) {
|
|
138
|
+
try {
|
|
139
|
+
(0, child_process_1.execSync)(`git commit -m "${commitMessage}"`, { encoding: 'utf-8' });
|
|
140
|
+
(0, output_1.printSuccess)('Committed:', commitMessage);
|
|
141
|
+
(0, output_1.printResponseStats)(timer.elapsed());
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
(0, output_1.printError)('Failed to commit');
|
|
145
|
+
if (error instanceof Error) {
|
|
146
|
+
console.error(error.message);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
(0, output_1.printWarning)('Commit cancelled');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
(0, output_1.stopLoadingAnimation)();
|
|
156
|
+
(0, output_1.printError)('Failed to generate commit message');
|
|
157
|
+
if (error instanceof Error) {
|
|
158
|
+
console.error(error.message);
|
|
159
|
+
}
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["../../src/commands/commit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,sCAkIC;AAlJD,wCAAoC;AAEpC,4CAWyB;AACzB,iDAAyC;AAElC,KAAK,UAAU,aAAa,CAAC,aAAsB,EAAE,UAAmB,KAAK;IAClF,MAAM,KAAK,GAAG,IAAI,cAAK,EAAE,CAAC;IAE1B,IAAI,CAAC;QACH,iBAAiB;QACjB,IAAI,SAAiB,CAAC;QACtB,IAAI,OAAe,CAAC;QAEpB,IAAI,CAAC;YACH,SAAS,GAAG,IAAA,wBAAQ,EAAC,wBAAwB,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YACtE,OAAO,GAAG,IAAA,wBAAQ,EAAC,mBAAmB,EAAE,EAA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
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configInitCommand = configInitCommand;
|
|
7
|
+
exports.configShowCommand = configShowCommand;
|
|
8
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
9
|
+
const sylix_1 = require("../api/sylix");
|
|
10
|
+
const output_1 = require("../utils/output");
|
|
11
|
+
async function configInitCommand() {
|
|
12
|
+
await (0, output_1.printHeader)();
|
|
13
|
+
console.log('Configure your Sylix API connection');
|
|
14
|
+
console.log();
|
|
15
|
+
const questions = [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
name: 'baseUrl',
|
|
19
|
+
message: 'Sylix API Base URL',
|
|
20
|
+
initial: 'https://api.sylixide.com',
|
|
21
|
+
validate: (value) => {
|
|
22
|
+
if (!value)
|
|
23
|
+
return 'Base URL is required';
|
|
24
|
+
try {
|
|
25
|
+
new URL(value);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return 'Please enter a valid URL';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'password',
|
|
35
|
+
name: 'apiKey',
|
|
36
|
+
message: 'API Key (or run "coworker login" for SSO)',
|
|
37
|
+
validate: (value) => value ? true : 'API Key is required'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'text',
|
|
41
|
+
name: 'defaultModel',
|
|
42
|
+
message: 'Default Model (optional)',
|
|
43
|
+
initial: 'sylix-4'
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
const response = await (0, prompts_1.default)(questions);
|
|
47
|
+
if (!response.baseUrl || !response.apiKey) {
|
|
48
|
+
(0, output_1.printError)('Configuration cancelled');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const config = {
|
|
52
|
+
baseUrl: response.baseUrl,
|
|
53
|
+
apiKey: response.apiKey,
|
|
54
|
+
defaultModel: response.defaultModel || 'sylix-4'
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
await (0, sylix_1.saveConfig)(config);
|
|
58
|
+
(0, output_1.printSuccess)('Configuration saved successfully');
|
|
59
|
+
(0, output_1.printInfo)(`Config file: ${(0, sylix_1.getConfigPath)()}`);
|
|
60
|
+
console.log();
|
|
61
|
+
(0, output_1.printInfo)('Run "coworker ask <prompt>" to start using CoWorker');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
(0, output_1.printError)('Failed to save configuration');
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
console.error(error.message);
|
|
67
|
+
}
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function configShowCommand() {
|
|
72
|
+
await (0, output_1.printHeader)();
|
|
73
|
+
const config = await (0, sylix_1.loadConfig)();
|
|
74
|
+
if (!config) {
|
|
75
|
+
(0, output_1.printInfo)('No configuration found');
|
|
76
|
+
(0, output_1.printInfo)('Run "coworker login" to authenticate with Sylix');
|
|
77
|
+
(0, output_1.printInfo)('Or run "coworker config init" to configure manually');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.log();
|
|
81
|
+
console.log('Current Configuration:');
|
|
82
|
+
console.log();
|
|
83
|
+
console.log(` ${output_1.theme.dim('Base URL:')} ${config.baseUrl}`);
|
|
84
|
+
console.log(` ${output_1.theme.dim('API Key:')} ${maskApiKey(config.apiKey)}`);
|
|
85
|
+
console.log(` ${output_1.theme.dim('Default Model:')} ${config.defaultModel || 'sylix-4'}`);
|
|
86
|
+
console.log();
|
|
87
|
+
console.log(` ${output_1.theme.dim('Config file:')} ${(0, sylix_1.getConfigPath)()}`);
|
|
88
|
+
console.log();
|
|
89
|
+
}
|
|
90
|
+
function maskApiKey(key) {
|
|
91
|
+
if (!key)
|
|
92
|
+
return output_1.theme.dim('(not set)');
|
|
93
|
+
if (key.length <= 8)
|
|
94
|
+
return output_1.theme.error('********');
|
|
95
|
+
if (key.length > 32) {
|
|
96
|
+
// JWT token
|
|
97
|
+
return output_1.theme.success(key.slice(0, 20) + '...' + key.slice(-10));
|
|
98
|
+
}
|
|
99
|
+
return output_1.theme.success(key.slice(0, 4) + '****' + key.slice(-4));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":";;;;;AAkBA,8CA8DC;AAED,8CAqBC;AAvGD,sDAA8B;AAG9B,wCAKsB;AACtB,4CAOyB;AAElB,KAAK,UAAU,iBAAiB;IACrC,MAAM,IAAA,oBAAW,GAAE,CAAC;IAEpB,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,EAAE,CAAC;IAEd,MAAM,SAAS,GAAG;QAChB;YACE,IAAI,EAAE,MAAe;YACrB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,oBAAoB;YAC7B,OAAO,EAAE,0BAA0B;YACnC,QAAQ,EAAE,CAAC,KAAa,EAAE,EAAE;gBAC1B,IAAI,CAAC,KAAK;oBAAE,OAAO,sBAAsB,CAAC;gBAC1C,IAAI,CAAC;oBACH,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;oBACf,OAAO,IAAI,CAAC;gBACd,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,0BAA0B,CAAC;gBACpC,CAAC;YACH,CAAC;SACF;QACD;YACE,IAAI,EAAE,UAAmB;YACzB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,2CAA2C;YACpD,QAAQ,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAA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AE,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/commands/edit.ts"],"names":[],"mappings":"AAkBA,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyEtF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.editCommand = editCommand;
|
|
40
|
+
const sylix_1 = require("../api/sylix");
|
|
41
|
+
const output_1 = require("../utils/output");
|
|
42
|
+
const fs = __importStar(require("fs-extra"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
45
|
+
async function editCommand(filePath, instruction) {
|
|
46
|
+
const timer = new output_1.Timer();
|
|
47
|
+
const absolutePath = path.resolve(filePath);
|
|
48
|
+
// Check if file exists
|
|
49
|
+
if (!(await fs.pathExists(absolutePath))) {
|
|
50
|
+
(0, output_1.printError)(`File not found: ${filePath}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
(0, output_1.startLoadingAnimation)();
|
|
55
|
+
const originalContent = await fs.readFile(absolutePath, 'utf-8');
|
|
56
|
+
const ext = path.extname(filePath).slice(1) || 'text';
|
|
57
|
+
const fileName = path.basename(filePath);
|
|
58
|
+
const messages = [
|
|
59
|
+
{
|
|
60
|
+
role: 'system',
|
|
61
|
+
content: `You are CoWorker, an AI coding assistant by Sylix. You help edit code files.
|
|
62
|
+
When given a file and an instruction, output ONLY the modified file content.
|
|
63
|
+
Do not include explanations, comments about changes, or markdown code blocks.
|
|
64
|
+
Just output the complete modified file content directly.
|
|
65
|
+
|
|
66
|
+
Preserve the overall structure and style of the original file unless instructed otherwise.
|
|
67
|
+
Make minimal, focused changes that address the user's instruction exactly.`
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
role: 'user',
|
|
71
|
+
content: `File: ${fileName}
|
|
72
|
+
|
|
73
|
+
\`\`\`${ext}
|
|
74
|
+
${originalContent}
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
Instruction: ${instruction}
|
|
78
|
+
|
|
79
|
+
Output the complete modified file content:`
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
const chatResponse = await (0, sylix_1.chat)(messages);
|
|
83
|
+
const newContent = chatResponse.content;
|
|
84
|
+
(0, output_1.stopLoadingAnimation)();
|
|
85
|
+
// Show diff
|
|
86
|
+
(0, output_1.printDiff)(originalContent, newContent, fileName);
|
|
87
|
+
// Ask for confirmation
|
|
88
|
+
const response = await (0, prompts_1.default)({
|
|
89
|
+
type: 'confirm',
|
|
90
|
+
name: 'apply',
|
|
91
|
+
message: 'Apply these changes?',
|
|
92
|
+
initial: false
|
|
93
|
+
});
|
|
94
|
+
if (response.apply) {
|
|
95
|
+
await fs.writeFile(absolutePath, newContent, 'utf-8');
|
|
96
|
+
(0, output_1.printSuccess)(`File edited successfully`, filePath);
|
|
97
|
+
(0, output_1.printResponseStats)(timer.elapsed());
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
(0, output_1.printWarning)('Changes discarded');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
(0, output_1.stopLoadingAnimation)();
|
|
105
|
+
(0, output_1.printError)('Failed to edit file');
|
|
106
|
+
if (error instanceof Error) {
|
|
107
|
+
console.error(error.message);
|
|
108
|
+
}
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
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 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.explainCommand = explainCommand;
|
|
37
|
+
const sylix_1 = require("../api/sylix");
|
|
38
|
+
const reader_1 = require("../context/reader");
|
|
39
|
+
const output_1 = require("../utils/output");
|
|
40
|
+
const fs = __importStar(require("fs-extra"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
async function explainCommand(filePath, verbose = false) {
|
|
43
|
+
const timer = new output_1.Timer();
|
|
44
|
+
const absolutePath = path.resolve(filePath);
|
|
45
|
+
// Check if file exists
|
|
46
|
+
if (!(await fs.pathExists(absolutePath))) {
|
|
47
|
+
(0, output_1.printError)(`File not found: ${filePath}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
(0, output_1.startLoadingAnimation)();
|
|
52
|
+
const content = await (0, reader_1.readFileContext)(absolutePath);
|
|
53
|
+
const ext = path.extname(filePath).slice(1) || 'text';
|
|
54
|
+
const fileName = path.basename(filePath);
|
|
55
|
+
const messages = [
|
|
56
|
+
{
|
|
57
|
+
role: 'system',
|
|
58
|
+
content: `You are CoWorker, an AI coding assistant by Sylix. You explain code clearly and concisely.
|
|
59
|
+
Structure your explanations with:
|
|
60
|
+
1. A brief summary of what the file does
|
|
61
|
+
2. Key components/functions and their purposes
|
|
62
|
+
3. Important patterns or conventions used
|
|
63
|
+
4. Any notable dependencies or integrations
|
|
64
|
+
|
|
65
|
+
Keep explanations practical and focused on what developers need to know.`
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
role: 'user',
|
|
69
|
+
content: `Explain this file: ${fileName}\n\n\`\`\`${ext}\n${content}\n\`\`\``
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
(0, output_1.stopLoadingAnimation)();
|
|
73
|
+
// Show file preview
|
|
74
|
+
console.log();
|
|
75
|
+
console.log(output_1.theme.brand('━') + ' ' + output_1.theme.white(fileName));
|
|
76
|
+
console.log();
|
|
77
|
+
// Start response
|
|
78
|
+
const renderer = new output_1.StreamingRenderer();
|
|
79
|
+
renderer.start();
|
|
80
|
+
let response = '';
|
|
81
|
+
let tokenCount = 0;
|
|
82
|
+
await (0, sylix_1.chat)(messages, (chunk) => {
|
|
83
|
+
response += chunk;
|
|
84
|
+
renderer.write(chunk);
|
|
85
|
+
tokenCount++;
|
|
86
|
+
});
|
|
87
|
+
renderer.end();
|
|
88
|
+
(0, output_1.printResponseStats)(timer.elapsed(), verbose ? tokenCount : undefined, verbose);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
(0, output_1.stopLoadingAnimation)();
|
|
92
|
+
(0, output_1.printError)('Failed to explain file');
|
|
93
|
+
if (error instanceof Error) {
|
|
94
|
+
console.error(error.message);
|
|
95
|
+
}
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../src/commands/explain.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,wCAkEC;AAlFD,wCAAoC;AACpC,8CAAoD;AACpD,4CAUyB;AACzB,6CAA+B;AAC/B,2CAA6B;AAEtB,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,UAAmB,KAAK;IAC7E,MAAM,KAAK,GAAG,IAAI,cAAK,EAAE,CAAC;IAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5C,uBAAuB;IACvB,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;QACzC,IAAA,mBAAU,EAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,CAAC;QACH,IAAA,8BAAqB,GAAE,CAAC;QAExB,MAAM,OAAO,GAAG,MAAM,IAAA,wBAAe,EAAC,YAAY,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,C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