@llmtune/cli 0.1.0 → 0.1.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/README.md +1 -1
- package/dist/agent/conversation.d.ts +42 -0
- package/dist/agent/conversation.js +105 -0
- package/dist/agent/loop.d.ts +19 -0
- package/dist/agent/loop.js +185 -0
- package/dist/agent/planner.d.ts +8 -0
- package/dist/agent/planner.js +43 -0
- package/dist/auth/client.d.ts +4 -0
- package/dist/auth/client.js +24 -0
- package/dist/auth/config.d.ts +21 -0
- package/dist/auth/config.js +83 -0
- package/dist/commands/chat.d.ts +5 -0
- package/dist/commands/chat.js +27 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +37 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +93 -0
- package/dist/commands/marketplace.d.ts +6 -0
- package/dist/commands/marketplace.js +213 -0
- package/dist/commands/models.d.ts +2 -0
- package/dist/commands/models.js +53 -0
- package/dist/compact/history-store.d.ts +29 -0
- package/dist/compact/history-store.js +110 -0
- package/dist/compact/microcompact.d.ts +10 -0
- package/dist/compact/microcompact.js +43 -0
- package/dist/compact/service.d.ts +13 -0
- package/dist/compact/service.js +156 -0
- package/dist/context/analyzer.d.ts +26 -0
- package/dist/context/analyzer.js +99 -0
- package/dist/context/builder.d.ts +13 -0
- package/dist/context/builder.js +144 -0
- package/dist/context/cache.d.ts +6 -0
- package/dist/context/cache.js +8 -0
- package/dist/context/git-context.d.ts +9 -0
- package/dist/context/git-context.js +39 -0
- package/dist/context/llmtune-md.d.ts +6 -0
- package/dist/context/llmtune-md.js +73 -0
- package/dist/context/workspace.d.ts +11 -0
- package/dist/context/workspace.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -2
- package/dist/marketplace/client.d.ts +52 -0
- package/dist/marketplace/client.js +86 -0
- package/dist/memory/files.d.ts +14 -0
- package/dist/memory/files.js +116 -0
- package/dist/memory/service.d.ts +22 -0
- package/dist/memory/service.js +146 -0
- package/dist/repl/repl.d.ts +8 -0
- package/dist/repl/repl.js +375 -0
- package/dist/skills/args.d.ts +10 -0
- package/dist/skills/args.js +37 -0
- package/dist/skills/frontmatter.d.ts +6 -0
- package/dist/skills/frontmatter.js +44 -0
- package/dist/skills/loader.d.ts +5 -0
- package/dist/skills/loader.js +59 -0
- package/dist/skills/registry.d.ts +27 -0
- package/dist/skills/registry.js +162 -0
- package/dist/skills/signing/signer.d.ts +19 -0
- package/dist/skills/signing/signer.js +110 -0
- package/dist/skills/trust.d.ts +11 -0
- package/dist/skills/trust.js +42 -0
- package/dist/telemetry/logger.d.ts +51 -0
- package/dist/telemetry/logger.js +135 -0
- package/dist/tools/permissions.d.ts +20 -0
- package/dist/tools/permissions.js +58 -0
- package/dist/tools/protocol.d.ts +22 -0
- package/dist/tools/protocol.js +3 -0
- package/dist/tools/registry.d.ts +20 -0
- package/dist/tools/registry.js +77 -0
- package/dist/tools/sandbox/docker.d.ts +16 -0
- package/dist/tools/sandbox/docker.js +240 -0
- package/dist/tools/sandbox/index.d.ts +18 -0
- package/dist/tools/sandbox/index.js +80 -0
- package/dist/tools/tools/ask-user.d.ts +3 -0
- package/dist/tools/tools/ask-user.js +56 -0
- package/dist/tools/tools/bash.d.ts +3 -0
- package/dist/tools/tools/bash.js +85 -0
- package/dist/tools/tools/edit.d.ts +3 -0
- package/dist/tools/tools/edit.js +138 -0
- package/dist/tools/tools/glob.d.ts +3 -0
- package/dist/tools/tools/glob.js +63 -0
- package/dist/tools/tools/grep.d.ts +3 -0
- package/dist/tools/tools/grep.js +148 -0
- package/dist/tools/tools/read.d.ts +3 -0
- package/dist/tools/tools/read.js +85 -0
- package/dist/tools/tools/web-fetch.d.ts +3 -0
- package/dist/tools/tools/web-fetch.js +143 -0
- package/dist/tools/tools/write.d.ts +3 -0
- package/dist/tools/tools/write.js +84 -0
- package/dist/tools/validation.d.ts +13 -0
- package/dist/tools/validation.js +142 -0
- package/dist/utils/markdown.d.ts +9 -0
- package/dist/utils/markdown.js +89 -0
- package/dist/utils/streaming.d.ts +10 -0
- package/dist/utils/streaming.js +63 -0
- package/dist/utils/tokens.d.ts +12 -0
- package/dist/utils/tokens.js +44 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +9 -0
- package/package.json +2 -2
- package/dist/agent/conversation.d.ts.map +0 -1
- package/dist/agent/loop.d.ts.map +0 -1
- package/dist/agent/planner.d.ts.map +0 -1
- package/dist/auth/client.d.ts.map +0 -1
- package/dist/auth/config.d.ts.map +0 -1
- package/dist/commands/chat.d.ts.map +0 -1
- package/dist/commands/config.d.ts.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/marketplace.d.ts.map +0 -1
- package/dist/commands/models.d.ts.map +0 -1
- package/dist/compact/history-store.d.ts.map +0 -1
- package/dist/compact/microcompact.d.ts.map +0 -1
- package/dist/compact/service.d.ts.map +0 -1
- package/dist/context/analyzer.d.ts.map +0 -1
- package/dist/context/builder.d.ts.map +0 -1
- package/dist/context/cache.d.ts.map +0 -1
- package/dist/context/git-context.d.ts.map +0 -1
- package/dist/context/llmtune-md.d.ts.map +0 -1
- package/dist/context/workspace.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/marketplace/client.d.ts.map +0 -1
- package/dist/memory/files.d.ts.map +0 -1
- package/dist/memory/service.d.ts.map +0 -1
- package/dist/repl/repl.d.ts.map +0 -1
- package/dist/skills/args.d.ts.map +0 -1
- package/dist/skills/frontmatter.d.ts.map +0 -1
- package/dist/skills/loader.d.ts.map +0 -1
- package/dist/skills/registry.d.ts.map +0 -1
- package/dist/skills/signing/signer.d.ts.map +0 -1
- package/dist/skills/trust.d.ts.map +0 -1
- package/dist/telemetry/logger.d.ts.map +0 -1
- package/dist/tools/permissions.d.ts.map +0 -1
- package/dist/tools/protocol.d.ts.map +0 -1
- package/dist/tools/registry.d.ts.map +0 -1
- package/dist/tools/sandbox/docker.d.ts.map +0 -1
- package/dist/tools/sandbox/index.d.ts.map +0 -1
- package/dist/tools/tools/ask-user.d.ts.map +0 -1
- package/dist/tools/tools/bash.d.ts.map +0 -1
- package/dist/tools/tools/edit.d.ts.map +0 -1
- package/dist/tools/tools/glob.d.ts.map +0 -1
- package/dist/tools/tools/grep.d.ts.map +0 -1
- package/dist/tools/tools/read.d.ts.map +0 -1
- package/dist/tools/tools/web-fetch.d.ts.map +0 -1
- package/dist/tools/tools/write.d.ts.map +0 -1
- package/dist/tools/validation.d.ts.map +0 -1
- package/dist/utils/markdown.d.ts.map +0 -1
- package/dist/utils/streaming.d.ts.map +0 -1
- package/dist/utils/tokens.d.ts.map +0 -1
- package/src/agent/conversation.ts +0 -140
- package/src/agent/loop.ts +0 -215
- package/src/agent/planner.ts +0 -55
- package/src/auth/client.ts +0 -19
- package/src/auth/config.ts +0 -89
- package/src/commands/chat.ts +0 -28
- package/src/commands/config.ts +0 -36
- package/src/commands/login.ts +0 -63
- package/src/commands/marketplace.ts +0 -190
- package/src/commands/models.ts +0 -74
- package/src/compact/history-store.ts +0 -101
- package/src/compact/microcompact.ts +0 -49
- package/src/compact/service.ts +0 -154
- package/src/context/analyzer.ts +0 -127
- package/src/context/builder.ts +0 -123
- package/src/context/cache.ts +0 -11
- package/src/context/git-context.ts +0 -58
- package/src/context/llmtune-md.ts +0 -48
- package/src/context/workspace.ts +0 -139
- package/src/index.ts +0 -100
- package/src/marketplace/client.ts +0 -118
- package/src/memory/files.ts +0 -81
- package/src/memory/service.ts +0 -124
- package/src/repl/repl.ts +0 -400
- package/src/skills/args.ts +0 -35
- package/src/skills/builtin/explain-code/SKILL.md +0 -30
- package/src/skills/frontmatter.ts +0 -47
- package/src/skills/loader.ts +0 -25
- package/src/skills/registry.ts +0 -155
- package/src/skills/signing/signer.ts +0 -101
- package/src/skills/trust.ts +0 -50
- package/src/telemetry/logger.ts +0 -108
- package/src/tools/permissions.ts +0 -83
- package/src/tools/protocol.ts +0 -24
- package/src/tools/registry.ts +0 -93
- package/src/tools/sandbox/docker.ts +0 -225
- package/src/tools/sandbox/index.ts +0 -91
- package/src/tools/tools/ask-user.ts +0 -60
- package/src/tools/tools/bash.ts +0 -97
- package/src/tools/tools/edit.ts +0 -111
- package/src/tools/tools/glob.ts +0 -68
- package/src/tools/tools/grep.ts +0 -121
- package/src/tools/tools/read.ts +0 -57
- package/src/tools/tools/web-fetch.ts +0 -158
- package/src/tools/tools/write.ts +0 -52
- package/src/tools/validation.ts +0 -164
- package/src/utils/markdown.ts +0 -96
- package/src/utils/streaming.ts +0 -63
- package/src/utils/tokens.ts +0 -41
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.loginCommand = loginCommand;
|
|
40
|
+
const readline = __importStar(require("readline"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const config_1 = require("../auth/config");
|
|
43
|
+
function ask(question, defaultValue) {
|
|
44
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
45
|
+
const prompt = defaultValue ? `${question} (${defaultValue})` : question;
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
rl.question(`${prompt}: `, (answer) => {
|
|
48
|
+
rl.close();
|
|
49
|
+
resolve(answer.trim() || defaultValue || "");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function askPassword(question) {
|
|
54
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
rl.question(`${question}: `, (answer) => {
|
|
57
|
+
rl.close();
|
|
58
|
+
resolve(answer.trim());
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function maskKey(key) {
|
|
63
|
+
if (key.length <= 12)
|
|
64
|
+
return "sk_***";
|
|
65
|
+
return `${key.slice(0, 5)}...${key.slice(-4)}`;
|
|
66
|
+
}
|
|
67
|
+
async function loginCommand() {
|
|
68
|
+
console.log(chalk_1.default.blue.bold("\nLLMTune CLI - API Configuration\n"));
|
|
69
|
+
const configPath = (0, config_1.getConfigPath)();
|
|
70
|
+
const existing = (0, config_1.loadConfig)();
|
|
71
|
+
const existingKey = existing.apiKey || "";
|
|
72
|
+
const existingUrl = existing.apiBase || "https://api.llmtune.io/api/agent/v1";
|
|
73
|
+
const existingModel = existing.defaultModel || "";
|
|
74
|
+
console.log(chalk_1.default.dim(`Config file: ${configPath}\n`));
|
|
75
|
+
const key = await askPassword("Enter your LLMTune API key (sk_...)");
|
|
76
|
+
if (!key) {
|
|
77
|
+
console.log(chalk_1.default.red("\nAPI key is required."));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
const apiBase = await ask("API base URL", existingUrl);
|
|
81
|
+
const model = await ask("Default model (leave empty for auto)", existingModel || undefined);
|
|
82
|
+
(0, config_1.saveConfig)({
|
|
83
|
+
apiKey: key,
|
|
84
|
+
apiBase: apiBase.replace(/\/$/, ""),
|
|
85
|
+
defaultModel: model || undefined,
|
|
86
|
+
});
|
|
87
|
+
console.log(chalk_1.default.green("\nConfiguration saved!"));
|
|
88
|
+
console.log(` API key: ${maskKey(key)}`);
|
|
89
|
+
console.log(` API base: ${apiBase}`);
|
|
90
|
+
console.log(` Model: ${model || "auto"}`);
|
|
91
|
+
console.log(chalk_1.default.dim(`\nRun ${chalk_1.default.bold("llmtune chat")} to start.\n`));
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function marketplaceCommand(action: string, args: string[]): Promise<void>;
|
|
2
|
+
export declare function listSkillsCommand(): Promise<void>;
|
|
3
|
+
export declare function installSkillCommand(name: string): Promise<void>;
|
|
4
|
+
export declare function publishSkillCommand(dir: string): Promise<void>;
|
|
5
|
+
export declare function signSkillCommand(dir: string): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=marketplace.d.ts.map
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.marketplaceCommand = marketplaceCommand;
|
|
40
|
+
exports.listSkillsCommand = listSkillsCommand;
|
|
41
|
+
exports.installSkillCommand = installSkillCommand;
|
|
42
|
+
exports.publishSkillCommand = publishSkillCommand;
|
|
43
|
+
exports.signSkillCommand = signSkillCommand;
|
|
44
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
const readline_1 = require("readline");
|
|
46
|
+
const client_1 = require("../marketplace/client");
|
|
47
|
+
const config_1 = require("../auth/config");
|
|
48
|
+
async function marketplaceCommand(action, args) {
|
|
49
|
+
const config = (0, config_1.loadConfig)();
|
|
50
|
+
const apiKey = config.apiKey;
|
|
51
|
+
if (!apiKey) {
|
|
52
|
+
console.log(chalk_1.default.red('Not logged in. Run "llmtune login" first.'));
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
switch (action) {
|
|
56
|
+
case "search":
|
|
57
|
+
case "list":
|
|
58
|
+
await searchSkills(config, args[0] ?? "");
|
|
59
|
+
break;
|
|
60
|
+
case "info":
|
|
61
|
+
if (!args[0]) {
|
|
62
|
+
console.log(chalk_1.default.yellow("Usage: llmtune skills info <skill-name>"));
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
await showSkillInfo(config, args[0]);
|
|
66
|
+
break;
|
|
67
|
+
case "install":
|
|
68
|
+
if (!args[0]) {
|
|
69
|
+
console.log(chalk_1.default.yellow("Usage: llmtune skills install <skill-name>"));
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
await doInstallSkill(config, args[0]);
|
|
73
|
+
break;
|
|
74
|
+
case "publish":
|
|
75
|
+
if (!args[0]) {
|
|
76
|
+
console.log(chalk_1.default.yellow("Usage: llmtune skills publish <skill-dir>"));
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
await doPublishSkill(config, args[0]);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
console.log(chalk_1.default.yellow(`Unknown action: ${action}`));
|
|
83
|
+
console.log(chalk_1.default.dim("Available: search, info, install, publish"));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function searchSkills(config, query) {
|
|
87
|
+
console.log(chalk_1.default.cyan(`\nSearching skills${query ? `: ${query}` : ""}...\n`));
|
|
88
|
+
const result = await (0, client_1.listSkills)(config, { search: query || undefined });
|
|
89
|
+
const skills = result.skills;
|
|
90
|
+
if (skills.length === 0) {
|
|
91
|
+
console.log(chalk_1.default.dim("No skills found."));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (const skill of skills) {
|
|
95
|
+
const trust = chalk_1.default.dim(`[${skill.trustLevel}]`);
|
|
96
|
+
const installs = skill.installs ? chalk_1.default.dim(`(${skill.installs} installs)`) : "";
|
|
97
|
+
console.log(` ${chalk_1.default.bold(skill.name)} ${trust} ${installs}`);
|
|
98
|
+
console.log(` ${chalk_1.default.dim(skill.description)}`);
|
|
99
|
+
if (skill.author) {
|
|
100
|
+
console.log(` ${chalk_1.default.dim(`by ${skill.author}`)}`);
|
|
101
|
+
}
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
console.log(chalk_1.default.dim(`${skills.length} of ${result.total} skills shown. Use ${chalk_1.default.bold("llmtune skills install <name>")} to install.`));
|
|
105
|
+
}
|
|
106
|
+
async function showSkillInfo(config, name) {
|
|
107
|
+
try {
|
|
108
|
+
const skill = await (0, client_1.getSkillDetails)(config, name);
|
|
109
|
+
console.log(chalk_1.default.bold(`\n${skill.name}`));
|
|
110
|
+
console.log(chalk_1.default.dim(skill.description));
|
|
111
|
+
console.log();
|
|
112
|
+
console.log(` Trust: ${skill.trustLevel}`);
|
|
113
|
+
console.log(` Author: ${skill.author ?? "unknown"}`);
|
|
114
|
+
if (skill.installs !== undefined)
|
|
115
|
+
console.log(` Installs: ${skill.installs}`);
|
|
116
|
+
if (skill.rating !== undefined) {
|
|
117
|
+
const stars = "\u2605".repeat(Math.round(skill.rating)) + "\u2606".repeat(5 - Math.round(skill.rating));
|
|
118
|
+
console.log(` Rating: ${stars} (${skill.rating.toFixed(1)})`);
|
|
119
|
+
}
|
|
120
|
+
if (skill.allowedTools.length > 0) {
|
|
121
|
+
console.log(` Tools: ${skill.allowedTools.join(", ")}`);
|
|
122
|
+
}
|
|
123
|
+
if (skill.tags && skill.tags.length > 0) {
|
|
124
|
+
console.log(` Tags: ${skill.tags.join(", ")}`);
|
|
125
|
+
}
|
|
126
|
+
console.log();
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
130
|
+
console.log(chalk_1.default.red(`Error: ${msg}`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function doInstallSkill(config, name) {
|
|
134
|
+
console.log(chalk_1.default.cyan(`Installing skill: ${name}...`));
|
|
135
|
+
try {
|
|
136
|
+
const skillPath = await (0, client_1.installSkill)(config, name);
|
|
137
|
+
console.log(chalk_1.default.green(`\nSkill "${name}" installed to: ${skillPath}`));
|
|
138
|
+
console.log(chalk_1.default.dim(`Run /${name} in a chat session to use it.`));
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
142
|
+
console.log(chalk_1.default.red(`\nFailed to install: ${msg}`));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function doPublishSkill(config, skillDir) {
|
|
146
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs/promises")));
|
|
147
|
+
const path = await Promise.resolve().then(() => __importStar(require("path")));
|
|
148
|
+
const mdPath = path.join(skillDir, "SKILL.md");
|
|
149
|
+
let content;
|
|
150
|
+
try {
|
|
151
|
+
content = await fs.readFile(mdPath, "utf-8");
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
console.log(chalk_1.default.red(`No SKILL.md found in: ${skillDir}`));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const name = path.basename(path.resolve(skillDir));
|
|
158
|
+
const description = content.split("\n").find((l) => l.trim() && !l.trim().startsWith("#") && !l.trim().startsWith("---"))?.trim() ?? `Skill: ${name}`;
|
|
159
|
+
console.log(chalk_1.default.cyan(`\nPublishing skill: ${name}`));
|
|
160
|
+
console.log(chalk_1.default.dim(`Path: ${skillDir}`));
|
|
161
|
+
console.log(chalk_1.default.dim(`Description: ${description.slice(0, 80)}`));
|
|
162
|
+
console.log();
|
|
163
|
+
const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout });
|
|
164
|
+
const answer = await new Promise((resolve) => {
|
|
165
|
+
rl.question(chalk_1.default.yellow("Publish this skill? [y/N] "), (ans) => {
|
|
166
|
+
rl.close();
|
|
167
|
+
resolve(ans.trim().toLowerCase());
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
if (answer !== "y" && answer !== "yes") {
|
|
171
|
+
console.log(chalk_1.default.dim("Cancelled."));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const result = await (0, client_1.publishSkill)(config, {
|
|
176
|
+
name,
|
|
177
|
+
description,
|
|
178
|
+
content,
|
|
179
|
+
trustLevel: "community",
|
|
180
|
+
allowedTools: [],
|
|
181
|
+
});
|
|
182
|
+
if (result.published) {
|
|
183
|
+
console.log(chalk_1.default.green(`\nSkill "${result.skillName}" published successfully!`));
|
|
184
|
+
console.log(chalk_1.default.dim("It will appear in the marketplace after review."));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
console.log(chalk_1.default.red(`\nFailed to publish skill "${name}".`));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
192
|
+
console.log(chalk_1.default.red(`\nFailed to publish: ${msg}`));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function listSkillsCommand() {
|
|
196
|
+
await marketplaceCommand("list", []);
|
|
197
|
+
}
|
|
198
|
+
async function installSkillCommand(name) {
|
|
199
|
+
await marketplaceCommand("install", [name]);
|
|
200
|
+
}
|
|
201
|
+
async function publishSkillCommand(dir) {
|
|
202
|
+
await marketplaceCommand("publish", [dir]);
|
|
203
|
+
}
|
|
204
|
+
async function signSkillCommand(dir) {
|
|
205
|
+
const { signSkill, generateKeyPair } = await Promise.resolve().then(() => __importStar(require("../skills/signing/signer")));
|
|
206
|
+
const keys = generateKeyPair();
|
|
207
|
+
const result = signSkill(dir, keys.privateKey, keys.publicKey);
|
|
208
|
+
console.log(chalk_1.default.green(`\nSkill signed: ${dir}`));
|
|
209
|
+
console.log(chalk_1.default.dim(`Signature: ${result.signature}`));
|
|
210
|
+
console.log(chalk_1.default.dim(`Public key: ${result.publicKey}`));
|
|
211
|
+
console.log(chalk_1.default.yellow("\nSave your private key securely. You'll need it to sign future versions."));
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=marketplace.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.modelsCommand = modelsCommand;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
+
const config_1 = require("../auth/config");
|
|
10
|
+
async function modelsCommand() {
|
|
11
|
+
const apiKey = (0, config_1.getApiKey)();
|
|
12
|
+
if (!apiKey) {
|
|
13
|
+
console.log(chalk_1.default.red('Not authenticated. Run "llmtune login" first.'));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const apiBase = (0, config_1.getApiBase)();
|
|
17
|
+
try {
|
|
18
|
+
const modelsUrl = apiBase.replace(/\/$/, "") + "/models";
|
|
19
|
+
const response = await fetch(modelsUrl, {
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${apiKey}`,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const body = await response.text();
|
|
26
|
+
console.log(chalk_1.default.red(`Failed to fetch models: ${response.status}`));
|
|
27
|
+
console.log(chalk_1.default.dim(body.slice(0, 200)));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const data = (await response.json());
|
|
31
|
+
if (data.subscription) {
|
|
32
|
+
console.log(chalk_1.default.cyan(`\nSubscription: ${data.subscription.planName}`));
|
|
33
|
+
console.log(chalk_1.default.dim(`Daily quota: ${data.subscription.quotaDaily} requests\n`));
|
|
34
|
+
}
|
|
35
|
+
const table = new cli_table3_1.default({
|
|
36
|
+
head: [
|
|
37
|
+
chalk_1.default.cyan("Model ID"),
|
|
38
|
+
chalk_1.default.cyan("Provider"),
|
|
39
|
+
],
|
|
40
|
+
colWidths: [50, 20],
|
|
41
|
+
});
|
|
42
|
+
for (const model of data.data) {
|
|
43
|
+
table.push([model.id, model.owned_by]);
|
|
44
|
+
}
|
|
45
|
+
console.log(table.toString());
|
|
46
|
+
console.log(chalk_1.default.dim(`\n${data.data.length} models available`));
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
console.log(chalk_1.default.red(`Error: ${err instanceof Error ? err.message : String(err)}`));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Message } from "../agent/conversation";
|
|
2
|
+
export interface HistorySnapshot {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
reason: "manual" | "auto";
|
|
6
|
+
messageCount: number;
|
|
7
|
+
tokenEstimate: number;
|
|
8
|
+
messages: Message[];
|
|
9
|
+
}
|
|
10
|
+
export declare function getHistoryDir(sessionId: string): string;
|
|
11
|
+
export declare function saveRawHistory(sessionId: string, messages: Message[], reason?: "manual" | "auto"): string;
|
|
12
|
+
export declare function loadRawHistory(sessionId: string): HistorySnapshot | null;
|
|
13
|
+
export declare function saveCompactionMeta(sessionId: string, meta: {
|
|
14
|
+
compactedAt: string;
|
|
15
|
+
tokensBefore: number;
|
|
16
|
+
tokensAfter: number;
|
|
17
|
+
tokensSaved: number;
|
|
18
|
+
messagesBefore: number;
|
|
19
|
+
messagesAfter: number;
|
|
20
|
+
}): void;
|
|
21
|
+
export declare function loadCompactionHistory(sessionId: string): Array<{
|
|
22
|
+
compactedAt: string;
|
|
23
|
+
tokensBefore: number;
|
|
24
|
+
tokensAfter: number;
|
|
25
|
+
tokensSaved: number;
|
|
26
|
+
messagesBefore: number;
|
|
27
|
+
messagesAfter: number;
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=history-store.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getHistoryDir = getHistoryDir;
|
|
37
|
+
exports.saveRawHistory = saveRawHistory;
|
|
38
|
+
exports.loadRawHistory = loadRawHistory;
|
|
39
|
+
exports.saveCompactionMeta = saveCompactionMeta;
|
|
40
|
+
exports.loadCompactionHistory = loadCompactionHistory;
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const os = __importStar(require("os"));
|
|
44
|
+
const SESSIONS_DIR = () => {
|
|
45
|
+
const dir = path.join(os.homedir(), ".llmtune", "sessions");
|
|
46
|
+
if (!fs.existsSync(dir))
|
|
47
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
48
|
+
return dir;
|
|
49
|
+
};
|
|
50
|
+
function getHistoryDir(sessionId) {
|
|
51
|
+
const dir = path.join(SESSIONS_DIR(), sessionId);
|
|
52
|
+
if (!fs.existsSync(dir))
|
|
53
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
54
|
+
return dir;
|
|
55
|
+
}
|
|
56
|
+
function saveRawHistory(sessionId, messages, reason = "manual") {
|
|
57
|
+
const dir = getHistoryDir(sessionId);
|
|
58
|
+
const filePath = path.join(dir, "history.json");
|
|
59
|
+
const tokenEstimate = messages.reduce((total, msg) => {
|
|
60
|
+
const content = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
61
|
+
return total + Math.ceil(content.length / 4);
|
|
62
|
+
}, 0);
|
|
63
|
+
const snapshot = {
|
|
64
|
+
sessionId,
|
|
65
|
+
timestamp: new Date().toISOString(),
|
|
66
|
+
reason,
|
|
67
|
+
messageCount: messages.length,
|
|
68
|
+
tokenEstimate,
|
|
69
|
+
messages,
|
|
70
|
+
};
|
|
71
|
+
fs.writeFileSync(filePath, JSON.stringify(snapshot, null, 2), "utf-8");
|
|
72
|
+
return filePath;
|
|
73
|
+
}
|
|
74
|
+
function loadRawHistory(sessionId) {
|
|
75
|
+
const filePath = path.join(getHistoryDir(sessionId), "history.json");
|
|
76
|
+
if (!fs.existsSync(filePath))
|
|
77
|
+
return null;
|
|
78
|
+
try {
|
|
79
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function saveCompactionMeta(sessionId, meta) {
|
|
86
|
+
const filePath = path.join(getHistoryDir(sessionId), "compaction-meta.json");
|
|
87
|
+
const history = [];
|
|
88
|
+
if (fs.existsSync(filePath)) {
|
|
89
|
+
try {
|
|
90
|
+
const existing = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
91
|
+
if (Array.isArray(existing))
|
|
92
|
+
history.push(...existing);
|
|
93
|
+
}
|
|
94
|
+
catch { /* ignore */ }
|
|
95
|
+
}
|
|
96
|
+
history.push(meta);
|
|
97
|
+
fs.writeFileSync(filePath, JSON.stringify(history, null, 2), "utf-8");
|
|
98
|
+
}
|
|
99
|
+
function loadCompactionHistory(sessionId) {
|
|
100
|
+
const filePath = path.join(getHistoryDir(sessionId), "compaction-meta.json");
|
|
101
|
+
if (!fs.existsSync(filePath))
|
|
102
|
+
return [];
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=history-store.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Message } from "../agent/conversation";
|
|
2
|
+
/**
|
|
3
|
+
* Microcompact: reduce token usage by stripping verbose tool results
|
|
4
|
+
* and compressing old messages. Ported from Clawd-Code compact_service/microcompact.py.
|
|
5
|
+
*/
|
|
6
|
+
export declare function microcompactMessages(messages: Message[]): {
|
|
7
|
+
compacted: Message[];
|
|
8
|
+
tokensSaved: number;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=microcompact.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.microcompactMessages = microcompactMessages;
|
|
4
|
+
/**
|
|
5
|
+
* Microcompact: reduce token usage by stripping verbose tool results
|
|
6
|
+
* and compressing old messages. Ported from Clawd-Code compact_service/microcompact.py.
|
|
7
|
+
*/
|
|
8
|
+
function microcompactMessages(messages) {
|
|
9
|
+
let tokensSaved = 0;
|
|
10
|
+
const compacted = [];
|
|
11
|
+
for (const msg of messages) {
|
|
12
|
+
if (msg.role === "tool") {
|
|
13
|
+
const text = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
14
|
+
if (text.length > 2000) {
|
|
15
|
+
const compressed = compressToolResult(text);
|
|
16
|
+
tokensSaved += Math.ceil((text.length - compressed.length) / 4);
|
|
17
|
+
compacted.push({ ...msg, content: compressed });
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (msg.role === "assistant" && msg.content) {
|
|
22
|
+
const text = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
23
|
+
if (text.length > 10000) {
|
|
24
|
+
const truncated = text.slice(0, 5000) + "\n... [truncated for compaction]";
|
|
25
|
+
tokensSaved += Math.ceil((text.length - truncated.length) / 4);
|
|
26
|
+
compacted.push({ ...msg, content: truncated });
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
compacted.push(msg);
|
|
31
|
+
}
|
|
32
|
+
return { compacted, tokensSaved };
|
|
33
|
+
}
|
|
34
|
+
function compressToolResult(text) {
|
|
35
|
+
// Keep first 500 chars and last 500 chars of large tool results
|
|
36
|
+
if (text.length <= 2000)
|
|
37
|
+
return text;
|
|
38
|
+
const head = text.slice(0, 500);
|
|
39
|
+
const tail = text.slice(-500);
|
|
40
|
+
const lines = text.split("\n").length;
|
|
41
|
+
return `${head}\n\n... [${lines} lines compressed, ${text.length} chars total] ...\n\n${tail}`;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=microcompact.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { Conversation } from "../agent/conversation";
|
|
3
|
+
export interface CompactResult {
|
|
4
|
+
tokensSaved: number;
|
|
5
|
+
preCompactTokens: number;
|
|
6
|
+
postCompactTokens: number;
|
|
7
|
+
preCompactMessages: number;
|
|
8
|
+
postCompactMessages: number;
|
|
9
|
+
summary: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function compactConversation(client: OpenAI, model: string, conversation: Conversation, sessionsDir?: string): Promise<CompactResult>;
|
|
12
|
+
export declare function uncompactConversation(conversation: Conversation, sessionsDir?: string): boolean;
|
|
13
|
+
//# sourceMappingURL=service.d.ts.map
|