minimal-agent 0.18.20 → 0.18.22
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/README.md +16 -3
- package/package.json +1 -1
- package/plugins/cron-runner/README.md +23 -0
- package/plugins/cron-runner/commands/cron.md +7 -1
- package/plugins/cron-runner/plugin.js +9 -2
- package/plugins/cron-runner/plugin.ts +10 -2
- package/plugins/cron-runner/src/commands.js +112 -25
- package/plugins/cron-runner/src/commands.ts +154 -33
- package/plugins/cron-runner/src/contract.js +70 -0
- package/plugins/cron-runner/src/contract.ts +70 -0
- package/plugins/cron-runner/src/requests.js +22 -13
- package/plugins/cron-runner/src/requests.ts +34 -14
- package/plugins/cron-runner/src/runs.js +63 -10
- package/plugins/cron-runner/src/runs.ts +107 -15
- package/plugins/cron-runner/src/scheduler.js +188 -76
- package/plugins/cron-runner/src/scheduler.ts +277 -94
- package/plugins/cron-runner/src/schema.js +52 -17
- package/plugins/cron-runner/src/schema.ts +73 -22
- package/plugins/cron-runner/src/service.js +29 -8
- package/plugins/cron-runner/src/service.ts +71 -18
- package/plugins/cron-runner/src/store.js +92 -30
- package/plugins/cron-runner/src/store.ts +156 -53
- package/plugins/cron-runner/src/transaction.js +24 -0
- package/plugins/cron-runner/src/transaction.ts +36 -0
- package/plugins/cron-runner/src/types.ts +30 -4
- package/plugins/cron-runner/test/lifecycle.test.ts +419 -0
- package/plugins/cron-runner/test/plugin-integration.test.ts +3 -2
- package/plugins/cron-runner/test/reliability.test.ts +2 -2
- package/plugins/cron-runner/test/store-and-scheduler.test.ts +9 -7
- package/plugins/workflow-runner/plugin.js +1 -0
- package/plugins/workflow-runner/plugin.ts +1 -0
- package/plugins/workflow-runner/src/index.js +1 -0
- package/plugins/workflow-runner/src/index.ts +2 -0
- package/plugins/workflow-runner/src/runner.js +6 -1
- package/plugins/workflow-runner/src/runner.ts +5 -1
- package/plugins/workflow-runner/src/types.ts +1 -0
- package/plugins/workflow-runner/test/api.test.ts +1 -0
- package/plugins/workflow-runner/test/apiCapabilities.test.ts +4 -0
- package/plugins/workflow-runner/test/apiConcurrencyGate.test.ts +1 -0
- package/plugins/workflow-runner/test/childWorkflow.test.ts +19 -0
- package/plugins/workflow-runner/test/embeddedExecution.test.ts +23 -3
- package/src/advisor/README.md +17 -6
- package/src/advisor/advisorNudge.js +23 -3
- package/src/advisor/advisorNudge.ts +20 -3
- package/src/advisor/deliveryReview.js +9 -2
- package/src/advisor/deliveryReview.ts +10 -2
- package/src/cli/args.js +1 -0
- package/src/cli/args.ts +1 -0
- package/src/cli/headlessTurn.js +143 -0
- package/src/cli/headlessTurn.ts +187 -0
- package/src/cli/lifecycle.js +52 -0
- package/src/cli/lifecycle.ts +59 -0
- package/src/cli/print.js +91 -240
- package/src/cli/print.ts +99 -301
- package/src/cli/quickModelSetup.js +3 -0
- package/src/cli/quickModelSetup.tsx +3 -0
- package/src/cli/streamJson.js +244 -334
- package/src/cli/streamJson.ts +248 -416
- package/src/cli/wizards/contextAdvisorWizard.js +0 -7
- package/src/cli/wizards/contextAdvisorWizard.tsx +0 -11
- package/src/cli/wizards/providerPresets.js +25 -14
- package/src/cli/wizards/providerPresets.ts +25 -14
- package/src/cli/wizards/providerWizard.js +29 -11
- package/src/cli/wizards/providerWizard.tsx +29 -11
- package/src/config/configDefaults.js +2 -2
- package/src/config/configDefaults.ts +2 -2
- package/src/config/configDiagnostics.js +7 -3
- package/src/config/configDiagnostics.ts +6 -3
- package/src/config/configFile.ts +1 -1
- package/src/context/compact.js +40 -10
- package/src/context/compact.ts +51 -12
- package/src/context/compactResources.js +39 -0
- package/src/context/compactResources.ts +35 -0
- package/src/context/manualCompact.js +20 -0
- package/src/context/manualCompact.ts +28 -0
- package/src/llm/client.js +4 -0
- package/src/llm/client.ts +4 -0
- package/src/llm/messageProvenance.js +1 -1
- package/src/llm/messageProvenance.ts +1 -1
- package/src/loop/README.md +4 -2
- package/src/loop/deliveryIntent.js +3 -2
- package/src/loop/deliveryIntent.ts +4 -2
- package/src/loop/messages.js +1 -0
- package/src/loop/messages.ts +1 -0
- package/src/loop/options.ts +2 -0
- package/src/loop.js +10 -2
- package/src/loop.ts +9 -2
- package/src/main.js +40 -45
- package/src/main.tsx +33 -52
- package/src/plugin-sdk.js +1 -1
- package/src/plugin-sdk.ts +1 -1
- package/src/plugins/artifactDelivery.js +76 -0
- package/src/plugins/artifactDelivery.ts +76 -0
- package/src/plugins/pluginApi.ts +4 -0
- package/src/plugins/pluginRunner.js +2 -0
- package/src/plugins/pluginRunner.ts +3 -0
- package/src/prompts/delegation.js +2 -2
- package/src/prompts/delegation.ts +2 -2
- package/src/prompts/policyRegistry.js +7 -5
- package/src/prompts/policyRegistry.ts +7 -5
- package/src/prompts/promptAssembly.js +2 -2
- package/src/prompts/promptAssembly.ts +2 -2
- package/src/runtime/requestIntent.js +86 -0
- package/src/runtime/requestIntent.ts +66 -0
- package/src/runtime/systemEvents.js +10 -1
- package/src/runtime/systemEvents.ts +9 -1
- package/src/session/commandTranscript.js +76 -0
- package/src/session/commandTranscript.ts +77 -0
- package/src/session/executionOutcome.js +25 -0
- package/src/session/executionOutcome.ts +34 -0
- package/src/session/runAgentTurn.js +8 -1
- package/src/session/runAgentTurn.ts +10 -1
- package/src/session/runTurn.js +40 -15
- package/src/session/runTurn.ts +38 -12
- package/src/session/sessionState.js +7 -2
- package/src/session/sessionState.ts +7 -2
- package/src/team/onlineToolContract.js +1 -0
- package/src/team/onlineToolContract.ts +1 -0
- package/src/tools/advisor/advisor.js +73 -30
- package/src/tools/advisor/advisor.ts +73 -33
- package/src/tools/advisor/advisorCoordination.js +44 -0
- package/src/tools/advisor/advisorCoordination.ts +45 -0
- package/src/tools/advisor/advisorDescription.js +1 -1
- package/src/tools/advisor/advisorDescription.ts +1 -1
- package/src/tools/agent/README.md +2 -0
- package/src/tools/agent/agent.js +7 -3
- package/src/tools/agent/agent.ts +7 -3
- package/src/tools/agent/agentHandoff.js +2 -1
- package/src/tools/agent/agentHandoff.ts +2 -1
- package/src/tools/agent/agentTaskService.js +26 -5
- package/src/tools/agent/agentTaskService.ts +25 -5
- package/src/tools/agent/agentTypes.js +2 -2
- package/src/tools/agent/agentTypes.ts +2 -2
- package/src/tools/agent/baselineAttach.js +14 -7
- package/src/tools/agent/baselineAttach.ts +14 -7
- package/src/tools/applypatch/applyPatch.js +39 -13
- package/src/tools/applypatch/applyPatch.ts +35 -15
- package/src/tools/bash/bash.js +3 -0
- package/src/tools/bash/bash.ts +3 -0
- package/src/tools/capabilities.js +1 -0
- package/src/tools/capabilities.ts +1 -0
- package/src/tools/download/download.js +147 -11
- package/src/tools/download/download.ts +193 -17
- package/src/tools/edit/edit.js +4 -4
- package/src/tools/edit/edit.ts +4 -4
- package/src/tools/edit/multi-edit.js +2 -2
- package/src/tools/edit/multi-edit.ts +2 -2
- package/src/tools/index.js +2 -0
- package/src/tools/index.ts +2 -0
- package/src/tools/powershell/powershell.js +2 -0
- package/src/tools/powershell/powershell.ts +2 -0
- package/src/tools/schedule/schedule.js +184 -0
- package/src/tools/schedule/schedule.ts +214 -0
- package/src/tools/shared/fileUtils.js +16 -6
- package/src/tools/shared/fileUtils.ts +15 -6
- package/src/tools/tasks/backgroundTaskService.js +108 -12
- package/src/tools/tasks/backgroundTaskService.ts +106 -14
- package/src/tools/tasks/taskOutput.js +15 -5
- package/src/tools/tasks/taskOutput.ts +13 -5
- package/src/tools/tasks/taskStop.js +2 -2
- package/src/tools/tasks/taskStop.ts +2 -2
- package/src/tools/toolPromptGuides.js +4 -3
- package/src/tools/toolPromptGuides.ts +4 -3
- package/src/tools/webfetch/webfetch.js +1 -1
- package/src/tools/webfetch/webfetch.ts +1 -1
- package/src/types.ts +6 -0
- package/src/ui/App.js +3 -1
- package/src/ui/App.tsx +2 -0
- package/src/ui/InputBox.js +2 -2
- package/src/ui/InputBox.tsx +2 -2
- package/src/ui/LiveArea.js +6 -1
- package/src/ui/LiveArea.tsx +6 -1
- package/src/ui/MessageList.js +2 -0
- package/src/ui/MessageList.tsx +2 -0
- package/src/ui/README.md +8 -2
- package/src/ui/activityPresentation.js +23 -3
- package/src/ui/activityPresentation.ts +22 -3
- package/src/ui/backgroundWake.js +20 -4
- package/src/ui/backgroundWake.ts +19 -4
- package/src/ui/commandTranscript.js +2 -69
- package/src/ui/commandTranscript.ts +2 -71
- package/src/ui/hooks/useBackgroundAgents.js +33 -0
- package/src/ui/hooks/useBackgroundAgents.ts +36 -0
- package/src/ui/hooks/useChat.js +46 -25
- package/src/ui/hooks/useChat.ts +36 -23
- package/src/web/protocol.ts +5 -2
- package/src/cli/wizards/advisorWizard.js +0 -152
- package/src/cli/wizards/advisorWizard.tsx +0 -203
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { appendFile, mkdir, readFile, readdir, stat } from 'node:fs/promises';
|
|
1
|
+
import { appendFile, mkdir, readFile, readdir, stat, copyFile, writeFile, rename, } from 'node:fs/promises';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { dirname, join } from 'node:path';
|
|
3
4
|
import { withStoreLock } from './lock.js';
|
|
4
5
|
/** A damaged line must not hide all other runs. Preserve the file and report its location. */
|
|
5
6
|
const cache = new Map();
|
|
7
|
+
const folded = new WeakMap();
|
|
6
8
|
async function records(file) {
|
|
7
9
|
let raw;
|
|
8
10
|
let key;
|
|
@@ -44,12 +46,53 @@ async function append(file, record) {
|
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
export async function appendRun(runsDir, record) {
|
|
47
|
-
|
|
49
|
+
const file = join(runsDir, `${record.taskId}.jsonl`);
|
|
50
|
+
await append(file, record);
|
|
51
|
+
if (record.status !== 'queued' &&
|
|
52
|
+
record.status !== 'running' &&
|
|
53
|
+
(await stat(file)).size > 4 * 1024 * 1024)
|
|
54
|
+
await compactRunLog(runsDir, record.taskId);
|
|
48
55
|
}
|
|
49
|
-
|
|
56
|
+
/** Preserve the full raw journal before compacting old terminal payloads. IDs,
|
|
57
|
+
* counters and plan identities stay hot for durable deduplication/recovery. */
|
|
58
|
+
export async function compactRunLog(runsDir, taskId) {
|
|
59
|
+
await withStoreLock(runsDir, async () => {
|
|
60
|
+
const all = await recentRuns(runsDir, taskId, Infinity);
|
|
61
|
+
const old = all
|
|
62
|
+
.filter((r) => !['queued', 'running'].includes(r.status))
|
|
63
|
+
.slice(100);
|
|
64
|
+
if (!old.some((r) => r.result !== undefined || r.snapshot !== undefined))
|
|
65
|
+
return;
|
|
66
|
+
const file = join(runsDir, `${taskId}.jsonl`);
|
|
67
|
+
const archive = join(runsDir, 'archive', `${taskId}-${randomUUID()}.jsonl`);
|
|
68
|
+
await mkdir(dirname(archive), { recursive: true });
|
|
69
|
+
await copyFile(file, archive);
|
|
70
|
+
const ids = new Set(old.map((r) => r.id));
|
|
71
|
+
const rows = all.map((r) => {
|
|
72
|
+
if (!ids.has(r.id))
|
|
73
|
+
return r;
|
|
74
|
+
const { result, snapshot, ...rest } = r;
|
|
75
|
+
return {
|
|
76
|
+
...rest,
|
|
77
|
+
planId: r.planId ?? snapshot?.planId,
|
|
78
|
+
archiveFile: r.archiveFile ?? archive,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const tmp = `${file}.${randomUUID()}.tmp`;
|
|
82
|
+
await writeFile(tmp, rows.map((r) => JSON.stringify(r)).join('\n') + '\n');
|
|
83
|
+
await rename(tmp, file);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export async function recentRuns(runsDir, taskId, limit = 5, activeOnly = false) {
|
|
87
|
+
const rows = await records(join(runsDir, `${taskId}.jsonl`));
|
|
88
|
+
const prior = folded.get(rows);
|
|
89
|
+
if (prior)
|
|
90
|
+
return (activeOnly ? prior.active : prior.all)
|
|
91
|
+
.slice(0, limit)
|
|
92
|
+
.map((r) => ({ ...r }));
|
|
50
93
|
const byId = new Map();
|
|
51
94
|
const reads = new Map();
|
|
52
|
-
for (const record of
|
|
95
|
+
for (const record of rows) {
|
|
53
96
|
if (!record || typeof record.id !== 'string')
|
|
54
97
|
continue;
|
|
55
98
|
if (record.event === 'read') {
|
|
@@ -69,10 +112,14 @@ export async function recentRuns(runsDir, taskId, limit = 5) {
|
|
|
69
112
|
}
|
|
70
113
|
byId.set(record.id, { ...byId.get(record.id), ...record });
|
|
71
114
|
}
|
|
72
|
-
|
|
73
|
-
.map((record) =>
|
|
74
|
-
|
|
75
|
-
|
|
115
|
+
const all = [...byId.values()]
|
|
116
|
+
.map((record) => reads.has(record.id)
|
|
117
|
+
? { ...record, readAt: reads.get(record.id) }
|
|
118
|
+
: record)
|
|
119
|
+
.sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt));
|
|
120
|
+
const active = all.filter((r) => r.status === 'queued' || r.status === 'running');
|
|
121
|
+
folded.set(rows, { all, active });
|
|
122
|
+
return (activeOnly ? active : all).slice(0, limit).map((r) => ({ ...r }));
|
|
76
123
|
}
|
|
77
124
|
export async function markRunsRead(runsDir, taskId) {
|
|
78
125
|
const ids = taskId ? [taskId] : await listRunTaskIds(runsDir);
|
|
@@ -90,7 +137,9 @@ export async function markRunsRead(runsDir, taskId) {
|
|
|
90
137
|
}
|
|
91
138
|
export async function listRunTaskIds(runsDir) {
|
|
92
139
|
try {
|
|
93
|
-
return (await readdir(runsDir))
|
|
140
|
+
return (await readdir(runsDir))
|
|
141
|
+
.filter((n) => n.endsWith('.jsonl'))
|
|
142
|
+
.map((n) => n.slice(0, -6));
|
|
94
143
|
}
|
|
95
144
|
catch (error) {
|
|
96
145
|
if (error.code === 'ENOENT')
|
|
@@ -127,6 +176,10 @@ export async function listMissed(file, limit = 20) {
|
|
|
127
176
|
export async function markMissedRead(file, taskId) {
|
|
128
177
|
for (const record of await listMissed(file, Infinity))
|
|
129
178
|
if (!record.readAt && (!taskId || record.taskId === taskId)) {
|
|
130
|
-
await append(file, {
|
|
179
|
+
await append(file, {
|
|
180
|
+
event: 'read',
|
|
181
|
+
id: record.id,
|
|
182
|
+
readAt: new Date().toISOString(),
|
|
183
|
+
});
|
|
131
184
|
}
|
|
132
185
|
}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
appendFile,
|
|
3
|
+
mkdir,
|
|
4
|
+
readFile,
|
|
5
|
+
readdir,
|
|
6
|
+
stat,
|
|
7
|
+
copyFile,
|
|
8
|
+
writeFile,
|
|
9
|
+
rename,
|
|
10
|
+
} from 'node:fs/promises';
|
|
11
|
+
import { randomUUID } from 'node:crypto';
|
|
2
12
|
import { dirname, join } from 'node:path';
|
|
3
13
|
import type { CronMissedRecord, CronRunRecord } from './types.js';
|
|
4
14
|
import { withStoreLock } from './lock.js';
|
|
5
15
|
|
|
6
16
|
/** A damaged line must not hide all other runs. Preserve the file and report its location. */
|
|
7
17
|
const cache = new Map<string, { key: string; rows: any[] }>();
|
|
18
|
+
const folded = new WeakMap<
|
|
19
|
+
object,
|
|
20
|
+
{ all: CronRunRecord[]; active: CronRunRecord[] }
|
|
21
|
+
>();
|
|
8
22
|
async function records(file: string): Promise<any[]> {
|
|
9
23
|
let raw: string;
|
|
10
24
|
let key: string;
|
|
@@ -25,7 +39,9 @@ async function records(file: string): Promise<any[]> {
|
|
|
25
39
|
try {
|
|
26
40
|
return [JSON.parse(line)];
|
|
27
41
|
} catch {
|
|
28
|
-
console.error(
|
|
42
|
+
console.error(
|
|
43
|
+
`[cron-runner] 损坏的日志行,保留原件:${file}:${index + 1}`,
|
|
44
|
+
);
|
|
29
45
|
return [];
|
|
30
46
|
}
|
|
31
47
|
});
|
|
@@ -42,17 +58,67 @@ async function append(file: string, record: unknown): Promise<void> {
|
|
|
42
58
|
});
|
|
43
59
|
}
|
|
44
60
|
|
|
45
|
-
export async function appendRun(
|
|
46
|
-
|
|
61
|
+
export async function appendRun(
|
|
62
|
+
runsDir: string,
|
|
63
|
+
record: CronRunRecord,
|
|
64
|
+
): Promise<void> {
|
|
65
|
+
const file = join(runsDir, `${record.taskId}.jsonl`);
|
|
66
|
+
await append(file, record);
|
|
67
|
+
if (
|
|
68
|
+
record.status !== 'queued' &&
|
|
69
|
+
record.status !== 'running' &&
|
|
70
|
+
(await stat(file)).size > 4 * 1024 * 1024
|
|
71
|
+
)
|
|
72
|
+
await compactRunLog(runsDir, record.taskId);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Preserve the full raw journal before compacting old terminal payloads. IDs,
|
|
76
|
+
* counters and plan identities stay hot for durable deduplication/recovery. */
|
|
77
|
+
export async function compactRunLog(
|
|
78
|
+
runsDir: string,
|
|
79
|
+
taskId: string,
|
|
80
|
+
): Promise<void> {
|
|
81
|
+
await withStoreLock(runsDir, async () => {
|
|
82
|
+
const all = await recentRuns(runsDir, taskId, Infinity);
|
|
83
|
+
const old = all
|
|
84
|
+
.filter((r) => !['queued', 'running'].includes(r.status))
|
|
85
|
+
.slice(100);
|
|
86
|
+
if (!old.some((r) => r.result !== undefined || r.snapshot !== undefined))
|
|
87
|
+
return;
|
|
88
|
+
const file = join(runsDir, `${taskId}.jsonl`);
|
|
89
|
+
const archive = join(runsDir, 'archive', `${taskId}-${randomUUID()}.jsonl`);
|
|
90
|
+
await mkdir(dirname(archive), { recursive: true });
|
|
91
|
+
await copyFile(file, archive);
|
|
92
|
+
const ids = new Set(old.map((r) => r.id));
|
|
93
|
+
const rows = all.map((r) => {
|
|
94
|
+
if (!ids.has(r.id)) return r;
|
|
95
|
+
const { result, snapshot, ...rest } = r;
|
|
96
|
+
return {
|
|
97
|
+
...rest,
|
|
98
|
+
planId: r.planId ?? snapshot?.planId,
|
|
99
|
+
archiveFile: r.archiveFile ?? archive,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
const tmp = `${file}.${randomUUID()}.tmp`;
|
|
103
|
+
await writeFile(tmp, rows.map((r) => JSON.stringify(r)).join('\n') + '\n');
|
|
104
|
+
await rename(tmp, file);
|
|
105
|
+
});
|
|
47
106
|
}
|
|
48
107
|
export async function recentRuns(
|
|
49
108
|
runsDir: string,
|
|
50
109
|
taskId: string,
|
|
51
110
|
limit = 5,
|
|
111
|
+
activeOnly = false,
|
|
52
112
|
): Promise<CronRunRecord[]> {
|
|
113
|
+
const rows = await records(join(runsDir, `${taskId}.jsonl`));
|
|
114
|
+
const prior = folded.get(rows);
|
|
115
|
+
if (prior)
|
|
116
|
+
return (activeOnly ? prior.active : prior.all)
|
|
117
|
+
.slice(0, limit)
|
|
118
|
+
.map((r) => ({ ...r }));
|
|
53
119
|
const byId = new Map<string, CronRunRecord>();
|
|
54
120
|
const reads = new Map<string, string>();
|
|
55
|
-
for (const record of
|
|
121
|
+
for (const record of rows) {
|
|
56
122
|
if (!record || typeof record.id !== 'string') continue;
|
|
57
123
|
if (record.event === 'read') {
|
|
58
124
|
reads.set(record.id, record.readAt);
|
|
@@ -71,12 +137,23 @@ export async function recentRuns(
|
|
|
71
137
|
}
|
|
72
138
|
byId.set(record.id, { ...byId.get(record.id), ...record });
|
|
73
139
|
}
|
|
74
|
-
|
|
75
|
-
.map((record) =>
|
|
76
|
-
|
|
77
|
-
|
|
140
|
+
const all = [...byId.values()]
|
|
141
|
+
.map((record) =>
|
|
142
|
+
reads.has(record.id)
|
|
143
|
+
? { ...record, readAt: reads.get(record.id) }
|
|
144
|
+
: record,
|
|
145
|
+
)
|
|
146
|
+
.sort((a, b) => Date.parse(b.startedAt) - Date.parse(a.startedAt));
|
|
147
|
+
const active = all.filter(
|
|
148
|
+
(r) => r.status === 'queued' || r.status === 'running',
|
|
149
|
+
);
|
|
150
|
+
folded.set(rows, { all, active });
|
|
151
|
+
return (activeOnly ? active : all).slice(0, limit).map((r) => ({ ...r }));
|
|
78
152
|
}
|
|
79
|
-
export async function markRunsRead(
|
|
153
|
+
export async function markRunsRead(
|
|
154
|
+
runsDir: string,
|
|
155
|
+
taskId?: string,
|
|
156
|
+
): Promise<void> {
|
|
80
157
|
const ids = taskId ? [taskId] : await listRunTaskIds(runsDir);
|
|
81
158
|
for (const id of ids)
|
|
82
159
|
for (const run of await recentRuns(runsDir, id, Infinity)) {
|
|
@@ -92,16 +169,24 @@ export async function markRunsRead(runsDir: string, taskId?: string): Promise<vo
|
|
|
92
169
|
}
|
|
93
170
|
export async function listRunTaskIds(runsDir: string): Promise<string[]> {
|
|
94
171
|
try {
|
|
95
|
-
return (await readdir(runsDir))
|
|
172
|
+
return (await readdir(runsDir))
|
|
173
|
+
.filter((n) => n.endsWith('.jsonl'))
|
|
174
|
+
.map((n) => n.slice(0, -6));
|
|
96
175
|
} catch (error) {
|
|
97
176
|
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return [];
|
|
98
177
|
throw error;
|
|
99
178
|
}
|
|
100
179
|
}
|
|
101
|
-
export async function appendMissed(
|
|
180
|
+
export async function appendMissed(
|
|
181
|
+
file: string,
|
|
182
|
+
record: CronMissedRecord,
|
|
183
|
+
): Promise<void> {
|
|
102
184
|
await append(file, record);
|
|
103
185
|
}
|
|
104
|
-
export async function listMissed(
|
|
186
|
+
export async function listMissed(
|
|
187
|
+
file: string,
|
|
188
|
+
limit = 20,
|
|
189
|
+
): Promise<CronMissedRecord[]> {
|
|
105
190
|
const bySlot = new Map<string, CronMissedRecord>();
|
|
106
191
|
const reads = new Set<string>();
|
|
107
192
|
for (const parsed of await records(file)) {
|
|
@@ -122,9 +207,16 @@ export async function listMissed(file: string, limit = 20): Promise<CronMissedRe
|
|
|
122
207
|
.sort((a, b) => Date.parse(b.detectedAt) - Date.parse(a.detectedAt))
|
|
123
208
|
.slice(0, limit);
|
|
124
209
|
}
|
|
125
|
-
export async function markMissedRead(
|
|
210
|
+
export async function markMissedRead(
|
|
211
|
+
file: string,
|
|
212
|
+
taskId?: string,
|
|
213
|
+
): Promise<void> {
|
|
126
214
|
for (const record of await listMissed(file, Infinity))
|
|
127
215
|
if (!record.readAt && (!taskId || record.taskId === taskId)) {
|
|
128
|
-
await append(file, {
|
|
216
|
+
await append(file, {
|
|
217
|
+
event: 'read',
|
|
218
|
+
id: record.id,
|
|
219
|
+
readAt: new Date().toISOString(),
|
|
220
|
+
});
|
|
129
221
|
}
|
|
130
222
|
}
|