neural-loom 0.2.69 → 0.2.70

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 (144) 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/dev/build-manifest.json +50 -0
  7. package/.next/dev/fallback-build-manifest.json +37 -0
  8. package/.next/dev/logs/next-development.log +3737 -0
  9. package/.next/dev/server/chunks/[root-of-the-server]__11uf~fd._.js +2396 -0
  10. package/.next/dev/server/chunks/[root-of-the-server]__11uf~fd._.js.map +20 -0
  11. package/.next/dev/server/chunks/ssr/[externals]__0.o~_~l._.js +32 -0
  12. package/.next/dev/server/chunks/ssr/[externals]__0.o~_~l._.js.map +5 -0
  13. package/.next/dev/server/chunks/ssr/[externals]_next_dist_shared_lib_no-fallback-error_external_0fgm~bn.js +8 -0
  14. package/.next/dev/server/chunks/ssr/[externals]_next_dist_shared_lib_no-fallback-error_external_0fgm~bn.js.map +5 -0
  15. package/.next/dev/server/chunks/ssr/[root-of-the-server]__0je5zm2._.js +285 -0
  16. package/.next/dev/server/chunks/ssr/[root-of-the-server]__0je5zm2._.js.map +9 -0
  17. package/.next/dev/server/chunks/ssr/node_modules_01ed9g5._.js +6621 -0
  18. package/.next/dev/server/chunks/ssr/node_modules_01ed9g5._.js.map +76 -0
  19. package/.next/dev/server/chunks/ssr/node_modules_129w7gn._.js +4399 -0
  20. package/.next/dev/server/chunks/ssr/node_modules_129w7gn._.js.map +35 -0
  21. package/.next/dev/server/chunks/ssr/node_modules_next_12i4inu._.js +55 -0
  22. package/.next/dev/server/chunks/ssr/node_modules_next_12i4inu._.js.map +7 -0
  23. package/.next/dev/server/middleware-build-manifest.js +50 -0
  24. package/.next/dev/server/next-font-manifest.js +1 -0
  25. package/.next/dev/server/next-font-manifest.json +11 -0
  26. package/.next/dev/server/pages/_app/build-manifest.json +23 -0
  27. package/.next/dev/server/pages/_app/client-build-manifest.json +5 -0
  28. package/.next/dev/server/pages/_app/next-font-manifest.json +6 -0
  29. package/.next/dev/server/pages/_app/pages-manifest.json +3 -0
  30. package/.next/dev/server/pages/_app/react-loadable-manifest.json +1 -0
  31. package/.next/dev/server/pages/_app.js +4 -0
  32. package/.next/dev/server/pages/_app.js.map +5 -0
  33. package/.next/dev/server/pages/_document/next-font-manifest.json +6 -0
  34. package/.next/dev/server/pages/_document/pages-manifest.json +3 -0
  35. package/.next/dev/server/pages/_document/react-loadable-manifest.json +1 -0
  36. package/.next/dev/server/pages/_document.js +5 -0
  37. package/.next/dev/server/pages/_document.js.map +5 -0
  38. package/.next/dev/server/pages/_error/build-manifest.json +22 -0
  39. package/.next/dev/server/pages/_error/client-build-manifest.json +5 -0
  40. package/.next/dev/server/pages/_error/next-font-manifest.json +6 -0
  41. package/.next/dev/server/pages/_error/pages-manifest.json +3 -0
  42. package/.next/dev/server/pages/_error/react-loadable-manifest.json +1 -0
  43. package/.next/dev/server/pages/_error.js +8 -0
  44. package/.next/dev/server/pages/_error.js.map +5 -0
  45. package/.next/dev/server/pages-manifest.json +5 -0
  46. package/.next/dev/static/chunks/[next]_entry_page-loader_ts_0j~flwh._.js +23 -0
  47. package/.next/dev/static/chunks/[next]_entry_page-loader_ts_0j~flwh._.js.map +6 -0
  48. package/.next/dev/static/chunks/[next]_entry_page-loader_ts_0rqw6yo._.js +23 -0
  49. package/.next/dev/static/chunks/[next]_entry_page-loader_ts_0rqw6yo._.js.map +6 -0
  50. package/.next/dev/static/chunks/[root-of-the-server]__01mw43t._.js +476 -0
  51. package/.next/dev/static/chunks/[root-of-the-server]__01mw43t._.js.map +6 -0
  52. package/.next/dev/static/chunks/[root-of-the-server]__0c0okpg._.js +476 -0
  53. package/.next/dev/static/chunks/[root-of-the-server]__0c0okpg._.js.map +6 -0
  54. package/.next/dev/static/chunks/node_modules_0lx093h._.js +1343 -0
  55. package/.next/dev/static/chunks/node_modules_0lx093h._.js.map +13 -0
  56. package/.next/dev/static/chunks/node_modules_next_app_0jt-zj..js +8 -0
  57. package/.next/dev/static/chunks/node_modules_next_app_0jt-zj..js.map +6 -0
  58. package/.next/dev/static/chunks/node_modules_next_dist_0rt-2cr._.js +2334 -0
  59. package/.next/dev/static/chunks/node_modules_next_dist_0rt-2cr._.js.map +26 -0
  60. package/.next/dev/static/chunks/node_modules_next_dist_0u_w_5s._.js +2165 -0
  61. package/.next/dev/static/chunks/node_modules_next_dist_0u_w_5s._.js.map +25 -0
  62. package/.next/dev/static/chunks/node_modules_next_dist_client_0pe1dg-._.js +4091 -0
  63. package/.next/dev/static/chunks/node_modules_next_dist_client_0pe1dg-._.js.map +49 -0
  64. package/.next/dev/static/chunks/node_modules_next_dist_compiled_0o6l_m6._.js +6064 -0
  65. package/.next/dev/static/chunks/node_modules_next_dist_compiled_0o6l_m6._.js.map +17 -0
  66. package/.next/dev/static/chunks/node_modules_next_dist_shared_lib_0ek5eq7._.js +6535 -0
  67. package/.next/dev/static/chunks/node_modules_next_dist_shared_lib_0ek5eq7._.js.map +72 -0
  68. package/.next/dev/static/chunks/node_modules_next_dist_shared_lib_0n1wg2c._.js +6294 -0
  69. package/.next/dev/static/chunks/node_modules_next_dist_shared_lib_0n1wg2c._.js.map +70 -0
  70. package/.next/dev/static/chunks/node_modules_react-dom_0bruynb._.js +15381 -0
  71. package/.next/dev/static/chunks/node_modules_react-dom_0bruynb._.js.map +9 -0
  72. package/.next/dev/static/chunks/pages/_app.js +13 -0
  73. package/.next/dev/static/chunks/pages/_error.js +12 -0
  74. package/.next/dev/static/chunks/pages__app_0-bg2z-._.js.map +11 -0
  75. package/.next/dev/static/chunks/pages__app_07xvfw~._.js +5 -0
  76. package/.next/dev/static/chunks/pages__error_0.i_zsq._.js.map +11 -0
  77. package/.next/dev/static/chunks/pages__error_07xvfw~._.js +5 -0
  78. package/.next/dev/static/chunks/turbopack-pages__app_0-bg2z-._.js +2236 -0
  79. package/.next/dev/static/chunks/turbopack-pages__error_0.i_zsq._.js +2236 -0
  80. package/.next/diagnostics/route-bundle-stats.json +1 -1
  81. package/.next/fallback-build-manifest.json +3 -3
  82. package/.next/prerender-manifest.json +3 -3
  83. package/.next/server/app/_global-error.html +1 -1
  84. package/.next/server/app/_global-error.rsc +1 -1
  85. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  86. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  87. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  88. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  89. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  90. package/.next/server/app/_not-found.html +1 -1
  91. package/.next/server/app/_not-found.rsc +1 -1
  92. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  93. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  94. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  95. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  96. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  97. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  98. package/.next/server/app/api/configs/route.js.nft.json +1 -1
  99. package/.next/server/app/api/context/aider/route.js.nft.json +1 -1
  100. package/.next/server/app/api/context/claude/route.js.nft.json +1 -1
  101. package/.next/server/app/api/context/route.js.nft.json +1 -1
  102. package/.next/server/app/api/context/ssh/route.js.nft.json +1 -1
  103. package/.next/server/app/api/recents/route.js.nft.json +1 -1
  104. package/.next/server/app/api/sessions/inject/route.js.nft.json +1 -1
  105. package/.next/server/app/api/sessions/input/route.js.nft.json +1 -1
  106. package/.next/server/app/api/sessions/launch/route.js.nft.json +1 -1
  107. package/.next/server/app/api/sessions/route.js.nft.json +1 -1
  108. package/.next/server/app/api/sessions/scope/route.js.nft.json +1 -1
  109. package/.next/server/app/api/sessions/start/route.js.nft.json +1 -1
  110. package/.next/server/app/api/sessions/stats/route.js.nft.json +1 -1
  111. package/.next/server/app/api/sessions/stop/route.js.nft.json +1 -1
  112. package/.next/server/app/api/sessions/upload-image/route.js.nft.json +1 -1
  113. package/.next/server/app/api/sql/connections/route.js.nft.json +1 -1
  114. package/.next/server/app/api/sql/mcp/route.js.nft.json +1 -1
  115. package/.next/server/app/api/sql/query/route.js.nft.json +1 -1
  116. package/.next/server/app/api/sql/schema/route.js.nft.json +1 -1
  117. package/.next/server/app/index.html +1 -1
  118. package/.next/server/app/index.rsc +2 -2
  119. package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  120. package/.next/server/app/index.segments/_full.segment.rsc +2 -2
  121. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  122. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  123. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  124. package/.next/server/app/page/react-loadable-manifest.json +3 -3
  125. package/.next/server/app/page_client-reference-manifest.js +1 -1
  126. package/.next/server/chunks/[root-of-the-server]__0tq0maq._.js +1 -1
  127. package/.next/server/chunks/[root-of-the-server]__0tq0maq._.js.map +1 -1
  128. package/.next/server/middleware-build-manifest.js +3 -3
  129. package/.next/server/pages/404.html +1 -1
  130. package/.next/server/pages/500.html +1 -1
  131. package/.next/server/server-reference-manifest.js +1 -1
  132. package/.next/server/server-reference-manifest.json +1 -1
  133. package/.next/static/chunks/{008bf~h8rh5_3.js → 0fxouf2n_5adf.js} +1 -1
  134. package/.next/static/chunks/{00pgauqedvo01.js → 0r3x2gcn0sde..js} +1 -1
  135. package/.next/static/chunks/11c6f8pb_6s91.js +4 -0
  136. package/.next/trace +1 -1
  137. package/.next/trace-build +1 -1
  138. package/package.json +1 -1
  139. package/src/app/components/MarkdownPreview.tsx +17 -10
  140. package/src/app/components/TerminalConsole.tsx +25 -11
  141. package/.next/static/chunks/0ii_nb0g40rmj.js +0 -4
  142. /package/.next/static/{EglcK14vXeSWIjxjJCP9A → llmJsGQafolZV5_sqEw4l}/_buildManifest.js +0 -0
  143. /package/.next/static/{EglcK14vXeSWIjxjJCP9A → llmJsGQafolZV5_sqEw4l}/_clientMiddlewareManifest.js +0 -0
  144. /package/.next/static/{EglcK14vXeSWIjxjJCP9A → llmJsGQafolZV5_sqEw4l}/_ssgManifest.js +0 -0
