From f3b2fc01082e754f7dfe73caa4f0a4f207a2adfb Mon Sep 17 00:00:00 2001 From: YurenHao0426 Date: Sun, 13 Sep 2026 04:05:38 +0000 Subject: Add headless CLI for Overleaf project management (lattex-cli) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New src/cli/ module providing a headless CLI for AI agents to work with Overleaf projects from a server with no display. Commands: auth, projects, clone, pull, status, push, compile. Key design decisions: - Uses Node.js https module (no Electron dependency), same approach as the existing MCP server in src/mcp/lattex.mjs - Reuses overleafProtocol.ts for Socket.IO v0.9 parsing (pure, no Electron) - Separate esbuild bundle (out/cli/lattex-cli.mjs) — does not touch the Electron app build - 64 tests for arg parsing, file tree walking, diff logic, and log parsing Files: - src/cli/main.ts — CLI entry point with all commands - src/cli/args.ts — argument parser - src/cli/overleafApi.ts — Overleaf API client using https + ws - src/cli/fileTree.ts — project root folder walker - src/cli/localState.ts — per-clone state (.lattex-cli.json) and auth storage - src/cli/diff.ts — local vs remote diff logic - src/cli/logParser.ts — LaTeX compile log parser - src/cli/test.ts — unit tests - tsconfig.cli.json — TypeScript config for CLI Co-Authored-By: Claude Opus 5 --- src/cli/args.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/cli/args.ts (limited to 'src/cli/args.ts') diff --git a/src/cli/args.ts b/src/cli/args.ts new file mode 100644 index 0000000..0f7a767 --- /dev/null +++ b/src/cli/args.ts @@ -0,0 +1,39 @@ +// CLI argument parser + +export interface ParsedArgs { + command: string + positional: string[] + flags: Record +} + +export function parseArgs(argv: string[]): ParsedArgs { + const args = argv.slice(2) + const command = args[0] || '' + const positional: string[] = [] + const flags: Record = {} + + for (let i = 1; i < args.length; i++) { + const arg = args[i] + if (arg.startsWith('--')) { + const eqIdx = arg.indexOf('=') + if (eqIdx !== -1) { + flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1) + } else if (i + 1 < args.length && !args[i + 1].startsWith('--')) { + const key = arg.slice(2) + // Boolean flags that never take a value + const boolFlags = new Set(['json', 'dry-run', 'delete', 'force', 'help']) + if (boolFlags.has(key)) { + flags[key] = true + } else { + flags[key] = args[++i] + } + } else { + flags[arg.slice(2)] = true + } + } else { + positional.push(arg) + } + } + + return { command, positional, flags } +} -- cgit v1.2.3