mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 16:27:18 +02:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The CLI onboarding wizard's custom-setup path collects server,
database, storage, and secrets configuration through `@clack/prompts`
text prompts, most of which show a sensible default
> - `@clack/prompts` runs each prompt's `validate` callback on the raw
typed value, and only substitutes `defaultValue` after validation passes
— so pressing Enter to accept a shown default hands the validator an
empty string
> - Eleven of the wizard's validators reject the empty string, which
makes their own displayed defaults unacceptable: accepting "Embedded
PostgreSQL port: 54329" fails with "Port must be an integer between 1
and 65535", "Backup directory" fails with "Backup directory is
required", and so on through every prompt in the custom path
> - This pull request makes each affected validator accept empty input
when a default exists, while keeping all real validation for typed input
> - The benefit is that the custom-setup wizard is walkable by pressing
Enter through the defaults, as the UI clearly intends
## Linked Issues or Issue Description
No existing issue. Description follows the bug-report template:
**What happened?**
In `paperclipai onboard` custom setup, pressing Enter to accept a
prompt's displayed default fails validation on eleven prompts. Confirmed
live on the "Embedded PostgreSQL port" prompt (default 54329 → "Port
must be an integer between 1 and 65535") and the "Backup directory"
prompt (populated default path → "Backup directory is required"). The
only way through is to retype every default by hand.
**Expected behavior**
Pressing Enter accepts the displayed default, as in every standard
`@clack/prompts` flow.
**Steps to reproduce**
1. `npx paperclipai onboard` → choose Custom setup.
2. At "Embedded PostgreSQL port", press Enter to accept the shown
default.
3. Validation rejects it. Same for the backup directory, backup
interval/retention, server port, bind host, storage directory, S3
bucket/region, and secrets key-file prompts.
**Paperclip version or commit**
Reproduced on `2026.915.0-canary.11`; the same validators exist in the
latest stable (`v2026.831.1`) — long-standing, not a recent regression.
**Deployment mode**
Any (the bug is in the CLI wizard).
**Installation method**
`npx paperclipai onboard`.
## What Changed
- Audited all 15 `validate:` callbacks across
`cli/src/prompts/{database,server,storage,llm,secrets}.ts`. Eleven
rejected the empty string while displaying a default; two were already
fine (hostname CSV prompts, where empty parses to `[]`); one is an
intentionally required password with no default (left alone); one
(PostgreSQL connection string) and one (public base URL) are
conditionally required — empty now passes only when a saved default
exists, so fresh setups still enforce the field
- Fix pattern: allow empty/undefined input at the top of each affected
validator; every check for non-empty typed input is unchanged. One
deliberate exception: the bind-host validator validates `(val ||
defaultHost)` so accepting the default still runs the loopback safety
check rather than bypassing it
- New `cli/src/__tests__/prompt-default-accept.test.ts` (repo-convention
vitest + clack mock reproducing real submit semantics — validate raw
`""`, then substitute the default): drives the four prompt modules
end-to-end and unit-exercises each captured validator (empty accepted,
garbage still rejected, required-when-fresh still rejected)
## Verification
- `pnpm exec vitest run src/__tests__/prompt-default-accept.test.ts` in
`cli/`: 13/13 pass; with the prompt fixes stashed: 12/13 fail — the
suite reproduces the bug
- Full cli suite: 483 passed; 15 failures are pre-existing/environmental
on the clean tree too (macOS `/var` realpath mismatch in
`worktree.test.ts`, one parallel-run flake that passes in isolation)
- `pnpm run typecheck` in `cli/`: zero errors in `cli/src` (the 228
pre-existing errors in `../server/src` from missing prebuilt workspace
dist are identical with and without the change)
## Risks
- Low. Typed input validates exactly as before; whitespace-only input is
still rejected (clack substitutes the default only for truly-empty
input). The two conditionally-required prompts still hard-require a
value on fresh setups
- No migrations, no API surface changes; CLI-only
## Model Used
Claude Fable 5 (`claude-fable-5`), extended thinking with tool use
(Claude Code); implementation drafted by a subagent on the same model
and reviewed before commit.
## 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 searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
167 lines
5.4 KiB
TypeScript
167 lines
5.4 KiB
TypeScript
import * as p from "@clack/prompts";
|
|
import type { DatabaseConfig } from "../config/schema.js";
|
|
import {
|
|
resolveDefaultBackupDir,
|
|
resolveDefaultEmbeddedPostgresDir,
|
|
resolvePaperclipInstanceId,
|
|
} from "../config/home.js";
|
|
|
|
export async function promptDatabase(current?: DatabaseConfig): Promise<DatabaseConfig> {
|
|
const instanceId = resolvePaperclipInstanceId();
|
|
const defaultEmbeddedDir = resolveDefaultEmbeddedPostgresDir(instanceId);
|
|
const defaultBackupDir = resolveDefaultBackupDir(instanceId);
|
|
const base: DatabaseConfig = current ?? {
|
|
mode: "embedded-postgres",
|
|
embeddedPostgresDataDir: defaultEmbeddedDir,
|
|
embeddedPostgresPort: 54329,
|
|
backup: {
|
|
enabled: true,
|
|
intervalMinutes: 60,
|
|
retentionDays: 30,
|
|
dir: defaultBackupDir,
|
|
},
|
|
};
|
|
|
|
const mode = await p.select({
|
|
message: "Database mode",
|
|
options: [
|
|
{ value: "embedded-postgres" as const, label: "Embedded PostgreSQL (managed locally)", hint: "recommended" },
|
|
{ value: "postgres" as const, label: "PostgreSQL (external server)" },
|
|
],
|
|
initialValue: base.mode,
|
|
});
|
|
|
|
if (p.isCancel(mode)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
let connectionString: string | undefined = base.connectionString;
|
|
let embeddedPostgresDataDir = base.embeddedPostgresDataDir || defaultEmbeddedDir;
|
|
let embeddedPostgresPort = base.embeddedPostgresPort || 54329;
|
|
const embeddedPortDefault = String(base.embeddedPostgresPort || 54329);
|
|
|
|
if (mode === "postgres") {
|
|
// Clack validates the raw input before applying defaultValue, so an
|
|
// Enter press hands the validator an empty string. Validate the value
|
|
// that will actually be submitted — the typed input, or the default.
|
|
const connectionStringDefault = base.connectionString ?? "";
|
|
const value = await p.text({
|
|
message: "PostgreSQL connection string",
|
|
defaultValue: connectionStringDefault,
|
|
placeholder: "postgres://user:pass@localhost:5432/paperclip",
|
|
validate: (val) => {
|
|
const candidate = val || connectionStringDefault;
|
|
if (!candidate) return "Connection string is required for PostgreSQL mode";
|
|
if (!candidate.startsWith("postgres")) return "Must be a postgres:// or postgresql:// URL";
|
|
},
|
|
});
|
|
|
|
if (p.isCancel(value)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
connectionString = value;
|
|
} else {
|
|
const dataDir = await p.text({
|
|
message: "Embedded PostgreSQL data directory",
|
|
defaultValue: base.embeddedPostgresDataDir || defaultEmbeddedDir,
|
|
placeholder: defaultEmbeddedDir,
|
|
});
|
|
|
|
if (p.isCancel(dataDir)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
embeddedPostgresDataDir = dataDir || defaultEmbeddedDir;
|
|
|
|
const portValue = await p.text({
|
|
message: "Embedded PostgreSQL port",
|
|
defaultValue: embeddedPortDefault,
|
|
placeholder: "54329",
|
|
validate: (val) => {
|
|
const n = Number(val || embeddedPortDefault);
|
|
if (!Number.isInteger(n) || n < 1 || n > 65535) return "Port must be an integer between 1 and 65535";
|
|
},
|
|
});
|
|
|
|
if (p.isCancel(portValue)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
embeddedPostgresPort = Number(portValue || embeddedPortDefault);
|
|
connectionString = undefined;
|
|
}
|
|
|
|
const backupEnabled = await p.confirm({
|
|
message: "Enable automatic database backups?",
|
|
initialValue: base.backup.enabled,
|
|
});
|
|
if (p.isCancel(backupEnabled)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
const backupDirDefault = base.backup.dir || defaultBackupDir;
|
|
const backupDirInput = await p.text({
|
|
message: "Backup directory",
|
|
defaultValue: backupDirDefault,
|
|
placeholder: defaultBackupDir,
|
|
validate: (val) => ((val || backupDirDefault).trim().length === 0 ? "Backup directory is required" : undefined),
|
|
});
|
|
if (p.isCancel(backupDirInput)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
const backupIntervalDefault = String(base.backup.intervalMinutes || 60);
|
|
const backupRetentionDefault = String(base.backup.retentionDays || 30);
|
|
const backupIntervalInput = await p.text({
|
|
message: "Backup interval (minutes)",
|
|
defaultValue: backupIntervalDefault,
|
|
placeholder: "60",
|
|
validate: (val) => {
|
|
const n = Number(val || backupIntervalDefault);
|
|
if (!Number.isInteger(n) || n < 1) return "Interval must be a positive integer";
|
|
if (n > 10080) return "Interval must be 10080 minutes (7 days) or less";
|
|
return undefined;
|
|
},
|
|
});
|
|
if (p.isCancel(backupIntervalInput)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
const backupRetentionInput = await p.text({
|
|
message: "Backup retention (days)",
|
|
defaultValue: backupRetentionDefault,
|
|
placeholder: "30",
|
|
validate: (val) => {
|
|
const n = Number(val || backupRetentionDefault);
|
|
if (!Number.isInteger(n) || n < 1) return "Retention must be a positive integer";
|
|
if (n > 3650) return "Retention must be 3650 days or less";
|
|
return undefined;
|
|
},
|
|
});
|
|
if (p.isCancel(backupRetentionInput)) {
|
|
p.cancel("Setup cancelled.");
|
|
process.exit(0);
|
|
}
|
|
|
|
return {
|
|
mode,
|
|
connectionString,
|
|
embeddedPostgresDataDir,
|
|
embeddedPostgresPort,
|
|
backup: {
|
|
enabled: backupEnabled,
|
|
intervalMinutes: Number(backupIntervalInput || backupIntervalDefault),
|
|
retentionDays: Number(backupRetentionInput || backupRetentionDefault),
|
|
dir: backupDirInput || defaultBackupDir,
|
|
},
|
|
};
|
|
}
|