@@ -0,0 +1,2396 @@
1
+ module.exports = [
2
+ "[externals]/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-route-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {
3
+
4
+ const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js"));
5
+
6
+ module.exports = mod;
7
+ }),
8
+ "[externals]/next/dist/compiled/@opentelemetry/api [external] (next/dist/compiled/@opentelemetry/api, cjs)", ((__turbopack_context__, module, exports) => {
9
+
10
+ const mod = __turbopack_context__.x("next/dist/compiled/@opentelemetry/api", () => require("next/dist/compiled/@opentelemetry/api"));
11
+
12
+ module.exports = mod;
13
+ }),
14
+ "[externals]/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-page-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {
15
+
16
+ const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js"));
17
+
18
+ module.exports = mod;
19
+ }),
20
+ "[externals]/next/dist/server/app-render/work-unit-async-storage.external.js [external] (next/dist/server/app-render/work-unit-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {
21
+
22
+ const mod = __turbopack_context__.x("next/dist/server/app-render/work-unit-async-storage.external.js", () => require("next/dist/server/app-render/work-unit-async-storage.external.js"));
23
+
24
+ module.exports = mod;
25
+ }),
26
+ "[externals]/next/dist/server/app-render/work-async-storage.external.js [external] (next/dist/server/app-render/work-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {
27
+
28
+ const mod = __turbopack_context__.x("next/dist/server/app-render/work-async-storage.external.js", () => require("next/dist/server/app-render/work-async-storage.external.js"));
29
+
30
+ module.exports = mod;
31
+ }),
32
+ "[externals]/next/dist/shared/lib/no-fallback-error.external.js [external] (next/dist/shared/lib/no-fallback-error.external.js, cjs)", ((__turbopack_context__, module, exports) => {
33
+
34
+ const mod = __turbopack_context__.x("next/dist/shared/lib/no-fallback-error.external.js", () => require("next/dist/shared/lib/no-fallback-error.external.js"));
35
+
36
+ module.exports = mod;
37
+ }),
38
+ "[externals]/next/dist/server/app-render/after-task-async-storage.external.js [external] (next/dist/server/app-render/after-task-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {
39
+
40
+ const mod = __turbopack_context__.x("next/dist/server/app-render/after-task-async-storage.external.js", () => require("next/dist/server/app-render/after-task-async-storage.external.js"));
41
+
42
+ module.exports = mod;
43
+ }),
44
+ "[externals]/crypto [external] (crypto, cjs)", ((__turbopack_context__, module, exports) => {
45
+
46
+ const mod = __turbopack_context__.x("crypto", () => require("crypto"));
47
+
48
+ module.exports = mod;
49
+ }),
50
+ "[externals]/fs [external] (fs, cjs)", ((__turbopack_context__, module, exports) => {
51
+
52
+ const mod = __turbopack_context__.x("fs", () => require("fs"));
53
+
54
+ module.exports = mod;
55
+ }),
56
+ "[externals]/path [external] (path, cjs)", ((__turbopack_context__, module, exports) => {
57
+
58
+ const mod = __turbopack_context__.x("path", () => require("path"));
59
+
60
+ module.exports = mod;
61
+ }),
62
+ "[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
63
+ "use strict";
64
+
65
+ __turbopack_context__.s([
66
+ "AgentRunner",
67
+ ()=>AgentRunner
68
+ ]);
69
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
70
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
71
+ ;
72
+ ;
73
+ class AgentRunner {
74
+ workspaceRoot;
75
+ scopedDirs;
76
+ lastSyncedWorkspaceFolders;
77
+ tokenUsage = {
78
+ input: 0,
79
+ output: 0,
80
+ cost: 0
81
+ };
82
+ agentState = 'idle';
83
+ hasAnalyzedInitialState = false;
84
+ stateTimer = null;
85
+ idleTimer = null;
86
+ lastLoggedUsage = {
87
+ input: 0,
88
+ output: 0,
89
+ cost: 0
90
+ };
91
+ resetInitialStateAnalysis() {
92
+ this.hasAnalyzedInitialState = false;
93
+ }
94
+ logTokenUsageUpdate() {
95
+ if (this.tokenUsage.input === this.lastLoggedUsage.input && this.tokenUsage.output === this.lastLoggedUsage.output && this.tokenUsage.cost === this.lastLoggedUsage.cost) {
96
+ return;
97
+ }
98
+ const diffInput = this.tokenUsage.input - this.lastLoggedUsage.input;
99
+ const diffOutput = this.tokenUsage.output - this.lastLoggedUsage.output;
100
+ const diffCost = this.tokenUsage.cost - this.lastLoggedUsage.cost;
101
+ if (diffInput > 0 || diffOutput > 0 || diffCost > 0) {
102
+ try {
103
+ const configDir = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(process.cwd(), ".ai", "neural-loom");
104
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(configDir)) {
105
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(configDir, {
106
+ recursive: true
107
+ });
108
+ }
109
+ const historyFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(configDir, "token-history.json");
110
+ let history = [];
111
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(historyFile)) {
112
+ try {
113
+ history = JSON.parse(__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(historyFile, "utf8")) || [];
114
+ } catch {
115
+ history = [];
116
+ }
117
+ }
118
+ history.push({
119
+ timestamp: new Date().toISOString(),
120
+ sessionId: this.id,
121
+ sessionName: this.name,
122
+ type: this.type,
123
+ inputTokens: diffInput > 0 ? diffInput : 0,
124
+ outputTokens: diffOutput > 0 ? diffOutput : 0,
125
+ cost: diffCost > 0 ? diffCost : 0,
126
+ totalInput: this.tokenUsage.input,
127
+ totalOutput: this.tokenUsage.output,
128
+ totalCost: this.tokenUsage.cost
129
+ });
130
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(historyFile, JSON.stringify(history, null, 2), "utf8");
131
+ this.lastLoggedUsage = {
132
+ ...this.tokenUsage
133
+ };
134
+ } catch (err) {
135
+ console.error("[AgentRunner] Failed to log token usage transaction:", err);
136
+ }
137
+ }
138
+ }
139
+ parseTokenUsage(data) {
140
+ const cleanData = data.replace(/\x1b\[[0-9;]*m/g, ""); // Strip ANSI colors
141
+ // Regex for cost
142
+ const costMatch = cleanData.match(/(?:cost|estimated cost)[:\s]*\$([0-9.]+)/i);
143
+ if (costMatch) {
144
+ this.tokenUsage.cost = parseFloat(costMatch[1]);
145
+ }
146
+ const parseNum = (str)=>{
147
+ str = str.replace(/,/g, '').toLowerCase().trim();
148
+ if (str.endsWith('k')) {
149
+ return parseFloat(str.slice(0, -1)) * 1000;
150
+ }
151
+ if (str.endsWith('m')) {
152
+ return parseFloat(str.slice(0, -1)) * 1000000;
153
+ }
154
+ return parseInt(str, 10) || 0;
155
+ };
156
+ // Tokens pattern: "Tokens: 1,500 sent, 300 received" or "1.5k sent, 0.3k received"
157
+ const tokensPattern1 = /tokens?[:\s]*([0-9,.]+[km]?)\s*(?:sent|input|prompt)[^a-zA-Z0-9]+([0-9,.]+[km]?)\s*(?:received|output|completion)/i;
158
+ const match1 = cleanData.match(tokensPattern1);
159
+ if (match1) {
160
+ this.tokenUsage.input = parseNum(match1[1]);
161
+ this.tokenUsage.output = parseNum(match1[2]);
162
+ } else {
163
+ // Try separate matches
164
+ const inputMatch = cleanData.match(/([0-9,.]+[km]?)\s*(?:sent|input|prompt)\s*tokens?/i) || cleanData.match(/tokens?\s*(?:sent|input|prompt)[:\s]*([0-9,.]+[km]?)/i);
165
+ if (inputMatch) {
166
+ this.tokenUsage.input = parseNum(inputMatch[1]);
167
+ }
168
+ const outputMatch = cleanData.match(/([0-9,.]+[km]?)\s*(?:received|output|completion)\s*tokens?/i) || cleanData.match(/tokens?\s*(?:received|output|completion)[:\s]*([0-9,.]+[km]?)/i);
169
+ if (outputMatch) {
170
+ this.tokenUsage.output = parseNum(outputMatch[1]);
171
+ }
172
+ }
173
+ // Fallback cost estimation if input/output is updated but cost is 0/unmatched
174
+ if (this.tokenUsage.cost === 0 && (this.tokenUsage.input > 0 || this.tokenUsage.output > 0)) {
175
+ this.tokenUsage.cost = this.tokenUsage.input * 0.000003 + this.tokenUsage.output * 0.000015;
176
+ }
177
+ this.logTokenUsageUpdate();
178
+ }
179
+ getStatus() {
180
+ if (!this.hasAnalyzedInitialState && this.status === 'running') {
181
+ this.analyzeState();
182
+ this.hasAnalyzedInitialState = true;
183
+ }
184
+ return {
185
+ id: this.id,
186
+ name: this.name,
187
+ type: this.type,
188
+ status: this.status,
189
+ createdAt: this.createdAt,
190
+ logsCount: this.logs.length,
191
+ workspaceRoot: this.workspaceRoot || (this.type === 'shell' ? process.env.ORIGINAL_CWD || process.cwd() : undefined),
192
+ scopedDirs: this.scopedDirs,
193
+ lastSyncedWorkspaceFolders: this.lastSyncedWorkspaceFolders,
194
+ tokenUsage: this.tokenUsage,
195
+ agentState: this.agentState
196
+ };
197
+ }
198
+ resize(_cols, _rows) {
199
+ // No-op by default, overridden by PTY runners
200
+ }
201
+ listeners = [];
202
+ onOutput(callback) {
203
+ this.listeners.push(callback);
204
+ }
205
+ offOutput(callback) {
206
+ this.listeners = this.listeners.filter((cb)=>cb !== callback);
207
+ }
208
+ emitOutput(data) {
209
+ this.updateAgentState(data);
210
+ this.listeners.forEach((cb)=>cb(data));
211
+ }
212
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ async writeToPty(ptyProcess, text) {
213
+ if (!ptyProcess) return;
214
+ const isWin = process.platform === "win32";
215
+ if (isWin && text.length > 100) {
216
+ const chunkSize = 128;
217
+ for(let i = 0; i < text.length; i += chunkSize){
218
+ const chunk = text.slice(i, i + chunkSize);
219
+ ptyProcess.write(chunk);
220
+ await new Promise((resolve)=>setTimeout(resolve, 10));
221
+ }
222
+ } else {
223
+ ptyProcess.write(text);
224
+ }
225
+ }
226
+ updateAgentState(newData) {
227
+ if (this.status !== 'running') {
228
+ this.agentState = 'idle';
229
+ return;
230
+ }
231
+ const isTelemetry = /\[Telemetry\]/i.test(newData);
232
+ if (newData.trim().length > 0 && !isTelemetry) {
233
+ this.agentState = 'thinking';
234
+ }
235
+ if (this.stateTimer) {
236
+ clearTimeout(this.stateTimer);
237
+ }
238
+ this.stateTimer = setTimeout(()=>{
239
+ this.analyzeState();
240
+ }, 800);
241
+ }
242
+ analyzeState() {
243
+ if (this.status !== 'running') {
244
+ this.agentState = 'idle';
245
+ return;
246
+ }
247
+ // Filter out telemetry lines to prevent shifting the prompt/question out of the logs tail
248
+ const nonTelemetryLogs = this.logs.filter((line)=>!/\[Telemetry\]/i.test(line));
249
+ const tailLines = nonTelemetryLogs.slice(-5).join("");
250
+ const cleanTail = tailLines.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, "").trim();
251
+ const isPrompt = cleanTail.endsWith(">") || cleanTail.endsWith("> ") || /([a-zA-Z0-9_-]+>\s*)$/.test(cleanTail) || cleanTail.endsWith("$") || cleanTail.endsWith("$ ");
252
+ const isQuestion = /(\[y\/n\]|\(y\/n\)|\?|confirm|allow|should I|would you|press enter|proceed)/i.test(cleanTail);
253
+ if (isPrompt) {
254
+ if (this.agentState === 'thinking' || this.agentState === 'needs-input') {
255
+ this.agentState = 'complete';
256
+ if (this.idleTimer) clearTimeout(this.idleTimer);
257
+ this.idleTimer = setTimeout(()=>{
258
+ if (this.agentState === 'complete') {
259
+ this.agentState = 'idle';
260
+ }
261
+ }, 5000);
262
+ }
263
+ } else if (isQuestion) {
264
+ this.agentState = 'needs-input';
265
+ }
266
+ }
267
+ }
268
+ }),
269
+ "[externals]/os [external] (os, cjs)", ((__turbopack_context__, module, exports) => {
270
+
271
+ const mod = __turbopack_context__.x("os", () => require("os"));
272
+
273
+ module.exports = mod;
274
+ }),
275
+ "[project]/src/lib/config.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
276
+ "use strict";
277
+
278
+ __turbopack_context__.s([
279
+ "getConfigDir",
280
+ ()=>getConfigDir,
281
+ "getDefaultWorkspaceRoot",
282
+ ()=>getDefaultWorkspaceRoot,
283
+ "isDirWritable",
284
+ ()=>isDirWritable,
285
+ "isSystemDirectory",
286
+ ()=>isSystemDirectory
287
+ ]);
288
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
289
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
290
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$os__$5b$external$5d$__$28$os$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/os [external] (os, cjs)");
291
+ ;
292
+ ;
293
+ ;
294
+ let cachedConfigDir = null;
295
+ function getConfigDir() {
296
+ if (cachedConfigDir) {
297
+ return cachedConfigDir;
298
+ }
299
+ const primaryDir = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(process.env.ORIGINAL_CWD || process.cwd(), ".ai", "neural-loom");
300
+ try {
301
+ // Check if primary directory exists. If not, try to create it.
302
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(primaryDir)) {
303
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(primaryDir, {
304
+ recursive: true
305
+ });
306
+ }
307
+ // Perform a test write to verify write permissions (crucial for read-only directories like C:\Program Files)
308
+ const testFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(primaryDir, ".write-test-" + Math.random().toString(36).substring(7));
309
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(testFile, "test");
310
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].unlinkSync(testFile);
311
+ cachedConfigDir = primaryDir;
312
+ return primaryDir;
313
+ } catch (err) {
314
+ // If EPERM or any other write error occurs, fall back to the user's home directory
315
+ console.warn(`[Config] Primary config dir is not writable (${primaryDir}). Falling back to home directory.`);
316
+ const fallbackDir = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(__TURBOPACK__imported__module__$5b$externals$5d2f$os__$5b$external$5d$__$28$os$2c$__cjs$29$__["default"].homedir(), ".ai", "neural-loom");
317
+ try {
318
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(fallbackDir)) {
319
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(fallbackDir, {
320
+ recursive: true
321
+ });
322
+ }
323
+ cachedConfigDir = fallbackDir;
324
+ return fallbackDir;
325
+ } catch (fallbackErr) {
326
+ console.error("[Config] Fallback config dir is also not writable!", fallbackErr);
327
+ cachedConfigDir = primaryDir;
328
+ return primaryDir;
329
+ }
330
+ }
331
+ }
332
+ function isDirWritable(dir) {
333
+ try {
334
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(dir)) {
335
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(dir, {
336
+ recursive: true
337
+ });
338
+ }
339
+ const testFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(dir, ".write-test-" + Math.random().toString(36).substring(7));
340
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(testFile, "test");
341
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].unlinkSync(testFile);
342
+ return true;
343
+ } catch {
344
+ return false;
345
+ }
346
+ }
347
+ function isSystemDirectory(dir) {
348
+ const normalized = dir.toLowerCase().replace(/\\/g, "/");
349
+ return normalized.includes("/program files") || normalized.includes("/windows/system32") || normalized.includes("/winnt") || normalized.startsWith("/usr/") || normalized.startsWith("/bin/") || normalized.startsWith("/sbin/") || normalized.startsWith("/etc/") || normalized.startsWith("/var/");
350
+ }
351
+ function getDefaultWorkspaceRoot() {
352
+ const launchDir = process.env.ORIGINAL_CWD || process.cwd();
353
+ if (isDirWritable(launchDir) && !isSystemDirectory(launchDir)) {
354
+ return launchDir.replace(/\\/g, "/");
355
+ }
356
+ const home = __TURBOPACK__imported__module__$5b$externals$5d2f$os__$5b$external$5d$__$28$os$2c$__cjs$29$__["default"].homedir();
357
+ const commonDirs = [
358
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(home, "OneDrive", "Projects"),
359
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(home, "Projects"),
360
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(home, "source", "repos"),
361
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(home, "Documents"),
362
+ home
363
+ ];
364
+ for (const dir of commonDirs){
365
+ try {
366
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(dir) && isDirWritable(dir)) {
367
+ return dir.replace(/\\/g, "/");
368
+ }
369
+ } catch {
370
+ // Continue checking
371
+ }
372
+ }
373
+ return home.replace(/\\/g, "/");
374
+ }
375
+ }),
376
+ "[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
377
+ "use strict";
378
+
379
+ __turbopack_context__.s([
380
+ "SessionPersister",
381
+ ()=>SessionPersister
382
+ ]);
383
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
384
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
385
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/config.ts [app-route] (ecmascript)");
386
+ ;
387
+ ;
388
+ ;
389
+ class SessionPersister {
390
+ static pendingSaves = new Map();
391
+ static pendingData = new Map();
392
+ static getSessionsDir() {
393
+ const dir = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getConfigDir"])(), "sessions");
394
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(dir)) {
395
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(dir, {
396
+ recursive: true
397
+ });
398
+ }
399
+ return dir;
400
+ }
401
+ static saveSession(session, immediate = false) {
402
+ const data = {
403
+ id: session.id,
404
+ name: session.name,
405
+ type: session.type,
406
+ status: session.status === 'running' && session.type === 'mock' ? 'running' : session.status,
407
+ createdAt: session.createdAt,
408
+ logs: session.logs,
409
+ workspaceRoot: session.workspaceRoot,
410
+ scopedDirs: session.scopedDirs,
411
+ lastSyncedWorkspaceFolders: session.lastSyncedWorkspaceFolders
412
+ };
413
+ if (immediate) {
414
+ // Clear any pending debounced save
415
+ const timer = this.pendingSaves.get(session.id);
416
+ if (timer) {
417
+ clearTimeout(timer);
418
+ this.pendingSaves.delete(session.id);
419
+ }
420
+ this.pendingData.delete(session.id);
421
+ this.writeToDisk(session.id, data);
422
+ return;
423
+ }
424
+ // Update pending data
425
+ this.pendingData.set(session.id, data);
426
+ // Schedule save if not already scheduled
427
+ if (!this.pendingSaves.has(session.id)) {
428
+ const timer = setTimeout(()=>{
429
+ this.pendingSaves.delete(session.id);
430
+ const dataToWrite = this.pendingData.get(session.id);
431
+ if (dataToWrite) {
432
+ this.pendingData.delete(session.id);
433
+ this.writeToDisk(session.id, dataToWrite);
434
+ }
435
+ }, 1000); // 1-second debounce
436
+ this.pendingSaves.set(session.id, timer);
437
+ }
438
+ }
439
+ static writeToDisk(id, data) {
440
+ try {
441
+ const dir = this.getSessionsDir();
442
+ const filePath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(dir, `${id}.json`);
443
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFile(filePath, JSON.stringify(data, null, 2), "utf8", (err)=>{
444
+ if (err) {
445
+ console.error(`[SessionPersister] Failed to save session ${id} asynchronously:`, err);
446
+ }
447
+ });
448
+ } catch (err) {
449
+ console.error(`[SessionPersister] Failed to save session ${id}:`, err);
450
+ }
451
+ }
452
+ static loadAllSessions() {
453
+ try {
454
+ const dir = this.getSessionsDir();
455
+ const files = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readdirSync(dir);
456
+ const sessions = [];
457
+ for (const file of files){
458
+ if (file.endsWith(".json")) {
459
+ const filePath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(dir, file);
460
+ try {
461
+ const raw = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(filePath, "utf8");
462
+ const data = JSON.parse(raw);
463
+ // On server restart, active PTY processes (which are dead) are marked stopped
464
+ if (data.status === "running" && data.type !== "mock") {
465
+ data.status = "stopped";
466
+ data.logs.push("\r\n\x1b[1;31m[System] Server restarted. Terminal connection lost.\x1b[0m\r\n");
467
+ // Save the updated status back to disk
468
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(filePath, JSON.stringify(data, null, 2), "utf8");
469
+ }
470
+ sessions.push(data);
471
+ } catch (fileErr) {
472
+ console.error(`[SessionPersister] Failed to load session file ${file}:`, fileErr);
473
+ }
474
+ }
475
+ }
476
+ return sessions;
477
+ } catch (err) {
478
+ console.error("[SessionPersister] Failed to load sessions:", err);
479
+ return [];
480
+ }
481
+ }
482
+ static cancelPendingSave(id) {
483
+ const timer = this.pendingSaves.get(id);
484
+ if (timer) {
485
+ clearTimeout(timer);
486
+ this.pendingSaves.delete(id);
487
+ }
488
+ this.pendingData.delete(id);
489
+ }
490
+ static deleteSession(id) {
491
+ this.cancelPendingSave(id);
492
+ try {
493
+ const dir = this.getSessionsDir();
494
+ const filePath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(dir, `${id}.json`);
495
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(filePath)) {
496
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].unlinkSync(filePath);
497
+ }
498
+ } catch (err) {
499
+ console.error(`[SessionPersister] Failed to delete session ${id}:`, err);
500
+ }
501
+ }
502
+ }
503
+ }),
504
+ "[project]/src/lib/agents/MockRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
505
+ "use strict";
506
+
507
+ __turbopack_context__.s([
508
+ "MockRunner",
509
+ ()=>MockRunner
510
+ ]);
511
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)");
512
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)");
513
+ ;
514
+ ;
515
+ class MockRunner extends __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AgentRunner"] {
516
+ id;
517
+ name;
518
+ type = 'mock';
519
+ status = 'idle';
520
+ createdAt;
521
+ logs = [];
522
+ intervalId = null;
523
+ awaitingConfirmation = false;
524
+ mockSteps = [
525
+ "[NeuralLoom] Loading virtual PTY context...",
526
+ "[NeuralLoom] Spawning sandbox mock runtime environment...",
527
+ "[Mock Agent] Model online (v2.0-mock-flash). Dedicated memory allocated.",
528
+ "[Mock Agent] System rules parsed successfully from global context registry.",
529
+ "[Mock Agent] Awaiting developer commands. Type '/help' to list mock skills.",
530
+ "mock-agent> "
531
+ ];
532
+ stepIndex = 0;
533
+ constructor(id, name){
534
+ super();
535
+ this.id = id;
536
+ this.name = name || `Mock Session ${id.substring(0, 8)}`;
537
+ this.createdAt = new Date().toISOString();
538
+ }
539
+ appendLog(line) {
540
+ this.logs.push(line);
541
+ this.parseTokenUsage(line);
542
+ this.emitOutput(line + "\r\n");
543
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(this);
544
+ }
545
+ async start(resume) {
546
+ if (this.status === 'running') return;
547
+ this.status = 'running';
548
+ // Add banner
549
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m");
550
+ this.appendLog("\x1b[1;36m NEURALLOOM SIMULATED AGENT ENVIRONMENT \x1b[0m");
551
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m");
552
+ // Post initial log immediately
553
+ if (this.stepIndex < this.mockSteps.length) {
554
+ this.appendLog(this.mockSteps[this.stepIndex++]);
555
+ }
556
+ // Schedule subsequent logs
557
+ this.intervalId = setInterval(()=>{
558
+ this.tokenUsage.input += Math.floor(Math.random() * 50) + 10;
559
+ this.tokenUsage.output += Math.floor(Math.random() * 20) + 5;
560
+ this.tokenUsage.cost = this.tokenUsage.input * 0.000003 + this.tokenUsage.output * 0.000015;
561
+ if (this.stepIndex < this.mockSteps.length) {
562
+ this.appendLog(this.mockSteps[this.stepIndex++]);
563
+ } else {
564
+ // Just general ambient telemetry mock log
565
+ const time = new Date().toLocaleTimeString();
566
+ this.appendLog(`[${time}] [Telemetry] CPU utilization 1.2% | Memory 142MB | Link stable.`);
567
+ }
568
+ }, 4000);
569
+ }
570
+ async stop() {
571
+ this.status = 'stopped';
572
+ if (this.intervalId) {
573
+ clearInterval(this.intervalId);
574
+ this.intervalId = null;
575
+ }
576
+ this.appendLog("\x1b[1;31m[System] Process terminated. Connection closed.\x1b[0m");
577
+ }
578
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
579
+ async sendInput(text, _isRaw) {
580
+ if (this.status !== 'running') {
581
+ this.appendLog(`\x1b[1;31m[Error] Cannot write input: process is ${this.status}.\x1b[0m`);
582
+ return;
583
+ }
584
+ // Echo the command back as user prompt
585
+ this.appendLog(`\x1b[1;32m> ${text}\x1b[0m`);
586
+ // Simulated parser responses
587
+ setTimeout(()=>{
588
+ const cleanInput = text.trim().toLowerCase();
589
+ if (this.awaitingConfirmation) {
590
+ if (cleanInput === 'y' || cleanInput === 'yes') {
591
+ this.appendLog("[Mock Agent] Proceeding with production deployment...");
592
+ setTimeout(()=>{
593
+ this.appendLog("[Mock Agent] Deploying build artifacts to edge network...");
594
+ this.appendLog("[Mock Agent] Deployment complete. Site live!");
595
+ this.appendLog("mock-agent> ");
596
+ }, 1000);
597
+ } else if (cleanInput === 'n' || cleanInput === 'no') {
598
+ this.appendLog("[Mock Agent] Deployment aborted.");
599
+ this.appendLog("mock-agent> ");
600
+ } else {
601
+ this.appendLog("[Mock Agent] Invalid input. Please confirm with y/n:");
602
+ return; // Remain in confirmation state
603
+ }
604
+ this.awaitingConfirmation = false;
605
+ return;
606
+ }
607
+ if (cleanInput === '/help') {
608
+ this.appendLog("[Mock Agent] Available commands:");
609
+ this.appendLog(" /help - List available mock commands.");
610
+ this.appendLog(" /status - Fetch current agent diagnostic metrics.");
611
+ this.appendLog(" /context - View loaded staging files.");
612
+ this.appendLog(" /deploy - Trigger production deployment wizard (requires confirmation).");
613
+ this.appendLog(" /clear - Flush terminal console buffer.");
614
+ this.appendLog("mock-agent> ");
615
+ } else if (cleanInput === '/status') {
616
+ this.appendLog("[Mock Agent] Diagnostics:");
617
+ this.appendLog(" - Connection Type: WebSocket gateway (mock)");
618
+ this.appendLog(` - Active Runtime: ${this.id}`);
619
+ this.appendLog(" - Sandbox State: Healthy (0 warnings)");
620
+ this.appendLog("mock-agent> ");
621
+ } else if (cleanInput === '/context') {
622
+ this.appendLog("[Mock Agent] Loaded Workspace Context Files:");
623
+ this.appendLog(" - [Mounted] src/app/globals.css (Modified)");
624
+ this.appendLog(" - [Mounted] src/app/page.tsx");
625
+ this.appendLog("mock-agent> ");
626
+ } else if (cleanInput === '/deploy') {
627
+ this.appendLog("[Mock Agent] Starting production deployment...");
628
+ this.appendLog("[Mock Agent] Warning: This will push current local build to server.");
629
+ this.appendLog("[Mock Agent] Are you sure you want to proceed? (y/n)");
630
+ this.awaitingConfirmation = true;
631
+ } else if (cleanInput === '/clear') {
632
+ this.logs = [];
633
+ this.appendLog("\x1b[1;33m[Console Cleared]\x1b[0m");
634
+ this.appendLog("mock-agent> ");
635
+ } else {
636
+ this.appendLog(`[Mock Agent] Received command: "${text}". Processing...`);
637
+ setTimeout(()=>{
638
+ this.appendLog(`[Mock Agent] Done. Task simulated successfully.`);
639
+ this.appendLog("mock-agent> ");
640
+ }, 1500);
641
+ }
642
+ }, 400);
643
+ }
644
+ }
645
+ }),
646
+ "[externals]/child_process [external] (child_process, cjs)", ((__turbopack_context__, module, exports) => {
647
+
648
+ const mod = __turbopack_context__.x("child_process", () => require("child_process"));
649
+
650
+ module.exports = mod;
651
+ }),
652
+ "[project]/src/lib/agents/ClaudeRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
653
+ "use strict";
654
+
655
+ __turbopack_context__.s([
656
+ "ClaudeRunner",
657
+ ()=>ClaudeRunner
658
+ ]);
659
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
660
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
661
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$os__$5b$external$5d$__$28$os$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/os [external] (os, cjs)");
662
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$child_process__$5b$external$5d$__$28$child_process$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/child_process [external] (child_process, cjs)");
663
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/config.ts [app-route] (ecmascript)");
664
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)");
665
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)");
666
+ ;
667
+ ;
668
+ ;
669
+ ;
670
+ ;
671
+ ;
672
+ ;
673
+ function isWindows() {
674
+ return typeof process !== "undefined" && process.platform === "win32";
675
+ }
676
+ function findGitBash() {
677
+ if (!isWindows()) {
678
+ return "bash";
679
+ }
680
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
681
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
682
+ const local = process.env.LOCALAPPDATA || "";
683
+ const candidates = [
684
+ process.env.WINGMAN_BASH_PATH,
685
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf, "Git", "bin", "bash.exe"),
686
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf86, "Git", "bin", "bash.exe"),
687
+ local ? __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(local, "Programs", "Git", "bin", "bash.exe") : ""
688
+ ].filter((p)=>typeof p === "string" && p !== "");
689
+ return candidates.find((p)=>__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(p)) || null;
690
+ }
691
+ class ClaudeRunner extends __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AgentRunner"] {
692
+ id;
693
+ name;
694
+ type = 'claude';
695
+ status = 'idle';
696
+ createdAt;
697
+ logs = [];
698
+ ptyProcess = null;
699
+ ptyModule = null;
700
+ constructor(id, name){
701
+ super();
702
+ this.id = id;
703
+ this.name = name || `Claude Session ${id.substring(0, 8)}`;
704
+ this.createdAt = new Date().toISOString();
705
+ }
706
+ appendLog(line) {
707
+ this.logs.push(line);
708
+ if (this.logs.length > 5000) {
709
+ this.logs.shift();
710
+ }
711
+ this.parseTokenUsage(line);
712
+ this.emitOutput(line);
713
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(this);
714
+ }
715
+ async start(resume) {
716
+ if (this.status === 'running') return;
717
+ // Detect Git Bash on Windows
718
+ const useCmd = isWindows();
719
+ const shellPath = useCmd ? process.env.COMSPEC || "cmd.exe" : findGitBash();
720
+ if (!shellPath) {
721
+ this.status = 'stopped';
722
+ this.appendLog("\x1b[1;31m[System Error] Shell not found. Cannot spawn terminal.\x1b[0m\r\n");
723
+ return;
724
+ }
725
+ const shellArgs = useCmd ? [
726
+ "/c"
727
+ ] : [
728
+ "-c"
729
+ ];
730
+ try {
731
+ // Dynamic import to prevent bundler SSR/Turbopack errors on server start
732
+ if (!this.ptyModule) {
733
+ this.ptyModule = eval("require")("node-pty");
734
+ }
735
+ this.status = 'running';
736
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
737
+ this.appendLog("\x1b[1;36m NEURALLOOM ACTIVE CLAUDE TERMINAL ROUTE \x1b[0m\r\n");
738
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
739
+ const targetCwd = this.workspaceRoot && __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(this.workspaceRoot) ? this.workspaceRoot : process.env.ORIGINAL_CWD || process.cwd();
740
+ // Load Claude configuration to check for extraFlags (like --resume)
741
+ let extraFlags = "";
742
+ if (resume) {
743
+ extraFlags = "--resume";
744
+ } else {
745
+ const claudeConfigPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getConfigDir"])(), "claude.json");
746
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(claudeConfigPath)) {
747
+ try {
748
+ const config = JSON.parse(__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(claudeConfigPath, "utf8"));
749
+ if (config.extraFlags) {
750
+ extraFlags = config.extraFlags;
751
+ }
752
+ } catch (err) {
753
+ console.error("Failed to parse Claude configuration:", err);
754
+ }
755
+ }
756
+ }
757
+ // Setup process environment with injected keys
758
+ const customEnv = {
759
+ ...process.env,
760
+ TERM: "xterm-256color",
761
+ COLORTERM: "truecolor"
762
+ };
763
+ if (isWindows()) {
764
+ const vsNode = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Microsoft\\VisualStudio\\NodeJs";
765
+ const localNpm = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(__TURBOPACK__imported__module__$5b$externals$5d2f$os__$5b$external$5d$__$28$os$2c$__cjs$29$__["default"].homedir(), "AppData", "Local", "npm");
766
+ const existingPath = process.env.Path || process.env.PATH || "";
767
+ const winPath = [
768
+ vsNode,
769
+ localNpm,
770
+ existingPath
771
+ ].filter(Boolean).join(";");
772
+ for (const key of Object.keys(customEnv)){
773
+ if (key.toLowerCase() === "path") {
774
+ delete customEnv[key];
775
+ }
776
+ }
777
+ customEnv.Path = winPath;
778
+ customEnv.PATH = winPath;
779
+ }
780
+ // Check if 'claude' command exists in PATH, fallback to npx if not
781
+ let baseCmd = "claude";
782
+ try {
783
+ const checkCmd = isWindows() ? "where.exe claude" : "which claude";
784
+ (0, __TURBOPACK__imported__module__$5b$externals$5d2f$child_process__$5b$external$5d$__$28$child_process$2c$__cjs$29$__["execSync"])(checkCmd, {
785
+ env: customEnv,
786
+ stdio: "ignore"
787
+ });
788
+ } catch {
789
+ baseCmd = "npx -y @anthropic-ai/claude-code";
790
+ }
791
+ const claudeCmd = `${baseCmd} ${extraFlags}`.trim();
792
+ this.appendLog(`[System] Spawning command: ${claudeCmd}\r\n`);
793
+ // Spawn shell and run 'claude' command
794
+ this.ptyProcess = this.ptyModule.spawn(shellPath, [
795
+ ...shellArgs,
796
+ claudeCmd
797
+ ], {
798
+ name: "xterm-256color",
799
+ cols: 120,
800
+ rows: 30,
801
+ cwd: targetCwd,
802
+ env: customEnv
803
+ });
804
+ // Capture output
805
+ this.ptyProcess.onData((data)=>{
806
+ this.appendLog(data);
807
+ });
808
+ // Capture process exit
809
+ this.ptyProcess.onExit(({ exitCode, signal })=>{
810
+ this.status = 'stopped';
811
+ this.appendLog(`\r\n\x1b[1;31m[System] Claude Code PTY process exited (code=${exitCode}, signal=${signal}).\x1b[0m\r\n`);
812
+ this.ptyProcess = null;
813
+ });
814
+ } catch (err) {
815
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
816
+ this.status = 'stopped';
817
+ this.appendLog(`\x1b[1;31m[System Error] Failed to initialize node-pty runner: ${errorMessage}\x1b[0m\r\n`);
818
+ console.error("Failed to start Claude PTY runner:", err);
819
+ }
820
+ }
821
+ async stop() {
822
+ this.status = 'stopped';
823
+ if (this.ptyProcess) {
824
+ try {
825
+ this.ptyProcess.kill();
826
+ } catch (err) {
827
+ console.error("Error killing PTY process:", err);
828
+ }
829
+ this.ptyProcess = null;
830
+ }
831
+ this.appendLog("\r\n\x1b[1;31m[System] Terminal bridge terminated.\x1b[0m\r\n");
832
+ }
833
+ async sendInput(text, isRaw = false) {
834
+ if (this.status !== 'running' || !this.ptyProcess) {
835
+ this.appendLog(`\r\n\x1b[1;31m[Error] Cannot write: session process is ${this.status}.\x1b[0m\r\n`);
836
+ return;
837
+ }
838
+ this.agentState = 'thinking';
839
+ await this.writeToPty(this.ptyProcess, isRaw ? text : text + "\r");
840
+ }
841
+ resize(cols, rows) {
842
+ if (this.ptyProcess) {
843
+ try {
844
+ this.ptyProcess.resize(cols, rows);
845
+ } catch (err) {
846
+ console.error("[ClaudeRunner] Failed to resize PTY:", err);
847
+ }
848
+ }
849
+ }
850
+ }
851
+ }),
852
+ "[project]/src/lib/agents/DockerRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
853
+ "use strict";
854
+
855
+ __turbopack_context__.s([
856
+ "DockerRunner",
857
+ ()=>DockerRunner
858
+ ]);
859
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
860
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
861
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/config.ts [app-route] (ecmascript)");
862
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)");
863
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)");
864
+ ;
865
+ ;
866
+ ;
867
+ ;
868
+ ;
869
+ function isWindows() {
870
+ return typeof process !== "undefined" && process.platform === "win32";
871
+ }
872
+ function findGitBash() {
873
+ if (!isWindows()) {
874
+ return "bash";
875
+ }
876
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
877
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
878
+ const local = process.env.LOCALAPPDATA || "";
879
+ const candidates = [
880
+ process.env.WINGMAN_BASH_PATH,
881
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf, "Git", "bin", "bash.exe"),
882
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf86, "Git", "bin", "bash.exe"),
883
+ local ? __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(local, "Programs", "Git", "bin", "bash.exe") : ""
884
+ ].filter((p)=>typeof p === "string" && p !== "");
885
+ return candidates.find((p)=>__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(p)) || null;
886
+ }
887
+ class DockerRunner extends __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AgentRunner"] {
888
+ id;
889
+ name;
890
+ type = 'claude-docker';
891
+ status = 'idle';
892
+ createdAt;
893
+ logs = [];
894
+ ptyProcess = null;
895
+ ptyModule = null;
896
+ constructor(id, name){
897
+ super();
898
+ this.id = id;
899
+ this.name = name || `Docker Session ${id.substring(0, 8)}`;
900
+ this.createdAt = new Date().toISOString();
901
+ }
902
+ appendLog(line) {
903
+ this.logs.push(line);
904
+ if (this.logs.length > 5000) {
905
+ this.logs.shift();
906
+ }
907
+ this.parseTokenUsage(line);
908
+ this.emitOutput(line);
909
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(this);
910
+ }
911
+ async start(resume) {
912
+ if (this.status === 'running') return;
913
+ this.status = 'running';
914
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
915
+ this.appendLog("\x1b[1;36m NEURALLOOM DOCKER SANDBOX RUNTIME BRIDGE \x1b[0m\r\n");
916
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
917
+ this.appendLog("[System] Verifying Docker environment accessibility...\r\n");
918
+ const bashPath = findGitBash();
919
+ if (!bashPath) {
920
+ this.status = 'stopped';
921
+ this.appendLog("\x1b[1;31m[System Error] Git Bash not found. Cannot bootstrap PTY sandbox.\x1b[0m\r\n");
922
+ return;
923
+ }
924
+ try {
925
+ if (!this.ptyModule) {
926
+ this.ptyModule = eval("require")("node-pty");
927
+ }
928
+ const targetCwd = this.workspaceRoot && __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(this.workspaceRoot) ? this.workspaceRoot : process.env.ORIGINAL_CWD || process.cwd();
929
+ // Check if docker executable exists by spawning `docker -v`
930
+ const testPty = this.ptyModule.spawn(bashPath, [
931
+ "-c",
932
+ "docker --version"
933
+ ], {
934
+ name: "xterm-256color",
935
+ cols: 80,
936
+ rows: 10,
937
+ cwd: targetCwd
938
+ });
939
+ let hasDocker = false;
940
+ testPty.onData((data)=>{
941
+ if (data.toLowerCase().includes("docker version")) {
942
+ hasDocker = true;
943
+ }
944
+ });
945
+ // Wait briefly for docker check
946
+ await new Promise((resolve)=>setTimeout(resolve, 800));
947
+ testPty.kill();
948
+ if (!hasDocker) {
949
+ this.status = 'stopped';
950
+ this.appendLog("\x1b[1;31m[Dependency Warning] Docker command not recognized in local PATH.\x1b[0m\r\n");
951
+ this.appendLog("\x1b[1;33mPlease install Docker Desktop (https://www.docker.com/products/docker-desktop) and ensure the daemon is running.\x1b[0m\r\n");
952
+ this.appendLog("\x1b[1;31m[System] Sandbox launch aborted.\x1b[0m\r\n");
953
+ return;
954
+ }
955
+ // If docker is available, spawn container with mounted workspace
956
+ this.appendLog("[System] Docker detected. Initializing container mount...\r\n");
957
+ const mounts = [
958
+ `-v "${targetCwd}:/workspace"`
959
+ ];
960
+ if (this.scopedDirs && Array.isArray(this.scopedDirs)) {
961
+ this.scopedDirs.forEach((dir)=>{
962
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(dir)) {
963
+ const folderName = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].basename(dir).replace(/[^a-zA-Z0-9-_]/g, "_");
964
+ mounts.push(`-v "${dir}:/scoped/${folderName}"`);
965
+ }
966
+ });
967
+ }
968
+ const mountsStr = mounts.join(" ");
969
+ // Load Claude configuration to check for extraFlags (like --resume)
970
+ let extraFlags = "";
971
+ if (resume) {
972
+ extraFlags = "--resume";
973
+ } else {
974
+ const claudeConfigPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getConfigDir"])(), "claude.json");
975
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(claudeConfigPath)) {
976
+ try {
977
+ const config = JSON.parse(__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(claudeConfigPath, "utf8"));
978
+ if (config.extraFlags) {
979
+ extraFlags = config.extraFlags;
980
+ }
981
+ } catch (err) {
982
+ console.error("Failed to parse Claude configuration:", err);
983
+ }
984
+ }
985
+ }
986
+ const dockerCmd = `docker run -it --name neural-loom-session-${this.id} --rm ${mountsStr} -w /workspace node:20-alpine npx -y @anthropic-ai/claude-code ${extraFlags}`.trim();
987
+ this.ptyProcess = this.ptyModule.spawn(bashPath, [
988
+ "-c",
989
+ dockerCmd
990
+ ], {
991
+ name: "xterm-256color",
992
+ cols: 120,
993
+ rows: 30,
994
+ cwd: targetCwd,
995
+ env: {
996
+ ...process.env,
997
+ TERM: "xterm-256color",
998
+ COLORTERM: "truecolor"
999
+ }
1000
+ });
1001
+ this.ptyProcess.onData((data)=>{
1002
+ this.appendLog(data);
1003
+ });
1004
+ this.ptyProcess.onExit(({ exitCode, signal })=>{
1005
+ this.status = 'stopped';
1006
+ this.appendLog(`\r\n\x1b[1;31m[System] Docker Sandbox exited (code=${exitCode}, signal=${signal}).\x1b[0m\r\n`);
1007
+ this.ptyProcess = null;
1008
+ });
1009
+ } catch (err) {
1010
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
1011
+ this.status = 'stopped';
1012
+ this.appendLog(`\x1b[1;31m[System Error] Failed to launch Docker runner: ${errorMessage}\x1b[0m\r\n`);
1013
+ }
1014
+ }
1015
+ async stop() {
1016
+ this.status = 'stopped';
1017
+ if (this.ptyProcess) {
1018
+ try {
1019
+ this.ptyProcess.kill();
1020
+ } catch (err) {
1021
+ console.error("Error killing Docker PTY process:", err);
1022
+ }
1023
+ this.ptyProcess = null;
1024
+ }
1025
+ this.appendLog("\r\n\x1b[1;31m[System] Docker container stopped and unmounted.\x1b[0m\r\n");
1026
+ }
1027
+ async sendInput(text, isRaw = false) {
1028
+ if (this.status !== 'running' || !this.ptyProcess) {
1029
+ this.appendLog(`\r\n\x1b[1;31m[Error] Cannot write: Docker container is ${this.status}.\x1b[0m\r\n`);
1030
+ return;
1031
+ }
1032
+ this.agentState = 'thinking';
1033
+ await this.writeToPty(this.ptyProcess, isRaw ? text : text + "\r");
1034
+ }
1035
+ resize(cols, rows) {
1036
+ if (this.ptyProcess) {
1037
+ try {
1038
+ this.ptyProcess.resize(cols, rows);
1039
+ } catch (err) {
1040
+ console.error("[DockerRunner] Failed to resize PTY:", err);
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ }),
1046
+ "[project]/src/lib/agents/SSHRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
1047
+ "use strict";
1048
+
1049
+ __turbopack_context__.s([
1050
+ "SSHRunner",
1051
+ ()=>SSHRunner
1052
+ ]);
1053
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
1054
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
1055
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/config.ts [app-route] (ecmascript)");
1056
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)");
1057
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)");
1058
+ ;
1059
+ ;
1060
+ ;
1061
+ ;
1062
+ ;
1063
+ function isWindows() {
1064
+ return typeof process !== "undefined" && process.platform === "win32";
1065
+ }
1066
+ function findGitBash() {
1067
+ if (!isWindows()) {
1068
+ return "bash";
1069
+ }
1070
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
1071
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
1072
+ const local = process.env.LOCALAPPDATA || "";
1073
+ const candidates = [
1074
+ process.env.WINGMAN_BASH_PATH,
1075
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf, "Git", "bin", "bash.exe"),
1076
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf86, "Git", "bin", "bash.exe"),
1077
+ local ? __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(local, "Programs", "Git", "bin", "bash.exe") : ""
1078
+ ].filter((p)=>typeof p === "string" && p !== "");
1079
+ return candidates.find((p)=>__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(p)) || null;
1080
+ }
1081
+ class SSHRunner extends __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AgentRunner"] {
1082
+ id;
1083
+ name;
1084
+ type = 'claude-ssh';
1085
+ status = 'idle';
1086
+ createdAt;
1087
+ logs = [];
1088
+ ptyProcess = null;
1089
+ ptyModule = null;
1090
+ constructor(id, name){
1091
+ super();
1092
+ this.id = id;
1093
+ this.name = name || `SSH Session ${id.substring(0, 8)}`;
1094
+ this.createdAt = new Date().toISOString();
1095
+ }
1096
+ appendLog(line) {
1097
+ this.logs.push(line);
1098
+ if (this.logs.length > 5000) {
1099
+ this.logs.shift();
1100
+ }
1101
+ this.parseTokenUsage(line);
1102
+ this.emitOutput(line);
1103
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(this);
1104
+ }
1105
+ async start(resume) {
1106
+ if (this.status === 'running') return;
1107
+ this.status = 'running';
1108
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
1109
+ this.appendLog("\x1b[1;36m NEURALLOOM REMOTE VM (SSH) ROUTE BRIDGE \x1b[0m\r\n");
1110
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
1111
+ this.appendLog("[System] Loading SSH configuration...\r\n");
1112
+ const bashPath = findGitBash();
1113
+ if (!bashPath) {
1114
+ this.status = 'stopped';
1115
+ this.appendLog("\x1b[1;31m[System Error] Git Bash not found. Cannot bootstrap SSH terminal.\x1b[0m\r\n");
1116
+ return;
1117
+ }
1118
+ const configPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getConfigDir"])(), "ssh.json");
1119
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(configPath)) {
1120
+ this.status = 'stopped';
1121
+ this.appendLog("\x1b[1;31m[Configuration Error] ssh.json not found!\x1b[0m\r\n");
1122
+ this.appendLog(`\x1b[1;33mPlease create the SSH credentials file at: ${configPath}\x1b[0m\r\n`);
1123
+ this.appendLog("\x1b[1;36mTemplate structure:\x1b[0m\r\n");
1124
+ this.appendLog(JSON.stringify({
1125
+ host: "your.remote.host.com",
1126
+ username: "dave",
1127
+ privateKeyPath: "C:\\\\Users\\\\Dave\\\\.ssh\\\\id_rsa",
1128
+ port: 22
1129
+ }, null, 2).replace(/\n/g, "\r\n") + "\r\n");
1130
+ this.appendLog("\x1b[1;31m[System] SSH startup aborted.\x1b[0m\r\n");
1131
+ return;
1132
+ }
1133
+ try {
1134
+ const rawConfig = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(configPath, "utf8");
1135
+ const config = JSON.parse(rawConfig);
1136
+ if (!config.host || !config.username) {
1137
+ this.status = 'stopped';
1138
+ this.appendLog("\x1b[1;31m[System Error] Invalid ssh.json configuration. 'host' and 'username' are required.\x1b[0m\r\n");
1139
+ return;
1140
+ }
1141
+ if (!this.ptyModule) {
1142
+ this.ptyModule = eval("require")("node-pty");
1143
+ }
1144
+ this.appendLog(`[System] Connecting to ${config.username}@${config.host}...\r\n`);
1145
+ const portOpt = config.port ? `-p ${config.port}` : "";
1146
+ const keyOpt = config.privateKeyPath ? `-i "${config.privateKeyPath}"` : "";
1147
+ // Load Claude configuration to check for extraFlags (like --resume)
1148
+ let extraFlags = "";
1149
+ if (resume) {
1150
+ extraFlags = "--resume";
1151
+ } else {
1152
+ const claudeConfigPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getConfigDir"])(), "claude.json");
1153
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(claudeConfigPath)) {
1154
+ try {
1155
+ const config = JSON.parse(__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(claudeConfigPath, "utf8"));
1156
+ if (config.extraFlags) {
1157
+ extraFlags = config.extraFlags;
1158
+ }
1159
+ } catch (err) {
1160
+ console.error("Failed to parse Claude configuration:", err);
1161
+ }
1162
+ }
1163
+ }
1164
+ const sshCmd = `ssh -t ${keyOpt} ${portOpt} ${config.username}@${config.host} "claude ${extraFlags}"`;
1165
+ this.ptyProcess = this.ptyModule.spawn(bashPath, [
1166
+ "-c",
1167
+ sshCmd
1168
+ ], {
1169
+ name: "xterm-256color",
1170
+ cols: 120,
1171
+ rows: 30,
1172
+ cwd: process.env.ORIGINAL_CWD || process.cwd(),
1173
+ env: {
1174
+ ...process.env,
1175
+ TERM: "xterm-256color",
1176
+ COLORTERM: "truecolor"
1177
+ }
1178
+ });
1179
+ this.ptyProcess.onData((data)=>{
1180
+ this.appendLog(data);
1181
+ });
1182
+ this.ptyProcess.onExit(({ exitCode, signal })=>{
1183
+ this.status = 'stopped';
1184
+ this.appendLog(`\r\n\x1b[1;31m[System] SSH Session exited (code=${exitCode}, signal=${signal}).\x1b[0m\r\n`);
1185
+ this.ptyProcess = null;
1186
+ });
1187
+ } catch (err) {
1188
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
1189
+ this.status = 'stopped';
1190
+ this.appendLog(`\x1b[1;31m[System Error] SSH connection failed: ${errorMessage}\x1b[0m\r\n`);
1191
+ }
1192
+ }
1193
+ async stop() {
1194
+ this.status = 'stopped';
1195
+ if (this.ptyProcess) {
1196
+ try {
1197
+ this.ptyProcess.kill();
1198
+ } catch (err) {
1199
+ console.error("Error killing SSH PTY process:", err);
1200
+ }
1201
+ this.ptyProcess = null;
1202
+ }
1203
+ this.appendLog("\r\n\x1b[1;31m[System] SSH Connection terminated.\x1b[0m\r\n");
1204
+ }
1205
+ async sendInput(text, isRaw = false) {
1206
+ if (this.status !== 'running' || !this.ptyProcess) {
1207
+ this.appendLog(`\r\n\x1b[1;31m[Error] Cannot write: SSH session is ${this.status}.\x1b[0m\r\n`);
1208
+ return;
1209
+ }
1210
+ this.agentState = 'thinking';
1211
+ await this.writeToPty(this.ptyProcess, isRaw ? text : text + "\r");
1212
+ }
1213
+ resize(cols, rows) {
1214
+ if (this.ptyProcess) {
1215
+ try {
1216
+ this.ptyProcess.resize(cols, rows);
1217
+ } catch (err) {
1218
+ console.error("[SSHRunner] Failed to resize PTY:", err);
1219
+ }
1220
+ }
1221
+ }
1222
+ }
1223
+ }),
1224
+ "[project]/src/lib/agents/AiderRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
1225
+ "use strict";
1226
+
1227
+ __turbopack_context__.s([
1228
+ "AiderRunner",
1229
+ ()=>AiderRunner
1230
+ ]);
1231
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
1232
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
1233
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$child_process__$5b$external$5d$__$28$child_process$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/child_process [external] (child_process, cjs)");
1234
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/config.ts [app-route] (ecmascript)");
1235
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)");
1236
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)");
1237
+ ;
1238
+ ;
1239
+ ;
1240
+ ;
1241
+ ;
1242
+ ;
1243
+ function isWindows() {
1244
+ return typeof process !== "undefined" && process.platform === "win32";
1245
+ }
1246
+ function findGitBash() {
1247
+ if (!isWindows()) {
1248
+ return "bash";
1249
+ }
1250
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
1251
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
1252
+ const local = process.env.LOCALAPPDATA || "";
1253
+ const candidates = [
1254
+ process.env.WINGMAN_BASH_PATH,
1255
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf, "Git", "bin", "bash.exe"),
1256
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf86, "Git", "bin", "bash.exe"),
1257
+ local ? __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(local, "Programs", "Git", "bin", "bash.exe") : ""
1258
+ ].filter((p)=>typeof p === "string" && p !== "");
1259
+ return candidates.find((p)=>__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(p)) || null;
1260
+ }
1261
+ function getFilesForAider(dir) {
1262
+ const maxFiles = 150;
1263
+ const files = [];
1264
+ function walk(current) {
1265
+ if (files.length >= maxFiles) return;
1266
+ try {
1267
+ const entries = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readdirSync(current, {
1268
+ withFileTypes: true
1269
+ });
1270
+ for (const entry of entries){
1271
+ const name = entry.name;
1272
+ if (name.startsWith(".") || name === "node_modules" || name === "out" || name === ".next" || name === "bin" || name === "obj" || name === "dist" || name === "build") {
1273
+ continue;
1274
+ }
1275
+ const fullPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(current, name);
1276
+ if (entry.isDirectory()) {
1277
+ walk(fullPath);
1278
+ } else {
1279
+ const relPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].relative(dir, fullPath);
1280
+ files.push(relPath);
1281
+ if (files.length >= maxFiles) return;
1282
+ }
1283
+ }
1284
+ } catch (err) {
1285
+ console.error("Error reading dir for Aider files list:", err);
1286
+ }
1287
+ }
1288
+ walk(dir);
1289
+ return files.map((f)=>`"${f.replace(/"/g, '\\"')}"`).join(" ");
1290
+ }
1291
+ class AiderRunner extends __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AgentRunner"] {
1292
+ id;
1293
+ name;
1294
+ type;
1295
+ status = 'idle';
1296
+ createdAt;
1297
+ logs = [];
1298
+ ptyProcess = null;
1299
+ ptyModule = null;
1300
+ constructor(id, type, name){
1301
+ super();
1302
+ this.id = id;
1303
+ this.type = type;
1304
+ this.name = name || (type === 'aider-docker' ? `Aider Docker ${id.substring(0, 8)}` : `Aider Session ${id.substring(0, 8)}`);
1305
+ this.createdAt = new Date().toISOString();
1306
+ }
1307
+ appendLog(line) {
1308
+ this.logs.push(line);
1309
+ if (this.logs.length > 5000) {
1310
+ this.logs.shift();
1311
+ }
1312
+ this.parseTokenUsage(line);
1313
+ this.emitOutput(line);
1314
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(this);
1315
+ }
1316
+ async start(resume) {
1317
+ if (this.status === 'running') return;
1318
+ this.status = 'running';
1319
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
1320
+ this.appendLog(`\x1b[1;36m NEURALLOOM AIDER AGENT ROUTE (${this.type.toUpperCase()}) \x1b[0m\r\n`);
1321
+ this.appendLog("\x1b[1;35m==================================================\x1b[0m\r\n");
1322
+ const useCmd = isWindows();
1323
+ const shellPath = useCmd ? process.env.COMSPEC || "cmd.exe" : findGitBash();
1324
+ if (!shellPath) {
1325
+ this.status = 'stopped';
1326
+ this.appendLog("\x1b[1;31m[System Error] Shell not found. Cannot spawn terminal.\x1b[0m\r\n");
1327
+ return;
1328
+ }
1329
+ const shellArgs = useCmd ? [
1330
+ "/c"
1331
+ ] : [
1332
+ "-c"
1333
+ ];
1334
+ try {
1335
+ if (!this.ptyModule) {
1336
+ this.ptyModule = eval("require")("node-pty");
1337
+ }
1338
+ // Load Aider configuration
1339
+ let aiderConfig = {
1340
+ openaiApiKey: "",
1341
+ anthropicApiKey: "",
1342
+ geminiApiKey: "",
1343
+ model: "claude-3-5-sonnet",
1344
+ extraFlags: "",
1345
+ loadAllFiles: true
1346
+ };
1347
+ const aiderConfigPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join((0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getConfigDir"])(), "aider.json");
1348
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(aiderConfigPath)) {
1349
+ try {
1350
+ aiderConfig = JSON.parse(__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(aiderConfigPath, "utf8"));
1351
+ } catch (err) {
1352
+ console.error("Failed to parse Aider configuration:", err);
1353
+ }
1354
+ }
1355
+ // Setup process environment with injected keys
1356
+ const customEnv = {
1357
+ ...process.env,
1358
+ TERM: "xterm-256color",
1359
+ COLORTERM: "truecolor",
1360
+ NEURAL_LOOM: "true"
1361
+ };
1362
+ if (aiderConfig.openaiApiKey) {
1363
+ customEnv.OPENAI_API_KEY = aiderConfig.openaiApiKey;
1364
+ }
1365
+ if (aiderConfig.anthropicApiKey) {
1366
+ customEnv.ANTHROPIC_API_KEY = aiderConfig.anthropicApiKey;
1367
+ }
1368
+ if (aiderConfig.geminiApiKey) {
1369
+ customEnv.GEMINI_API_KEY = aiderConfig.geminiApiKey;
1370
+ }
1371
+ const targetCwd = this.workspaceRoot && __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(this.workspaceRoot) ? this.workspaceRoot : process.env.ORIGINAL_CWD || process.cwd();
1372
+ const modelFlag = aiderConfig.model ? `--model ${aiderConfig.model}` : "";
1373
+ const extraFlags = aiderConfig.extraFlags || "";
1374
+ let loadAllFilesFlag = "";
1375
+ if (aiderConfig.loadAllFiles !== false) {
1376
+ if (extraFlags.includes("--no-git")) {
1377
+ loadAllFilesFlag = getFilesForAider(targetCwd);
1378
+ } else {
1379
+ loadAllFilesFlag = ".";
1380
+ }
1381
+ }
1382
+ if (this.type === "aider-docker") {
1383
+ this.appendLog("[System] Verifying Docker environment accessibility...\r\n");
1384
+ // Check if docker executable exists by running `docker --version`
1385
+ const hasDocker = await new Promise((resolve)=>{
1386
+ (0, __TURBOPACK__imported__module__$5b$externals$5d2f$child_process__$5b$external$5d$__$28$child_process$2c$__cjs$29$__["exec"])("docker --version", {
1387
+ env: process.env
1388
+ }, (error, stdout)=>{
1389
+ if (!error && stdout.toLowerCase().includes("version")) {
1390
+ resolve(true);
1391
+ } else {
1392
+ resolve(false);
1393
+ }
1394
+ });
1395
+ });
1396
+ if (!hasDocker) {
1397
+ this.status = 'stopped';
1398
+ this.appendLog("\x1b[1;31m[Dependency Warning] Docker command not recognized in local PATH.\x1b[0m\r\n");
1399
+ this.appendLog("\x1b[1;33mPlease install Docker Desktop and ensure the daemon is running.\x1b[0m\r\n");
1400
+ return;
1401
+ }
1402
+ this.appendLog("[System] Spawning Aider container environment...\r\n");
1403
+ const envFlags = [];
1404
+ if (aiderConfig.openaiApiKey) envFlags.push("-e OPENAI_API_KEY");
1405
+ if (aiderConfig.anthropicApiKey) envFlags.push("-e ANTHROPIC_API_KEY");
1406
+ if (aiderConfig.geminiApiKey) envFlags.push("-e GEMINI_API_KEY");
1407
+ envFlags.push("-e NEURAL_LOOM=true");
1408
+ const envFlagsStr = envFlags.join(" ");
1409
+ // Volume mounts for primary workspace and each scoped directory
1410
+ const mounts = [
1411
+ `-v "${targetCwd}:/workspace"`
1412
+ ];
1413
+ if (this.scopedDirs && Array.isArray(this.scopedDirs)) {
1414
+ this.scopedDirs.forEach((dir)=>{
1415
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(dir)) {
1416
+ const folderName = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].basename(dir).replace(/[^a-zA-Z0-9-_]/g, "_");
1417
+ mounts.push(`-v "${dir}:/scoped/${folderName}"`);
1418
+ }
1419
+ });
1420
+ }
1421
+ const mountsStr = mounts.join(" ");
1422
+ const dockerCmd = `docker run -it --name neural-loom-session-${this.id} --rm ${mountsStr} -w /workspace ${envFlagsStr} paulgauthier/aider ${modelFlag} ${extraFlags} --no-fancy-input ${loadAllFilesFlag}`.trim();
1423
+ this.ptyProcess = this.ptyModule.spawn(shellPath, [
1424
+ ...shellArgs,
1425
+ dockerCmd
1426
+ ], {
1427
+ name: "xterm-256color",
1428
+ cols: 120,
1429
+ rows: 30,
1430
+ cwd: targetCwd,
1431
+ env: customEnv
1432
+ });
1433
+ } else {
1434
+ this.appendLog("[System] Verifying 'aider' command availability in local PATH...\r\n");
1435
+ // Check if aider executable exists by running `aider --version`
1436
+ const hasAider = await new Promise((resolve)=>{
1437
+ (0, __TURBOPACK__imported__module__$5b$externals$5d2f$child_process__$5b$external$5d$__$28$child_process$2c$__cjs$29$__["exec"])("aider --version", {
1438
+ env: process.env
1439
+ }, (error, stdout)=>{
1440
+ if (!error && stdout.toLowerCase().includes("aider")) {
1441
+ resolve(true);
1442
+ } else {
1443
+ resolve(false);
1444
+ }
1445
+ });
1446
+ });
1447
+ if (!hasAider) {
1448
+ this.status = 'stopped';
1449
+ this.appendLog("\x1b[1;31m[Dependency Warning] 'aider' executable not found on local PATH.\x1b[0m\r\n");
1450
+ this.appendLog("\x1b[1;33mPlease install Aider globally via pip:\r\n pip install aider-chat\x1b[0m\r\n");
1451
+ return;
1452
+ }
1453
+ this.appendLog("[System] Spawning local Aider CLI...\r\n");
1454
+ const localCmd = `aider ${modelFlag} ${extraFlags} --no-fancy-input ${loadAllFilesFlag}`.trim();
1455
+ this.ptyProcess = this.ptyModule.spawn(shellPath, [
1456
+ ...shellArgs,
1457
+ localCmd
1458
+ ], {
1459
+ name: "xterm-256color",
1460
+ cols: 120,
1461
+ rows: 30,
1462
+ cwd: targetCwd,
1463
+ env: customEnv
1464
+ });
1465
+ }
1466
+ this.ptyProcess.onData((data)=>{
1467
+ this.appendLog(data);
1468
+ });
1469
+ this.ptyProcess.onExit(({ exitCode, signal })=>{
1470
+ this.status = 'stopped';
1471
+ this.appendLog(`\r\n\x1b[1;31m[System] Aider process exited (code=${exitCode}, signal=${signal}).\x1b[0m\r\n`);
1472
+ this.ptyProcess = null;
1473
+ });
1474
+ } catch (err) {
1475
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
1476
+ this.status = 'stopped';
1477
+ this.appendLog(`\x1b[1;31m[System Error] Failed to launch Aider: ${errorMessage}\x1b[0m\r\n`);
1478
+ }
1479
+ }
1480
+ async stop() {
1481
+ this.status = 'stopped';
1482
+ if (this.ptyProcess) {
1483
+ try {
1484
+ this.ptyProcess.kill();
1485
+ } catch (err) {
1486
+ console.error("Error killing Aider PTY process:", err);
1487
+ }
1488
+ this.ptyProcess = null;
1489
+ }
1490
+ this.appendLog("\r\n\x1b[1;31m[System] Aider session terminated.\x1b[0m\r\n");
1491
+ }
1492
+ async sendInput(text, isRaw = false) {
1493
+ if (this.status !== 'running' || !this.ptyProcess) {
1494
+ this.appendLog(`\r\n\x1b[1;31m[Error] Cannot write: Aider process is ${this.status}.\x1b[0m\r\n`);
1495
+ return;
1496
+ }
1497
+ this.agentState = 'thinking';
1498
+ await this.writeToPty(this.ptyProcess, isRaw ? text : text + "\r");
1499
+ }
1500
+ resize(cols, rows) {
1501
+ if (this.ptyProcess) {
1502
+ try {
1503
+ this.ptyProcess.resize(cols, rows);
1504
+ } catch (err) {
1505
+ console.error("[AiderRunner] Failed to resize PTY:", err);
1506
+ }
1507
+ }
1508
+ }
1509
+ }
1510
+ }),
1511
+ "[externals]/events [external] (events, cjs)", ((__turbopack_context__, module, exports) => {
1512
+
1513
+ const mod = __turbopack_context__.x("events", () => require("events"));
1514
+
1515
+ module.exports = mod;
1516
+ }),
1517
+ "[externals]/https [external] (https, cjs)", ((__turbopack_context__, module, exports) => {
1518
+
1519
+ const mod = __turbopack_context__.x("https", () => require("https"));
1520
+
1521
+ module.exports = mod;
1522
+ }),
1523
+ "[externals]/http [external] (http, cjs)", ((__turbopack_context__, module, exports) => {
1524
+
1525
+ const mod = __turbopack_context__.x("http", () => require("http"));
1526
+
1527
+ module.exports = mod;
1528
+ }),
1529
+ "[externals]/net [external] (net, cjs)", ((__turbopack_context__, module, exports) => {
1530
+
1531
+ const mod = __turbopack_context__.x("net", () => require("net"));
1532
+
1533
+ module.exports = mod;
1534
+ }),
1535
+ "[externals]/tls [external] (tls, cjs)", ((__turbopack_context__, module, exports) => {
1536
+
1537
+ const mod = __turbopack_context__.x("tls", () => require("tls"));
1538
+
1539
+ module.exports = mod;
1540
+ }),
1541
+ "[externals]/stream [external] (stream, cjs)", ((__turbopack_context__, module, exports) => {
1542
+
1543
+ const mod = __turbopack_context__.x("stream", () => require("stream"));
1544
+
1545
+ module.exports = mod;
1546
+ }),
1547
+ "[externals]/url [external] (url, cjs)", ((__turbopack_context__, module, exports) => {
1548
+
1549
+ const mod = __turbopack_context__.x("url", () => require("url"));
1550
+
1551
+ module.exports = mod;
1552
+ }),
1553
+ "[externals]/zlib [external] (zlib, cjs)", ((__turbopack_context__, module, exports) => {
1554
+
1555
+ const mod = __turbopack_context__.x("zlib", () => require("zlib"));
1556
+
1557
+ module.exports = mod;
1558
+ }),
1559
+ "[externals]/buffer [external] (buffer, cjs)", ((__turbopack_context__, module, exports) => {
1560
+
1561
+ const mod = __turbopack_context__.x("buffer", () => require("buffer"));
1562
+
1563
+ module.exports = mod;
1564
+ }),
1565
+ "[externals]/util [external] (util, cjs)", ((__turbopack_context__, module, exports) => {
1566
+
1567
+ const mod = __turbopack_context__.x("util", () => require("util"));
1568
+
1569
+ module.exports = mod;
1570
+ }),
1571
+ "[project]/src/lib/agents/WebSocketServer.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
1572
+ "use strict";
1573
+
1574
+ __turbopack_context__.s([
1575
+ "initWebSocketServer",
1576
+ ()=>initWebSocketServer
1577
+ ]);
1578
+ var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$ws$2f$wrapper$2e$mjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/node_modules/ws/wrapper.mjs [app-route] (ecmascript) <locals>");
1579
+ var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$ws$2f$lib$2f$websocket$2d$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$export__default__as__WebSocketServer$3e$__ = __turbopack_context__.i("[project]/node_modules/ws/lib/websocket-server.js [app-route] (ecmascript) <export default as WebSocketServer>");
1580
+ var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$ws$2f$lib$2f$websocket$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$export__default__as__WebSocket$3e$__ = __turbopack_context__.i("[project]/node_modules/ws/lib/websocket.js [app-route] (ecmascript) <export default as WebSocket>");
1581
+ ;
1582
+ let getSessionCallback = null;
1583
+ function initWebSocketServer(port = 9601, getSession) {
1584
+ if (getSession) {
1585
+ getSessionCallback = getSession;
1586
+ }
1587
+ // Prevent duplicate WebSocket servers during hot reloads in development
1588
+ if (/*TURBOPACK member replacement*/ __turbopack_context__.g.wss) {
1589
+ console.log(`[WebSocketServer] WebSocket Server already active on port ${/*TURBOPACK member replacement*/ __turbopack_context__.g.wsPort || 9601} (cached).`);
1590
+ return;
1591
+ }
1592
+ let currentPort = port;
1593
+ const maxPort = port + 10;
1594
+ function tryBind() {
1595
+ console.log(`[WebSocketServer] Launching NeuralLoom WebSocket Gateway on port ${currentPort}...`);
1596
+ try {
1597
+ const wss = new __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$ws$2f$lib$2f$websocket$2d$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$export__default__as__WebSocketServer$3e$__["WebSocketServer"]({
1598
+ port: currentPort
1599
+ });
1600
+ wss.on("error", (err)=>{
1601
+ const socketErr = err;
1602
+ if (socketErr.code === "EADDRINUSE" && currentPort < maxPort) {
1603
+ console.warn(`[WebSocketServer] Port ${currentPort} in use, trying next port...`);
1604
+ currentPort++;
1605
+ tryBind();
1606
+ } else {
1607
+ console.error("[WebSocketServer] WebSocket server error:", err);
1608
+ }
1609
+ });
1610
+ wss.on("listening", ()=>{
1611
+ /*TURBOPACK member replacement*/ __turbopack_context__.g.wss = wss;
1612
+ /*TURBOPACK member replacement*/ __turbopack_context__.g.wsPort = currentPort;
1613
+ console.log(`[WebSocketServer] WebSocket gateway successfully listening on port ${currentPort}.`);
1614
+ });
1615
+ wss.on("connection", (ws)=>{
1616
+ console.log("[WebSocketServer] New client connected via gateway.");
1617
+ let mockBuffer = "";
1618
+ ws.on("message", async (rawMsg)=>{
1619
+ try {
1620
+ const msg = JSON.parse(rawMsg.toString());
1621
+ // Client handshake to establish connection to a specific session
1622
+ if (msg.type === "handshake") {
1623
+ const { sessionId } = msg;
1624
+ // Clean up previous registration for this connection if it exists
1625
+ if (ws.sessionId && ws.outputListener) {
1626
+ const oldSession = getSessionCallback ? getSessionCallback(ws.sessionId) : null;
1627
+ if (oldSession) {
1628
+ oldSession.offOutput(ws.outputListener);
1629
+ }
1630
+ }
1631
+ const session = getSessionCallback ? getSessionCallback(sessionId) : null;
1632
+ if (session) {
1633
+ ws.sessionId = sessionId;
1634
+ console.log(`[WebSocketServer] Client connected to active session: ${sessionId}`);
1635
+ // Subscribe to runner output events
1636
+ const listener = (data)=>{
1637
+ if (ws.readyState === __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$ws$2f$lib$2f$websocket$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$export__default__as__WebSocket$3e$__["WebSocket"].OPEN) {
1638
+ ws.send(JSON.stringify({
1639
+ type: "output",
1640
+ data
1641
+ }));
1642
+ }
1643
+ };
1644
+ ws.outputListener = listener;
1645
+ session.onOutput(listener);
1646
+ // Send handshake acknowledgment and full historical logs
1647
+ ws.send(JSON.stringify({
1648
+ type: "handshake-ack",
1649
+ sessionId,
1650
+ history: session.logs.join("")
1651
+ }));
1652
+ } else {
1653
+ ws.send(JSON.stringify({
1654
+ type: "error",
1655
+ message: "Requested session not found"
1656
+ }));
1657
+ }
1658
+ }
1659
+ // User terminal input routing
1660
+ if (msg.type === "input" && ws.sessionId) {
1661
+ const session = getSessionCallback ? getSessionCallback(ws.sessionId) : null;
1662
+ if (session && session.status === "running") {
1663
+ if (session.type === "mock") {
1664
+ // Buffer input for simulated command parsing in MockRunner
1665
+ const data = msg.data;
1666
+ if (data === "\r" || data === "\r\n") {
1667
+ ws.send(JSON.stringify({
1668
+ type: "output",
1669
+ data: "\r\n"
1670
+ }));
1671
+ const cmd = mockBuffer;
1672
+ mockBuffer = "";
1673
+ await session.sendInput(cmd);
1674
+ } else if (data === "\u007f" || data === "\b") {
1675
+ if (mockBuffer.length > 0) {
1676
+ mockBuffer = mockBuffer.slice(0, -1);
1677
+ ws.send(JSON.stringify({
1678
+ type: "output",
1679
+ data: "\b \b"
1680
+ }));
1681
+ }
1682
+ } else {
1683
+ mockBuffer += data;
1684
+ ws.send(JSON.stringify({
1685
+ type: "output",
1686
+ data
1687
+ })); // Local echo of key
1688
+ }
1689
+ } else {
1690
+ // Pass raw keystrokes straight to Claude Code PTY
1691
+ await session.sendInput(msg.data, true);
1692
+ }
1693
+ }
1694
+ }
1695
+ // User terminal resize routing
1696
+ if (msg.type === "resize" && ws.sessionId) {
1697
+ const { cols, rows } = msg;
1698
+ const session = getSessionCallback ? getSessionCallback(ws.sessionId) : null;
1699
+ if (session) {
1700
+ session.resize(cols, rows);
1701
+ }
1702
+ }
1703
+ } catch (err) {
1704
+ console.error("[WebSocketServer] Error processing socket packet:", err);
1705
+ }
1706
+ });
1707
+ ws.on("close", ()=>{
1708
+ if (ws.sessionId && ws.outputListener) {
1709
+ const session = getSessionCallback ? getSessionCallback(ws.sessionId) : null;
1710
+ if (session) {
1711
+ session.offOutput(ws.outputListener);
1712
+ }
1713
+ }
1714
+ console.log("[WebSocketServer] Client connection closed.");
1715
+ });
1716
+ ws.on("error", (err)=>{
1717
+ console.error("[WebSocketServer] Socket error:", err);
1718
+ });
1719
+ });
1720
+ } catch (error) {
1721
+ if (currentPort < maxPort) {
1722
+ currentPort++;
1723
+ tryBind();
1724
+ } else {
1725
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1726
+ console.error(`[WebSocketServer] Failed to initialize WebSocket Server: ${errorMessage}`);
1727
+ }
1728
+ }
1729
+ }
1730
+ tryBind();
1731
+ }
1732
+ }),
1733
+ "[project]/src/lib/agents/ContextManager.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
1734
+ "use strict";
1735
+
1736
+ __turbopack_context__.s([
1737
+ "ContextManager",
1738
+ ()=>ContextManager
1739
+ ]);
1740
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
1741
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
1742
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/config.ts [app-route] (ecmascript)");
1743
+ ;
1744
+ ;
1745
+ ;
1746
+ class ContextManager {
1747
+ static writableCache = new Map();
1748
+ static isWritable(root) {
1749
+ if (this.writableCache.has(root)) {
1750
+ return this.writableCache.get(root);
1751
+ }
1752
+ const res = (0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$config$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["isDirWritable"])(root);
1753
+ this.writableCache.set(root, res);
1754
+ return res;
1755
+ }
1756
+ static get workspaceRoot() {
1757
+ return process.env.ORIGINAL_CWD || process.cwd();
1758
+ }
1759
+ static ensureDirs(root) {
1760
+ if (!this.isWritable(root)) {
1761
+ return;
1762
+ }
1763
+ try {
1764
+ const aiDir = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".ai", "neural-loom");
1765
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(aiDir)) {
1766
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(aiDir, {
1767
+ recursive: true
1768
+ });
1769
+ }
1770
+ const commandDir = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".claude", "commands");
1771
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(commandDir)) {
1772
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].mkdirSync(commandDir, {
1773
+ recursive: true
1774
+ });
1775
+ }
1776
+ } catch (err) {
1777
+ console.warn(`[ContextManager] Failed to ensure directories at ${root}:`, err);
1778
+ }
1779
+ }
1780
+ static initializeStaging(root = process.env.ORIGINAL_CWD || process.cwd()) {
1781
+ if (!this.isWritable(root)) {
1782
+ return;
1783
+ }
1784
+ try {
1785
+ this.ensureDirs(root);
1786
+ // Create /ccp.md custom slash command file
1787
+ const ccpPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".claude", "commands", "ccp.md");
1788
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(ccpPath)) {
1789
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(ccpPath, "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");
1790
+ }
1791
+ // Create /ccc.md custom slash command file
1792
+ const cccPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".claude", "commands", "ccc.md");
1793
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(cccPath)) {
1794
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(cccPath, "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");
1795
+ }
1796
+ } catch (err) {
1797
+ console.warn(`[ContextManager] Failed to initialize staging at ${root}:`, err);
1798
+ }
1799
+ }
1800
+ static updatePrompt(promptText, root = process.env.ORIGINAL_CWD || process.cwd()) {
1801
+ if (!this.isWritable(root)) {
1802
+ return;
1803
+ }
1804
+ try {
1805
+ this.ensureDirs(root);
1806
+ const promptFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".ai", "neural-loom", "cprompt.md");
1807
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(promptFile, promptText);
1808
+ } catch (err) {
1809
+ console.error(`[ContextManager] Failed to write prompt file at ${root}:`, err);
1810
+ }
1811
+ }
1812
+ static updateContext(contextText, root = process.env.ORIGINAL_CWD || process.cwd()) {
1813
+ if (!this.isWritable(root)) {
1814
+ return;
1815
+ }
1816
+ try {
1817
+ this.ensureDirs(root);
1818
+ const contextFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".ai", "neural-loom", "ccontext.md");
1819
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(contextFile, contextText);
1820
+ } catch (err) {
1821
+ console.error(`[ContextManager] Failed to write context file at ${root}:`, err);
1822
+ }
1823
+ }
1824
+ static updateRules(rulesText, root = process.env.ORIGINAL_CWD || process.cwd()) {
1825
+ if (!this.isWritable(root)) {
1826
+ return;
1827
+ }
1828
+ try {
1829
+ this.ensureDirs(root);
1830
+ const agentsMdPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, "AGENTS.md");
1831
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(agentsMdPath, rulesText, "utf8");
1832
+ } catch (err) {
1833
+ console.error(`[ContextManager] Failed to write rules file at ${root}:`, err);
1834
+ }
1835
+ }
1836
+ static loadPrompt(root = process.env.ORIGINAL_CWD || process.cwd()) {
1837
+ const promptFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".ai", "neural-loom", "cprompt.md");
1838
+ return __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(promptFile) ? __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(promptFile, "utf8") : "";
1839
+ }
1840
+ static loadRules(root = process.env.ORIGINAL_CWD || process.cwd()) {
1841
+ const agentsMdPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, "AGENTS.md");
1842
+ return __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(agentsMdPath) ? __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(agentsMdPath, "utf8") : "";
1843
+ }
1844
+ static compileGlobalRules() {
1845
+ this.compileSessionContext();
1846
+ }
1847
+ static compileSessionContext(root = process.env.ORIGINAL_CWD || process.cwd(), scopedDirs) {
1848
+ if (!this.isWritable(root)) {
1849
+ return;
1850
+ }
1851
+ try {
1852
+ this.ensureDirs(root);
1853
+ this.initializeStaging(root);
1854
+ // Check if AGENTS.md rules template exists
1855
+ const agentsMdPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, "AGENTS.md");
1856
+ let agentsRules = "";
1857
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(agentsMdPath)) {
1858
+ agentsRules = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(agentsMdPath, "utf8");
1859
+ } else {
1860
+ // Try fallback from global
1861
+ const fallbackPath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(this.workspaceRoot, "AGENTS.md");
1862
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(fallbackPath)) {
1863
+ agentsRules = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(fallbackPath, "utf8");
1864
+ }
1865
+ }
1866
+ // Generate maps
1867
+ let maps = `## Workspace Root Map (${root}):\n${this.generateProjectMapFor(root)}`;
1868
+ if (scopedDirs && Array.isArray(scopedDirs)) {
1869
+ scopedDirs.forEach((dir)=>{
1870
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(dir)) {
1871
+ maps += `\n\n## Scoped Directory Map (${dir}):\n${this.generateProjectMapFor(dir)}`;
1872
+ }
1873
+ });
1874
+ }
1875
+ // Combine rules and folder map
1876
+ const compiledContext = `# System Rules & Guidelines\n\n${agentsRules}\n\n# Project File Hierarchy Map\n\n${maps}`;
1877
+ this.updateContext(compiledContext, root);
1878
+ // Write a default empty prompt staging file if missing
1879
+ const promptFile = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(root, ".ai", "neural-loom", "cprompt.md");
1880
+ if (!__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(promptFile)) {
1881
+ __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].writeFileSync(promptFile, "Hello! Please review the project context (/ccc) and check for any tasks to execute.");
1882
+ }
1883
+ } catch (err) {
1884
+ console.warn(`[ContextManager] Failed to compile session context at ${root}:`, err);
1885
+ }
1886
+ }
1887
+ static generateProjectMapFor(targetDir) {
1888
+ try {
1889
+ const walk = (dir, depth = 0)=>{
1890
+ if (depth > 2) return ""; // Keep map depth concise to fit tokens
1891
+ let result = "";
1892
+ const files = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readdirSync(dir, {
1893
+ withFileTypes: true
1894
+ });
1895
+ for (const file of files){
1896
+ if (file.name.startsWith(".") || file.name === "node_modules" || file.name === "out" || file.name === ".next") {
1897
+ continue;
1898
+ }
1899
+ const indent = " ".repeat(depth);
1900
+ if (file.isDirectory()) {
1901
+ result += `${indent}- [Dir] ${file.name}/\n`;
1902
+ result += walk(__TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(dir, file.name), depth + 1);
1903
+ } else {
1904
+ result += `${indent}- [File] ${file.name}\n`;
1905
+ }
1906
+ }
1907
+ return result;
1908
+ };
1909
+ return walk(targetDir);
1910
+ } catch (err) {
1911
+ return "Error generating project map: " + (err instanceof Error ? err.message : String(err));
1912
+ }
1913
+ }
1914
+ }
1915
+ }),
1916
+ "[project]/src/lib/agents/ShellRunner.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
1917
+ "use strict";
1918
+
1919
+ __turbopack_context__.s([
1920
+ "ShellRunner",
1921
+ ()=>ShellRunner
1922
+ ]);
1923
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
1924
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
1925
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AgentRunner.ts [app-route] (ecmascript)");
1926
+ ;
1927
+ ;
1928
+ ;
1929
+ function isWindows() {
1930
+ return typeof process !== "undefined" && process.platform === "win32";
1931
+ }
1932
+ function findGitBash() {
1933
+ if (!isWindows()) {
1934
+ return "bash";
1935
+ }
1936
+ const pf = process.env.PROGRAMFILES || "C:\\Program Files";
1937
+ const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
1938
+ const local = process.env.LOCALAPPDATA || "";
1939
+ const candidates = [
1940
+ process.env.WINGMAN_BASH_PATH,
1941
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf, "Git", "bin", "bash.exe"),
1942
+ __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(pf86, "Git", "bin", "bash.exe"),
1943
+ local ? __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(local, "Programs", "Git", "bin", "bash.exe") : ""
1944
+ ].filter((p)=>typeof p === "string" && p !== "");
1945
+ const found = candidates.find((p)=>__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(p));
1946
+ if (found) return found;
1947
+ // Fallback to PowerShell or Cmd on Windows
1948
+ const windir = process.env.windir || "C:\\Windows";
1949
+ const powershell = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(windir, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
1950
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(powershell)) return powershell;
1951
+ const cmd = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(windir, "System32", "cmd.exe");
1952
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(cmd)) return cmd;
1953
+ return null;
1954
+ }
1955
+ class ShellRunner extends __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AgentRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AgentRunner"] {
1956
+ id;
1957
+ name;
1958
+ type = "shell";
1959
+ status = 'idle';
1960
+ createdAt;
1961
+ logs = [];
1962
+ ptyProcess = null;
1963
+ ptyModule = null;
1964
+ constructor(id = "workspace-terminal", name, workspaceRoot){
1965
+ super();
1966
+ this.id = id;
1967
+ this.name = name || "Workspace Shell";
1968
+ this.workspaceRoot = workspaceRoot;
1969
+ this.createdAt = new Date().toISOString();
1970
+ }
1971
+ appendLog(line) {
1972
+ this.logs.push(line);
1973
+ if (this.logs.length > 5000) {
1974
+ this.logs.shift();
1975
+ }
1976
+ this.emitOutput(line);
1977
+ }
1978
+ async start(resume) {
1979
+ if (this.status === 'running') return;
1980
+ const shellPath = findGitBash();
1981
+ if (!shellPath) {
1982
+ this.status = 'stopped';
1983
+ this.appendLog("[System Error] Shell executable (Git Bash/PowerShell) not found.\r\n");
1984
+ return;
1985
+ }
1986
+ try {
1987
+ if (!this.ptyModule) {
1988
+ this.ptyModule = eval("require")("node-pty");
1989
+ }
1990
+ this.status = 'running';
1991
+ this.appendLog("\x1b[1;36m[System] Launching workspace terminal interactive shell...\x1b[0m\r\n");
1992
+ const targetCwd = this.workspaceRoot && __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(this.workspaceRoot) ? this.workspaceRoot : process.env.ORIGINAL_CWD || process.cwd();
1993
+ // Spawn login/interactive shell
1994
+ const spawnArgs = isWindows() && shellPath.endsWith("bash.exe") ? [
1995
+ "--login"
1996
+ ] : [];
1997
+ this.ptyProcess = this.ptyModule.spawn(shellPath, spawnArgs, {
1998
+ name: "xterm-256color",
1999
+ cols: 120,
2000
+ rows: 30,
2001
+ cwd: targetCwd,
2002
+ env: {
2003
+ ...process.env,
2004
+ TERM: "xterm-256color",
2005
+ COLORTERM: "truecolor"
2006
+ }
2007
+ });
2008
+ this.ptyProcess.onData((data)=>{
2009
+ this.appendLog(data);
2010
+ });
2011
+ this.ptyProcess.onExit(({ exitCode, signal })=>{
2012
+ this.status = 'stopped';
2013
+ this.appendLog(`\r\n\x1b[1;31m[System] Shell process exited (code=${exitCode}, signal=${signal}).\x1b[0m\r\n`);
2014
+ this.ptyProcess = null;
2015
+ });
2016
+ } catch (err) {
2017
+ const errorMessage = err instanceof Error ? err.message : "Unknown error";
2018
+ this.status = 'stopped';
2019
+ this.appendLog(`[System Error] Failed to initialize shell runner: ${errorMessage}\r\n`);
2020
+ }
2021
+ }
2022
+ async stop() {
2023
+ this.status = 'stopped';
2024
+ if (this.ptyProcess) {
2025
+ try {
2026
+ this.ptyProcess.kill();
2027
+ } catch (err) {
2028
+ console.error("Error killing shell process:", err);
2029
+ }
2030
+ this.ptyProcess = null;
2031
+ }
2032
+ this.appendLog("\r\n\x1b[1;31m[System] Shell session stopped.\x1b[0m\r\n");
2033
+ }
2034
+ async sendInput(text, isRaw = false) {
2035
+ if (this.status !== 'running' || !this.ptyProcess) {
2036
+ this.appendLog(`\r\n[Error] Shell process is ${this.status}.\r\n`);
2037
+ return;
2038
+ }
2039
+ this.agentState = 'thinking';
2040
+ await this.writeToPty(this.ptyProcess, isRaw ? text : text + "\r");
2041
+ }
2042
+ resize(cols, rows) {
2043
+ if (this.ptyProcess) {
2044
+ try {
2045
+ this.ptyProcess.resize(cols, rows);
2046
+ } catch (err) {
2047
+ console.error("[ShellRunner] Failed to resize:", err);
2048
+ }
2049
+ }
2050
+ }
2051
+ }
2052
+ }),
2053
+ "[project]/src/lib/workspaceParser.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
2054
+ "use strict";
2055
+
2056
+ __turbopack_context__.s([
2057
+ "getWorkspaceFileFolders",
2058
+ ()=>getWorkspaceFileFolders
2059
+ ]);
2060
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs [external] (fs, cjs)");
2061
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
2062
+ ;
2063
+ ;
2064
+ function getWorkspaceFileFolders(workspaceRoot) {
2065
+ try {
2066
+ if (!workspaceRoot || !__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(workspaceRoot)) return [];
2067
+ // Normalize workspaceRoot path
2068
+ const normRoot = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].resolve(workspaceRoot).replace(/\\/g, "/");
2069
+ const files = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readdirSync(normRoot);
2070
+ const workspaceFile = files.find((f)=>f.endsWith(".code-workspace"));
2071
+ if (!workspaceFile) return [];
2072
+ const filePath = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(normRoot, workspaceFile);
2073
+ const content = __TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].readFileSync(filePath, "utf8");
2074
+ const json = JSON.parse(content);
2075
+ if (!json.folders || !Array.isArray(json.folders)) return [];
2076
+ const folders = [];
2077
+ for (const folder of json.folders){
2078
+ if (folder.path) {
2079
+ // Resolve relative to workspace root (where the workspace file resides)
2080
+ const resolved = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].resolve(normRoot, folder.path).replace(/\\/g, "/");
2081
+ // Exclude the workspace root folder itself
2082
+ if (resolved !== normRoot) {
2083
+ if (__TURBOPACK__imported__module__$5b$externals$5d2f$fs__$5b$external$5d$__$28$fs$2c$__cjs$29$__["default"].existsSync(resolved)) {
2084
+ folders.push(resolved);
2085
+ }
2086
+ }
2087
+ }
2088
+ }
2089
+ return folders;
2090
+ } catch (err) {
2091
+ console.error("[WorkspaceParser] Failed to parse code-workspace file:", err);
2092
+ return [];
2093
+ }
2094
+ }
2095
+ }),
2096
+ "[project]/src/lib/agents/SessionManager.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
2097
+ "use strict";
2098
+
2099
+ __turbopack_context__.s([
2100
+ "SessionManager",
2101
+ ()=>SessionManager
2102
+ ]);
2103
+ var __TURBOPACK__imported__module__$5b$externals$5d2f$crypto__$5b$external$5d$__$28$crypto$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/crypto [external] (crypto, cjs)");
2104
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$MockRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/MockRunner.ts [app-route] (ecmascript)");
2105
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ClaudeRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/ClaudeRunner.ts [app-route] (ecmascript)");
2106
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$DockerRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/DockerRunner.ts [app-route] (ecmascript)");
2107
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SSHRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SSHRunner.ts [app-route] (ecmascript)");
2108
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AiderRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/AiderRunner.ts [app-route] (ecmascript)");
2109
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$WebSocketServer$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/WebSocketServer.ts [app-route] (ecmascript)");
2110
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ContextManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/ContextManager.ts [app-route] (ecmascript)");
2111
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionPersister.ts [app-route] (ecmascript)");
2112
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ShellRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/ShellRunner.ts [app-route] (ecmascript)");
2113
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$workspaceParser$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/workspaceParser.ts [app-route] (ecmascript)");
2114
+ ;
2115
+ ;
2116
+ ;
2117
+ ;
2118
+ ;
2119
+ ;
2120
+ ;
2121
+ ;
2122
+ ;
2123
+ ;
2124
+ ;
2125
+ class SessionManager {
2126
+ static instance = null;
2127
+ sessions = new Map();
2128
+ constructor(){
2129
+ // Bootstrap staging filesystem and slash commands
2130
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ContextManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ContextManager"].initializeStaging();
2131
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ContextManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ContextManager"].compileGlobalRules();
2132
+ // Spawn/start permanent workspace terminal shell runner
2133
+ const shellRunner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ShellRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ShellRunner"]();
2134
+ shellRunner.start();
2135
+ this.sessions.set(shellRunner.id, shellRunner);
2136
+ // Reload persisted sessions
2137
+ try {
2138
+ const saved = __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].loadAllSessions();
2139
+ for (const data of saved){
2140
+ // Preserved persisted session
2141
+ let runner;
2142
+ if (data.type === "mock") {
2143
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$MockRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["MockRunner"](data.id, data.name);
2144
+ } else if (data.type === "claude-docker") {
2145
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$DockerRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["DockerRunner"](data.id, data.name);
2146
+ } else if (data.type === "claude-ssh") {
2147
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SSHRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SSHRunner"](data.id, data.name);
2148
+ } else if (data.type === "aider" || data.type === "aider-docker") {
2149
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AiderRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AiderRunner"](data.id, data.type, data.name);
2150
+ } else if (data.type === "shell") {
2151
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ShellRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ShellRunner"](data.id, data.name, data.workspaceRoot);
2152
+ } else {
2153
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ClaudeRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ClaudeRunner"](data.id, data.name);
2154
+ }
2155
+ runner.status = data.status;
2156
+ runner.createdAt = data.createdAt;
2157
+ runner.logs = data.logs;
2158
+ runner.workspaceRoot = data.workspaceRoot;
2159
+ runner.scopedDirs = data.scopedDirs;
2160
+ runner.lastSyncedWorkspaceFolders = data.lastSyncedWorkspaceFolders;
2161
+ this.sessions.set(data.id, runner);
2162
+ }
2163
+ } catch (err) {
2164
+ console.error("[SessionManager] Failed to reload saved sessions:", err);
2165
+ }
2166
+ }
2167
+ static getInstance() {
2168
+ if (!globalThis.sessionManager) {
2169
+ globalThis.sessionManager = new SessionManager();
2170
+ // Initialize WebSocket gateway server
2171
+ const wsPort = Number(process.env.WS_PORT) || 9601;
2172
+ (0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$WebSocketServer$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["initWebSocketServer"])(wsPort, (id)=>globalThis.sessionManager.getSession(id));
2173
+ }
2174
+ return globalThis.sessionManager;
2175
+ }
2176
+ generateId() {
2177
+ return __TURBOPACK__imported__module__$5b$externals$5d2f$crypto__$5b$external$5d$__$28$crypto$2c$__cjs$29$__["default"].randomUUID();
2178
+ }
2179
+ async createSession(type, name, workspaceRoot, scopedDirs, parentSessionId) {
2180
+ const id = type === 'shell' && parentSessionId ? `shell-${parentSessionId}-${__TURBOPACK__imported__module__$5b$externals$5d2f$crypto__$5b$external$5d$__$28$crypto$2c$__cjs$29$__["default"].randomUUID()}` : this.generateId();
2181
+ let runner;
2182
+ if (type === 'mock') {
2183
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$MockRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["MockRunner"](id, name);
2184
+ } else if (type === 'claude-docker') {
2185
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$DockerRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["DockerRunner"](id, name);
2186
+ } else if (type === 'claude-ssh') {
2187
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SSHRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SSHRunner"](id, name);
2188
+ } else if (type === 'aider' || type === 'aider-docker') {
2189
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$AiderRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AiderRunner"](id, type, name);
2190
+ } else if (type === 'shell') {
2191
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ShellRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ShellRunner"](id, name, workspaceRoot);
2192
+ } else {
2193
+ runner = new __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ClaudeRunner$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ClaudeRunner"](id, name);
2194
+ }
2195
+ runner.workspaceRoot = workspaceRoot;
2196
+ runner.scopedDirs = scopedDirs;
2197
+ runner.resetInitialStateAnalysis();
2198
+ await runner.start();
2199
+ this.sessions.set(id, runner);
2200
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(runner, true);
2201
+ return runner;
2202
+ }
2203
+ getSession(id) {
2204
+ const runner = this.sessions.get(id);
2205
+ if (runner) {
2206
+ this.syncWorkspaceFolders(runner);
2207
+ }
2208
+ return runner;
2209
+ }
2210
+ listSessions() {
2211
+ return Array.from(this.sessions.values()).map((runner)=>{
2212
+ this.syncWorkspaceFolders(runner);
2213
+ return runner.getStatus();
2214
+ });
2215
+ }
2216
+ syncWorkspaceFolders(session) {
2217
+ if (session.type === 'mock' || session.type === 'shell') return;
2218
+ const root = session.workspaceRoot || process.env.ORIGINAL_CWD || process.cwd();
2219
+ const currentWorkspaceFolders = (0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$workspaceParser$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getWorkspaceFileFolders"])(root);
2220
+ const lastSynced = session.lastSyncedWorkspaceFolders || [];
2221
+ // Check if the folders list from .code-workspace has changed since last sync
2222
+ const hasChanged = currentWorkspaceFolders.length !== lastSynced.length || currentWorkspaceFolders.some((f)=>!lastSynced.includes(f)) || lastSynced.some((f)=>!currentWorkspaceFolders.includes(f));
2223
+ if (hasChanged) {
2224
+ console.log(`[SessionManager] Code workspace folders changed for session ${session.id}. Re-syncing...`);
2225
+ if (!session.scopedDirs) session.scopedDirs = [];
2226
+ // 1. Remove folders that were in the previous sync but are no longer in .code-workspace
2227
+ session.scopedDirs = session.scopedDirs.filter((dir)=>{
2228
+ if (lastSynced.includes(dir) && !currentWorkspaceFolders.includes(dir)) {
2229
+ return false;
2230
+ }
2231
+ return true;
2232
+ });
2233
+ // 2. Add new folders that are in .code-workspace
2234
+ for (const dir of currentWorkspaceFolders){
2235
+ if (!session.scopedDirs.includes(dir)) {
2236
+ session.scopedDirs.push(dir);
2237
+ }
2238
+ }
2239
+ // 3. Update last synced flag
2240
+ session.lastSyncedWorkspaceFolders = currentWorkspaceFolders;
2241
+ // 4. Save session status
2242
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(session, true);
2243
+ // 5. Re-compile context
2244
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ContextManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ContextManager"].compileSessionContext(root, session.scopedDirs);
2245
+ // 6. Auto-inject mount context command if active
2246
+ if (session.status === 'running') {
2247
+ this.injectCommand(session.id, "/ccc");
2248
+ }
2249
+ }
2250
+ }
2251
+ async startSession(id, resume) {
2252
+ const runner = this.sessions.get(id);
2253
+ if (!runner) return false;
2254
+ runner.resetInitialStateAnalysis();
2255
+ await runner.start(resume);
2256
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(runner, true);
2257
+ return true;
2258
+ }
2259
+ async stopSession(id) {
2260
+ const runner = this.sessions.get(id);
2261
+ if (!runner) return false;
2262
+ await runner.stop();
2263
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].saveSession(runner, true);
2264
+ return true;
2265
+ }
2266
+ async deleteSession(id) {
2267
+ const runner = this.sessions.get(id);
2268
+ if (runner) {
2269
+ await runner.stop();
2270
+ }
2271
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionPersister$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionPersister"].deleteSession(id);
2272
+ return this.sessions.delete(id);
2273
+ }
2274
+ async injectCommand(id, command) {
2275
+ const runner = this.sessions.get(id);
2276
+ if (!runner || runner.status !== 'running') return false;
2277
+ const root = runner.workspaceRoot || process.env.ORIGINAL_CWD || process.cwd();
2278
+ if (command === '/ccc' || command === '/ccp') {
2279
+ __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$ContextManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ContextManager"].compileSessionContext(root, runner.scopedDirs);
2280
+ }
2281
+ let finalCommand = command;
2282
+ if (runner.type === 'aider' || runner.type === 'aider-docker') {
2283
+ if (command === '/ccc') {
2284
+ finalCommand = "/read .ai/neural-loom/ccontext.md";
2285
+ } else if (command === '/ccp') {
2286
+ finalCommand = "/read .ai/neural-loom/cprompt.md";
2287
+ }
2288
+ }
2289
+ // Inject Ctrl+U to clear input, then command, then Enter (\r)
2290
+ await runner.sendInput("\x15" + finalCommand + "\r", true);
2291
+ return true;
2292
+ }
2293
+ }
2294
+ }),
2295
+ "[project]/package.json.[json].cjs [app-route] (ecmascript)", ((__turbopack_context__, module, exports) => {
2296
+
2297
+ module.exports = {
2298
+ "name": "neural-loom",
2299
+ "version": "0.2.70",
2300
+ "bin": {
2301
+ "neural-loom": "./bin/cli.js"
2302
+ },
2303
+ "files": [
2304
+ "bin",
2305
+ "public",
2306
+ ".next",
2307
+ "src",
2308
+ "next.config.ts",
2309
+ "tsconfig.json",
2310
+ "README.md"
2311
+ ],
2312
+ "scripts": {
2313
+ "dev": "next dev",
2314
+ "build": "next build",
2315
+ "start": "next start",
2316
+ "lint": "eslint"
2317
+ },
2318
+ "dependencies": {
2319
+ "@monaco-editor/react": "^4.7.0",
2320
+ "@xterm/addon-search": "^0.16.0",
2321
+ "mssql": "^12.5.5",
2322
+ "next": "16.2.6",
2323
+ "node-pty": "^1.1.0",
2324
+ "react": "19.2.4",
2325
+ "react-dom": "19.2.4",
2326
+ "ws": "^8.21.0",
2327
+ "xterm": "^5.3.0",
2328
+ "xterm-addon-fit": "^0.8.0"
2329
+ },
2330
+ "devDependencies": {
2331
+ "@types/node": "^20",
2332
+ "@types/react": "^19",
2333
+ "@types/react-dom": "^19",
2334
+ "@types/ws": "^8.18.1",
2335
+ "eslint": "^9",
2336
+ "eslint-config-next": "16.2.6",
2337
+ "typescript": "^5"
2338
+ }
2339
+ };
2340
+ }),
2341
+ "[project]/src/app/api/sessions/route.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
2342
+ "use strict";
2343
+
2344
+ __turbopack_context__.s([
2345
+ "GET",
2346
+ ()=>GET
2347
+ ]);
2348
+ var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/next/server.js [app-route] (ecmascript)");
2349
+ var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/lib/agents/SessionManager.ts [app-route] (ecmascript)");
2350
+ var __TURBOPACK__imported__module__$5b$project$5d2f$package$2e$json$2e5b$json$5d2e$cjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/package.json.[json].cjs [app-route] (ecmascript)");
2351
+ ;
2352
+ ;
2353
+ ;
2354
+ async function GET(request) {
2355
+ try {
2356
+ const { searchParams } = new URL(request.url);
2357
+ const id = searchParams.get("id");
2358
+ const manager = __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$lib$2f$agents$2f$SessionManager$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["SessionManager"].getInstance();
2359
+ if (id) {
2360
+ const session = manager.getSession(id);
2361
+ if (!session) {
2362
+ return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
2363
+ error: "Session not found"
2364
+ }, {
2365
+ status: 404
2366
+ });
2367
+ }
2368
+ return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
2369
+ ...session.getStatus(),
2370
+ logs: session.logs,
2371
+ wsPort: /*TURBOPACK member replacement*/ __turbopack_context__.g.wsPort || 9601,
2372
+ version: __TURBOPACK__imported__module__$5b$project$5d2f$package$2e$json$2e5b$json$5d2e$cjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].version
2373
+ });
2374
+ }
2375
+ const sessions = manager.listSessions();
2376
+ const originalCwd = process.env.ORIGINAL_CWD || process.cwd();
2377
+ const wsPort = /*TURBOPACK member replacement*/ __turbopack_context__.g.wsPort || 9601;
2378
+ return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
2379
+ sessions,
2380
+ originalCwd,
2381
+ wsPort,
2382
+ version: __TURBOPACK__imported__module__$5b$project$5d2f$package$2e$json$2e5b$json$5d2e$cjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].version
2383
+ });
2384
+ } catch (error) {
2385
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
2386
+ return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
2387
+ error: errorMessage
2388
+ }, {
2389
+ status: 500
2390
+ });
2391
+ }
2392
+ }
2393
+ }),
2394
+ ];
2395
+
2396
+ //# sourceMappingURL=%5Broot-of-the-server%5D__11uf~fd._.js.map