-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·147 lines (127 loc) · 4.24 KB
/
index.ts
File metadata and controls
executable file
·147 lines (127 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bun
import { parseCliArgs } from "./src/cli";
import { scanAllPlugins, listAvailablePlugins } from "./src/scanner";
import { loadConfig, saveConfig, mergeCliWithConfig } from "./src/config";
import { translatePlugins } from "./src/translator";
import { executeCopilot } from "./src/executor";
import { runOperator } from "./src/operator";
import { clearAllCaches } from "./src/cache";
import { enablePlugin, disablePlugin, listEnabledPlugins } from "./src/plugin";
import {
addMarketplace,
listMarketplaces,
removeMarketplace,
updateMarketplace,
updateAllMarketplaces,
} from "./src/marketplace";
async function main(): Promise<void> {
const args = parseCliArgs(process.argv);
if (args.command === "operator") {
const exitCode = await runOperator({ passthroughArgs: args.passthroughArgs });
process.exit(exitCode);
}
if (args.command === "plugin") {
if (args.pluginSubcommand === "enable" && args.pluginName) {
await enablePlugin(args.pluginName);
process.exit(0);
}
if (args.pluginSubcommand === "disable" && args.pluginName) {
await disablePlugin(args.pluginName);
process.exit(0);
}
if (
args.listEnabledPlugins &&
!args.pluginSubcommand &&
!args.marketplaceSubcommand
) {
await listEnabledPlugins();
process.exit(0);
}
if (args.marketplaceSubcommand === "list") {
await listMarketplaces();
process.exit(0);
}
if (args.marketplaceSubcommand === "add" && args.marketplaceTarget) {
await addMarketplace(args.marketplaceTarget);
process.exit(0);
}
if (args.marketplaceSubcommand === "remove" && args.marketplaceTarget) {
await removeMarketplace(args.marketplaceTarget);
process.exit(0);
}
if (args.marketplaceSubcommand === "update") {
if (args.updateAll) {
await updateAllMarketplaces();
process.exit(0);
}
if (args.marketplaceTarget) {
await updateMarketplace(args.marketplaceTarget);
process.exit(0);
}
console.error(
"Error: Marketplace name is required for 'update' command. Use '--all' to update all marketplaces or provide a marketplace name."
);
process.exit(1);
}
// If we get here with a plugin command but no valid subcommand,
// show help for the plugin command
console.error("Error: plugin command requires a subcommand");
console.error("Run 'construct plugin --help' for usage information");
process.exit(1);
}
// Handle --clear-cache
if (args.clearCache) {
await clearAllCaches();
console.log("Cache cleared.");
process.exit(0);
}
// Handle --list
if (args.listAvailablePlugins) {
const plugins = await listAvailablePlugins();
if (plugins.length === 0) {
console.log("No plugins installed. Install plugins via Claude Code first.");
} else {
console.log("Available plugins:");
for (const plugin of plugins) {
console.log(` ${plugin}`);
}
}
process.exit(0);
}
// Load saved config and merge with CLI args
const savedConfig = await loadConfig();
const enabledPluginNames = mergeCliWithConfig(args.enabledPlugins, savedConfig);
// Scan all available plugins (installed and marketplace)
const registry = await scanAllPlugins();
// Resolve enabled plugins to PluginInfo objects
const enabledPlugins = [];
for (const pluginName of enabledPluginNames) {
const plugin = registry.plugins.get(pluginName);
if (plugin) {
enabledPlugins.push(plugin);
} else {
console.warn(`Warning: Plugin "${pluginName}" not found. Skipping.`);
}
}
// Save config if plugins were enabled via CLI
if (args.enabledPlugins.length > 0) {
await saveConfig({
enabledPlugins: args.enabledPlugins,
lastUsed: new Date().toISOString(),
});
}
// Translate plugins to copilot format
const translation = await translatePlugins(enabledPlugins);
// Execute copilot
const exitCode = executeCopilot({
env: translation.env,
additionalMcpConfig: translation.additionalMcpConfig,
passthroughArgs: args.passthroughArgs,
translatedAgents: translation.translatedAgents,
});
process.exit(exitCode);
}
main().catch((error) => {
console.error("Error:", error);
process.exit(1);
});