gigaclaw 1.4.0

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.
Files changed (249) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +237 -0
  3. package/api/CLAUDE.md +19 -0
  4. package/api/index.js +265 -0
  5. package/bin/cli.js +823 -0
  6. package/bin/local.sh +85 -0
  7. package/bin/postinstall.js +63 -0
  8. package/config/index.js +26 -0
  9. package/config/instrumentation.js +62 -0
  10. package/drizzle/0000_initial.sql +52 -0
  11. package/drizzle/0001_nostalgic_sersi.sql +11 -0
  12. package/drizzle/0002_black_daimon_hellstrom.sql +19 -0
  13. package/drizzle/0003_rename_code_workspaces.sql +5 -0
  14. package/drizzle/meta/0000_snapshot.json +321 -0
  15. package/drizzle/meta/0001_snapshot.json +390 -0
  16. package/drizzle/meta/0002_snapshot.json +411 -0
  17. package/drizzle/meta/0003_snapshot.json +419 -0
  18. package/drizzle/meta/_journal.json +34 -0
  19. package/lib/actions.js +44 -0
  20. package/lib/ai/agent.js +86 -0
  21. package/lib/ai/index.js +342 -0
  22. package/lib/ai/model.js +180 -0
  23. package/lib/ai/tools.js +269 -0
  24. package/lib/ai/web-search.js +42 -0
  25. package/lib/auth/actions.js +28 -0
  26. package/lib/auth/config.js +27 -0
  27. package/lib/auth/edge-config.js +27 -0
  28. package/lib/auth/index.js +27 -0
  29. package/lib/auth/middleware.js +62 -0
  30. package/lib/channels/base.js +56 -0
  31. package/lib/channels/index.js +15 -0
  32. package/lib/channels/telegram.js +148 -0
  33. package/lib/chat/actions.js +579 -0
  34. package/lib/chat/api.js +140 -0
  35. package/lib/chat/components/app-sidebar.js +213 -0
  36. package/lib/chat/components/app-sidebar.jsx +279 -0
  37. package/lib/chat/components/chat-header.js +192 -0
  38. package/lib/chat/components/chat-header.jsx +223 -0
  39. package/lib/chat/components/chat-input.js +236 -0
  40. package/lib/chat/components/chat-input.jsx +249 -0
  41. package/lib/chat/components/chat-nav-context.js +11 -0
  42. package/lib/chat/components/chat-nav-context.jsx +11 -0
  43. package/lib/chat/components/chat-page.js +99 -0
  44. package/lib/chat/components/chat-page.jsx +121 -0
  45. package/lib/chat/components/chat.js +153 -0
  46. package/lib/chat/components/chat.jsx +199 -0
  47. package/lib/chat/components/chats-page.js +367 -0
  48. package/lib/chat/components/chats-page.jsx +394 -0
  49. package/lib/chat/components/code-mode-toggle.js +132 -0
  50. package/lib/chat/components/code-mode-toggle.jsx +163 -0
  51. package/lib/chat/components/crons-page.js +172 -0
  52. package/lib/chat/components/crons-page.jsx +244 -0
  53. package/lib/chat/components/greeting.js +11 -0
  54. package/lib/chat/components/greeting.jsx +16 -0
  55. package/lib/chat/components/icons.js +805 -0
  56. package/lib/chat/components/icons.jsx +751 -0
  57. package/lib/chat/components/index.js +20 -0
  58. package/lib/chat/components/message.js +363 -0
  59. package/lib/chat/components/message.jsx +422 -0
  60. package/lib/chat/components/messages.js +65 -0
  61. package/lib/chat/components/messages.jsx +74 -0
  62. package/lib/chat/components/notifications-page.js +56 -0
  63. package/lib/chat/components/notifications-page.jsx +87 -0
  64. package/lib/chat/components/page-layout.js +21 -0
  65. package/lib/chat/components/page-layout.jsx +28 -0
  66. package/lib/chat/components/pull-requests-page.js +103 -0
  67. package/lib/chat/components/pull-requests-page.jsx +113 -0
  68. package/lib/chat/components/settings-layout.js +39 -0
  69. package/lib/chat/components/settings-layout.jsx +53 -0
  70. package/lib/chat/components/settings-secrets-page.js +216 -0
  71. package/lib/chat/components/settings-secrets-page.jsx +264 -0
  72. package/lib/chat/components/sidebar-history-item.js +138 -0
  73. package/lib/chat/components/sidebar-history-item.jsx +119 -0
  74. package/lib/chat/components/sidebar-history.js +167 -0
  75. package/lib/chat/components/sidebar-history.jsx +220 -0
  76. package/lib/chat/components/sidebar-user-nav.js +61 -0
  77. package/lib/chat/components/sidebar-user-nav.jsx +77 -0
  78. package/lib/chat/components/swarm-page.js +157 -0
  79. package/lib/chat/components/swarm-page.jsx +210 -0
  80. package/lib/chat/components/tool-call.js +89 -0
  81. package/lib/chat/components/tool-call.jsx +107 -0
  82. package/lib/chat/components/triggers-page.js +153 -0
  83. package/lib/chat/components/triggers-page.jsx +221 -0
  84. package/lib/chat/components/ui/combobox.js +98 -0
  85. package/lib/chat/components/ui/combobox.jsx +114 -0
  86. package/lib/chat/components/ui/confirm-dialog.js +53 -0
  87. package/lib/chat/components/ui/confirm-dialog.jsx +57 -0
  88. package/lib/chat/components/ui/dropdown-menu.js +194 -0
  89. package/lib/chat/components/ui/dropdown-menu.jsx +215 -0
  90. package/lib/chat/components/ui/rename-dialog.js +78 -0
  91. package/lib/chat/components/ui/rename-dialog.jsx +74 -0
  92. package/lib/chat/components/ui/scroll-area.js +13 -0
  93. package/lib/chat/components/ui/scroll-area.jsx +17 -0
  94. package/lib/chat/components/ui/separator.js +21 -0
  95. package/lib/chat/components/ui/separator.jsx +18 -0
  96. package/lib/chat/components/ui/sheet.js +75 -0
  97. package/lib/chat/components/ui/sheet.jsx +95 -0
  98. package/lib/chat/components/ui/sidebar.js +228 -0
  99. package/lib/chat/components/ui/sidebar.jsx +246 -0
  100. package/lib/chat/components/ui/tooltip.js +56 -0
  101. package/lib/chat/components/ui/tooltip.jsx +66 -0
  102. package/lib/chat/components/upgrade-dialog.js +151 -0
  103. package/lib/chat/components/upgrade-dialog.jsx +170 -0
  104. package/lib/chat/utils.js +11 -0
  105. package/lib/code/actions.js +153 -0
  106. package/lib/code/code-page.js +22 -0
  107. package/lib/code/code-page.jsx +25 -0
  108. package/lib/code/index.js +1 -0
  109. package/lib/code/terminal-view.js +201 -0
  110. package/lib/code/terminal-view.jsx +224 -0
  111. package/lib/code/ws-proxy.js +80 -0
  112. package/lib/cron.js +246 -0
  113. package/lib/db/api-keys.js +163 -0
  114. package/lib/db/chats.js +168 -0
  115. package/lib/db/code-workspaces.js +110 -0
  116. package/lib/db/index.js +52 -0
  117. package/lib/db/notifications.js +99 -0
  118. package/lib/db/schema.js +66 -0
  119. package/lib/db/update-check.js +96 -0
  120. package/lib/db/users.js +89 -0
  121. package/lib/paths.js +42 -0
  122. package/lib/tools/create-job.js +97 -0
  123. package/lib/tools/docker.js +146 -0
  124. package/lib/tools/github.js +271 -0
  125. package/lib/tools/openai.js +35 -0
  126. package/lib/tools/telegram.js +292 -0
  127. package/lib/triggers.js +104 -0
  128. package/lib/utils/render-md.js +111 -0
  129. package/package.json +118 -0
  130. package/setup/lib/auth.mjs +81 -0
  131. package/setup/lib/env.mjs +21 -0
  132. package/setup/lib/fs-utils.mjs +20 -0
  133. package/setup/lib/github.mjs +149 -0
  134. package/setup/lib/prerequisites.mjs +155 -0
  135. package/setup/lib/prompts.mjs +267 -0
  136. package/setup/lib/providers.mjs +105 -0
  137. package/setup/lib/sync.mjs +125 -0
  138. package/setup/lib/targets.mjs +45 -0
  139. package/setup/lib/telegram-verify.mjs +63 -0
  140. package/setup/lib/telegram.mjs +76 -0
  141. package/setup/setup-cloud.mjs +833 -0
  142. package/setup/setup-local.mjs +377 -0
  143. package/setup/setup-telegram.mjs +265 -0
  144. package/setup/setup.mjs +87 -0
  145. package/templates/.dockerignore +5 -0
  146. package/templates/.env.example +104 -0
  147. package/templates/.github/workflows/auto-merge.yml +117 -0
  148. package/templates/.github/workflows/notify-job-failed.yml +64 -0
  149. package/templates/.github/workflows/notify-pr-complete.yml +119 -0
  150. package/templates/.github/workflows/rebuild-event-handler.yml +121 -0
  151. package/templates/.github/workflows/run-job.yml +89 -0
  152. package/templates/.github/workflows/upgrade-event-handler.yml +62 -0
  153. package/templates/.gitignore.template +45 -0
  154. package/templates/.pi/extensions/env-sanitizer/index.ts +48 -0
  155. package/templates/.pi/extensions/env-sanitizer/package.json +5 -0
  156. package/templates/CLAUDE.md +29 -0
  157. package/templates/CLAUDE.md.template +308 -0
  158. package/templates/app/api/[...gigaclaw]/route.js +1 -0
  159. package/templates/app/api/auth/[...nextauth]/route.js +1 -0
  160. package/templates/app/chat/[chatId]/page.js +9 -0
  161. package/templates/app/chats/page.js +7 -0
  162. package/templates/app/code/[codeWorkspaceId]/page.js +9 -0
  163. package/templates/app/components/ascii-logo.jsx +12 -0
  164. package/templates/app/components/login-form.jsx +92 -0
  165. package/templates/app/components/setup-form.jsx +82 -0
  166. package/templates/app/components/theme-provider.jsx +11 -0
  167. package/templates/app/components/theme-toggle.jsx +38 -0
  168. package/templates/app/components/ui/button.jsx +21 -0
  169. package/templates/app/components/ui/card.jsx +23 -0
  170. package/templates/app/components/ui/input.jsx +10 -0
  171. package/templates/app/components/ui/label.jsx +10 -0
  172. package/templates/app/crons/page.js +5 -0
  173. package/templates/app/globals.css +90 -0
  174. package/templates/app/layout.js +33 -0
  175. package/templates/app/login/page.js +15 -0
  176. package/templates/app/notifications/page.js +7 -0
  177. package/templates/app/page.js +7 -0
  178. package/templates/app/pull-requests/page.js +7 -0
  179. package/templates/app/settings/crons/page.js +5 -0
  180. package/templates/app/settings/layout.js +7 -0
  181. package/templates/app/settings/page.js +5 -0
  182. package/templates/app/settings/secrets/page.js +5 -0
  183. package/templates/app/settings/triggers/page.js +5 -0
  184. package/templates/app/stream/chat/route.js +1 -0
  185. package/templates/app/swarm/page.js +7 -0
  186. package/templates/app/triggers/page.js +5 -0
  187. package/templates/config/CODE_PLANNING.md +14 -0
  188. package/templates/config/CRONS.json +56 -0
  189. package/templates/config/HEARTBEAT.md +3 -0
  190. package/templates/config/JOB_AGENT.md +30 -0
  191. package/templates/config/JOB_PLANNING.md +240 -0
  192. package/templates/config/JOB_SUMMARY.md +130 -0
  193. package/templates/config/SKILL_BUILDING_GUIDE.md +96 -0
  194. package/templates/config/SOUL.md +48 -0
  195. package/templates/config/TRIGGERS.json +58 -0
  196. package/templates/config/WEB_SEARCH_AVAILABLE.md +5 -0
  197. package/templates/config/WEB_SEARCH_UNAVAILABLE.md +3 -0
  198. package/templates/docker/claude-code-job/Dockerfile +34 -0
  199. package/templates/docker/claude-code-job/entrypoint.sh +149 -0
  200. package/templates/docker/claude-code-workspace/.tmux.conf +5 -0
  201. package/templates/docker/claude-code-workspace/Dockerfile +61 -0
  202. package/templates/docker/claude-code-workspace/entrypoint.sh +51 -0
  203. package/templates/docker/event-handler/Dockerfile +20 -0
  204. package/templates/docker/event-handler/ecosystem.config.cjs +7 -0
  205. package/templates/docker/pi-coding-agent-job/Dockerfile +51 -0
  206. package/templates/docker/pi-coding-agent-job/entrypoint.sh +164 -0
  207. package/templates/docker-compose.local.yml +78 -0
  208. package/templates/docker-compose.yml +64 -0
  209. package/templates/instrumentation.js +6 -0
  210. package/templates/middleware.js +23 -0
  211. package/templates/next.config.mjs +3 -0
  212. package/templates/postcss.config.mjs +5 -0
  213. package/templates/public/favicon.ico +0 -0
  214. package/templates/server.js +25 -0
  215. package/templates/skills/LICENSE +21 -0
  216. package/templates/skills/README.md +119 -0
  217. package/templates/skills/brave-search/SKILL.md +79 -0
  218. package/templates/skills/brave-search/content.js +86 -0
  219. package/templates/skills/brave-search/package-lock.json +621 -0
  220. package/templates/skills/brave-search/package.json +14 -0
  221. package/templates/skills/brave-search/search.js +199 -0
  222. package/templates/skills/browser-tools/SKILL.md +196 -0
  223. package/templates/skills/browser-tools/browser-content.js +103 -0
  224. package/templates/skills/browser-tools/browser-cookies.js +35 -0
  225. package/templates/skills/browser-tools/browser-eval.js +53 -0
  226. package/templates/skills/browser-tools/browser-hn-scraper.js +108 -0
  227. package/templates/skills/browser-tools/browser-nav.js +44 -0
  228. package/templates/skills/browser-tools/browser-pick.js +162 -0
  229. package/templates/skills/browser-tools/browser-screenshot.js +34 -0
  230. package/templates/skills/browser-tools/browser-start.js +87 -0
  231. package/templates/skills/browser-tools/package-lock.json +2556 -0
  232. package/templates/skills/browser-tools/package.json +19 -0
  233. package/templates/skills/google-docs/SKILL.md +23 -0
  234. package/templates/skills/google-docs/create.sh +69 -0
  235. package/templates/skills/google-drive/SKILL.md +47 -0
  236. package/templates/skills/google-drive/delete.sh +47 -0
  237. package/templates/skills/google-drive/download.sh +50 -0
  238. package/templates/skills/google-drive/list.sh +41 -0
  239. package/templates/skills/google-drive/upload.sh +76 -0
  240. package/templates/skills/kie-ai/SKILL.md +38 -0
  241. package/templates/skills/kie-ai/generate-image.sh +77 -0
  242. package/templates/skills/kie-ai/generate-video.sh +69 -0
  243. package/templates/skills/llm-secrets/SKILL.md +34 -0
  244. package/templates/skills/llm-secrets/llm-secrets.js +33 -0
  245. package/templates/skills/modify-self/SKILL.md +12 -0
  246. package/templates/skills/youtube-transcript/SKILL.md +41 -0
  247. package/templates/skills/youtube-transcript/package-lock.json +24 -0
  248. package/templates/skills/youtube-transcript/package.json +8 -0
  249. package/templates/skills/youtube-transcript/transcript.js +84 -0
