katt 0.0.9 → 0.0.11
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 +44 -19
- package/build-tests/check1.eval.js +2 -11
- package/build-tests/check2.eval.js +0 -7
- package/dist/index.js +478 -383
- package/dist/katt.js +6 -4
- package/dist/runCli-CJ7_lGMV.js +398 -0
- package/package.json +7 -7
- package/build-tests/__snapshots__/check1.snap.md +0 -1
- package/build-tests/__snapshots__/check1__Hello_World__should_return_the_date_in_a_json_format.snap.md +0 -1
- package/build-tests/__snapshots__/check1__root.snap.md +0 -1
- package/dist/runCli-j5xhVCdB.js +0 -424
package/dist/index.js
CHANGED
|
@@ -1,393 +1,488 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { spawn as
|
|
7
|
-
import { tmpdir as
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _, y as v } from "./runCli-CJ7_lGMV.js";
|
|
2
|
+
import { access as y, constants as b, mkdir as x, mkdtemp as S, readFile as C, rm as w, writeFile as ee } from "node:fs/promises";
|
|
3
|
+
import { basename as T, dirname as E, isAbsolute as te, join as D, resolve as O } from "node:path";
|
|
4
|
+
import { mkdirSync as k, readFileSync as A, writeFileSync as j } from "node:fs";
|
|
5
|
+
import { CopilotClient as ne, approveAll as re } from "@github/copilot-sdk";
|
|
6
|
+
import { spawn as ie } from "node:child_process";
|
|
7
|
+
import { tmpdir as ae } from "node:os";
|
|
8
|
+
//#region src/lib/describe/describe.ts
|
|
9
|
+
function oe(t, n) {
|
|
10
|
+
_(() => {
|
|
11
|
+
o(t);
|
|
12
|
+
try {
|
|
13
|
+
let t = n();
|
|
14
|
+
if (t && typeof t.then == "function") {
|
|
15
|
+
e(t.finally(() => {
|
|
16
|
+
l();
|
|
17
|
+
}));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
} catch (e) {
|
|
21
|
+
throw l(), e;
|
|
22
|
+
}
|
|
23
|
+
l();
|
|
24
|
+
}, c());
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/lib/prompt/codex.ts
|
|
28
|
+
var se = "katt-codex-", ce = "last-message.txt";
|
|
29
|
+
function le(e, t) {
|
|
30
|
+
return typeof e == "object" && !!e && "code" in e && e.code === t;
|
|
31
|
+
}
|
|
32
|
+
function M(e) {
|
|
33
|
+
return typeof e == "string" && e.length > 0;
|
|
34
|
+
}
|
|
35
|
+
function ue(e) {
|
|
36
|
+
return M(e) ? [e] : Array.isArray(e) ? e.filter(M) : [];
|
|
37
|
+
}
|
|
38
|
+
function de(e, t, n = !1) {
|
|
39
|
+
let r = t ?? {}, i = [
|
|
40
|
+
"exec",
|
|
41
|
+
"--color",
|
|
42
|
+
"never",
|
|
43
|
+
...n ? ["--json"] : [],
|
|
44
|
+
"--output-last-message",
|
|
45
|
+
e
|
|
46
|
+
];
|
|
47
|
+
M(r.model) && i.push("--model", r.model), M(r.profile) && i.push("--profile", r.profile), M(r.sandbox) && i.push("--sandbox", r.sandbox), r.fullAuto === !0 && i.push("--full-auto"), r.skipGitRepoCheck === !0 && i.push("--skip-git-repo-check"), r.dangerouslyBypassApprovalsAndSandbox === !0 && i.push("--dangerously-bypass-approvals-and-sandbox");
|
|
48
|
+
for (let e of ue(r.config)) i.push("--config", e);
|
|
49
|
+
return i.push("-"), i;
|
|
50
|
+
}
|
|
51
|
+
function N(e, t, n, r) {
|
|
52
|
+
return new Promise((i, a) => {
|
|
53
|
+
let o = ie("codex", t, {
|
|
54
|
+
cwd: r,
|
|
55
|
+
stdio: [
|
|
56
|
+
"pipe",
|
|
57
|
+
"pipe",
|
|
58
|
+
"pipe"
|
|
59
|
+
]
|
|
60
|
+
}), s = "", c = "", l = !1;
|
|
61
|
+
o.stdout.setEncoding("utf8"), o.stderr.setEncoding("utf8"), o.stdout.on("data", (e) => {
|
|
62
|
+
s += e;
|
|
63
|
+
}), o.stderr.on("data", (e) => {
|
|
64
|
+
c += e;
|
|
65
|
+
}), o.stdin.on("error", () => {});
|
|
66
|
+
let u = setTimeout(() => {
|
|
67
|
+
l = !0, o.kill("SIGTERM");
|
|
68
|
+
}, n);
|
|
69
|
+
o.once("error", (e) => {
|
|
70
|
+
clearTimeout(u), a(/* @__PURE__ */ Error(`Failed to start Codex CLI. Ensure codex is installed and available on PATH. ${String(e)}`));
|
|
71
|
+
}), o.once("close", (e, t) => {
|
|
72
|
+
clearTimeout(u), i({
|
|
73
|
+
exitCode: e,
|
|
74
|
+
signal: t,
|
|
75
|
+
stdout: s.trim(),
|
|
76
|
+
stderr: c.trim(),
|
|
77
|
+
timedOut: l
|
|
78
|
+
});
|
|
79
|
+
}), o.stdin.end(e);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async function P(e, t) {
|
|
83
|
+
try {
|
|
84
|
+
return await C(e, "utf8");
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (!le(e, "ENOENT")) throw e;
|
|
87
|
+
return t;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function F(e) {
|
|
91
|
+
if (e.timedOut) return "Codex timed out before returning a response.";
|
|
92
|
+
if (e.exitCode === null) return `Codex exited due to signal ${e.signal ?? "unknown"}.`;
|
|
93
|
+
let t = e.stderr.length > 0 ? ` ${e.stderr}` : "";
|
|
94
|
+
return `Codex exited with code ${e.exitCode}.${t}`;
|
|
95
|
+
}
|
|
96
|
+
function I(e) {
|
|
97
|
+
return typeof e == "object" && !!e;
|
|
98
|
+
}
|
|
99
|
+
function L(e) {
|
|
100
|
+
return typeof e == "string" && e.trim().length > 0 ? e.trim() : void 0;
|
|
101
|
+
}
|
|
102
|
+
function R(e, t, n = 0) {
|
|
103
|
+
if (n > 6) return;
|
|
104
|
+
let r = L(e);
|
|
105
|
+
if (r) {
|
|
106
|
+
t.push(r);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(e)) {
|
|
110
|
+
for (let r of e) R(r, t, n + 1);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (I(e)) for (let r of [
|
|
114
|
+
"reasoning",
|
|
115
|
+
"reasoningText",
|
|
116
|
+
"reasoning_text",
|
|
117
|
+
"content",
|
|
118
|
+
"summary",
|
|
119
|
+
"deltaContent",
|
|
120
|
+
"delta",
|
|
121
|
+
"text",
|
|
122
|
+
"intent",
|
|
123
|
+
"analysis",
|
|
124
|
+
"thought",
|
|
125
|
+
"plan",
|
|
126
|
+
"message"
|
|
127
|
+
]) r in e && R(e[r], t, n + 1);
|
|
128
|
+
}
|
|
129
|
+
function z(e) {
|
|
130
|
+
if (e.trim().length === 0) return [];
|
|
131
|
+
try {
|
|
132
|
+
let t = JSON.parse(e);
|
|
133
|
+
if (!I(t)) return [];
|
|
134
|
+
let n = [], r = L(t.type);
|
|
135
|
+
if (r && /reason|intent|plan|analysis|thought|think/i.test(r) && R(t, n), "msg" in t && I(t.msg)) {
|
|
136
|
+
let e = L(t.msg.type);
|
|
137
|
+
e && /reason|intent|plan|analysis|thought|think/i.test(e) && R(t.msg, n);
|
|
138
|
+
}
|
|
139
|
+
return n;
|
|
140
|
+
} catch {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function B(e) {
|
|
145
|
+
let t = e.split(/\r?\n/), n = [], r = /* @__PURE__ */ new Set();
|
|
146
|
+
for (let e of t) {
|
|
147
|
+
let t = z(e);
|
|
148
|
+
for (let e of t) r.has(e) || (r.add(e), n.push(e));
|
|
149
|
+
}
|
|
150
|
+
return n.join("\n\n");
|
|
151
|
+
}
|
|
152
|
+
function V(e) {
|
|
153
|
+
let t = e.split(/\r?\n/), n = "";
|
|
154
|
+
for (let e of t) if (e.trim().length !== 0) try {
|
|
155
|
+
let t = JSON.parse(e);
|
|
156
|
+
if (!I(t)) continue;
|
|
157
|
+
if (I(t.msg) && L(t.msg.type) === "agent_message") {
|
|
158
|
+
let e = L(t.msg.message);
|
|
159
|
+
e && (n = e);
|
|
160
|
+
}
|
|
161
|
+
} catch {}
|
|
162
|
+
return n;
|
|
163
|
+
}
|
|
164
|
+
async function H(e, t, n, r) {
|
|
165
|
+
let i = n ?? {}, a = M(i.workingDirectory) ? i.workingDirectory : process.cwd(), o = await S(D(ae(), se)), s = D(o, ce);
|
|
166
|
+
try {
|
|
167
|
+
let i = await N(e, de(s, n, r), t, a);
|
|
168
|
+
if (i.timedOut) throw Error(`Codex timed out after ${t}ms.`);
|
|
169
|
+
if (i.exitCode !== 0) throw Error(F(i));
|
|
170
|
+
let o = await P(s, r ? V(i.stdout) : i.stdout);
|
|
171
|
+
if (o.length === 0) throw Error("Codex did not return a response.");
|
|
172
|
+
return {
|
|
173
|
+
response: o,
|
|
174
|
+
reasoning: r ? B(i.stdout) : ""
|
|
175
|
+
};
|
|
176
|
+
} finally {
|
|
177
|
+
await w(o, {
|
|
178
|
+
recursive: !0,
|
|
179
|
+
force: !0
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async function fe(e, t, n) {
|
|
184
|
+
return (await H(e, t, n, !1)).response;
|
|
185
|
+
}
|
|
186
|
+
async function pe(e, t, n) {
|
|
187
|
+
return H(e, t, n, !0);
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/lib/prompt/reasoningWriter.ts
|
|
191
|
+
var me = "No reasoning was emitted by the runtime for this prompt.", he = "No final output was returned by the runtime for this prompt.", ge = new Set([
|
|
192
|
+
"<",
|
|
193
|
+
">",
|
|
194
|
+
":",
|
|
195
|
+
"\"",
|
|
196
|
+
"/",
|
|
197
|
+
"\\",
|
|
198
|
+
"|",
|
|
199
|
+
"?",
|
|
200
|
+
"*"
|
|
201
|
+
]);
|
|
202
|
+
function U(e) {
|
|
203
|
+
let t = e.trim().split("").map((e) => e.charCodeAt(0) <= 31 || ge.has(e) ? "_" : e).join("").replace(/\s+/g, "_");
|
|
204
|
+
return t.length > 0 ? t : "unnamed";
|
|
205
|
+
}
|
|
206
|
+
function _e() {
|
|
207
|
+
let e = g().map((e) => U(e.description)), t = i().map((e) => U(e.description)), n = [...e, ...t];
|
|
208
|
+
return n.length === 0 ? "root" : n.join("__");
|
|
209
|
+
}
|
|
210
|
+
function ve(e) {
|
|
211
|
+
return `${String(e.getUTCFullYear())}${String(e.getUTCMonth() + 1).padStart(2, "0")}${String(e.getUTCDate()).padStart(2, "0")}T${String(e.getUTCHours()).padStart(2, "0")}${String(e.getUTCMinutes()).padStart(2, "0")}${String(e.getUTCSeconds()).padStart(2, "0")}`;
|
|
212
|
+
}
|
|
213
|
+
async function ye(e) {
|
|
214
|
+
try {
|
|
215
|
+
return await y(e, b.F_OK), !0;
|
|
216
|
+
} catch {
|
|
217
|
+
return !1;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function be(e, t, n) {
|
|
221
|
+
let r = t.trim().length > 0 ? t : me, i = n.trim().length > 0 ? n : he;
|
|
222
|
+
return [
|
|
223
|
+
"# Reasoning",
|
|
224
|
+
"",
|
|
225
|
+
`Runtime: ${e}`,
|
|
226
|
+
"",
|
|
227
|
+
"## Reasoning Trace",
|
|
228
|
+
"",
|
|
229
|
+
r,
|
|
230
|
+
"",
|
|
231
|
+
"## Final Output",
|
|
232
|
+
"",
|
|
233
|
+
i,
|
|
234
|
+
""
|
|
235
|
+
].join("\n");
|
|
236
|
+
}
|
|
237
|
+
function xe(e) {
|
|
238
|
+
let t = T(e).replace(/\.eval\.[^./\\]+$/, ""), n = _e();
|
|
239
|
+
return D(E(e), "__reasoning__", `${t}__${n}.reasoning.md`);
|
|
240
|
+
}
|
|
241
|
+
function Se(e) {
|
|
242
|
+
let t = ve(/* @__PURE__ */ new Date());
|
|
243
|
+
return `${e.replace(/\.reasoning\.md$/, "")}__${t}.reasoning.md`;
|
|
244
|
+
}
|
|
245
|
+
async function W(e, n, r) {
|
|
246
|
+
let i = t.getStore()?.evalFile;
|
|
247
|
+
if (!i) return;
|
|
248
|
+
let a = xe(i);
|
|
249
|
+
await x(E(a), { recursive: !0 });
|
|
250
|
+
let o = await ye(a) ? Se(a) : a;
|
|
251
|
+
return await ee(o, be(e, n, r), "utf8"), o;
|
|
252
|
+
}
|
|
253
|
+
function G(e) {
|
|
254
|
+
return typeof e == "string" && e.length > 0 ? e : void 0;
|
|
255
|
+
}
|
|
256
|
+
function K(e) {
|
|
257
|
+
if (!e) return;
|
|
258
|
+
let t = { ...e };
|
|
259
|
+
if (t.model !== void 0) {
|
|
260
|
+
let e = G(typeof t.model == "string" ? t.model : void 0);
|
|
261
|
+
e ? t.model = e : delete t.model;
|
|
262
|
+
}
|
|
263
|
+
return Object.keys(t).length > 0 ? t : void 0;
|
|
264
|
+
}
|
|
265
|
+
function q(e) {
|
|
266
|
+
if (!(typeof e != "number" || !Number.isFinite(e)) && !(e <= 0)) return Math.floor(e);
|
|
267
|
+
}
|
|
268
|
+
function J(e) {
|
|
269
|
+
return !Number.isFinite(e) || (e ?? 0) <= 0 ? 0 : Math.floor(e ?? 0);
|
|
270
|
+
}
|
|
271
|
+
function Ce(e) {
|
|
272
|
+
return J(e.inputTokens) + J(e.outputTokens) + J(e.cacheReadTokens) + J(e.cacheWriteTokens);
|
|
273
|
+
}
|
|
274
|
+
async function Y(e, t = {}) {
|
|
275
|
+
let { timeoutMs: r, onPermissionRequest: i, ...a } = t, o = await u(), s = K(o.agentOptions), c = K(a), l = K({
|
|
276
|
+
...s ?? {},
|
|
277
|
+
...c ?? {}
|
|
278
|
+
}), d = q(o.promptTimeoutMs), f = q(r) ?? d ?? 6e5, m = G(typeof l?.model == "string" ? l.model : void 0), h = p();
|
|
279
|
+
if (o.agent === "codex") {
|
|
280
|
+
if (h) {
|
|
281
|
+
let t = await pe(e, f, l);
|
|
282
|
+
return m && v(m), await W("codex", t.reasoning, t.response), t.response;
|
|
283
|
+
}
|
|
284
|
+
let t = await fe(e, f, l);
|
|
285
|
+
return m && v(m), t;
|
|
286
|
+
}
|
|
287
|
+
let g = new ne({ useLoggedInUser: !0 }), _, y, b, x, S = 0, C = [], w = [];
|
|
288
|
+
try {
|
|
289
|
+
await g.start(), _ = await g.createSession({
|
|
290
|
+
...l,
|
|
291
|
+
onPermissionRequest: i ?? re
|
|
292
|
+
}), y = _.on("assistant.usage", (e) => {
|
|
293
|
+
S += Ce(e.data);
|
|
294
|
+
}), b = _.on("assistant.reasoning", (e) => {
|
|
295
|
+
typeof e.data.content == "string" && e.data.content.length > 0 && C.push(e.data.content);
|
|
296
|
+
}), x = _.on("assistant.intent", (e) => {
|
|
297
|
+
typeof e.data.intent == "string" && e.data.intent.length > 0 && w.push(e.data.intent);
|
|
298
|
+
});
|
|
299
|
+
let t = await _.sendAndWait({ prompt: e }, f);
|
|
300
|
+
if (!t?.data?.content) throw Error("Copilot did not return a response.");
|
|
301
|
+
if (h) {
|
|
302
|
+
let e = [];
|
|
303
|
+
for (let t of w) e.push(`Intent: ${t}`);
|
|
304
|
+
e.push(...C), typeof t.data.reasoningText == "string" && t.data.reasoningText.length > 0 && e.push(t.data.reasoningText), await W("gh-copilot", e.join("\n\n"), t.data.content);
|
|
305
|
+
}
|
|
306
|
+
return m && v(m), t.data.content;
|
|
307
|
+
} finally {
|
|
308
|
+
let e = [];
|
|
309
|
+
if (y?.(), b?.(), x?.(), S > 0 && n(S), _) try {
|
|
310
|
+
await _.destroy();
|
|
311
|
+
} catch (t) {
|
|
312
|
+
e.push(t);
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
let t = await g.stop();
|
|
316
|
+
e.push(...t);
|
|
317
|
+
} catch (t) {
|
|
318
|
+
e.push(t);
|
|
319
|
+
}
|
|
320
|
+
e.length > 0 && console.error(`Copilot cleanup encountered ${e.length} error(s).`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function we(e, n = {}) {
|
|
324
|
+
let r = t.getStore(), i = r?.evalFile ? E(r.evalFile) : process.cwd();
|
|
325
|
+
return Y(await C(te(e) ? e : O(i, e), "utf8"), n);
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/lib/expect/matcherUtils.ts
|
|
329
|
+
function X(e) {
|
|
330
|
+
a({
|
|
331
|
+
describePath: r(),
|
|
332
|
+
itPath: f(),
|
|
333
|
+
message: e
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/lib/expect/promptCheck.ts
|
|
338
|
+
async function Te(t, n) {
|
|
339
|
+
let r = Date.now(), i = `expected '${t}' to satisfy '${n}'`, a = Y(`Evaluate if the expectation is fulfiled in by the input.
|
|
340
|
+
Expectation: "${n}".
|
|
230
341
|
Input:
|
|
231
342
|
---
|
|
232
343
|
${t}
|
|
233
344
|
---
|
|
234
345
|
Important: Answer with "Yes" or "No" only, without any additional text.
|
|
235
|
-
`).then((
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
346
|
+
`).then((e) => {
|
|
347
|
+
e.includes("Yes") ? m(Date.now() - r, "promptCheck") : e.includes("No") ? X(i) : X(`failed to evaluate expectation '${n}'`);
|
|
348
|
+
});
|
|
349
|
+
return e(a), a;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/lib/expect/toBeClassifiedAs.ts
|
|
353
|
+
var Ee = 3;
|
|
354
|
+
function De(e) {
|
|
355
|
+
let t = e.match(/\b([1-5])\b/);
|
|
356
|
+
return t?.[1] ? Number(t[1]) : null;
|
|
357
|
+
}
|
|
358
|
+
async function Oe(t, n, r) {
|
|
359
|
+
let i = Date.now(), a = r?.threshold ?? Ee, o = Y(`Classify the input by how "${n}" it is on a scale of 1 to 5.
|
|
360
|
+
1 means "not ${n}" and 5 means "very ${n}".
|
|
249
361
|
Return only a single number: 1, 2, 3, 4, or 5.
|
|
250
362
|
|
|
251
363
|
Input:
|
|
252
364
|
---
|
|
253
365
|
${t}
|
|
254
|
-
---`,
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
},
|
|
378
|
-
promptCheck: async (e) => {
|
|
379
|
-
await wt(t, e);
|
|
380
|
-
},
|
|
381
|
-
toBeClassifiedAs: async (e, n) => {
|
|
382
|
-
await bt(t, e, n);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
export {
|
|
387
|
-
Nt as describe,
|
|
388
|
-
Lt as expect,
|
|
389
|
-
Pt as it,
|
|
390
|
-
F as prompt,
|
|
391
|
-
It as promptFile,
|
|
392
|
-
jt as runCli
|
|
393
|
-
};
|
|
366
|
+
---`, r?.model ? { model: r.model } : void 0).then((e) => {
|
|
367
|
+
let t = De(e);
|
|
368
|
+
if (t === null) {
|
|
369
|
+
X(`failed to classify as '${n}'. Evaluator returned '${e}'`);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
let r = `expected response to be classified as '${n}' with score >= ${a}, got ${t}`;
|
|
373
|
+
if (t < a) {
|
|
374
|
+
X(r);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
m(Date.now() - i, "toBeClassifiedAs");
|
|
378
|
+
});
|
|
379
|
+
return e(o), o;
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/lib/expect/toContain.ts
|
|
383
|
+
function ke(e, t) {
|
|
384
|
+
let n = `expected '${e}' to include '${t}'`;
|
|
385
|
+
e.includes(t) || X(n);
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
//#region src/lib/expect/toMatchSnapshot.ts
|
|
389
|
+
var Z = new Set([
|
|
390
|
+
"<",
|
|
391
|
+
">",
|
|
392
|
+
":",
|
|
393
|
+
"\"",
|
|
394
|
+
"/",
|
|
395
|
+
"\\",
|
|
396
|
+
"|",
|
|
397
|
+
"?",
|
|
398
|
+
"*"
|
|
399
|
+
]);
|
|
400
|
+
function Q(e) {
|
|
401
|
+
let t = e.trim().split("").map((e) => e.charCodeAt(0) <= 31 || Z.has(e) ? "_" : e).join("").replace(/\s+/g, "_");
|
|
402
|
+
return t.length > 0 ? t : "unnamed";
|
|
403
|
+
}
|
|
404
|
+
function Ae() {
|
|
405
|
+
let e = g().map((e) => Q(e.description)), t = i().map((e) => Q(e.description)), n = [...e, ...t];
|
|
406
|
+
return n.length === 0 ? "root" : n.join("__");
|
|
407
|
+
}
|
|
408
|
+
function je(e) {
|
|
409
|
+
let t = T(e).replace(/\.eval\.[^./\\]+$/, ""), n = Ae();
|
|
410
|
+
return D(E(e), "__snapshots__", `${t}__${n}.snap.md`);
|
|
411
|
+
}
|
|
412
|
+
function $(e) {
|
|
413
|
+
return e.split(/\r?\n/);
|
|
414
|
+
}
|
|
415
|
+
function Me(e, t) {
|
|
416
|
+
if (e === t) return " (no diff)";
|
|
417
|
+
let n = $(e), r = $(t), i = Math.max(n.length, r.length), a = [];
|
|
418
|
+
for (let e = 0; e < i; e += 1) {
|
|
419
|
+
let t = n[e], i = r[e];
|
|
420
|
+
if (t !== i) {
|
|
421
|
+
if (t === void 0 && i !== void 0) {
|
|
422
|
+
a.push(`+ ${i}`);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (t !== void 0 && i === void 0) {
|
|
426
|
+
a.push(`- ${t}`);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
a.push(`- ${t ?? ""}`), a.push(`+ ${i ?? ""}`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return a.join("\n");
|
|
433
|
+
}
|
|
434
|
+
function Ne(e) {
|
|
435
|
+
let n = t.getStore()?.evalFile;
|
|
436
|
+
if (!n) {
|
|
437
|
+
X("toMatchSnapshot can only be used while running an eval file.");
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
let r = je(n);
|
|
441
|
+
try {
|
|
442
|
+
let t = A(r, "utf8");
|
|
443
|
+
if (t === e) return;
|
|
444
|
+
if (s()) {
|
|
445
|
+
j(r, e, "utf8");
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
let n = Me(t, e);
|
|
449
|
+
X([
|
|
450
|
+
`Snapshot mismatch at ${r}`,
|
|
451
|
+
"",
|
|
452
|
+
"Diff:",
|
|
453
|
+
n,
|
|
454
|
+
"",
|
|
455
|
+
"Run 'npx katt --update-snapshots' (or -u) to accept this change."
|
|
456
|
+
].join("\n"));
|
|
457
|
+
} catch (t) {
|
|
458
|
+
if (t.code !== "ENOENT") {
|
|
459
|
+
X(`Failed to read snapshot at ${r}: ${String(t)}`);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
try {
|
|
463
|
+
k(E(r), { recursive: !0 }), j(r, e, "utf8");
|
|
464
|
+
} catch (e) {
|
|
465
|
+
X(`Failed to write snapshot at ${r}: ${String(e)}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/lib/expect/expect.ts
|
|
471
|
+
function Pe(e) {
|
|
472
|
+
return {
|
|
473
|
+
toContain: (t) => {
|
|
474
|
+
ke(e, t);
|
|
475
|
+
},
|
|
476
|
+
toMatchSnapshot: () => {
|
|
477
|
+
Ne(e);
|
|
478
|
+
},
|
|
479
|
+
promptCheck: async (t) => {
|
|
480
|
+
await Te(e, t);
|
|
481
|
+
},
|
|
482
|
+
toBeClassifiedAs: async (t, n) => {
|
|
483
|
+
await Oe(e, t, n);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
//#endregion
|
|
488
|
+
export { oe as describe, Pe as expect, d as it, Y as prompt, we as promptFile, h as runCli };
|