@fickydev/pigent 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +2 -10
- package/TODO.md +2 -0
- package/package.json +1 -1
- package/src/cli/run.ts +20 -9
- package/src/cli/setup.ts +5 -43
- package/src/db/client.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
- Added optional automatic Telegram chat setup via `PIGENT_AUTO_SETUP_CHATS`.
|
|
28
28
|
- Set default workspace root to `~/.pigent` and added tilde expansion for agent workspaces.
|
|
29
29
|
- Added npm package metadata and MIT license for publishing.
|
|
30
|
+
- Simplified published CLI flow so `bunx @fickydev/pigent` runs setup and starts Pigent without install/start/typecheck prompts.
|
|
31
|
+
- Added automatic database migrations at daemon startup.
|
|
30
32
|
|
|
31
33
|
### Changed
|
|
32
34
|
|
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ src/
|
|
|
71
71
|
|
|
72
72
|
## Setup And Run
|
|
73
73
|
|
|
74
|
-
From a published package, one command
|
|
74
|
+
From a published package, one command creates a project if needed, runs lightweight setup, applies migrations automatically, and starts the daemon:
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
77
|
bunx @fickydev/pigent my-pigent
|
|
@@ -91,12 +91,6 @@ bun run run -- --setup
|
|
|
91
91
|
bunx @fickydev/pigent my-pigent --setup
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
Skip slow setup steps when needed:
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
bun run run -- --skip-install --skip-migrate --skip-typecheck
|
|
98
|
-
```
|
|
99
|
-
|
|
100
94
|
The setup flow will:
|
|
101
95
|
|
|
102
96
|
- ask for quick or custom mode
|
|
@@ -106,9 +100,7 @@ The setup flow will:
|
|
|
106
100
|
- optionally enable automatic Telegram chat setup
|
|
107
101
|
- optionally configure Telegram chat routing in `pigent.yaml`
|
|
108
102
|
- optionally configure log level and Telegram polling values in custom mode
|
|
109
|
-
|
|
110
|
-
- optionally apply database migrations
|
|
111
|
-
- optionally run typecheck
|
|
103
|
+
Database migrations run automatically at daemon startup. The published CLI does not ask users to run `bun install`, `bun start`, or `bun typecheck`.
|
|
112
104
|
|
|
113
105
|
Manual setup:
|
|
114
106
|
|
package/TODO.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Now
|
|
4
4
|
|
|
5
|
+
- [x] Remove install/migrate/typecheck prompts from published run flow
|
|
6
|
+
- [x] Add automatic startup migrations
|
|
5
7
|
- [x] Add `bunx @fickydev/pigent <dir>` scaffold/setup/run command
|
|
6
8
|
- [x] Add one-command setup-and-run CLI
|
|
7
9
|
- [x] Add interactive setup CLI
|
package/package.json
CHANGED
package/src/cli/run.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { $ } from "bun";
|
|
3
2
|
import { existsSync } from "node:fs";
|
|
4
3
|
import { cp, mkdir } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
@@ -9,13 +9,11 @@ const args = process.argv.slice(2);
|
|
|
9
9
|
const flags = new Set(args.filter((arg) => arg.startsWith("--")));
|
|
10
10
|
const targetDirArg = args.find((arg) => !arg.startsWith("--"));
|
|
11
11
|
const forceSetup = flags.has("--setup") || flags.has("--reconfigure");
|
|
12
|
-
const skipInstall = flags.has("--skip-install");
|
|
13
|
-
const skipMigrate = flags.has("--skip-migrate");
|
|
14
|
-
const skipTypecheck = flags.has("--skip-typecheck");
|
|
15
12
|
|
|
16
13
|
async function main(): Promise<void> {
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const targetDir = resolveTargetDir();
|
|
15
|
+
|
|
16
|
+
if (targetDir) {
|
|
19
17
|
await ensureProject(targetDir);
|
|
20
18
|
process.chdir(targetDir);
|
|
21
19
|
}
|
|
@@ -23,10 +21,20 @@ async function main(): Promise<void> {
|
|
|
23
21
|
const { runSetup } = await import("./setup");
|
|
24
22
|
|
|
25
23
|
if (forceSetup || needsSetup(process.cwd())) {
|
|
26
|
-
await runSetup({
|
|
24
|
+
await runSetup({
|
|
25
|
+
skipInstall: true,
|
|
26
|
+
skipMigrate: true,
|
|
27
|
+
skipTypecheck: true,
|
|
28
|
+
});
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
await
|
|
31
|
+
await import("../main");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolveTargetDir(): string | null {
|
|
35
|
+
if (targetDirArg) return resolve(process.cwd(), targetDirArg);
|
|
36
|
+
if (looksLikePigentProject(process.cwd())) return null;
|
|
37
|
+
return join(homedir(), ".pigent", "app");
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
async function ensureProject(targetDir: string): Promise<void> {
|
|
@@ -67,10 +75,13 @@ function shouldCopy(sourceRoot: string, source: string): boolean {
|
|
|
67
75
|
|
|
68
76
|
function needsSetup(rootDir: string): boolean {
|
|
69
77
|
if (!existsSync(join(rootDir, ".env"))) return true;
|
|
70
|
-
if (!existsSync(join(rootDir, "pigent.db"))) return true;
|
|
71
78
|
return false;
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
function looksLikePigentProject(rootDir: string): boolean {
|
|
82
|
+
return existsSync(join(rootDir, "pigent.yaml")) && existsSync(join(rootDir, "agents"));
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
main().catch((error) => {
|
|
75
86
|
console.error("[pigent] failed", error instanceof Error ? error.message : error);
|
|
76
87
|
process.exit(1);
|
package/src/cli/setup.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { $ } from "bun";
|
|
5
4
|
import YAML from "yaml";
|
|
6
5
|
|
|
7
6
|
const rootDir = process.cwd();
|
|
@@ -15,11 +14,7 @@ export type SetupOptions = {
|
|
|
15
14
|
skipTypecheck?: boolean;
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
export async function runSetup(
|
|
19
|
-
const skipInstall = options.skipInstall ?? false;
|
|
20
|
-
const skipMigrate = options.skipMigrate ?? false;
|
|
21
|
-
const skipTypecheck = options.skipTypecheck ?? false;
|
|
22
|
-
|
|
17
|
+
export async function runSetup(_options: SetupOptions = {}): Promise<void> {
|
|
23
18
|
banner();
|
|
24
19
|
|
|
25
20
|
const mode = select("Setup mode", ["quick", "custom"], "quick");
|
|
@@ -29,30 +24,12 @@ export async function runSetup(options: SetupOptions = {}): Promise<void> {
|
|
|
29
24
|
await configureEnvironment(isCustom);
|
|
30
25
|
await configureTelegramChat(isCustom);
|
|
31
26
|
|
|
32
|
-
if (!skipInstall && confirm("Install dependencies?", true)) {
|
|
33
|
-
await runStep("Install dependencies", async () => {
|
|
34
|
-
await $`bun install`;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!skipMigrate && confirm("Apply database migrations?", true)) {
|
|
39
|
-
await runStep("Apply database migrations", async () => {
|
|
40
|
-
await $`bun run db:migrate`;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!skipTypecheck && confirm("Run typecheck?", true)) {
|
|
45
|
-
await runStep("Typecheck", async () => {
|
|
46
|
-
await $`bun run typecheck`;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
27
|
summary();
|
|
51
28
|
}
|
|
52
29
|
|
|
53
30
|
function banner(): void {
|
|
54
|
-
console.log("\nPigent
|
|
55
|
-
console.log("
|
|
31
|
+
console.log("\nPigent setup");
|
|
32
|
+
console.log("------------");
|
|
56
33
|
}
|
|
57
34
|
|
|
58
35
|
async function ensureEnvFile(): Promise<void> {
|
|
@@ -172,11 +149,6 @@ async function configureTelegramChat(isCustom: boolean): Promise<void> {
|
|
|
172
149
|
log(`Configured Telegram chat ${chatId}`);
|
|
173
150
|
}
|
|
174
151
|
|
|
175
|
-
async function runStep(name: string, step: () => Promise<void>): Promise<void> {
|
|
176
|
-
log(name);
|
|
177
|
-
await step();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
152
|
function input(label: string, defaultValue: string): string {
|
|
181
153
|
const suffix = defaultValue ? ` [${defaultValue}]` : "";
|
|
182
154
|
const value = prompt(`${label}${suffix}:`)?.trim();
|
|
@@ -236,11 +208,7 @@ function setEnvValue(content: string, key: string, value: string): string {
|
|
|
236
208
|
}
|
|
237
209
|
|
|
238
210
|
function summary(): void {
|
|
239
|
-
console.log("\nSetup complete");
|
|
240
|
-
console.log("--------------");
|
|
241
|
-
console.log("Start daemon: bun run start");
|
|
242
|
-
console.log("Dev mode: bun run dev");
|
|
243
|
-
console.log("Typecheck: bun run typecheck");
|
|
211
|
+
console.log("\nSetup complete. Starting Pigent...\n");
|
|
244
212
|
}
|
|
245
213
|
|
|
246
214
|
function log(message: string): void {
|
|
@@ -248,13 +216,7 @@ function log(message: string): void {
|
|
|
248
216
|
}
|
|
249
217
|
|
|
250
218
|
if (import.meta.main) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
runSetup({
|
|
254
|
-
skipInstall: flags.has("--skip-install"),
|
|
255
|
-
skipMigrate: flags.has("--skip-migrate"),
|
|
256
|
-
skipTypecheck: flags.has("--skip-typecheck"),
|
|
257
|
-
}).catch((error) => {
|
|
219
|
+
runSetup().catch((error) => {
|
|
258
220
|
console.error("[setup] failed", error instanceof Error ? error.message : error);
|
|
259
221
|
process.exit(1);
|
|
260
222
|
});
|
package/src/db/client.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { mkdirSync } from "node:fs";
|
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
3
|
import { Database } from "bun:sqlite";
|
|
4
4
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
|
5
|
+
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
|
5
6
|
import * as schema from "./schema";
|
|
6
7
|
|
|
7
8
|
function databasePathFromEnv(): string {
|
|
@@ -16,6 +17,8 @@ mkdirSync(dirname(databasePath), { recursive: true });
|
|
|
16
17
|
export const sqlite = new Database(databasePath);
|
|
17
18
|
export const db = drizzle(sqlite, { schema });
|
|
18
19
|
|
|
20
|
+
migrate(db, { migrationsFolder: "./drizzle/migrations" });
|
|
21
|
+
|
|
19
22
|
export type DbClient = typeof db;
|
|
20
23
|
|
|
21
24
|
export function getDatabasePath(): string {
|