package/bin/local.sh ADDED
@@ -0,0 +1,85 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ if [ -z "$1" ]; then
5
+ echo "Usage: local.sh <path-to-project>"
6
+ exit 1
7
+ fi
8
+
9
+ PACKAGE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
10
+ TARGET_DIR="$(cd "$1" && pwd)"
11
+ DEST="$TARGET_DIR/node_modules/gigaclaw"
12
+
13
+ if [ ! -d "$DEST" ]; then
14
+ echo "Error: gigaclaw not found in $TARGET_DIR/node_modules/"
15
+ exit 1
16
+ fi
17
+
18
+ # 1. Sync templates → project root
19
+ # - exclude *.template files (handled separately below with rename)
20
+ # - exclude bare CLAUDE.md (matches init's EXCLUDED_FILENAMES)
21
+ echo "Syncing templates to project..."
22
+ rsync -av "$PACKAGE_DIR/templates/" "$TARGET_DIR/" \
23
+ --exclude '*.template' \
24
+ --exclude 'CLAUDE.md'
25
+
26
+ # Handle .template files (strip suffix on copy)
27
+ cp "$PACKAGE_DIR/templates/.gitignore.template" "$TARGET_DIR/.gitignore"
28
+ cp "$PACKAGE_DIR/templates/CLAUDE.md.template" "$TARGET_DIR/CLAUDE.md"
29
+
30
+ # 2. Sync package runtime → node_modules/gigaclaw
31
+ echo "Syncing package to node_modules..."
32
+ rsync -av --delete "$PACKAGE_DIR/lib/" "$DEST/lib/"
33
+ rsync -av --delete "$PACKAGE_DIR/api/" "$DEST/api/"
34
+ rsync -av --delete "$PACKAGE_DIR/config/" "$DEST/config/"
35
+ rsync -av --delete "$PACKAGE_DIR/bin/" "$DEST/bin/"
36
+ rsync -av --delete "$PACKAGE_DIR/setup/" "$DEST/setup/"
37
+ rsync -av --delete "$PACKAGE_DIR/drizzle/" "$DEST/drizzle/"
38
+ rsync -av --delete "$PACKAGE_DIR/templates/" "$DEST/templates/"
39
+ cp "$PACKAGE_DIR/package.json" "$DEST/package.json"
40
+
41
+ # 3. Build JSX (esbuild is in source repo, compile all .jsx files in destination)
42
+ echo "Building JSX..."
43
+ find "$DEST/lib" -name '*.jsx' -print0 | while IFS= read -r -d '' file; do
44
+ outdir="$(dirname "$file")"
45
+ "$PACKAGE_DIR/node_modules/.bin/esbuild" "$file" \
46
+ --outdir="$outdir" --format=esm --jsx=automatic
47
+ done
48
+
49
+ # 4. Install any dependencies from gigaclaw that aren't in the target yet
50
+ echo "Checking for missing dependencies..."
51
+ MISSING=$(node -e "
52
+ const fs = require('fs');
53
+ const path = require('path');
54
+ const pkg = JSON.parse(fs.readFileSync('$DEST/package.json', 'utf8'));
55
+ const missing = [];
56
+ for (const [name, ver] of Object.entries(pkg.dependencies || {})) {
57
+ if (!fs.existsSync(path.join('$TARGET_DIR', 'node_modules', name))) missing.push(name + '@' + ver);
58
+ }
59
+ if (missing.length) console.log(missing.join(' '));
60
+ ")
61
+ if [ -n "$MISSING" ]; then
62
+ echo "Installing missing dependencies: $MISSING"
63
+ cd "$TARGET_DIR" && npm install $MISSING
64
+ else
65
+ echo "All dependencies present."
66
+ fi
67
+
68
+ # 5. Clear .next cache and rebuild
69
+ echo "Clearing .next cache..."
70
+ rm -rf "$TARGET_DIR/.next"
71
+
72
+ echo "Rebuilding..."
73
+ cd "$TARGET_DIR" && npm run build
74
+
75
+ # 6. Restart the server
76
+ if [ -f "$TARGET_DIR/docker-compose.yml" ] && docker compose version &>/dev/null; then
77
+ echo "Restarting Docker container..."
78
+ cd "$TARGET_DIR" && docker compose restart event-handler
79
+ elif pgrep -f "next-server.*$TARGET_DIR" &>/dev/null; then
80
+ echo "Restarting Next.js server..."
81
+ pkill -f "next-server.*$TARGET_DIR"
82
+ cd "$TARGET_DIR" && npm start &
83
+ fi
84
+
85
+ echo "Done!"
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ // postinstall runs from the package dir inside node_modules.
11
+ // The user's project root is two levels up: node_modules/gigaclaw/ -> project root
12
+ const projectRoot = path.resolve(__dirname, '..', '..', '..');
13
+ const templatesDir = path.join(__dirname, '..', 'templates');
14
+
15
+ // Skip if templates dir doesn't exist (shouldn't happen, but be safe)
16
+ if (!fs.existsSync(templatesDir)) process.exit(0);
17
+
18
+ // Skip if this doesn't look like a user project (no package.json with gigaclaw dep)
19
+ const pkgPath = path.join(projectRoot, 'package.json');
20
+ if (!fs.existsSync(pkgPath)) process.exit(0);
21
+ try {
22
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
23
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
24
+ if (!deps || !deps.gigaclaw) process.exit(0);
25
+ } catch { process.exit(0); }
26
+
27
+ function walk(dir) {
28
+ const files = [];
29
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
30
+ for (const entry of entries) {
31
+ const fullPath = path.join(dir, entry.name);
32
+ if (entry.isDirectory()) {
33
+ files.push(...walk(fullPath));
34
+ } else {
35
+ files.push(path.relative(templatesDir, fullPath));
36
+ }
37
+ }
38
+ return files;
39
+ }
40
+
41
+ const changed = [];
42
+ for (const relPath of walk(templatesDir)) {
43
+ const src = path.join(templatesDir, relPath);
44
+ const dest = path.join(projectRoot, relPath);
45
+ if (fs.existsSync(dest)) {
46
+ const srcContent = fs.readFileSync(src);
47
+ const destContent = fs.readFileSync(dest);
48
+ if (!srcContent.equals(destContent)) {
49
+ changed.push(relPath);
50
+ }
51
+ }
52
+ }
53
+
54
+ if (changed.length > 0) {
55
+ console.log('\n gigaclaw: these project files differ from the latest package templates.');
56
+ console.log(' This is normal if you\'ve customized them. If gigaclaw was just');
57
+ console.log(' updated, new defaults may be available.\n');
58
+ for (const file of changed) {
59
+ console.log(` ${file}`);
60
+ }
61
+ console.log('\n To compare: npx gigaclaw diff <file>');
62
+ console.log(' To restore: npx gigaclaw reset <file>\n');
63
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Next.js config wrapper for gigaclaw.
3
+ * Enables instrumentation hook for cron scheduling on server start.
4
+ *
5
+ * Usage in user's next.config.mjs:
6
+ * import { withGigaclaw } from 'gigaclaw/config';
7
+ * export default withGigaclaw({});
8
+ *
9
+ * @param {Object} nextConfig - User's Next.js config
10
+ * @returns {Object} Enhanced Next.js config
11
+ */
12
+ export function withGigaclaw(nextConfig = {}) {
13
+ return {
14
+ ...nextConfig,
15
+ distDir: process.env.NEXT_BUILD_DIR || '.next',
16
+ env: {
17
+ ...nextConfig.env,
18
+ NEXT_PUBLIC_CODE_WORKSPACE: process.env.CLAUDE_CODE_OAUTH_TOKEN && process.env.BETA ? 'true' : '',
19
+ },
20
+ serverExternalPackages: [
21
+ ...(nextConfig.serverExternalPackages || []),
22
+ 'better-sqlite3',
23
+ 'drizzle-orm',
24
+ ],
25
+ };
26
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Next.js instrumentation hook for gigaclaw.
3
+ * This file is loaded by Next.js on server start when instrumentationHook is enabled.
4
+ *
5
+ * Users should create an instrumentation.js in their project root that imports this:
6
+ *
7
+ * export { register } from 'gigaclaw/instrumentation';
8
+ *
9
+ * Or they can re-export and add their own logic.
10
+ */
11
+
12
+ let initialized = false;
13
+
14
+ export async function register() {
15
+ // Only run on the server, and only once
16
+ if (typeof window !== 'undefined' || initialized) return;
17
+ initialized = true;
18
+
19
+ // Skip database init and cron scheduling during `next build` —
20
+ // these are runtime-only concerns that keep the event loop alive
21
+ // and can cause build output corruption.
22
+ if (process.argv.includes('build')) return;
23
+
24
+ // Load .env from project root
25
+ const dotenv = await import('dotenv');
26
+ dotenv.config();
27
+
28
+ // Set AUTH_URL from APP_URL so NextAuth redirects to the correct host (e.g., on sign-out)
29
+ if (process.env.APP_URL && !process.env.AUTH_URL) {
30
+ process.env.AUTH_URL = process.env.APP_URL;
31
+ }
32
+
33
+ // Validate AUTH_SECRET is set (required by Auth.js for session encryption)
34
+ if (!process.env.AUTH_SECRET) {
35
+ console.error('\n ERROR: AUTH_SECRET is not set in your .env file.');
36
+ console.error(' This is required for session encryption.');
37
+ console.error(' Run "npm run setup" to generate it automatically, or add manually:');
38
+ console.error(' openssl rand -base64 32\n');
39
+ throw new Error('AUTH_SECRET environment variable is required');
40
+ }
41
+
42
+ // Initialize auth database
43
+ const { initDatabase } = await import('../lib/db/index.js');
44
+ initDatabase();
45
+
46
+ // Start cron scheduler
47
+ const { loadCrons } = await import('../lib/cron.js');
48
+ loadCrons();
49
+
50
+ // Start built-in crons (version check)
51
+ const { startBuiltinCrons, setUpdateAvailable } = await import('../lib/cron.js');
52
+ startBuiltinCrons();
53
+
54
+ // Warm in-memory flag from DB (covers the window before the async cron fetch completes)
55
+ try {
56
+ const { getAvailableVersion } = await import('../lib/db/update-check.js');
57
+ const stored = getAvailableVersion();
58
+ if (stored) setUpdateAvailable(stored);
59
+ } catch {}
60
+
61
+ console.log('gigaclaw initialized');
62
+ }
@@ -0,0 +1,52 @@
1
+ CREATE TABLE `chats` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `user_id` text NOT NULL,
4
+ `title` text DEFAULT 'New Chat' NOT NULL,
5
+ `starred` integer DEFAULT 0 NOT NULL,
6
+ `created_at` integer NOT NULL,
7
+ `updated_at` integer NOT NULL
8
+ );
9
+ --> statement-breakpoint
10
+ CREATE TABLE `messages` (
11
+ `id` text PRIMARY KEY NOT NULL,
12
+ `chat_id` text NOT NULL,
13
+ `role` text NOT NULL,
14
+ `content` text NOT NULL,
15
+ `created_at` integer NOT NULL
16
+ );
17
+ --> statement-breakpoint
18
+ CREATE TABLE `notifications` (
19
+ `id` text PRIMARY KEY NOT NULL,
20
+ `notification` text NOT NULL,
21
+ `payload` text NOT NULL,
22
+ `read` integer DEFAULT 0 NOT NULL,
23
+ `created_at` integer NOT NULL
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE TABLE `settings` (
27
+ `id` text PRIMARY KEY NOT NULL,
28
+ `type` text NOT NULL,
29
+ `key` text NOT NULL,
30
+ `value` text NOT NULL,
31
+ `created_by` text,
32
+ `created_at` integer NOT NULL,
33
+ `updated_at` integer NOT NULL
34
+ );
35
+ --> statement-breakpoint
36
+ CREATE TABLE `subscriptions` (
37
+ `id` text PRIMARY KEY NOT NULL,
38
+ `platform` text NOT NULL,
39
+ `channel_id` text NOT NULL,
40
+ `created_at` integer NOT NULL
41
+ );
42
+ --> statement-breakpoint
43
+ CREATE TABLE `users` (
44
+ `id` text PRIMARY KEY NOT NULL,
45
+ `email` text NOT NULL,
46
+ `password_hash` text NOT NULL,
47
+ `role` text DEFAULT 'admin' NOT NULL,
48
+ `created_at` integer NOT NULL,
49
+ `updated_at` integer NOT NULL
50
+ );
51
+ --> statement-breakpoint
52
+ CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);
@@ -0,0 +1,11 @@
1
+ CREATE TABLE `claude_workspaces` (
2
+ `id` text PRIMARY KEY NOT NULL,
3
+ `user_id` text NOT NULL,
4
+ `container_name` text NOT NULL,
5
+ `title` text DEFAULT 'Claude Workspace' NOT NULL,
6
+ `starred` integer DEFAULT 0 NOT NULL,
7
+ `created_at` integer NOT NULL,
8
+ `updated_at` integer NOT NULL
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE UNIQUE INDEX `claude_workspaces_container_name_unique` ON `claude_workspaces` (`container_name`);
@@ -0,0 +1,19 @@
1
+ PRAGMA foreign_keys=OFF;--> statement-breakpoint
2
+ CREATE TABLE `__new_claude_workspaces` (
3
+ `id` text PRIMARY KEY NOT NULL,
4
+ `user_id` text NOT NULL,
5
+ `container_name` text,
6
+ `repo` text,
7
+ `branch` text,
8
+ `title` text DEFAULT 'Claude Workspace' NOT NULL,
9
+ `starred` integer DEFAULT 0 NOT NULL,
10
+ `created_at` integer NOT NULL,
11
+ `updated_at` integer NOT NULL
12
+ );
13
+ --> statement-breakpoint
14
+ INSERT INTO `__new_claude_workspaces`("id", "user_id", "container_name", "repo", "branch", "title", "starred", "created_at", "updated_at") SELECT "id", "user_id", "container_name", NULL, NULL, "title", "starred", "created_at", "updated_at" FROM `claude_workspaces`;--> statement-breakpoint
15
+ DROP TABLE `claude_workspaces`;--> statement-breakpoint
16
+ ALTER TABLE `__new_claude_workspaces` RENAME TO `claude_workspaces`;--> statement-breakpoint
17
+ PRAGMA foreign_keys=ON;--> statement-breakpoint
18
+ CREATE UNIQUE INDEX `claude_workspaces_container_name_unique` ON `claude_workspaces` (`container_name`);--> statement-breakpoint
19
+ ALTER TABLE `chats` ADD `claude_workspace_id` text;
@@ -0,0 +1,5 @@
1
+ ALTER TABLE `claude_workspaces` RENAME TO `code_workspaces`;--> statement-breakpoint
2
+ DROP INDEX IF EXISTS `claude_workspaces_container_name_unique`;--> statement-breakpoint
3
+ CREATE UNIQUE INDEX `code_workspaces_container_name_unique` ON `code_workspaces` (`container_name`);--> statement-breakpoint
4
+ ALTER TABLE `code_workspaces` ADD `coding_agent` text NOT NULL DEFAULT 'claude-code';--> statement-breakpoint
5
+ ALTER TABLE `chats` RENAME COLUMN `claude_workspace_id` TO `code_workspace_id`;
@@ -0,0 +1,321 @@
1
+ {
2
+ "version": "6",
3
+ "dialect": "sqlite",
4
+ "id": "3312cdb9-4f3b-4004-921b-d6598d2eb2a1",
5
+ "prevId": "00000000-0000-0000-0000-000000000000",
6
+ "tables": {
7
+ "chats": {
8
+ "name": "chats",
9
+ "columns": {
10
+ "id": {
11
+ "name": "id",
12
+ "type": "text",
13
+ "primaryKey": true,
14
+ "notNull": true,
15
+ "autoincrement": false
16
+ },
17
+ "user_id": {
18
+ "name": "user_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true,
22
+ "autoincrement": false
23
+ },
24
+ "title": {
25
+ "name": "title",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true,
29
+ "autoincrement": false,
30
+ "default": "'New Chat'"
31
+ },
32
+ "starred": {
33
+ "name": "starred",
34
+ "type": "integer",
35
+ "primaryKey": false,
36
+ "notNull": true,
37
+ "autoincrement": false,
38
+ "default": 0
39
+ },
40
+ "created_at": {
41
+ "name": "created_at",
42
+ "type": "integer",
43
+ "primaryKey": false,
44
+ "notNull": true,
45
+ "autoincrement": false
46
+ },
47
+ "updated_at": {
48
+ "name": "updated_at",
49
+ "type": "integer",
50
+ "primaryKey": false,
51
+ "notNull": true,
52
+ "autoincrement": false
53
+ }
54
+ },
55
+ "indexes": {},
56
+ "foreignKeys": {},
57
+ "compositePrimaryKeys": {},
58
+ "uniqueConstraints": {},
59
+ "checkConstraints": {}
60
+ },
61
+ "messages": {
62
+ "name": "messages",
63
+ "columns": {
64
+ "id": {
65
+ "name": "id",
66
+ "type": "text",
67
+ "primaryKey": true,
68
+ "notNull": true,
69
+ "autoincrement": false
70
+ },
71
+ "chat_id": {
72
+ "name": "chat_id",
73
+ "type": "text",
74
+ "primaryKey": false,
75
+ "notNull": true,
76
+ "autoincrement": false
77
+ },
78
+ "role": {
79
+ "name": "role",
80
+ "type": "text",
81
+ "primaryKey": false,
82
+ "notNull": true,
83
+ "autoincrement": false
84
+ },
85
+ "content": {
86
+ "name": "content",
87
+ "type": "text",
88
+ "primaryKey": false,
89
+ "notNull": true,
90
+ "autoincrement": false
91
+ },
92
+ "created_at": {
93
+ "name": "created_at",
94
+ "type": "integer",
95
+ "primaryKey": false,
96
+ "notNull": true,
97
+ "autoincrement": false
98
+ }
99
+ },
100
+ "indexes": {},
101
+ "foreignKeys": {},
102
+ "compositePrimaryKeys": {},
103
+ "uniqueConstraints": {},
104
+ "checkConstraints": {}
105
+ },
106
+ "notifications": {
107
+ "name": "notifications",
108
+ "columns": {
109
+ "id": {
110
+ "name": "id",
111
+ "type": "text",
112
+ "primaryKey": true,
113
+ "notNull": true,
114
+ "autoincrement": false
115
+ },
116
+ "notification": {
117
+ "name": "notification",
118
+ "type": "text",
119
+ "primaryKey": false,
120
+ "notNull": true,
121
+ "autoincrement": false
122
+ },
123
+ "payload": {
124
+ "name": "payload",
125
+ "type": "text",
126
+ "primaryKey": false,
127
+ "notNull": true,
128
+ "autoincrement": false
129
+ },
130
+ "read": {
131
+ "name": "read",
132
+ "type": "integer",
133
+ "primaryKey": false,
134
+ "notNull": true,
135
+ "autoincrement": false,
136
+ "default": 0
137
+ },
138
+ "created_at": {
139
+ "name": "created_at",
140
+ "type": "integer",
141
+ "primaryKey": false,
142
+ "notNull": true,
143
+ "autoincrement": false
144
+ }
145
+ },
146
+ "indexes": {},
147
+ "foreignKeys": {},
148
+ "compositePrimaryKeys": {},
149
+ "uniqueConstraints": {},
150
+ "checkConstraints": {}
151
+ },
152
+ "settings": {
153
+ "name": "settings",
154
+ "columns": {
155
+ "id": {
156
+ "name": "id",
157
+ "type": "text",
158
+ "primaryKey": true,
159
+ "notNull": true,
160
+ "autoincrement": false
161
+ },
162
+ "type": {
163
+ "name": "type",
164
+ "type": "text",
165
+ "primaryKey": false,
166
+ "notNull": true,
167
+ "autoincrement": false
168
+ },
169
+ "key": {
170
+ "name": "key",
171
+ "type": "text",
172
+ "primaryKey": false,
173
+ "notNull": true,
174
+ "autoincrement": false
175
+ },
176
+ "value": {
177
+ "name": "value",
178
+ "type": "text",
179
+ "primaryKey": false,
180
+ "notNull": true,
181
+ "autoincrement": false
182
+ },
183
+ "created_by": {
184
+ "name": "created_by",
185
+ "type": "text",
186
+ "primaryKey": false,
187
+ "notNull": false,
188
+ "autoincrement": false
189
+ },
190
+ "created_at": {
191
+ "name": "created_at",
192
+ "type": "integer",
193
+ "primaryKey": false,
194
+ "notNull": true,
195
+ "autoincrement": false
196
+ },
197
+ "updated_at": {
198
+ "name": "updated_at",
199
+ "type": "integer",
200
+ "primaryKey": false,
201
+ "notNull": true,
202
+ "autoincrement": false
203
+ }
204
+ },
205
+ "indexes": {},
206
+ "foreignKeys": {},
207
+ "compositePrimaryKeys": {},
208
+ "uniqueConstraints": {},
209
+ "checkConstraints": {}
210
+ },
211
+ "subscriptions": {
212
+ "name": "subscriptions",
213
+ "columns": {
214
+ "id": {
215
+ "name": "id",
216
+ "type": "text",
217
+ "primaryKey": true,
218
+ "notNull": true,
219
+ "autoincrement": false
220
+ },
221
+ "platform": {
222
+ "name": "platform",
223
+ "type": "text",
224
+ "primaryKey": false,
225
+ "notNull": true,
226
+ "autoincrement": false
227
+ },
228
+ "channel_id": {
229
+ "name": "channel_id",
230
+ "type": "text",
231
+ "primaryKey": false,
232
+ "notNull": true,
233
+ "autoincrement": false
234
+ },
235
+ "created_at": {
236
+ "name": "created_at",
237
+ "type": "integer",
238
+ "primaryKey": false,
239
+ "notNull": true,
240
+ "autoincrement": false
241
+ }
242
+ },
243
+ "indexes": {},
244
+ "foreignKeys": {},
245
+ "compositePrimaryKeys": {},
246
+ "uniqueConstraints": {},
247
+ "checkConstraints": {}
248
+ },
249
+ "users": {
250
+ "name": "users",
251
+ "columns": {
252
+ "id": {
253
+ "name": "id",
254
+ "type": "text",
255
+ "primaryKey": true,
256
+ "notNull": true,
257
+ "autoincrement": false
258
+ },
259
+ "email": {
260
+ "name": "email",
261
+ "type": "text",
262
+ "primaryKey": false,
263
+ "notNull": true,
264
+ "autoincrement": false
265
+ },
266
+ "password_hash": {
267
+ "name": "password_hash",
268
+ "type": "text",
269
+ "primaryKey": false,
270
+ "notNull": true,
271
+ "autoincrement": false
272
+ },
273
+ "role": {
274
+ "name": "role",
275
+ "type": "text",
276
+ "primaryKey": false,
277
+ "notNull": true,
278
+ "autoincrement": false,
279
+ "default": "'admin'"
280
+ },
281
+ "created_at": {
282
+ "name": "created_at",
283
+ "type": "integer",
284
+ "primaryKey": false,
285
+ "notNull": true,
286
+ "autoincrement": false
287
+ },
288
+ "updated_at": {
289
+ "name": "updated_at",
290
+ "type": "integer",
291
+ "primaryKey": false,
292
+ "notNull": true,
293
+ "autoincrement": false
294
+ }
295
+ },
296
+ "indexes": {
297
+ "users_email_unique": {
298
+ "name": "users_email_unique",
299
+ "columns": [
300
+ "email"
301
+ ],
302
+ "isUnique": true
303
+ }
304
+ },
305
+ "foreignKeys": {},
306
+ "compositePrimaryKeys": {},
307
+ "uniqueConstraints": {},
308
+ "checkConstraints": {}
309
+ }
310
+ },
311
+ "views": {},
312
+ "enums": {},
313
+ "_meta": {
314
+ "schemas": {},
315
+ "tables": {},
316
+ "columns": {}
317
+ },
318
+ "internal": {
319
+ "indexes": {}
320
+ }
321
+ }