mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-03-25 09:25:47 +00:00
Prepare release
This commit is contained in:
parent
66cc0e76ea
commit
731b89b779
11 changed files with 375 additions and 14 deletions
46
.eslintrc.json
Normal file
46
.eslintrc.json
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2022,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es2022": true
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"dist/",
|
||||
"node_modules/",
|
||||
"coverage/",
|
||||
"*.js",
|
||||
"scripts/prepare-release.js"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
"@typescript-eslint/no-unused-vars": ["error", {
|
||||
"argsIgnorePattern": "^_",
|
||||
"varsIgnorePattern": "^_"
|
||||
}],
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"no-console": "error",
|
||||
"prefer-const": "error",
|
||||
"no-var": "error",
|
||||
"eqeqeq": ["error", "always"],
|
||||
"curly": ["error", "all"],
|
||||
"brace-style": ["error", "1tbs"],
|
||||
"quotes": ["error", "double", { "avoidEscape": true }],
|
||||
"semi": ["error", "always"],
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"no-trailing-spaces": "error",
|
||||
"indent": ["error", 2, { "SwitchCase": 1 }],
|
||||
"max-len": ["warn", { "code": 120, "ignoreUrls": true, "ignoreStrings": true }]
|
||||
}
|
||||
}
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -114,3 +114,6 @@ Thumbs.db
|
|||
|
||||
# npm package files
|
||||
*.tgz
|
||||
|
||||
# Auto-generated version file
|
||||
peekaboo-cli/Sources/peekaboo/Version.swift
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ Cast powerful spells upon Peekaboo using mystical environment variables:
|
|||
{
|
||||
"PEEKABOO_AI_PROVIDERS": "ollama/llava:latest,openai/gpt-4o",
|
||||
"PEEKABOO_LOG_LEVEL": "debug",
|
||||
"PEEKABOO_LOG_FILE": "/tmp/peekaboo-mcp.log",
|
||||
"PEEKABOO_LOG_FILE": "~/Library/Logs/peekaboo-mcp-debug.log",
|
||||
"PEEKABOO_DEFAULT_SAVE_PATH": "~/Pictures/PeekabooCaptures",
|
||||
"PEEKABOO_CONSOLE_LOGGING": "true",
|
||||
"PEEKABOO_CLI_PATH": "/opt/custom/peekaboo"
|
||||
|
|
@ -89,7 +89,7 @@ Cast powerful spells upon Peekaboo using mystical environment variables:
|
|||
|----------|-------------|---------|
|
||||
| `PEEKABOO_AI_PROVIDERS` | Comma-separated list of `provider_name/default_model_for_provider` pairs (e.g., `\"openai/gpt-4o,ollama/llava:7b\"`). If a model is not specified for a provider (e.g., `\"openai\"`), a default model for that provider will be used. This setting determines which AI backends are available for the `analyze` tool and the `image` tool (when a `question` is provided). **Recommended for Ollama:** `\"ollama/llava:latest\"` for the best vision model. | `\"\"` (none) |
|
||||
| `PEEKABOO_LOG_LEVEL` | Logging level (trace, debug, info, warn, error, fatal). | `info` |
|
||||
| `PEEKABOO_LOG_FILE` | Path to the server's log file. | `path.join(os.tmpdir(), 'peekaboo-mcp.log')` |
|
||||
| `PEEKABOO_LOG_FILE` | Path to the server's log file. If the specified directory is not writable, falls back to the system temp directory. | `~/Library/Logs/peekaboo-mcp.log` |
|
||||
| `PEEKABOO_DEFAULT_SAVE_PATH` | Default base absolute path for saving images captured by the `image` tool. If the `path` argument is provided to the `image` tool, it takes precedence. If neither `image.path` nor this environment variable is set, the Swift CLI saves to its default temporary directory. | (none, Swift CLI uses temp paths) |
|
||||
| `PEEKABOO_OLLAMA_BASE_URL` | Base URL for the Ollama API server. Only needed if Ollama is running on a non-default address. | `http://localhost:11434` |
|
||||
| `PEEKABOO_CONSOLE_LOGGING` | Boolean (`"true"`/`"false"`) for development console logs. | `"false"` |
|
||||
|
|
|
|||
111
docs/mcp-best-practices.md
Normal file
111
docs/mcp-best-practices.md
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
# MCP Best Practices - May 26, 2025
|
||||
|
||||
**I. General Tool Configuration & Behavior**
|
||||
|
||||
1. **Sensible Defaults:** All environment variables must have sensible defaults for easy out-of-the-box usage.
|
||||
2. **Dynamic Versioning:** The tool's version is emitted in its description. This version must be read dynamically (e.g., from `package.json`) and not hardcoded.
|
||||
3. **Tool & Parameter Descriptions:**
|
||||
* **Tool Titles:** Use descriptive, human-friendly titles for tools.
|
||||
* **Parameter Descriptions:** All parameters must offer a clear description.
|
||||
* **Optional/Required Parameters:** Parameters must be explicitly noted as "optional" or "required."
|
||||
* **Default Values:** If a parameter is optional, its default value must be explained.
|
||||
* (These details should be verifiable by hovering over the tool in clients like Cursor or using the MCP inspector.)
|
||||
4. **Parameter Parsing:** Parameter parsing should be lenient (e.g., accept `path` if `project_path` is formally defined). Generally, advertise stricter schemas but be more lenient in execution to accommodate variations from agents.
|
||||
5. **Runtime Error Handling:** In case of an error, emit a helpful message to the caller with information to potentially recover.
|
||||
6. **Configuration Error Handling:** Misconfigurations (e.g., wrongly set environment variables) must not crash the tool. Instead, provide a useful explanation when the tool is run, enabling the user to self-correct their setup.
|
||||
7. **Output Control:** There should be no output to `stdio` during normal tool operation, as this can disrupt MCP clients. File-based logging is the designated method for operational output.
|
||||
8. **`info` Command:**
|
||||
* At least one tool must offer an `info` sub command (find the most appropriate tool and add there)
|
||||
* This command shall list:
|
||||
* The version of the MCP tool.
|
||||
* The status of any required native dependencies (if applicable), including tests for their presence and functionality.
|
||||
* Any detected configuration issues or missing environment variables (e.g., problems with the logger path).
|
||||
|
||||
**II. Logging (Pino)**
|
||||
|
||||
1. **Default File Logger:** Pino is used for logging with a default file logger in the system's log directory (e.g., `~/Library/Logs/`). The log file path is configurable via the `[ProjectName]_LOG_FILE` environment variable.
|
||||
2. **Log Path Resilience:**
|
||||
* Pino logic must automatically create missing parent directories for the specified log file path.
|
||||
* If pino cannot write to the `[ProjectName]_LOG_FILE` path, it must fall back to logging to the default temporary directory path.
|
||||
3. **Configurable Log Level:** The log level is set using the `[ProjectName]_LOG_LEVEL` environment variable (accepts upper, lower, or mixed case values).
|
||||
4. **Optional Console Logging:** An environment variable, `[ProjectName]_CONSOLE_LOGGING=true`, enables logging to the console in addition to the pino file logger.
|
||||
5. **Logger Flush:** The logger must be flushed before the process exits to ensure all log messages are written.
|
||||
|
||||
**III. Code, Dependencies & Build**
|
||||
|
||||
1. **Dependency Management:** All dependencies should be kept at their latest stable versions. (The release script will warn for outdated dependencies).
|
||||
2. **Static Analysis:** There must be no linter (e.g., ESLint) or TypeScript errors.
|
||||
3. **File Size:** No single file should exceed 500 lines of code (LOC); aim for below 300 LOC.
|
||||
4. **Execution with Compiled Code:** The startup logic and all tool operations must always use the compiled JavaScript output (e.g., from the `dist` folder).
|
||||
5. **Shebangs:** Compiled JavaScript files intended for direct execution must have the correct shebang (e.g., `#!/usr/bin/env node`).
|
||||
6. **NPM Package Contents:** The published npm package must contain only the absolute minimum files: the `dist/` folder, any potential native components, the `README.md`, and a `LICENSE` file.
|
||||
|
||||
**IV. Testing**
|
||||
|
||||
1. **Test Framework:** Tests must use `vitest`.
|
||||
2. **TypeScript Test Suite:** A comprehensive test suite for the TypeScript layer is required.
|
||||
3. **End-to-End (E2E) Tests:** E2E tests that validate the complete setup are necessary. (These might be run as release preparation if CI execution is challenging due to permissions like macOS access).
|
||||
4. **NPM Scripts:**
|
||||
* `npm run prepare-release` executes a comprehensive test suite (detailed in Section VI).
|
||||
* `npm run inspector` executes `npx @modelcontextprotocol/inspector node path/to/server/index.js`.
|
||||
|
||||
**V. Native Binary Rules (If Applicable)**
|
||||
|
||||
1. **macOS Compatibility:** The binary must be universal (Apple Silicon & Intel) and support the current macOS version and the previous major version (n-1, e.g., macOS >= 14 if current is 15).
|
||||
2. **Build Optimization:** Compiler and linker flags must be set to achieve a minimal binary file size.
|
||||
3. **Native Test Suite:** A comprehensive test suite using Swift's native testing tools (e.g., `swift-test` or XCTest) is required.
|
||||
4. **Custom Path Configuration:** An environment variable must allow setting a custom absolute path to run the native binary.
|
||||
5. **Error Communication:** If the tool uses a native library, `errno` (or an equivalent mechanism) must be used to pass error and execution issues to the TypeScript logger and back to the tool.
|
||||
6. **Version Synchronization:** The native CLI and the MCP tool (TypeScript package) must have the same version number. This version must be injected during the build process, not hardcoded, while still allowing easy development (e.g., in Xcode using current source, with the script replacing the version on build).
|
||||
7. **Native Code Quality:**
|
||||
* The CLI must have no linter issues (e.g., SwiftLint for Swift).
|
||||
* A formatter must be applied (e.g., SwiftFormat for Swift).
|
||||
* The CLI must show no analyzer issues.
|
||||
8. **JSON Communication:** The native binary part of the tool must have a mode to communicate in JSON back to the TypeScript server for easier parsing. JSON responses should include debug logs if requested (e.g., by passing a log level).
|
||||
9. **CLI Help Command:** The binary must respond to `--help` with a helpful command explaining its use and all options.
|
||||
10. **Argument Parsing Framework:** The binary must use a robust argument parser framework (e.g., `swift-argument-parser` for Swift).
|
||||
11. **Single File Distribution:** For native CLIs, consider options for distributing as a single, statically linked binary if feasible and beneficial for simpler installation by end-users who might use the CLI directly.
|
||||
|
||||
**VI. Rules to Check Before a Release (`scripts/prepare-release.js`)**
|
||||
|
||||
* There is a `scripts/prepare-release.js` that runs an extensive test suite. The script runs these checks sequentially and stops at the first failure.
|
||||
|
||||
**Git & Version Control:**
|
||||
1. Check current branch (warns if not on main or designated release branch).
|
||||
2. Check for uncommitted changes.
|
||||
3. Check if synced with origin/main (or designated release branch).
|
||||
4. Version availability check (ensures version isn't already published).
|
||||
5. Version consistency between `package.json` and `package-lock.json`.
|
||||
6. **Changelog Check:** Check for a changelog entry corresponding to the current version.
|
||||
|
||||
**Code Quality & Security:**
|
||||
1. Dependency installation check.
|
||||
2. Outdated dependencies check (warning only).
|
||||
3. Security audit (fails on critical/high vulnerabilities).
|
||||
4. TypeScript compilation.
|
||||
5. TypeScript tests.
|
||||
6. TypeScript declaration files generation.
|
||||
7. Delete any build folders and reset package caches before building.
|
||||
8. *If native binary exists:* Swift analyze.
|
||||
9. *If native binary exists:* Swift formatting (SwiftFormat).
|
||||
10. *If native binary exists:* Swift linting (SwiftLint).
|
||||
11. *If native binary exists:* Swift tests.
|
||||
12. No build warnings.
|
||||
|
||||
**Binary & CLI Validation (If Applicable):**
|
||||
13. *If native binary exists:* Swift CLI command tests (help, version, and other key functionalities).
|
||||
14. *If native binary exists:* Swift CLI error handling tests (invalid commands, missing args, invalid window index, etc.).
|
||||
15. *If native binary exists:* Swift CLI JSON output validation.
|
||||
16. *If native binary exists:* Binary exists and is executable.
|
||||
17. *If native binary exists:* Binary contains both architectures (arm64 + x86_64, verifiable via `lipo -info`).
|
||||
18. *If native binary exists:* Binary responds correctly to `--help`.
|
||||
|
||||
**Package Validation:**
|
||||
19. Required fields in `package.json`.
|
||||
20. Package size check (warns if >2MB, configurable threshold).
|
||||
21. Executable permission check in `postinstall` (if a CLI is present).
|
||||
22. Critical files included (e.g., `dist/index.js`, native binary name, `README.md`, `LICENSE`).
|
||||
23. MCP server smoke test (JSON-RPC request/response).
|
||||
24. Full integration tests.
|
||||
|
||||
* Releases are first done with a `beta` tag to the npm registry so they can be tested via the `npx [packageName]@beta install` method.
|
||||
|
|
@ -9,7 +9,9 @@
|
|||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
"peekaboo"
|
||||
"peekaboo",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
|
|
@ -26,6 +28,8 @@
|
|||
"test:swift": "cd peekaboo-cli && swift test",
|
||||
"test:integration": "npm run build && npm run test:swift && vitest run",
|
||||
"test:all": "npm run test:integration",
|
||||
"lint": "eslint 'src/**/*.ts' 'tests/**/*.ts'",
|
||||
"lint:fix": "eslint 'src/**/*.ts' 'tests/**/*.ts' --fix",
|
||||
"lint:swift": "cd peekaboo-cli && swiftlint",
|
||||
"format:swift": "cd peekaboo-cli && swiftformat .",
|
||||
"prepare-release": "node ./scripts/prepare-release.js",
|
||||
|
|
@ -50,6 +54,9 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.15.21",
|
||||
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
||||
"@typescript-eslint/parser": "^8.19.1",
|
||||
"eslint": "^8.57.1",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"typescript": "^5.3.0",
|
||||
"vitest": "^3.1.4",
|
||||
|
|
|
|||
8
peekaboo-cli/Sources/peekaboo/Version.swift.development
Normal file
8
peekaboo-cli/Sources/peekaboo/Version.swift.development
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// This file is used for development when building directly in Xcode.
|
||||
// The actual Version.swift is auto-generated by the build script.
|
||||
// To use this file for development, copy it to Version.swift:
|
||||
// cp Version.swift.development Version.swift
|
||||
|
||||
struct Version {
|
||||
static let current = "dev"
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ struct PeekabooCommand: ParsableCommand {
|
|||
static let configuration = CommandConfiguration(
|
||||
commandName: "peekaboo",
|
||||
abstract: "A macOS utility for screen capture, application listing, and window management",
|
||||
version: "1.0.0-beta.9",
|
||||
version: Version.current,
|
||||
subcommands: [ImageCommand.self, ListCommand.self],
|
||||
defaultSubcommand: ImageCommand.self
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,19 @@ echo "🧹 Cleaning previous build artifacts..."
|
|||
rm -rf "$SWIFT_PROJECT_PATH/.build"
|
||||
rm -f "$ARM64_BINARY_TEMP" "$X86_64_BINARY_TEMP" "$FINAL_BINARY_PATH.tmp"
|
||||
|
||||
echo "📦 Reading version from package.json..."
|
||||
VERSION=$(node -p "require('$PROJECT_ROOT/package.json').version")
|
||||
echo "Version: $VERSION"
|
||||
|
||||
echo "💉 Injecting version into Swift code..."
|
||||
VERSION_SWIFT_PATH="$SWIFT_PROJECT_PATH/Sources/peekaboo/Version.swift"
|
||||
cat > "$VERSION_SWIFT_PATH" << EOF
|
||||
// This file is auto-generated by the build script. Do not edit manually.
|
||||
struct Version {
|
||||
static let current = "$VERSION"
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "🏗️ Building for arm64 (Apple Silicon)..."
|
||||
(cd "$SWIFT_PROJECT_PATH" && swift build --arch arm64 -c release $SWIFT_OPTIMIZATION_FLAGS)
|
||||
cp "$SWIFT_PROJECT_PATH/.build/arm64-apple-macosx/release/$FINAL_BINARY_NAME" "$ARM64_BINARY_TEMP"
|
||||
|
|
|
|||
|
|
@ -161,6 +161,13 @@ function checkTypeScript() {
|
|||
log('Cleaning build directory...', colors.cyan);
|
||||
rmSync(join(projectRoot, 'dist'), { recursive: true, force: true });
|
||||
|
||||
// Run ESLint
|
||||
if (!execWithOutput('npm run lint', 'ESLint')) {
|
||||
logError('ESLint found violations');
|
||||
return false;
|
||||
}
|
||||
logSuccess('ESLint passed');
|
||||
|
||||
// Type check
|
||||
if (!execWithOutput('npm run build', 'TypeScript compilation')) {
|
||||
logError('TypeScript compilation failed');
|
||||
|
|
|
|||
26
src/index.ts
26
src/index.ts
|
|
@ -37,10 +37,30 @@ initializeSwiftCliPath(packageRootDir);
|
|||
|
||||
// No longer need to track initial status display
|
||||
|
||||
// Initialize logger
|
||||
// Initialize logger with fallback support
|
||||
const baseLogLevel = (process.env.PEEKABOO_LOG_LEVEL || "info").toLowerCase();
|
||||
const logFile =
|
||||
process.env.PEEKABOO_LOG_FILE || path.join(os.tmpdir(), "peekaboo-mcp.log");
|
||||
const defaultLogPath = path.join(os.homedir(), "Library/Logs/peekaboo-mcp.log");
|
||||
const fallbackLogPath = path.join(os.tmpdir(), "peekaboo-mcp.log");
|
||||
let logFile = process.env.PEEKABOO_LOG_FILE || defaultLogPath;
|
||||
|
||||
// Test if the log directory is writable
|
||||
const logDir = path.dirname(logFile);
|
||||
try {
|
||||
// Try to create the directory if it doesn't exist
|
||||
await fs.mkdir(logDir, { recursive: true });
|
||||
// Test write access by creating a temp file
|
||||
const testFile = path.join(logDir, `.peekaboo-test-${Date.now()}`);
|
||||
await fs.writeFile(testFile, "test");
|
||||
await fs.unlink(testFile);
|
||||
} catch (error) {
|
||||
// If we can't write to the configured/default location, fall back to temp directory
|
||||
if (logFile !== fallbackLogPath) {
|
||||
const originalPath = logFile;
|
||||
logFile = fallbackLogPath;
|
||||
// We'll log this error after the logger is initialized
|
||||
console.error(`Unable to write to log directory: ${logDir}. Falling back to: ${fallbackLogPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
const transportTargets = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@ import {
|
|||
ApplicationListData,
|
||||
WindowListData,
|
||||
} from "../types/index.js";
|
||||
import { executeSwiftCli } from "../utils/peekaboo-cli.js";
|
||||
import { executeSwiftCli, execPeekaboo } from "../utils/peekaboo-cli.js";
|
||||
import { generateServerStatusString } from "../utils/server-status.js";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import { existsSync, accessSync, constants } from "fs";
|
||||
import os from "os";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export const listToolSchema = z
|
||||
.object({
|
||||
|
|
@ -85,13 +88,16 @@ export async function listToolHandler(
|
|||
|
||||
// Handle server_status directly without calling Swift CLI
|
||||
if (input.item_type === "server_status") {
|
||||
// Get package version
|
||||
const packageJsonPath = path.join(process.cwd(), "package.json");
|
||||
// Get package version and root directory
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const packageRootDir = path.resolve(__dirname, "../..");
|
||||
const packageJsonPath = path.join(packageRootDir, "package.json");
|
||||
const packageJson = JSON.parse(
|
||||
await fs.readFile(packageJsonPath, "utf-8"),
|
||||
);
|
||||
const version = packageJson.version || "[unknown]";
|
||||
return await handleServerStatus(version);
|
||||
return await handleServerStatus(version, packageRootDir, logger);
|
||||
}
|
||||
|
||||
// Build Swift CLI arguments
|
||||
|
|
@ -172,14 +178,154 @@ export async function listToolHandler(
|
|||
|
||||
async function handleServerStatus(
|
||||
version: string,
|
||||
packageRootDir: string,
|
||||
logger: any,
|
||||
): Promise<{ content: { type: string; text: string }[] }> {
|
||||
const statusString = generateServerStatusString(version);
|
||||
const statusSections: string[] = [];
|
||||
|
||||
// 1. Server version and AI providers
|
||||
statusSections.push(generateServerStatusString(version));
|
||||
|
||||
// 2. Native Binary Status
|
||||
statusSections.push("\n## Native Binary (Swift CLI) Status");
|
||||
|
||||
const cliPath = process.env.PEEKABOO_CLI_PATH || path.join(packageRootDir, "peekaboo");
|
||||
let cliStatus = "❌ Not found";
|
||||
let cliVersion = "Unknown";
|
||||
let cliExecutable = false;
|
||||
|
||||
if (existsSync(cliPath)) {
|
||||
try {
|
||||
accessSync(cliPath, constants.X_OK);
|
||||
cliExecutable = true;
|
||||
|
||||
// Try to get CLI version
|
||||
const versionResult = await execPeekaboo(
|
||||
["--version"],
|
||||
packageRootDir,
|
||||
{ expectSuccess: false }
|
||||
);
|
||||
|
||||
if (versionResult.success && versionResult.data) {
|
||||
cliVersion = versionResult.data.trim();
|
||||
cliStatus = "✅ Found and executable";
|
||||
} else {
|
||||
cliStatus = "⚠️ Found but version check failed";
|
||||
}
|
||||
} catch (error) {
|
||||
cliStatus = "⚠️ Found but not executable";
|
||||
}
|
||||
}
|
||||
|
||||
statusSections.push(`- Location: ${cliPath}`);
|
||||
statusSections.push(`- Status: ${cliStatus}`);
|
||||
statusSections.push(`- Version: ${cliVersion}`);
|
||||
statusSections.push(`- Executable: ${cliExecutable ? "Yes" : "No"}`);
|
||||
|
||||
// 3. Permissions Status
|
||||
statusSections.push("\n## System Permissions");
|
||||
|
||||
if (cliExecutable) {
|
||||
try {
|
||||
const permissionsResult = await execPeekaboo(
|
||||
["list", "server_status", "--json-output"],
|
||||
packageRootDir,
|
||||
{ expectSuccess: false }
|
||||
);
|
||||
|
||||
if (permissionsResult.success && permissionsResult.data) {
|
||||
const status = JSON.parse(permissionsResult.data);
|
||||
if (status.data?.permissions) {
|
||||
const perms = status.data.permissions;
|
||||
statusSections.push(`- Screen Recording: ${perms.screen_recording ? "✅ Granted" : "❌ Not granted"}`);
|
||||
statusSections.push(`- Accessibility: ${perms.accessibility ? "✅ Granted" : "❌ Not granted"}`);
|
||||
} else {
|
||||
statusSections.push("- Unable to determine permissions status");
|
||||
}
|
||||
} else {
|
||||
statusSections.push("- Unable to check permissions (CLI error)");
|
||||
}
|
||||
} catch (error) {
|
||||
statusSections.push(`- Unable to check permissions: ${error}`);
|
||||
}
|
||||
} else {
|
||||
statusSections.push("- Unable to check permissions (CLI not available)");
|
||||
}
|
||||
|
||||
// 4. Environment Configuration
|
||||
statusSections.push("\n## Environment Configuration");
|
||||
|
||||
const logFile = process.env.PEEKABOO_LOG_FILE || path.join(os.homedir(), "Library/Logs/peekaboo-mcp.log");
|
||||
const logLevel = process.env.PEEKABOO_LOG_LEVEL || "info";
|
||||
const consoleLogging = process.env.PEEKABOO_CONSOLE_LOGGING === "true";
|
||||
const aiProviders = process.env.PEEKABOO_AI_PROVIDERS || "None configured";
|
||||
const customCliPath = process.env.PEEKABOO_CLI_PATH;
|
||||
const defaultSavePath = process.env.PEEKABOO_DEFAULT_SAVE_PATH || "Not set";
|
||||
|
||||
statusSections.push(`- Log File: ${logFile}`);
|
||||
|
||||
// Check log file accessibility
|
||||
try {
|
||||
const logDir = path.dirname(logFile);
|
||||
await fs.access(logDir, constants.W_OK);
|
||||
statusSections.push(` Status: ✅ Directory writable`);
|
||||
} catch (error) {
|
||||
statusSections.push(` Status: ❌ Directory not writable`);
|
||||
}
|
||||
|
||||
statusSections.push(`- Log Level: ${logLevel}`);
|
||||
statusSections.push(`- Console Logging: ${consoleLogging ? "Enabled" : "Disabled"}`);
|
||||
statusSections.push(`- AI Providers: ${aiProviders}`);
|
||||
statusSections.push(`- Custom CLI Path: ${customCliPath || "Not set (using default)"}`);
|
||||
statusSections.push(`- Default Save Path: ${defaultSavePath}`);
|
||||
|
||||
// 5. Configuration Issues
|
||||
statusSections.push("\n## Configuration Issues");
|
||||
|
||||
const issues: string[] = [];
|
||||
|
||||
if (!cliExecutable) {
|
||||
issues.push("❌ Swift CLI not found or not executable");
|
||||
}
|
||||
|
||||
if (cliVersion !== version && cliVersion !== "Unknown") {
|
||||
issues.push(`⚠️ Version mismatch: Server ${version} vs CLI ${cliVersion}`);
|
||||
}
|
||||
|
||||
if (!aiProviders || aiProviders === "None configured") {
|
||||
issues.push("⚠️ No AI providers configured (analysis features will be limited)");
|
||||
}
|
||||
|
||||
// Check if log directory is writable
|
||||
try {
|
||||
const logDir = path.dirname(logFile);
|
||||
await fs.access(logDir, constants.W_OK);
|
||||
} catch {
|
||||
issues.push(`❌ Log directory not writable: ${path.dirname(logFile)}`);
|
||||
}
|
||||
|
||||
if (issues.length === 0) {
|
||||
statusSections.push("✅ No configuration issues detected");
|
||||
} else {
|
||||
issues.forEach(issue => statusSections.push(issue));
|
||||
}
|
||||
|
||||
// 6. System Information
|
||||
statusSections.push("\n## System Information");
|
||||
statusSections.push(`- Platform: ${os.platform()}`);
|
||||
statusSections.push(`- Architecture: ${os.arch()}`);
|
||||
statusSections.push(`- OS Version: ${os.release()}`);
|
||||
statusSections.push(`- Node.js Version: ${process.version}`);
|
||||
|
||||
const fullStatus = statusSections.join("\n");
|
||||
|
||||
logger.info({ status: fullStatus }, "Server status info generated");
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: statusString,
|
||||
text: fullStatus,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue