@dadado/agent-kit-cli 6.3.0 → 6.4.0
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/dashboard/dashboard-data.mjs +14 -2
- package/dashboard/dashboard.html +139 -4
- package/dashboard/lib/chat-sessions.d.mts +63 -0
- package/dashboard/lib/chat-sessions.mjs +430 -0
- package/dashboard/serve.mjs +5 -1
- package/dist/{add-VA2W7I6P.js → add-HFDX3U3R.js} +2 -2
- package/dist/{chunk-6GYKOHIL.js → chunk-3OM7JODZ.js} +2 -2
- package/dist/{chunk-Z7RYIHHX.js → chunk-6OTJEQEC.js} +3 -3
- package/dist/{chunk-MAPOQEA2.js → chunk-6RRG3WOE.js} +8 -1
- package/dist/{chunk-6KUSG7BJ.js → chunk-7BEHUBEJ.js} +3 -1
- package/dist/{chunk-VQBI3JVS.js → chunk-ANPSYWQO.js} +2 -2
- package/dist/{chunk-WMVMBPCR.js → chunk-AXLXEAVJ.js} +1 -1
- package/dist/{chunk-25J2SMJQ.js → chunk-E465FAWM.js} +1 -1
- package/dist/{chunk-U26MRIWN.js → chunk-H46W7NHC.js} +1 -1
- package/dist/{chunk-NNKOWUWM.js → chunk-HHR56LJQ.js} +64 -28
- package/dist/{chunk-SV2BR2LZ.js → chunk-IMIVTDMK.js} +7 -7
- package/dist/chunk-IRTS7WEA.js +374 -0
- package/dist/{chunk-MO63KZBP.js → chunk-KX3OUY4W.js} +8 -6
- package/dist/chunk-MWTXI6C5.js +223 -0
- package/dist/{chunk-JEI6HACW.js → chunk-NJVWTROP.js} +24 -377
- package/dist/{chunk-OVOXRH5W.js → chunk-Q4PCMRM5.js} +1 -1
- package/dist/{chunk-GUQYNUV4.js → chunk-R7DA4KXG.js} +1 -1
- package/dist/{chunk-OWWFKGKS.js → chunk-SE7ZIRLX.js} +2 -2
- package/dist/{chunk-KVY425NM.js → chunk-TZ5XYIEF.js} +4 -2
- package/dist/{chunk-Z7ABX5QI.js → chunk-WOHZ4T5V.js} +4 -2
- package/dist/{chunk-YRFSTHR5.js → chunk-XEEB4YSA.js} +13 -219
- package/dist/{chunk-QTBTKEXK.js → chunk-ZPZVROS5.js} +1 -1
- package/dist/{contribute-NLM2BN6Z.js → contribute-PP7HMPW7.js} +3 -3
- package/dist/{countdown-QXJD6TDB.js → countdown-LAUZMI7U.js} +10 -8
- package/dist/{diff-HHG4JEDE.js → diff-HYWC4G6Y.js} +4 -4
- package/dist/{doctor-TWF2M3S3.js → doctor-2X3HBRJJ.js} +8 -8
- package/dist/engine-info-4ZWEIHSX.js +89 -0
- package/dist/{ground-control-NMYYIVCV.js → ground-control-WKV2BMOW.js} +5 -4
- package/dist/{guard-EHXF76ID.js → guard-ZZRQW3DJ.js} +107 -8
- package/dist/{hook-VP7FHRSZ.js → hook-UEYR4M3Z.js} +10 -4
- package/dist/index.js +26 -22
- package/dist/{init-UOTV4ASJ.js → init-UF5VEIJX.js} +11 -11
- package/dist/{install-VCHPXQV3.js → install-6ILVA22C.js} +11 -11
- package/dist/{run-R66G276Q.js → run-2EKD2BEC.js} +12 -9
- package/dist/{run-plan-24Z5K4P3.js → run-plan-G72XMC5Z.js} +11 -7
- package/dist/sessions-O7MYEMCT.js +343 -0
- package/dist/{setup-global-M6LKGJHQ.js → setup-global-ZZEY5KWE.js} +5 -5
- package/dist/{status-5UKVIKOI.js → status-4LK2QXVQ.js} +6 -6
- package/dist/{update-VQBGEUWS.js → update-FPR2NZND.js} +9 -9
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatHitlGateLine
|
|
3
|
+
} from "./chunk-IRTS7WEA.js";
|
|
4
|
+
|
|
5
|
+
// src/plan-loop/driver-events.ts
|
|
6
|
+
import { createInterface } from "readline";
|
|
7
|
+
import { StringDecoder } from "string_decoder";
|
|
8
|
+
var DRIVER_PROTOCOL_MAJOR = 1;
|
|
9
|
+
var DRIVER_PROTOCOL_VERSION = "1.1.0";
|
|
10
|
+
var DRIVER_EVENTS_FORMATS = ["ndjson"];
|
|
11
|
+
var INBOUND_MAX_CHARS = 64 * 1024;
|
|
12
|
+
var AGENT_PENDING_MAX_CHARS = 4 * 1024 * 1024;
|
|
13
|
+
function formatDriverEvent(event, now = () => /* @__PURE__ */ new Date()) {
|
|
14
|
+
return `${JSON.stringify({ v: DRIVER_PROTOCOL_MAJOR, ts: now().toISOString(), ...event })}
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
function createDriverEmitter(write = (text) => {
|
|
18
|
+
process.stdout.write(text);
|
|
19
|
+
}, now) {
|
|
20
|
+
return {
|
|
21
|
+
emit(event) {
|
|
22
|
+
try {
|
|
23
|
+
write(formatDriverEvent(event, now));
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function parseDriverInbound(line) {
|
|
30
|
+
const text = line.trim();
|
|
31
|
+
if (text.length > INBOUND_MAX_CHARS) return { ok: false, error: "line too long" };
|
|
32
|
+
let value;
|
|
33
|
+
try {
|
|
34
|
+
value = JSON.parse(text);
|
|
35
|
+
} catch {
|
|
36
|
+
return { ok: false, error: "not JSON" };
|
|
37
|
+
}
|
|
38
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
39
|
+
return { ok: false, error: "not a JSON object" };
|
|
40
|
+
}
|
|
41
|
+
const msg = value;
|
|
42
|
+
if (msg.v !== void 0 && msg.v !== DRIVER_PROTOCOL_MAJOR) {
|
|
43
|
+
return { ok: false, error: `unsupported protocol v${String(msg.v)}` };
|
|
44
|
+
}
|
|
45
|
+
if (msg.type === "stop") {
|
|
46
|
+
return {
|
|
47
|
+
ok: true,
|
|
48
|
+
message: { type: "stop", ...typeof msg.reason === "string" ? { reason: msg.reason } : {} }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (msg.type !== "hitl_reply")
|
|
52
|
+
return { ok: false, error: `unknown type ${JSON.stringify(msg.type)}` };
|
|
53
|
+
if (typeof msg.askId !== "string" || !/^[a-z0-9-]+$/.test(msg.askId)) {
|
|
54
|
+
return { ok: false, error: "hitl_reply.askId must be a kebab-case string" };
|
|
55
|
+
}
|
|
56
|
+
if (typeof msg.reply === "number") {
|
|
57
|
+
if (!Number.isInteger(msg.reply) || msg.reply < 1) {
|
|
58
|
+
return { ok: false, error: "hitl_reply.reply number must be a positive integer" };
|
|
59
|
+
}
|
|
60
|
+
return { ok: true, message: { type: "hitl_reply", askId: msg.askId, reply: msg.reply } };
|
|
61
|
+
}
|
|
62
|
+
if (typeof msg.reply === "string" && msg.reply.trim() && !/[\r\n]/.test(msg.reply)) {
|
|
63
|
+
return { ok: true, message: { type: "hitl_reply", askId: msg.askId, reply: msg.reply.trim() } };
|
|
64
|
+
}
|
|
65
|
+
return { ok: false, error: "hitl_reply.reply must be a number or a one-line non-empty string" };
|
|
66
|
+
}
|
|
67
|
+
function inboundToRawAnswer(gate, parsed) {
|
|
68
|
+
if (!parsed.ok) return { kind: "stop", cause: "protocol error", detail: parsed.error };
|
|
69
|
+
const message = parsed.message;
|
|
70
|
+
if (message.type === "stop") return { kind: "stop", cause: "driver stop" };
|
|
71
|
+
if (message.askId !== gate.askId) {
|
|
72
|
+
return {
|
|
73
|
+
kind: "stop",
|
|
74
|
+
cause: "protocol error",
|
|
75
|
+
detail: `reply for ${message.askId} while gate ${gate.askId} is open`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { kind: "line", text: String(message.reply) };
|
|
79
|
+
}
|
|
80
|
+
function createDriverAnswerReader(opts) {
|
|
81
|
+
const input = opts.input ?? process.stdin;
|
|
82
|
+
const queue = [];
|
|
83
|
+
let ended = false;
|
|
84
|
+
let waiter = null;
|
|
85
|
+
let rl = null;
|
|
86
|
+
const ensure = () => {
|
|
87
|
+
if (rl) return;
|
|
88
|
+
rl = createInterface({ input, terminal: false, crlfDelay: Number.POSITIVE_INFINITY });
|
|
89
|
+
rl.on("line", (line) => {
|
|
90
|
+
if (!line.trim()) return;
|
|
91
|
+
if (waiter) {
|
|
92
|
+
const w = waiter;
|
|
93
|
+
waiter = null;
|
|
94
|
+
w(line);
|
|
95
|
+
} else queue.push(line);
|
|
96
|
+
});
|
|
97
|
+
rl.on("close", () => {
|
|
98
|
+
ended = true;
|
|
99
|
+
if (waiter) {
|
|
100
|
+
const w = waiter;
|
|
101
|
+
waiter = null;
|
|
102
|
+
w(null);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const nextLine = (signal) => new Promise((resolve) => {
|
|
107
|
+
const queued = queue.shift();
|
|
108
|
+
if (queued !== void 0) {
|
|
109
|
+
resolve(queued);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (ended) {
|
|
113
|
+
resolve(null);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const onAbort = () => {
|
|
117
|
+
if (waiter === settle) waiter = null;
|
|
118
|
+
resolve(null);
|
|
119
|
+
};
|
|
120
|
+
const settle = (line) => {
|
|
121
|
+
signal?.removeEventListener("abort", onAbort);
|
|
122
|
+
resolve(line);
|
|
123
|
+
};
|
|
124
|
+
if (signal?.aborted) {
|
|
125
|
+
resolve(null);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
129
|
+
waiter = settle;
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
read: async (gate, readOpts) => {
|
|
133
|
+
ensure();
|
|
134
|
+
opts.emitter.emit({
|
|
135
|
+
type: "hitl_gate",
|
|
136
|
+
tick: opts.tick(),
|
|
137
|
+
askId: gate.askId,
|
|
138
|
+
labels: [...gate.labels],
|
|
139
|
+
detection: gate.detection,
|
|
140
|
+
line: formatHitlGateLine(gate)
|
|
141
|
+
});
|
|
142
|
+
const line = await nextLine(readOpts.signal);
|
|
143
|
+
if (line === null) return { kind: "eof" };
|
|
144
|
+
return inboundToRawAnswer(gate, parseDriverInbound(line));
|
|
145
|
+
},
|
|
146
|
+
close: () => {
|
|
147
|
+
const r = rl;
|
|
148
|
+
rl = null;
|
|
149
|
+
r?.close();
|
|
150
|
+
if (typeof input.pause === "function") {
|
|
151
|
+
input.pause();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
var DriverAgentSink = class {
|
|
157
|
+
constructor(emitter, tick) {
|
|
158
|
+
this.emitter = emitter;
|
|
159
|
+
this.tick = tick;
|
|
160
|
+
}
|
|
161
|
+
emitter;
|
|
162
|
+
tick;
|
|
163
|
+
pending = "";
|
|
164
|
+
dropped = false;
|
|
165
|
+
decoder = new StringDecoder("utf8");
|
|
166
|
+
feed(chunk) {
|
|
167
|
+
try {
|
|
168
|
+
const text = typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
169
|
+
if (!text) return;
|
|
170
|
+
const lines = (this.pending + text).split("\n");
|
|
171
|
+
this.pending = lines.pop() ?? "";
|
|
172
|
+
for (const line of lines) {
|
|
173
|
+
if (this.dropped) {
|
|
174
|
+
this.dropped = false;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
this.take(line);
|
|
178
|
+
}
|
|
179
|
+
if (this.pending.length > AGENT_PENDING_MAX_CHARS) {
|
|
180
|
+
this.pending = "";
|
|
181
|
+
this.dropped = true;
|
|
182
|
+
}
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
end() {
|
|
187
|
+
try {
|
|
188
|
+
const rest = this.pending + this.decoder.end();
|
|
189
|
+
this.pending = "";
|
|
190
|
+
if (rest && !this.dropped) this.take(rest);
|
|
191
|
+
this.dropped = false;
|
|
192
|
+
} catch {
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
take(raw) {
|
|
196
|
+
const line = raw.replace(/\r$/, "");
|
|
197
|
+
if (!line.trim()) return;
|
|
198
|
+
const trimmed = line.trim();
|
|
199
|
+
if (trimmed.startsWith("{")) {
|
|
200
|
+
try {
|
|
201
|
+
const event = JSON.parse(trimmed);
|
|
202
|
+
if (typeof event === "object" && event !== null && !Array.isArray(event)) {
|
|
203
|
+
this.emitter.emit({
|
|
204
|
+
type: "agent_event",
|
|
205
|
+
tick: this.tick,
|
|
206
|
+
event
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
this.emitter.emit({ type: "agent_text", tick: this.tick, text: line });
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export {
|
|
218
|
+
DRIVER_PROTOCOL_VERSION,
|
|
219
|
+
DRIVER_EVENTS_FORMATS,
|
|
220
|
+
createDriverEmitter,
|
|
221
|
+
createDriverAnswerReader,
|
|
222
|
+
DriverAgentSink
|
|
223
|
+
};
|