@nick848/sf-cli 1.0.12 → 1.0.13
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/CHANGELOG.md +33 -0
- package/dist/cli/index.js +148 -45
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +121 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8860,7 +8860,7 @@ async function executeShell(command, ctx) {
|
|
|
8860
8860
|
init_esm_shims();
|
|
8861
8861
|
init_new();
|
|
8862
8862
|
async function handleNaturalLanguage(input, ctx) {
|
|
8863
|
-
input.trim()
|
|
8863
|
+
const trimmedInput = input.trim();
|
|
8864
8864
|
const session = getActiveSession();
|
|
8865
8865
|
if (session) {
|
|
8866
8866
|
const result = await handleWorkflowInput(input, ctx);
|
|
@@ -8871,81 +8871,163 @@ async function handleNaturalLanguage(input, ctx) {
|
|
|
8871
8871
|
};
|
|
8872
8872
|
}
|
|
8873
8873
|
}
|
|
8874
|
-
ctx.
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8874
|
+
const apiKey = ctx.configManager.get("apiKey");
|
|
8875
|
+
if (!apiKey) {
|
|
8876
|
+
return {
|
|
8877
|
+
output: chalk9.yellow("\u26A0\uFE0F \u672A\u914D\u7F6E API Key\uFF0C\u65E0\u6CD5\u4F7F\u7528 AI \u529F\u80FD") + chalk9.gray("\n\n\u8BF7\u5148\u6267\u884C /model \u914D\u7F6E\u6A21\u578B") + chalk9.gray("\n\u652F\u6301: GLM-5, GPT-4o, Claude"),
|
|
8878
|
+
contextUsed: 0
|
|
8879
|
+
};
|
|
8880
|
+
}
|
|
8881
|
+
try {
|
|
8882
|
+
const response = await ctx.modelService.sendMessage(
|
|
8883
|
+
[
|
|
8884
|
+
{
|
|
8885
|
+
role: "system",
|
|
8886
|
+
content: buildSystemPrompt(ctx)
|
|
8887
|
+
},
|
|
8888
|
+
{
|
|
8889
|
+
role: "user",
|
|
8890
|
+
content: trimmedInput
|
|
8891
|
+
}
|
|
8892
|
+
],
|
|
8893
|
+
{
|
|
8894
|
+
temperature: 0.7,
|
|
8895
|
+
maxTokens: 2e3
|
|
8896
|
+
}
|
|
8897
|
+
);
|
|
8898
|
+
ctx.contextManager.addMessage({
|
|
8899
|
+
role: "user",
|
|
8900
|
+
content: trimmedInput
|
|
8901
|
+
});
|
|
8902
|
+
ctx.contextManager.addMessage({
|
|
8903
|
+
role: "assistant",
|
|
8904
|
+
content: response.content
|
|
8905
|
+
});
|
|
8906
|
+
return {
|
|
8907
|
+
output: response.content,
|
|
8908
|
+
contextUsed: response.usage?.totalTokens || 0
|
|
8909
|
+
};
|
|
8910
|
+
} catch (error) {
|
|
8911
|
+
const errorMessage = error.message;
|
|
8912
|
+
if (errorMessage.includes("\u672A\u914D\u7F6E") || errorMessage.includes("\u672A\u521D\u59CB\u5316")) {
|
|
8913
|
+
return {
|
|
8914
|
+
output: chalk9.yellow("\u26A0\uFE0F \u6A21\u578B\u672A\u6B63\u786E\u914D\u7F6E") + chalk9.gray("\n\n\u8BF7\u6267\u884C /model \u91CD\u65B0\u914D\u7F6E"),
|
|
8915
|
+
contextUsed: 0
|
|
8916
|
+
};
|
|
8917
|
+
}
|
|
8918
|
+
if (errorMessage.includes("timeout") || errorMessage.includes("\u8D85\u65F6")) {
|
|
8919
|
+
return {
|
|
8920
|
+
output: chalk9.red("\u2717 \u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"),
|
|
8921
|
+
contextUsed: 0
|
|
8922
|
+
};
|
|
8923
|
+
}
|
|
8924
|
+
return {
|
|
8925
|
+
output: chalk9.red(`\u2717 \u5904\u7406\u5931\u8D25: ${errorMessage}`),
|
|
8926
|
+
contextUsed: 0
|
|
8927
|
+
};
|
|
8928
|
+
}
|
|
8929
|
+
}
|
|
8930
|
+
function buildSystemPrompt(ctx) {
|
|
8931
|
+
const parts = [
|
|
8932
|
+
"\u4F60\u662F sf-cli \u7684 AI \u52A9\u624B\uFF0C\u4E00\u4E2A\u4E13\u4E1A\u7684\u8F6F\u4EF6\u5F00\u53D1\u52A9\u624B\u3002",
|
|
8933
|
+
"",
|
|
8934
|
+
"\u4F60\u53EF\u4EE5\u5E2E\u52A9\u7528\u6237\uFF1A",
|
|
8935
|
+
"1. \u7406\u89E3\u548C\u5206\u6790\u9700\u6C42",
|
|
8936
|
+
"2. \u63D0\u4F9B\u4EE3\u7801\u5EFA\u8BAE\u548C\u5B9E\u73B0\u65B9\u6848",
|
|
8937
|
+
"3. \u56DE\u7B54\u6280\u672F\u95EE\u9898",
|
|
8938
|
+
"4. \u8F85\u52A9\u8FDB\u884C\u4EE3\u7801\u5BA1\u67E5",
|
|
8939
|
+
"",
|
|
8940
|
+
"\u5F53\u524D\u9879\u76EE\u4FE1\u606F\uFF1A",
|
|
8941
|
+
`- \u5DE5\u4F5C\u76EE\u5F55: ${ctx.options.workingDirectory}`,
|
|
8942
|
+
`- \u6A21\u578B: ${ctx.modelService.getCurrentModel() || "\u672A\u6307\u5B9A"}`
|
|
8943
|
+
];
|
|
8944
|
+
return parts.join("\n");
|
|
8883
8945
|
}
|
|
8884
8946
|
|
|
8885
8947
|
// src/cli/executor.ts
|
|
8886
8948
|
init_new();
|
|
8887
|
-
var
|
|
8949
|
+
var ALWAYS_ALLOWED = [
|
|
8888
8950
|
"help",
|
|
8889
8951
|
"h",
|
|
8890
8952
|
"?",
|
|
8891
|
-
"init",
|
|
8892
|
-
"i",
|
|
8893
8953
|
"model",
|
|
8894
8954
|
"m",
|
|
8895
|
-
"new",
|
|
8896
|
-
"n",
|
|
8897
8955
|
"exit",
|
|
8898
8956
|
"e",
|
|
8899
8957
|
"q",
|
|
8900
8958
|
"quit",
|
|
8901
8959
|
"clear",
|
|
8902
8960
|
"c",
|
|
8903
|
-
"update",
|
|
8904
|
-
"u",
|
|
8905
8961
|
"version",
|
|
8906
8962
|
"v"
|
|
8907
8963
|
];
|
|
8964
|
+
var REQUIRES_API_KEY = [
|
|
8965
|
+
"new",
|
|
8966
|
+
"n",
|
|
8967
|
+
"init",
|
|
8968
|
+
"i",
|
|
8969
|
+
"update",
|
|
8970
|
+
"u"
|
|
8971
|
+
];
|
|
8908
8972
|
var CommandExecutor = class {
|
|
8909
8973
|
async execute(parseResult, ctx) {
|
|
8910
8974
|
if (!parseResult.success || !parseResult.command) {
|
|
8911
8975
|
return { output: chalk9.red(`\u9519\u8BEF: ${parseResult.error}`) };
|
|
8912
8976
|
}
|
|
8913
8977
|
const { command } = parseResult;
|
|
8978
|
+
const hasApiKey = !!ctx.configManager.get("apiKey");
|
|
8914
8979
|
const hasActiveWorkflow = getActiveSession() !== null;
|
|
8915
|
-
if (
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8980
|
+
if (command.type === "slash" /* SLASH */) {
|
|
8981
|
+
const cmd = command.command?.toLowerCase() || "";
|
|
8982
|
+
if (ALWAYS_ALLOWED.includes(cmd)) {
|
|
8983
|
+
return this.executeSlashCommand(command, ctx);
|
|
8984
|
+
}
|
|
8985
|
+
if (REQUIRES_API_KEY.includes(cmd)) {
|
|
8986
|
+
if (!hasApiKey) {
|
|
8919
8987
|
return {
|
|
8920
|
-
output: chalk9.yellow("\
|
|
8988
|
+
output: chalk9.yellow("\u26A0\uFE0F \u8BF7\u5148\u914D\u7F6E API Key") + chalk9.gray("\n\n\u6267\u884C /model \u9009\u62E9\u6A21\u578B\u5E76\u914D\u7F6E API Key")
|
|
8921
8989
|
};
|
|
8922
8990
|
}
|
|
8923
|
-
|
|
8991
|
+
return this.executeSlashCommand(command, ctx);
|
|
8992
|
+
}
|
|
8993
|
+
if (!hasActiveWorkflow) {
|
|
8994
|
+
return {
|
|
8995
|
+
output: chalk9.yellow("\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u5DE5\u4F5C\u6D41") + chalk9.gray("\n\u8BF7\u5148\u4F7F\u7528 ") + chalk9.cyan("/new <\u9700\u6C42\u63CF\u8FF0>") + chalk9.gray(" \u542F\u52A8\u65B0\u5DE5\u4F5C\u6D41")
|
|
8996
|
+
};
|
|
8997
|
+
}
|
|
8998
|
+
return this.executeSlashCommand(command, ctx);
|
|
8999
|
+
}
|
|
9000
|
+
if (command.type === "dollar" /* DOLLAR */) {
|
|
9001
|
+
if (!hasActiveWorkflow) {
|
|
8924
9002
|
return {
|
|
8925
9003
|
output: chalk9.yellow("\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u5DE5\u4F5C\u6D41\uFF0C\u65E0\u6CD5\u8C03\u7528 Agent") + chalk9.gray("\n\u8BF7\u5148\u4F7F\u7528 ") + chalk9.cyan("/new <\u9700\u6C42\u63CF\u8FF0>") + chalk9.gray(" \u542F\u52A8\u65B0\u5DE5\u4F5C\u6D41")
|
|
8926
9004
|
};
|
|
8927
|
-
}
|
|
9005
|
+
}
|
|
9006
|
+
if (!hasApiKey) {
|
|
9007
|
+
return {
|
|
9008
|
+
output: chalk9.yellow("\u26A0\uFE0F \u8BF7\u5148\u914D\u7F6E API Key") + chalk9.gray("\n\n\u6267\u884C /model \u914D\u7F6E\u6A21\u578B")
|
|
9009
|
+
};
|
|
9010
|
+
}
|
|
9011
|
+
return this.executeAgent(command, ctx);
|
|
9012
|
+
}
|
|
9013
|
+
if (command.type === "shell" /* SHELL */) {
|
|
9014
|
+
if (!hasActiveWorkflow) {
|
|
8928
9015
|
return {
|
|
8929
9016
|
output: chalk9.yellow("\u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u5DE5\u4F5C\u6D41\uFF0C\u65E0\u6CD5\u6267\u884C Shell \u547D\u4EE4") + chalk9.gray("\n\u8BF7\u5148\u4F7F\u7528 ") + chalk9.cyan("/new <\u9700\u6C42\u63CF\u8FF0>") + chalk9.gray(" \u542F\u52A8\u65B0\u5DE5\u4F5C\u6D41")
|
|
8930
9017
|
};
|
|
8931
9018
|
}
|
|
9019
|
+
return this.executeShell(command, ctx);
|
|
8932
9020
|
}
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
return this.executeShell(command, ctx);
|
|
8942
|
-
case "natural" /* NATURAL */:
|
|
8943
|
-
return this.executeNaturalLanguage(command, ctx);
|
|
8944
|
-
case "yolo" /* YOLO */:
|
|
8945
|
-
return this.executeYolo(ctx);
|
|
8946
|
-
default:
|
|
8947
|
-
return { output: chalk9.red("\u672A\u77E5\u7684\u547D\u4EE4\u7C7B\u578B") };
|
|
9021
|
+
if (command.type === "at" /* AT */) {
|
|
9022
|
+
return this.executeFileReference(command, ctx);
|
|
9023
|
+
}
|
|
9024
|
+
if (command.type === "natural" /* NATURAL */) {
|
|
9025
|
+
return this.executeNaturalLanguage(command, ctx);
|
|
9026
|
+
}
|
|
9027
|
+
if (command.type === "yolo" /* YOLO */) {
|
|
9028
|
+
return this.executeYolo(ctx);
|
|
8948
9029
|
}
|
|
9030
|
+
return { output: chalk9.red("\u672A\u77E5\u7684\u547D\u4EE4\u7C7B\u578B") };
|
|
8949
9031
|
}
|
|
8950
9032
|
async executeSlashCommand(command, ctx) {
|
|
8951
9033
|
const result = await runSlashCommand(
|