@tinykode/tinykode
v1.0.0
Published
A lightweight code assistant library with CLI support
Downloads
6
Readme
TinyKode
A lightweight code assistant library with CLI support.
Installation
As a global CLI tool
npm install -g tinykodeThen use the CLI:
tinykodeAs a local dependency
npm install tinykodeUsage
Programmatic Usage
import { TinyKode } from "tinykode";
const tinykode = new TinyKode({
workspaceRoot: process.cwd()
});
const messages = await tinykode.processQuery({
query: "Create a file named hello.txt with the content 'Hello, World!'",
});CLI Usage
After installing globally, run:
tinykodeThis will start an interactive session where you can type your queries.
Available commands in CLI:
- Type any query and press Enter
- Type
exitorquitto close the CLI - Use Ctrl+C for immediate exit
Programmatic CLI Usage
You can also create and customize the CLI programmatically:
import { createCLI, setupEventHandlers } from "tinykode";
const cli = createCLI({
prompt: "my-cli> ",
welcomeMessage: "Welcome to my custom CLI!",
exitCommands: ['exit', 'quit', 'bye'],
tinykodeConfig: {
workspaceRoot: process.cwd()
},
onExit: () => {
console.log('Custom goodbye message!');
process.exit(0);
}
});
setupEventHandlers(cli);
await cli.start();Configuration
TinyKode CLI can be configured using a JSON file located at ~/.tinykode/tinykode.json.
Example Configuration
{
"workspaceRoot": "/path/to/your/projects",
"customOption": "value"
}The configuration object is passed directly to the TinyKode constructor, so any valid TinyKode configuration options can be specified.
TinyKode
Main class for interacting with the code assistant.
Constructor
new TinyKode(config, tools, messages)config: Configuration object (optional, uses default config if not provided)tools: Tools map (optional, uses default tools if not provided)messages: Initial messages array (optional, defaults to empty array)
Methods
processQuery(options)
Process a user query and return the conversation messages.
const messages = await tinykode.processQuery({
query: "Your query here",
onUpdate: (chunk) => console.log(chunk),
onToolCalls: (toolCalls) => console.log('Tool calls:', toolCalls),
onToolResults: (toolResults) => console.log('Tool results:', toolResults),
onToolConfirm: async ({ tool, params }) => {
// Return true to confirm tool execution, false to deny
return true;
}
});Options:
query(string, required): The user query to processonUpdate(function, optional): Callback for streaming text updatesonToolCalls(function, optional): Callback when tools are calledonToolResults(function, optional): Callback when tool results are availableonToolConfirm(function, optional): Callback to confirm tool execution
CLI API
createCLI(options)
Create a customizable CLI instance.
const cli = createCLI({
prompt: "> ", // CLI prompt (default: ">")
welcomeMessage: null, // Welcome message (default: none)
tinykodeConfig: {}, // TinyKode configuration
exitCommands: ['exit', 'quit'], // Commands that exit the CLI
onExit: () => process.exit(0) // Custom exit handler
});Returns an object with:
start(): Start the CLI loopprocessQuery(query): Process a single querycleanup(): Clean up resourcestinykode: Access to the underlying TinyKode instance
setupEventHandlers(cli)
Set up standard event handlers for the CLI (SIGINT, SIGTERM, uncaught exceptions).
input(question)
Utility function for prompting user input in CLI applications.
License
ISC
