@danya-ai/cli 0.1.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/LICENSE +201 -0
- package/README.md +336 -0
- package/cli-acp.js +82 -0
- package/cli.js +105 -0
- package/dist/REPL-EYUOXCEC.js +42 -0
- package/dist/REPL-EYUOXCEC.js.map +7 -0
- package/dist/acp-S5WNCLMD.js +1372 -0
- package/dist/acp-S5WNCLMD.js.map +7 -0
- package/dist/agentsValidate-RQ2QDGNY.js +373 -0
- package/dist/agentsValidate-RQ2QDGNY.js.map +7 -0
- package/dist/ask-TX526UBD.js +129 -0
- package/dist/ask-TX526UBD.js.map +7 -0
- package/dist/autoUpdater-63RAZ24N.js +17 -0
- package/dist/autoUpdater-63RAZ24N.js.map +7 -0
- package/dist/chunk-2VQWLLDU.js +16 -0
- package/dist/chunk-2VQWLLDU.js.map +7 -0
- package/dist/chunk-4CLHMO4I.js +656 -0
- package/dist/chunk-4CLHMO4I.js.map +7 -0
- package/dist/chunk-4ZNNWJZU.js +5696 -0
- package/dist/chunk-4ZNNWJZU.js.map +7 -0
- package/dist/chunk-66EZC7Y7.js +149 -0
- package/dist/chunk-66EZC7Y7.js.map +7 -0
- package/dist/chunk-6EPQRP3S.js +96 -0
- package/dist/chunk-6EPQRP3S.js.map +7 -0
- package/dist/chunk-77IRSDFR.js +195 -0
- package/dist/chunk-77IRSDFR.js.map +7 -0
- package/dist/chunk-7RZNLBEK.js +136 -0
- package/dist/chunk-7RZNLBEK.js.map +7 -0
- package/dist/chunk-BNBV2FXC.js +19 -0
- package/dist/chunk-BNBV2FXC.js.map +7 -0
- package/dist/chunk-CQCREBDO.js +248 -0
- package/dist/chunk-CQCREBDO.js.map +7 -0
- package/dist/chunk-D77XS6TB.js +74 -0
- package/dist/chunk-D77XS6TB.js.map +7 -0
- package/dist/chunk-DHYBJN3V.js +474 -0
- package/dist/chunk-DHYBJN3V.js.map +7 -0
- package/dist/chunk-DLSLSLTR.js +842 -0
- package/dist/chunk-DLSLSLTR.js.map +7 -0
- package/dist/chunk-ELAE6Z4H.js +514 -0
- package/dist/chunk-ELAE6Z4H.js.map +7 -0
- package/dist/chunk-ELZQD7ZR.js +531 -0
- package/dist/chunk-ELZQD7ZR.js.map +7 -0
- package/dist/chunk-F6DEGMX6.js +31269 -0
- package/dist/chunk-F6DEGMX6.js.map +7 -0
- package/dist/chunk-GDF2AON2.js +124 -0
- package/dist/chunk-GDF2AON2.js.map +7 -0
- package/dist/chunk-H7BGBV4P.js +498 -0
- package/dist/chunk-H7BGBV4P.js.map +7 -0
- package/dist/chunk-HIIHGKXP.js +24 -0
- package/dist/chunk-HIIHGKXP.js.map +7 -0
- package/dist/chunk-HJCCXED7.js +17 -0
- package/dist/chunk-HJCCXED7.js.map +7 -0
- package/dist/chunk-IQ6VZB2Y.js +139 -0
- package/dist/chunk-IQ6VZB2Y.js.map +7 -0
- package/dist/chunk-J4D7AELD.js +518 -0
- package/dist/chunk-J4D7AELD.js.map +7 -0
- package/dist/chunk-JVGG2YQR.js +23 -0
- package/dist/chunk-JVGG2YQR.js.map +7 -0
- package/dist/chunk-LGEK2NV7.js +939 -0
- package/dist/chunk-LGEK2NV7.js.map +7 -0
- package/dist/chunk-LWXT5RGE.js +95 -0
- package/dist/chunk-LWXT5RGE.js.map +7 -0
- package/dist/chunk-M3TKNAUR.js +35 -0
- package/dist/chunk-M3TKNAUR.js.map +7 -0
- package/dist/chunk-MRFO7QO5.js +170 -0
- package/dist/chunk-MRFO7QO5.js.map +7 -0
- package/dist/chunk-MVN3DHQF.js +95 -0
- package/dist/chunk-MVN3DHQF.js.map +7 -0
- package/dist/chunk-O25PXGOC.js +772 -0
- package/dist/chunk-O25PXGOC.js.map +7 -0
- package/dist/chunk-OBGVKM3N.js +1618 -0
- package/dist/chunk-OBGVKM3N.js.map +7 -0
- package/dist/chunk-OV5HJXXQ.js +198 -0
- package/dist/chunk-OV5HJXXQ.js.map +7 -0
- package/dist/chunk-P5VWDMRD.js +249 -0
- package/dist/chunk-P5VWDMRD.js.map +7 -0
- package/dist/chunk-PDSAJX7G.js +49 -0
- package/dist/chunk-PDSAJX7G.js.map +7 -0
- package/dist/chunk-RHNEZOPO.js +739 -0
- package/dist/chunk-RHNEZOPO.js.map +7 -0
- package/dist/chunk-SQGAHZPM.js +3004 -0
- package/dist/chunk-SQGAHZPM.js.map +7 -0
- package/dist/chunk-U7Z4MXY4.js +21 -0
- package/dist/chunk-U7Z4MXY4.js.map +7 -0
- package/dist/chunk-UNCTVIS7.js +146 -0
- package/dist/chunk-UNCTVIS7.js.map +7 -0
- package/dist/chunk-VMEOI6MH.js +1103 -0
- package/dist/chunk-VMEOI6MH.js.map +7 -0
- package/dist/chunk-WAY3DKFO.js +47 -0
- package/dist/chunk-WAY3DKFO.js.map +7 -0
- package/dist/chunk-XEYEKVFT.js +24 -0
- package/dist/chunk-XEYEKVFT.js.map +7 -0
- package/dist/chunk-Y4BQ36T4.js +796 -0
- package/dist/chunk-Y4BQ36T4.js.map +7 -0
- package/dist/chunk-Y5LQPJWK.js +12 -0
- package/dist/chunk-Y5LQPJWK.js.map +7 -0
- package/dist/chunk-YIJWUNWF.js +1260 -0
- package/dist/chunk-YIJWUNWF.js.map +7 -0
- package/dist/chunk-YMIWYEZ7.js +34 -0
- package/dist/chunk-YMIWYEZ7.js.map +7 -0
- package/dist/cli-PQNZWJX4.js +3952 -0
- package/dist/cli-PQNZWJX4.js.map +7 -0
- package/dist/commands-HOBCZ3VQ.js +46 -0
- package/dist/commands-HOBCZ3VQ.js.map +7 -0
- package/dist/config-MLH7ZTFA.js +81 -0
- package/dist/config-MLH7ZTFA.js.map +7 -0
- package/dist/context-FZ6G4J63.js +30 -0
- package/dist/context-FZ6G4J63.js.map +7 -0
- package/dist/costTracker-5WKZXN5S.js +19 -0
- package/dist/costTracker-5WKZXN5S.js.map +7 -0
- package/dist/customCommands-EB4MMZSS.js +25 -0
- package/dist/customCommands-EB4MMZSS.js.map +7 -0
- package/dist/env-VMEIP4EW.js +28 -0
- package/dist/env-VMEIP4EW.js.map +7 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +7 -0
- package/dist/kodeAgentSessionId-WUT74FSH.js +16 -0
- package/dist/kodeAgentSessionId-WUT74FSH.js.map +7 -0
- package/dist/kodeAgentSessionLoad-KR4JSD6D.js +21 -0
- package/dist/kodeAgentSessionLoad-KR4JSD6D.js.map +7 -0
- package/dist/kodeAgentSessionResume-BCD6UV74.js +18 -0
- package/dist/kodeAgentSessionResume-BCD6UV74.js.map +7 -0
- package/dist/kodeAgentStreamJson-EDHHWNNX.js +15 -0
- package/dist/kodeAgentStreamJson-EDHHWNNX.js.map +7 -0
- package/dist/kodeAgentStreamJsonSession-G4RBNZRN.js +133 -0
- package/dist/kodeAgentStreamJsonSession-G4RBNZRN.js.map +7 -0
- package/dist/kodeAgentStructuredStdio-UA5P5UNU.js +11 -0
- package/dist/kodeAgentStructuredStdio-UA5P5UNU.js.map +7 -0
- package/dist/kodeHooks-EHM6GSIQ.js +37 -0
- package/dist/kodeHooks-EHM6GSIQ.js.map +7 -0
- package/dist/llm-SJXCV7DA.js +3138 -0
- package/dist/llm-SJXCV7DA.js.map +7 -0
- package/dist/llmLazy-2QYJVD6K.js +15 -0
- package/dist/llmLazy-2QYJVD6K.js.map +7 -0
- package/dist/loader-LJX77EFL.js +28 -0
- package/dist/loader-LJX77EFL.js.map +7 -0
- package/dist/mcp-DOROSLPN.js +49 -0
- package/dist/mcp-DOROSLPN.js.map +7 -0
- package/dist/mentionProcessor-5UZRHCGH.js +215 -0
- package/dist/mentionProcessor-5UZRHCGH.js.map +7 -0
- package/dist/messages-N5KBI53P.js +65 -0
- package/dist/messages-N5KBI53P.js.map +7 -0
- package/dist/model-HPLBR53R.js +30 -0
- package/dist/model-HPLBR53R.js.map +7 -0
- package/dist/openai-YP4OJYKF.js +29 -0
- package/dist/openai-YP4OJYKF.js.map +7 -0
- package/dist/outputStyles-NNALI5D7.js +28 -0
- package/dist/outputStyles-NNALI5D7.js.map +7 -0
- package/dist/package.json +4 -0
- package/dist/pluginRuntime-JYYI5BSQ.js +220 -0
- package/dist/pluginRuntime-JYYI5BSQ.js.map +7 -0
- package/dist/pluginValidation-JWUFPZUE.js +17 -0
- package/dist/pluginValidation-JWUFPZUE.js.map +7 -0
- package/dist/prompts-B2SS7CWI.js +50 -0
- package/dist/prompts-B2SS7CWI.js.map +7 -0
- package/dist/query-HIK457UU.js +50 -0
- package/dist/query-HIK457UU.js.map +7 -0
- package/dist/responsesStreaming-L2BSN37C.js +10 -0
- package/dist/responsesStreaming-L2BSN37C.js.map +7 -0
- package/dist/ripgrep-GCKI4UTL.js +17 -0
- package/dist/ripgrep-GCKI4UTL.js.map +7 -0
- package/dist/skillMarketplace-PCTUUX46.js +37 -0
- package/dist/skillMarketplace-PCTUUX46.js.map +7 -0
- package/dist/state-XJICGOUA.js +18 -0
- package/dist/state-XJICGOUA.js.map +7 -0
- package/dist/theme-DP7O4SGH.js +14 -0
- package/dist/theme-DP7O4SGH.js.map +7 -0
- package/dist/toolPermissionContext-DHAGUPEW.js +17 -0
- package/dist/toolPermissionContext-DHAGUPEW.js.map +7 -0
- package/dist/toolPermissionSettings-PT65MQIQ.js +18 -0
- package/dist/toolPermissionSettings-PT65MQIQ.js.map +7 -0
- package/dist/tools-BHW37PCF.js +47 -0
- package/dist/tools-BHW37PCF.js.map +7 -0
- package/dist/userInput-XDRYT5TI.js +316 -0
- package/dist/userInput-XDRYT5TI.js.map +7 -0
- package/dist/uuid-QUYJMIUV.js +9 -0
- package/dist/uuid-QUYJMIUV.js.map +7 -0
- package/dist/yoga.wasm +0 -0
- package/package.json +115 -0
- package/scripts/binary-utils.cjs +62 -0
- package/scripts/cli-acp-wrapper.cjs +82 -0
- package/scripts/cli-wrapper.cjs +105 -0
- package/scripts/postinstall.js +144 -0
- package/yoga.wasm +0 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { createRequire as __kodeCreateRequire } from "node:module";
|
|
2
|
+
const require = __kodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
lastX
|
|
5
|
+
} from "./chunk-BNBV2FXC.js";
|
|
6
|
+
import {
|
|
7
|
+
BashTool,
|
|
8
|
+
Spinner,
|
|
9
|
+
UserBashInputMessage,
|
|
10
|
+
getCommand,
|
|
11
|
+
hasCommand
|
|
12
|
+
} from "./chunk-F6DEGMX6.js";
|
|
13
|
+
import "./chunk-OV5HJXXQ.js";
|
|
14
|
+
import "./chunk-OBGVKM3N.js";
|
|
15
|
+
import "./chunk-DHYBJN3V.js";
|
|
16
|
+
import "./chunk-VMEOI6MH.js";
|
|
17
|
+
import "./chunk-IQ6VZB2Y.js";
|
|
18
|
+
import "./chunk-CQCREBDO.js";
|
|
19
|
+
import "./chunk-Y5LQPJWK.js";
|
|
20
|
+
import "./chunk-JVGG2YQR.js";
|
|
21
|
+
import "./chunk-YIJWUNWF.js";
|
|
22
|
+
import "./chunk-U7Z4MXY4.js";
|
|
23
|
+
import "./chunk-ELAE6Z4H.js";
|
|
24
|
+
import "./chunk-LGEK2NV7.js";
|
|
25
|
+
import "./chunk-YMIWYEZ7.js";
|
|
26
|
+
import "./chunk-MRFO7QO5.js";
|
|
27
|
+
import "./chunk-O25PXGOC.js";
|
|
28
|
+
import "./chunk-77IRSDFR.js";
|
|
29
|
+
import "./chunk-66EZC7Y7.js";
|
|
30
|
+
import "./chunk-MVN3DHQF.js";
|
|
31
|
+
import "./chunk-J4D7AELD.js";
|
|
32
|
+
import "./chunk-XEYEKVFT.js";
|
|
33
|
+
import "./chunk-RHNEZOPO.js";
|
|
34
|
+
import "./chunk-WAY3DKFO.js";
|
|
35
|
+
import "./chunk-2VQWLLDU.js";
|
|
36
|
+
import {
|
|
37
|
+
NO_RESPONSE_REQUESTED,
|
|
38
|
+
createAssistantMessage,
|
|
39
|
+
createUserMessage
|
|
40
|
+
} from "./chunk-H7BGBV4P.js";
|
|
41
|
+
import "./chunk-4CLHMO4I.js";
|
|
42
|
+
import "./chunk-ELZQD7ZR.js";
|
|
43
|
+
import "./chunk-GDF2AON2.js";
|
|
44
|
+
import "./chunk-DLSLSLTR.js";
|
|
45
|
+
import {
|
|
46
|
+
MalformedCommandError
|
|
47
|
+
} from "./chunk-HIIHGKXP.js";
|
|
48
|
+
import "./chunk-Y4BQ36T4.js";
|
|
49
|
+
import {
|
|
50
|
+
getCwd,
|
|
51
|
+
init_log,
|
|
52
|
+
init_state,
|
|
53
|
+
logError,
|
|
54
|
+
setCwd
|
|
55
|
+
} from "./chunk-SQGAHZPM.js";
|
|
56
|
+
import "./chunk-UNCTVIS7.js";
|
|
57
|
+
import "./chunk-LWXT5RGE.js";
|
|
58
|
+
import "./chunk-M3TKNAUR.js";
|
|
59
|
+
|
|
60
|
+
// src/utils/messages/userInput.tsx
|
|
61
|
+
import { Box } from "ink";
|
|
62
|
+
init_log();
|
|
63
|
+
import { resolve } from "path";
|
|
64
|
+
init_state();
|
|
65
|
+
init_state();
|
|
66
|
+
import chalk from "chalk";
|
|
67
|
+
import * as React from "react";
|
|
68
|
+
async function processUserInput(input, mode, setToolJSX, context, pastedImages) {
|
|
69
|
+
if (mode === "bash") {
|
|
70
|
+
const userMessage2 = createUserMessage(`<bash-input>${input}</bash-input>`);
|
|
71
|
+
if (input.startsWith("cd ")) {
|
|
72
|
+
const oldCwd = getCwd();
|
|
73
|
+
const newCwd = resolve(getCwd(), input.slice(3).trim());
|
|
74
|
+
try {
|
|
75
|
+
await setCwd(newCwd);
|
|
76
|
+
return [
|
|
77
|
+
userMessage2,
|
|
78
|
+
createAssistantMessage(
|
|
79
|
+
`<bash-stdout>Changed directory to ${chalk.bold(`${newCwd}/`)}</bash-stdout>`
|
|
80
|
+
)
|
|
81
|
+
];
|
|
82
|
+
} catch (e) {
|
|
83
|
+
logError(e);
|
|
84
|
+
return [
|
|
85
|
+
userMessage2,
|
|
86
|
+
createAssistantMessage(
|
|
87
|
+
`<bash-stderr>cwd error: ${e instanceof Error ? e.message : String(e)}</bash-stderr>`
|
|
88
|
+
)
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
setToolJSX({
|
|
93
|
+
jsx: /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(
|
|
94
|
+
UserBashInputMessage,
|
|
95
|
+
{
|
|
96
|
+
addMargin: false,
|
|
97
|
+
param: { text: `<bash-input>${input}</bash-input>`, type: "text" }
|
|
98
|
+
}
|
|
99
|
+
), /* @__PURE__ */ React.createElement(Spinner, null)),
|
|
100
|
+
shouldHidePromptInput: false
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
const validationResult = await BashTool.validateInput(
|
|
104
|
+
{ command: input },
|
|
105
|
+
{ commandSource: "user_bash_mode" }
|
|
106
|
+
);
|
|
107
|
+
if (!validationResult.result) {
|
|
108
|
+
return [userMessage2, createAssistantMessage(validationResult.message)];
|
|
109
|
+
}
|
|
110
|
+
const { data } = await lastX(
|
|
111
|
+
BashTool.call({ command: input }, {
|
|
112
|
+
...context,
|
|
113
|
+
commandSource: "user_bash_mode"
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
return [
|
|
117
|
+
userMessage2,
|
|
118
|
+
createAssistantMessage(
|
|
119
|
+
`<bash-stdout>${data.stdout}</bash-stdout><bash-stderr>${data.stderr}</bash-stderr>`
|
|
120
|
+
)
|
|
121
|
+
];
|
|
122
|
+
} catch (e) {
|
|
123
|
+
return [
|
|
124
|
+
userMessage2,
|
|
125
|
+
createAssistantMessage(
|
|
126
|
+
`<bash-stderr>Command failed: ${e instanceof Error ? e.message : String(e)}</bash-stderr>`
|
|
127
|
+
)
|
|
128
|
+
];
|
|
129
|
+
} finally {
|
|
130
|
+
setToolJSX(null);
|
|
131
|
+
}
|
|
132
|
+
} else if (mode === "koding") {
|
|
133
|
+
const userMessage2 = createUserMessage(
|
|
134
|
+
`<koding-input>${input}</koding-input>`
|
|
135
|
+
);
|
|
136
|
+
userMessage2.options = {
|
|
137
|
+
...userMessage2.options,
|
|
138
|
+
isKodingRequest: true
|
|
139
|
+
};
|
|
140
|
+
return [userMessage2];
|
|
141
|
+
}
|
|
142
|
+
if (context.options?.disableSlashCommands !== true && input.startsWith("/")) {
|
|
143
|
+
const words = input.slice(1).split(" ");
|
|
144
|
+
let commandName = words[0];
|
|
145
|
+
if (words.length > 1 && words[1] === "(MCP)") {
|
|
146
|
+
commandName = commandName + " (MCP)";
|
|
147
|
+
}
|
|
148
|
+
if (!commandName) {
|
|
149
|
+
return [
|
|
150
|
+
createAssistantMessage("Commands are in the form `/command [args]`")
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
if (!hasCommand(commandName, context.options.commands)) {
|
|
154
|
+
return [createUserMessage(input)];
|
|
155
|
+
}
|
|
156
|
+
const args = input.slice(commandName.length + 2);
|
|
157
|
+
const newMessages = await getMessagesForSlashCommand(
|
|
158
|
+
commandName,
|
|
159
|
+
args,
|
|
160
|
+
setToolJSX,
|
|
161
|
+
context
|
|
162
|
+
);
|
|
163
|
+
if (newMessages.length === 0) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
if (newMessages.length === 2 && newMessages[0].type === "user" && newMessages[1].type === "assistant" && typeof newMessages[1].message.content === "string" && newMessages[1].message.content.startsWith("Unknown command:")) {
|
|
167
|
+
return newMessages;
|
|
168
|
+
}
|
|
169
|
+
if (newMessages.length === 2) {
|
|
170
|
+
return newMessages;
|
|
171
|
+
}
|
|
172
|
+
return newMessages;
|
|
173
|
+
}
|
|
174
|
+
const isKodingRequest = context.options?.isKodingRequest === true;
|
|
175
|
+
const kodingContextInfo = context.options?.kodingContext;
|
|
176
|
+
let userMessage;
|
|
177
|
+
let processedInput = isKodingRequest && kodingContextInfo ? `${kodingContextInfo}
|
|
178
|
+
|
|
179
|
+
${input}` : input;
|
|
180
|
+
if (processedInput.includes("!`") || processedInput.includes("@")) {
|
|
181
|
+
try {
|
|
182
|
+
const { executeBashCommands } = await import("./customCommands-EB4MMZSS.js");
|
|
183
|
+
if (processedInput.includes("!`")) {
|
|
184
|
+
processedInput = await executeBashCommands(processedInput);
|
|
185
|
+
}
|
|
186
|
+
if (processedInput.includes("@")) {
|
|
187
|
+
const { processMentions } = await import("./mentionProcessor-5UZRHCGH.js");
|
|
188
|
+
await processMentions(processedInput);
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
logError(error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (pastedImages && pastedImages.length > 0) {
|
|
195
|
+
const occurrences = pastedImages.map((img) => ({ img, index: processedInput.indexOf(img.placeholder) })).filter((o) => o.index >= 0).sort((a, b) => a.index - b.index);
|
|
196
|
+
const blocks = [];
|
|
197
|
+
let cursor = 0;
|
|
198
|
+
for (const { img, index } of occurrences) {
|
|
199
|
+
const before = processedInput.slice(cursor, index);
|
|
200
|
+
if (before) {
|
|
201
|
+
blocks.push({ type: "text", text: before });
|
|
202
|
+
}
|
|
203
|
+
blocks.push({
|
|
204
|
+
type: "image",
|
|
205
|
+
source: {
|
|
206
|
+
type: "base64",
|
|
207
|
+
media_type: img.mediaType,
|
|
208
|
+
data: img.data
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
cursor = index + img.placeholder.length;
|
|
212
|
+
}
|
|
213
|
+
const after = processedInput.slice(cursor);
|
|
214
|
+
if (after) {
|
|
215
|
+
blocks.push({ type: "text", text: after });
|
|
216
|
+
}
|
|
217
|
+
if (!blocks.some((b) => b.type === "text")) {
|
|
218
|
+
blocks.push({ type: "text", text: "" });
|
|
219
|
+
}
|
|
220
|
+
userMessage = createUserMessage(blocks);
|
|
221
|
+
} else {
|
|
222
|
+
userMessage = createUserMessage(processedInput);
|
|
223
|
+
}
|
|
224
|
+
if (isKodingRequest) {
|
|
225
|
+
userMessage.options = {
|
|
226
|
+
...userMessage.options,
|
|
227
|
+
isKodingRequest: true
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return [userMessage];
|
|
231
|
+
}
|
|
232
|
+
async function getMessagesForSlashCommand(commandName, args, setToolJSX, context) {
|
|
233
|
+
try {
|
|
234
|
+
const command = getCommand(commandName, context.options.commands);
|
|
235
|
+
switch (command.type) {
|
|
236
|
+
case "local-jsx": {
|
|
237
|
+
return new Promise((resolve2) => {
|
|
238
|
+
command.call(
|
|
239
|
+
(r) => {
|
|
240
|
+
setToolJSX(null);
|
|
241
|
+
resolve2([
|
|
242
|
+
createUserMessage(`<command-name>${command.userFacingName()}</command-name>
|
|
243
|
+
<command-message>${command.userFacingName()}</command-message>
|
|
244
|
+
<command-args>${args}</command-args>`),
|
|
245
|
+
r ? createAssistantMessage(r) : createAssistantMessage(NO_RESPONSE_REQUESTED)
|
|
246
|
+
]);
|
|
247
|
+
},
|
|
248
|
+
context,
|
|
249
|
+
args
|
|
250
|
+
).then((jsx) => {
|
|
251
|
+
if (!jsx) return;
|
|
252
|
+
setToolJSX({ jsx, shouldHidePromptInput: true });
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
case "local": {
|
|
257
|
+
const userMessage = createUserMessage(`<command-name>${command.userFacingName()}</command-name>
|
|
258
|
+
<command-message>${command.userFacingName()}</command-message>
|
|
259
|
+
<command-args>${args}</command-args>`);
|
|
260
|
+
try {
|
|
261
|
+
const result = await command.call(args, {
|
|
262
|
+
...context,
|
|
263
|
+
options: {
|
|
264
|
+
commands: context.options.commands || [],
|
|
265
|
+
tools: context.options.tools || [],
|
|
266
|
+
slowAndCapableModel: context.options.slowAndCapableModel || "main"
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
return [
|
|
270
|
+
userMessage,
|
|
271
|
+
createAssistantMessage(
|
|
272
|
+
`<local-command-stdout>${result}</local-command-stdout>`
|
|
273
|
+
)
|
|
274
|
+
];
|
|
275
|
+
} catch (e) {
|
|
276
|
+
logError(e);
|
|
277
|
+
return [
|
|
278
|
+
userMessage,
|
|
279
|
+
createAssistantMessage(
|
|
280
|
+
`<local-command-stderr>${String(e)}</local-command-stderr>`
|
|
281
|
+
)
|
|
282
|
+
];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
case "prompt": {
|
|
286
|
+
const commandName2 = command.userFacingName();
|
|
287
|
+
const progressMessage = command.progressMessage || "running";
|
|
288
|
+
const metaMessage = createUserMessage(`<command-name>${commandName2}</command-name>
|
|
289
|
+
<command-message>${commandName2} is ${progressMessage}\u2026</command-message>
|
|
290
|
+
<command-args>${args}</command-args>`);
|
|
291
|
+
const prompt = await command.getPromptForCommand(args);
|
|
292
|
+
const expandedMessages = prompt.map((msg) => {
|
|
293
|
+
const userMessage = createUserMessage(
|
|
294
|
+
typeof msg.content === "string" ? msg.content : msg.content.map((block) => block.type === "text" ? block.text : "").join("\n")
|
|
295
|
+
);
|
|
296
|
+
userMessage.options = {
|
|
297
|
+
...userMessage.options,
|
|
298
|
+
isCustomCommand: true,
|
|
299
|
+
commandName: command.userFacingName(),
|
|
300
|
+
commandArgs: args
|
|
301
|
+
};
|
|
302
|
+
return userMessage;
|
|
303
|
+
});
|
|
304
|
+
return [metaMessage, ...expandedMessages];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
} catch (e) {
|
|
308
|
+
if (e instanceof MalformedCommandError) {
|
|
309
|
+
return [createAssistantMessage(e.message)];
|
|
310
|
+
}
|
|
311
|
+
throw e;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
export {
|
|
315
|
+
processUserInput
|
|
316
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/utils/messages/userInput.tsx"],
|
|
4
|
+
"sourcesContent": ["import { Box } from 'ink'\r\nimport { getCommand, hasCommand } from '@commands'\r\nimport { MalformedCommandError } from '@utils/text/errors'\r\nimport { logError } from '@utils/log'\r\nimport { resolve } from 'path'\r\nimport { lastX } from '@utils/text/generators'\r\nimport type { SetToolJSXFn, ToolUseContext } from '@tool'\r\nimport type { ContentBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'\r\nimport { setCwd } from '@utils/state'\r\nimport { getCwd } from '@utils/state'\r\nimport chalk from 'chalk'\r\nimport * as React from 'react'\r\nimport { UserBashInputMessage } from '@components/messages/UserBashInputMessage'\r\nimport { Spinner } from '@components/Spinner'\r\nimport { BashTool } from '@tools/BashTool/BashTool'\r\nimport type { Message, UserMessage } from '@query'\r\nimport { NO_RESPONSE_REQUESTED, createAssistantMessage, createUserMessage } from './core'\r\n\r\n\r\nexport async function processUserInput(\r\n input: string,\r\n mode: 'bash' | 'prompt' | 'koding',\r\n setToolJSX: SetToolJSXFn,\r\n context: ToolUseContext & {\r\n setForkConvoWithMessagesOnTheNextRender: (\r\n forkConvoWithMessages: Message[],\r\n ) => void\r\n options?: {\r\n isKodingRequest?: boolean\r\n kodingContext?: string\r\n }\r\n },\r\n pastedImages: Array<{\r\n placeholder: string\r\n data: string\r\n mediaType: string\r\n }> | null,\r\n): Promise<Message[]> {\r\n if (mode === 'bash') {\r\n const userMessage = createUserMessage(`<bash-input>${input}</bash-input>`)\r\n\r\n if (input.startsWith('cd ')) {\r\n const oldCwd = getCwd()\r\n const newCwd = resolve(getCwd(), input.slice(3).trim())\r\n try {\r\n await setCwd(newCwd)\r\n return [\r\n userMessage,\r\n createAssistantMessage(\r\n `<bash-stdout>Changed directory to ${chalk.bold(`${newCwd}/`)}</bash-stdout>`,\r\n ),\r\n ]\r\n } catch (e) {\r\n logError(e)\r\n return [\r\n userMessage,\r\n createAssistantMessage(\r\n `<bash-stderr>cwd error: ${e instanceof Error ? e.message : String(e)}</bash-stderr>`,\r\n ),\r\n ]\r\n }\r\n }\r\n\r\n setToolJSX({\r\n jsx: (\r\n <Box flexDirection=\"column\" marginTop={1}>\r\n <UserBashInputMessage\r\n addMargin={false}\r\n param={{ text: `<bash-input>${input}</bash-input>`, type: 'text' }}\r\n />\r\n <Spinner />\r\n </Box>\r\n ),\r\n shouldHidePromptInput: false,\r\n })\r\n try {\r\n const validationResult = await BashTool.validateInput(\r\n { command: input },\r\n { commandSource: 'user_bash_mode' } as any,\r\n )\r\n if (!validationResult.result) {\r\n return [userMessage, createAssistantMessage(validationResult.message)]\r\n }\r\n const { data } = await lastX(\r\n BashTool.call({ command: input }, {\r\n ...(context as any),\r\n commandSource: 'user_bash_mode',\r\n } as any),\r\n )\r\n return [\r\n userMessage,\r\n createAssistantMessage(\r\n `<bash-stdout>${data.stdout}</bash-stdout><bash-stderr>${data.stderr}</bash-stderr>`,\r\n ),\r\n ]\r\n } catch (e) {\r\n return [\r\n userMessage,\r\n createAssistantMessage(\r\n `<bash-stderr>Command failed: ${e instanceof Error ? e.message : String(e)}</bash-stderr>`,\r\n ),\r\n ]\r\n } finally {\r\n setToolJSX(null)\r\n }\r\n }\r\n else if (mode === 'koding') {\r\n const userMessage = createUserMessage(\r\n `<koding-input>${input}</koding-input>`,\r\n )\r\n userMessage.options = {\r\n ...userMessage.options,\r\n isKodingRequest: true,\r\n }\r\n\r\n return [userMessage]\r\n }\r\n\r\n if (context.options?.disableSlashCommands !== true && input.startsWith('/')) {\r\n const words = input.slice(1).split(' ')\r\n let commandName = words[0]\r\n if (words.length > 1 && words[1] === '(MCP)') {\r\n commandName = commandName + ' (MCP)'\r\n }\r\n if (!commandName) {\r\n return [\r\n createAssistantMessage('Commands are in the form `/command [args]`'),\r\n ]\r\n }\r\n\r\n if (!hasCommand(commandName, context.options.commands)) {\r\n\r\n return [createUserMessage(input)]\r\n }\r\n\r\n const args = input.slice(commandName.length + 2)\r\n const newMessages = await getMessagesForSlashCommand(\r\n commandName,\r\n args,\r\n setToolJSX,\r\n context,\r\n )\r\n\r\n if (newMessages.length === 0) {\r\n return []\r\n }\r\n\r\n if (\r\n newMessages.length === 2 &&\r\n newMessages[0]!.type === 'user' &&\r\n newMessages[1]!.type === 'assistant' &&\r\n typeof newMessages[1]!.message.content === 'string' &&\r\n newMessages[1]!.message.content.startsWith('Unknown command:')\r\n ) {\r\n return newMessages\r\n }\r\n\r\n if (newMessages.length === 2) {\r\n return newMessages\r\n }\r\n\r\n\r\n return newMessages\r\n }\r\n\r\n\r\n const isKodingRequest = context.options?.isKodingRequest === true\r\n const kodingContextInfo = context.options?.kodingContext\r\n\r\n let userMessage: UserMessage\r\n\r\n let processedInput =\r\n isKodingRequest && kodingContextInfo\r\n ? `${kodingContextInfo}\\n\\n${input}`\r\n : input\r\n\r\n if (processedInput.includes('!`') || processedInput.includes('@')) {\r\n try {\r\n const { executeBashCommands } = await import('@services/customCommands')\r\n\r\n if (processedInput.includes('!`')) {\r\n processedInput = await executeBashCommands(processedInput)\r\n }\r\n\r\n if (processedInput.includes('@')) {\r\n const { processMentions } = await import('@services/mentionProcessor')\r\n await processMentions(processedInput)\r\n }\r\n } catch (error) {\r\n logError(error)\r\n }\r\n }\r\n\r\n if (pastedImages && pastedImages.length > 0) {\r\n const occurrences = pastedImages\r\n .map(img => ({ img, index: processedInput.indexOf(img.placeholder) }))\r\n .filter(o => o.index >= 0)\r\n .sort((a, b) => a.index - b.index)\r\n\r\n const blocks: ContentBlockParam[] = []\r\n let cursor = 0\r\n\r\n for (const { img, index } of occurrences) {\r\n const before = processedInput.slice(cursor, index)\r\n if (before) {\r\n blocks.push({ type: 'text', text: before })\r\n }\r\n blocks.push({\r\n type: 'image',\r\n source: {\r\n type: 'base64',\r\n media_type: img.mediaType,\r\n data: img.data,\r\n },\r\n } as any)\r\n cursor = index + img.placeholder.length\r\n }\r\n\r\n const after = processedInput.slice(cursor)\r\n if (after) {\r\n blocks.push({ type: 'text', text: after })\r\n }\r\n\r\n if (!blocks.some(b => b.type === 'text')) {\r\n blocks.push({ type: 'text', text: '' })\r\n }\r\n\r\n userMessage = createUserMessage(blocks)\r\n } else {\r\n userMessage = createUserMessage(processedInput)\r\n }\r\n\r\n if (isKodingRequest) {\r\n userMessage.options = {\r\n ...userMessage.options,\r\n isKodingRequest: true,\r\n }\r\n }\r\n\r\n return [userMessage]\r\n}\r\n\r\nasync function getMessagesForSlashCommand(\r\n commandName: string,\r\n args: string,\r\n setToolJSX: SetToolJSXFn,\r\n context: ToolUseContext & {\r\n setForkConvoWithMessagesOnTheNextRender: (\r\n forkConvoWithMessages: Message[],\r\n ) => void\r\n },\r\n): Promise<Message[]> {\r\n try {\r\n const command = getCommand(commandName, context.options.commands)\r\n switch (command.type) {\r\n case 'local-jsx': {\r\n return new Promise(resolve => {\r\n command\r\n .call(\r\n r => {\r\n setToolJSX(null)\r\n resolve([\r\n createUserMessage(`<command-name>${command.userFacingName()}</command-name>\r\n <command-message>${command.userFacingName()}</command-message>\r\n <command-args>${args}</command-args>`),\r\n r\r\n ? createAssistantMessage(r)\r\n : createAssistantMessage(NO_RESPONSE_REQUESTED),\r\n ])\r\n },\r\n context,\r\n args,\r\n )\r\n .then(jsx => {\r\n if (!jsx) return\r\n setToolJSX({ jsx, shouldHidePromptInput: true })\r\n })\r\n })\r\n }\r\n case 'local': {\r\n const userMessage =\r\n createUserMessage(`<command-name>${command.userFacingName()}</command-name>\r\n <command-message>${command.userFacingName()}</command-message>\r\n <command-args>${args}</command-args>`)\r\n\r\n try {\r\n const result = await command.call(args, {\r\n ...context,\r\n options: {\r\n commands: context.options.commands || [],\r\n tools: context.options.tools || [],\r\n slowAndCapableModel:\r\n context.options.slowAndCapableModel || 'main',\r\n },\r\n })\r\n\r\n return [\r\n userMessage,\r\n createAssistantMessage(\r\n `<local-command-stdout>${result}</local-command-stdout>`,\r\n ),\r\n ]\r\n } catch (e) {\r\n logError(e)\r\n return [\r\n userMessage,\r\n createAssistantMessage(\r\n `<local-command-stderr>${String(e)}</local-command-stderr>`,\r\n ),\r\n ]\r\n }\r\n }\r\n case 'prompt': {\r\n const commandName = command.userFacingName()\r\n const progressMessage = (command as any).progressMessage || 'running'\r\n const metaMessage =\r\n createUserMessage(`<command-name>${commandName}</command-name>\r\n <command-message>${commandName} is ${progressMessage}\u2026</command-message>\r\n <command-args>${args}</command-args>`)\r\n\r\n const prompt = await command.getPromptForCommand(args)\r\n const expandedMessages = prompt.map(msg => {\r\n const userMessage = createUserMessage(\r\n typeof msg.content === 'string'\r\n ? msg.content\r\n : msg.content\r\n .map(block => (block.type === 'text' ? block.text : ''))\r\n .join('\\n'),\r\n )\r\n\r\n userMessage.options = {\r\n ...userMessage.options,\r\n isCustomCommand: true,\r\n commandName: command.userFacingName(),\r\n commandArgs: args,\r\n }\r\n\r\n return userMessage\r\n })\r\n\r\n return [metaMessage, ...expandedMessages]\r\n }\r\n }\r\n } catch (e) {\r\n if (e instanceof MalformedCommandError) {\r\n return [createAssistantMessage(e.message)]\r\n }\r\n throw e\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW;AAGpB;AACA,SAAS,eAAe;AAIxB;AACA;AACA,OAAO,WAAW;AAClB,YAAY,WAAW;AAQvB,eAAsB,iBACpB,OACA,MACA,YACA,SASA,cAKoB;AACpB,MAAI,SAAS,QAAQ;AACnB,UAAMA,eAAc,kBAAkB,eAAe,KAAK,eAAe;AAEzE,QAAI,MAAM,WAAW,KAAK,GAAG;AAC3B,YAAM,SAAS,OAAO;AACtB,YAAM,SAAS,QAAQ,OAAO,GAAG,MAAM,MAAM,CAAC,EAAE,KAAK,CAAC;AACtD,UAAI;AACF,cAAM,OAAO,MAAM;AACnB,eAAO;AAAA,UACLA;AAAA,UACA;AAAA,YACE,qCAAqC,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC;AAAA,UAC/D;AAAA,QACF;AAAA,MACF,SAAS,GAAG;AACV,iBAAS,CAAC;AACV,eAAO;AAAA,UACLA;AAAA,UACA;AAAA,YACE,2BAA2B,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;AAAA,UACvE;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,eAAW;AAAA,MACT,KACE,oCAAC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,eAAc,QAAQ,eAAe;AAC3C,cAAM,kBAAmB,QAAgB,mBAAmB;AAC5D,cAAM,cACJ,kBAAkB,iBAAiBA,YAAW;AAAA,2BAC7BA,YAAW,OAAO,eAAe;AAAA,wBACpC,IAAI,iBAAiB;AAErC,cAAM,SAAS,MAAM,QAAQ,oBAAoB,IAAI;AACrD,cAAM,mBAAmB,OAAO,IAAI,SAAO;AACzC,gBAAM,cAAc;AAAA,YAClB,OAAO,IAAI,YAAY,WACnB,IAAI,UACJ,IAAI,QACD,IAAI,WAAU,MAAM,SAAS,SAAS,MAAM,OAAO,EAAG,EACtD,KAAK,IAAI;AAAA,UAClB;AAEA,sBAAY,UAAU;AAAA,YACpB,GAAG,YAAY;AAAA,YACf,iBAAiB;AAAA,YACjB,aAAa,QAAQ,eAAe;AAAA,YACpC,aAAa;AAAA,UACf;AAEA,iBAAO;AAAA,QACT,CAAC;AAED,eAAO,CAAC,aAAa,GAAG,gBAAgB;AAAA,MAC1C;AAAA,IACF;AAAA,EACF,SAAS,GAAG;AACV,QAAI,aAAa,uBAAuB;AACtC,aAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC;AAAA,IAC3C;AACA,UAAM;AAAA,EACR;AACF;",
|
|
6
|
+
"names": ["userMessage", "resolve", "commandName"]
|
|
7
|
+
}
|
package/dist/yoga.wasm
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@danya-ai/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"bin": {
|
|
5
|
+
"danya": "cli.js"
|
|
6
|
+
},
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.18.1"
|
|
9
|
+
},
|
|
10
|
+
"main": "cli.js",
|
|
11
|
+
"author": "Danya Team",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"description": "AI-powered game development coding assistant. Understands game engines, enforces quality gates, and automates development workflows.",
|
|
14
|
+
"homepage": "https://github.com/danya-game/danya",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/danya-game/danya.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/danya-game/danya/issues"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"cli.js",
|
|
24
|
+
"cli-acp.js",
|
|
25
|
+
"yoga.wasm",
|
|
26
|
+
"dist/**/*",
|
|
27
|
+
"scripts/binary-utils.cjs",
|
|
28
|
+
"scripts/cli-wrapper.cjs",
|
|
29
|
+
"scripts/cli-acp-wrapper.cjs",
|
|
30
|
+
"scripts/postinstall.js",
|
|
31
|
+
".npmrc"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "bun run ./src/entrypoints/cli.tsx --verbose",
|
|
35
|
+
"build:npm": "bun run scripts/build.mjs",
|
|
36
|
+
"build": "bun run build:npm",
|
|
37
|
+
"build:binary": "bun run scripts/build-binary.mjs",
|
|
38
|
+
"clean": "bun run scripts/clean.mjs",
|
|
39
|
+
"prepublishOnly": "bun run build:npm && bun run scripts/prepublish-check.js",
|
|
40
|
+
"postinstall": "node scripts/postinstall.js || true",
|
|
41
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json}\" \"tests/**/*.{ts,tsx,js,jsx,json}\"",
|
|
42
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json}\" \"tests/**/*.{ts,tsx,js,jsx,json}\"",
|
|
43
|
+
"lint": "eslint . --ext .ts,.tsx,.js --max-warnings 0",
|
|
44
|
+
"lint:fix": "eslint . --ext .ts,.tsx,.js --fix",
|
|
45
|
+
"test": "bun test",
|
|
46
|
+
"test:unit": "bun test tests/unit",
|
|
47
|
+
"test:integration": "bun test tests/integration",
|
|
48
|
+
"test:e2e": "bun test tests/e2e",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"typecheck:game": "tsc --noEmit --project tsconfig.game.json"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@anthropic-ai/sdk": "^0.39.0",
|
|
54
|
+
"@commander-js/extra-typings": "^13.1.0",
|
|
55
|
+
"@inkjs/ui": "^2.0.0",
|
|
56
|
+
"@modelcontextprotocol/sdk": "^1.15.1",
|
|
57
|
+
"@types/lodash-es": "^4.17.12",
|
|
58
|
+
"@types/react": "^19.1.8",
|
|
59
|
+
"@vscode/ripgrep": "^1.17.0",
|
|
60
|
+
"ajv": "^8.17.1",
|
|
61
|
+
"ansi-escapes": "^7.0.0",
|
|
62
|
+
"chalk": "^5.4.1",
|
|
63
|
+
"cli-highlight": "^2.1.11",
|
|
64
|
+
"cli-table3": "^0.6.5",
|
|
65
|
+
"commander": "^13.1.0",
|
|
66
|
+
"debug": "^4.4.1",
|
|
67
|
+
"diff": "^7.0.0",
|
|
68
|
+
"dotenv": "^16.6.1",
|
|
69
|
+
"env-paths": "^3.0.0",
|
|
70
|
+
"fflate": "^0.8.2",
|
|
71
|
+
"figures": "^6.1.0",
|
|
72
|
+
"glob": "^11.0.3",
|
|
73
|
+
"gray-matter": "^4.0.3",
|
|
74
|
+
"highlight.js": "^11.11.1",
|
|
75
|
+
"ignore": "^7.0.5",
|
|
76
|
+
"ink": "5.2.1",
|
|
77
|
+
"ink-link": "^4.1.0",
|
|
78
|
+
"ink-select-input": "^6.2.0",
|
|
79
|
+
"ink-text-input": "^6.0.0",
|
|
80
|
+
"js-yaml": "^4.1.1",
|
|
81
|
+
"lodash-es": "^4.17.21",
|
|
82
|
+
"lru-cache": "^11.1.0",
|
|
83
|
+
"marked": "^15.0.12",
|
|
84
|
+
"minimatch": "^10.1.1",
|
|
85
|
+
"nanoid": "^5.1.5",
|
|
86
|
+
"node-html-parser": "^7.0.1",
|
|
87
|
+
"openai": "^4.104.0",
|
|
88
|
+
"react": "18.3.1",
|
|
89
|
+
"semver": "^7.7.2",
|
|
90
|
+
"shell-quote": "^1.8.3",
|
|
91
|
+
"spawn-rx": "^5.1.2",
|
|
92
|
+
"string-width": "^7.2.0",
|
|
93
|
+
"strip-ansi": "^7.1.0",
|
|
94
|
+
"turndown": "^7.2.0",
|
|
95
|
+
"which": "^6.0.0",
|
|
96
|
+
"wrap-ansi": "^9.0.0",
|
|
97
|
+
"zod": "^3.25.76",
|
|
98
|
+
"zod-to-json-schema": "^3.24.6"
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"@types/bun": "latest",
|
|
102
|
+
"@types/jest": "^30.0.0",
|
|
103
|
+
"@types/node": "^24.1.0",
|
|
104
|
+
"@types/which": "^3.0.4",
|
|
105
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
106
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
107
|
+
"bun-types": "latest",
|
|
108
|
+
"esbuild": "^0.25.9",
|
|
109
|
+
"eslint": "8.57.0",
|
|
110
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
111
|
+
"prettier": "^3.6.2",
|
|
112
|
+
"react-devtools-core": "^7.0.1",
|
|
113
|
+
"typescript": "^5.9.2"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const os = require('node:os')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
|
|
4
|
+
function getPlatformArch(platform = process.platform, arch = process.arch) {
|
|
5
|
+
return `${platform}-${arch}`
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getBinaryFilename(platform = process.platform) {
|
|
9
|
+
return platform === 'win32' ? 'kode.exe' : 'kode'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getDefaultBinBaseDir() {
|
|
13
|
+
return (
|
|
14
|
+
process.env.KODE_BIN_DIR ||
|
|
15
|
+
process.env.ANYKODE_BIN_DIR ||
|
|
16
|
+
path.join(os.homedir(), '.kode', 'bin')
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getCachedBinaryPath(options) {
|
|
21
|
+
const version = options?.version
|
|
22
|
+
const platform = options?.platform ?? process.platform
|
|
23
|
+
const arch = options?.arch ?? process.arch
|
|
24
|
+
const baseDir = options?.baseDir ?? getDefaultBinBaseDir()
|
|
25
|
+
if (!version) throw new Error('getCachedBinaryPath: version is required')
|
|
26
|
+
|
|
27
|
+
return path.join(baseDir, version, getPlatformArch(platform, arch), getBinaryFilename(platform))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getGithubReleaseBinaryAssetName(platform = process.platform, arch = process.arch) {
|
|
31
|
+
const ext = platform === 'win32' ? '.exe' : ''
|
|
32
|
+
return `kode-${platform}-${arch}${ext}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getGithubReleaseBinaryUrl(options) {
|
|
36
|
+
const version = options?.version
|
|
37
|
+
const platform = options?.platform ?? process.platform
|
|
38
|
+
const arch = options?.arch ?? process.arch
|
|
39
|
+
const owner = options?.owner ?? 'shareAI-lab'
|
|
40
|
+
const repo = options?.repo ?? 'kode'
|
|
41
|
+
const tag = options?.tag ?? `v${version}`
|
|
42
|
+
const baseUrl = options?.baseUrl ?? process.env.KODE_BINARY_BASE_URL
|
|
43
|
+
|
|
44
|
+
if (!version) throw new Error('getGithubReleaseBinaryUrl: version is required')
|
|
45
|
+
|
|
46
|
+
if (baseUrl) {
|
|
47
|
+
const trimmed = String(baseUrl).replace(/\/+$/, '')
|
|
48
|
+
return `${trimmed}/${getGithubReleaseBinaryAssetName(platform, arch)}`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return `https://github.com/${owner}/${repo}/releases/download/${tag}/${getGithubReleaseBinaryAssetName(platform, arch)}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
getPlatformArch,
|
|
56
|
+
getBinaryFilename,
|
|
57
|
+
getDefaultBinBaseDir,
|
|
58
|
+
getCachedBinaryPath,
|
|
59
|
+
getGithubReleaseBinaryAssetName,
|
|
60
|
+
getGithubReleaseBinaryUrl,
|
|
61
|
+
}
|
|
62
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs')
|
|
4
|
+
const path = require('node:path')
|
|
5
|
+
const { spawnSync } = require('node:child_process')
|
|
6
|
+
|
|
7
|
+
function findPackageRoot(startDir) {
|
|
8
|
+
let dir = startDir
|
|
9
|
+
for (let i = 0; i < 25; i++) {
|
|
10
|
+
if (fs.existsSync(path.join(dir, 'package.json'))) return dir
|
|
11
|
+
const parent = path.dirname(dir)
|
|
12
|
+
if (parent === dir) break
|
|
13
|
+
dir = parent
|
|
14
|
+
}
|
|
15
|
+
return startDir
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function readPackageJson(packageRoot) {
|
|
19
|
+
try {
|
|
20
|
+
const p = path.join(packageRoot, 'package.json')
|
|
21
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'))
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function run(cmd, args) {
|
|
28
|
+
const result = spawnSync(cmd, args, {
|
|
29
|
+
stdio: 'inherit',
|
|
30
|
+
env: { ...process.env, KODE_PACKAGED: process.env.KODE_PACKAGED || '1' },
|
|
31
|
+
})
|
|
32
|
+
if (result.error) {
|
|
33
|
+
throw result.error
|
|
34
|
+
}
|
|
35
|
+
process.exit(typeof result.status === 'number' ? result.status : 1)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function main() {
|
|
39
|
+
const packageRoot = findPackageRoot(__dirname)
|
|
40
|
+
const pkg = readPackageJson(packageRoot)
|
|
41
|
+
const version = pkg?.version || ''
|
|
42
|
+
const { getCachedBinaryPath } = require(path.join(
|
|
43
|
+
packageRoot,
|
|
44
|
+
'scripts',
|
|
45
|
+
'binary-utils.cjs',
|
|
46
|
+
))
|
|
47
|
+
|
|
48
|
+
// 1) Prefer native binary (postinstall download)
|
|
49
|
+
if (version) {
|
|
50
|
+
const binPath = getCachedBinaryPath({ version })
|
|
51
|
+
if (fs.existsSync(binPath)) {
|
|
52
|
+
run(binPath, ['--acp', ...process.argv.slice(2)])
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 2) Node.js runtime fallback (npm install should work without Bun)
|
|
57
|
+
const distEntry = path.join(packageRoot, 'dist', 'index.js')
|
|
58
|
+
if (fs.existsSync(distEntry)) {
|
|
59
|
+
run(process.execPath, [distEntry, '--acp', ...process.argv.slice(2)])
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
process.stderr.write(
|
|
63
|
+
[
|
|
64
|
+
'❌ kode-acp is not runnable on this system.',
|
|
65
|
+
'',
|
|
66
|
+
'Tried:',
|
|
67
|
+
'- Native binary (postinstall download)',
|
|
68
|
+
'- Node.js runtime fallback',
|
|
69
|
+
'',
|
|
70
|
+
'Fix:',
|
|
71
|
+
'- Reinstall (ensure network access), or set KODE_BINARY_BASE_URL to a mirror',
|
|
72
|
+
'- Or download a standalone binary from GitHub Releases',
|
|
73
|
+
'',
|
|
74
|
+
version ? `Package version: ${version}` : '',
|
|
75
|
+
]
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join('\n'),
|
|
78
|
+
)
|
|
79
|
+
process.exit(1)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main()
|