Files
letta-code-sdk/examples/file-organizer/cli.ts
Cameron Pfiffer 3b4811f035 feat: add basic utility examples with agent persistence
Three practical examples showing core SDK capabilities:

- **bug-fixer**: Find and fix bugs, remembers codebase patterns
- **release-notes**: Generate release notes from git commits
- **file-organizer**: Organize directories, learns preferences

Each example uses agent persistence (getOrCreateAgent pattern) so the
agent remembers context across sessions - the key Letta differentiator.

🤖 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>
2026-01-27 15:51:27 -08:00

121 lines
3.2 KiB
TypeScript
Executable File

#!/usr/bin/env bun
/**
* File Organizer CLI
*
* Organize files in directories with AI assistance.
*
* Usage:
* bun cli.ts ~/Downloads # Organize Downloads folder
* bun cli.ts . --strategy=type # Organize by file type
* bun cli.ts . --dry-run # Preview without changes
* bun cli.ts # Interactive mode
* bun cli.ts --status # Show agent status
* bun cli.ts --reset # Reset agent
*/
import { parseArgs } from 'node:util';
import {
loadState,
saveState,
getOrCreateAgent,
organizeDirectory,
interactiveMode,
showStatus,
reset,
} from './organizer.js';
async function main() {
const { values, positionals } = parseArgs({
args: process.argv.slice(2),
options: {
strategy: { type: 'string', short: 's' },
'dry-run': { type: 'boolean', default: false },
status: { type: 'boolean', default: false },
reset: { type: 'boolean', default: false },
help: { type: 'boolean', short: 'h', default: false },
},
allowPositionals: true,
});
if (values.help) {
printHelp();
return;
}
if (values.reset) {
await reset();
return;
}
const state = await loadState();
if (values.status) {
await showStatus(state);
return;
}
// Get or create the agent
const agent = await getOrCreateAgent(state);
// Save agent ID if new
if (!state.agentId && agent.agentId) {
state.agentId = agent.agentId;
await saveState(state);
console.log(`\x1b[90m[Agent: ${agent.agentId}]\x1b[0m`);
console.log(`\x1b[90m[→ https://app.letta.com/agents/${agent.agentId}]\x1b[0m\n`);
}
if (positionals.length > 0) {
// Organize the specified directory
const targetDir = positionals[0];
await organizeDirectory(agent, state, targetDir, values.strategy, values['dry-run']);
} else {
// Interactive mode
await interactiveMode(agent, state);
}
agent.close();
}
function printHelp() {
console.log(`
📁 File Organizer
Organize files in directories with AI assistance. Remembers your preferences.
USAGE:
bun cli.ts [directory] Organize a directory
bun cli.ts Interactive mode
bun cli.ts --status Show agent status
bun cli.ts --reset Reset agent (forget preferences)
bun cli.ts -h, --help Show this help
OPTIONS:
-s, --strategy TYPE Organization strategy (type, date, project)
--dry-run Preview changes without moving files
EXAMPLES:
bun cli.ts ~/Downloads # Organize Downloads
bun cli.ts ~/Documents --strategy=date # Organize by date
bun cli.ts ./messy-folder --dry-run # Preview only
bun cli.ts . # Organize current directory
STRATEGIES:
type Group by file extension (images/, documents/, code/)
date Group by date (2024/, 2025/ or by month)
project Group by project (inferred from content)
(none) AI decides best approach
SAFETY:
- Always previews changes before executing
- Never deletes files (only moves)
- Creates directories as needed
PERSISTENCE:
The agent learns your organizational preferences over time.
`);
}
main().catch(console.error);