autohand-cli 0.6.0 → 0.6.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/dist/agents-32JB7KMB.js +9 -0
- package/dist/agents-3K6PHXQ6.js +9 -0
- package/dist/agents-A7AUMVQD.js +8 -0
- package/dist/agents-AHFECO5Q.js +9 -0
- package/dist/agents-DQFYBMJG.js +8 -0
- package/dist/agents-GX6L7BXZ.js +9 -0
- package/dist/agents-IWJJ7YJM.js +8 -0
- package/dist/agents-J2QLDVOP.js +9 -0
- package/dist/agents-OWTSY74S.js +9 -0
- package/dist/agents-RB34F4XE.js +9 -0
- package/dist/agents-XL27P67O.js +9 -0
- package/dist/agents-new-5I3B2W2I.js +9 -0
- package/dist/agents-new-CHV2AV34.js +9 -0
- package/dist/agents-new-F6F2VMDB.js +9 -0
- package/dist/agents-new-FDMUH7NL.js +9 -0
- package/dist/agents-new-GBF6JJIA.js +9 -0
- package/dist/agents-new-GCZEY4TE.js +8 -0
- package/dist/agents-new-OCIB72NU.js +9 -0
- package/dist/agents-new-PQGD47BZ.js +9 -0
- package/dist/agents-new-V6BNVJAB.js +9 -0
- package/dist/agents-new-WQUEZ2XH.js +8 -0
- package/dist/chunk-2DEJU7WQ.js +373 -0
- package/dist/chunk-2EPIFDFM.js +68 -0
- package/dist/chunk-2FUWKZFN.js +68 -0
- package/dist/chunk-2HIILNYH.js +197 -0
- package/dist/chunk-2QAL3HH4.js +79 -0
- package/dist/chunk-3FRM7HJY.js +57 -0
- package/dist/chunk-4LDR3Y3A.js +79 -0
- package/dist/{chunk-6PYYLBNT.js → chunk-4LLTISFP.js} +1 -1
- package/dist/chunk-4UISIRMD.js +288 -0
- package/dist/chunk-4VWPX2X3.js +131 -0
- package/dist/chunk-7FMMKTRG.js +64 -0
- package/dist/chunk-7MFSCH7E.js +382 -0
- package/dist/chunk-7TV5KURP.js +79 -0
- package/dist/chunk-7WBK33MM.js +57 -0
- package/dist/chunk-7XN6PAKV.js +79 -0
- package/dist/chunk-A7HRTONQ.js +382 -0
- package/dist/chunk-ALMJANSA.js +197 -0
- package/dist/chunk-CD7GNBIE.js +288 -0
- package/dist/chunk-CV3LEQRD.js +57 -0
- package/dist/chunk-DAHMHLM6.js +102 -0
- package/dist/chunk-DAMLAWGE.js +68 -0
- package/dist/chunk-F4YPGOQJ.js +105 -0
- package/dist/chunk-FQDXFNOI.js +57 -0
- package/dist/chunk-FQI7EJY2.js +105 -0
- package/dist/chunk-GAJCZDZ5.js +286 -0
- package/dist/chunk-GEOP77H3.js +79 -0
- package/dist/chunk-GRX3IQHC.js +131 -0
- package/dist/chunk-GX24PC3L.js +288 -0
- package/dist/chunk-H53NQAC2.js +131 -0
- package/dist/chunk-HJYISR7Y.js +382 -0
- package/dist/chunk-HLSI4HQM.js +105 -0
- package/dist/chunk-IAOMCEYU.js +68 -0
- package/dist/chunk-J7RENRJG.js +382 -0
- package/dist/chunk-JUDX6E53.js +105 -0
- package/dist/chunk-JZQKOM7X.js +382 -0
- package/dist/chunk-K75NWR5V.js +108 -0
- package/dist/chunk-KCMWJB53.js +288 -0
- package/dist/chunk-KERHTHMK.js +302 -0
- package/dist/chunk-KJ4M6KAK.js +57 -0
- package/dist/chunk-L3JXU574.js +77 -0
- package/dist/chunk-LR2XPUPT.js +236 -0
- package/dist/chunk-MCWNGAZG.js +198 -0
- package/dist/chunk-MQTBFYEG.js +288 -0
- package/dist/chunk-NCUJWSGP.js +287 -0
- package/dist/chunk-NWEUBPSG.js +79 -0
- package/dist/chunk-OJ5EBWOQ.js +232 -0
- package/dist/chunk-PKQZWNS2.js +131 -0
- package/dist/chunk-PQJIQBQ5.js +57 -0
- package/dist/chunk-PX5AGAEX.js +105 -0
- package/dist/chunk-Q7HX4VZD.js +197 -0
- package/dist/chunk-QE5RKNVN.js +30 -0
- package/dist/chunk-QLVXFPE3.js +145 -0
- package/dist/chunk-QUC577LO.js +79 -0
- package/dist/chunk-RAL2W5UX.js +55 -0
- package/dist/chunk-RANNBYFJ.js +105 -0
- package/dist/chunk-RCSSFUGL.js +131 -0
- package/dist/chunk-RUQVXU6K.js +131 -0
- package/dist/chunk-RZ7TASUI.js +57 -0
- package/dist/chunk-SN7D2PJO.js +68 -0
- package/dist/chunk-T4WQUJAE.js +79 -0
- package/dist/chunk-U2Z5BABG.js +57 -0
- package/dist/chunk-UHC4DIK5.js +105 -0
- package/dist/chunk-UNS4S6J3.js +197 -0
- package/dist/chunk-UW2LYWIM.js +131 -0
- package/dist/chunk-VRCQBFSX.js +102 -0
- package/dist/chunk-W76N6IZV.js +197 -0
- package/dist/chunk-WTEZYXD2.js +67 -0
- package/dist/chunk-X7EWON4T.js +105 -0
- package/dist/chunk-XARAKKJ4.js +197 -0
- package/dist/chunk-Y6JDGDEE.js +197 -0
- package/dist/chunk-Y7FSNXMR.js +382 -0
- package/dist/chunk-YPZMUIB5.js +50 -0
- package/dist/chunk-ZMDUVLR4.js +148 -0
- package/dist/chunk-ZRFAICDG.js +382 -0
- package/dist/export-HEFUNSR4.js +8 -0
- package/dist/feedback-3U2WYQK6.js +9 -0
- package/dist/feedback-5IIX372K.js +9 -0
- package/dist/feedback-6S6DWGIU.js +9 -0
- package/dist/feedback-7DEOY2AP.js +9 -0
- package/dist/feedback-BBQT42R6.js +9 -0
- package/dist/feedback-CGCSAWQT.js +9 -0
- package/dist/feedback-NEDFOKMA.js +9 -0
- package/dist/feedback-OXGGJVNA.js +9 -0
- package/dist/feedback-ZJECE2FS.js +8 -0
- package/dist/help-NQUZ7TNJ.js +10 -0
- package/dist/index.cjs +16 -2
- package/dist/index.js +2 -2
- package/dist/login-D53NQ7UY.js +10 -0
- package/dist/login-GPXDNB2F.js +10 -0
- package/dist/login-HDF4GSTP.js +10 -0
- package/dist/login-SDAZTJAK.js +10 -0
- package/dist/login-SM6LEDDA.js +10 -0
- package/dist/login-TDI7HBRZ.js +10 -0
- package/dist/login-Y7XXSNOZ.js +10 -0
- package/dist/logout-32RNT7G2.js +10 -0
- package/dist/logout-43W7N6JU.js +10 -0
- package/dist/logout-BMHTSXIY.js +10 -0
- package/dist/logout-JNNJJYYL.js +10 -0
- package/dist/logout-LW42QASH.js +10 -0
- package/dist/logout-QLWM6P26.js +10 -0
- package/dist/logout-TL7GLGWU.js +10 -0
- package/dist/memory-GVYG653L.js +8 -0
- package/dist/new-MCN36AOD.js +8 -0
- package/dist/{status-RNUAXIRO.js → status-DCVSUWZG.js} +1 -1
- package/dist/status-F6TQOCON.js +8 -0
- package/dist/status-IT5CYW37.js +8 -0
- package/dist/status-MRJOSVE3.js +8 -0
- package/dist/status-MWFV2DZG.js +8 -0
- package/dist/status-N3PMJRSB.js +8 -0
- package/dist/status-NK7YSBXZ.js +8 -0
- package/dist/status-QLQ5ZKJ3.js +8 -0
- package/dist/status-SQEFMII5.js +8 -0
- package/dist/status-U33PEUBO.js +8 -0
- package/dist/status-XAJH67SE.js +8 -0
- package/package.json +16 -2
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// src/commands/status.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import readline from "readline";
|
|
4
|
+
|
|
5
|
+
// package.json
|
|
6
|
+
var package_default = {
|
|
7
|
+
name: "autohand-cli",
|
|
8
|
+
version: "0.2.0",
|
|
9
|
+
description: "Autohand interactive coding agent CLI powered by LLMs.",
|
|
10
|
+
type: "module",
|
|
11
|
+
bin: {
|
|
12
|
+
autohand: "dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
main: "dist/index.js",
|
|
15
|
+
files: [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
scripts: {
|
|
19
|
+
go: 'bun run build && ./install-local.sh && echo "COMPLETED"',
|
|
20
|
+
build: "tsup src/index.ts --format esm,cjs --dts",
|
|
21
|
+
dev: "tsx src/index.ts",
|
|
22
|
+
typecheck: "tsc --noEmit",
|
|
23
|
+
lint: "eslint .",
|
|
24
|
+
test: "vitest run",
|
|
25
|
+
start: "node dist/index.js",
|
|
26
|
+
"compile:macos-arm64": "bun build ./src/index.ts --compile --target=bun-darwin-arm64 --outfile ./binaries/autohand-macos-arm64",
|
|
27
|
+
"compile:macos-x64": "bun build ./src/index.ts --compile --target=bun-darwin-x64 --outfile ./binaries/autohand-macos-x64",
|
|
28
|
+
"compile:linux-x64": "bun build ./src/index.ts --compile --target=bun-linux-x64 --outfile ./binaries/autohand-linux-x64",
|
|
29
|
+
"compile:linux-arm64": "bun build ./src/index.ts --compile --target=bun-linux-arm64 --outfile ./binaries/autohand-linux-arm64",
|
|
30
|
+
"compile:windows-x64": "bun build ./src/index.ts --compile --target=bun-windows-x64 --outfile ./binaries/autohand-windows-x64.exe",
|
|
31
|
+
"compile:all": "bun run compile:macos-arm64 && bun run compile:macos-x64 && bun run compile:linux-x64 && bun run compile:linux-arm64 && bun run compile:windows-x64",
|
|
32
|
+
link: "bun link"
|
|
33
|
+
},
|
|
34
|
+
keywords: [
|
|
35
|
+
"cli",
|
|
36
|
+
"llm",
|
|
37
|
+
"agent",
|
|
38
|
+
"autohand"
|
|
39
|
+
],
|
|
40
|
+
engines: {
|
|
41
|
+
node: ">=18.17.0"
|
|
42
|
+
},
|
|
43
|
+
dependencies: {
|
|
44
|
+
chalk: "^5.6.2",
|
|
45
|
+
commander: "^14.0.2",
|
|
46
|
+
diff: "^8.0.2",
|
|
47
|
+
dotenv: "^17.2.3",
|
|
48
|
+
enquirer: "^2.4.1",
|
|
49
|
+
"fs-extra": "^11.3.2",
|
|
50
|
+
ignore: "^5.3.1",
|
|
51
|
+
ink: "^4.4.1",
|
|
52
|
+
open: "^10.1.0",
|
|
53
|
+
ora: "^9.0.0",
|
|
54
|
+
react: "^18.2.0",
|
|
55
|
+
"terminal-link": "^3.0.0",
|
|
56
|
+
yaml: "^2.8.2",
|
|
57
|
+
zod: "^4.1.12"
|
|
58
|
+
},
|
|
59
|
+
devDependencies: {
|
|
60
|
+
"@types/diff": "^8.0.0",
|
|
61
|
+
"@types/fs-extra": "^11.0.4",
|
|
62
|
+
"@types/node": "^24.10.1",
|
|
63
|
+
"@types/react": "^18.3.3",
|
|
64
|
+
"@types/terminal-link": "^1.2.0",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
66
|
+
"@typescript-eslint/parser": "^8.48.1",
|
|
67
|
+
eslint: "^9.39.1",
|
|
68
|
+
"react-devtools-core": "^7.0.1",
|
|
69
|
+
tsup: "^8.5.1",
|
|
70
|
+
tsx: "^4.20.6",
|
|
71
|
+
typescript: "^5.9.3",
|
|
72
|
+
vitest: "^1.6.0"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/commands/status.ts
|
|
77
|
+
var metadata = {
|
|
78
|
+
command: "/status",
|
|
79
|
+
description: "Show Autohand status including version, model, API connectivity, and usage",
|
|
80
|
+
implemented: true
|
|
81
|
+
};
|
|
82
|
+
async function status(ctx) {
|
|
83
|
+
const data = await gatherStatusData(ctx);
|
|
84
|
+
await renderStatusUI(data);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
async function gatherStatusData(ctx) {
|
|
88
|
+
const currentSession = ctx.sessionManager.getCurrentSession();
|
|
89
|
+
const allSessions = await ctx.sessionManager.listSessions();
|
|
90
|
+
let apiConnected = false;
|
|
91
|
+
try {
|
|
92
|
+
apiConnected = await ctx.llm.isAvailable();
|
|
93
|
+
} catch {
|
|
94
|
+
apiConnected = false;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
version: package_default.version,
|
|
98
|
+
sessionId: currentSession?.metadata.sessionId ?? null,
|
|
99
|
+
cwd: ctx.workspaceRoot,
|
|
100
|
+
provider: ctx.provider ?? "openrouter",
|
|
101
|
+
model: ctx.model,
|
|
102
|
+
apiConnected,
|
|
103
|
+
sessionsCount: allSessions.length,
|
|
104
|
+
contextPercentLeft: ctx.getContextPercentLeft?.() ?? 100,
|
|
105
|
+
totalTokensUsed: ctx.getTotalTokensUsed?.() ?? 0,
|
|
106
|
+
config: ctx.config
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function renderStatusUI(data) {
|
|
110
|
+
return new Promise((resolve) => {
|
|
111
|
+
const tabs = ["Status", "Config", "Usage"];
|
|
112
|
+
let currentTab = 0;
|
|
113
|
+
const input = process.stdin;
|
|
114
|
+
const isTTY = input.isTTY;
|
|
115
|
+
const wasRaw = input.isRaw;
|
|
116
|
+
const wasPaused = typeof input.isPaused === "function" ? input.isPaused() : false;
|
|
117
|
+
if (wasPaused && typeof input.resume === "function") {
|
|
118
|
+
input.resume();
|
|
119
|
+
}
|
|
120
|
+
if (isTTY) {
|
|
121
|
+
readline.emitKeypressEvents(input);
|
|
122
|
+
if (!wasRaw && typeof input.setRawMode === "function") {
|
|
123
|
+
input.setRawMode(true);
|
|
124
|
+
}
|
|
125
|
+
if (typeof input.setEncoding === "function") {
|
|
126
|
+
input.setEncoding("utf8");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const render = () => {
|
|
130
|
+
process.stdout.write("\x1B[2J\x1B[H");
|
|
131
|
+
renderTabHeader(tabs, currentTab);
|
|
132
|
+
renderTabContent(tabs[currentTab], data);
|
|
133
|
+
console.log(chalk.gray("\nEsc to exit"));
|
|
134
|
+
};
|
|
135
|
+
let buffer = "";
|
|
136
|
+
const handler = (chunk) => {
|
|
137
|
+
buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
138
|
+
const processNext = () => {
|
|
139
|
+
if (!buffer.length) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
const first = buffer[0];
|
|
143
|
+
if (first === "\x1B") {
|
|
144
|
+
if (buffer.length === 1) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (buffer[1] === "[") {
|
|
148
|
+
if (buffer.length < 3) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const seq = buffer.slice(0, 3);
|
|
152
|
+
buffer = buffer.slice(3);
|
|
153
|
+
handleSequence(seq);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
buffer = buffer.slice(1);
|
|
157
|
+
handleSequence("\x1B");
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
buffer = buffer.slice(1);
|
|
161
|
+
handleSequence(first);
|
|
162
|
+
return true;
|
|
163
|
+
};
|
|
164
|
+
while (processNext()) {
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const handleSequence = (sequence) => {
|
|
168
|
+
switch (sequence) {
|
|
169
|
+
case "\x1B":
|
|
170
|
+
// ESC
|
|
171
|
+
case "":
|
|
172
|
+
cleanup();
|
|
173
|
+
resolve();
|
|
174
|
+
return;
|
|
175
|
+
case " ":
|
|
176
|
+
// Tab
|
|
177
|
+
case "\x1B[C":
|
|
178
|
+
currentTab = (currentTab + 1) % tabs.length;
|
|
179
|
+
render();
|
|
180
|
+
return;
|
|
181
|
+
case "\x1B[Z":
|
|
182
|
+
// Shift+Tab
|
|
183
|
+
case "\x1B[D":
|
|
184
|
+
currentTab = (currentTab - 1 + tabs.length) % tabs.length;
|
|
185
|
+
render();
|
|
186
|
+
return;
|
|
187
|
+
default:
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const cleanup = () => {
|
|
192
|
+
input.off("data", handler);
|
|
193
|
+
if (isTTY && !wasRaw && typeof input.setRawMode === "function") {
|
|
194
|
+
input.setRawMode(false);
|
|
195
|
+
}
|
|
196
|
+
if (wasPaused && typeof input.pause === "function") {
|
|
197
|
+
input.pause();
|
|
198
|
+
}
|
|
199
|
+
process.stdout.write("\x1B[2J\x1B[H");
|
|
200
|
+
};
|
|
201
|
+
input.on("data", handler);
|
|
202
|
+
render();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function renderTabHeader(tabs, currentIndex) {
|
|
206
|
+
const header = tabs.map((tab, i) => {
|
|
207
|
+
return i === currentIndex ? chalk.bgWhite.black(` ${tab} `) : chalk.gray(` ${tab} `);
|
|
208
|
+
}).join(" ");
|
|
209
|
+
console.log(`Settings: ${header} ${chalk.gray("(tab to cycle)")}
|
|
210
|
+
`);
|
|
211
|
+
}
|
|
212
|
+
function renderTabContent(tab, data) {
|
|
213
|
+
switch (tab) {
|
|
214
|
+
case "Status":
|
|
215
|
+
renderStatusTab(data);
|
|
216
|
+
break;
|
|
217
|
+
case "Config":
|
|
218
|
+
renderConfigTab(data);
|
|
219
|
+
break;
|
|
220
|
+
case "Usage":
|
|
221
|
+
renderUsageTab(data);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function renderStatusTab(data) {
|
|
226
|
+
console.log(chalk.bold("Version:"), data.version);
|
|
227
|
+
console.log(chalk.bold("Session ID:"), data.sessionId ?? chalk.gray("none"));
|
|
228
|
+
console.log(chalk.bold("cwd:"), data.cwd);
|
|
229
|
+
console.log(chalk.bold("Provider:"), data.provider);
|
|
230
|
+
console.log(chalk.bold("Model:"), data.model);
|
|
231
|
+
console.log();
|
|
232
|
+
console.log(
|
|
233
|
+
chalk.bold("API Status:"),
|
|
234
|
+
data.apiConnected ? chalk.green("Connected") : chalk.red("Disconnected")
|
|
235
|
+
);
|
|
236
|
+
console.log(chalk.bold("Sessions:"), `${data.sessionsCount} total`);
|
|
237
|
+
console.log(chalk.bold("Memory:"), "user (~/.autohand/memory/), project (.autohand/memory/)");
|
|
238
|
+
}
|
|
239
|
+
function renderConfigTab(data) {
|
|
240
|
+
const config = data.config;
|
|
241
|
+
console.log(chalk.bold("Autohand preferences\n"));
|
|
242
|
+
const settings = [
|
|
243
|
+
["Theme", config?.ui?.theme ?? "dark"],
|
|
244
|
+
["Auto-confirm", config?.ui?.autoConfirm ? "true" : "false"],
|
|
245
|
+
["Show thinking", config?.ui?.showThinking !== false ? "true" : "false"],
|
|
246
|
+
["Show completion notification", config?.ui?.showCompletionNotification !== false ? "true" : "false"],
|
|
247
|
+
["Permission mode", config?.permissions?.mode ?? "interactive"],
|
|
248
|
+
["Telemetry", config?.telemetry?.enabled !== false ? "true" : "false"],
|
|
249
|
+
["Network retries", String(config?.network?.maxRetries ?? 3)],
|
|
250
|
+
["Network timeout", `${config?.network?.timeout ?? 3e4}ms`]
|
|
251
|
+
];
|
|
252
|
+
for (const [name, value] of settings) {
|
|
253
|
+
console.log(` ${chalk.cyan(name.padEnd(30))} ${value}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function renderUsageTab(data) {
|
|
257
|
+
const contextUsed = 100 - data.contextPercentLeft;
|
|
258
|
+
console.log(chalk.bold("Current session\n"));
|
|
259
|
+
renderProgressBar("Context used", contextUsed, 100);
|
|
260
|
+
console.log();
|
|
261
|
+
console.log(chalk.bold("Tokens used:"), formatTokens(data.totalTokensUsed));
|
|
262
|
+
}
|
|
263
|
+
function renderProgressBar(label, value, max) {
|
|
264
|
+
const width = 30;
|
|
265
|
+
const filled = Math.round(value / max * width);
|
|
266
|
+
const empty = width - filled;
|
|
267
|
+
const bar = chalk.cyan("\u2588".repeat(filled)) + chalk.gray("\u2591".repeat(empty));
|
|
268
|
+
const percent = Math.round(value / max * 100);
|
|
269
|
+
console.log(label);
|
|
270
|
+
console.log(`${bar} ${percent}% used`);
|
|
271
|
+
}
|
|
272
|
+
function formatTokens(tokens) {
|
|
273
|
+
if (tokens >= 1e3) {
|
|
274
|
+
return `${(tokens / 1e3).toFixed(1)}k tokens`;
|
|
275
|
+
}
|
|
276
|
+
return `${tokens} tokens`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export {
|
|
280
|
+
package_default,
|
|
281
|
+
metadata,
|
|
282
|
+
status
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* @license
|
|
286
|
+
* Copyright 2025 Autohand AI LLC
|
|
287
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
288
|
+
*/
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAuthClient,
|
|
3
|
+
saveConfig
|
|
4
|
+
} from "./chunk-JZQKOM7X.js";
|
|
5
|
+
import {
|
|
6
|
+
AUTH_CONFIG
|
|
7
|
+
} from "./chunk-IAOMCEYU.js";
|
|
8
|
+
|
|
9
|
+
// src/commands/login.ts
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import enquirer from "enquirer";
|
|
12
|
+
var metadata = {
|
|
13
|
+
command: "/login",
|
|
14
|
+
description: "sign in to your Autohand account",
|
|
15
|
+
implemented: true
|
|
16
|
+
};
|
|
17
|
+
async function openBrowser(url) {
|
|
18
|
+
try {
|
|
19
|
+
const open = await import("open").then((m) => m.default).catch(() => null);
|
|
20
|
+
if (open) {
|
|
21
|
+
await open(url);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const { exec } = await import("child_process");
|
|
25
|
+
const { promisify } = await import("util");
|
|
26
|
+
const execAsync = promisify(exec);
|
|
27
|
+
const platform = process.platform;
|
|
28
|
+
let command;
|
|
29
|
+
if (platform === "darwin") {
|
|
30
|
+
command = `open "${url}"`;
|
|
31
|
+
} else if (platform === "win32") {
|
|
32
|
+
command = `start "" "${url}"`;
|
|
33
|
+
} else {
|
|
34
|
+
command = `xdg-open "${url}"`;
|
|
35
|
+
}
|
|
36
|
+
await execAsync(command);
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function sleep(ms) {
|
|
43
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
44
|
+
}
|
|
45
|
+
async function login(ctx) {
|
|
46
|
+
const config = ctx.config;
|
|
47
|
+
if (config?.auth?.token && config?.auth?.user) {
|
|
48
|
+
const { continueLogin } = await enquirer.prompt({
|
|
49
|
+
type: "confirm",
|
|
50
|
+
name: "continueLogin",
|
|
51
|
+
message: `Already logged in as ${chalk.cyan(config.auth.user.email)}. Log in with a different account?`,
|
|
52
|
+
initial: false
|
|
53
|
+
});
|
|
54
|
+
if (!continueLogin) {
|
|
55
|
+
console.log(chalk.gray("Login cancelled."));
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const authClient = getAuthClient();
|
|
60
|
+
console.log(chalk.gray("Initiating authentication..."));
|
|
61
|
+
const initResult = await authClient.initiateDeviceAuth();
|
|
62
|
+
if (!initResult.success || !initResult.deviceCode || !initResult.userCode) {
|
|
63
|
+
console.log(chalk.red(`Failed to start login: ${initResult.error || "Unknown error"}`));
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
console.log();
|
|
67
|
+
console.log(chalk.bold("To sign in, visit:"));
|
|
68
|
+
console.log(chalk.cyan.underline(initResult.verificationUriComplete || `${AUTH_CONFIG.authorizationUrl}?code=${initResult.userCode}`));
|
|
69
|
+
console.log();
|
|
70
|
+
console.log(chalk.gray("Or enter this code manually:"));
|
|
71
|
+
console.log(chalk.bold.yellow(` ${initResult.userCode}`));
|
|
72
|
+
console.log();
|
|
73
|
+
const browserOpened = await openBrowser(
|
|
74
|
+
initResult.verificationUriComplete || `${AUTH_CONFIG.authorizationUrl}?code=${initResult.userCode}`
|
|
75
|
+
);
|
|
76
|
+
if (browserOpened) {
|
|
77
|
+
console.log(chalk.gray("Browser opened. Complete the login in your browser."));
|
|
78
|
+
} else {
|
|
79
|
+
console.log(chalk.yellow("Could not open browser automatically. Please visit the URL above."));
|
|
80
|
+
}
|
|
81
|
+
console.log();
|
|
82
|
+
console.log(chalk.gray("Waiting for authorization..."));
|
|
83
|
+
console.log(chalk.gray("(Press Ctrl+C to cancel)"));
|
|
84
|
+
const startTime = Date.now();
|
|
85
|
+
const timeout = AUTH_CONFIG.authTimeout;
|
|
86
|
+
const pollInterval = initResult.interval ? initResult.interval * 1e3 : AUTH_CONFIG.pollInterval;
|
|
87
|
+
let dots = 0;
|
|
88
|
+
const maxDots = 3;
|
|
89
|
+
while (Date.now() - startTime < timeout) {
|
|
90
|
+
process.stdout.write(`\r${chalk.gray("Waiting" + ".".repeat(dots + 1) + " ".repeat(maxDots - dots))}`);
|
|
91
|
+
dots = (dots + 1) % (maxDots + 1);
|
|
92
|
+
await sleep(pollInterval);
|
|
93
|
+
const pollResult = await authClient.pollDeviceAuth(initResult.deviceCode);
|
|
94
|
+
if (pollResult.status === "authorized" && pollResult.token && pollResult.user) {
|
|
95
|
+
process.stdout.write("\r" + " ".repeat(20) + "\r");
|
|
96
|
+
const expiresAt = new Date(Date.now() + AUTH_CONFIG.sessionExpiryDays * 24 * 60 * 60 * 1e3).toISOString();
|
|
97
|
+
const updatedConfig = {
|
|
98
|
+
...config,
|
|
99
|
+
auth: {
|
|
100
|
+
token: pollResult.token,
|
|
101
|
+
user: pollResult.user,
|
|
102
|
+
expiresAt
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
await saveConfig(updatedConfig);
|
|
106
|
+
console.log();
|
|
107
|
+
console.log(chalk.green("Login successful!"));
|
|
108
|
+
console.log(chalk.cyan(`Welcome, ${pollResult.user.name || pollResult.user.email}!`));
|
|
109
|
+
console.log();
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (pollResult.status === "expired") {
|
|
113
|
+
process.stdout.write("\r" + " ".repeat(20) + "\r");
|
|
114
|
+
console.log(chalk.red("Authorization code expired. Please try again."));
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
process.stdout.write("\r" + " ".repeat(20) + "\r");
|
|
119
|
+
console.log(chalk.red("Authorization timed out. Please try again."));
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
metadata,
|
|
125
|
+
login
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* @license
|
|
129
|
+
* Copyright 2025 Autohand AI LLC
|
|
130
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
131
|
+
*/
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
var AUTOHAND_HOME = process.env.AUTOHAND_HOME || path.join(os.homedir(), ".autohand");
|
|
5
|
+
var AUTOHAND_PATHS = {
|
|
6
|
+
/** Configuration files (config.json, config.yaml, config.yml) */
|
|
7
|
+
config: AUTOHAND_HOME,
|
|
8
|
+
/** Session data storage */
|
|
9
|
+
sessions: path.join(AUTOHAND_HOME, "sessions"),
|
|
10
|
+
/** Project knowledge base */
|
|
11
|
+
projects: path.join(AUTOHAND_HOME, "projects"),
|
|
12
|
+
/** User-level memory */
|
|
13
|
+
memory: path.join(AUTOHAND_HOME, "memory"),
|
|
14
|
+
/** Feedback state and responses */
|
|
15
|
+
feedback: path.join(AUTOHAND_HOME, "feedback"),
|
|
16
|
+
/** Telemetry data */
|
|
17
|
+
telemetry: path.join(AUTOHAND_HOME, "telemetry"),
|
|
18
|
+
/** Custom commands */
|
|
19
|
+
commands: path.join(AUTOHAND_HOME, "commands"),
|
|
20
|
+
/** Agent definitions */
|
|
21
|
+
agents: path.join(AUTOHAND_HOME, "agents"),
|
|
22
|
+
/** Custom tools */
|
|
23
|
+
tools: path.join(AUTOHAND_HOME, "tools")
|
|
24
|
+
};
|
|
25
|
+
var AUTOHAND_FILES = {
|
|
26
|
+
/** Main config file */
|
|
27
|
+
configJson: path.join(AUTOHAND_HOME, "config.json"),
|
|
28
|
+
configYaml: path.join(AUTOHAND_HOME, "config.yaml"),
|
|
29
|
+
configYml: path.join(AUTOHAND_HOME, "config.yml"),
|
|
30
|
+
/** Device ID for telemetry */
|
|
31
|
+
deviceId: path.join(AUTOHAND_HOME, "device-id"),
|
|
32
|
+
/** Error log */
|
|
33
|
+
errorLog: path.join(AUTOHAND_HOME, "error.log"),
|
|
34
|
+
/** Feedback log */
|
|
35
|
+
feedbackLog: path.join(AUTOHAND_HOME, "feedback.log"),
|
|
36
|
+
/** Telemetry queue */
|
|
37
|
+
telemetryQueue: path.join(AUTOHAND_PATHS.telemetry, "queue.json"),
|
|
38
|
+
/** Session sync queue */
|
|
39
|
+
sessionSyncQueue: path.join(AUTOHAND_PATHS.telemetry, "session-sync-queue.json")
|
|
40
|
+
};
|
|
41
|
+
var PROJECT_DIR_NAME = ".autohand";
|
|
42
|
+
var AUTH_BASE_URL = process.env.AUTOHAND_API_URL || "https://autohand.ai";
|
|
43
|
+
var AUTH_CONFIG = {
|
|
44
|
+
apiBaseUrl: `${AUTH_BASE_URL}/api/auth`,
|
|
45
|
+
authorizationUrl: `${AUTH_BASE_URL}/cli-auth`,
|
|
46
|
+
pollInterval: 2e3,
|
|
47
|
+
authTimeout: 5 * 60 * 1e3,
|
|
48
|
+
sessionExpiryDays: 30
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
AUTOHAND_HOME,
|
|
53
|
+
AUTOHAND_PATHS,
|
|
54
|
+
AUTOHAND_FILES,
|
|
55
|
+
PROJECT_DIR_NAME,
|
|
56
|
+
AUTH_CONFIG
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @license
|
|
60
|
+
* Copyright 2025 Autohand AI LLC
|
|
61
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
62
|
+
*
|
|
63
|
+
* Centralized constants for Autohand CLI
|
|
64
|
+
*/
|