Skip to content

Commit a6c556e

Browse files
Merge pull request #25 from IQAIcom/feat/cli-improvements
Feat/cli improvements
2 parents 323e0be + dd053b3 commit a6c556e

File tree

11 files changed

+603
-119
lines changed

11 files changed

+603
-119
lines changed

CLAUDE.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ adk-claw/
3535
│ ├── AGENTS.md # Agent configuration template
3636
│ ├── SOUL.md # Agent personality template
3737
│ ├── USER.md # User profile template
38-
│ ├── .gitignore
39-
│ └── memory/ # Memory file templates
38+
│ └── .gitignore
4039
├── dist/ # Compiled output (includes templates after build)
4140
└── .adk-claw/ # User's local config (created by init, gitignored)
4241
├── config.json # User configuration (API keys, etc.)
@@ -59,7 +58,7 @@ pnpm lint:fix # Fix linting issues
5958
3. Creates `.adk-claw/config.json` with all settings
6059
4. Copies templates from `templates/workspace/` to `.adk-claw/workspace/`:
6160
- AGENTS.md, SOUL.md, USER.md (with placeholder replacement)
62-
- memory/facts.md, context.md, preferences.md
61+
- Creates empty `memory/` and `skills/` directories (ADK MemoryService creates memory files automatically)
6362
5. Initializes git in workspace
6463
6. User runs `adk-claw start` to launch the agent
6564

@@ -108,7 +107,6 @@ This copies templates to `dist/templates/` so the built CLI can find them.
108107
## Known Issues / TODOs
109108

110109
- The `@iqai/adk` package may show warnings about missing CLI files (can be ignored)
111-
- Memory tools in `src/tools/memoryTools.ts` has uncommitted changes
112110

113111
## Tips for Future Sessions
114112

CODEBASE.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,17 @@ Telegram Flow:
145145
- **Exports**: `startTelegramBot()`
146146
- **Flow**:
147147
1. Creates agent with `createClawdAgent({ channel: "telegram" })`
148-
2. Wires SessionManager with memory service
149-
3. Creates sampling handler that:
148+
2. Creates sampling handler that:
150149
- Parses incoming MCP messages (`parseTelegramMessage()`)
151150
- Routes `/start`, `/new`, `/reset`, `/help` commands
152151
- Checks pairing for non-command messages
153152
- Forwards to `runner.ask()` for AI responses
154-
4. Initializes Telegram agent (MCP tools)
155-
5. Registers bot commands with Telegram API
156-
6. Initializes scheduler
153+
3. Initializes Telegram agent (MCP tools)
154+
4. Registers bot commands with Telegram API
155+
5. Initializes scheduler
157156
- **Message format**: Key-value format from MCP (user_id, chat_id, content fields)
158157
- **Bot commands**: `/start`, `/new` (save & reset), `/reset` (clear), `/help`
159158

160-
### `src/services/SessionManager.ts` (Session State)
161-
- **Purpose**: Per-chat session tracking with memory persistence
162-
- **Exports**: `sessionManager` (singleton instance)
163-
- **Class**: `SessionManager`
164-
- `setDeps(memoryService, sessionService, adkSession)` — late-bound dependencies
165-
- `getOrCreate(chatId, userId, username?)` → Session
166-
- `addMessage(chatId, role, content)`
167-
- `saveAndReset(chatId)` → summary string (saves to memory via ADK)
168-
- `reset(chatId)` — clears without saving
169-
- `getHistory(chatId)` / `getRecentHistory(chatId, count?)`
170-
171159
### `src/services/SchedulerService.ts` (Cron Jobs)
172160
- **Purpose**: Manages scheduled/recurring tasks via `@iqai/adk` `AgentScheduler`
173161
- **Exports**:
@@ -179,7 +167,7 @@ Telegram Flow:
179167
- **Key**: Jobs are configured in `config.json` cron section, results broadcast to all paired Telegram users
180168

181169
### `src/services/index.ts` (Services Barrel)
182-
- **Re-exports**: `initScheduler`, `stopScheduler`, `sessionManager`, `startTelegramBot`
170+
- **Re-exports**: `initScheduler`, `stopScheduler`, `startTelegramBot`
183171

184172
---
185173

@@ -361,7 +349,6 @@ src/services/TelegramService.ts
361349
├── lib/logger.ts, lib/pairing.ts
362350
├── tools/scheduleTools.ts (setSchedulerDeps)
363351
├── services/SchedulerService.ts
364-
└── services/SessionManager.ts
365352
366353
src/agents/agent.ts
367354
├── config/index.ts (getConfig)

