mcp-codex-subagent 1.0.0 → 2.0.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.
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +183 -4
- package/dist/server.js.map +1 -1
- package/dist/services/output-file.d.ts +38 -0
- package/dist/services/output-file.d.ts.map +1 -0
- package/dist/services/output-file.js +136 -0
- package/dist/services/output-file.js.map +1 -0
- package/dist/services/task-manager.d.ts +69 -0
- package/dist/services/task-manager.d.ts.map +1 -0
- package/dist/services/task-manager.js +171 -0
- package/dist/services/task-manager.js.map +1 -0
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js +11 -2
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/handlers.d.ts +2 -1
- package/dist/tools/handlers.d.ts.map +1 -1
- package/dist/tools/handlers.js +196 -116
- package/dist/tools/handlers.js.map +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/brief-validator.d.ts +34 -0
- package/dist/utils/brief-validator.d.ts.map +1 -0
- package/dist/utils/brief-validator.js +251 -0
- package/dist/utils/brief-validator.js.map +1 -0
- package/dist/utils/format.d.ts +34 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +40 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/task-id-generator.d.ts +15 -0
- package/dist/utils/task-id-generator.d.ts.map +1 -0
- package/dist/utils/task-id-generator.js +45 -0
- package/dist/utils/task-id-generator.js.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { CodexMcpServer } from './server.js';
|
|
4
|
+
import { closeAllOutputHandles } from './services/output-file.js';
|
|
4
5
|
const SERVER_CONFIG = {
|
|
5
6
|
name: 'codex-mcp-server',
|
|
6
7
|
version: '0.0.6',
|
|
@@ -15,5 +16,17 @@ async function main() {
|
|
|
15
16
|
process.exit(1);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
19
|
+
// Graceful shutdown: close all output file handles
|
|
20
|
+
async function shutdown() {
|
|
21
|
+
try {
|
|
22
|
+
await closeAllOutputHandles();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Best-effort cleanup
|
|
26
|
+
}
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
process.on('SIGINT', shutdown);
|
|
30
|
+
process.on('SIGTERM', shutdown);
|
|
18
31
|
main();
|
|
19
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,OAAO;CACR,CAAC;AAEX,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;QACjD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,KAAK,UAAU,QAAQ;IACrB,IAAI,CAAC;QACH,MAAM,qBAAqB,EAAE,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAEhC,IAAI,EAAE,CAAC"}
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,KAAK,YAAY,EAKlB,MAAM,YAAY,CAAC;AAwBpB,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,MAAM,EAAE,YAAY;IA6BhC,OAAO,CAAC,aAAa;IAyOrB,OAAO,CAAC,eAAe;IAIjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
|
package/dist/server.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ListResourceTemplatesRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { TOOLS, } from './types.js';
|
|
6
6
|
import { handleError } from './errors.js';
|
|
7
7
|
import { toolDefinitions } from './tools/definitions.js';
|
|
8
|
-
import { toolHandlers } from './tools/handlers.js';
|
|
8
|
+
import { toolHandlers, setNotificationSender } from './tools/handlers.js';
|
|
9
|
+
import { getTask, getAllTasks, getTaskCounts, } from './services/task-manager.js';
|
|
10
|
+
/**
|
|
11
|
+
* Filter output lines to remove noise for resource display.
|
|
12
|
+
*/
|
|
13
|
+
function filterOutputForResource(lines) {
|
|
14
|
+
return lines.filter(line => {
|
|
15
|
+
if (!line.trim())
|
|
16
|
+
return false;
|
|
17
|
+
// Keep meaningful lines, skip internal debug noise
|
|
18
|
+
if (line.startsWith('[stderr]') && line.length < 20)
|
|
19
|
+
return false;
|
|
20
|
+
return true;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
9
23
|
export class CodexMcpServer {
|
|
10
24
|
server;
|
|
11
25
|
config;
|
|
@@ -17,9 +31,21 @@ export class CodexMcpServer {
|
|
|
17
31
|
}, {
|
|
18
32
|
capabilities: {
|
|
19
33
|
tools: {},
|
|
34
|
+
resources: {},
|
|
20
35
|
},
|
|
21
36
|
});
|
|
22
37
|
this.setupHandlers();
|
|
38
|
+
// Wire notification sender so handlers can send resource-changed notifications
|
|
39
|
+
setNotificationSender({
|
|
40
|
+
sendNotification: async (notification) => {
|
|
41
|
+
try {
|
|
42
|
+
await this.server.sendResourceListChanged();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Non-fatal
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
23
49
|
}
|
|
24
50
|
setupHandlers() {
|
|
25
51
|
// List tools handler
|
|
@@ -30,7 +56,6 @@ export class CodexMcpServer {
|
|
|
30
56
|
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
31
57
|
const { name, arguments: args } = request.params;
|
|
32
58
|
const progressToken = request.params._meta?.progressToken;
|
|
33
|
-
// Create progress sender that uses MCP notifications
|
|
34
59
|
const createProgressContext = () => {
|
|
35
60
|
let progressCount = 0;
|
|
36
61
|
return {
|
|
@@ -51,7 +76,6 @@ export class CodexMcpServer {
|
|
|
51
76
|
});
|
|
52
77
|
}
|
|
53
78
|
catch (err) {
|
|
54
|
-
// Log but don't fail the operation if progress notification fails
|
|
55
79
|
console.error(chalk.yellow('Failed to send progress notification:'), err);
|
|
56
80
|
}
|
|
57
81
|
},
|
|
@@ -77,6 +101,161 @@ export class CodexMcpServer {
|
|
|
77
101
|
};
|
|
78
102
|
}
|
|
79
103
|
});
|
|
104
|
+
// --- MCP Resources ---
|
|
105
|
+
// List resources
|
|
106
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
107
|
+
const tasks = getAllTasks();
|
|
108
|
+
const counts = getTaskCounts();
|
|
109
|
+
const resources = [
|
|
110
|
+
{
|
|
111
|
+
uri: 'system:///status',
|
|
112
|
+
name: 'System Status',
|
|
113
|
+
description: `Server status — ${counts.total} tasks (${counts.running} running, ${counts.completed} completed, ${counts.failed} failed)`,
|
|
114
|
+
mimeType: 'application/json',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
uri: 'task:///all',
|
|
118
|
+
name: 'All Tasks',
|
|
119
|
+
description: `${counts.total} tasks total`,
|
|
120
|
+
mimeType: 'application/json',
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
// Add individual task resources
|
|
124
|
+
for (const task of tasks) {
|
|
125
|
+
resources.push({
|
|
126
|
+
uri: `task:///${task.id}`,
|
|
127
|
+
name: `Task: ${task.id}`,
|
|
128
|
+
description: `[${task.status}] ${task.prompt.slice(0, 80)}`,
|
|
129
|
+
mimeType: 'application/json',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return { resources };
|
|
133
|
+
});
|
|
134
|
+
// List resource templates
|
|
135
|
+
this.server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
|
|
136
|
+
return {
|
|
137
|
+
resourceTemplates: [
|
|
138
|
+
{
|
|
139
|
+
uriTemplate: 'task:///{task_id}',
|
|
140
|
+
name: 'Task Details',
|
|
141
|
+
description: 'Full task detail including output tail, metadata, and timing',
|
|
142
|
+
mimeType: 'application/json',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
// Read resource
|
|
148
|
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
149
|
+
const { uri } = request.params;
|
|
150
|
+
// system:///status
|
|
151
|
+
if (uri === 'system:///status') {
|
|
152
|
+
const counts = getTaskCounts();
|
|
153
|
+
const status = {
|
|
154
|
+
server: {
|
|
155
|
+
name: this.config.name,
|
|
156
|
+
version: this.config.version,
|
|
157
|
+
model: 'gpt-5.3-codex',
|
|
158
|
+
uptime_seconds: Math.floor(process.uptime()),
|
|
159
|
+
},
|
|
160
|
+
tasks: counts,
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
contents: [
|
|
164
|
+
{
|
|
165
|
+
uri,
|
|
166
|
+
mimeType: 'application/json',
|
|
167
|
+
text: JSON.stringify(status, null, 2),
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// task:///all
|
|
173
|
+
if (uri === 'task:///all') {
|
|
174
|
+
const tasks = getAllTasks();
|
|
175
|
+
const summary = {
|
|
176
|
+
count: tasks.length,
|
|
177
|
+
tasks: tasks.map(t => ({
|
|
178
|
+
id: t.id,
|
|
179
|
+
status: t.status,
|
|
180
|
+
role: t.role,
|
|
181
|
+
specialization: t.specialization,
|
|
182
|
+
model: t.model,
|
|
183
|
+
output_lines: t.outputLines,
|
|
184
|
+
started: t.startTime,
|
|
185
|
+
ended: t.endTime,
|
|
186
|
+
error: t.error,
|
|
187
|
+
cwd: t.cwd,
|
|
188
|
+
prompt: t.prompt,
|
|
189
|
+
})),
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
contents: [
|
|
193
|
+
{
|
|
194
|
+
uri,
|
|
195
|
+
mimeType: 'application/json',
|
|
196
|
+
text: JSON.stringify(summary, null, 2),
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// task:///{id}
|
|
202
|
+
const taskIdMatch = uri.match(/^task:\/\/\/(.+)$/);
|
|
203
|
+
if (taskIdMatch) {
|
|
204
|
+
const taskId = taskIdMatch[1];
|
|
205
|
+
const task = getTask(taskId);
|
|
206
|
+
if (!task) {
|
|
207
|
+
return {
|
|
208
|
+
contents: [
|
|
209
|
+
{
|
|
210
|
+
uri,
|
|
211
|
+
mimeType: 'application/json',
|
|
212
|
+
text: JSON.stringify({ error: `Task "${taskId}" not found` }),
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const filteredOutput = filterOutputForResource(task.output);
|
|
218
|
+
const outputTail = filteredOutput.slice(-50);
|
|
219
|
+
const detail = {
|
|
220
|
+
id: task.id,
|
|
221
|
+
status: task.status,
|
|
222
|
+
role: task.role,
|
|
223
|
+
specialization: task.specialization,
|
|
224
|
+
model: task.model,
|
|
225
|
+
output_lines: task.outputLines,
|
|
226
|
+
output_tail: outputTail.join('\n'),
|
|
227
|
+
started: task.startTime,
|
|
228
|
+
ended: task.endTime,
|
|
229
|
+
cwd: task.cwd,
|
|
230
|
+
output_file: task.outputFilePath,
|
|
231
|
+
prompt: task.prompt,
|
|
232
|
+
error: task.error,
|
|
233
|
+
};
|
|
234
|
+
// Include last_message from metadata if available
|
|
235
|
+
if (task.metadata?.lastMessage) {
|
|
236
|
+
detail.last_message = task.metadata.lastMessage;
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
contents: [
|
|
240
|
+
{
|
|
241
|
+
uri,
|
|
242
|
+
mimeType: 'application/json',
|
|
243
|
+
text: JSON.stringify(detail, null, 2),
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
// Unknown URI
|
|
249
|
+
return {
|
|
250
|
+
contents: [
|
|
251
|
+
{
|
|
252
|
+
uri,
|
|
253
|
+
mimeType: 'text/plain',
|
|
254
|
+
text: `Unknown resource: ${uri}`,
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
});
|
|
80
259
|
}
|
|
81
260
|
isValidToolName(name) {
|
|
82
261
|
return Object.values(TOOLS).includes(name);
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAKL,KAAK,GACN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,OAAO,EACP,WAAW,EACX,aAAa,GAEd,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,SAAS,uBAAuB,CAAC,KAAe;IAC9C,OAAO,KAAK,CAAC,MAAM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;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,uBAAuB,CAAC,CAAC,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages task output file persistence with streaming.
|
|
3
|
+
* Ported from mcp-supersubagents/src/services/output-file.ts
|
|
4
|
+
* Uses .codex-agents/ directory (distinct from .super-agents/).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get the output directory path for a given cwd.
|
|
8
|
+
* Returns: {cwd}/.codex-agents/
|
|
9
|
+
*/
|
|
10
|
+
export declare function getOutputDir(cwd: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get the output file path for a task.
|
|
13
|
+
* Returns: {cwd}/.codex-agents/{taskId}.output
|
|
14
|
+
*/
|
|
15
|
+
export declare function getOutputPath(cwd: string, taskId: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Get the last-message file path for a task.
|
|
18
|
+
* Returns: {cwd}/.codex-agents/{taskId}.last-message.txt
|
|
19
|
+
*/
|
|
20
|
+
export declare function getLastMessagePath(cwd: string, taskId: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Create an empty output file for a task.
|
|
23
|
+
* Returns the absolute path to the output file, or null on failure.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createOutputFile(cwd: string, taskId: string): Promise<string | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Append a line to the task's output file (async, uses persistent handle).
|
|
28
|
+
*/
|
|
29
|
+
export declare function appendToOutputFile(cwd: string, taskId: string, line: string): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Append completion footer to output file and close handle.
|
|
32
|
+
*/
|
|
33
|
+
export declare function finalizeOutputFile(cwd: string, taskId: string, status: string, error?: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Close all open file handles (called during shutdown).
|
|
36
|
+
*/
|
|
37
|
+
export declare function closeAllOutputHandles(): Promise<void>;
|
|
38
|
+
//# sourceMappingURL=output-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-file.d.ts","sourceRoot":"","sources":["../../src/services/output-file.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAkBD;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmB1F;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBpG;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAuBtH;AAED;;GAEG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAS3D"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages task output file persistence with streaming.
|
|
3
|
+
* Ported from mcp-supersubagents/src/services/output-file.ts
|
|
4
|
+
* Uses .codex-agents/ directory (distinct from .super-agents/).
|
|
5
|
+
*/
|
|
6
|
+
import { open, mkdir } from 'fs/promises';
|
|
7
|
+
import { join } from 'path';
|
|
8
|
+
const OUTPUT_DIR_NAME = '.codex-agents';
|
|
9
|
+
// Cache of directories known to exist — avoids stat syscall on every append
|
|
10
|
+
const knownDirs = new Set();
|
|
11
|
+
// Persistent file handles — one per task, closed on finalize
|
|
12
|
+
const openHandles = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Get the output directory path for a given cwd.
|
|
15
|
+
* Returns: {cwd}/.codex-agents/
|
|
16
|
+
*/
|
|
17
|
+
export function getOutputDir(cwd) {
|
|
18
|
+
return join(cwd, OUTPUT_DIR_NAME);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the output file path for a task.
|
|
22
|
+
* Returns: {cwd}/.codex-agents/{taskId}.output
|
|
23
|
+
*/
|
|
24
|
+
export function getOutputPath(cwd, taskId) {
|
|
25
|
+
return join(getOutputDir(cwd), `${taskId}.output`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the last-message file path for a task.
|
|
29
|
+
* Returns: {cwd}/.codex-agents/{taskId}.last-message.txt
|
|
30
|
+
*/
|
|
31
|
+
export function getLastMessagePath(cwd, taskId) {
|
|
32
|
+
return join(getOutputDir(cwd), `${taskId}.last-message.txt`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Ensure output directory exists (async, cached).
|
|
36
|
+
*/
|
|
37
|
+
async function ensureOutputDir(cwd) {
|
|
38
|
+
const dir = getOutputDir(cwd);
|
|
39
|
+
if (knownDirs.has(dir))
|
|
40
|
+
return true;
|
|
41
|
+
try {
|
|
42
|
+
await mkdir(dir, { recursive: true });
|
|
43
|
+
knownDirs.add(dir);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error(`[output-file] Failed to create output directory: ${error}`);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create an empty output file for a task.
|
|
53
|
+
* Returns the absolute path to the output file, or null on failure.
|
|
54
|
+
*/
|
|
55
|
+
export async function createOutputFile(cwd, taskId) {
|
|
56
|
+
if (!(await ensureOutputDir(cwd))) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const outputPath = getOutputPath(cwd, taskId);
|
|
60
|
+
try {
|
|
61
|
+
const header = `# Task: ${taskId}\n# Started: ${new Date().toISOString()}\n# Working directory: ${cwd}\n${'─'.repeat(60)}\n\n`;
|
|
62
|
+
// Write header and close immediately — appendToOutputFile will open
|
|
63
|
+
// its own persistent handle on first call.
|
|
64
|
+
const handle = await open(outputPath, 'w');
|
|
65
|
+
await handle.write(header);
|
|
66
|
+
await handle.close();
|
|
67
|
+
return outputPath;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(`[output-file] Failed to create output file: ${error}`);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Append a line to the task's output file (async, uses persistent handle).
|
|
76
|
+
*/
|
|
77
|
+
export async function appendToOutputFile(cwd, taskId, line) {
|
|
78
|
+
const key = `${cwd}:${taskId}`;
|
|
79
|
+
try {
|
|
80
|
+
let handle = openHandles.get(key);
|
|
81
|
+
if (!handle) {
|
|
82
|
+
await ensureOutputDir(cwd);
|
|
83
|
+
handle = await open(getOutputPath(cwd, taskId), 'a');
|
|
84
|
+
openHandles.set(key, handle);
|
|
85
|
+
}
|
|
86
|
+
await handle.write(line + '\n');
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Silent failure — don't break task execution for file I/O issues
|
|
91
|
+
openHandles.delete(key);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Append completion footer to output file and close handle.
|
|
97
|
+
*/
|
|
98
|
+
export async function finalizeOutputFile(cwd, taskId, status, error) {
|
|
99
|
+
const key = `${cwd}:${taskId}`;
|
|
100
|
+
try {
|
|
101
|
+
const footer = [
|
|
102
|
+
'',
|
|
103
|
+
'─'.repeat(60),
|
|
104
|
+
`# Completed: ${new Date().toISOString()}`,
|
|
105
|
+
`# Status: ${status}`,
|
|
106
|
+
error ? `# Error: ${error}` : null,
|
|
107
|
+
].filter(Boolean).join('\n') + '\n';
|
|
108
|
+
let handle = openHandles.get(key);
|
|
109
|
+
if (!handle) {
|
|
110
|
+
handle = await open(getOutputPath(cwd, taskId), 'a');
|
|
111
|
+
}
|
|
112
|
+
await handle.write(footer);
|
|
113
|
+
await handle.close();
|
|
114
|
+
openHandles.delete(key);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
openHandles.delete(key);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Close all open file handles (called during shutdown).
|
|
124
|
+
*/
|
|
125
|
+
export async function closeAllOutputHandles() {
|
|
126
|
+
for (const [key, handle] of openHandles) {
|
|
127
|
+
try {
|
|
128
|
+
await handle.close();
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Ignore close errors during shutdown
|
|
132
|
+
}
|
|
133
|
+
openHandles.delete(key);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=output-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-file.js","sourceRoot":"","sources":["../../src/services/output-file.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,MAAM,eAAe,GAAG,eAAe,CAAC;AAExC,4EAA4E;AAC5E,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;AAEpC,6DAA6D;AAC7D,MAAM,WAAW,GAAG,IAAI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AAG,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory task state manager for async codex execution.
|
|
3
|
+
* Tracks background codex processes and their output.
|
|
4
|
+
*/
|
|
5
|
+
import type { ChildProcess } from 'child_process';
|
|
6
|
+
export type TaskStatus = 'pending' | 'running' | 'completed' | 'failed';
|
|
7
|
+
export interface CodexTask {
|
|
8
|
+
id: string;
|
|
9
|
+
status: TaskStatus;
|
|
10
|
+
prompt: string;
|
|
11
|
+
role?: string;
|
|
12
|
+
specialization?: string;
|
|
13
|
+
model: string;
|
|
14
|
+
cwd: string;
|
|
15
|
+
startTime: string;
|
|
16
|
+
endTime?: string;
|
|
17
|
+
outputFilePath?: string;
|
|
18
|
+
outputLines: number;
|
|
19
|
+
output: string[];
|
|
20
|
+
error?: string;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a new task and return it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createTask(opts: {
|
|
27
|
+
prompt: string;
|
|
28
|
+
role?: string;
|
|
29
|
+
specialization?: string;
|
|
30
|
+
model: string;
|
|
31
|
+
cwd: string;
|
|
32
|
+
}): Promise<CodexTask>;
|
|
33
|
+
/**
|
|
34
|
+
* Get a task by ID.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getTask(id: string): CodexTask | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get all tasks.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getAllTasks(): CodexTask[];
|
|
41
|
+
/**
|
|
42
|
+
* Update a task with partial data.
|
|
43
|
+
*/
|
|
44
|
+
export declare function updateTask(id: string, partial: Partial<CodexTask>): CodexTask | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Append an output line to a task and stream to output file.
|
|
47
|
+
*/
|
|
48
|
+
export declare function appendOutput(id: string, line: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Mark task as completed with optional metadata.
|
|
51
|
+
*/
|
|
52
|
+
export declare function completeTask(id: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Mark task as failed with error.
|
|
55
|
+
*/
|
|
56
|
+
export declare function failTask(id: string, error: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Store a background process reference for a task.
|
|
59
|
+
*/
|
|
60
|
+
export declare function setProcess(id: string, proc: ChildProcess): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get the background process for a task.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getProcess(id: string): ChildProcess | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Get task counts by status.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getTaskCounts(): Record<TaskStatus | 'total', number>;
|
|
69
|
+
//# sourceMappingURL=task-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-manager.d.ts","sourceRoot":"","sources":["../../src/services/task-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAUlD,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM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