Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.blink/data/
.blink/
**/*.hbs
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ agent.on("request", async (request, context) => {
agent.serve();
```

Locally, all chats are stored in `./data/chats/<key>.json` relative to where your agent is running.
Locally, all chats are stored in `./.blink/chats/<key>.json` relative to where your agent is running.

In the cloud, chats keys are namespaced per-agent.

Expand Down Expand Up @@ -174,7 +174,7 @@ agent.on("chat", async ({ messages }) => {
agent.serve();
```

Locally, all storage is in `./data/storage.json` relative to where your agent is running.
Locally, all storage is in `./.blink/storage.json` relative to where your agent is running.

In the cloud, storage is namespaced per-agent.

Expand Down
4 changes: 2 additions & 2 deletions packages/blink/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Config {

/**
* outdir is the directory to write the build output to.
* Defaults to `data/build` in the current working directory.
* Defaults to `.blink/build` in the current working directory.
*/
outdir?: string;

Expand Down Expand Up @@ -111,7 +111,7 @@ Try creating "agent.ts" or specify "entry" in a blink.config.ts file.`);
}
}
if (!config.outdir) {
config.outdir = path.resolve(directory, "data/build");
config.outdir = path.resolve(directory, ".blink/build");
}
if (!config.build) {
// By default, we bundle with esbuild.
Expand Down
12 changes: 6 additions & 6 deletions packages/blink/src/cli/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Client, {
import { stat, readFile } from "node:fs/promises";
import { basename, dirname, join, relative } from "node:path";
import { loginIfNeeded } from "./lib/auth";
import { migrateBlinkToData } from "./lib/migrate";
import { migrateDataToBlink } from "./lib/migrate";
import { existsSync } from "node:fs";
import { mkdir, writeFile, readdir } from "fs/promises";
import { select, confirm, isCancel, spinner } from "@clack/prompts";
Expand All @@ -26,8 +26,8 @@ export default async function deploy(
directory = process.cwd();
}

// Auto-migrate .blink to data if it exists
await migrateBlinkToData(directory);
// Auto-migrate data to .blink if it exists
await migrateDataToBlink(directory);

const token = await loginIfNeeded();
const client = new Client({
Expand All @@ -54,8 +54,8 @@ export default async function deploy(
// Find the nearest config file if it exists.
const rootDirectory = dirname(packageJSON);

// Check for a data directory. This stores the agent's deploy config.
const deployConfigPath = join(rootDirectory, "data", "config.json");
// Check for a .blink directory. This stores the agent's deploy config.
const deployConfigPath = join(rootDirectory, ".blink", "config.json");

let deployConfig: DeployConfig = {};
if (existsSync(deployConfigPath)) {
Expand Down Expand Up @@ -549,7 +549,7 @@ async function collectSourceFiles(rootDir: string): Promise<string[]> {
const defaultIgnorePatterns = [
".git",
"node_modules",
"data",
".blink",
".env",
".env.*",
];
Expand Down
9 changes: 4 additions & 5 deletions packages/blink/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolveConfig } from "../build/index";
import { findNearestEntry } from "../build/util";
import { startDev } from "../tui/dev";
import { getAuthToken } from "./lib/auth";
import { migrateBlinkToData } from "./lib/migrate";
import { migrateDataToBlink } from "./lib/migrate";

export default async function dev(directory?: string): Promise<void> {
if (!directory) {
Expand All @@ -19,7 +19,7 @@ export default async function dev(directory?: string): Promise<void> {
// No agent found in current directory, search upward for .blink
let dotBlinkPath = await findNearestEntry(cwd, ".blink");

// This is legacy behavior to migrate old Blink directories to the new data/ directory.
// This is legacy behavior to migrate old Blink directories to the new .blink/ directory.
if (dotBlinkPath && existsSync(join(dotBlinkPath, "build"))) {
dotBlinkPath = undefined;
}
Expand All @@ -32,9 +32,8 @@ export default async function dev(directory?: string): Promise<void> {
}
}
}

// Auto-migrate .blink to data if it exists
await migrateBlinkToData(directory);
// Auto-migrate data/ to .blink/ if it exists
await migrateDataToBlink(directory);

const exitWithDump = (error: Error) => {
writeFileSync("error.dump", inspect(error, { depth: null }));
Expand Down
24 changes: 12 additions & 12 deletions packages/blink/src/cli/init-templates/index.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/blink/src/cli/init-templates/scratch/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules

# config and build
data
.blink

# dotenv environment variables file
.env
Expand Down
2 changes: 1 addition & 1 deletion packages/blink/src/cli/init-templates/slack-bot/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules

# config and build
data
.blink

# dotenv environment variables file
.env
Expand Down
2 changes: 1 addition & 1 deletion packages/blink/src/cli/lib/devhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { dirname, join } from "path";
* Gets the path to the devhook ID file.
*/
export function getDevhookPath(directory: string): string {
return join(directory, "data", "devhook.txt");
return join(directory, ".blink", "devhook.txt");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/blink/src/cli/lib/first-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { dirname, join } from "path";
* @returns true if this is the first time, false otherwise
*/
export function checkAndMarkFirstRun(directory: string): boolean {
const storagePath = join(directory, "data", ".first-run");
const storagePath = join(directory, ".blink", ".first-run");
mkdirSync(dirname(storagePath), { recursive: true });

if (existsSync(storagePath)) {
Expand Down
89 changes: 32 additions & 57 deletions packages/blink/src/cli/lib/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,63 @@ import { join } from "path";
import chalk from "chalk";

/**
* Automatically migrates .blink/ to data/ if it exists.
* Automatically migrates data/ to .blink/ if it exists.
* This helps users transition from the old directory structure.
*/
export async function migrateBlinkToData(directory: string): Promise<void> {
const oldPath = join(directory, ".blink");
const newPath = join(directory, "data");
export async function migrateDataToBlink(directory: string): Promise<void> {
const oldPath = join(directory, "data");
const newPath = join(directory, ".blink");

// Check if .blink exists and data doesn't
// Check if data exists and .blink doesn't
if (!existsSync(oldPath) || existsSync(newPath)) {
return;
}

// Check if .blink/data/ exists (old nested structure)
const oldNestedDataPath = join(oldPath, "data");
const hasNestedData = existsSync(oldNestedDataPath);
// Check if data contains any data files (chats, storage, config, devhook, .first-run)
const hasData =
existsSync(join(oldPath, "chats")) ||
existsSync(join(oldPath, "storage.json")) ||
existsSync(join(oldPath, "config.json")) ||
existsSync(join(oldPath, "devhook.txt")) ||
existsSync(join(oldPath, "devhook")) ||
existsSync(join(oldPath, ".first-run"));

if (hasNestedData) {
// Old structure: .blink/data/chats → data/chats
console.log(chalk.yellow("Migrating .blink/data/ to data/..."));
await rename(oldNestedDataPath, newPath);

// Move any remaining files from .blink/ into data/
const remainingFiles = readdirSync(oldPath);
for (const file of remainingFiles) {
const srcPath = join(oldPath, file);
const destPath = join(newPath, file);
if (!existsSync(destPath)) {
await rename(srcPath, destPath);
}
}

// Remove empty .blink directory
await rm(oldPath, { recursive: true, force: true });
} else {
// Check if .blink contains any data files directly (build, chats, storage, config, devhook)
const hasData =
existsSync(join(oldPath, "build")) ||
existsSync(join(oldPath, "chats")) ||
existsSync(join(oldPath, "storage.json")) ||
existsSync(join(oldPath, "config.json")) ||
existsSync(join(oldPath, "devhook.txt"));

if (!hasData) {
return;
}

// Simple rename: .blink/ → data/
console.log(chalk.yellow("Migrating .blink/ to data/..."));
await rename(oldPath, newPath);
if (!hasData) {
return;
}

// Simple rename: data/ → .blink/
console.log(chalk.yellow("Migrating data/ to .blink/..."));
await rename(oldPath, newPath);

// Update .gitignore if it exists
const gitignorePath = join(directory, ".gitignore");
if (existsSync(gitignorePath)) {
const content = readFileSync(gitignorePath, "utf-8");

// Only add if 'data' isn't already in gitignore
if (!content.includes("data")) {
// Only update if 'data' is in gitignore and '.blink' is not
if (content.includes("data") && !content.includes(".blink")) {
const lines = content.split("\n");

// Find where .blink is mentioned
const blinkIndex = lines.findIndex((line) =>
line.trim().match(/^\.blink\s*$/)
// Find where data is mentioned
const dataIndex = lines.findIndex((line) =>
line.trim().match(/^data\s*$/)
);

if (blinkIndex !== -1) {
// Replace .blink with data and add comment
lines[blinkIndex] = "data";
if (dataIndex !== -1) {
// Replace data with .blink and add comment
lines[dataIndex] = ".blink";
// Add comment before if there isn't already one
if (
blinkIndex === 0 ||
!lines[blinkIndex - 1]?.trim().startsWith("#")
) {
lines.splice(blinkIndex, 0, "# .blink has migrated to data/");
if (dataIndex === 0 || !lines[dataIndex - 1]?.trim().startsWith("#")) {
lines.splice(dataIndex, 0, "# data has migrated to .blink/");
}
} else {
// .blink not found, just append data at the end
// data not found, just append .blink at the end
if (!content.endsWith("\n")) {
lines.push("");
}
lines.push("# .blink has migrated to data/");
lines.push("data");
lines.push("# data has migrated to .blink/");
lines.push(".blink");
}

writeFileSync(gitignorePath, lines.join("\n"));
Expand Down
10 changes: 5 additions & 5 deletions packages/blink/src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spawnAgent } from "../local/spawn-agent";
import { parse } from "dotenv";
import { readFile } from "node:fs/promises";
import { getAuthToken } from "./lib/auth";
import { migrateBlinkToData } from "./lib/migrate";
import { migrateDataToBlink } from "./lib/migrate";
import { resolveConfig } from "../build";
import { findNearestEntry } from "../build/util";
import { existsSync } from "node:fs";
Expand All @@ -25,7 +25,7 @@ export default async function run(
// No agent found in current directory, search upward for .blink
let dotBlinkPath = await findNearestEntry(cwd, ".blink");

// This is legacy behavior to migrate old Blink directories to the new data/ directory.
// This is legacy behavior to migrate old Blink directories to the new .blink/ directory.
if (dotBlinkPath && existsSync(join(dotBlinkPath, "build"))) {
dotBlinkPath = undefined;
}
Expand All @@ -39,8 +39,8 @@ export default async function run(
}
}

// Auto-migrate .blink to data if it exists
await migrateBlinkToData(opts.directory);
// Auto-migrate data/ to .blink/ if it exists
await migrateDataToBlink(opts.directory);

const config = resolveConfig(opts.directory);

Expand All @@ -62,7 +62,7 @@ export default async function run(
});
console.log("Agent spawned");

const chatsDir = resolve(opts?.directory ?? process.cwd(), "data", "chats");
const chatsDir = resolve(opts?.directory ?? process.cwd(), ".blink", "chats");

const manager = new ChatManager({
chatId: opts?.chat,
Expand Down
2 changes: 1 addition & 1 deletion packages/blink/src/react/use-dev-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default function useDevMode(options: UseDevModeOptions): UseDevMode {
const server = useMemo(() => {
return createLocalServer({
port: 0,
dataDirectory: join(directory, "data"),
dataDirectory: join(directory, ".blink"),
getAgent: () => runAgentRef.current,
});
}, [directory]);
Expand Down
2 changes: 1 addition & 1 deletion packages/blink/src/react/use-devhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function useDevhook(options: UseDevhookOptions) {
let isConnecting = false;
let releaseLock: (() => void) | undefined;

const lockPath = join(options.directory, "data", "devhook");
const lockPath = join(options.directory, ".blink", "devhook");

// Acquire lock before connecting
(async () => {
Expand Down
Loading