refactor: remove GMAIL_CHANNEL_ENABLED env flag from add-gmail skill

Channel vs tool-only is now a code-level decision at skill apply time.
If the user chose channel mode, GmailChannel is wired unconditionally.
If tool-only, no channel code is added. No runtime flag needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Fritzzzz
2026-02-24 23:46:24 +02:00
parent 41e2424856
commit 6dd90829e1
7 changed files with 21 additions and 148 deletions

View File

@@ -1,74 +0,0 @@
import os from 'os';
import path from 'path';
import { readEnvFile } from './env.js';
// Read config values from .env (falls back to process.env).
// Secrets are NOT read here — they stay on disk and are loaded only
// where needed (container-runner.ts) to avoid leaking to child processes.
const envConfig = readEnvFile([
'ASSISTANT_NAME',
'ASSISTANT_HAS_OWN_NUMBER',
'GMAIL_CHANNEL_ENABLED',
]);
export const ASSISTANT_NAME =
process.env.ASSISTANT_NAME || envConfig.ASSISTANT_NAME || 'Andy';
export const ASSISTANT_HAS_OWN_NUMBER =
(process.env.ASSISTANT_HAS_OWN_NUMBER || envConfig.ASSISTANT_HAS_OWN_NUMBER) === 'true';
export const POLL_INTERVAL = 2000;
export const SCHEDULER_POLL_INTERVAL = 60000;
// Absolute paths needed for container mounts
const PROJECT_ROOT = process.cwd();
const HOME_DIR = process.env.HOME || os.homedir();
// Mount security: allowlist stored OUTSIDE project root, never mounted into containers
export const MOUNT_ALLOWLIST_PATH = path.join(
HOME_DIR,
'.config',
'nanoclaw',
'mount-allowlist.json',
);
export const STORE_DIR = path.resolve(PROJECT_ROOT, 'store');
export const GROUPS_DIR = path.resolve(PROJECT_ROOT, 'groups');
export const DATA_DIR = path.resolve(PROJECT_ROOT, 'data');
export const MAIN_GROUP_FOLDER = 'main';
export const CONTAINER_IMAGE =
process.env.CONTAINER_IMAGE || 'nanoclaw-agent:latest';
export const CONTAINER_TIMEOUT = parseInt(
process.env.CONTAINER_TIMEOUT || '1800000',
10,
);
export const CONTAINER_MAX_OUTPUT_SIZE = parseInt(
process.env.CONTAINER_MAX_OUTPUT_SIZE || '10485760',
10,
); // 10MB default
export const IPC_POLL_INTERVAL = 1000;
export const IDLE_TIMEOUT = parseInt(
process.env.IDLE_TIMEOUT || '1800000',
10,
); // 30min default — how long to keep container alive after last result
export const MAX_CONCURRENT_CONTAINERS = Math.max(
1,
parseInt(process.env.MAX_CONCURRENT_CONTAINERS || '5', 10) || 5,
);
function escapeRegex(str: string): string {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
export const TRIGGER_PATTERN = new RegExp(
`^@${escapeRegex(ASSISTANT_NAME)}\\b`,
'i',
);
// Timezone for scheduled tasks (cron expressions, etc.)
// Uses system timezone by default
export const TIMEZONE =
process.env.TZ || Intl.DateTimeFormat().resolvedOptions().timeZone;
// Gmail configuration
export const GMAIL_CHANNEL_ENABLED =
(process.env.GMAIL_CHANNEL_ENABLED || envConfig.GMAIL_CHANNEL_ENABLED) === 'true';

View File

@@ -1,20 +0,0 @@
# Intent: src/config.ts modifications
## What changed
Added configuration exports for Gmail channel support.
## Key sections
- **readEnvFile call**: Must include `GMAIL_CHANNEL_ENABLED` in the keys array. NanoClaw does NOT load `.env` into `process.env` — all `.env` values must be explicitly requested via `readEnvFile()`.
- **GMAIL_CHANNEL_ENABLED**: Boolean feature flag — when `true`, the Gmail channel is connected and polls for inbound emails. When `false` (default), Gmail is available as a tool only (agent can read/send emails when asked from other channels).
## Invariants
- All existing config exports remain unchanged
- New Gmail keys are added to the `readEnvFile` call alongside existing keys
- New exports are appended at the end of the file
- No existing behavior is modified — Gmail config is additive and minimal
- Both `process.env` and `envConfig` are checked (same pattern as `ASSISTANT_NAME`)
## Must-keep
- All existing exports (`ASSISTANT_NAME`, `POLL_INTERVAL`, `TRIGGER_PATTERN`, etc.)
- The `readEnvFile` pattern — ALL config read from `.env` must go through this function
- The `escapeRegex` helper and `TRIGGER_PATTERN` construction

View File

@@ -3,7 +3,6 @@ import path from 'path';
import {
ASSISTANT_NAME,
GMAIL_CHANNEL_ENABLED,
IDLE_TIMEOUT,
MAIN_GROUP_FOLDER,
POLL_INTERVAL,
@@ -451,11 +450,9 @@ async function main(): Promise<void> {
channels.push(whatsapp);
await whatsapp.connect();
if (GMAIL_CHANNEL_ENABLED) {
const gmail = new GmailChannel(channelOpts);
channels.push(gmail);
await gmail.connect();
}
const gmail = new GmailChannel(channelOpts);
channels.push(gmail);
await gmail.connect();
// Start subsystems (independently of connection handler)
startSchedulerLoop({

View File

@@ -2,24 +2,21 @@
## What changed
Added Gmail as a channel option alongside WhatsApp (and any other channels).
Added Gmail as a channel.
## Key sections
### Imports (top of file)
- Added: `GmailChannel` from `./channels/gmail.js`
- Added: `GMAIL_CHANNEL_ENABLED` from `./config.js`
### main()
- Added: conditional Gmail channel creation after WhatsApp:
- Added Gmail channel creation:
```
if (GMAIL_CHANNEL_ENABLED) {
const gmail = new GmailChannel(channelOpts);
channels.push(gmail);
await gmail.connect();
}
const gmail = new GmailChannel(channelOpts);
channels.push(gmail);
await gmail.connect();
```
- Gmail uses the same `channelOpts` callbacks as other channels
- Incoming emails are delivered to the main group (agent decides how to respond, user can configure)
@@ -31,7 +28,7 @@ Added Gmail as a channel option alongside WhatsApp (and any other channels).
- State management (loadState/saveState) is unchanged
- Recovery logic is unchanged
- Container runtime check is unchanged
- WhatsApp and any other channel creation is untouched
- Any other channel creation is untouched
- Shutdown iterates `channels` array (Gmail is included automatically)
## Must-keep