autodev-cli 1.4.0 → 1.4.4

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 (237) hide show
  1. package/bin/autodev.js +0 -0
  2. package/out/agentBackup/archive.d.ts +44 -0
  3. package/out/agentBackup/archive.js +131 -0
  4. package/out/agentBackup/archive.js.map +1 -0
  5. package/out/agentBackup/export.d.ts +18 -0
  6. package/out/agentBackup/export.js +92 -0
  7. package/out/agentBackup/export.js.map +1 -0
  8. package/out/agentBackup/import.d.ts +21 -0
  9. package/out/agentBackup/import.js +40 -0
  10. package/out/agentBackup/import.js.map +1 -0
  11. package/out/agentBackup/index.d.ts +6 -0
  12. package/out/agentBackup/index.js +11 -0
  13. package/out/agentBackup/index.js.map +1 -0
  14. package/out/agentBackup/layout.d.ts +30 -0
  15. package/out/agentBackup/layout.js +126 -0
  16. package/out/agentBackup/layout.js.map +1 -0
  17. package/out/agentBackup/manifest.d.ts +24 -0
  18. package/out/agentBackup/manifest.js +70 -0
  19. package/out/agentBackup/manifest.js.map +1 -0
  20. package/out/agentBackup/opencodeDb.d.ts +20 -0
  21. package/out/agentBackup/opencodeDb.js +213 -0
  22. package/out/agentBackup/opencodeDb.js.map +1 -0
  23. package/out/agentBackup/sessionProviders.d.ts +35 -0
  24. package/out/agentBackup/sessionProviders.js +263 -0
  25. package/out/agentBackup/sessionProviders.js.map +1 -0
  26. package/out/agentBackup/upload.d.ts +9 -0
  27. package/out/agentBackup/upload.js +121 -0
  28. package/out/agentBackup/upload.js.map +1 -0
  29. package/out/cli.d.ts +1 -0
  30. package/out/cli.js +8 -0
  31. package/out/cli.js.map +1 -1
  32. package/out/cliExit.d.ts +34 -0
  33. package/out/cliExit.js +159 -0
  34. package/out/cliExit.js.map +1 -0
  35. package/out/commands/config.d.ts +2 -0
  36. package/out/commands/config.js +7 -7
  37. package/out/commands/config.js.map +1 -1
  38. package/out/commands/connect.d.ts +2 -0
  39. package/out/commands/connect.js +11 -0
  40. package/out/commands/connect.js.map +1 -1
  41. package/out/commands/export.d.ts +2 -0
  42. package/out/commands/export.js +79 -0
  43. package/out/commands/export.js.map +1 -0
  44. package/out/commands/import.d.ts +2 -0
  45. package/out/commands/import.js +92 -0
  46. package/out/commands/import.js.map +1 -0
  47. package/out/commands/init.d.ts +16 -0
  48. package/out/commands/init.js +9 -5
  49. package/out/commands/init.js.map +1 -1
  50. package/out/commands/resume.d.ts +2 -0
  51. package/out/commands/resume.js +65 -0
  52. package/out/commands/resume.js.map +1 -0
  53. package/out/commands/sessions.d.ts +2 -0
  54. package/out/commands/sessions.js +64 -0
  55. package/out/commands/sessions.js.map +1 -0
  56. package/out/commands/start.d.ts +2 -0
  57. package/out/commands/start.js +40 -7
  58. package/out/commands/start.js.map +1 -1
  59. package/out/commands/status.d.ts +2 -0
  60. package/out/commands/status.js +3 -3
  61. package/out/commands/status.js.map +1 -1
  62. package/out/commands/tailOutput.d.ts +12 -0
  63. package/out/commands/up.d.ts +3 -0
  64. package/out/configManager.d.ts +42 -0
  65. package/out/configManager.js +447 -0
  66. package/out/configManager.js.map +1 -0
  67. package/out/connect.d.ts +4 -0
  68. package/out/connect.js +7 -7
  69. package/out/connect.js.map +1 -1
  70. package/out/core/adapters.d.ts +34 -0
  71. package/out/core/adapters.js +84 -0
  72. package/out/core/adapters.js.map +1 -0
  73. package/out/core/commandHelpers.d.ts +12 -0
  74. package/out/core/commandHelpers.js +96 -0
  75. package/out/core/commandHelpers.js.map +1 -0
  76. package/out/core/projectMcp.d.ts +34 -0
  77. package/out/core/projectMcp.js +160 -0
  78. package/out/core/projectMcp.js.map +1 -0
  79. package/out/core/provider/BaseProvider.d.ts +14 -0
  80. package/out/core/provider/BaseProvider.js +25 -0
  81. package/out/core/provider/BaseProvider.js.map +1 -0
  82. package/out/core/provider/ProviderRegistry.d.ts +12 -0
  83. package/out/core/provider/ProviderRegistry.js +40 -0
  84. package/out/core/provider/ProviderRegistry.js.map +1 -0
  85. package/out/core/provider/contract.d.ts +62 -0
  86. package/out/core/provider/contract.js +9 -0
  87. package/out/core/provider/contract.js.map +1 -0
  88. package/out/core/provider/implementations.d.ts +54 -0
  89. package/out/core/provider/implementations.js +147 -0
  90. package/out/core/provider/implementations.js.map +1 -0
  91. package/out/core/settingsLoader.d.ts +221 -0
  92. package/out/core/settingsLoader.js +176 -0
  93. package/out/core/settingsLoader.js.map +1 -0
  94. package/out/discordGateway.d.ts +26 -0
  95. package/out/discordGateway.js +230 -0
  96. package/out/discordGateway.js.map +1 -0
  97. package/out/discordPoller.d.ts +28 -0
  98. package/out/discordPoller.js +247 -0
  99. package/out/discordPoller.js.map +1 -0
  100. package/out/dispatcher.d.ts +12 -0
  101. package/out/dispatcher.js +214 -0
  102. package/out/dispatcher.js.map +1 -0
  103. package/out/emailPoller.d.ts +42 -0
  104. package/out/emailPoller.js +221 -0
  105. package/out/emailPoller.js.map +1 -0
  106. package/out/git/gitService.d.ts +36 -0
  107. package/out/git/gitService.js +165 -0
  108. package/out/git/gitService.js.map +1 -0
  109. package/out/hookEventNormalizer.d.ts +39 -0
  110. package/out/hookEventNormalizer.js +397 -0
  111. package/out/hookEventNormalizer.js.map +1 -0
  112. package/out/hooksManager.d.ts +25 -0
  113. package/out/hooksManager.js +471 -0
  114. package/out/hooksManager.js.map +1 -0
  115. package/out/launchIde.d.ts +14 -0
  116. package/out/logger.d.ts +12 -0
  117. package/out/mcpEmailTest.d.ts +29 -0
  118. package/out/mcpEmailTest.js +245 -0
  119. package/out/mcpEmailTest.js.map +1 -0
  120. package/out/mcpInstallCheck.d.ts +23 -0
  121. package/out/mcpInstallCheck.js +219 -0
  122. package/out/mcpInstallCheck.js.map +1 -0
  123. package/out/mcpManager.d.ts +35 -0
  124. package/out/mcpManager.js +371 -0
  125. package/out/mcpManager.js.map +1 -0
  126. package/out/messageBuilder.d.ts +54 -0
  127. package/out/messageBuilder.js +373 -0
  128. package/out/messageBuilder.js.map +1 -0
  129. package/out/openCodeHooksManager.d.ts +23 -0
  130. package/out/openCodeHooksManager.js +511 -0
  131. package/out/openCodeHooksManager.js.map +1 -0
  132. package/out/periodicActions.d.ts +63 -0
  133. package/out/periodicActions.js +237 -0
  134. package/out/periodicActions.js.map +1 -0
  135. package/out/profileBuilder.d.ts +29 -0
  136. package/out/profileBuilder.js +366 -0
  137. package/out/profileBuilder.js.map +1 -0
  138. package/out/prompt.d.ts +12 -0
  139. package/out/prompt.js +18 -0
  140. package/out/prompt.js.map +1 -0
  141. package/out/protocolSections.d.ts +26 -0
  142. package/out/protocolSections.js +209 -0
  143. package/out/protocolSections.js.map +1 -0
  144. package/out/providers/claudeCliProvider.d.ts +71 -0
  145. package/out/providers/claudeCliProvider.js +425 -0
  146. package/out/providers/claudeCliProvider.js.map +1 -0
  147. package/out/providers/claudeTuiProvider.d.ts +23 -0
  148. package/out/providers/claudeTuiProvider.js +296 -0
  149. package/out/providers/claudeTuiProvider.js.map +1 -0
  150. package/out/providers/copilotCliProvider.d.ts +16 -0
  151. package/out/providers/copilotCliProvider.js +44 -0
  152. package/out/providers/copilotCliProvider.js.map +1 -0
  153. package/out/providers/copilotSdkProvider.d.ts +12 -0
  154. package/out/providers/copilotSdkProvider.js +445 -0
  155. package/out/providers/copilotSdkProvider.js.map +1 -0
  156. package/out/providers/grokTuiProvider.d.ts +14 -0
  157. package/out/providers/grokTuiProvider.js +271 -0
  158. package/out/providers/grokTuiProvider.js.map +1 -0
  159. package/out/providers/opencodeCliProvider.d.ts +29 -0
  160. package/out/providers/opencodeCliProvider.js +199 -0
  161. package/out/providers/opencodeCliProvider.js.map +1 -0
  162. package/out/providers/opencodeSdkProvider.d.ts +22 -0
  163. package/out/providers/opencodeSdkProvider.js +557 -0
  164. package/out/providers/opencodeSdkProvider.js.map +1 -0
  165. package/out/providers.d.ts +9 -0
  166. package/out/providers.js +44 -0
  167. package/out/providers.js.map +1 -0
  168. package/out/rateLimit.d.ts +18 -0
  169. package/out/rateLimit.js +90 -0
  170. package/out/rateLimit.js.map +1 -0
  171. package/out/rdp/auth.d.ts +55 -0
  172. package/out/rdp/auth.js +197 -0
  173. package/out/rdp/auth.js.map +1 -0
  174. package/out/rdp/bridge.d.ts +86 -0
  175. package/out/rdp/bridge.js +1398 -0
  176. package/out/rdp/bridge.js.map +1 -0
  177. package/out/rdp/constants.d.ts +86 -0
  178. package/out/rdp/constants.js +182 -0
  179. package/out/rdp/constants.js.map +1 -0
  180. package/out/rdp/index.d.ts +7 -0
  181. package/out/rdp/index.js +14 -0
  182. package/out/rdp/index.js.map +1 -0
  183. package/out/rdp/session.d.ts +30 -0
  184. package/out/rdp/session.js +196 -0
  185. package/out/rdp/session.js.map +1 -0
  186. package/out/rdp/types.d.ts +27 -0
  187. package/out/rdp/types.js +6 -0
  188. package/out/rdp/types.js.map +1 -0
  189. package/out/sdk/index.d.ts +22 -0
  190. package/out/sdk/index.js +81 -0
  191. package/out/sdk/index.js.map +1 -0
  192. package/out/sessionState.d.ts +54 -0
  193. package/out/sessionState.js +284 -0
  194. package/out/sessionState.js.map +1 -0
  195. package/out/sessions.d.ts +11 -0
  196. package/out/sessions.js +32 -0
  197. package/out/sessions.js.map +1 -0
  198. package/out/taskLoop.d.ts +152 -0
  199. package/out/taskLoop.js +2505 -0
  200. package/out/taskLoop.js.map +1 -0
  201. package/out/todo.d.ts +42 -0
  202. package/out/todo.js +311 -0
  203. package/out/todo.js.map +1 -0
  204. package/out/todoWriteManager.d.ts +26 -0
  205. package/out/todoWriteManager.js +44 -0
  206. package/out/todoWriteManager.js.map +1 -0
  207. package/out/vnc/auth.d.ts +52 -0
  208. package/out/vnc/auth.js +181 -0
  209. package/out/vnc/auth.js.map +1 -0
  210. package/out/vnc/bridge.d.ts +40 -0
  211. package/out/vnc/bridge.js +540 -0
  212. package/out/vnc/bridge.js.map +1 -0
  213. package/out/vnc/constants.d.ts +8 -0
  214. package/out/vnc/constants.js +34 -0
  215. package/out/vnc/constants.js.map +1 -0
  216. package/out/vnc/des.d.ts +6 -0
  217. package/out/vnc/des.js +93 -0
  218. package/out/vnc/des.js.map +1 -0
  219. package/out/vnc/index.d.ts +7 -0
  220. package/out/vnc/index.js +13 -0
  221. package/out/vnc/index.js.map +1 -0
  222. package/out/vnc/session.d.ts +18 -0
  223. package/out/vnc/session.js +193 -0
  224. package/out/vnc/session.js.map +1 -0
  225. package/out/vnc/types.d.ts +16 -0
  226. package/out/vnc/types.js +6 -0
  227. package/out/vnc/types.js.map +1 -0
  228. package/out/webSocketPoller.d.ts +95 -0
  229. package/out/webSocketPoller.js +986 -0
  230. package/out/webSocketPoller.js.map +1 -0
  231. package/out/webhook.d.ts +37 -0
  232. package/out/webhook.js +265 -0
  233. package/out/webhook.js.map +1 -0
  234. package/out/webhookPoller.d.ts +40 -0
  235. package/out/webhookPoller.js +378 -0
  236. package/out/webhookPoller.js.map +1 -0
  237. package/package.json +54 -41
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.AGENT_PROFILE_FILE = exports.PROMPT_FILE = exports.SESSION_OUT_FILE = exports.SESSION_STATE_FILE = void 0;
37
+ exports.autodevDir = autodevDir;
38
+ exports.latestMessageId = latestMessageId;
39
+ exports.stdoutFilePath = stdoutFilePath;
40
+ exports.exitFilePath = exitFilePath;
41
+ exports.newMessageOutput = newMessageOutput;
42
+ exports.getSessionId = getSessionId;
43
+ exports.saveSessionId = saveSessionId;
44
+ exports.clearSessionId = clearSessionId;
45
+ exports.getSessionClearedAt = getSessionClearedAt;
46
+ exports.saveSessionName = saveSessionName;
47
+ exports.getSessionName = getSessionName;
48
+ exports.extractClaudeSessionId = extractClaudeSessionId;
49
+ exports.extractCopilotSessionId = extractCopilotSessionId;
50
+ exports.extractOpenCodeSessionId = extractOpenCodeSessionId;
51
+ exports.captureAndSaveSessionId = captureAndSaveSessionId;
52
+ const fs = __importStar(require("fs"));
53
+ const path = __importStar(require("path"));
54
+ // ---------------------------------------------------------------------------
55
+ // All autodev runtime files live under <workspace>/.autodev/
56
+ // ---------------------------------------------------------------------------
57
+ /** Returns the .autodev directory path, creating it if needed. */
58
+ function autodevDir(root) {
59
+ const dir = path.join(root, '.autodev');
60
+ if (!fs.existsSync(dir)) {
61
+ fs.mkdirSync(dir, { recursive: true });
62
+ }
63
+ return dir;
64
+ }
65
+ /** .autodev/session-state.json — session IDs keyed by provider */
66
+ exports.SESSION_STATE_FILE = '.autodev/session-state.json';
67
+ /** .autodev/TEMP_SESSION_OUT.txt — CLI stdout tee for session ID extraction */
68
+ exports.SESSION_OUT_FILE = '.autodev/TEMP_SESSION_OUT.txt';
69
+ /** .autodev/TEMP_PROMPT.md — prompt written for CLI providers (legacy) */
70
+ exports.PROMPT_FILE = '.autodev/TEMP_PROMPT.md';
71
+ /** .autodev/AGENT_PROFILE.md — profile instructions written per task */
72
+ exports.AGENT_PROFILE_FILE = '.autodev/AGENT_PROFILE.md';
73
+ // ---------------------------------------------------------------------------
74
+ // Per-message output files
75
+ // ───────────────────────────────────────────────────────────────────────────
76
+ // Each CLI dispatch gets a unique messageId. Output and exit files live at:
77
+ // .autodev/output/<providerId>/<messageId>.txt ← stdout capture
78
+ // .autodev/output/<providerId>/<messageId>.exit.txt ← exit code
79
+ // A pointer file `.autodev/output/<providerId>.latest` always contains the
80
+ // current messageId, so existing callers of `stdoutFilePath/exitFilePath`
81
+ // transparently see the latest message's files without API changes.
82
+ //
83
+ // This prevents the previous bug where the shared per-provider file got
84
+ // overwritten between back-to-back tasks, sometimes losing the final output.
85
+ // ---------------------------------------------------------------------------
86
+ const MAX_MESSAGES_KEPT = 100; // delete older than this per provider
87
+ function outputBase(root) {
88
+ const dir = path.join(autodevDir(root), 'output');
89
+ if (!fs.existsSync(dir)) {
90
+ fs.mkdirSync(dir, { recursive: true });
91
+ }
92
+ return dir;
93
+ }
94
+ function pointerPath(root, providerId) {
95
+ return path.join(outputBase(root), `${providerId}.latest`);
96
+ }
97
+ function legacyStdoutPath(root, providerId) {
98
+ return path.join(outputBase(root), `${providerId}.txt`);
99
+ }
100
+ function legacyExitPath(root, providerId) {
101
+ return path.join(outputBase(root), `${providerId}-exit.txt`);
102
+ }
103
+ /** Read the messageId currently pointed at, or null if none yet. */
104
+ function latestMessageId(root, providerId) {
105
+ try {
106
+ const p = pointerPath(root, providerId);
107
+ if (!fs.existsSync(p)) {
108
+ return null;
109
+ }
110
+ const id = fs.readFileSync(p, 'utf8').trim();
111
+ return id || null;
112
+ }
113
+ catch {
114
+ return null;
115
+ }
116
+ }
117
+ /** Path of the latest message's stdout file. Falls back to legacy path if
118
+ * no message has been rotated yet (so first-time installs keep working). */
119
+ function stdoutFilePath(root, providerId) {
120
+ const id = latestMessageId(root, providerId);
121
+ if (!id) {
122
+ return legacyStdoutPath(root, providerId);
123
+ }
124
+ const dir = path.join(outputBase(root), providerId);
125
+ if (!fs.existsSync(dir)) {
126
+ fs.mkdirSync(dir, { recursive: true });
127
+ }
128
+ return path.join(dir, `${id}.txt`);
129
+ }
130
+ /** Path of the latest message's exit file. */
131
+ function exitFilePath(root, providerId) {
132
+ const id = latestMessageId(root, providerId);
133
+ if (!id) {
134
+ return legacyExitPath(root, providerId);
135
+ }
136
+ const dir = path.join(outputBase(root), providerId);
137
+ if (!fs.existsSync(dir)) {
138
+ fs.mkdirSync(dir, { recursive: true });
139
+ }
140
+ return path.join(dir, `${id}.exit.txt`);
141
+ }
142
+ /** Rotate to a fresh messageId and return the empty stdout/exit file paths
143
+ * the dispatcher should write to and tee into. Updates the pointer file so
144
+ * every subsequent call to stdoutFilePath/exitFilePath returns these paths. */
145
+ function newMessageOutput(root, providerId) {
146
+ const messageId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
147
+ const dir = path.join(outputBase(root), providerId);
148
+ if (!fs.existsSync(dir)) {
149
+ fs.mkdirSync(dir, { recursive: true });
150
+ }
151
+ const stdoutFile = path.join(dir, `${messageId}.txt`);
152
+ const exitFile = path.join(dir, `${messageId}.exit.txt`);
153
+ // Atomically point at the new id BEFORE returning so concurrent readers see it
154
+ fs.writeFileSync(pointerPath(root, providerId), messageId, 'utf8');
155
+ // Best-effort cleanup of older messages
156
+ pruneOldMessages(dir, MAX_MESSAGES_KEPT);
157
+ return { messageId, stdoutFile, exitFile };
158
+ }
159
+ function pruneOldMessages(dir, keep) {
160
+ try {
161
+ const files = fs.readdirSync(dir);
162
+ // Distinct message IDs derived from filenames `<id>.txt` / `<id>.exit.txt`
163
+ const ids = Array.from(new Set(files.map(f => f.replace(/\.exit\.txt$|\.txt$/, ''))
164
+ .filter(id => id && id !== ''))).sort(); // lexicographic = chronological since IDs start with Date.now()
165
+ const toDelete = ids.slice(0, Math.max(0, ids.length - keep));
166
+ for (const id of toDelete) {
167
+ try {
168
+ fs.unlinkSync(path.join(dir, `${id}.txt`));
169
+ }
170
+ catch { /* ignore */ }
171
+ try {
172
+ fs.unlinkSync(path.join(dir, `${id}.exit.txt`));
173
+ }
174
+ catch { /* ignore */ }
175
+ }
176
+ }
177
+ catch { /* ignore */ }
178
+ }
179
+ function readMap(root) {
180
+ try {
181
+ const p = path.join(root, exports.SESSION_STATE_FILE);
182
+ if (fs.existsSync(p)) {
183
+ return JSON.parse(fs.readFileSync(p, 'utf8'));
184
+ }
185
+ }
186
+ catch { }
187
+ return {};
188
+ }
189
+ function writeMap(root, map) {
190
+ autodevDir(root); // ensure dir exists
191
+ fs.writeFileSync(path.join(root, exports.SESSION_STATE_FILE), JSON.stringify(map, null, 2), 'utf8');
192
+ }
193
+ function getSessionId(root, providerId) {
194
+ return readMap(root)[providerId] ?? undefined;
195
+ }
196
+ function saveSessionId(root, providerId, sessionId) {
197
+ const map = readMap(root);
198
+ map[providerId] = sessionId;
199
+ writeMap(root, map);
200
+ }
201
+ function clearSessionId(root, providerId) {
202
+ const map = readMap(root);
203
+ delete map[providerId];
204
+ // Record the time of the clear so discovery helpers can ignore stale sessions
205
+ map[`${providerId}-cleared-at`] = String(Date.now());
206
+ writeMap(root, map);
207
+ }
208
+ /**
209
+ * Returns the epoch-ms timestamp of the last clearSessionId() call for this
210
+ * provider, or 0 if clearSessionId() has never been called.
211
+ */
212
+ function getSessionClearedAt(root, providerId) {
213
+ const raw = readMap(root)[`${providerId}-cleared-at`];
214
+ return raw ? parseInt(raw, 10) : 0;
215
+ }
216
+ // ---------------------------------------------------------------------------
217
+ // Session display names — stored in session-state.json keyed by session ID
218
+ // ---------------------------------------------------------------------------
219
+ /** Save a human-readable display name for a session ID. */
220
+ function saveSessionName(root, sessionId, name) {
221
+ const map = readMap(root);
222
+ map[`name:${sessionId}`] = name;
223
+ writeMap(root, map);
224
+ }
225
+ /** Get the saved display name for a session ID, or undefined if none. */
226
+ function getSessionName(root, sessionId) {
227
+ return readMap(root)[`name:${sessionId}`] ?? undefined;
228
+ }
229
+ // ---------------------------------------------------------------------------
230
+ // Session ID extractors — scan raw stdout per provider
231
+ // ---------------------------------------------------------------------------
232
+ /** Claude: "session_id":"<id>" in --output-format stream-json events */
233
+ function extractClaudeSessionId(stdout) {
234
+ return stdout.match(/"session_id"\s*:\s*"([^"]+)"/)?.[1];
235
+ }
236
+ /** Copilot: "sessionId":"<id>" in JSON stream */
237
+ function extractCopilotSessionId(stdout) {
238
+ return stdout.match(/"sessionId"\s*:\s*"([^"]+)"/)?.[1];
239
+ }
240
+ /** OpenCode: "sessionID":"ses_xxx" in --format json event stream */
241
+ function extractOpenCodeSessionId(stdout) {
242
+ return stdout.match(/"sessionID"\s*:\s*"(ses_[^"]+)"/)?.[1];
243
+ }
244
+ /**
245
+ * After a CLI task finishes, try to capture and persist the session ID.
246
+ * - claude-cli: reads from .autodev/output/claude-cli.txt (stdout tee)
247
+ * - opencode-cli: reads from .autodev/output/opencode-cli.txt (--format json tee)
248
+ * - copilot-cli: reads from .autodev/TEMP_SESSION_OUT.txt
249
+ * Falls back silently — never throws.
250
+ */
251
+ function captureAndSaveSessionId(root, providerId,
252
+ /** Fallback session ID (e.g. from findLatestClaudeSession for claude-cli) */
253
+ fallbackSessionId) {
254
+ try {
255
+ // All CLI providers tee stdout to the per-message capture file now.
256
+ // Falls back to the legacy SESSION_OUT_FILE only if the latest-message
257
+ // file is absent (e.g. very first dispatch hasn't created a pointer yet).
258
+ const captureFile = fs.existsSync(stdoutFilePath(root, providerId))
259
+ ? stdoutFilePath(root, providerId)
260
+ : path.join(root, exports.SESSION_OUT_FILE);
261
+ if (fs.existsSync(captureFile)) {
262
+ const stdout = fs.readFileSync(captureFile, 'utf8');
263
+ let id;
264
+ if (providerId === 'claude-cli') {
265
+ id = extractClaudeSessionId(stdout);
266
+ }
267
+ if (providerId === 'copilot-cli') {
268
+ id = extractCopilotSessionId(stdout);
269
+ }
270
+ if (providerId === 'opencode-cli') {
271
+ id = extractOpenCodeSessionId(stdout);
272
+ }
273
+ if (id) {
274
+ saveSessionId(root, providerId, id);
275
+ return;
276
+ }
277
+ }
278
+ if (fallbackSessionId) {
279
+ saveSessionId(root, providerId, fallbackSessionId);
280
+ }
281
+ }
282
+ catch { }
283
+ }
284
+ //# sourceMappingURL=sessionState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionState.js","sourceRoot":"","sources":["../src/sessionState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,gCAIC;AAiDD,0CAOC;AAID,wCAMC;AAGD,oCAMC;AAKD,4CAcC;AAiCD,oCAEC;AAED,sCAIC;AAED,wCAMC;AAMD,kDAGC;AAOD,0CAIC;AAGD,wCAEC;AAOD,wDAEC;AAGD,0DAEC;AAGD,4DAEC;AASD,0DAuBC;AAxOD,uCAAyB;AACzB,2CAA6B;AAG7B,8EAA8E;AAC9E,6DAA6D;AAC7D,8EAA8E;AAE9E,kEAAkE;AAClE,SAAgB,UAAU,CAAC,IAAY;IACrC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAAC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAAC,CAAC;IACpE,OAAO,GAAG,CAAC;AACb,CAAC;AAED,kEAAkE;AACrD,QAAA,kBAAkB,GAAG,6BAA6B,CAAC;AAEhE,+EAA+E;AAClE,QAAA,gBAAgB,GAAG,+BAA+B,CAAC;AAEhE,0EAA0E;AAC7D,QAAA,WAAW,GAAG,yBAAyB,CAAC;AAErD,wEAAwE;AAC3D,QAAA,kBAAkB,GAAG,2BAA2B,CAAC;AAE9D,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAC9E,4EAA4E;AAC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C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,wBAAgB,CAAC,CAAC;QACtC,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YACpD,IAAI,EAAsB,CAAC;YAC3B,IAAI,UAAU,KAAK,YAAY,EAAK,CAAC;gBAAC,EAAE,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;YAAC,CAAC;YAC5E,IAAI,UAAU,KAAK,aAAa,EAAI,CAAC;gBAAC,EAAE,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;YAAC,CAAC;YAC7E,IAAI,UAAU,KAAK,cAAc,EAAG,CAAC;gBAAC,EAAE,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;YAAC,CAAC;YAC9E,IAAI,EAAE,EAAE,CAAC;gBAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;gBAAC,OAAO;YAAC,CAAC;QAC1D,CAAC;QACD,IAAI,iBAAiB,EAAE,CAAC;YAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;QAAC,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ProviderId } from './providers';
2
+ export interface SessionInfo {
3
+ provider: 'claude' | 'opencode' | string;
4
+ id: string;
5
+ name: string;
6
+ updated: number;
7
+ active?: boolean;
8
+ }
9
+ /** List sessions for a workspace. If `provider` is omitted, infer the family
10
+ * from settings and include claude + opencode (the inspectable stores). */
11
+ export declare function collectSessions(root: string, provider?: ProviderId): SessionInfo[];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectSessions = collectSessions;
4
+ // ---------------------------------------------------------------------------
5
+ // Cross-provider session listing for a workspace — surfaces existing sessions
6
+ // (id + display name/title + last-updated) so UIs (CLI, app) can show and
7
+ // resume them. Provider-aware; honest about which stores are inspectable.
8
+ // ---------------------------------------------------------------------------
9
+ const claudeCliProvider_1 = require("./providers/claudeCliProvider");
10
+ const opencodeDb_1 = require("./agentBackup/opencodeDb");
11
+ const settingsLoader_1 = require("./core/settingsLoader");
12
+ /** List sessions for a workspace. If `provider` is omitted, infer the family
13
+ * from settings and include claude + opencode (the inspectable stores). */
14
+ function collectSessions(root, provider) {
15
+ const settings = (0, settingsLoader_1.loadSettingsForRoot)(root);
16
+ const fam = (provider ?? settings.provider ?? 'claude-cli');
17
+ const out = [];
18
+ const wantClaude = fam.startsWith('claude') || !provider;
19
+ const wantOpencode = fam.startsWith('opencode') || !provider;
20
+ if (wantClaude) {
21
+ for (const s of (0, claudeCliProvider_1.listClaudeSessions)(root)) {
22
+ out.push({ provider: 'claude', id: s.id, name: (0, claudeCliProvider_1.getClaudeSessionDisplay)(s.id) || '(untitled)', updated: s.mtime });
23
+ }
24
+ }
25
+ if (wantOpencode) {
26
+ for (const s of (0, opencodeDb_1.listOpenCodeSessionsDetailed)(root)) {
27
+ out.push({ provider: 'opencode', id: s.id, name: s.title || '(untitled)', updated: s.updated });
28
+ }
29
+ }
30
+ return out.sort((a, b) => b.updated - a.updated);
31
+ }
32
+ //# sourceMappingURL=sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":";;AAoBA,0CAmBC;AAvCD,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,0EAA0E;AAC1E,8EAA8E;AAC9E,qEAA4F;AAC5F,yDAAwE;AACxE,0DAA4D;AAW5D;4EAC4E;AAC5E,SAAgB,eAAe,CAAC,IAAY,EAAE,QAAqB;IACjE,MAAM,QAAQ,GAAG,IAAA,oCAAmB,EAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,IAAI,YAAY,CAAC,CAAC;IAC5D,MAAM,GAAG,GAAkB,EAAE,CAAC;IAE9B,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzD,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;IAE7D,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,MAAM,CAAC,IAAI,IAAA,sCAAkB,EAAC,IAAI,CAAC,EAAE,CAAC;YACzC,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,IAAA,2CAAuB,EAAC,CAAC,CAAC,EAAE,CAAC,IAAI,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACpH,CAAC;IACH,CAAC;IACD,IAAI,YAAY,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,IAAI,IAAA,yCAA4B,EAAC,IAAI,CAAC,EAAE,CAAC;YACnD,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAClG,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { IFileWatcher } from './core/adapters';
2
+ import { ProviderId } from './providers';
3
+ export type LoopState = 'idle' | 'running' | 'stopping' | 'paused';
4
+ export interface LoopCallbacks {
5
+ /** Send a prompt to the active AI provider. messageFile is the absolute path of the written .md file for CLI providers. */
6
+ sendToAi: (prompt: string, taskLabel: string, includeProfile?: boolean, messageFile?: string) => Promise<void>;
7
+ /** Append a message to the extension's output channel */
8
+ log: (msg: string) => void;
9
+ /** Called whenever the loop state changes so the sidebar can refresh */
10
+ onStatusChange: (state: LoopState, currentTask?: string) => void;
11
+ /** Called when Claude's current tool activity changes (undefined = idle/done) */
12
+ onActivityChange?: (activity: string | undefined) => void;
13
+ /** Called once when the queue drains (all tasks done). Used by `--once` to stop. */
14
+ onAllTasksDone?: () => void;
15
+ /** Returns the currently selected provider ID (live, not from settings file) */
16
+ getActiveProvider: () => ProviderId;
17
+ /** Transiently override the active provider (e.g. fallback on rate limit). */
18
+ setActiveProvider?: (id: ProviderId) => void;
19
+ /** Absolute path to the workspace root directory */
20
+ workspaceRoot: string;
21
+ /** File watcher used to monitor TODO.md and output files */
22
+ fileWatcher: IFileWatcher;
23
+ }
24
+ export declare class TaskLoopRunner {
25
+ private _state;
26
+ private _currentTask;
27
+ private _taskWatcher;
28
+ private _iterations;
29
+ private _cb;
30
+ private _webhook;
31
+ private _settings;
32
+ private _workspaceRoot;
33
+ private _discordPoller;
34
+ private _discordGateway;
35
+ private _webhookPoller;
36
+ private _emailPoller;
37
+ /** True after we last told the server "all_tasks_done" — cleared on task_start.
38
+ * Used to re-assert idle state on WS reconnect, otherwise agent_online flips
39
+ * the server-side status back to 'active' even though we have no work. */
40
+ private _idleNotified;
41
+ private _pollerIntervals;
42
+ private _hooksFileOffset;
43
+ /** Recently-forwarded hook-line hashes → first-seen timestamp (ms).
44
+ * Used to suppress byte-identical hook events that get appended multiple
45
+ * times to the shared JSONL (Copilot CLI fires the same hook from every
46
+ * parallel session in the same workspace, all writing to one homedir
47
+ * file). Entries older than HOOKS_DEDUPE_WINDOW_MS are pruned each tick. */
48
+ private _hookLineSeen;
49
+ private _taskCompletionAbort;
50
+ private _retryScheduler;
51
+ private _resumeResolve;
52
+ /** Resolves the idle no-task sleep early when a poller appends a new task. */
53
+ private _idleSleepWake;
54
+ private _resumeAt;
55
+ /** When fallback is active: the saved main provider and when to switch back. */
56
+ private _mainProviderBeforeFallback;
57
+ private _mainProviderResumeAt;
58
+ private _gitRepo;
59
+ private _gitBranch;
60
+ private _hostname;
61
+ private _completedCount;
62
+ private _failedCount;
63
+ private _loopStartTime;
64
+ /** Task lines that have already had /compact run — prevents infinite compact loops. */
65
+ private _compactedTaskLines;
66
+ /** True while a compact operation is in progress — prevents nested/recursive compacts. */
67
+ private _compacting;
68
+ /** Timestamp (ms) when compact was last run — used to throttle auto-compact (minimum 2min between compacts). */
69
+ private _lastCompactTime;
70
+ /** Dispatch attempt counter per task key (id or text). After 3 failed attempts the
71
+ * loop force-marks the task done so it doesn't block the queue indefinitely. */
72
+ private _taskAttempts;
73
+ /** Counts completed tasks since the last auto-compact run. */
74
+ private _autoCompactCounter;
75
+ /** Counts completed tasks since the last session reset. */
76
+ private _resetSessionCounter;
77
+ /** Counts tasks dispatched since the last profile-included send. */
78
+ private _profileSentCounter;
79
+ /** Manages all "every N tasks" periodic action counters. */
80
+ private readonly _periodicMgr;
81
+ get state(): LoopState;
82
+ get currentTask(): string | undefined;
83
+ get resumeAt(): Date | undefined;
84
+ /** Manually trigger a /compact on the current session for the given provider/root. */
85
+ compact(root: string, provider: ProviderId): Promise<void>;
86
+ /** Manually trigger a /clear on the current Claude session for the given provider/root. */
87
+ clearSession(root: string, provider: ProviderId): Promise<void>;
88
+ /** Resume the loop after a rate-limit pause. Clears the scheduled timer. */
89
+ retry(): void;
90
+ start(callbacks: LoopCallbacks): Promise<void>;
91
+ stop(): void;
92
+ /**
93
+ * Stop the loop and, once it reaches idle, start it again with the same
94
+ * callbacks. Useful for picking up new MCP server configs etc.
95
+ */
96
+ restart(): Promise<void>;
97
+ /** Handle mcp_update pushed from pixel-office: write .mcp.json, sync all providers, restart loop. */
98
+ private _handleMcpUpdate;
99
+ /** Handle export_request from pixel-office: create backup zip and upload. */
100
+ private _handleExportRequest;
101
+ /** Handle restore_request from pixel-office: download zip and restore workspace. */
102
+ private _handleRestoreRequest;
103
+ /** Handle export_config from pixel-office: persist exportEnabled + exportDailyBackup to settings. */
104
+ private _handleExportConfig;
105
+ /** Check if a daily backup is due and trigger it automatically. */
106
+ private _checkDailyBackup;
107
+ private _saveLastBackupTime;
108
+ /** Dispatch a slash command received from any inbound channel. */
109
+ private _handleCommand;
110
+ /**
111
+ * Build an EmailTaskPoller from the Email MCP entry's env block, or return
112
+ * null if the feature is disabled or required IMAP creds are missing.
113
+ */
114
+ private _buildEmailPoller;
115
+ /**
116
+ * Start Discord and webhook server pollers as independent setInterval loops.
117
+ * They run continuously in the background — even while the AI is processing a task.
118
+ */
119
+ private _startPollers;
120
+ /**
121
+ * Run `cozempic init` in the given project directory if:
122
+ * 1. `cozempic` is on the PATH (or login-shell PATH on Unix)
123
+ * 2. The project hasn't been initialised yet
124
+ * (`.claude/settings.local.json` does not contain a cozempic hook entry)
125
+ *
126
+ * Runs synchronously in a background thread-pool task (spawnSync) so it
127
+ * doesn't block the VS Code event loop but still logs completion.
128
+ */
129
+ private _runCozempicInit;
130
+ private _stopPollers;
131
+ private _runLoop;
132
+ /**
133
+ * Suspend the loop in 'paused' state.
134
+ * Resolves when retry() is called or (optionally) the timer fires.
135
+ * MUST be called only from _runLoop.
136
+ */
137
+ private _pauseLoop;
138
+ /** Interrupt the idle no-task sleep — called by pollers when they append a task. */
139
+ private _wakeIdleSleep;
140
+ /** sleep() that resolves early when _wakeIdleSleep() is called. */
141
+ private _sleepOrWake;
142
+ /** sleep() that resolves immediately when the task-completion abort fires. */
143
+ private _sleepAbortable;
144
+ /** Return when the task text appears with [x] status in the TODO.md file. */
145
+ private _waitForTaskCompletion;
146
+ private _disposeWatcher;
147
+ private _setState;
148
+ private _notifyWebhook;
149
+ private _notifyDiscord;
150
+ }
151
+ /** Singleton runner — one loop per workspace session. */
152
+ export declare const taskLoopRunner: TaskLoopRunner;