neural-loom 0.2.43 → 0.2.45

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 (79) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +3 -3
  3. package/.next/cache/.previewinfo +1 -1
  4. package/.next/cache/.rscinfo +1 -1
  5. package/.next/cache/.tsbuildinfo +1 -1
  6. package/.next/fallback-build-manifest.json +3 -3
  7. package/.next/prerender-manifest.json +3 -3
  8. package/.next/server/app/_global-error.html +1 -1
  9. package/.next/server/app/_global-error.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  15. package/.next/server/app/_not-found.html +1 -1
  16. package/.next/server/app/_not-found.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  18. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  20. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  21. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  22. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  23. package/.next/server/app/api/sessions/inject/route.js.nft.json +1 -1
  24. package/.next/server/app/api/sessions/input/route.js.nft.json +1 -1
  25. package/.next/server/app/api/sessions/launch/route.js.nft.json +1 -1
  26. package/.next/server/app/api/sessions/route.js.nft.json +1 -1
  27. package/.next/server/app/api/sessions/scope/route.js.nft.json +1 -1
  28. package/.next/server/app/api/sessions/start/route.js.nft.json +1 -1
  29. package/.next/server/app/api/sessions/stats/route.js.nft.json +1 -1
  30. package/.next/server/app/api/sessions/stop/route.js.nft.json +1 -1
  31. package/.next/server/app/index.html +1 -1
  32. package/.next/server/app/index.rsc +1 -1
  33. package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  34. package/.next/server/app/index.segments/_full.segment.rsc +1 -1
  35. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  36. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  37. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  38. package/.next/server/chunks/[root-of-the-server]__01.zh3b._.js +6 -6
  39. package/.next/server/chunks/[root-of-the-server]__01.zh3b._.js.map +1 -1
  40. package/.next/server/chunks/[root-of-the-server]__0656ruo._.js +6 -6
  41. package/.next/server/chunks/[root-of-the-server]__0656ruo._.js.map +1 -1
  42. package/.next/server/chunks/[root-of-the-server]__07zx04e._.js +3 -3
  43. package/.next/server/chunks/[root-of-the-server]__07zx04e._.js.map +1 -1
  44. package/.next/server/chunks/[root-of-the-server]__0_o7_jj._.js +7 -7
  45. package/.next/server/chunks/[root-of-the-server]__0_o7_jj._.js.map +1 -1
  46. package/.next/server/chunks/[root-of-the-server]__0d0pykb._.js +7 -7
  47. package/.next/server/chunks/[root-of-the-server]__0d0pykb._.js.map +1 -1
  48. package/.next/server/chunks/[root-of-the-server]__0em6a~~._.js +5 -5
  49. package/.next/server/chunks/[root-of-the-server]__0em6a~~._.js.map +1 -1
  50. package/.next/server/chunks/[root-of-the-server]__0gchnwb._.js +1 -1
  51. package/.next/server/chunks/[root-of-the-server]__0gchnwb._.js.map +1 -1
  52. package/.next/server/chunks/[root-of-the-server]__0i~01cv._.js +3 -3
  53. package/.next/server/chunks/[root-of-the-server]__0i~01cv._.js.map +1 -1
  54. package/.next/server/chunks/[root-of-the-server]__0s0is_9._.js +6 -6
  55. package/.next/server/chunks/[root-of-the-server]__0s0is_9._.js.map +1 -1
  56. package/.next/server/chunks/[root-of-the-server]__0t713sv._.js +1 -1
  57. package/.next/server/chunks/[root-of-the-server]__0t713sv._.js.map +1 -1
  58. package/.next/server/chunks/[root-of-the-server]__0thsozo._.js +5 -5
  59. package/.next/server/chunks/[root-of-the-server]__0thsozo._.js.map +1 -1
  60. package/.next/server/chunks/[root-of-the-server]__10wwca8._.js +5 -5
  61. package/.next/server/chunks/[root-of-the-server]__10wwca8._.js.map +1 -1
  62. package/.next/server/chunks/[root-of-the-server]__11h_nxt._.js +1 -1
  63. package/.next/server/chunks/[root-of-the-server]__11h_nxt._.js.map +1 -1
  64. package/.next/server/chunks/[root-of-the-server]__11z12oe._.js +1 -1
  65. package/.next/server/chunks/[root-of-the-server]__11z12oe._.js.map +1 -1
  66. package/.next/server/middleware-build-manifest.js +3 -3
  67. package/.next/server/pages/404.html +1 -1
  68. package/.next/server/pages/500.html +1 -1
  69. package/.next/server/server-reference-manifest.js +1 -1
  70. package/.next/server/server-reference-manifest.json +1 -1
  71. package/.next/trace +1 -1
  72. package/.next/trace-build +1 -1
  73. package/package.json +1 -1
  74. package/src/lib/agents/ContextManager.ts +87 -63
  75. package/src/lib/agents/SessionPersister.ts +2 -5
  76. package/src/lib/config.ts +10 -1
  77. /package/.next/static/{xqFiJPAmHsNHappCgW2Ov → X96CB5X5ONpzNOxbXcD_F}/_buildManifest.js +0 -0
  78. /package/.next/static/{xqFiJPAmHsNHappCgW2Ov → X96CB5X5ONpzNOxbXcD_F}/_clientMiddlewareManifest.js +0 -0
  79. /package/.next/static/{xqFiJPAmHsNHappCgW2Ov → X96CB5X5ONpzNOxbXcD_F}/_ssgManifest.js +0 -0
