@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.
Files changed (198) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/conversation.d.ts +42 -0
  3. package/dist/agent/conversation.js +105 -0
  4. package/dist/agent/loop.d.ts +19 -0
  5. package/dist/agent/loop.js +185 -0
  6. package/dist/agent/planner.d.ts +8 -0
  7. package/dist/agent/planner.js +43 -0
  8. package/dist/auth/client.d.ts +4 -0
  9. package/dist/auth/client.js +24 -0
  10. package/dist/auth/config.d.ts +21 -0
  11. package/dist/auth/config.js +83 -0
  12. package/dist/commands/chat.d.ts +5 -0
  13. package/dist/commands/chat.js +27 -0
  14. package/dist/commands/config.d.ts +2 -0
  15. package/dist/commands/config.js +37 -0
  16. package/dist/commands/login.d.ts +2 -0
  17. package/dist/commands/login.js +93 -0
  18. package/dist/commands/marketplace.d.ts +6 -0
  19. package/dist/commands/marketplace.js +213 -0
  20. package/dist/commands/models.d.ts +2 -0
  21. package/dist/commands/models.js +53 -0
  22. package/dist/compact/history-store.d.ts +29 -0
  23. package/dist/compact/history-store.js +110 -0
  24. package/dist/compact/microcompact.d.ts +10 -0
  25. package/dist/compact/microcompact.js +43 -0
  26. package/dist/compact/service.d.ts +13 -0
  27. package/dist/compact/service.js +156 -0
  28. package/dist/context/analyzer.d.ts +26 -0
  29. package/dist/context/analyzer.js +99 -0
  30. package/dist/context/builder.d.ts +13 -0
  31. package/dist/context/builder.js +144 -0
  32. package/dist/context/cache.d.ts +6 -0
  33. package/dist/context/cache.js +8 -0
  34. package/dist/context/git-context.d.ts +9 -0
  35. package/dist/context/git-context.js +39 -0
  36. package/dist/context/llmtune-md.d.ts +6 -0
  37. package/dist/context/llmtune-md.js +73 -0
  38. package/dist/context/workspace.d.ts +11 -0
  39. package/dist/context/workspace.js +115 -0
  40. package/dist/index.d.ts +3 -0
  41. package/dist/index.js +3 -2
  42. package/dist/marketplace/client.d.ts +52 -0
  43. package/dist/marketplace/client.js +86 -0
  44. package/dist/memory/files.d.ts +14 -0
  45. package/dist/memory/files.js +116 -0
  46. package/dist/memory/service.d.ts +22 -0
  47. package/dist/memory/service.js +146 -0
  48. package/dist/repl/repl.d.ts +8 -0
  49. package/dist/repl/repl.js +375 -0
  50. package/dist/skills/args.d.ts +10 -0
  51. package/dist/skills/args.js +37 -0
  52. package/dist/skills/frontmatter.d.ts +6 -0
  53. package/dist/skills/frontmatter.js +44 -0
  54. package/dist/skills/loader.d.ts +5 -0
  55. package/dist/skills/loader.js +59 -0
  56. package/dist/skills/registry.d.ts +27 -0
  57. package/dist/skills/registry.js +162 -0
  58. package/dist/skills/signing/signer.d.ts +19 -0
  59. package/dist/skills/signing/signer.js +110 -0
  60. package/dist/skills/trust.d.ts +11 -0
  61. package/dist/skills/trust.js +42 -0
  62. package/dist/telemetry/logger.d.ts +51 -0
  63. package/dist/telemetry/logger.js +135 -0
  64. package/dist/tools/permissions.d.ts +20 -0
  65. package/dist/tools/permissions.js +58 -0
  66. package/dist/tools/protocol.d.ts +22 -0
  67. package/dist/tools/protocol.js +3 -0
  68. package/dist/tools/registry.d.ts +20 -0
  69. package/dist/tools/registry.js +77 -0
  70. package/dist/tools/sandbox/docker.d.ts +16 -0
  71. package/dist/tools/sandbox/docker.js +240 -0
  72. package/dist/tools/sandbox/index.d.ts +18 -0
  73. package/dist/tools/sandbox/index.js +80 -0
  74. package/dist/tools/tools/ask-user.d.ts +3 -0
  75. package/dist/tools/tools/ask-user.js +56 -0
  76. package/dist/tools/tools/bash.d.ts +3 -0
  77. package/dist/tools/tools/bash.js +85 -0
  78. package/dist/tools/tools/edit.d.ts +3 -0
  79. package/dist/tools/tools/edit.js +138 -0
  80. package/dist/tools/tools/glob.d.ts +3 -0
  81. package/dist/tools/tools/glob.js +63 -0
  82. package/dist/tools/tools/grep.d.ts +3 -0
  83. package/dist/tools/tools/grep.js +148 -0
  84. package/dist/tools/tools/read.d.ts +3 -0
  85. package/dist/tools/tools/read.js +85 -0
  86. package/dist/tools/tools/web-fetch.d.ts +3 -0
  87. package/dist/tools/tools/web-fetch.js +143 -0
  88. package/dist/tools/tools/write.d.ts +3 -0
  89. package/dist/tools/tools/write.js +84 -0
  90. package/dist/tools/validation.d.ts +13 -0
  91. package/dist/tools/validation.js +142 -0
  92. package/dist/utils/markdown.d.ts +9 -0
  93. package/dist/utils/markdown.js +89 -0
  94. package/dist/utils/streaming.d.ts +10 -0
  95. package/dist/utils/streaming.js +63 -0
  96. package/dist/utils/tokens.d.ts +12 -0
  97. package/dist/utils/tokens.js +44 -0
  98. package/dist/version.d.ts +2 -0
  99. package/dist/version.js +9 -0
  100. package/package.json +2 -2
  101. package/dist/agent/conversation.d.ts.map +0 -1
  102. package/dist/agent/loop.d.ts.map +0 -1
  103. package/dist/agent/planner.d.ts.map +0 -1
  104. package/dist/auth/client.d.ts.map +0 -1
  105. package/dist/auth/config.d.ts.map +0 -1
  106. package/dist/commands/chat.d.ts.map +0 -1
  107. package/dist/commands/config.d.ts.map +0 -1
  108. package/dist/commands/login.d.ts.map +0 -1
  109. package/dist/commands/marketplace.d.ts.map +0 -1
  110. package/dist/commands/models.d.ts.map +0 -1
  111. package/dist/compact/history-store.d.ts.map +0 -1
  112. package/dist/compact/microcompact.d.ts.map +0 -1
  113. package/dist/compact/service.d.ts.map +0 -1
  114. package/dist/context/analyzer.d.ts.map +0 -1
  115. package/dist/context/builder.d.ts.map +0 -1
  116. package/dist/context/cache.d.ts.map +0 -1
  117. package/dist/context/git-context.d.ts.map +0 -1
  118. package/dist/context/llmtune-md.d.ts.map +0 -1
  119. package/dist/context/workspace.d.ts.map +0 -1
  120. package/dist/index.d.ts.map +0 -1
  121. package/dist/marketplace/client.d.ts.map +0 -1
  122. package/dist/memory/files.d.ts.map +0 -1
  123. package/dist/memory/service.d.ts.map +0 -1
  124. package/dist/repl/repl.d.ts.map +0 -1
  125. package/dist/skills/args.d.ts.map +0 -1
  126. package/dist/skills/frontmatter.d.ts.map +0 -1
  127. package/dist/skills/loader.d.ts.map +0 -1
  128. package/dist/skills/registry.d.ts.map +0 -1
  129. package/dist/skills/signing/signer.d.ts.map +0 -1
  130. package/dist/skills/trust.d.ts.map +0 -1
  131. package/dist/telemetry/logger.d.ts.map +0 -1
  132. package/dist/tools/permissions.d.ts.map +0 -1
  133. package/dist/tools/protocol.d.ts.map +0 -1
  134. package/dist/tools/registry.d.ts.map +0 -1
  135. package/dist/tools/sandbox/docker.d.ts.map +0 -1
  136. package/dist/tools/sandbox/index.d.ts.map +0 -1
  137. package/dist/tools/tools/ask-user.d.ts.map +0 -1
  138. package/dist/tools/tools/bash.d.ts.map +0 -1
  139. package/dist/tools/tools/edit.d.ts.map +0 -1
  140. package/dist/tools/tools/glob.d.ts.map +0 -1
  141. package/dist/tools/tools/grep.d.ts.map +0 -1
  142. package/dist/tools/tools/read.d.ts.map +0 -1
  143. package/dist/tools/tools/web-fetch.d.ts.map +0 -1
  144. package/dist/tools/tools/write.d.ts.map +0 -1
  145. package/dist/tools/validation.d.ts.map +0 -1
  146. package/dist/utils/markdown.d.ts.map +0 -1
  147. package/dist/utils/streaming.d.ts.map +0 -1
  148. package/dist/utils/tokens.d.ts.map +0 -1
  149. package/src/agent/conversation.ts +0 -140
  150. package/src/agent/loop.ts +0 -215
  151. package/src/agent/planner.ts +0 -55
  152. package/src/auth/client.ts +0 -19
  153. package/src/auth/config.ts +0 -89
  154. package/src/commands/chat.ts +0 -28
  155. package/src/commands/config.ts +0 -36
  156. package/src/commands/login.ts +0 -63
  157. package/src/commands/marketplace.ts +0 -190
  158. package/src/commands/models.ts +0 -74
  159. package/src/compact/history-store.ts +0 -101
  160. package/src/compact/microcompact.ts +0 -49
  161. package/src/compact/service.ts +0 -154
  162. package/src/context/analyzer.ts +0 -127
  163. package/src/context/builder.ts +0 -123
  164. package/src/context/cache.ts +0 -11
  165. package/src/context/git-context.ts +0 -58
  166. package/src/context/llmtune-md.ts +0 -48
  167. package/src/context/workspace.ts +0 -139
  168. package/src/index.ts +0 -100
  169. package/src/marketplace/client.ts +0 -118
  170. package/src/memory/files.ts +0 -81
  171. package/src/memory/service.ts +0 -124
  172. package/src/repl/repl.ts +0 -400
  173. package/src/skills/args.ts +0 -35
  174. package/src/skills/builtin/explain-code/SKILL.md +0 -30
  175. package/src/skills/frontmatter.ts +0 -47
  176. package/src/skills/loader.ts +0 -25
  177. package/src/skills/registry.ts +0 -155
  178. package/src/skills/signing/signer.ts +0 -101
  179. package/src/skills/trust.ts +0 -50
  180. package/src/telemetry/logger.ts +0 -108
  181. package/src/tools/permissions.ts +0 -83
  182. package/src/tools/protocol.ts +0 -24
  183. package/src/tools/registry.ts +0 -93
  184. package/src/tools/sandbox/docker.ts +0 -225
  185. package/src/tools/sandbox/index.ts +0 -91
  186. package/src/tools/tools/ask-user.ts +0 -60
  187. package/src/tools/tools/bash.ts +0 -97
  188. package/src/tools/tools/edit.ts +0 -111
  189. package/src/tools/tools/glob.ts +0 -68
  190. package/src/tools/tools/grep.ts +0 -121
  191. package/src/tools/tools/read.ts +0 -57
  192. package/src/tools/tools/web-fetch.ts +0 -158
  193. package/src/tools/tools/write.ts +0 -52
  194. package/src/tools/validation.ts +0 -164
  195. package/src/utils/markdown.ts +0 -96
  196. package/src/utils/streaming.ts +0 -63
  197. package/src/utils/tokens.ts +0 -41
  198. package/tsconfig.json +0 -20
