@trikhub/cli 0.17.1-dev.2 → 0.17.1-dev.3
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/dist/templates/agent-python.d.ts.map +1 -1
- package/dist/templates/agent-python.js +125 -22
- package/dist/templates/agent-python.js.map +1 -1
- package/dist/templates/agent-typescript.d.ts.map +1 -1
- package/dist/templates/agent-typescript.js +108 -21
- package/dist/templates/agent-typescript.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-python.d.ts","sourceRoot":"","sources":["../../src/templates/agent-python.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-python.d.ts","sourceRoot":"","sources":["../../src/templates/agent-python.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAmf/D;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgB5F"}
|
|
@@ -47,7 +47,8 @@ dependencies = [
|
|
|
47
47
|
"langchain-core>=0.3.0",
|
|
48
48
|
"langgraph>=0.2.0",
|
|
49
49
|
"trikhub>=0.6.0",
|
|
50
|
-
"python-dotenv>=1.0.0"
|
|
50
|
+
"python-dotenv>=1.0.0",
|
|
51
|
+
"rich>=13.0.0",${config.channels === 'cli+telegram' ? `\n "python-telegram-bot>=21.0",` : ''}
|
|
51
52
|
]
|
|
52
53
|
`;
|
|
53
54
|
}
|
|
@@ -125,6 +126,7 @@ function generateCliPy() {
|
|
|
125
126
|
from __future__ import annotations
|
|
126
127
|
|
|
127
128
|
import asyncio
|
|
129
|
+
import sys
|
|
128
130
|
|
|
129
131
|
from dotenv import load_dotenv
|
|
130
132
|
|
|
@@ -132,30 +134,121 @@ load_dotenv()
|
|
|
132
134
|
|
|
133
135
|
from agent import initialize_agent
|
|
134
136
|
|
|
137
|
+
pretty = "--no-pretty" not in sys.argv
|
|
138
|
+
|
|
139
|
+
if pretty:
|
|
140
|
+
from rich.console import Console
|
|
141
|
+
from rich.markdown import Markdown
|
|
142
|
+
from rich.theme import Theme
|
|
143
|
+
|
|
144
|
+
theme = Theme({"trik.name": "bold magenta", "trik.system": "dim italic", "trik.error": "bold red"})
|
|
145
|
+
console = Console(theme=theme)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def render_response(result) -> None:
|
|
149
|
+
if not pretty:
|
|
150
|
+
if result.source == "system":
|
|
151
|
+
print(f"\\n\\033[2m{result.message}\\033[0m\\n")
|
|
152
|
+
elif result.source != "main":
|
|
153
|
+
print(f"\\n[{result.source}] {result.message}\\n")
|
|
154
|
+
else:
|
|
155
|
+
print(f"\\nAssistant: {result.message}\\n")
|
|
156
|
+
return
|
|
157
|
+
|
|
158
|
+
if result.source == "system":
|
|
159
|
+
console.print(f" [trik.system]{result.message}[/]")
|
|
160
|
+
elif result.source != "main":
|
|
161
|
+
console.print(f"\\n [trik.name]{result.source}[/]\\n")
|
|
162
|
+
md = Markdown(result.message, code_theme="monokai")
|
|
163
|
+
console.print(md, width=min(console.width, 100))
|
|
164
|
+
console.print()
|
|
165
|
+
else:
|
|
166
|
+
console.print()
|
|
167
|
+
md = Markdown(result.message, code_theme="monokai")
|
|
168
|
+
console.print(md, width=min(console.width, 100))
|
|
169
|
+
console.print()
|
|
170
|
+
|
|
135
171
|
|
|
136
172
|
async def main() -> None:
|
|
137
|
-
|
|
173
|
+
if pretty:
|
|
174
|
+
with console.status("Loading agent..."):
|
|
175
|
+
app = await initialize_agent()
|
|
176
|
+
else:
|
|
177
|
+
print("Loading agent...\\n")
|
|
178
|
+
app = await initialize_agent()
|
|
138
179
|
|
|
139
|
-
|
|
180
|
+
status = None
|
|
140
181
|
|
|
141
182
|
# Subscribe to gateway events for real-time status feedback
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
183
|
+
def on_start(e):
|
|
184
|
+
nonlocal status
|
|
185
|
+
if pretty:
|
|
186
|
+
status = console.status(f" Connecting to {e['trikName']}...")
|
|
187
|
+
status.start()
|
|
188
|
+
else:
|
|
189
|
+
print(f"[{e['trikName']}] Connecting...")
|
|
190
|
+
|
|
191
|
+
def on_container(e):
|
|
192
|
+
nonlocal status
|
|
193
|
+
if pretty and status:
|
|
194
|
+
status.update(f" Starting {e['trikName']} container...")
|
|
195
|
+
elif not pretty:
|
|
196
|
+
print(f"[{e['trikName']}] Starting container...")
|
|
197
|
+
|
|
198
|
+
def on_thinking(e):
|
|
199
|
+
nonlocal status
|
|
200
|
+
if pretty and status:
|
|
201
|
+
status.update(f" {e['trikName']} is thinking...")
|
|
202
|
+
elif not pretty:
|
|
203
|
+
print(f"[{e['trikName']}] Thinking...")
|
|
204
|
+
|
|
205
|
+
def on_error(e):
|
|
206
|
+
nonlocal status
|
|
207
|
+
if status:
|
|
208
|
+
status.stop()
|
|
209
|
+
status = None
|
|
210
|
+
if pretty:
|
|
211
|
+
console.print(f" [trik.error]\\u2716 [{e['trikName']}] {e['error']}[/]")
|
|
212
|
+
else:
|
|
213
|
+
print(f"[{e['trikName']}] Error: {e['error']}")
|
|
214
|
+
|
|
215
|
+
def on_transfer_back(e):
|
|
216
|
+
nonlocal status
|
|
217
|
+
if status:
|
|
218
|
+
status.stop()
|
|
219
|
+
status = None
|
|
220
|
+
if pretty:
|
|
221
|
+
console.print(f" [dim]\\u2190 {e['trikName']} transferred back ({e['reason']})[/]")
|
|
222
|
+
else:
|
|
223
|
+
print(f"[{e['trikName']}] Transferred back ({e['reason']})")
|
|
224
|
+
|
|
225
|
+
app.gateway.on("handoff:start", on_start)
|
|
226
|
+
app.gateway.on("handoff:container_start", on_container)
|
|
227
|
+
app.gateway.on("handoff:thinking", on_thinking)
|
|
228
|
+
app.gateway.on("handoff:error", on_error)
|
|
229
|
+
app.gateway.on("handoff:transfer_back", on_transfer_back)
|
|
147
230
|
|
|
148
231
|
loaded_triks = app.get_loaded_triks()
|
|
149
232
|
if loaded_triks:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
233
|
+
if pretty:
|
|
234
|
+
names = ", ".join(f"[cyan]{t}[/]" for t in loaded_triks)
|
|
235
|
+
console.print(f" [dim]Loaded triks:[/] {names}")
|
|
236
|
+
else:
|
|
237
|
+
print(f"Loaded triks: {', '.join(loaded_triks)}")
|
|
238
|
+
if pretty:
|
|
239
|
+
console.print(" [dim]Type /back to return from a trik, exit to quit.[/]\\n")
|
|
240
|
+
else:
|
|
241
|
+
print('Type "/back" to return from a trik handoff, "exit" to quit.')
|
|
242
|
+
print('Tip: Ask the Agent what to do next\\n')
|
|
153
243
|
|
|
154
244
|
session_id = f"cli-{id(app)}"
|
|
155
245
|
|
|
156
246
|
while True:
|
|
157
247
|
try:
|
|
158
|
-
|
|
248
|
+
if pretty:
|
|
249
|
+
user_input = console.input("[bold green]You:[/] ").strip()
|
|
250
|
+
else:
|
|
251
|
+
user_input = input("You: ").strip()
|
|
159
252
|
except (KeyboardInterrupt, EOFError):
|
|
160
253
|
print("\\n\\nGoodbye!")
|
|
161
254
|
break
|
|
@@ -163,21 +256,31 @@ async def main() -> None:
|
|
|
163
256
|
if not user_input:
|
|
164
257
|
continue
|
|
165
258
|
if user_input.lower() in ("exit", "quit"):
|
|
166
|
-
|
|
259
|
+
if pretty:
|
|
260
|
+
console.print("\\n [dim]Goodbye![/]\\n")
|
|
261
|
+
else:
|
|
262
|
+
print("\\nGoodbye!")
|
|
167
263
|
break
|
|
168
264
|
|
|
169
265
|
try:
|
|
266
|
+
if status:
|
|
267
|
+
status.stop()
|
|
268
|
+
status = None
|
|
170
269
|
result = await app.process_message(user_input, session_id)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
print(f"\\n[{result.source}] {result.message}\\n")
|
|
176
|
-
else:
|
|
177
|
-
print(f"\\nAssistant: {result.message}\\n")
|
|
270
|
+
if status:
|
|
271
|
+
status.stop()
|
|
272
|
+
status = None
|
|
273
|
+
render_response(result)
|
|
178
274
|
except Exception as e:
|
|
179
|
-
|
|
180
|
-
|
|
275
|
+
if status:
|
|
276
|
+
status.stop()
|
|
277
|
+
status = None
|
|
278
|
+
if pretty:
|
|
279
|
+
console.print(f" [trik.error]Error: {e}[/]")
|
|
280
|
+
console.print(" [dim]Please try again.[/]\\n")
|
|
281
|
+
else:
|
|
282
|
+
print(f"\\nError: {e}")
|
|
283
|
+
print("Please try again.\\n")
|
|
181
284
|
|
|
182
285
|
|
|
183
286
|
if __name__ == "__main__":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-python.js","sourceRoot":"","sources":["../../src/templates/agent-python.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,MAAM,SAAS,GAAiC;IAC9C,MAAM,EAAE;QACN,UAAU,EAAE,kBAAkB;QAC9B,SAAS,EAAE,YAAY;QACvB,UAAU,EAAE,kBAAkB;QAC9B,YAAY,EAAE,aAAa;QAC3B,MAAM,EAAE,gBAAgB;KACzB;IACD,SAAS,EAAE;QACT,UAAU,EAAE,qBAAqB;QACjC,SAAS,EAAE,eAAe;QAC1B,UAAU,EAAE,qBAAqB;QACjC,YAAY,EAAE,0BAA0B;QACxC,MAAM,EAAE,mBAAmB;KAC5B;IACD,MAAM,EAAE;QACN,UAAU,EAAE,wBAAwB;QACpC,SAAS,EAAE,wBAAwB;QACnC,UAAU,EAAE,wBAAwB;QACpC,YAAY,EAAE,kBAAkB;QAChC,MAAM,EAAE,gBAAgB;KACzB;CACF,CAAC;AAEF,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,SAAS,qBAAqB,CAAC,MAAyB;IACtD,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,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KAAK,CAAC,iBAAiB,CAAC,GAAG,kBAAkB,EAAE,CAAC;IAClD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-typescript.d.ts","sourceRoot":"","sources":["../../src/templates/agent-typescript.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC5C,QAAQ,CAAC,EAAE,KAAK,GAAG,cAAc,CAAC;CACnC;
|
|
1
|
+
{"version":3,"file":"agent-typescript.d.ts","sourceRoot":"","sources":["../../src/templates/agent-typescript.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC5C,QAAQ,CAAC,EAAE,KAAK,GAAG,cAAc,CAAC;CACnC;AA2fD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBhG"}
|
|
@@ -47,6 +47,11 @@ function generatePackageJson(config) {
|
|
|
47
47
|
'@langchain/langgraph': '^1.0.0',
|
|
48
48
|
'@trikhub/gateway': 'latest',
|
|
49
49
|
dotenv: '^16.4.0',
|
|
50
|
+
marked: '^15.0.0',
|
|
51
|
+
'marked-terminal': '^7.0.0',
|
|
52
|
+
chalk: '^5.3.0',
|
|
53
|
+
ora: '^8.0.1',
|
|
54
|
+
'cli-highlight': '^2.1.11',
|
|
50
55
|
};
|
|
51
56
|
if (hasTelegram) {
|
|
52
57
|
dependencies.grammy = '^1.0.0';
|
|
@@ -148,8 +153,61 @@ export async function initializeAgent() {
|
|
|
148
153
|
function generateCliTs() {
|
|
149
154
|
return `import 'dotenv/config';
|
|
150
155
|
import * as readline from 'readline';
|
|
156
|
+
import chalk from 'chalk';
|
|
157
|
+
import ora from 'ora';
|
|
158
|
+
import { Marked } from 'marked';
|
|
159
|
+
import TerminalRenderer from 'marked-terminal';
|
|
160
|
+
import { highlight } from 'cli-highlight';
|
|
151
161
|
import { initializeAgent } from './agent.js';
|
|
152
162
|
|
|
163
|
+
const pretty = !process.argv.includes('--no-pretty');
|
|
164
|
+
|
|
165
|
+
const marked = new Marked();
|
|
166
|
+
if (pretty) {
|
|
167
|
+
marked.use({
|
|
168
|
+
renderer: new TerminalRenderer({
|
|
169
|
+
code: (code: string) => {
|
|
170
|
+
try {
|
|
171
|
+
return '\\n' + highlight(code, { ignoreIllegals: true }) + '\\n';
|
|
172
|
+
} catch {
|
|
173
|
+
return '\\n' + chalk.gray(code) + '\\n';
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
heading: (text: string, level: number) => {
|
|
177
|
+
const prefix = level <= 2 ? chalk.bold.cyan : chalk.bold;
|
|
178
|
+
return '\\n' + prefix(text) + '\\n';
|
|
179
|
+
},
|
|
180
|
+
listitem: (text: string) => ' ' + chalk.dim('•') + ' ' + text + '\\n',
|
|
181
|
+
paragraph: (text: string) => text + '\\n',
|
|
182
|
+
strong: (text: string) => chalk.bold(text),
|
|
183
|
+
em: (text: string) => chalk.italic(text),
|
|
184
|
+
codespan: (text: string) => chalk.cyan(text),
|
|
185
|
+
link: (href: string, _title: string, text: string) => text + chalk.dim(' (' + href + ')'),
|
|
186
|
+
hr: () => chalk.dim('─'.repeat(Math.min(process.stdout.columns || 80, 60))) + '\\n',
|
|
187
|
+
} as any),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function render(text: string): string {
|
|
192
|
+
if (!pretty) return text;
|
|
193
|
+
return (marked.parse(text) as string).trimEnd();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function renderResponse(result: { source: string; message: string }): void {
|
|
197
|
+
if (result.source === 'system') {
|
|
198
|
+
console.log('\\n ' + chalk.dim.italic(result.message) + '\\n');
|
|
199
|
+
} else if (result.source !== 'main') {
|
|
200
|
+
console.log('\\n ' + chalk.bold.magenta(result.source) + '\\n');
|
|
201
|
+
const rendered = render(result.message);
|
|
202
|
+
const indented = rendered.split('\\n').map((l: string) => ' ' + l).join('\\n');
|
|
203
|
+
console.log(indented + '\\n');
|
|
204
|
+
} else {
|
|
205
|
+
const rendered = render(result.message);
|
|
206
|
+
const indented = rendered.split('\\n').map((l: string) => ' ' + l).join('\\n');
|
|
207
|
+
console.log('\\n' + indented + '\\n');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
153
211
|
const rl = readline.createInterface({
|
|
154
212
|
input: process.stdin,
|
|
155
213
|
output: process.stdout,
|
|
@@ -162,57 +220,86 @@ function prompt(question: string): Promise<string> {
|
|
|
162
220
|
}
|
|
163
221
|
|
|
164
222
|
async function main() {
|
|
165
|
-
|
|
223
|
+
const loadingSpinner = pretty ? ora('Loading agent...').start() : null;
|
|
224
|
+
if (!pretty) console.log('Loading agent...\\n');
|
|
166
225
|
|
|
167
226
|
const app = await initializeAgent();
|
|
168
227
|
|
|
169
|
-
|
|
228
|
+
if (loadingSpinner) loadingSpinner.stop();
|
|
229
|
+
|
|
230
|
+
let spinner: ReturnType<typeof ora> | null = null;
|
|
231
|
+
|
|
232
|
+
// Subscribe to gateway events
|
|
170
233
|
app.gateway.on('handoff:start', ({ trikName }: { trikName: string }) => {
|
|
171
|
-
|
|
234
|
+
if (pretty) {
|
|
235
|
+
spinner = ora({ text: chalk.dim(\`Connecting to \${trikName}...\`), indent: 2 }).start();
|
|
236
|
+
} else {
|
|
237
|
+
console.log(\`[\${trikName}] Connecting...\`);
|
|
238
|
+
}
|
|
172
239
|
});
|
|
173
240
|
app.gateway.on('handoff:container_start', ({ trikName }: { trikName: string }) => {
|
|
174
|
-
|
|
241
|
+
if (pretty && spinner) {
|
|
242
|
+
spinner.text = chalk.dim(\`Starting \${trikName} container...\`);
|
|
243
|
+
} else if (!pretty) {
|
|
244
|
+
console.log(\`[\${trikName}] Starting container...\`);
|
|
245
|
+
}
|
|
175
246
|
});
|
|
176
247
|
app.gateway.on('handoff:thinking', ({ trikName }: { trikName: string }) => {
|
|
177
|
-
|
|
248
|
+
if (pretty && spinner) {
|
|
249
|
+
spinner.text = chalk.dim(\`\${trikName} is thinking...\`);
|
|
250
|
+
} else if (!pretty) {
|
|
251
|
+
console.log(\`[\${trikName}] Thinking...\`);
|
|
252
|
+
}
|
|
178
253
|
});
|
|
179
254
|
app.gateway.on('handoff:error', ({ trikName, error }: { trikName: string; error: string }) => {
|
|
180
|
-
|
|
255
|
+
if (spinner) spinner.stop();
|
|
256
|
+
if (pretty) {
|
|
257
|
+
console.log(' ' + chalk.red(\`\\u2716 [\${trikName}] \${error}\`));
|
|
258
|
+
} else {
|
|
259
|
+
console.log(\`[\${trikName}] Error: \${error}\`);
|
|
260
|
+
}
|
|
181
261
|
});
|
|
182
262
|
app.gateway.on('handoff:transfer_back', ({ trikName, reason }: { trikName: string; reason: string }) => {
|
|
183
|
-
|
|
263
|
+
if (spinner) spinner.stop();
|
|
264
|
+
if (pretty) {
|
|
265
|
+
console.log(' ' + chalk.dim(\`\\u2190 \${trikName} transferred back (\${reason})\`));
|
|
266
|
+
} else {
|
|
267
|
+
console.log(\`[\${trikName}] Transferred back (\${reason})\`);
|
|
268
|
+
}
|
|
184
269
|
});
|
|
185
270
|
|
|
186
271
|
const loadedTriks = app.getLoadedTriks();
|
|
187
272
|
if (loadedTriks.length > 0) {
|
|
188
|
-
console.log(
|
|
273
|
+
console.log(pretty
|
|
274
|
+
? chalk.dim(' Loaded triks: ') + loadedTriks.map((t: string) => chalk.cyan(t)).join(chalk.dim(', '))
|
|
275
|
+
: \`Loaded triks: \${loadedTriks.join(', ')}\`
|
|
276
|
+
);
|
|
189
277
|
}
|
|
190
|
-
console.log(
|
|
278
|
+
console.log(pretty
|
|
279
|
+
? chalk.dim(' Type /back to return from a trik, exit to quit.\\n')
|
|
280
|
+
: 'Type "/back" to return from a trik handoff, "exit" to quit.\\n'
|
|
281
|
+
);
|
|
191
282
|
|
|
192
283
|
const sessionId = \`cli-\${Date.now()}\`;
|
|
193
284
|
|
|
194
285
|
while (true) {
|
|
195
|
-
const userInput = await prompt('
|
|
286
|
+
const userInput = await prompt(pretty ? chalk.bold.green('You: ') : 'You: ');
|
|
196
287
|
|
|
197
288
|
if (!userInput.trim()) continue;
|
|
198
289
|
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
|
199
|
-
console.log('\\nGoodbye!');
|
|
290
|
+
console.log(pretty ? '\\n ' + chalk.dim('Goodbye!') + '\\n' : '\\nGoodbye!');
|
|
200
291
|
break;
|
|
201
292
|
}
|
|
202
293
|
|
|
203
294
|
try {
|
|
295
|
+
if (spinner) spinner.stop();
|
|
204
296
|
const result = await app.processMessage(userInput, sessionId);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
console.log(\`\\n\\x1b[2m\${result.message}\\x1b[0m\\n\`);
|
|
208
|
-
} else if (result.source !== 'main') {
|
|
209
|
-
console.log(\`\\n[\${result.source}] \${result.message}\\n\`);
|
|
210
|
-
} else {
|
|
211
|
-
console.log(\`\\nAssistant: \${result.message}\\n\`);
|
|
212
|
-
}
|
|
297
|
+
if (spinner) spinner.stop();
|
|
298
|
+
renderResponse(result);
|
|
213
299
|
} catch (error) {
|
|
214
|
-
|
|
215
|
-
console.
|
|
300
|
+
if (spinner) spinner.stop();
|
|
301
|
+
console.error(pretty ? ' ' + chalk.red('Error: ' + error) : '\\nError: ' + error);
|
|
302
|
+
console.log(pretty ? ' ' + chalk.dim('Please try again.') + '\\n' : 'Please try again.\\n');
|
|
216
303
|
}
|
|
217
304
|
}
|
|
218
305
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-typescript.js","sourceRoot":"","sources":["../../src/templates/agent-typescript.ts"],"names":[],"mapp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,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trikhub/cli",
|
|
3
|
-
"version": "0.17.1-dev.
|
|
3
|
+
"version": "0.17.1-dev.3",
|
|
4
4
|
"description": "CLI for TrikHub - Teaching AI new triks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@inquirer/prompts": "^7.2.1",
|
|
30
|
-
"@trikhub/linter": "0.17.1-dev.
|
|
31
|
-
"@trikhub/manifest": "0.17.1-dev.
|
|
30
|
+
"@trikhub/linter": "0.17.1-dev.3",
|
|
31
|
+
"@trikhub/manifest": "0.17.1-dev.3",
|
|
32
32
|
"chalk": "^5.3.0",
|
|
33
33
|
"commander": "^12.1.0",
|
|
34
34
|
"ora": "^8.0.1",
|