Centralize all path management via src/config/paths.ts
- Add getPaths() with workspace, scripts, ppt skin/template paths - Export getWorkspacePath(args?) helper — removes duplicate local functions and stale process.cwd()/workspace fallbacks from sqlite, pdf, excel, image, pubmed, email, audio-transcribe (7 files) - weather.ts: replace __dirname-relative scripts path with getPaths().scripts - Move ppt/ to .smallclaw/skills/presenter/ppt/; update server-v2.ts, pptx.ts, pptx_gen.py (argparse --skin-dir/--template-dir) - Fix PPT skin thumbnail serving: res.sendFile → fs.createReadStream (bypasses send module dotfiles restriction for .smallclaw/ paths) - Fix workspace default: .smallclaw/workspace (was project root workspace/) - Fix subagent paths to use SMALLCLAW_DATA_DIR env var - Fix Monaco marked module load failure: restore define.amd on DOMContentLoaded after deferred UMD libs (tone, magenta) have loaded - Add AudioContext resume on first user click (Chrome autoplay policy) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
5608b83850
commit
2d3e33b6b3
15 files changed
+96
-85
No files matched your search
@@ -107,7 +107,7 @@
|
||||
"ppt": {
|
||||
"engine": "python",
|
||||
"template": "business",
|
||||
"skin": "cream",
|
||||
"skin": "coral",
|
||||
"unsplash_key": "env:UNSPLASH_ACCESS_KEY",
|
||||
"pexels_key": "env:PEXELS_API_KEY",
|
||||
"pixabay_key": ""
|
||||
@@ -117,6 +117,10 @@
|
||||
"interval_minutes": 30,
|
||||
"workspace_file": "HEARTBEAT.md"
|
||||
},
|
||||
"workspace": {
|
||||
"path": "/home/kim/homeclaw/.smallclaw/workspace",
|
||||
"codeDir": "code"
|
||||
},
|
||||
"agents": [
|
||||
{
|
||||
"id": "pubmed_researcher",
|
||||
|
||||
+19
-7
@@ -39,6 +39,7 @@ import json
|
||||
import os
|
||||
import re
|
||||
import math
|
||||
import argparse
|
||||
|
||||
# Force UTF-8 output on Windows
|
||||
if sys.platform == 'win32':
|
||||
@@ -56,8 +57,8 @@ from pptx.enum.text import PP_ALIGN, MSO_ANCHOR, MSO_AUTO_SIZE
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
PROJECT_ROOT = os.path.join(SCRIPT_DIR, '..')
|
||||
SKIN_DIR = os.path.join(PROJECT_ROOT, 'ppt', 'skin')
|
||||
TEMPLATE_DIR = os.path.join(PROJECT_ROOT, 'ppt', 'template')
|
||||
SKIN_DIR = os.path.join(PROJECT_ROOT, '.smallclaw', 'skills', 'presenter', 'ppt', 'skin')
|
||||
TEMPLATE_DIR = os.path.join(PROJECT_ROOT, '.smallclaw', 'skills', 'presenter', 'ppt', 'template')
|
||||
|
||||
SKIN_EXTENSIONS = {'.png', '.jpg', '.jpeg'}
|
||||
|
||||
@@ -1354,12 +1355,23 @@ def generate(spec: dict, workspace_path: str) -> dict:
|
||||
# ─── CLI Entry Point ───────────────────────────────────────────────────────────
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(json.dumps({"success": False, "error": "Usage: python pptx_gen.py <spec_json_path> [workspace_path]"}))
|
||||
sys.exit(1)
|
||||
parser = argparse.ArgumentParser(description='Generate PPTX from spec JSON')
|
||||
parser.add_argument('spec_path', help='Path to spec JSON file')
|
||||
parser.add_argument('workspace_path', nargs='?', default=os.getcwd(), help='Workspace directory')
|
||||
parser.add_argument('--skin-dir', default=None, help='Override skin directory path')
|
||||
parser.add_argument('--template-dir', default=None, help='Override template directory path')
|
||||
args = parser.parse_args()
|
||||
|
||||
spec_path = sys.argv[1]
|
||||
workspace_path = sys.argv[2] if len(sys.argv) > 2 else os.getcwd()
|
||||
spec_path = args.spec_path
|
||||
workspace_path = args.workspace_path
|
||||
|
||||
# Override paths if provided by caller (keeps paths.ts as single source of truth)
|
||||
global SKIN_DIR, TEMPLATE_DIR, SKIN_INDEX
|
||||
if args.skin_dir:
|
||||
SKIN_DIR = args.skin_dir
|
||||
SKIN_INDEX = _build_skin_index()
|
||||
if args.template_dir:
|
||||
TEMPLATE_DIR = args.template_dir
|
||||
|
||||
try:
|
||||
with open(spec_path, "r", encoding="utf-8") as f:
|
||||
|
||||
@@ -63,10 +63,10 @@ const CONFIG_DIR =
|
||||
|
||||
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
||||
|
||||
// Workspace: env var → config-dir-relative default (cross-platform safe)
|
||||
// Workspace: env var → inside config dir (avoids polluting project root)
|
||||
const WORKSPACE_DIR =
|
||||
process.env.SMALLCLAW_WORKSPACE_DIR ??
|
||||
path.join(CONFIG_DIR, '..', 'workspace');
|
||||
path.join(CONFIG_DIR, 'workspace');
|
||||
|
||||
export const DEFAULT_CONFIG: SmallClawConfig = {
|
||||
version: '1.0.1',
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import path from 'path';
|
||||
import { getConfig } from './config.js';
|
||||
|
||||
export function getPaths() {
|
||||
const configDir = getConfig().getConfigDir(); // .smallclaw/
|
||||
const projectRoot = path.join(configDir, '..');
|
||||
|
||||
return {
|
||||
configDir,
|
||||
projectRoot,
|
||||
workspace: getConfig().getWorkspacePath(),
|
||||
scripts: path.join(projectRoot, 'scripts'),
|
||||
templates: path.join(configDir, 'templates'),
|
||||
databases: path.join(configDir, 'databases'),
|
||||
agents: path.join(configDir, 'agents'),
|
||||
subagents: path.join(configDir, 'subagents'),
|
||||
skills: path.join(configDir, 'skills'),
|
||||
pptSkinDir: path.join(configDir, 'skills', 'presenter', 'ppt', 'skin'),
|
||||
pptTemplateDir: path.join(configDir, 'skills', 'presenter', 'ppt', 'template'),
|
||||
pptxScript: path.join(projectRoot, 'scripts', 'pptx_gen.py'),
|
||||
pptxPreviewScript: path.join(projectRoot, 'scripts', 'pptx_preview.py'),
|
||||
};
|
||||
}
|
||||
|
||||
// Session-aware workspace resolver: args._workspacePath (per-user) → config default
|
||||
export function getWorkspacePath(args?: any): string {
|
||||
return args?._workspacePath || args?._workspace || getConfig().getWorkspacePath();
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
getUserWorkspace,
|
||||
ensureUserWorkspace,
|
||||
} from '../config/config';
|
||||
import { getPaths } from '../config/paths';
|
||||
import { getVault, SecretValue } from '../security/vault';
|
||||
import { getOllamaClient } from '../agents/ollama-client';
|
||||
import { spawnAgent } from '../agents/spawner';
|
||||
@@ -8611,6 +8612,8 @@ app.use((req, _res, next) => {
|
||||
|
||||
// Allow auth endpoints, login page, and static assets without authentication
|
||||
if (req.path.startsWith('/api/auth/') || req.path === '/login.html') return next();
|
||||
// PPT skin thumbnails are UI decoration — allow without auth
|
||||
if (req.path.startsWith('/api/ppt/skins/') || req.path === '/api/ppt/skins') return next();
|
||||
|
||||
const token = extractAuthToken(req);
|
||||
const session = token ? activeSessions.get(token) : undefined;
|
||||
@@ -12207,8 +12210,7 @@ app.post('/api/auth/openai/disconnect', (_req, res) => {
|
||||
clearTokens(configDir);
|
||||
res.json({ success: true });
|
||||
});
|
||||
const PPT_SKIN_DIR = path.join(process.cwd(), 'ppt', 'skin');
|
||||
const PPT_TEMPLATE_DIR = path.join(process.cwd(), 'ppt', 'template');
|
||||
const { pptSkinDir: PPT_SKIN_DIR, pptTemplateDir: PPT_TEMPLATE_DIR } = getPaths();
|
||||
|
||||
app.get('/api/ppt/templates', (_req, res) => {
|
||||
try {
|
||||
@@ -12272,14 +12274,10 @@ app.get('/api/ppt/skins/{*skinPath}', (req, res) => {
|
||||
if (!skinFile) { res.status(404).json({ error: 'Skin not found' }); return; }
|
||||
const ext = path.extname(skinFile).toLowerCase();
|
||||
const contentType = ext === '.jpg' || ext === '.jpeg' ? 'image/jpeg' : 'image/png';
|
||||
if (isThumb) {
|
||||
res.setHeader('Content-Type', contentType);
|
||||
res.setHeader('Cache-Control', 'public, max-age=3600');
|
||||
res.sendFile(skinFile);
|
||||
} else {
|
||||
res.setHeader('Content-Type', contentType);
|
||||
res.sendFile(skinFile);
|
||||
}
|
||||
res.setHeader('Content-Type', contentType);
|
||||
if (isThumb) res.setHeader('Cache-Control', 'public, max-age=3600');
|
||||
// Use createReadStream to bypass send module's dotfile restriction on .smallclaw/
|
||||
fs.createReadStream(skinFile).pipe(res);
|
||||
});
|
||||
// GET /api/settings/openweather — return masked OpenWeather key status
|
||||
// POST /api/settings/openweather — save OpenWeather API key (vault-encrypted)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
import { ToolResult } from '../types.js';
|
||||
import { transcribeAudio } from './stt.js';
|
||||
|
||||
@@ -26,7 +27,7 @@ export const audioTranscribeTool = {
|
||||
const filePath = String(args?.path || '').trim();
|
||||
if (!filePath) return { success: false, error: 'path is required' };
|
||||
|
||||
const workspacePath = args?._workspacePath || args?._workspace || getConfig().getConfig()?.workspace?.path || process.cwd();
|
||||
const workspacePath = getWorkspacePath(args);
|
||||
const resolved = path.isAbsolute(filePath) ? filePath : path.resolve(workspacePath, filePath);
|
||||
|
||||
if (!fs.existsSync(resolved)) {
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { ToolResult } from '../types.js';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
|
||||
// ── Config ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -333,7 +334,7 @@ export const emailReadTool = {
|
||||
resolvedWorkspacePath = path.resolve(String(injectedWorkspace));
|
||||
} else {
|
||||
const cfg = getConfig().getConfig();
|
||||
resolvedWorkspacePath = path.resolve(cfg?.workspace?.path || path.join(process.cwd(), 'workspace'));
|
||||
resolvedWorkspacePath = path.resolve(getWorkspacePath(args));
|
||||
}
|
||||
const relDir = path.join('attachments', `uid-${uid}`);
|
||||
const saveDir = path.join(resolvedWorkspacePath, relDir);
|
||||
|
||||
+1
-11
@@ -2,21 +2,11 @@ import { execFile } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { ToolResult } from '../types.js';
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
function getWorkspacePath(args?: any): string {
|
||||
const sessionPath = args?._workspacePath || args?._workspace;
|
||||
if (sessionPath) return sessionPath;
|
||||
try {
|
||||
return getConfig().getConfig()?.workspace?.path || path.join(process.cwd(), 'workspace');
|
||||
} catch {
|
||||
return path.join(process.cwd(), 'workspace');
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Python scripts ────────────────────────────────────────────────────────────
|
||||
|
||||
const READ_SCRIPT = `
|
||||
|
||||
+1
-11
@@ -1,18 +1,8 @@
|
||||
import { spawn } from 'child_process';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { ToolResult } from '../types.js';
|
||||
|
||||
function getWorkspacePath(args?: any): string {
|
||||
const sessionPath = args?._workspacePath || args?._workspace;
|
||||
if (sessionPath) return sessionPath;
|
||||
try {
|
||||
return getConfig().getConfig()?.workspace?.path || path.join(process.cwd(), 'workspace');
|
||||
} catch {
|
||||
return path.join(process.cwd(), 'workspace');
|
||||
}
|
||||
}
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
|
||||
function isPathInsideDir(base: string, target: string): boolean {
|
||||
const resolvedBase = path.resolve(base);
|
||||
|
||||
+1
-11
@@ -2,21 +2,11 @@ import { execFile } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { ToolResult } from '../types.js';
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
function getWorkspacePath(args?: any): string {
|
||||
const sessionPath = args?._workspacePath || args?._workspace;
|
||||
if (sessionPath) return sessionPath;
|
||||
try {
|
||||
return getConfig().getConfig()?.workspace?.path || path.join(process.cwd(), 'workspace');
|
||||
} catch {
|
||||
return path.join(process.cwd(), 'workspace');
|
||||
}
|
||||
}
|
||||
|
||||
function isPathInsideDir(base: string, target: string): boolean {
|
||||
const resolvedBase = path.resolve(base);
|
||||
const resolvedTarget = path.resolve(target);
|
||||
|
||||
+6
-15
@@ -2,26 +2,17 @@ import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { execFile } from 'child_process';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { getPaths } from '../config/paths.js';
|
||||
import { ToolResult } from '../types.js';
|
||||
|
||||
type SSESender = (type: string, data: any) => void;
|
||||
|
||||
// ─── Engine paths ──────────────────────────────────────────────────────────────
|
||||
const PYTHON_SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'pptx_gen.py');
|
||||
|
||||
// ─── Paths ──────────────────────────────────────────────────────────────────────
|
||||
const SKIN_DIR = path.join(__dirname, '..', '..', '.smallclaw', 'skills', 'presenter', 'ppt', 'skin');
|
||||
const TEMPLATE_DIR = path.join(__dirname, '..', '..', '.smallclaw', 'skills', 'presenter', 'ppt', 'template');
|
||||
const LEGACY_SKIN_DIR = path.join(__dirname, '..', '..', 'assets', 'pptx_template');
|
||||
|
||||
// Resolve skin directory: prefer ppt/skin, fall back to legacy assets/pptx_template
|
||||
const ACTIVE_SKIN_DIR = fs.existsSync(SKIN_DIR) ? SKIN_DIR
|
||||
: fs.existsSync(LEGACY_SKIN_DIR) ? LEGACY_SKIN_DIR
|
||||
: SKIN_DIR;
|
||||
// ─── Paths (from central paths.ts) ──────────────────────────────────────────────
|
||||
const { pptxScript: PYTHON_SCRIPT, pptSkinDir: SKIN_DIR, pptTemplateDir: TEMPLATE_DIR } = getPaths();
|
||||
|
||||
const SKIN_EXTENSIONS = ['.png', '.jpg', '.jpeg'];
|
||||
const SKIN_NAMES = fs.existsSync(ACTIVE_SKIN_DIR)
|
||||
? fs.readdirSync(ACTIVE_SKIN_DIR)
|
||||
const SKIN_NAMES = fs.existsSync(SKIN_DIR)
|
||||
? fs.readdirSync(SKIN_DIR)
|
||||
.filter(f => SKIN_EXTENSIONS.includes(path.extname(f).toLowerCase()))
|
||||
.map(f => path.basename(f, path.extname(f)))
|
||||
: [];
|
||||
@@ -180,7 +171,7 @@ async function generateWithPython(spec: PresentationSpec, workspacePath: string)
|
||||
|
||||
const result = await new Promise<{ success: boolean; path?: string; folder?: string; filename?: string; slides?: number; warnings?: string[]; stdout?: string; error?: string; download_url?: string; preview_url?: string }>((resolve, reject) => {
|
||||
const pythonCmd = process.platform === 'win32' ? 'python' : 'python3';
|
||||
execFile(pythonCmd, [PYTHON_SCRIPT, tmpSpecPath, workspacePath], {
|
||||
execFile(pythonCmd, [PYTHON_SCRIPT, tmpSpecPath, workspacePath, '--skin-dir', SKIN_DIR, '--template-dir', TEMPLATE_DIR], {
|
||||
timeout: 60_000,
|
||||
maxBuffer: 1024 * 1024 * 10,
|
||||
windowsHide: true,
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import { execFile } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import { ToolResult } from '../types.js';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
@@ -349,7 +350,7 @@ export const pubmedFulltextTool = {
|
||||
|
||||
// Download PDF
|
||||
const config = getConfig().getConfig();
|
||||
const workspaceDir = args?._workspacePath || args?._workspace || config.workspace?.path || path.join(process.cwd(), 'workspace');
|
||||
const workspaceDir = getWorkspacePath(args);
|
||||
const pdfDir = path.join(workspaceDir, 'pubmed');
|
||||
fs.mkdirSync(pdfDir, { recursive: true });
|
||||
|
||||
@@ -466,7 +467,7 @@ export const pubmedFulltextTool = {
|
||||
|
||||
// Save to workspace (prefer per-user path injected by v2 executeTool)
|
||||
const config = getConfig().getConfig();
|
||||
const workspaceDir = args?._workspacePath || args?._workspace || config.workspace?.path || path.join(process.cwd(), 'workspace');
|
||||
const workspaceDir = getWorkspacePath(args);
|
||||
const savePath = args?.save_path
|
||||
? path.join(workspaceDir, args.save_path)
|
||||
: path.join(workspaceDir, 'pubmed', `${pmcid}.txt`);
|
||||
|
||||
+1
-9
@@ -1,16 +1,8 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { getWorkspacePath } from '../config/paths.js';
|
||||
import { ToolResult } from '../types.js';
|
||||
|
||||
function getWorkspacePath(args?: any): string {
|
||||
try {
|
||||
return args?._workspacePath || args?._workspace || getConfig().getConfig()?.workspace?.path || path.join(process.cwd(), 'workspace');
|
||||
} catch {
|
||||
return path.join(process.cwd(), 'workspace');
|
||||
}
|
||||
}
|
||||
|
||||
function isPathInsideDir(base: string, target: string): boolean {
|
||||
const resolvedBase = path.resolve(base);
|
||||
const resolvedTarget = path.resolve(target);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ToolResult } from '../types.js';
|
||||
import { getConfig } from '../config/config.js';
|
||||
import { getVault } from '../security/vault.js';
|
||||
import { getPaths } from '../config/paths.js';
|
||||
import { spawn } from 'child_process';
|
||||
import path from 'path';
|
||||
import https from 'https';
|
||||
@@ -1010,7 +1011,7 @@ function getCdsApiKey(): string | undefined {
|
||||
|
||||
function runPythonCds(input: object, timeoutMs = 300_000): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const scriptPath = path.resolve(__dirname, '../../scripts/era5_cds_fetch.py');
|
||||
const scriptPath = path.join(getPaths().scripts, 'era5_cds_fetch.py');
|
||||
const child = spawn('python3', [scriptPath], { stdio: ['pipe', 'pipe', 'pipe'] });
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
+15
-3
@@ -27,10 +27,22 @@
|
||||
<script src="https://cdn.jsdelivr.net/combine/npm/tone@14,npm/@magenta/music@1.23.1/es6/core.js,npm/html-midi-player@1.6.0" defer></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs/loader.js"></script>
|
||||
<script>
|
||||
// Prevent deferred UMD libs (tone, @magenta/music, html-midi-player) from
|
||||
// using Monaco's AMD define() — multiple anonymous define() calls in one
|
||||
// combined script cause "Can only have one anonymous define call per script".
|
||||
// Hide AMD from deferred UMD libs (tone, @magenta/music, html-midi-player) so they
|
||||
// don't call Monaco's anonymous define() — that would cause "Can only have one
|
||||
// anonymous define call per script". Restore define.amd on DOMContentLoaded (after
|
||||
// deferred scripts have run as globals) so Monaco's lazy modules like
|
||||
// vs/base/common/marked/marked can register themselves via AMD as expected.
|
||||
var _savedDefineAmd = window.define ? window.define.amd : undefined;
|
||||
if (window.define) window.define.amd = false;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
if (window.define && _savedDefineAmd !== undefined) window.define.amd = _savedDefineAmd;
|
||||
}, { once: true });
|
||||
|
||||
// Resume Tone.js AudioContext on first user gesture (Chrome autoplay policy)
|
||||
document.addEventListener('click', function() {
|
||||
if (window.Tone && Tone.context && Tone.context.state !== 'running') Tone.context.resume();
|
||||
}, { once: true });
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in new issue
Block a user