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,232 @@
|
|
|
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.1.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
|
+
enquirer: "^2.4.1",
|
|
48
|
+
"fs-extra": "^11.3.2",
|
|
49
|
+
ignore: "^5.3.1",
|
|
50
|
+
ink: "^4.4.1",
|
|
51
|
+
ora: "^9.0.0",
|
|
52
|
+
react: "^18.2.0",
|
|
53
|
+
"terminal-link": "^3.0.0",
|
|
54
|
+
yaml: "^2.8.2",
|
|
55
|
+
zod: "^4.1.12"
|
|
56
|
+
},
|
|
57
|
+
devDependencies: {
|
|
58
|
+
"@types/diff": "^8.0.0",
|
|
59
|
+
"@types/fs-extra": "^11.0.4",
|
|
60
|
+
"@types/node": "^24.10.1",
|
|
61
|
+
"@types/react": "^18.3.3",
|
|
62
|
+
"@types/terminal-link": "^1.2.0",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
64
|
+
"@typescript-eslint/parser": "^8.48.1",
|
|
65
|
+
eslint: "^9.39.1",
|
|
66
|
+
"react-devtools-core": "^7.0.1",
|
|
67
|
+
tsup: "^8.5.1",
|
|
68
|
+
tsx: "^4.20.6",
|
|
69
|
+
typescript: "^5.9.3",
|
|
70
|
+
vitest: "^1.6.0"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/commands/status.ts
|
|
75
|
+
var metadata = {
|
|
76
|
+
command: "/status",
|
|
77
|
+
description: "Show Autohand status including version, model, API connectivity, and usage",
|
|
78
|
+
implemented: true
|
|
79
|
+
};
|
|
80
|
+
async function status(ctx) {
|
|
81
|
+
const data = await gatherStatusData(ctx);
|
|
82
|
+
await renderStatusUI(data);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
async function gatherStatusData(ctx) {
|
|
86
|
+
const currentSession = ctx.sessionManager.getCurrentSession();
|
|
87
|
+
const allSessions = await ctx.sessionManager.listSessions();
|
|
88
|
+
let apiConnected = false;
|
|
89
|
+
try {
|
|
90
|
+
apiConnected = await ctx.llm.isAvailable();
|
|
91
|
+
} catch {
|
|
92
|
+
apiConnected = false;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
version: package_default.version,
|
|
96
|
+
sessionId: currentSession?.metadata.sessionId ?? null,
|
|
97
|
+
cwd: ctx.workspaceRoot,
|
|
98
|
+
provider: ctx.provider ?? "openrouter",
|
|
99
|
+
model: ctx.model,
|
|
100
|
+
apiConnected,
|
|
101
|
+
sessionsCount: allSessions.length,
|
|
102
|
+
contextPercentLeft: ctx.getContextPercentLeft?.() ?? 100,
|
|
103
|
+
totalTokensUsed: ctx.getTotalTokensUsed?.() ?? 0,
|
|
104
|
+
config: ctx.config
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function renderStatusUI(data) {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const tabs = ["Status", "Config", "Usage"];
|
|
110
|
+
let currentTab = 0;
|
|
111
|
+
const input = process.stdin;
|
|
112
|
+
const isTTY = input.isTTY;
|
|
113
|
+
if (isTTY) {
|
|
114
|
+
readline.emitKeypressEvents(input);
|
|
115
|
+
input.setRawMode(true);
|
|
116
|
+
}
|
|
117
|
+
const render = () => {
|
|
118
|
+
process.stdout.write("\x1B[2J\x1B[H");
|
|
119
|
+
renderTabHeader(tabs, currentTab);
|
|
120
|
+
renderTabContent(tabs[currentTab], data);
|
|
121
|
+
console.log(chalk.gray("\nEsc to exit"));
|
|
122
|
+
};
|
|
123
|
+
const handler = (_str, key) => {
|
|
124
|
+
if (key.name === "escape" || key.name === "c" && key.ctrl) {
|
|
125
|
+
cleanup();
|
|
126
|
+
resolve();
|
|
127
|
+
} else if (key.name === "tab") {
|
|
128
|
+
currentTab = (currentTab + 1) % tabs.length;
|
|
129
|
+
render();
|
|
130
|
+
} else if (key.name === "left") {
|
|
131
|
+
currentTab = (currentTab - 1 + tabs.length) % tabs.length;
|
|
132
|
+
render();
|
|
133
|
+
} else if (key.name === "right") {
|
|
134
|
+
currentTab = (currentTab + 1) % tabs.length;
|
|
135
|
+
render();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const cleanup = () => {
|
|
139
|
+
input.off("keypress", handler);
|
|
140
|
+
if (isTTY) {
|
|
141
|
+
input.setRawMode(false);
|
|
142
|
+
}
|
|
143
|
+
process.stdout.write("\x1B[2J\x1B[H");
|
|
144
|
+
};
|
|
145
|
+
input.on("keypress", handler);
|
|
146
|
+
render();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function renderTabHeader(tabs, currentIndex) {
|
|
150
|
+
const header = tabs.map((tab, i) => {
|
|
151
|
+
return i === currentIndex ? chalk.bgWhite.black(` ${tab} `) : chalk.gray(` ${tab} `);
|
|
152
|
+
}).join(" ");
|
|
153
|
+
console.log(`Settings: ${header} ${chalk.gray("(tab to cycle)")}
|
|
154
|
+
`);
|
|
155
|
+
}
|
|
156
|
+
function renderTabContent(tab, data) {
|
|
157
|
+
switch (tab) {
|
|
158
|
+
case "Status":
|
|
159
|
+
renderStatusTab(data);
|
|
160
|
+
break;
|
|
161
|
+
case "Config":
|
|
162
|
+
renderConfigTab(data);
|
|
163
|
+
break;
|
|
164
|
+
case "Usage":
|
|
165
|
+
renderUsageTab(data);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function renderStatusTab(data) {
|
|
170
|
+
console.log(chalk.bold("Version:"), data.version);
|
|
171
|
+
console.log(chalk.bold("Session ID:"), data.sessionId ?? chalk.gray("none"));
|
|
172
|
+
console.log(chalk.bold("cwd:"), data.cwd);
|
|
173
|
+
console.log(chalk.bold("Provider:"), data.provider);
|
|
174
|
+
console.log(chalk.bold("Model:"), data.model);
|
|
175
|
+
console.log();
|
|
176
|
+
console.log(
|
|
177
|
+
chalk.bold("API Status:"),
|
|
178
|
+
data.apiConnected ? chalk.green("Connected") : chalk.red("Disconnected")
|
|
179
|
+
);
|
|
180
|
+
console.log(chalk.bold("Sessions:"), `${data.sessionsCount} total`);
|
|
181
|
+
console.log(chalk.bold("Memory:"), "user (~/.autohand/memory/), project (.autohand/memory/)");
|
|
182
|
+
}
|
|
183
|
+
function renderConfigTab(data) {
|
|
184
|
+
const config = data.config;
|
|
185
|
+
console.log(chalk.bold("Autohand preferences\n"));
|
|
186
|
+
const settings = [
|
|
187
|
+
["Theme", config?.ui?.theme ?? "dark"],
|
|
188
|
+
["Auto-confirm", config?.ui?.autoConfirm ? "true" : "false"],
|
|
189
|
+
["Show thinking", config?.ui?.showThinking !== false ? "true" : "false"],
|
|
190
|
+
["Show completion notification", config?.ui?.showCompletionNotification !== false ? "true" : "false"],
|
|
191
|
+
["Permission mode", config?.permissions?.mode ?? "interactive"],
|
|
192
|
+
["Telemetry", config?.telemetry?.enabled !== false ? "true" : "false"],
|
|
193
|
+
["Network retries", String(config?.network?.maxRetries ?? 3)],
|
|
194
|
+
["Network timeout", `${config?.network?.timeout ?? 3e4}ms`]
|
|
195
|
+
];
|
|
196
|
+
for (const [name, value] of settings) {
|
|
197
|
+
console.log(` ${chalk.cyan(name.padEnd(30))} ${value}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function renderUsageTab(data) {
|
|
201
|
+
const contextUsed = 100 - data.contextPercentLeft;
|
|
202
|
+
console.log(chalk.bold("Current session\n"));
|
|
203
|
+
renderProgressBar("Context used", contextUsed, 100);
|
|
204
|
+
console.log();
|
|
205
|
+
console.log(chalk.bold("Tokens used:"), formatTokens(data.totalTokensUsed));
|
|
206
|
+
}
|
|
207
|
+
function renderProgressBar(label, value, max) {
|
|
208
|
+
const width = 30;
|
|
209
|
+
const filled = Math.round(value / max * width);
|
|
210
|
+
const empty = width - filled;
|
|
211
|
+
const bar = chalk.cyan("\u2588".repeat(filled)) + chalk.gray("\u2591".repeat(empty));
|
|
212
|
+
const percent = Math.round(value / max * 100);
|
|
213
|
+
console.log(label);
|
|
214
|
+
console.log(`${bar} ${percent}% used`);
|
|
215
|
+
}
|
|
216
|
+
function formatTokens(tokens) {
|
|
217
|
+
if (tokens >= 1e3) {
|
|
218
|
+
return `${(tokens / 1e3).toFixed(1)}k tokens`;
|
|
219
|
+
}
|
|
220
|
+
return `${tokens} tokens`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export {
|
|
224
|
+
package_default,
|
|
225
|
+
metadata,
|
|
226
|
+
status
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* @license
|
|
230
|
+
* Copyright 2025 Autohand AI LLC
|
|
231
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
232
|
+
*/
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAuthClient,
|
|
3
|
+
saveConfig
|
|
4
|
+
} from "./chunk-ZRFAICDG.js";
|
|
5
|
+
import {
|
|
6
|
+
AUTH_CONFIG
|
|
7
|
+
} from "./chunk-SN7D2PJO.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,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAuthClient,
|
|
3
|
+
saveConfig
|
|
4
|
+
} from "./chunk-A7HRTONQ.js";
|
|
5
|
+
|
|
6
|
+
// src/commands/logout.ts
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import enquirer from "enquirer";
|
|
9
|
+
var metadata = {
|
|
10
|
+
command: "/logout",
|
|
11
|
+
description: "sign out of your Autohand account",
|
|
12
|
+
implemented: true
|
|
13
|
+
};
|
|
14
|
+
async function logout(ctx) {
|
|
15
|
+
const config = ctx.config;
|
|
16
|
+
if (!config?.auth?.token) {
|
|
17
|
+
console.log(chalk.yellow("You are not currently logged in."));
|
|
18
|
+
console.log(chalk.gray("Use /login to sign in to your Autohand account."));
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const userName = config.auth.user?.name || config.auth.user?.email || "user";
|
|
22
|
+
const { confirm } = await enquirer.prompt({
|
|
23
|
+
type: "confirm",
|
|
24
|
+
name: "confirm",
|
|
25
|
+
message: `Log out from ${chalk.cyan(userName)}?`,
|
|
26
|
+
initial: true
|
|
27
|
+
});
|
|
28
|
+
if (!confirm) {
|
|
29
|
+
console.log(chalk.gray("Logout cancelled."));
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const authClient = getAuthClient();
|
|
33
|
+
try {
|
|
34
|
+
await authClient.logout(config.auth.token);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
const updatedConfig = {
|
|
38
|
+
...config,
|
|
39
|
+
auth: void 0
|
|
40
|
+
};
|
|
41
|
+
await saveConfig(updatedConfig);
|
|
42
|
+
console.log();
|
|
43
|
+
console.log(chalk.green("Successfully logged out."));
|
|
44
|
+
console.log(chalk.gray("Your local session has been cleared."));
|
|
45
|
+
console.log();
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
metadata,
|
|
51
|
+
logout
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @license
|
|
55
|
+
* Copyright 2025 Autohand AI LLC
|
|
56
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
57
|
+
*/
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTOHAND_PATHS
|
|
3
|
+
} from "./chunk-2EPIFDFM.js";
|
|
4
|
+
|
|
5
|
+
// src/commands/agents-new.ts
|
|
6
|
+
import path from "path";
|
|
7
|
+
import fs from "fs-extra";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import enquirer from "enquirer";
|
|
10
|
+
var metadata = {
|
|
11
|
+
command: "/agents new",
|
|
12
|
+
description: "create a new sub-agent from a description",
|
|
13
|
+
implemented: true,
|
|
14
|
+
prd: "prd/sub_agents_architecture.md"
|
|
15
|
+
};
|
|
16
|
+
async function createAgent(ctx) {
|
|
17
|
+
const answers = await enquirer.prompt([
|
|
18
|
+
{
|
|
19
|
+
type: "input",
|
|
20
|
+
name: "name",
|
|
21
|
+
message: "Agent name (e.g., Researcher, QA Tester)",
|
|
22
|
+
validate: (val) => typeof val === "string" && val.trim() ? true : "Name is required"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: "input",
|
|
26
|
+
name: "description",
|
|
27
|
+
message: "Briefly describe what the agent should do"
|
|
28
|
+
}
|
|
29
|
+
]);
|
|
30
|
+
const name = answers.name.trim();
|
|
31
|
+
const description = answers.description.trim();
|
|
32
|
+
if (!name) {
|
|
33
|
+
console.log(chalk.gray("Canceled: no name provided."));
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const filename = await ensureUniqueFilename(name);
|
|
37
|
+
const filePath = path.join(getAgentsDir(), filename);
|
|
38
|
+
const prompt = buildPrompt(name, description);
|
|
39
|
+
let content;
|
|
40
|
+
try {
|
|
41
|
+
const completion = await ctx.llm.complete({
|
|
42
|
+
messages: [
|
|
43
|
+
{
|
|
44
|
+
role: "system",
|
|
45
|
+
content: "You generate concise markdown definitions for sub-agents. Output only markdown with no code fences. Keep it short but complete."
|
|
46
|
+
},
|
|
47
|
+
{ role: "user", content: prompt }
|
|
48
|
+
],
|
|
49
|
+
maxTokens: 600
|
|
50
|
+
});
|
|
51
|
+
content = completion.content.trim();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(chalk.red(`Failed to generate agent: ${error.message}`));
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await fs.ensureDir(getAgentsDir());
|
|
58
|
+
await fs.writeFile(filePath, content + "\n", "utf8");
|
|
59
|
+
console.log(chalk.green(`Saved new agent to ${filePath}`));
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(chalk.red(`Failed to save agent: ${error.message}`));
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function buildPrompt(name, description) {
|
|
67
|
+
return [
|
|
68
|
+
`Create a sub-agent markdown file for "${name}".`,
|
|
69
|
+
description ? `Agent description: ${description}` : "",
|
|
70
|
+
"Structure it as:",
|
|
71
|
+
"# <Name>",
|
|
72
|
+
"## Purpose",
|
|
73
|
+
"## Operating Mode (bullet list)",
|
|
74
|
+
"## Tools (bullet list; mention existing CLI tools and constraints briefly)",
|
|
75
|
+
"## Output Contract (what to return to main agent)",
|
|
76
|
+
"Be concise, 120-160 words total."
|
|
77
|
+
].filter(Boolean).join("\n");
|
|
78
|
+
}
|
|
79
|
+
function getAgentsDir() {
|
|
80
|
+
return AUTOHAND_PATHS.agents;
|
|
81
|
+
}
|
|
82
|
+
function slugify(input) {
|
|
83
|
+
return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "agent";
|
|
84
|
+
}
|
|
85
|
+
async function ensureUniqueFilename(name) {
|
|
86
|
+
const base = slugify(name);
|
|
87
|
+
const dir = getAgentsDir();
|
|
88
|
+
let candidate = `${base}.md`;
|
|
89
|
+
let counter = 1;
|
|
90
|
+
while (await fs.pathExists(path.join(dir, candidate))) {
|
|
91
|
+
candidate = `${base}-${counter}.md`;
|
|
92
|
+
counter += 1;
|
|
93
|
+
}
|
|
94
|
+
return candidate;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
metadata,
|
|
99
|
+
createAgent
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* @license
|
|
103
|
+
* Copyright 2025 Autohand AI LLC
|
|
104
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
105
|
+
*/
|