@@ -1,118 +0,0 @@
1
- /**
2
- * Skill marketplace client.
3
- * Interacts with the infra's skill registry API to list, search, install, and publish skills.
4
- */
5
- import type { AppConfig } from "../auth/config"
6
-
7
- export interface MarketplaceSkill {
8
- name: string
9
- description: string
10
- trustLevel: "local" | "community" | "verified" | "signed"
11
- allowedTools: string[]
12
- author?: string
13
- version?: string
14
- installs?: number
15
- rating?: number
16
- tags?: string[]
17
- }
18
-
19
- export interface SearchResult {
20
- skills: MarketplaceSkill[]
21
- total: number
22
- page: number
23
- }
24
-
25
- function getApiBase(config: AppConfig): string {
26
- return String(config.apiBase ?? "https://api.llmtune.io/api/agent/v1").replace(/\/$/, "")
27
- }
28
-
29
- function getHeaders(config: AppConfig): Record<string, string> {
30
- return {
31
- "Content-Type": "application/json",
32
- Authorization: `Bearer ${config.apiKey}`,
33
- }
34
- }
35
-
36
- /**
37
- * List all skills in the marketplace.
38
- */
39
- export async function listSkills(
40
- config: AppConfig,
41
- options?: { search?: string; tag?: string; page?: number; limit?: number },
42
- ): Promise<SearchResult> {
43
- const base = getApiBase(config)
44
- const params = new URLSearchParams()
45
- if (options?.search) params.set("search", options.search)
46
- if (options?.tag) params.set("tag", options.tag)
47
- if (options?.page) params.set("page", String(options.page))
48
- if (options?.limit) params.set("limit", String(options.limit))
49
-
50
- const url = `${base}/skills?${params.toString()}`
51
- const response = await fetch(url, { headers: getHeaders(config) })
52
-
53
- if (!response.ok) {
54
- throw new Error(`Failed to list skills: HTTP ${response.status}`)
55
- }
56
-
57
- return (await response.json()) as SearchResult
58
- }
59
-
60
- /**
61
- * Get details for a specific skill.
62
- */
63
- export async function getSkillDetails(config: AppConfig, name: string): Promise<MarketplaceSkill> {
64
- const base = getApiBase(config)
65
- const url = `${base}/skills/${encodeURIComponent(name)}`
66
- const response = await fetch(url, { headers: getHeaders(config) })
67
-
68
- if (!response.ok) {
69
- if (response.status === 404) throw new Error(`Skill not found: ${name}`)
70
- throw new Error(`Failed to get skill: HTTP ${response.status}`)
71
- }
72
-
73
- return (await response.json()) as MarketplaceSkill
74
- }
75
-
76
- /**
77
- * Install a skill from the marketplace to the local skills directory.
78
- */
79
- export async function installSkill(config: AppConfig, name: string): Promise<string> {
80
- const base = getApiBase(config)
81
- const url = `${base}/skills/install`
82
- const response = await fetch(url, {
83
- method: "POST",
84
- headers: getHeaders(config),
85
- body: JSON.stringify({ skillName: name }),
86
- })
87
-
88
- if (!response.ok) {
89
- const body = await response.text()
90
- throw new Error(`Failed to install skill: ${body}`)
91
- }
92
-
93
- const data = (await response.json()) as { installPath: string; skillName: string }
94
- return data.installPath
95
- }
96
-
97
- /**
98
- * Publish a local skill to the marketplace.
99
- */
100
- export async function publishSkill(
101
- config: AppConfig,
102
- skill: { name: string; description: string; content: string; trustLevel: string; allowedTools: string[] },
103
- ): Promise<{ published: boolean; skillName: string }> {
104
- const base = getApiBase(config)
105
- const url = `${base}/skills`
106
- const response = await fetch(url, {
107
- method: "POST",
108
- headers: getHeaders(config),
109
- body: JSON.stringify(skill),
110
- })
111
-
112
- if (!response.ok) {
113
- const body = await response.text()
114
- throw new Error(`Failed to publish skill: ${body}`)
115
- }
116
-
117
- return (await response.json()) as { published: boolean; skillName: string }
118
- }
@@ -1,81 +0,0 @@
1
- import * as fs from "fs"
2
- import * as path from "path"
3
- import { getConfigDir } from "../auth/config"
4
-
5
- export interface MemoryCategory {
6
- key: string
7
- filename: string
8
- description: string
9
- }
10
-
11
- export const MEMORY_CATEGORIES: MemoryCategory[] = [
12
- { key: "preferences", filename: "preferences.md", description: "User preferences (language, style, conventions)" },
13
- { key: "project", filename: "project-notes.md", description: "Project knowledge (architecture, patterns, key decisions)" },
14
- { key: "decisions", filename: "decisions.md", description: "Past decisions and rationale" },
15
- { key: "architecture", filename: "architecture.md", description: "System architecture notes" },
16
- ]
17
-
18
- export function getMemoryDir(): string {
19
- return path.join(getConfigDir(), "memory")
20
- }
21
-
22
- export function ensureMemoryDir(): void {
23
- const dir = getMemoryDir()
24
- if (!fs.existsSync(dir)) {
25
- fs.mkdirSync(dir, { recursive: true })
26
- }
27
- for (const cat of MEMORY_CATEGORIES) {
28
- const filePath = path.join(dir, cat.filename)
29
- if (!fs.existsSync(filePath)) {
30
- fs.writeFileSync(filePath, `# ${cat.description}\n\n`, "utf-8")
31
- }
32
- }
33
- }
34
-
35
- export function readMemory(key: string): string {
36
- const cat = MEMORY_CATEGORIES.find((c) => c.key === key)
37
- if (!cat) return ""
38
- const filePath = path.join(getMemoryDir(), cat.filename)
39
- try {
40
- return fs.readFileSync(filePath, "utf-8").trim()
41
- } catch {
42
- return ""
43
- }
44
- }
45
-
46
- export function writeMemory(key: string, content: string): void {
47
- const cat = MEMORY_CATEGORIES.find((c) => c.key === key)
48
- if (!cat) return
49
- ensureMemoryDir()
50
- const filePath = path.join(getMemoryDir(), cat.filename)
51
- fs.writeFileSync(filePath, content, "utf-8")
52
- }
53
-
54
- export function appendMemory(key: string, line: string): void {
55
- const current = readMemory(key)
56
- writeMemory(key, current + "\n" + line)
57
- }
58
-
59
- export function readAllMemory(): Record<string, string> {
60
- const result: Record<string, string> = {}
61
- for (const cat of MEMORY_CATEGORIES) {
62
- const content = readMemory(cat.key)
63
- if (content) result[cat.key] = content
64
- }
65
- return result
66
- }
67
-
68
- export function buildMemoryPrompt(): string {
69
- const memories = readAllMemory()
70
- const entries = Object.entries(memories)
71
- if (entries.length === 0) return ""
72
- const lines = ["## User Memory"]
73
- for (const [key, content] of entries) {
74
- const cat = MEMORY_CATEGORIES.find((c) => c.key === key)
75
- if (cat && content.trim()) {
76
- lines.push(`### ${cat.description}`)
77
- lines.push(content)
78
- }
79
- }
80
- return lines.join("\n")
81
- }
@@ -1,124 +0,0 @@
1
- import * as fs from "fs"
2
- import * as path from "path"
3
- import * as os from "os"
4
-
5
- const MEMORY_DIR = path.join(os.homedir(), ".llmtune", "memory")
6
-
7
- const MEMORY_FILES = {
8
- preferences: "preferences.md",
9
- "project-notes": "project-notes.md",
10
- decisions: "decisions.md",
11
- architecture: "architecture.md",
12
- } as const
13
-
14
- type MemoryCategory = keyof typeof MEMORY_FILES
15
-
16
- export interface MemoryEntry {
17
- category: MemoryCategory
18
- content: string
19
- path: string
20
- }
21
-
22
- function ensureMemoryDir(): void {
23
- if (!fs.existsSync(MEMORY_DIR)) {
24
- fs.mkdirSync(MEMORY_DIR, { recursive: true })
25
- }
26
- }
27
-
28
- function getMemoryPath(category: MemoryCategory): string {
29
- return path.join(MEMORY_DIR, MEMORY_FILES[category])
30
- }
31
-
32
- export function readMemory(category: MemoryCategory): string {
33
- const filePath = getMemoryPath(category)
34
- try {
35
- return fs.readFileSync(filePath, "utf-8").trim()
36
- } catch {
37
- return ""
38
- }
39
- }
40
-
41
- export function writeMemory(category: MemoryCategory, content: string): void {
42
- ensureMemoryDir()
43
- const filePath = getMemoryPath(category)
44
- fs.writeFileSync(filePath, content.trim() + "\n", "utf-8")
45
- }
46
-
47
- export function appendMemory(category: MemoryCategory, line: string): void {
48
- ensureMemoryDir()
49
- const existing = readMemory(category)
50
- const updated = existing ? `${existing}\n${line}` : line
51
- writeMemory(category, updated)
52
- }
53
-
54
- export function readAllMemory(): MemoryEntry[] {
55
- ensureMemoryDir()
56
- const entries: MemoryEntry[] = []
57
- for (const [category, filename] of Object.entries(MEMORY_FILES)) {
58
- const content = readMemory(category as MemoryCategory)
59
- if (content) {
60
- entries.push({
61
- category: category as MemoryCategory,
62
- content,
63
- path: path.join(MEMORY_DIR, filename),
64
- })
65
- }
66
- }
67
- return entries
68
- }
69
-
70
- export function buildMemoryPrompt(): string {
71
- const entries = readAllMemory()
72
- if (entries.length === 0) return ""
73
-
74
- const sections = entries.map((entry) => {
75
- const label = entry.category.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())
76
- return `### ${label}\n${entry.content}`
77
- })
78
-
79
- return "## User Memory\n\n" + sections.join("\n\n")
80
- }
81
-
82
- export function clearMemory(category?: MemoryCategory): void {
83
- if (category) {
84
- const filePath = getMemoryPath(category)
85
- try {
86
- fs.unlinkSync(filePath)
87
- } catch {
88
- // file doesn't exist
89
- }
90
- } else {
91
- for (const filename of Object.values(MEMORY_FILES)) {
92
- try {
93
- fs.unlinkSync(path.join(MEMORY_DIR, filename))
94
- } catch {
95
- // skip
96
- }
97
- }
98
- }
99
- }
100
-
101
- export function getMemoryDir(): string {
102
- return MEMORY_DIR
103
- }
104
-
105
- export function initMemoryFiles(): void {
106
- ensureMemoryDir()
107
- const defaults: Record<MemoryCategory, string> = {
108
- preferences:
109
- "# User Preferences\n# Add your coding preferences here (one per line)\n# Example: I prefer TypeScript over JavaScript\n# Example: I use 2-space indentation\n",
110
- "project-notes":
111
- "# Project Notes\n# Key facts about the current project\n# Example: Auth uses JWT + bcrypt\n# Example: Database is Neon PostgreSQL via Prisma\n",
112
- decisions:
113
- "# Architecture Decisions\n# Record important technical decisions\n# Example: Decided to use Prisma instead of Drizzle for ORM\n",
114
- architecture:
115
- "# Architecture Overview\n# Describe the project structure\n# Example: Frontend: Next.js 16, Backend: Express 5, DB: Neon\n",
116
- }
117
-
118
- for (const [category, defaultContent] of Object.entries(defaults)) {
119
- const filePath = getMemoryPath(category as MemoryCategory)
120
- if (!fs.existsSync(filePath)) {
121
- fs.writeFileSync(filePath, defaultContent, "utf-8")
122
- }
123
- }
124
- }