clementine-agent 1.0.42 → 1.0.43

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.
@@ -1058,7 +1058,13 @@ When ${owner} gives you an API key, access token, or similar credential in chat,
1058
1058
 
1059
1059
  Use \`env_list\` to show what's configured (values masked) and \`env_unset\` to remove one. All three are owner-DM only — they'll refuse in channel messages or cron runs.
1060
1060
 
1061
- Don't tell ${owner} "add this to your .env" — just call env_set and report what you saved. For integrations connected at claude.ai (Google Drive, Gmail, Slack, Notion, Linear, etc.), the \`mcp__claude_ai_*\` tools appear automatically via Claude Desktop — never claim one is "not available" without trying the tool call first.
1061
+ ### Tool schema self-extension
1062
+
1063
+ If a tool call fails with **"not in my function schema" / "tool not allowed" / "unknown tool"** BUT you can see it in the SDK init inventory (e.g. \`mcp__claude_ai_Google_Drive__search_files\`), call \`allow_tool(name)\` to add it to your whitelist. Takes effect on your next query — no restart, no owner intervention. Then try the original task again.
1064
+
1065
+ This is the correct response to "tool not in schema" errors. **Do not dead-end** and tell ${owner} to edit a config file. Use \`list_allowed_tools\` to see what you've already added, \`disallow_tool\` to remove one.
1066
+
1067
+ Don't tell ${owner} "add this to your .env" — just call env_set and report what you saved. For integrations connected at claude.ai (Google Drive, Gmail, Slack, Notion, Linear, etc.), the \`mcp__claude_ai_*\` tools appear in your SDK init inventory; if your first call is refused, call \`allow_tool\` with the exact tool name and retry.
1062
1068
 
1063
1069
  ## Context Window Management
1064
1070
 
@@ -1366,6 +1372,11 @@ You have a cost budget per message — not a hard turn limit. Work until the tas
1366
1372
  mcpTool('env_set'),
1367
1373
  mcpTool('env_list'),
1368
1374
  mcpTool('env_unset'),
1375
+ // Self-service tool whitelist — Clementine can add tools she discovers
1376
+ // in the SDK init inventory but that aren't in her baseline allowedTools
1377
+ mcpTool('allow_tool'),
1378
+ mcpTool('list_allowed_tools'),
1379
+ mcpTool('disallow_tool'),
1369
1380
  mcpTool('self_restart'),
1370
1381
  mcpTool('cron_list'),
1371
1382
  mcpTool('add_cron_job'),
@@ -1423,6 +1434,41 @@ You have a cost budget per message — not a hard turn limit. Work until the tas
1423
1434
  }
1424
1435
  }
1425
1436
  catch { /* non-fatal — dynamic tools are supplementary */ }
1437
+ // Claude Desktop connector tools (mcp__claude_ai_*). These reach the SDK
1438
+ // subprocess via Claude Code's runtime but are NOT added to allowedTools
1439
+ // automatically — which caused the model to see them in the init
1440
+ // inventory but get refused when it tried to call one ("not in my
1441
+ // function schema"). Add every tool from every auto-registered
1442
+ // integration (populated from the SDK init message on prior queries) so
1443
+ // the whitelist matches reality.
1444
+ try {
1445
+ const integrations = _mcpBridge?.getClaudeIntegrations() ?? [];
1446
+ for (const ig of integrations) {
1447
+ for (const tool of ig.tools) {
1448
+ const fullName = `mcp__claude_ai_${ig.name}__${tool}`;
1449
+ if (!allowedTools.includes(fullName))
1450
+ allowedTools.push(fullName);
1451
+ }
1452
+ }
1453
+ }
1454
+ catch { /* non-fatal */ }
1455
+ // Self-service extension — Clementine can add tools to her own whitelist
1456
+ // at runtime via the `allow_tool` MCP tool, writing to allowed-tools-
1457
+ // extra.json. This eliminates the "tool not in schema → dead end → tell
1458
+ // owner to edit config" failure pattern. See admin-tools.ts:allow_tool.
1459
+ try {
1460
+ const extraPath = path.join(BASE_DIR, 'allowed-tools-extra.json');
1461
+ if (fs.existsSync(extraPath)) {
1462
+ const extras = JSON.parse(fs.readFileSync(extraPath, 'utf-8'));
1463
+ if (Array.isArray(extras)) {
1464
+ for (const t of extras) {
1465
+ if (typeof t === 'string' && !allowedTools.includes(t))
1466
+ allowedTools.push(t);
1467
+ }
1468
+ }
1469
+ }
1470
+ }
1471
+ catch { /* non-fatal */ }
1426
1472
  // Agent tool whitelist: filter down to only allowed tools
1427
1473
  if (profile?.team?.allowedTools?.length) {
1428
1474
  const whitelist = new Set(profile.team.allowedTools.flatMap(t => [t, mcpTool(t)]));
@@ -170,6 +170,82 @@ export function registerAdminTools(server) {
170
170
  logger.info({ key: normalizedKey }, 'env_unset');
171
171
  return textResult(`Removed ${normalizedKey} from ~/.clementine/.env`);
172
172
  });
173
+ // ── Self-service tool whitelist ────────────────────────────────────────
174
+ const ALLOWED_TOOLS_EXTRA = path.join(BASE_DIR, 'allowed-tools-extra.json');
175
+ function readExtraAllowedTools() {
176
+ if (!existsSync(ALLOWED_TOOLS_EXTRA))
177
+ return [];
178
+ try {
179
+ const arr = JSON.parse(readFileSync(ALLOWED_TOOLS_EXTRA, 'utf-8'));
180
+ return Array.isArray(arr) ? arr.filter((x) => typeof x === 'string') : [];
181
+ }
182
+ catch {
183
+ return [];
184
+ }
185
+ }
186
+ function writeExtraAllowedTools(tools) {
187
+ if (!existsSync(BASE_DIR))
188
+ mkdirSync(BASE_DIR, { recursive: true });
189
+ const unique = [...new Set(tools)].sort();
190
+ writeFileSync(ALLOWED_TOOLS_EXTRA, JSON.stringify(unique, null, 2));
191
+ }
192
+ server.tool('allow_tool', 'Add a tool name to your self-managed allowedTools list. Use when you see a tool in the SDK inventory but get "not in function schema" when you try to call it. Writes to ~/.clementine/allowed-tools-extra.json; takes effect on your NEXT query. Owner-DM only. Common case: Claude Desktop connector tools like mcp__claude_ai_Google_Drive__search_files that appear in the init inventory but aren\'t in your baseline whitelist.', {
193
+ name: z.string().describe('Exact tool name (e.g. "mcp__claude_ai_Google_Drive__search_files")'),
194
+ reason: z.string().optional().describe('Brief note: why you need this tool. For audit trail.'),
195
+ }, async ({ name, reason }) => {
196
+ const gate = requireOwnerDm();
197
+ if (!gate.ok)
198
+ return textResult(gate.message);
199
+ const trimmed = name.trim();
200
+ if (!trimmed)
201
+ return textResult('Refused: empty tool name.');
202
+ // Loose format check — MCP tool names, built-in tool names, or namespaced patterns.
203
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed.replace(/__[A-Za-z0-9_-]+/g, ''))) {
204
+ return textResult(`Refused: "${trimmed}" doesn't look like a valid tool name. Use a literal name like "mcp__claude_ai_Google_Drive__search_files" or a built-in like "WebFetch".`);
205
+ }
206
+ const current = readExtraAllowedTools();
207
+ if (current.includes(trimmed)) {
208
+ return textResult(`${trimmed} is already in your extra-allowed list. If it's still being refused, it may be disallowed by a higher-priority block (heartbeat/cron disallowed tools, profile tier).`);
209
+ }
210
+ current.push(trimmed);
211
+ try {
212
+ writeExtraAllowedTools(current);
213
+ }
214
+ catch (err) {
215
+ return textResult(`Failed to persist: ${String(err).slice(0, 200)}`);
216
+ }
217
+ logger.info({ name: trimmed, reason, totalExtras: current.length }, 'allow_tool');
218
+ return textResult(`Added ${trimmed} to ~/.clementine/allowed-tools-extra.json (${current.length} total extras). Active on your next query — no daemon restart needed.${reason ? ` Reason: ${reason}` : ''}`);
219
+ });
220
+ server.tool('list_allowed_tools', 'Show the current self-managed allowedTools extras (tools you added via allow_tool on top of the built-in whitelist). Owner-DM only.', {}, async () => {
221
+ const gate = requireOwnerDm();
222
+ if (!gate.ok)
223
+ return textResult(gate.message);
224
+ const current = readExtraAllowedTools();
225
+ if (current.length === 0)
226
+ return textResult('No extra tools registered. The built-in whitelist is the only source; add entries via `allow_tool` when you encounter "not in function schema" errors.');
227
+ return textResult(`Extra allowed tools (${current.length}):\n${current.map(t => `- ${t}`).join('\n')}\n\nStored in ~/.clementine/allowed-tools-extra.json; merged into allowedTools on every query.`);
228
+ });
229
+ server.tool('disallow_tool', 'Remove a tool from your self-managed allowedTools extras. Takes effect on next query. Owner-DM only.', {
230
+ name: z.string().describe('Exact tool name to remove'),
231
+ }, async ({ name }) => {
232
+ const gate = requireOwnerDm();
233
+ if (!gate.ok)
234
+ return textResult(gate.message);
235
+ const trimmed = name.trim();
236
+ const current = readExtraAllowedTools();
237
+ if (!current.includes(trimmed))
238
+ return textResult(`${trimmed} isn't in the extras list. Nothing to remove.`);
239
+ const next = current.filter(t => t !== trimmed);
240
+ try {
241
+ writeExtraAllowedTools(next);
242
+ }
243
+ catch (err) {
244
+ return textResult(`Failed to persist: ${String(err).slice(0, 200)}`);
245
+ }
246
+ logger.info({ name: trimmed, totalExtras: next.length }, 'disallow_tool');
247
+ return textResult(`Removed ${trimmed} from extras (${next.length} remaining).`);
248
+ });
173
249
  // ── Workspace Tools ─────────────────────────────────────────────────────
174
250
  /** Common developer directories to auto-scan (relative to home). */
175
251
  const DEFAULT_WORKSPACE_CANDIDATES = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clementine-agent",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "Clementine — Personal AI Assistant (TypeScript)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",