@lovelybunch/api 1.0.24 → 1.0.26

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.
@@ -1,25 +1,13 @@
1
1
  /**
2
- * Get the base path for .gait directory based on environment
3
- *
4
- * Priority order:
5
- * 1. Explicit basePath parameter
6
- * 2. Dev mode: GAIT_DEV_ROOT environment variable
7
- * 3. Production mode: GAIT_DATA_PATH environment variable
8
- * 4. Fallback: current working directory
2
+ * Find the .gait directory by traversing up from the current working directory
3
+ * If GAIT_DATA_PATH is set (from CLI), use that instead
9
4
  */
10
- export declare function getGaitBasePath(basePath?: string): string;
5
+ export declare function findGaitDirectory(startDir?: string): Promise<string | null>;
11
6
  /**
12
- * Get the full path to a specific .gait subdirectory
7
+ * Get the path to a context file, automatically finding the .gait directory
13
8
  */
14
- export declare function getGaitPath(subdirectory: string, basePath?: string): string;
9
+ export declare function getContextFilePath(fileName: string): Promise<string | null>;
15
10
  /**
16
- * Common .gait subdirectories
11
+ * Get the .gait config to read storage path settings
17
12
  */
18
- export declare const GAIT_PATHS: {
19
- readonly proposals: () => string;
20
- readonly context: () => string;
21
- readonly agents: () => string;
22
- readonly resources: () => string;
23
- readonly chats: () => string;
24
- readonly config: () => string;
25
- };
13
+ export declare function getGaitConfig(): Promise<any | null>;
@@ -1,45 +1,57 @@
1
+ import { promises as fs } from 'fs';
1
2
  import path from 'path';
2
3
  /**
3
- * Get the base path for .gait directory based on environment
4
- *
5
- * Priority order:
6
- * 1. Explicit basePath parameter
7
- * 2. Dev mode: GAIT_DEV_ROOT environment variable
8
- * 3. Production mode: GAIT_DATA_PATH environment variable
9
- * 4. Fallback: current working directory
4
+ * Find the .gait directory by traversing up from the current working directory
5
+ * If GAIT_DATA_PATH is set (from CLI), use that instead
10
6
  */
11
- export function getGaitBasePath(basePath) {
12
- if (basePath) {
13
- return basePath;
7
+ export async function findGaitDirectory(startDir) {
8
+ // If running from CLI (gait serve), use the directory where command was run
9
+ if (process.env.GAIT_DATA_PATH) {
10
+ const gaitPath = path.join(process.env.GAIT_DATA_PATH, '.gait');
11
+ try {
12
+ await fs.access(gaitPath);
13
+ return gaitPath;
14
+ }
15
+ catch {
16
+ // Fall through to directory traversal
17
+ }
14
18
  }
15
- if (process.env.NODE_ENV === 'development' && process.env.GAIT_DEV_ROOT) {
16
- // Dev mode: use project root .gait directory
17
- return process.env.GAIT_DEV_ROOT;
18
- }
19
- else if (process.env.GAIT_DATA_PATH) {
20
- // Production mode: use GAIT_DATA_PATH (set by CLI)
21
- return path.resolve(process.env.GAIT_DATA_PATH, '.gait');
22
- }
23
- else {
24
- // Fallback: use current directory .gait
25
- return path.resolve(process.cwd(), '.gait');
19
+ // Otherwise traverse up from start directory
20
+ let currentDir = startDir || process.cwd();
21
+ while (currentDir !== path.parse(currentDir).root) {
22
+ const gaitPath = path.join(currentDir, '.gait');
23
+ try {
24
+ await fs.access(gaitPath);
25
+ return gaitPath;
26
+ }
27
+ catch {
28
+ currentDir = path.dirname(currentDir);
29
+ }
26
30
  }
31
+ return null;
27
32
  }
28
33
  /**
29
- * Get the full path to a specific .gait subdirectory
34
+ * Get the path to a context file, automatically finding the .gait directory
30
35
  */
31
- export function getGaitPath(subdirectory, basePath) {
32
- const base = getGaitBasePath(basePath);
33
- return path.join(base, subdirectory);
36
+ export async function getContextFilePath(fileName) {
37
+ const gaitDir = await findGaitDirectory();
38
+ if (!gaitDir)
39
+ return null;
40
+ return path.join(gaitDir, 'context', fileName);
34
41
  }
35
42
  /**
36
- * Common .gait subdirectories
43
+ * Get the .gait config to read storage path settings
37
44
  */
38
- export const GAIT_PATHS = {
39
- proposals: () => getGaitPath('proposals'),
40
- context: () => getGaitPath('context'),
41
- agents: () => getGaitPath('agents'),
42
- resources: () => getGaitPath('resources'),
43
- chats: () => getGaitPath('chats'),
44
- config: () => getGaitPath(''),
45
- };
45
+ export async function getGaitConfig() {
46
+ const gaitDir = await findGaitDirectory();
47
+ if (!gaitDir)
48
+ return null;
49
+ const configPath = path.join(gaitDir, 'config.json');
50
+ try {
51
+ const config = await fs.readFile(configPath, 'utf-8');
52
+ return JSON.parse(config);
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
@@ -2,11 +2,24 @@ import { promises as fs } from 'fs';
2
2
  import path from 'path';
3
3
  import matter from 'gray-matter';
4
4
  import Fuse from 'fuse.js';
5
- import { getGaitPath } from '../gait-path.js';
6
5
  export class FileStorageAdapter {
7
6
  basePath;
8
7
  constructor(basePath) {
9
- this.basePath = basePath || getGaitPath('proposals');
8
+ if (basePath) {
9
+ this.basePath = basePath;
10
+ }
11
+ else if (process.env.NODE_ENV === 'development' && process.env.GAIT_DEV_ROOT) {
12
+ // Dev mode: use project root .gait directory
13
+ this.basePath = process.env.GAIT_DEV_ROOT;
14
+ }
15
+ else if (process.env.GAIT_DATA_PATH) {
16
+ // Production mode: use GAIT_DATA_PATH (set by CLI)
17
+ this.basePath = path.join(process.env.GAIT_DATA_PATH, '.gait');
18
+ }
19
+ else {
20
+ // Fallback: use current directory .gait
21
+ this.basePath = '.gait';
22
+ }
10
23
  }
11
24
  async ensureDirectories() {
12
25
  const dirs = ['proposals', 'specs', 'flags', 'experiments', 'templates'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovelybunch/api",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "type": "module",
5
5
  "main": "dist/server-with-static.js",
6
6
  "exports": {
@@ -32,8 +32,8 @@
32
32
  "dependencies": {
33
33
  "@hono/node-server": "^1.13.7",
34
34
  "@hono/node-ws": "^1.0.6",
35
- "@lovelybunch/core": "^1.0.24",
36
- "@lovelybunch/types": "^1.0.24",
35
+ "@lovelybunch/core": "^1.0.25",
36
+ "@lovelybunch/types": "^1.0.25",
37
37
  "dotenv": "^17.2.1",
38
38
  "fuse.js": "^7.0.0",
39
39
  "gray-matter": "^4.0.3",