agentsw 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/README.zh-CN.md +21 -0
- package/dist/commands.js +30 -40
- package/dist/config-transaction.js +138 -0
- package/dist/envfile.js +27 -0
- package/dist/i18n.js +24 -3
- package/dist/import.js +35 -21
- package/dist/index.js +16 -3
- package/dist/menu.js +90 -9
- package/dist/provider-actions.js +37 -0
- package/dist/remove.js +651 -0
- package/dist/rename.js +458 -0
- package/dist/slug.js +17 -8
- package/dist/sources/ccswitch.js +4 -2
- package/dist/targets/claudecode.js +4 -3
- package/dist/targets/workbuddy.js +11 -10
- package/package.json +1 -1
package/dist/menu.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import pc from "picocolors";
|
|
2
2
|
import prompts from "prompts";
|
|
3
|
-
import { cmdAdd, cmdQuickAdd, cmdApps, cmdInstall, cmdDiscover, cmdImport, cmdList,
|
|
3
|
+
import { cmdAdd, cmdQuickAdd, cmdApps, cmdInstall, cmdDiscover, cmdImport, cmdList, cmdStatus, cmdSync, cmdUpgrade, cmdUse, } from "./commands.js";
|
|
4
4
|
import { getLocale, setLocale, t } from "./i18n.js";
|
|
5
5
|
import { loadStore, saveStore } from "./store.js";
|
|
6
6
|
import { appPackages, appCommand, installedVersion } from "./apps.js";
|
|
7
|
+
import { cmdRemoveProvider, cmdRename } from "./provider-actions.js";
|
|
8
|
+
import { listRemovableProviders } from "./remove.js";
|
|
9
|
+
import { providerIdFromBaseUrl } from "./slug.js";
|
|
10
|
+
import { targets } from "./targets/index.js";
|
|
7
11
|
function bye() {
|
|
8
12
|
console.log(pc.dim(`\n${t("menu.bye")}`));
|
|
9
13
|
process.exit(0);
|
|
@@ -57,6 +61,80 @@ async function pickProvider(message) {
|
|
|
57
61
|
const p = store.providers[id];
|
|
58
62
|
return { id, defaultModel: p.defaultModel, models: p.models.map((m) => m.id) };
|
|
59
63
|
}
|
|
64
|
+
async function renameFromMenu() {
|
|
65
|
+
const picked = await pickProvider(t("menu.renameProvider"));
|
|
66
|
+
if (!picked)
|
|
67
|
+
return;
|
|
68
|
+
const provider = loadStore().providers[picked.id];
|
|
69
|
+
const { newId } = await prompts({
|
|
70
|
+
type: "text",
|
|
71
|
+
name: "newId",
|
|
72
|
+
message: t("menu.newId"),
|
|
73
|
+
initial: providerIdFromBaseUrl(provider.baseUrl, provider.protocol),
|
|
74
|
+
validate: (value) => /^[a-z0-9][a-z0-9_-]*$/.test(value.trim()) || t("add.idInvalid"),
|
|
75
|
+
}, cancel);
|
|
76
|
+
if (!newId)
|
|
77
|
+
return;
|
|
78
|
+
const next = String(newId).trim();
|
|
79
|
+
await cmdRename(picked.id, next, { dryRun: true });
|
|
80
|
+
if (await askToggle(t("menu.renameConfirm", { oldId: picked.id, newId: next }))) {
|
|
81
|
+
await cmdRename(picked.id, next);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function removeFromMenu() {
|
|
85
|
+
const { scope } = await prompts({
|
|
86
|
+
type: "select",
|
|
87
|
+
name: "scope",
|
|
88
|
+
message: t("menu.removeScope"),
|
|
89
|
+
hint: t("menu.selectInstructions"),
|
|
90
|
+
choices: [
|
|
91
|
+
{ title: t("menu.removeStore"), value: "store" },
|
|
92
|
+
{ title: t("menu.removeEverywhere"), value: "everywhere" },
|
|
93
|
+
{ title: t("menu.removeLocal"), value: "local" },
|
|
94
|
+
],
|
|
95
|
+
}, cancel);
|
|
96
|
+
if (!scope)
|
|
97
|
+
return;
|
|
98
|
+
let app;
|
|
99
|
+
if (scope === "local") {
|
|
100
|
+
const answer = await prompts({
|
|
101
|
+
type: "select",
|
|
102
|
+
name: "app",
|
|
103
|
+
message: t("menu.removeApp"),
|
|
104
|
+
hint: t("menu.selectInstructions"),
|
|
105
|
+
choices: targets.map((target) => ({ title: `${target.id} · ${target.name}`, value: target.id })),
|
|
106
|
+
}, cancel);
|
|
107
|
+
app = answer.app;
|
|
108
|
+
if (!app)
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const entries = app
|
|
112
|
+
? listRemovableProviders(app)
|
|
113
|
+
: Object.values(loadStore().providers).map((provider) => ({ id: provider.id, name: provider.name }));
|
|
114
|
+
if (!entries.length) {
|
|
115
|
+
console.log(pc.dim(t("menu.noRemovable")));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const { selected } = await prompts({
|
|
119
|
+
type: "select",
|
|
120
|
+
name: "selected",
|
|
121
|
+
message: t("menu.removeProvider"),
|
|
122
|
+
hint: t("menu.selectInstructions"),
|
|
123
|
+
choices: entries.map((entry, index) => ({
|
|
124
|
+
title: `${entry.id} · ${entry.app ?? "agentsw"}${entry.name && entry.name !== entry.id ? ` · ${entry.name}` : ""}`,
|
|
125
|
+
value: index,
|
|
126
|
+
})),
|
|
127
|
+
}, cancel);
|
|
128
|
+
const picked = entries[selected];
|
|
129
|
+
if (!picked)
|
|
130
|
+
return;
|
|
131
|
+
const opts = scope === "local" ? { apps: picked.app } : { prune: scope === "everywhere" };
|
|
132
|
+
await cmdRemoveProvider(picked.id, { ...opts, dryRun: true });
|
|
133
|
+
const scopeLabel = picked.app ?? t(scope === "everywhere" ? "menu.removeEverywhere" : "menu.removeStore");
|
|
134
|
+
if (await askToggle(t("menu.removeConfirmScope", { id: picked.id, scope: scopeLabel }))) {
|
|
135
|
+
await cmdRemoveProvider(picked.id, opts);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
60
138
|
export async function cmdMenu() {
|
|
61
139
|
if (!loadStore().language)
|
|
62
140
|
await chooseLanguage();
|
|
@@ -82,6 +160,7 @@ export async function cmdMenu() {
|
|
|
82
160
|
{ title: t("menu.list"), value: "list" },
|
|
83
161
|
{ title: t("menu.sync"), value: "sync" },
|
|
84
162
|
{ title: t("menu.discover"), value: "discover" },
|
|
163
|
+
{ title: t("menu.rename"), value: "rename" },
|
|
85
164
|
{ title: t("menu.remove"), value: "remove" },
|
|
86
165
|
{ title: t("menu.apps"), value: "apps" },
|
|
87
166
|
{ title: t("menu.installApp"), value: "install" },
|
|
@@ -142,14 +221,16 @@ export async function cmdMenu() {
|
|
|
142
221
|
const sync = await askToggle(t("menu.pushRefresh"));
|
|
143
222
|
await cmdDiscover(picked.id, { sync });
|
|
144
223
|
}
|
|
145
|
-
else if (action === "remove") {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
224
|
+
else if (action === "rename" || action === "remove") {
|
|
225
|
+
try {
|
|
226
|
+
if (action === "rename")
|
|
227
|
+
await renameFromMenu();
|
|
228
|
+
else
|
|
229
|
+
await removeFromMenu();
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
console.error(pc.red(error instanceof Error ? error.message : String(error)));
|
|
233
|
+
}
|
|
153
234
|
}
|
|
154
235
|
else if (action === "apps") {
|
|
155
236
|
await cmdApps();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { t } from "./i18n.js";
|
|
3
|
+
import { renameProvider } from "./rename.js";
|
|
4
|
+
import { listRemovableProviders, removeProvider } from "./remove.js";
|
|
5
|
+
function reportChanges(result, dryRun) {
|
|
6
|
+
console.log(t(dryRun ? "manage.preview" : "manage.changed", { count: result.files.length }));
|
|
7
|
+
for (const file of result.files)
|
|
8
|
+
console.log(` ${file}`);
|
|
9
|
+
if (result.backupDir)
|
|
10
|
+
console.log(pc.dim(t("manage.backup", { path: result.backupDir })));
|
|
11
|
+
}
|
|
12
|
+
export async function cmdRename(id, newId, opts = {}) {
|
|
13
|
+
const result = await renameProvider(id, newId, opts);
|
|
14
|
+
if (!opts.dryRun)
|
|
15
|
+
console.log(pc.green(t("rename.done", { oldId: id, newId })));
|
|
16
|
+
reportChanges(result, opts.dryRun);
|
|
17
|
+
}
|
|
18
|
+
export async function cmdRemoveProvider(id, opts = {}) {
|
|
19
|
+
const result = await removeProvider(id, opts);
|
|
20
|
+
if (!opts.dryRun) {
|
|
21
|
+
console.log(pc.green(opts.apps
|
|
22
|
+
? t("remove.localDone", { id, apps: opts.apps })
|
|
23
|
+
: t("remove.removed", { id })));
|
|
24
|
+
if (!opts.apps && !opts.prune)
|
|
25
|
+
console.log(pc.dim(t("remove.note")));
|
|
26
|
+
}
|
|
27
|
+
reportChanges(result, opts.dryRun);
|
|
28
|
+
}
|
|
29
|
+
export function cmdListLocalProviders(apps) {
|
|
30
|
+
const rows = listRemovableProviders(apps);
|
|
31
|
+
if (!rows.length) {
|
|
32
|
+
console.log(t("list.localNone"));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const row of rows)
|
|
36
|
+
console.log(`${row.app.padEnd(12)} ${row.id}${row.name && row.name !== row.id ? ` · ${row.name}` : ""}`);
|
|
37
|
+
}
|