input-kanban 0.0.8 → 0.0.10
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/ENVIRONMENT.md +7 -4
- package/LICENSE +21 -0
- package/PROJECT_GUIDE.md +124 -12
- package/README.en.md +27 -17
- package/README.md +27 -17
- package/RELEASE_NOTES.md +38 -1
- package/bin/input-kanban.js +277 -58
- package/package.json +5 -3
- package/public/index.html +101 -20
- package/src/orchestrator.js +523 -201
- package/src/scheduler.js +40 -0
- package/src/server.js +13 -6
- package/src/utils.js +7 -1
package/src/scheduler.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { autoAdvanceActiveRuns } from './orchestrator.js';
|
|
2
|
+
|
|
3
|
+
export function startAutoScheduler({ appClient = null, pollMs = Number(process.env.KANBAN_AUTO_POLL_MS || 3000), maxRetries = Number(process.env.KANBAN_AUTO_MAX_RETRIES || 1), startCreated = false, log = false } = {}) {
|
|
4
|
+
const intervalMs = Math.max(500, Number(pollMs) || 3000);
|
|
5
|
+
let stopped = false;
|
|
6
|
+
let running = false;
|
|
7
|
+
let timer = null;
|
|
8
|
+
|
|
9
|
+
const tick = async () => {
|
|
10
|
+
if (stopped || running) return;
|
|
11
|
+
running = true;
|
|
12
|
+
try {
|
|
13
|
+
const results = await autoAdvanceActiveRuns({ appClient, startCreated, maxRetries, retryReason: 'auto retry from server scheduler' });
|
|
14
|
+
if (log) {
|
|
15
|
+
for (const result of results) {
|
|
16
|
+
if (result.ok === false) console.warn(`[scheduler] ${result.runId}: ${result.error}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (log) console.warn(`[scheduler] ${error.message || String(error)}`);
|
|
21
|
+
} finally {
|
|
22
|
+
running = false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
timer = setInterval(() => { tick(); }, intervalMs);
|
|
27
|
+
timer.unref?.();
|
|
28
|
+
tick();
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
get running() { return running; },
|
|
32
|
+
get stopped() { return stopped; },
|
|
33
|
+
async tick() { await tick(); },
|
|
34
|
+
stop() {
|
|
35
|
+
stopped = true;
|
|
36
|
+
if (timer) clearInterval(timer);
|
|
37
|
+
timer = null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/server.js
CHANGED
|
@@ -3,8 +3,9 @@ import fsp from 'node:fs/promises';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { CodexAppServerClient } from './appServerClient.js';
|
|
6
|
-
import { APP_ROOT, DEFAULT_REPO, RUNNER, RUNS_DIR } from './utils.js';
|
|
7
|
-
import { createRun, listRuns, startPlanner, dispatchRun, startJudge, refreshRun, readRunFile, readRunTaskText, markTaskCompleted, stopRun, archiveRun, renameRun } from './orchestrator.js';
|
|
6
|
+
import { APP_ROOT, DEFAULT_WORKSPACE, DEFAULT_REPO, PACKAGE_VERSION, RUNNER, RUNS_DIR } from './utils.js';
|
|
7
|
+
import { createRun, listRuns, startPlanner, dispatchRun, startJudge, refreshRun, readRunFile, readRunTaskText, markTaskCompleted, stopRun, archiveRun, renameRun, retryRun } from './orchestrator.js';
|
|
8
|
+
import { startAutoScheduler } from './scheduler.js';
|
|
8
9
|
|
|
9
10
|
const PUBLIC_DIR = path.join(APP_ROOT, 'public');
|
|
10
11
|
|
|
@@ -42,10 +43,10 @@ async function handleApi(req, res, url, appClient) {
|
|
|
42
43
|
const parts = url.pathname.split('/').filter(Boolean);
|
|
43
44
|
try {
|
|
44
45
|
if (req.method === 'GET' && url.pathname === '/api/health') {
|
|
45
|
-
return send(res, 200, { ok: true, appRoot: APP_ROOT, runsDir: RUNS_DIR, defaultRepo: DEFAULT_REPO, runner: RUNNER });
|
|
46
|
+
return send(res, 200, { ok: true, version: PACKAGE_VERSION, appRoot: APP_ROOT, runsDir: RUNS_DIR, defaultWorkspace: DEFAULT_WORKSPACE, defaultRepo: DEFAULT_REPO, runner: RUNNER });
|
|
46
47
|
}
|
|
47
48
|
if (parts[1] === 'runs' && parts.length === 2) {
|
|
48
|
-
if (req.method === 'GET') return send(res, 200, { runs: await listRuns({ includeArchived: url.searchParams.get('includeArchived') === '1' }) });
|
|
49
|
+
if (req.method === 'GET') return send(res, 200, { runs: await listRuns({ includeArchived: url.searchParams.get('includeArchived') === '1', workspace: url.searchParams.get('workspace') || '' }) });
|
|
49
50
|
if (req.method === 'POST') {
|
|
50
51
|
const body = await readBody(req);
|
|
51
52
|
return send(res, 201, await createRun(body));
|
|
@@ -58,6 +59,10 @@ async function handleApi(req, res, url, appClient) {
|
|
|
58
59
|
if (parts.length === 4 && parts[3] === 'plan' && req.method === 'POST') return send(res, 202, await startPlanner(runId));
|
|
59
60
|
if (parts.length === 4 && parts[3] === 'dispatch' && req.method === 'POST') return send(res, 202, await dispatchRun(runId));
|
|
60
61
|
if (parts.length === 4 && parts[3] === 'judge' && req.method === 'POST') return send(res, 202, await startJudge(runId));
|
|
62
|
+
if (parts.length === 4 && parts[3] === 'retry' && req.method === 'POST') {
|
|
63
|
+
const body = await readBody(req);
|
|
64
|
+
return send(res, 200, await retryRun(runId, body));
|
|
65
|
+
}
|
|
61
66
|
if (parts.length === 4 && parts[3] === 'stop' && req.method === 'POST') {
|
|
62
67
|
const body = await readBody(req);
|
|
63
68
|
return send(res, 200, await stopRun(runId, body));
|
|
@@ -94,17 +99,19 @@ export function createHttpServer({ appClient = new CodexAppServerClient() } = {}
|
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
export async function startServer({ host = process.env.HOST || '127.0.0.1', port = Number(process.env.PORT || 8787), log = true } = {}) {
|
|
102
|
+
export async function startServer({ host = process.env.HOST || '127.0.0.1', port = Number(process.env.PORT || 8787), log = true, scheduler = true } = {}) {
|
|
98
103
|
const appClient = new CodexAppServerClient();
|
|
99
104
|
const server = createHttpServer({ appClient });
|
|
105
|
+
const autoScheduler = scheduler ? startAutoScheduler({ appClient, log }) : null;
|
|
100
106
|
await new Promise(resolve => server.listen(port, host, resolve));
|
|
101
107
|
const url = `http://${host}:${port}`;
|
|
102
108
|
if (log) console.log(`input-kanban listening on ${url}`);
|
|
103
109
|
const stop = async () => {
|
|
110
|
+
autoScheduler?.stop();
|
|
104
111
|
appClient.stop();
|
|
105
112
|
await new Promise(resolve => server.close(resolve));
|
|
106
113
|
};
|
|
107
|
-
return { server, appClient, host, port, url, defaultRepo: DEFAULT_REPO, runsDir: RUNS_DIR, runner: RUNNER, stop };
|
|
114
|
+
return { server, appClient, autoScheduler, host, port, url, version: PACKAGE_VERSION, defaultWorkspace: DEFAULT_WORKSPACE, defaultRepo: DEFAULT_REPO, runsDir: RUNS_DIR, runner: RUNNER, scheduler: !!autoScheduler, stop };
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
package/src/utils.js
CHANGED
|
@@ -2,9 +2,15 @@ import fs from 'node:fs';
|
|
|
2
2
|
import fsp from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const { version: PACKAGE_VERSION } = require('../package.json');
|
|
5
9
|
|
|
6
10
|
export const APP_ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
|
|
7
|
-
export
|
|
11
|
+
export { PACKAGE_VERSION };
|
|
12
|
+
export const DEFAULT_WORKSPACE = path.resolve(process.env.KANBAN_DEFAULT_WORKSPACE || process.env.KANBAN_DEFAULT_REPO || process.cwd());
|
|
13
|
+
export const DEFAULT_REPO = DEFAULT_WORKSPACE;
|
|
8
14
|
export const RUNS_DIR = path.resolve(process.env.KANBAN_RUNS_DIR || path.join(process.env.HOME || APP_ROOT, '.input-kanban', 'runs'));
|
|
9
15
|
export const CODEX_BIN = process.env.KANBAN_CODEX_BIN || 'codex';
|
|
10
16
|
export const VALID_RUNNERS = ['headless', 'tmux'];
|