These three constants were carried over from v1's polling + IPC architecture and have zero callers in the v2 runtime: - POLL_INTERVAL (2000ms) — v1 message loop; replaced by event-driven delivery + delivery.ts's ACTIVE_POLL_MS (hardcoded 1000ms) - SCHEDULER_POLL_INTERVAL (60000ms) — v1 task scheduler; replaced by host-sweep.ts's SWEEP_INTERVAL_MS (hardcoded 60_000) - IPC_POLL_INTERVAL (1000ms) — v1 file-based IPC; meaningless in v2's session-DB architecture Grep confirms no imports in src/, container/, or tests. Docs/SPEC.md updated to match. Ref: docs/v1-vs-v2/ACTION-ITEMS.md item 15. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
2.8 KiB
TypeScript
60 lines
2.8 KiB
TypeScript
import os from 'os';
|
|
import path from 'path';
|
|
|
|
import { readEnvFile } from './env.js';
|
|
import { isValidTimezone } from './timezone.js';
|
|
|
|
// Read config values from .env (falls back to process.env).
|
|
const envConfig = readEnvFile(['ASSISTANT_NAME', 'ASSISTANT_HAS_OWN_NUMBER', 'ONECLI_URL', 'TZ']);
|
|
|
|
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';
|
|
|
|
// 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 SENDER_ALLOWLIST_PATH = path.join(HOME_DIR, '.config', 'nanoclaw', 'sender-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 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 ONECLI_URL = process.env.ONECLI_URL || envConfig.ONECLI_URL;
|
|
export const MAX_MESSAGES_PER_PROMPT = Math.max(1, parseInt(process.env.MAX_MESSAGES_PER_PROMPT || '10', 10) || 10);
|
|
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 function buildTriggerPattern(trigger: string): RegExp {
|
|
return new RegExp(`^${escapeRegex(trigger.trim())}\\b`, 'i');
|
|
}
|
|
|
|
export const DEFAULT_TRIGGER = `@${ASSISTANT_NAME}`;
|
|
|
|
export function getTriggerPattern(trigger?: string): RegExp {
|
|
const normalizedTrigger = trigger?.trim();
|
|
return buildTriggerPattern(normalizedTrigger || DEFAULT_TRIGGER);
|
|
}
|
|
|
|
export const TRIGGER_PATTERN = buildTriggerPattern(DEFAULT_TRIGGER);
|
|
|
|
// Timezone for scheduled tasks, message formatting, etc.
|
|
// Validates each candidate is a real IANA identifier before accepting.
|
|
function resolveConfigTimezone(): string {
|
|
const candidates = [process.env.TZ, envConfig.TZ, Intl.DateTimeFormat().resolvedOptions().timeZone];
|
|
for (const tz of candidates) {
|
|
if (tz && isValidTimezone(tz)) return tz;
|
|
}
|
|
return 'UTC';
|
|
}
|
|
export const TIMEZONE = resolveConfigTimezone();
|