forked from farhoodlabs/paperclip
e43b392a79
## Thinking Path > - Paperclip is the control plane for AI-agent companies. > - Operators need a path to move local company state toward Paperclip Cloud without losing local-first control. > - The Cloud Upstream flow needs API, persistence, CLI, and board UI surfaces that agree on the same manifest/run model. > - The existing branch had the feature work plus UX and error-handling follow-ups. > - This pull request packages the remaining Cloud Upstream sync work into one standalone branch. > - The benefit is an inspectable local-to-cloud sync workflow with preview, conflicts, activation, and captured UX review states. ## What Changed - Added Cloud Upstream shared types, server routes/services, and persisted run schema/migration. - Added Paperclip Cloud CLI sync helpers and local connection storage. - Added the Cloud Upstream board UI, settings entry points, query keys, and UX lab page. - Added preview/activation checklist behavior, redirect handling, manifest-only preview support, friendly errors, in-flight hints, and entity count summaries. ## Verification - `pnpm --filter @paperclipai/plugin-sdk build` - `NODE_ENV=test pnpm exec vitest run cli/src/__tests__/cloud.test.ts server/src/__tests__/instance-settings-routes.test.ts server/src/__tests__/instance-settings-service.test.ts ui/src/pages/CloudUpstream.test.tsx ui/src/components/CompanySettingsSidebar.test.tsx` - `NODE_ENV=test pnpm exec vitest run server/src/__tests__/cloud-upstreams.test.ts` Worktree setup note: the isolated worktree install skipped native sqlite build scripts, so I copied the already-built local sqlite binding from the main checkout before running `server/src/__tests__/cloud-upstreams.test.ts`. The test then passed. ## Risks - Medium: this adds a database migration and a broad feature path across CLI/server/UI. - Merge order: this is the only PR in this split with a DB migration; merge it before any future Cloud Upstream migration follow-up. - Mitigation: the PR is based directly on current `origin/master`, has targeted route/service/UI tests, and keeps the feature behind existing experimental Cloud Sync settings. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - OpenAI GPT-5 Codex via `codex_local`, tool-enabled coding session; exact context window not exposed by this runtime. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, screenshot artifacts are intentionally omitted per reviewer request - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge
189 lines
7.8 KiB
TypeScript
189 lines
7.8 KiB
TypeScript
import { Command } from "commander";
|
|
import { onboard } from "./commands/onboard.js";
|
|
import { doctor } from "./commands/doctor.js";
|
|
import { envCommand } from "./commands/env.js";
|
|
import { configure } from "./commands/configure.js";
|
|
import { addAllowedHostname } from "./commands/allowed-hostname.js";
|
|
import { heartbeatRun } from "./commands/heartbeat-run.js";
|
|
import { runCommand } from "./commands/run.js";
|
|
import { bootstrapCeoInvite } from "./commands/auth-bootstrap-ceo.js";
|
|
import { dbBackupCommand } from "./commands/db-backup.js";
|
|
import { registerEnvLabCommands } from "./commands/env-lab.js";
|
|
import { registerContextCommands } from "./commands/client/context.js";
|
|
import { registerCompanyCommands } from "./commands/client/company.js";
|
|
import { registerIssueCommands } from "./commands/client/issue.js";
|
|
import { registerAgentCommands } from "./commands/client/agent.js";
|
|
import { registerApprovalCommands } from "./commands/client/approval.js";
|
|
import { registerActivityCommands } from "./commands/client/activity.js";
|
|
import { registerDashboardCommands } from "./commands/client/dashboard.js";
|
|
import { registerRoutineCommands } from "./commands/routines.js";
|
|
import { registerFeedbackCommands } from "./commands/client/feedback.js";
|
|
import { registerSecretCommands } from "./commands/client/secrets.js";
|
|
import { registerCloudCommands } from "./commands/client/cloud.js";
|
|
import { applyDataDirOverride, type DataDirOptionLike } from "./config/data-dir.js";
|
|
import { loadPaperclipEnvFile } from "./config/env.js";
|
|
import { initTelemetryFromConfigFile, flushTelemetry } from "./telemetry.js";
|
|
import { registerWorktreeCommands } from "./commands/worktree.js";
|
|
import { registerPluginCommands } from "./commands/client/plugin.js";
|
|
import { registerClientAuthCommands } from "./commands/client/auth.js";
|
|
import { cliVersion } from "./version.js";
|
|
|
|
const program = new Command();
|
|
const DATA_DIR_OPTION_HELP =
|
|
"Paperclip data directory root (isolates state from ~/.paperclip)";
|
|
|
|
program
|
|
.name("paperclipai")
|
|
.description("Paperclip CLI — setup, diagnose, and configure your instance")
|
|
.version(cliVersion);
|
|
|
|
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
const options = actionCommand.optsWithGlobals() as DataDirOptionLike;
|
|
const optionNames = new Set(actionCommand.options.map((option) => option.attributeName()));
|
|
applyDataDirOverride(options, {
|
|
hasConfigOption: optionNames.has("config"),
|
|
hasContextOption: optionNames.has("context"),
|
|
});
|
|
loadPaperclipEnvFile(options.config);
|
|
initTelemetryFromConfigFile(options.config);
|
|
});
|
|
|
|
program
|
|
.command("onboard")
|
|
.description("Interactive first-run setup wizard")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("--bind <mode>", "Quickstart reachability preset (loopback, lan, tailnet)")
|
|
.option("-y, --yes", "Accept quickstart defaults (trusted local loopback unless --bind is set) and start immediately", false)
|
|
.option("--run", "Start Paperclip immediately after saving config", false)
|
|
.action(onboard);
|
|
|
|
program
|
|
.command("doctor")
|
|
.description("Run diagnostic checks on your Paperclip setup")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("--repair", "Attempt to repair issues automatically")
|
|
.alias("--fix")
|
|
.option("-y, --yes", "Skip repair confirmation prompts")
|
|
.action(async (opts) => {
|
|
await doctor(opts);
|
|
});
|
|
|
|
program
|
|
.command("env")
|
|
.description("Print environment variables for deployment")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.action(envCommand);
|
|
|
|
program
|
|
.command("configure")
|
|
.description("Update configuration sections")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("-s, --section <section>", "Section to configure (llm, database, logging, server, storage, secrets)")
|
|
.action(configure);
|
|
|
|
program
|
|
.command("db:backup")
|
|
.description("Create a one-off database backup using current config")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("--dir <path>", "Backup output directory (overrides config)")
|
|
.option("--retention-days <days>", "Retention window used for pruning", (value) => Number(value))
|
|
.option("--filename-prefix <prefix>", "Backup filename prefix", "paperclip")
|
|
.option("--json", "Print backup metadata as JSON")
|
|
.action(async (opts) => {
|
|
await dbBackupCommand(opts);
|
|
});
|
|
|
|
program
|
|
.command("allowed-hostname")
|
|
.description("Allow a hostname for authenticated/private mode access")
|
|
.argument("<host>", "Hostname to allow (for example dotta-macbook-pro)")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.action(addAllowedHostname);
|
|
|
|
program
|
|
.command("run")
|
|
.description("Bootstrap local setup (onboard + doctor) and run Paperclip")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("-i, --instance <id>", "Local instance id (default: default)")
|
|
.option("--bind <mode>", "On first run, use onboarding reachability preset (loopback, lan, tailnet)")
|
|
.option("--repair", "Attempt automatic repairs during doctor", true)
|
|
.option("--no-repair", "Disable automatic repairs during doctor")
|
|
.action(runCommand);
|
|
|
|
const heartbeat = program.command("heartbeat").description("Heartbeat utilities");
|
|
|
|
heartbeat
|
|
.command("run")
|
|
.description("Run one agent heartbeat and stream live logs")
|
|
.requiredOption("-a, --agent-id <agentId>", "Agent ID to invoke")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("--context <path>", "Path to CLI context file")
|
|
.option("--profile <name>", "CLI context profile name")
|
|
.option("--api-base <url>", "Base URL for the Paperclip server API")
|
|
.option("--api-key <token>", "Bearer token for agent-authenticated calls")
|
|
.option(
|
|
"--source <source>",
|
|
"Invocation source (timer | assignment | on_demand | automation)",
|
|
"on_demand",
|
|
)
|
|
.option("--trigger <trigger>", "Trigger detail (manual | ping | callback | system)", "manual")
|
|
.option("--timeout-ms <ms>", "Max time to wait before giving up", "0")
|
|
.option("--json", "Output raw JSON where applicable")
|
|
.option("--debug", "Show raw adapter stdout/stderr JSON chunks")
|
|
.action(heartbeatRun);
|
|
|
|
registerContextCommands(program);
|
|
registerCompanyCommands(program);
|
|
registerIssueCommands(program);
|
|
registerAgentCommands(program);
|
|
registerApprovalCommands(program);
|
|
registerActivityCommands(program);
|
|
registerDashboardCommands(program);
|
|
registerRoutineCommands(program);
|
|
registerFeedbackCommands(program);
|
|
registerSecretCommands(program);
|
|
registerCloudCommands(program);
|
|
registerWorktreeCommands(program);
|
|
registerEnvLabCommands(program);
|
|
registerPluginCommands(program);
|
|
|
|
const auth = program.command("auth").description("Authentication and bootstrap utilities");
|
|
|
|
auth
|
|
.command("bootstrap-ceo")
|
|
.description("Create a one-time bootstrap invite URL for first instance admin")
|
|
.option("-c, --config <path>", "Path to config file")
|
|
.option("-d, --data-dir <path>", DATA_DIR_OPTION_HELP)
|
|
.option("--force", "Create new invite even if admin already exists", false)
|
|
.option("--expires-hours <hours>", "Invite expiration window in hours", (value) => Number(value))
|
|
.option("--base-url <url>", "Public base URL used to print invite link")
|
|
.action(bootstrapCeoInvite);
|
|
|
|
registerClientAuthCommands(auth);
|
|
|
|
async function main(): Promise<void> {
|
|
let failed = false;
|
|
try {
|
|
await program.parseAsync();
|
|
} catch (err) {
|
|
failed = true;
|
|
console.error(err instanceof Error ? err.message : String(err));
|
|
} finally {
|
|
await flushTelemetry();
|
|
}
|
|
|
|
if (failed) {
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
void main();
|