@townco/cli 0.1.11 → 0.1.12
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 +66 -0
- package/dist/commands/create.d.ts +6 -5
- package/dist/commands/mcp-add.d.ts +5 -10
- package/dist/commands/mcp-list.js +47 -174
- package/dist/commands/run.d.ts +4 -4
- package/dist/commands/tool-add.d.ts +6 -0
- package/dist/commands/tool-add.js +376 -0
- package/dist/commands/tool-list.d.ts +3 -0
- package/dist/commands/tool-list.js +61 -0
- package/dist/commands/tool-register.d.ts +7 -0
- package/dist/commands/tool-register.js +291 -0
- package/dist/commands/tool-remove.d.ts +3 -0
- package/dist/commands/tool-remove.js +202 -0
- package/dist/commands/tool-stub.d.ts +6 -0
- package/dist/commands/tool-stub.js +376 -0
- package/dist/index.js +37 -2
- package/dist/lib/mcp-storage.d.ts +5 -5
- package/dist/lib/mcp-storage.js +48 -50
- package/dist/lib/tool-storage.d.ts +32 -0
- package/dist/lib/tool-storage.js +107 -0
- package/package.json +6 -6
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Constants
|
|
6
|
+
// ============================================================================
|
|
7
|
+
const TOWN_CONFIG_DIR = join(homedir(), ".config", "town");
|
|
8
|
+
const TOOLS_FILE = join(TOWN_CONFIG_DIR, "tools.json");
|
|
9
|
+
const TOOLS_DIR = join(TOWN_CONFIG_DIR, "tools");
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Helper Functions
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Ensure the config directory exists
|
|
15
|
+
*/
|
|
16
|
+
function ensureConfigDir() {
|
|
17
|
+
if (!existsSync(TOWN_CONFIG_DIR)) {
|
|
18
|
+
mkdirSync(TOWN_CONFIG_DIR, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Ensure the tools directory exists
|
|
23
|
+
*/
|
|
24
|
+
export function ensureToolsDir() {
|
|
25
|
+
if (!existsSync(TOOLS_DIR)) {
|
|
26
|
+
mkdirSync(TOOLS_DIR, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the tools directory path
|
|
31
|
+
*/
|
|
32
|
+
export function getToolsDir() {
|
|
33
|
+
return TOOLS_DIR;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load all tool configs from the JSON file
|
|
37
|
+
*/
|
|
38
|
+
function loadStore() {
|
|
39
|
+
ensureConfigDir();
|
|
40
|
+
if (!existsSync(TOOLS_FILE)) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const content = readFileSync(TOOLS_FILE, "utf-8");
|
|
45
|
+
return JSON.parse(content);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error(`Failed to load tool configs: ${error instanceof Error ? error.message : String(error)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Save all tool configs to the JSON file
|
|
53
|
+
*/
|
|
54
|
+
function saveStore(store) {
|
|
55
|
+
ensureConfigDir();
|
|
56
|
+
try {
|
|
57
|
+
const content = JSON.stringify(store, null, 2);
|
|
58
|
+
writeFileSync(TOOLS_FILE, content, "utf-8");
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(`Failed to save tool configs: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Public API
|
|
66
|
+
// ============================================================================
|
|
67
|
+
/**
|
|
68
|
+
* Save a tool config to the store
|
|
69
|
+
*/
|
|
70
|
+
export function saveToolConfig(config) {
|
|
71
|
+
const store = loadStore();
|
|
72
|
+
store[config.name] = config;
|
|
73
|
+
saveStore(store);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Load a tool config by name
|
|
77
|
+
*/
|
|
78
|
+
export function loadToolConfig(name) {
|
|
79
|
+
const store = loadStore();
|
|
80
|
+
return store[name] || null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Delete a tool config by name
|
|
84
|
+
*/
|
|
85
|
+
export function deleteToolConfig(name) {
|
|
86
|
+
const store = loadStore();
|
|
87
|
+
if (store[name]) {
|
|
88
|
+
delete store[name];
|
|
89
|
+
saveStore(store);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* List all tool configs
|
|
96
|
+
*/
|
|
97
|
+
export function listToolConfigs() {
|
|
98
|
+
const store = loadStore();
|
|
99
|
+
return Object.values(store).sort((a, b) => a.name.localeCompare(b.name));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if a tool config exists
|
|
103
|
+
*/
|
|
104
|
+
export function toolConfigExists(name) {
|
|
105
|
+
const store = loadStore();
|
|
106
|
+
return name in store;
|
|
107
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
-
"
|
|
6
|
+
"town": "./dist/index.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"build": "tsc"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@townco/tsconfig": "0.1.
|
|
22
|
+
"@townco/tsconfig": "0.1.4",
|
|
23
23
|
"@types/bun": "^1.3.1",
|
|
24
24
|
"@types/react": "^19.2.2"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@optique/core": "^0.6.2",
|
|
28
28
|
"@optique/run": "^0.6.2",
|
|
29
|
-
"@townco/agent": "0.1.
|
|
30
|
-
"@townco/secret": "0.1.
|
|
31
|
-
"@townco/ui": "0.1.
|
|
29
|
+
"@townco/agent": "0.1.12",
|
|
30
|
+
"@townco/secret": "0.1.7",
|
|
31
|
+
"@townco/ui": "0.1.7",
|
|
32
32
|
"@types/inquirer": "^9.0.9",
|
|
33
33
|
"ink": "^6.4.0",
|
|
34
34
|
"ink-text-input": "^6.0.0",
|