@@ -7,55 +7,75 @@ export class ContextManager {
7
7
  }
8
8
 
9
9
  private static ensureDirs(root: string) {
10
- const aiDir = path.join(root, ".ai", "neural-loom");
11
- if (!fs.existsSync(aiDir)) {
12
- fs.mkdirSync(aiDir, { recursive: true });
13
- }
10
+ try {
11
+ const aiDir = path.join(root, ".ai", "neural-loom");
12
+ if (!fs.existsSync(aiDir)) {
13
+ fs.mkdirSync(aiDir, { recursive: true });
14
+ }
14
15
 
15
- const commandDir = path.join(root, ".claude", "commands");
16
- if (!fs.existsSync(commandDir)) {
17
- fs.mkdirSync(commandDir, { recursive: true });
16
+ const commandDir = path.join(root, ".claude", "commands");
17
+ if (!fs.existsSync(commandDir)) {
18
+ fs.mkdirSync(commandDir, { recursive: true });
19
+ }
20
+ } catch (err) {
21
+ console.warn(`[ContextManager] Failed to ensure directories at ${root}:`, err);
18
22
  }
19
23
  }
20
24
 
21
25
  public static initializeStaging(root: string = process.env.ORIGINAL_CWD || process.cwd()) {
22
- this.ensureDirs(root);
23
-
24
- // Create /ccp.md custom slash command file
25
- const ccpPath = path.join(root, ".claude", "commands", "ccp.md");
26
- if (!fs.existsSync(ccpPath)) {
27
- fs.writeFileSync(
28
- ccpPath,
29
- "Read the prompt from .ai/neural-loom/cprompt.md and execute it. This is a staged prompt from the NeuralLoom UI. Treat the contents as user instructions.\n"
30
- );
31
- }
26
+ try {
27
+ this.ensureDirs(root);
28
+
29
+ // Create /ccp.md custom slash command file
30
+ const ccpPath = path.join(root, ".claude", "commands", "ccp.md");
31
+ if (!fs.existsSync(ccpPath)) {
32
+ fs.writeFileSync(
33
+ ccpPath,
34
+ "Read the prompt from .ai/neural-loom/cprompt.md and execute it. This is a staged prompt from the NeuralLoom UI. Treat the contents as user instructions.\n"
35
+ );
36
+ }
32
37
 
33
- // Create /ccc.md custom slash command file
34
- const cccPath = path.join(root, ".claude", "commands", "ccc.md");
35
- if (!fs.existsSync(cccPath)) {
36
- fs.writeFileSync(
37
- cccPath,
38
- "Read the context from .ai/neural-loom/ccontext.md. This is persistent context from the NeuralLoom UI. Absorb it as background information for this session. Acknowledge briefly what you received.\n"
39
- );
38
+ // Create /ccc.md custom slash command file
39
+ const cccPath = path.join(root, ".claude", "commands", "ccc.md");
40
+ if (!fs.existsSync(cccPath)) {
41
+ fs.writeFileSync(
42
+ cccPath,
43
+ "Read the context from .ai/neural-loom/ccontext.md. This is persistent context from the NeuralLoom UI. Absorb it as background information for this session. Acknowledge briefly what you received.\n"
44
+ );
45
+ }
46
+ } catch (err) {
47
+ console.warn(`[ContextManager] Failed to initialize staging at ${root}:`, err);
40
48
  }
41
49
  }
42
50
 
43
51
  public static updatePrompt(promptText: string, root: string = process.env.ORIGINAL_CWD || process.cwd()) {
44
- this.ensureDirs(root);
45
- const promptFile = path.join(root, ".ai", "neural-loom", "cprompt.md");
46
- fs.writeFileSync(promptFile, promptText);
52
+ try {
53
+ this.ensureDirs(root);
54
+ const promptFile = path.join(root, ".ai", "neural-loom", "cprompt.md");
55
+ fs.writeFileSync(promptFile, promptText);
56
+ } catch (err) {
57
+ console.error(`[ContextManager] Failed to write prompt file at ${root}:`, err);
58
+ }
47
59
  }
48
60
 
49
61
  public static updateContext(contextText: string, root: string = process.env.ORIGINAL_CWD || process.cwd()) {
50
- this.ensureDirs(root);
51
- const contextFile = path.join(root, ".ai", "neural-loom", "ccontext.md");
52
- fs.writeFileSync(contextFile, contextText);
62
+ try {
63
+ this.ensureDirs(root);
64
+ const contextFile = path.join(root, ".ai", "neural-loom", "ccontext.md");
65
+ fs.writeFileSync(contextFile, contextText);
66
+ } catch (err) {
67
+ console.error(`[ContextManager] Failed to write context file at ${root}:`, err);
68
+ }
53
69
  }
54
70
 
55
71
  public static updateRules(rulesText: string, root: string = process.env.ORIGINAL_CWD || process.cwd()) {
56
- this.ensureDirs(root);
57
- const agentsMdPath = path.join(root, "AGENTS.md");
58
- fs.writeFileSync(agentsMdPath, rulesText, "utf8");
72
+ try {
73
+ this.ensureDirs(root);
74
+ const agentsMdPath = path.join(root, "AGENTS.md");
75
+ fs.writeFileSync(agentsMdPath, rulesText, "utf8");
76
+ } catch (err) {
77
+ console.error(`[ContextManager] Failed to write rules file at ${root}:`, err);
78
+ }
59
79
  }
60
80
 
61
81
  public static loadPrompt(root: string = process.env.ORIGINAL_CWD || process.cwd()): string {
@@ -73,41 +93,45 @@ export class ContextManager {
73
93
  }
74
94
 
75
95
  public static compileSessionContext(root: string = process.env.ORIGINAL_CWD || process.cwd(), scopedDirs?: string[]) {
76
- this.ensureDirs(root);
77
- this.initializeStaging(root);
78
-
79
- // Check if AGENTS.md rules template exists
80
- const agentsMdPath = path.join(root, "AGENTS.md");
81
- let agentsRules = "";
82
- if (fs.existsSync(agentsMdPath)) {
83
- agentsRules = fs.readFileSync(agentsMdPath, "utf8");
84
- } else {
85
- // Try fallback from global
86
- const fallbackPath = path.join(this.workspaceRoot, "AGENTS.md");
87
- if (fs.existsSync(fallbackPath)) {
88
- agentsRules = fs.readFileSync(fallbackPath, "utf8");
96
+ try {
97
+ this.ensureDirs(root);
98
+ this.initializeStaging(root);
99
+
100
+ // Check if AGENTS.md rules template exists
101
+ const agentsMdPath = path.join(root, "AGENTS.md");
102
+ let agentsRules = "";
103
+ if (fs.existsSync(agentsMdPath)) {
104
+ agentsRules = fs.readFileSync(agentsMdPath, "utf8");
105
+ } else {
106
+ // Try fallback from global
107
+ const fallbackPath = path.join(this.workspaceRoot, "AGENTS.md");
108
+ if (fs.existsSync(fallbackPath)) {
109
+ agentsRules = fs.readFileSync(fallbackPath, "utf8");
110
+ }
89
111
  }
90
- }
91
112
 
92
- // Generate maps
93
- let maps = `## Workspace Root Map (${root}):\n${this.generateProjectMapFor(root)}`;
113
+ // Generate maps
114
+ let maps = `## Workspace Root Map (${root}):\n${this.generateProjectMapFor(root)}`;
94
115
 
95
- if (scopedDirs && Array.isArray(scopedDirs)) {
96
- scopedDirs.forEach((dir) => {
97
- if (fs.existsSync(dir)) {
98
- maps += `\n\n## Scoped Directory Map (${dir}):\n${this.generateProjectMapFor(dir)}`;
99
- }
100
- });
101
- }
116
+ if (scopedDirs && Array.isArray(scopedDirs)) {
117
+ scopedDirs.forEach((dir) => {
118
+ if (fs.existsSync(dir)) {
119
+ maps += `\n\n## Scoped Directory Map (${dir}):\n${this.generateProjectMapFor(dir)}`;
120
+ }
121
+ });
122
+ }
102
123
 
103
- // Combine rules and folder map
104
- const compiledContext = `# System Rules & Guidelines\n\n${agentsRules}\n\n# Project File Hierarchy Map\n\n${maps}`;
105
- this.updateContext(compiledContext, root);
124
+ // Combine rules and folder map
125
+ const compiledContext = `# System Rules & Guidelines\n\n${agentsRules}\n\n# Project File Hierarchy Map\n\n${maps}`;
126
+ this.updateContext(compiledContext, root);
106
127
 
107
- // Write a default empty prompt staging file if missing
108
- const promptFile = path.join(root, ".ai", "neural-loom", "cprompt.md");
109
- if (!fs.existsSync(promptFile)) {
110
- fs.writeFileSync(promptFile, "Hello! Please review the project context (/ccc) and check for any tasks to execute.");
128
+ // Write a default empty prompt staging file if missing
129
+ const promptFile = path.join(root, ".ai", "neural-loom", "cprompt.md");
130
+ if (!fs.existsSync(promptFile)) {
131
+ fs.writeFileSync(promptFile, "Hello! Please review the project context (/ccc) and check for any tasks to execute.");
132
+ }
133
+ } catch (err) {
134
+ console.warn(`[ContextManager] Failed to compile session context at ${root}:`, err);
111
135
  }
112
136
  }
113
137
 
@@ -1,5 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { getConfigDir } from "../config";
3
4
 
4
5
  export interface PersistedSession {
5
6
  id: string;
@@ -17,12 +18,8 @@ export class SessionPersister {
17
18
  private static pendingSaves = new Map<string, NodeJS.Timeout>();
18
19
  private static pendingData = new Map<string, PersistedSession>();
19
20
 
20
- private static get workspaceRoot(): string {
21
- return process.env.ORIGINAL_CWD || process.cwd();
22
- }
23
-
24
21
  private static getSessionsDir(): string {
25
- const dir = path.join(this.workspaceRoot, ".ai", "neural-loom", "sessions");
22
+ const dir = path.join(getConfigDir(), "sessions");
26
23
  if (!fs.existsSync(dir)) {
27
24
  fs.mkdirSync(dir, { recursive: true });
28
25
  }
package/src/lib/config.ts CHANGED
@@ -2,7 +2,13 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import os from "os";
4
4
 
5
+ let cachedConfigDir: string | null = null;
6
+
5
7
  export function getConfigDir(): string {
8
+ if (cachedConfigDir) {
9
+ return cachedConfigDir;
10
+ }
11
+
6
12
  const primaryDir = path.join(process.env.ORIGINAL_CWD || process.cwd(), ".ai", "neural-loom");
7
13
 
8
14
  try {
@@ -14,18 +20,21 @@ export function getConfigDir(): string {
14
20
  const testFile = path.join(primaryDir, ".write-test-" + Math.random().toString(36).substring(7));
15
21
  fs.writeFileSync(testFile, "test");
16
22
  fs.unlinkSync(testFile);
23
+ cachedConfigDir = primaryDir;
17
24
  return primaryDir;
18
25
  } catch (err) {
19
26
  // If EPERM or any other write error occurs, fall back to the user's home directory
20
- console.warn(`[Config] Primary config dir is not writable (${primaryDir}). Falling back to home directory.`, err);
27
+ console.warn(`[Config] Primary config dir is not writable (${primaryDir}). Falling back to home directory.`);
21
28
  const fallbackDir = path.join(os.homedir(), ".ai", "neural-loom");
22
29
  try {
23
30
  if (!fs.existsSync(fallbackDir)) {
24
31
  fs.mkdirSync(fallbackDir, { recursive: true });
25
32
  }
33
+ cachedConfigDir = fallbackDir;
26
34
  return fallbackDir;
27
35
  } catch (fallbackErr) {
28
36
  console.error("[Config] Fallback config dir is also not writable!", fallbackErr);
37
+ cachedConfigDir = primaryDir;
29
38
  return primaryDir;
30
39
  }
31
40
  }