@ironbee-ai/cli 0.5.3 → 0.6.1
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/CHANGELOG.md +12 -0
- package/dist/clients/claude/hooks/require-verification.d.ts.map +1 -1
- package/dist/clients/claude/hooks/require-verification.js +21 -2
- package/dist/clients/claude/hooks/require-verification.js.map +1 -1
- package/dist/clients/claude/hooks/session-end.d.ts.map +1 -1
- package/dist/clients/claude/hooks/session-end.js +4 -0
- package/dist/clients/claude/hooks/session-end.js.map +1 -1
- package/dist/clients/claude/hooks/session-start.d.ts.map +1 -1
- package/dist/clients/claude/hooks/session-start.js +14 -4
- package/dist/clients/claude/hooks/session-start.js.map +1 -1
- package/dist/clients/claude/hooks/track-action.d.ts +25 -4
- package/dist/clients/claude/hooks/track-action.d.ts.map +1 -1
- package/dist/clients/claude/hooks/track-action.js +145 -25
- package/dist/clients/claude/hooks/track-action.js.map +1 -1
- package/dist/clients/claude/hooks/verify-gate.d.ts.map +1 -1
- package/dist/clients/claude/hooks/verify-gate.js +5 -0
- package/dist/clients/claude/hooks/verify-gate.js.map +1 -1
- package/dist/clients/claude/index.d.ts.map +1 -1
- package/dist/clients/claude/index.js +18 -1
- package/dist/clients/claude/index.js.map +1 -1
- package/dist/clients/claude/util.d.ts +74 -0
- package/dist/clients/claude/util.d.ts.map +1 -0
- package/dist/clients/claude/util.js +352 -0
- package/dist/clients/claude/util.js.map +1 -0
- package/dist/clients/cursor/hooks/require-verification.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/require-verification.js +18 -2
- package/dist/clients/cursor/hooks/require-verification.js.map +1 -1
- package/dist/clients/cursor/hooks/session-end.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/session-end.js +4 -0
- package/dist/clients/cursor/hooks/session-end.js.map +1 -1
- package/dist/clients/cursor/hooks/session-start.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/session-start.js +4 -1
- package/dist/clients/cursor/hooks/session-start.js.map +1 -1
- package/dist/clients/cursor/hooks/track-action.d.ts +30 -8
- package/dist/clients/cursor/hooks/track-action.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/track-action.js +179 -52
- package/dist/clients/cursor/hooks/track-action.js.map +1 -1
- package/dist/clients/cursor/hooks/verify-gate.d.ts.map +1 -1
- package/dist/clients/cursor/hooks/verify-gate.js +4 -0
- package/dist/clients/cursor/hooks/verify-gate.js.map +1 -1
- package/dist/clients/cursor/index.d.ts.map +1 -1
- package/dist/clients/cursor/index.js +13 -2
- package/dist/clients/cursor/index.js.map +1 -1
- package/dist/clients/cursor/util.d.ts +52 -0
- package/dist/clients/cursor/util.d.ts.map +1 -0
- package/dist/clients/cursor/util.js +264 -0
- package/dist/clients/cursor/util.js.map +1 -0
- package/dist/commands/hook.js +1 -2
- package/dist/commands/hook.js.map +1 -1
- package/dist/commands/process-job-file.d.ts +10 -0
- package/dist/commands/process-job-file.d.ts.map +1 -0
- package/dist/commands/process-job-file.js +19 -0
- package/dist/commands/process-job-file.js.map +1 -0
- package/dist/commands/queue.d.ts +12 -0
- package/dist/commands/queue.d.ts.map +1 -0
- package/dist/commands/queue.js +495 -0
- package/dist/commands/queue.js.map +1 -0
- package/dist/hooks/core/actions.d.ts +73 -2
- package/dist/hooks/core/actions.d.ts.map +1 -1
- package/dist/hooks/core/actions.js +36 -2
- package/dist/hooks/core/actions.js.map +1 -1
- package/dist/hooks/core/session-state.d.ts +27 -0
- package/dist/hooks/core/session-state.d.ts.map +1 -1
- package/dist/hooks/core/session-state.js +97 -0
- package/dist/hooks/core/session-state.js.map +1 -1
- package/dist/hooks/core/verify-gate.d.ts.map +1 -1
- package/dist/hooks/core/verify-gate.js +13 -5
- package/dist/hooks/core/verify-gate.js.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/collector.d.ts +62 -3
- package/dist/lib/collector.d.ts.map +1 -1
- package/dist/lib/collector.js +107 -35
- package/dist/lib/collector.js.map +1 -1
- package/dist/lib/config.d.ts +72 -8
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +40 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/queue/dead-letter.d.ts +26 -0
- package/dist/queue/dead-letter.d.ts.map +1 -0
- package/dist/queue/dead-letter.js +233 -0
- package/dist/queue/dead-letter.js.map +1 -0
- package/dist/queue/drain.d.ts +36 -0
- package/dist/queue/drain.d.ts.map +1 -0
- package/dist/queue/drain.js +170 -0
- package/dist/queue/drain.js.map +1 -0
- package/dist/queue/flush.d.ts +64 -0
- package/dist/queue/flush.d.ts.map +1 -0
- package/dist/queue/flush.js +119 -0
- package/dist/queue/flush.js.map +1 -0
- package/dist/queue/handlers/send-event.d.ts +23 -0
- package/dist/queue/handlers/send-event.d.ts.map +1 -0
- package/dist/queue/handlers/send-event.js +131 -0
- package/dist/queue/handlers/send-event.js.map +1 -0
- package/dist/queue/index.d.ts +30 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/index.js +71 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/queue/paths.d.ts +40 -0
- package/dist/queue/paths.d.ts.map +1 -0
- package/dist/queue/paths.js +107 -0
- package/dist/queue/paths.js.map +1 -0
- package/dist/queue/process-file.d.ts +22 -0
- package/dist/queue/process-file.d.ts.map +1 -0
- package/dist/queue/process-file.js +257 -0
- package/dist/queue/process-file.js.map +1 -0
- package/dist/queue/register-handlers.d.ts +26 -0
- package/dist/queue/register-handlers.d.ts.map +1 -0
- package/dist/queue/register-handlers.js +36 -0
- package/dist/queue/register-handlers.js.map +1 -0
- package/dist/queue/registry.d.ts +42 -0
- package/dist/queue/registry.d.ts.map +1 -0
- package/dist/queue/registry.js +36 -0
- package/dist/queue/registry.js.map +1 -0
- package/dist/queue/snapshot.d.ts +16 -0
- package/dist/queue/snapshot.d.ts.map +1 -0
- package/dist/queue/snapshot.js +39 -0
- package/dist/queue/snapshot.js.map +1 -0
- package/dist/queue/spawn.d.ts +15 -0
- package/dist/queue/spawn.d.ts.map +1 -0
- package/dist/queue/spawn.js +45 -0
- package/dist/queue/spawn.js.map +1 -0
- package/dist/queue/submit.d.ts +19 -0
- package/dist/queue/submit.d.ts.map +1 -0
- package/dist/queue/submit.js +94 -0
- package/dist/queue/submit.js.map +1 -0
- package/dist/queue/types.d.ts +77 -0
- package/dist/queue/types.d.ts.map +1 -0
- package/dist/queue/types.js +83 -0
- package/dist/queue/types.js.map +1 -0
- package/dist/queue/worker-log.d.ts +21 -0
- package/dist/queue/worker-log.d.ts.map +1 -0
- package/dist/queue/worker-log.js +140 -0
- package/dist/queue/worker-log.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dead-letter.js","sourceRoot":"","sources":["../../src/queue/dead-letter.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAyCH,4CA4DC;AAMD,oDAYC;AA0HD,sDAoBC;AAnQD,2BAWY;AACZ,+BAAsC;AACtC,mCAAoC;AACpC,0CAAuC;AACvC,mCASiB;AACjB,mCAA8E;AAQ9E;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,KAAsB,EAAE,GAAQ,EAAE,QAAgB;IAC/E,MAAM,QAAQ,GAAW,IAAA,eAAQ,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,UAAU,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,MAAM,OAAO,GAAW,IAAA,mBAAU,GAAE,CAAC;IAErC,2CAA2C;IAC3C,IAAI,KAAK,GAAqB;QAC1B,EAAE,EAAE,OAAO;QACX,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;QACrB,QAAQ;QACR,QAAQ,EAAE,GAAG;KAChB,CAAC;IACF,IAAI,IAAI,GAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAEhD,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,sB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,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC;AACvD,CAAC;AAED,yCAAyC;AACzC,SAAgB,qBAAqB,CAAC,UAAkB,EAAE,SAAiB;IACvE,MAAM,IAAI,GAAW,IAAA,sBAAc,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC3D,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACD,OAAO,GAAG,IAAA,iBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,SAAS;QACb,CAAC;QACD,IAAI,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAoB,CAAC,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACL,oEAAoE;QACxE,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IronBee CLI — Queue drain()
|
|
3
|
+
*
|
|
4
|
+
* See docs/job-queue.md §5.4. Synchronous per-session final-flush.
|
|
5
|
+
* Cleanup touches ONLY the queue/ subdir — never the parent session dir,
|
|
6
|
+
* which is owned by the consumer (actions.jsonl, verdict.json, …).
|
|
7
|
+
*/
|
|
8
|
+
import { HandlerRegistry } from "./registry";
|
|
9
|
+
export interface DrainOptions {
|
|
10
|
+
registry?: HandlerRegistry;
|
|
11
|
+
/**
|
|
12
|
+
* Skip snapshot files whose mtime is within the last `skipRecentMs`
|
|
13
|
+
* milliseconds. Used by `flushSynchronously` at SessionEnd to avoid
|
|
14
|
+
* racing with a detached worker that was just spawned by a Stop-class
|
|
15
|
+
* hook (§7.3). Operator-facing `ironbee queue drain` leaves this at 0
|
|
16
|
+
* so it catches every snapshot, including those from a just-crashed
|
|
17
|
+
* worker. Default 0.
|
|
18
|
+
*/
|
|
19
|
+
skipRecentMs?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface DrainResult {
|
|
22
|
+
snapshotsProcessed: number;
|
|
23
|
+
snapshotsRemaining: number;
|
|
24
|
+
cleanedQueueDir: boolean;
|
|
25
|
+
/** Snapshots that were skipped because they are too recent (see DrainOptions.skipRecentMs). */
|
|
26
|
+
snapshotsSkippedRecent: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Drain one session synchronously:
|
|
30
|
+
* 1. Roll the live file (if any) into a snapshot.
|
|
31
|
+
* 2. Process every snapshot in sorted order.
|
|
32
|
+
* 3. Best-effort cleanup of the queue/ dir if fully empty of undelivered
|
|
33
|
+
* work and triage records.
|
|
34
|
+
*/
|
|
35
|
+
export declare function drain(projectDir: string, sessionId: string, opts?: DrainOptions): Promise<DrainResult>;
|
|
36
|
+
//# sourceMappingURL=drain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drain.d.ts","sourceRoot":"","sources":["../../src/queue/drain.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,+FAA+F;IAC/F,sBAAsB,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA2C5G"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IronBee CLI — Queue drain()
|
|
4
|
+
*
|
|
5
|
+
* See docs/job-queue.md §5.4. Synchronous per-session final-flush.
|
|
6
|
+
* Cleanup touches ONLY the queue/ subdir — never the parent session dir,
|
|
7
|
+
* which is owned by the consumer (actions.jsonl, verdict.json, …).
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.drain = drain;
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const snapshot_1 = require("./snapshot");
|
|
14
|
+
const process_file_1 = require("./process-file");
|
|
15
|
+
const paths_1 = require("./paths");
|
|
16
|
+
/**
|
|
17
|
+
* Drain one session synchronously:
|
|
18
|
+
* 1. Roll the live file (if any) into a snapshot.
|
|
19
|
+
* 2. Process every snapshot in sorted order.
|
|
20
|
+
* 3. Best-effort cleanup of the queue/ dir if fully empty of undelivered
|
|
21
|
+
* work and triage records.
|
|
22
|
+
*/
|
|
23
|
+
async function drain(projectDir, sessionId, opts) {
|
|
24
|
+
(0, paths_1.validateSessionId)(sessionId);
|
|
25
|
+
const dir = (0, paths_1.queueDir)(projectDir, sessionId);
|
|
26
|
+
const result = {
|
|
27
|
+
snapshotsProcessed: 0,
|
|
28
|
+
snapshotsRemaining: 0,
|
|
29
|
+
cleanedQueueDir: false,
|
|
30
|
+
snapshotsSkippedRecent: 0,
|
|
31
|
+
};
|
|
32
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
const skipRecentMs = opts?.skipRecentMs ?? 0;
|
|
36
|
+
// Step 3 of §5.4: roll live file into a snapshot if it exists. This
|
|
37
|
+
// freshly-renamed snapshot has a brand-new mtime, so skipRecentMs would
|
|
38
|
+
// exclude it. Remember its path (if any) and force-process it below.
|
|
39
|
+
let justRolled = null;
|
|
40
|
+
try {
|
|
41
|
+
justRolled = (0, snapshot_1.snapshot)(projectDir, sessionId);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// snapshot() already returns null on ENOENT; any other failure bubbles
|
|
45
|
+
// into the glob below which will skip it. Keep drain() fault-tolerant.
|
|
46
|
+
}
|
|
47
|
+
// Step 4: process every snapshot.
|
|
48
|
+
const { eligible, skipped } = listSnapshots(dir, skipRecentMs, justRolled);
|
|
49
|
+
result.snapshotsSkippedRecent = skipped;
|
|
50
|
+
for (const snap of eligible) {
|
|
51
|
+
try {
|
|
52
|
+
await (0, process_file_1.processFile)(snap, { registry: opts?.registry });
|
|
53
|
+
result.snapshotsProcessed++;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// processFile never throws in normal paths, but be defensive
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Step 5: cleanup — strictly queue/ only; never the session dir.
|
|
60
|
+
result.snapshotsRemaining = listSnapshots(dir, 0, null).eligible.length;
|
|
61
|
+
result.cleanedQueueDir = tryCleanupQueueDir(projectDir, sessionId);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Enumerate snapshot files under `dir`, filtering out those touched within
|
|
66
|
+
* `skipRecentMs` unless they match `forceInclude` (the path we just rolled
|
|
67
|
+
* this drain cycle — it always needs processing even if its mtime is fresh).
|
|
68
|
+
*/
|
|
69
|
+
function listSnapshots(dir, skipRecentMs, forceInclude) {
|
|
70
|
+
let entries;
|
|
71
|
+
try {
|
|
72
|
+
entries = (0, fs_1.readdirSync)(dir);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return { eligible: [], skipped: 0 };
|
|
76
|
+
}
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
const eligible = [];
|
|
79
|
+
let skipped = 0;
|
|
80
|
+
for (const name of entries) {
|
|
81
|
+
if (!paths_1.SNAPSHOT_FILENAME_REGEX.test(name)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const full = (0, path_1.join)(dir, name);
|
|
85
|
+
if (forceInclude !== null && full === forceInclude) {
|
|
86
|
+
eligible.push(full);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (skipRecentMs > 0) {
|
|
90
|
+
try {
|
|
91
|
+
const mtime = (0, fs_1.statSync)(full).mtimeMs;
|
|
92
|
+
if (now - mtime < skipRecentMs) {
|
|
93
|
+
skipped++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// stat failed — include and let processFile handle it
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
eligible.push(full);
|
|
102
|
+
}
|
|
103
|
+
eligible.sort();
|
|
104
|
+
return { eligible, skipped };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Remove worker.log and empty dead-letter.jsonl, then rmdir queue/ — but
|
|
108
|
+
* only if no undelivered work or non-empty triage record remains.
|
|
109
|
+
* The session directory itself is owned by the consumer; never touched.
|
|
110
|
+
*/
|
|
111
|
+
function tryCleanupQueueDir(projectDir, sessionId) {
|
|
112
|
+
const dir = (0, paths_1.queueDir)(projectDir, sessionId);
|
|
113
|
+
let entries;
|
|
114
|
+
try {
|
|
115
|
+
entries = (0, fs_1.readdirSync)(dir);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// Any undelivered snapshot, any live file, or any non-empty dead-letter
|
|
121
|
+
// content blocks cleanup.
|
|
122
|
+
for (const name of entries) {
|
|
123
|
+
if (name === "jobs.jsonl") {
|
|
124
|
+
if (fileSize((0, path_1.join)(dir, name)) > 0) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (paths_1.SNAPSHOT_FILENAME_REGEX.test(name)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
if (name === "dead-letter.jsonl" || paths_1.DEAD_LETTER_ROTATED_REGEX.test(name)) {
|
|
132
|
+
if (fileSize((0, path_1.join)(dir, name)) > 0) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Safe to cleanup. Remove discardable files first.
|
|
138
|
+
for (const name of entries) {
|
|
139
|
+
if (name === "jobs.jsonl"
|
|
140
|
+
|| name === "dead-letter.jsonl"
|
|
141
|
+
|| paths_1.DEAD_LETTER_ROTATED_REGEX.test(name)
|
|
142
|
+
|| name === "worker.log"
|
|
143
|
+
|| paths_1.WORKER_LOG_ROTATED_REGEX.test(name)) {
|
|
144
|
+
try {
|
|
145
|
+
(0, fs_1.unlinkSync)((0, path_1.join)(dir, name));
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// best-effort
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Attempt rmdir queue/ — fails silently if other (unknown) files remain,
|
|
153
|
+
// which is the safe thing to do.
|
|
154
|
+
try {
|
|
155
|
+
(0, fs_1.rmdirSync)(dir);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function fileSize(path) {
|
|
163
|
+
try {
|
|
164
|
+
return (0, fs_1.statSync)(path).size;
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=drain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drain.js","sourceRoot":"","sources":["../../src/queue/drain.ts"],"names":[],"mappings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OAAO,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,YAAY;eAClB,IAAI,KAAK,mBAAmB;eAC5B,iCAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;eACpC,IAAI,KAAK,YAAY;eACrB,gCAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC;gBACD,IAAA,eAAU,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACL,cAAc;YAClB,CAAC;QACL,CAAC;IACL,CAAC;IAED,yEAAyE;IACzE,iCAAiC;IACjC,IAAI,CAAC;QACD,IAAA,cAAS,EAAC,GAAG,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,IAAI,CAAC;QACD,OAAO,IAAA,aAAQ,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,CAAC,CAAC;IACb,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IronBee CLI — Queue flush helpers
|
|
3
|
+
*
|
|
4
|
+
* Per-session flush triggers for consumer hooks. Two modes, to be chosen per
|
|
5
|
+
* §5.6 of docs/job-queue.md:
|
|
6
|
+
*
|
|
7
|
+
* - flushInBackground() — used by Stop-class hooks (active session).
|
|
8
|
+
* snapshot() the live file and fire-and-forget a
|
|
9
|
+
* detached worker on it. Returns in <10 ms.
|
|
10
|
+
*
|
|
11
|
+
* - flushSynchronously() — used by SessionEnd-class hooks (consumer is
|
|
12
|
+
* about to exit). Synchronously drain() every
|
|
13
|
+
* snapshot. May block for milliseconds to low
|
|
14
|
+
* seconds.
|
|
15
|
+
*
|
|
16
|
+
* Both helpers are fail-safe: any thrown error is swallowed and debug-logged
|
|
17
|
+
* so a queue fault cannot break the hook.
|
|
18
|
+
*/
|
|
19
|
+
import { DrainOptions, DrainResult } from "./drain";
|
|
20
|
+
/** Default threshold for `maybeAutoFlush` when unset in config (32 KB). */
|
|
21
|
+
export declare const DEFAULT_AUTO_FLUSH_SIZE_BYTES: number;
|
|
22
|
+
/**
|
|
23
|
+
* Stop-class hooks use this: snapshot the live queue and launch a detached
|
|
24
|
+
* worker. The caller's process may exit immediately after — the worker's
|
|
25
|
+
* `child.unref()` detaches it from the parent's event loop and process group
|
|
26
|
+
* to the extent the platform allows.
|
|
27
|
+
*
|
|
28
|
+
* Behaviour when queue has no work: snapshot() returns null (no live file),
|
|
29
|
+
* no worker spawned. No-op when the queue module has no producer yet.
|
|
30
|
+
*/
|
|
31
|
+
export declare function flushInBackground(projectDir: string, sessionId: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Producer-side auto-flush trigger. Called from `submit()` after a successful
|
|
34
|
+
* append. If the live `jobs.jsonl` has grown to at least the configured
|
|
35
|
+
* threshold (`jobQueue.autoFlushSizeBytes`, default 32 KB), snapshot it and
|
|
36
|
+
* spawn a detached worker in the background — same mechanism as a Stop hook,
|
|
37
|
+
* just triggered mid-session by queue growth instead of by a lifecycle event.
|
|
38
|
+
*
|
|
39
|
+
* Complements Stop / SessionEnd flushes: provides checkpointing for turns
|
|
40
|
+
* that emit many tool_call events (so collector sees them sooner) and caps
|
|
41
|
+
* worst-case live file size on abandoned sessions.
|
|
42
|
+
*
|
|
43
|
+
* Fail-safe: config read errors, stat failures, and flushInBackground
|
|
44
|
+
* exceptions are all swallowed so a queue fault can never break submit().
|
|
45
|
+
*
|
|
46
|
+
* Threshold <= 0 disables the feature (only lifecycle flushes remain).
|
|
47
|
+
*/
|
|
48
|
+
export declare function maybeAutoFlush(projectDir: string, sessionId: string): void;
|
|
49
|
+
/** Default recent-skip window used by `flushSynchronously` (see §7.3). */
|
|
50
|
+
export declare const SESSION_END_SKIP_RECENT_MS: number;
|
|
51
|
+
/**
|
|
52
|
+
* SessionEnd-class hooks use this: synchronously drain every snapshot for the
|
|
53
|
+
* session, then (if possible) clean up the queue/ subdir. Consumer owns the
|
|
54
|
+
* session dir itself — drain never touches anything outside queue/.
|
|
55
|
+
*
|
|
56
|
+
* By default skips snapshot files modified in the last 2 seconds — this is
|
|
57
|
+
* the "in-flight detached worker" window opened by a Stop hook firing right
|
|
58
|
+
* before SessionEnd (§7.3). Override with `opts.skipRecentMs = 0` if you
|
|
59
|
+
* want to treat recent snapshots as orphans (e.g. from tests). Skipped
|
|
60
|
+
* snapshots remain on disk and are drained by the next `ironbee queue drain`
|
|
61
|
+
* invocation.
|
|
62
|
+
*/
|
|
63
|
+
export declare function flushSynchronously(projectDir: string, sessionId: string, opts?: DrainOptions): Promise<DrainResult>;
|
|
64
|
+
//# sourceMappingURL=flush.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush.d.ts","sourceRoot":"","sources":["../../src/queue/flush.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAS,MAAM,SAAS,CAAC;AAK3D,2EAA2E;AAC3E,eAAO,MAAM,6BAA6B,EAAE,MAAkB,CAAC;AAE/D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAU7E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAkB1E;AAED,0EAA0E;AAC1E,eAAO,MAAM,0BAA0B,EAAE,MAAa,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACpC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,CAAC,CAYtB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IronBee CLI — Queue flush helpers
|
|
4
|
+
*
|
|
5
|
+
* Per-session flush triggers for consumer hooks. Two modes, to be chosen per
|
|
6
|
+
* §5.6 of docs/job-queue.md:
|
|
7
|
+
*
|
|
8
|
+
* - flushInBackground() — used by Stop-class hooks (active session).
|
|
9
|
+
* snapshot() the live file and fire-and-forget a
|
|
10
|
+
* detached worker on it. Returns in <10 ms.
|
|
11
|
+
*
|
|
12
|
+
* - flushSynchronously() — used by SessionEnd-class hooks (consumer is
|
|
13
|
+
* about to exit). Synchronously drain() every
|
|
14
|
+
* snapshot. May block for milliseconds to low
|
|
15
|
+
* seconds.
|
|
16
|
+
*
|
|
17
|
+
* Both helpers are fail-safe: any thrown error is swallowed and debug-logged
|
|
18
|
+
* so a queue fault cannot break the hook.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.SESSION_END_SKIP_RECENT_MS = exports.DEFAULT_AUTO_FLUSH_SIZE_BYTES = void 0;
|
|
22
|
+
exports.flushInBackground = flushInBackground;
|
|
23
|
+
exports.maybeAutoFlush = maybeAutoFlush;
|
|
24
|
+
exports.flushSynchronously = flushSynchronously;
|
|
25
|
+
const fs_1 = require("fs");
|
|
26
|
+
const config_1 = require("../lib/config");
|
|
27
|
+
const logger_1 = require("../lib/logger");
|
|
28
|
+
const drain_1 = require("./drain");
|
|
29
|
+
const paths_1 = require("./paths");
|
|
30
|
+
const snapshot_1 = require("./snapshot");
|
|
31
|
+
const spawn_1 = require("./spawn");
|
|
32
|
+
/** Default threshold for `maybeAutoFlush` when unset in config (32 KB). */
|
|
33
|
+
exports.DEFAULT_AUTO_FLUSH_SIZE_BYTES = 32 * 1024;
|
|
34
|
+
/**
|
|
35
|
+
* Stop-class hooks use this: snapshot the live queue and launch a detached
|
|
36
|
+
* worker. The caller's process may exit immediately after — the worker's
|
|
37
|
+
* `child.unref()` detaches it from the parent's event loop and process group
|
|
38
|
+
* to the extent the platform allows.
|
|
39
|
+
*
|
|
40
|
+
* Behaviour when queue has no work: snapshot() returns null (no live file),
|
|
41
|
+
* no worker spawned. No-op when the queue module has no producer yet.
|
|
42
|
+
*/
|
|
43
|
+
function flushInBackground(projectDir, sessionId) {
|
|
44
|
+
try {
|
|
45
|
+
(0, paths_1.validateSessionId)(sessionId);
|
|
46
|
+
const snap = (0, snapshot_1.snapshot)(projectDir, sessionId);
|
|
47
|
+
if (snap !== null) {
|
|
48
|
+
(0, spawn_1.spawnDetachedWorker)(snap);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
logger_1.logger.debug(`queue flushInBackground failed: ${e instanceof Error ? e.message : e}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Producer-side auto-flush trigger. Called from `submit()` after a successful
|
|
57
|
+
* append. If the live `jobs.jsonl` has grown to at least the configured
|
|
58
|
+
* threshold (`jobQueue.autoFlushSizeBytes`, default 32 KB), snapshot it and
|
|
59
|
+
* spawn a detached worker in the background — same mechanism as a Stop hook,
|
|
60
|
+
* just triggered mid-session by queue growth instead of by a lifecycle event.
|
|
61
|
+
*
|
|
62
|
+
* Complements Stop / SessionEnd flushes: provides checkpointing for turns
|
|
63
|
+
* that emit many tool_call events (so collector sees them sooner) and caps
|
|
64
|
+
* worst-case live file size on abandoned sessions.
|
|
65
|
+
*
|
|
66
|
+
* Fail-safe: config read errors, stat failures, and flushInBackground
|
|
67
|
+
* exceptions are all swallowed so a queue fault can never break submit().
|
|
68
|
+
*
|
|
69
|
+
* Threshold <= 0 disables the feature (only lifecycle flushes remain).
|
|
70
|
+
*/
|
|
71
|
+
function maybeAutoFlush(projectDir, sessionId) {
|
|
72
|
+
try {
|
|
73
|
+
const config = (0, config_1.loadConfig)(projectDir);
|
|
74
|
+
const raw = config.jobQueue?.autoFlushSizeBytes;
|
|
75
|
+
const threshold = typeof raw === "number" ? raw : exports.DEFAULT_AUTO_FLUSH_SIZE_BYTES;
|
|
76
|
+
if (threshold <= 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const livePath = (0, paths_1.liveQueueFile)(projectDir, sessionId);
|
|
80
|
+
const size = (0, fs_1.statSync)(livePath).size;
|
|
81
|
+
if (size >= threshold) {
|
|
82
|
+
flushInBackground(projectDir, sessionId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
// ENOENT on stat (file rolled between submit and stat) or any other
|
|
87
|
+
// fault must not propagate — submit() already persisted the line.
|
|
88
|
+
logger_1.logger.debug(`queue maybeAutoFlush skipped: ${e instanceof Error ? e.message : e}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Default recent-skip window used by `flushSynchronously` (see §7.3). */
|
|
92
|
+
exports.SESSION_END_SKIP_RECENT_MS = 2000;
|
|
93
|
+
/**
|
|
94
|
+
* SessionEnd-class hooks use this: synchronously drain every snapshot for the
|
|
95
|
+
* session, then (if possible) clean up the queue/ subdir. Consumer owns the
|
|
96
|
+
* session dir itself — drain never touches anything outside queue/.
|
|
97
|
+
*
|
|
98
|
+
* By default skips snapshot files modified in the last 2 seconds — this is
|
|
99
|
+
* the "in-flight detached worker" window opened by a Stop hook firing right
|
|
100
|
+
* before SessionEnd (§7.3). Override with `opts.skipRecentMs = 0` if you
|
|
101
|
+
* want to treat recent snapshots as orphans (e.g. from tests). Skipped
|
|
102
|
+
* snapshots remain on disk and are drained by the next `ironbee queue drain`
|
|
103
|
+
* invocation.
|
|
104
|
+
*/
|
|
105
|
+
async function flushSynchronously(projectDir, sessionId, opts) {
|
|
106
|
+
try {
|
|
107
|
+
(0, paths_1.validateSessionId)(sessionId);
|
|
108
|
+
const merged = {
|
|
109
|
+
...opts,
|
|
110
|
+
skipRecentMs: opts?.skipRecentMs ?? exports.SESSION_END_SKIP_RECENT_MS,
|
|
111
|
+
};
|
|
112
|
+
return await (0, drain_1.drain)(projectDir, sessionId, merged);
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
logger_1.logger.debug(`queue flushSynchronously failed: ${e instanceof Error ? e.message : e}`);
|
|
116
|
+
return { snapshotsProcessed: 0, snapshotsRemaining: 0, cleanedQueueDir: false, snapshotsSkippedRecent: 0 };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=flush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush.js","sourceRoot":"","sources":["../../src/queue/flush.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAsBH,8CAUC;AAkBD,wCAkBC;AAiBD,gDAgBC;AAnGD,2BAA8B;AAC9B,0CAA0D;AAC1D,0CAAuC;AACvC,mCAA2D;AAC3D,mCAA2D;AAC3D,yCAAsC;AACtC,mCAA8C;AAE9C,2EAA2E;AAC9D,QAAA,6BAA6B,GAAW,EAAE,GAAG,IAAI,CAAC;AAE/D;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAC,UAAkB,EAAE,SAAiB;IACnE,IAAI,CAAC;QACD,IAAA,yBAAiB,EAAC,SAAS,CAAC,CAAC;QAC7B,MAAM,IAAI,GAAkB,IAAA,mBAAQ,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAC5D,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAChB,IAAA,2BAAmB,EAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;IACL,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QAClB,eAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,cA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AC,OAAO,CAAU,EAAE,CAAC;QAClB,eAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvF,OAAO,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC,EAAE,CAAC;IAC/G,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IronBee CLI — send_event Handler
|
|
3
|
+
*
|
|
4
|
+
* Queue handler for `type: "send_event"` jobs. Batches event payloads from
|
|
5
|
+
* `job.data` and POSTs them to the IronBee Collector via the shared
|
|
6
|
+
* transport + target resolver in `src/lib/collector.ts`.
|
|
7
|
+
*
|
|
8
|
+
* HTTP status → queue error classification (spec §6):
|
|
9
|
+
* - 2xx → success (jobs marked delivered)
|
|
10
|
+
* - 401 / 403 → AuthError (worker leaves the file; operator fixes creds)
|
|
11
|
+
* - 5xx / 429 → TransientError (worker leaves the file; next drain retries)
|
|
12
|
+
* - timeout / net → TransientError
|
|
13
|
+
* - 400 (batch) → BadRequestBatchError (worker falls back to dispatchSingle)
|
|
14
|
+
* - 400 (single) → BadRequestError (worker dead-letters that one job)
|
|
15
|
+
* - other 4xx → BadRequestBatchError / BadRequestError (permanent)
|
|
16
|
+
*
|
|
17
|
+
* When no collector is configured (or `IRONBEE_COLLECTOR=false`), dispatch
|
|
18
|
+
* is a no-op — jobs are silently "delivered" so the queue doesn't accumulate
|
|
19
|
+
* indefinitely in local-only mode.
|
|
20
|
+
*/
|
|
21
|
+
import { Handler } from "../registry";
|
|
22
|
+
export declare const sendEventHandler: Handler;
|
|
23
|
+
//# sourceMappingURL=send-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-event.d.ts","sourceRoot":"","sources":["../../../src/queue/handlers/send-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAoEtC,eAAO,MAAM,gBAAgB,EAAE,OAgD9B,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IronBee CLI — send_event Handler
|
|
4
|
+
*
|
|
5
|
+
* Queue handler for `type: "send_event"` jobs. Batches event payloads from
|
|
6
|
+
* `job.data` and POSTs them to the IronBee Collector via the shared
|
|
7
|
+
* transport + target resolver in `src/lib/collector.ts`.
|
|
8
|
+
*
|
|
9
|
+
* HTTP status → queue error classification (spec §6):
|
|
10
|
+
* - 2xx → success (jobs marked delivered)
|
|
11
|
+
* - 401 / 403 → AuthError (worker leaves the file; operator fixes creds)
|
|
12
|
+
* - 5xx / 429 → TransientError (worker leaves the file; next drain retries)
|
|
13
|
+
* - timeout / net → TransientError
|
|
14
|
+
* - 400 (batch) → BadRequestBatchError (worker falls back to dispatchSingle)
|
|
15
|
+
* - 400 (single) → BadRequestError (worker dead-letters that one job)
|
|
16
|
+
* - other 4xx → BadRequestBatchError / BadRequestError (permanent)
|
|
17
|
+
*
|
|
18
|
+
* When no collector is configured (or `IRONBEE_COLLECTOR=false`), dispatch
|
|
19
|
+
* is a no-op — jobs are silently "delivered" so the queue doesn't accumulate
|
|
20
|
+
* indefinitely in local-only mode.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.sendEventHandler = void 0;
|
|
24
|
+
const collector_1 = require("../../lib/collector");
|
|
25
|
+
const logger_1 = require("../../lib/logger");
|
|
26
|
+
const paths_1 = require("../paths");
|
|
27
|
+
const types_1 = require("../types");
|
|
28
|
+
const SEND_TIMEOUT_MS = 10000;
|
|
29
|
+
/**
|
|
30
|
+
* Default max events per POST. Collectors sometimes reject bodies above ~1 MB
|
|
31
|
+
* (Spring Boot default). With tool_call envelopes capped at 4 KB each, 100
|
|
32
|
+
* events ≈ 400 KB worst case — comfortably under typical limits.
|
|
33
|
+
* Override via `collector.batchSize` in config.json.
|
|
34
|
+
*/
|
|
35
|
+
const DEFAULT_BATCH_SIZE = 100;
|
|
36
|
+
function resolveBatchSize(target) {
|
|
37
|
+
if (typeof target.batchSize === "number" && target.batchSize >= 1) {
|
|
38
|
+
return Math.floor(target.batchSize);
|
|
39
|
+
}
|
|
40
|
+
return DEFAULT_BATCH_SIZE;
|
|
41
|
+
}
|
|
42
|
+
function classifyBatch(result) {
|
|
43
|
+
const { status, body } = result;
|
|
44
|
+
if (status >= 200 && status < 300) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (status === 401 || status === 403) {
|
|
48
|
+
throw new types_1.AuthError(`collector auth failed: HTTP ${status} ${truncate(body, 200)}`);
|
|
49
|
+
}
|
|
50
|
+
if (status === 429 || status >= 500) {
|
|
51
|
+
throw new types_1.TransientError(`collector transient: HTTP ${status} ${truncate(body, 200)}`);
|
|
52
|
+
}
|
|
53
|
+
if (status === 400) {
|
|
54
|
+
throw new types_1.BadRequestBatchError(`collector rejected batch: HTTP 400 ${truncate(body, 200)}`);
|
|
55
|
+
}
|
|
56
|
+
// other 4xx — treat as permanent per-batch; fallback will dead-letter each
|
|
57
|
+
throw new types_1.BadRequestBatchError(`collector error: HTTP ${status} ${truncate(body, 200)}`);
|
|
58
|
+
}
|
|
59
|
+
function classifySingle(result) {
|
|
60
|
+
const { status, body } = result;
|
|
61
|
+
if (status >= 200 && status < 300) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (status === 401 || status === 403) {
|
|
65
|
+
throw new types_1.AuthError(`collector auth failed: HTTP ${status} ${truncate(body, 200)}`);
|
|
66
|
+
}
|
|
67
|
+
if (status === 429 || status >= 500) {
|
|
68
|
+
throw new types_1.TransientError(`collector transient: HTTP ${status} ${truncate(body, 200)}`);
|
|
69
|
+
}
|
|
70
|
+
if (status === 400) {
|
|
71
|
+
throw new types_1.BadRequestError(`400: ${truncate(body, 200)}`);
|
|
72
|
+
}
|
|
73
|
+
throw new types_1.BadRequestError(`HTTP ${status}: ${truncate(body, 200)}`);
|
|
74
|
+
}
|
|
75
|
+
function truncate(s, max) {
|
|
76
|
+
if (s.length <= max) {
|
|
77
|
+
return s;
|
|
78
|
+
}
|
|
79
|
+
return s.slice(0, max) + "…";
|
|
80
|
+
}
|
|
81
|
+
exports.sendEventHandler = {
|
|
82
|
+
/**
|
|
83
|
+
* Chunk the jobs into `batchSize`-sized slices and POST each. The first
|
|
84
|
+
* failed chunk throws — if `TransientError`/`AuthError`, the worker
|
|
85
|
+
* leaves the snapshot for retry (which re-sends already-delivered chunks;
|
|
86
|
+
* downstream dedupes on `job.id`). A 400 throws `BadRequestBatchError`,
|
|
87
|
+
* triggering per-job fallback across the WHOLE snapshot (spec §5.3),
|
|
88
|
+
* again relying on id-dedup for chunks that already succeeded.
|
|
89
|
+
*/
|
|
90
|
+
async dispatch(jobs) {
|
|
91
|
+
const target = (0, collector_1.getCollectorTarget)((0, paths_1.resolveProjectDir)());
|
|
92
|
+
if (!target) {
|
|
93
|
+
logger_1.logger.debug(`send_event: no collector configured, skipping ${jobs.length} job(s)`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (jobs.length === 0) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const batchSize = resolveBatchSize(target);
|
|
100
|
+
const events = jobs.map((j) => j.data);
|
|
101
|
+
for (let i = 0; i < events.length; i += batchSize) {
|
|
102
|
+
const chunk = events.slice(i, i + batchSize);
|
|
103
|
+
let result;
|
|
104
|
+
try {
|
|
105
|
+
result = await (0, collector_1.postEventsBatch)(chunk, target, { timeoutMs: SEND_TIMEOUT_MS });
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
throw new types_1.TransientError(`collector network error: ${e instanceof Error ? e.message : String(e)}`);
|
|
109
|
+
}
|
|
110
|
+
classifyBatch(result);
|
|
111
|
+
}
|
|
112
|
+
// Note: worker stdio is "ignore" + no setLogFile — `processFile` writes
|
|
113
|
+
// a `BATCH_OK type=send_event count=N` line to `worker.log` per spec
|
|
114
|
+
// §5.3 which already covers per-batch observability.
|
|
115
|
+
},
|
|
116
|
+
async dispatchSingle(job) {
|
|
117
|
+
const target = (0, collector_1.getCollectorTarget)((0, paths_1.resolveProjectDir)());
|
|
118
|
+
if (!target) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let result;
|
|
122
|
+
try {
|
|
123
|
+
result = await (0, collector_1.postEventsBatch)([job.data], target, { timeoutMs: SEND_TIMEOUT_MS });
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
throw new types_1.TransientError(`collector network error: ${e instanceof Error ? e.message : String(e)}`);
|
|
127
|
+
}
|
|
128
|
+
classifySingle(result);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=send-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-event.js","sourceRoot":"","sources":["../../../src/queue/handlers/send-event.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,mDAA6G;AAC7G,6CAA0C;AAE1C,oCAA6C;AAC7C,oCAMkB;AAElB,MAAM,eAAe,GAAW,KAAM,CAAC;AACvC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAW,GAAG,CAAC;AAEvC,SAAS,gBAAgB,CAAC,MAAuB;IAC7C,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAED,SAAS,aAAa,CAAC,MAAwB;IAC3C,MAAM,EAAE,MAAM,EA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ue Module
|
|
3
|
+
*
|
|
4
|
+
* File-backed, crash-safe, concurrency-safe background job queue.
|
|
5
|
+
* Canonical spec: docs/job-queue.md.
|
|
6
|
+
*
|
|
7
|
+
* Public API:
|
|
8
|
+
* - submit(projectDir, sessionId, type, data, opts?) → job_id
|
|
9
|
+
* - snapshot(projectDir, sessionId) → snapshot_path | null
|
|
10
|
+
* - processFile(path, opts?) → void
|
|
11
|
+
* - drain(projectDir, sessionId, opts?) → DrainResult
|
|
12
|
+
* - register(type, handler) / unregister(type)
|
|
13
|
+
* - spawnDetachedWorker(snapshotPath)
|
|
14
|
+
*
|
|
15
|
+
* Error classes:
|
|
16
|
+
* InvalidSessionIdError, JobTooLargeError, IOError,
|
|
17
|
+
* TransientError, AuthError, BadRequestError, BadRequestBatchError
|
|
18
|
+
*/
|
|
19
|
+
export { submit, SubmitOptions } from "./submit";
|
|
20
|
+
export { snapshot } from "./snapshot";
|
|
21
|
+
export { processFile, ProcessFileOptions } from "./process-file";
|
|
22
|
+
export { drain, DrainOptions, DrainResult } from "./drain";
|
|
23
|
+
export { spawnDetachedWorker } from "./spawn";
|
|
24
|
+
export { flushInBackground, flushSynchronously, maybeAutoFlush, DEFAULT_AUTO_FLUSH_SIZE_BYTES } from "./flush";
|
|
25
|
+
export { registerQueueHandlers, SEND_EVENT_TYPE } from "./register-handlers";
|
|
26
|
+
export { Handler, HandlerRegistry, register, unregister, clear as clearRegistry, get as getHandler, snapshotRegistry, } from "./registry";
|
|
27
|
+
export { InvalidSessionIdError, JobTooLargeError, IOError, TransientError, AuthError, BadRequestError, BadRequestBatchError, Job, DeadLetterEntry, DeadLetterParsed, DeadLetterParseError, MAX_LINE_BYTES, } from "./types";
|
|
28
|
+
export { resolveProjectDir, validateSessionId, sessionsRoot, sessionDir, queueDir, liveQueueFile, snapshotFile, deadLetterFile, workerLogFile, parseSnapshotPath, SNAPSHOT_FILENAME_REGEX, DEAD_LETTER_ROTATED_REGEX, WORKER_LOG_ROTATED_REGEX, } from "./paths";
|
|
29
|
+
export { readDeadLetterEntries } from "./dead-letter";
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queue/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,cAAc,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC/G,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EACH,OAAO,EACP,eAAe,EACf,QAAQ,EACR,UAAU,EACV,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,UAAU,EACjB,gBAAgB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,GAAG,EACH,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACH,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,GAC3B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|