src/agents/config/agent.config.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as path from "node:path";
88
import matter from "gray-matter";
99
import { configExists, getConfig } from "../../config/index.js";
1010
import { HEARTBEAT_OK, SILENT_REPLY_TOKEN } from "../../lib/tokens.js";
11-
import { buildSkillsPrompt } from "../../skills/SkillService.js";
1211
import type {
1312
AgentsConfig,
1413
RuntimeInfo,
@@ -396,22 +395,6 @@ export function buildSystemPromptFromParams(
396395
return buildSystemPrompt(params.workspaceConfig, params.runtime);
397396
}
398397

399-
/**
400-
* Build the full system prompt with skills included (async version)
401-
*/
402-
export async function buildSystemPromptWithSkills(
403-
config: WorkspaceConfig,
404-
): Promise<string> {
405-
const basePrompt = buildSystemPrompt(config);
406-
const skillsPrompt = await buildSkillsPrompt(config.workspacePath);
407-
408-
if (skillsPrompt) {
409-
return `${basePrompt}\n\n${skillsPrompt}`;
410-
}
411-
412-
return basePrompt;
413-
}
414-
415398
/**
416399
* Check if workspace exists and has required files
417400
*/

src/cli/chat.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* CLI command for interactive terminal chat with the agent
3+
*/
4+
5+
import { existsSync } from "node:fs";
6+
import { join } from "node:path";
7+
import * as p from "@clack/prompts";
8+
import pc from "picocolors";
9+
10+
const CONFIG_PATH = join(process.cwd(), ".adk-claw", "config.json");
11+
12+
export async function chat() {
13+
if (!existsSync(CONFIG_PATH)) {
14+
p.log.error("ADK Claw is not initialized. Run 'adk-claw init' first.");
15+
process.exit(1);
16+
}
17+
18+
const s = p.spinner();
19+
s.start("Initializing agent...");
20+
21+
const { createClawdAgent } = await import("../agents/agent.js");
22+
const { getConfig } = await import("../config/index.js");
23+
24+
let agentResult: Awaited<ReturnType<typeof createClawdAgent>>;
25+
let agentName: string;
26+
27+
try {
28+
agentResult = await createClawdAgent({ channel: "cli" });
29+
agentName = getConfig().agentName;
30+
s.stop(`${pc.cyan(agentName)} is ready`);
31+
} catch (err) {
32+
s.stop("Failed to initialize agent");
33+
p.log.error(err instanceof Error ? err.message : "Unknown error");
34+
process.exit(1);
35+
}
36+
37+
p.intro(
38+
`${pc.bold(pc.magenta(agentName))} ${pc.dim("type /help for commands, /exit to quit")}`,
39+
);
40+
41+
while (true) {
42+
const input = await p.text({
43+
message: pc.cyan("You:"),
44+
placeholder: "Say something...",
45+
});
46+
47+
if (p.isCancel(input)) {
48+
break;
49+
}
50+
51+
const trimmed = (input as string).trim();
52+
53+
if (!trimmed) {
54+
continue;
55+
}
56+
57+
if (trimmed === "/exit" || trimmed === "/quit") {
58+
break;
59+
}
60+
61+
if (trimmed === "/help") {
62+
console.log(`
63+
${pc.bold("Commands:")}
64+
/help Show this help
65+
/new Start a fresh session
66+
/exit Quit the chat
67+
`);
68+
continue;
69+
}
70+
71+
if (trimmed === "/new") {
72+
const newS = p.spinner();
73+
newS.start("Starting new session...");
74+
try {
75+
agentResult = await createClawdAgent({ channel: "cli" });
76+
newS.stop("New session started");
77+
} catch (err) {
78+
newS.stop("Failed to start new session");
79+
p.log.error(err instanceof Error ? err.message : "Unknown error");
80+
}
81+
continue;
82+
}
83+
84+
const thinkS = p.spinner();
85+
thinkS.start("Thinking...");
86+
87+
try {
88+
const response = await agentResult.runner.ask(trimmed);
89+
thinkS.stop("");
90+
console.log(`\n ${pc.bold(pc.magenta(agentName))}: ${response}\n`);
91+
} catch (err) {
92+
thinkS.stop("Error");
93+
p.log.error(err instanceof Error ? err.message : "Unknown error");
94+
}
95+
}
96+
97+
p.outro("Goodbye!");
98+
}

0 commit comments

Comments
 (0)