@inerrata-corporation/errata 2.0.2-dev.305 → 2.0.2-dev.309
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/errata.mjs +108 -40
- package/package.json +1 -1
package/errata.mjs
CHANGED
|
@@ -26007,8 +26007,8 @@ function isDistinctiveIdentifier(name2) {
|
|
|
26007
26007
|
if (name2.length < 3) return false;
|
|
26008
26008
|
if (name2.includes(".") || name2.includes("_") || /\d/.test(name2)) return true;
|
|
26009
26009
|
if (/[a-z][A-Z]/.test(name2)) return true;
|
|
26010
|
-
if (/^[A-Z]/.test(name2) && name2.length >= 4) return true;
|
|
26011
|
-
return
|
|
26010
|
+
if (/^[A-Z]/.test(name2) && /[a-z]/.test(name2) && name2.length >= 4) return true;
|
|
26011
|
+
return false;
|
|
26012
26012
|
}
|
|
26013
26013
|
function buildSymbolLexicon(store, summariesByBodyHash2) {
|
|
26014
26014
|
const lex = /* @__PURE__ */ new Map();
|
|
@@ -28119,6 +28119,96 @@ var init_src10 = __esm({
|
|
|
28119
28119
|
}
|
|
28120
28120
|
});
|
|
28121
28121
|
|
|
28122
|
+
// src/llm-provider.ts
|
|
28123
|
+
function chatProvider() {
|
|
28124
|
+
return (process.env["EXTRACTION_PROVIDER"] ?? "anthropic").toLowerCase() === "azure" ? "azure" : "anthropic";
|
|
28125
|
+
}
|
|
28126
|
+
function deploymentFor(model) {
|
|
28127
|
+
const key = `MODEL_${model.toUpperCase().replace(/[^A-Z0-9]/g, "_")}_OPENAI`;
|
|
28128
|
+
return process.env[key] ?? process.env["AZURE_OPENAI_DEPLOYMENT"];
|
|
28129
|
+
}
|
|
28130
|
+
function isChatConfigured(model) {
|
|
28131
|
+
if (chatProvider() === "azure") {
|
|
28132
|
+
return Boolean(
|
|
28133
|
+
process.env["AZURE_OPENAI_API_KEY"] && process.env["AZURE_OPENAI_ENDPOINT"] && deploymentFor(model)
|
|
28134
|
+
);
|
|
28135
|
+
}
|
|
28136
|
+
return Boolean(process.env["ANTHROPIC_API_KEY"]);
|
|
28137
|
+
}
|
|
28138
|
+
async function chat(req) {
|
|
28139
|
+
const provider = chatProvider();
|
|
28140
|
+
try {
|
|
28141
|
+
if (provider === "azure") {
|
|
28142
|
+
const endpoint = (process.env["AZURE_OPENAI_ENDPOINT"] ?? "").replace(/\/+$/, "");
|
|
28143
|
+
const version2 = process.env["AZURE_OPENAI_API_VERSION"] ?? "2024-10-21";
|
|
28144
|
+
const deployment = deploymentFor(req.model);
|
|
28145
|
+
if (!endpoint || !deployment) {
|
|
28146
|
+
console.warn("[errata] llm: azure selected but endpoint/deployment missing \u2014 skipping");
|
|
28147
|
+
return null;
|
|
28148
|
+
}
|
|
28149
|
+
const resp2 = await fetch(
|
|
28150
|
+
`${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${version2}`,
|
|
28151
|
+
{
|
|
28152
|
+
method: "POST",
|
|
28153
|
+
headers: {
|
|
28154
|
+
"api-key": process.env["AZURE_OPENAI_API_KEY"] ?? "",
|
|
28155
|
+
"content-type": "application/json"
|
|
28156
|
+
},
|
|
28157
|
+
body: JSON.stringify({
|
|
28158
|
+
messages: [
|
|
28159
|
+
...req.system ? [{ role: "system", content: req.system }] : [],
|
|
28160
|
+
{ role: "user", content: req.user }
|
|
28161
|
+
],
|
|
28162
|
+
// `max_completion_tokens`: the newer deployments reject `max_tokens`.
|
|
28163
|
+
max_completion_tokens: req.maxTokens
|
|
28164
|
+
})
|
|
28165
|
+
}
|
|
28166
|
+
);
|
|
28167
|
+
if (!resp2.ok) {
|
|
28168
|
+
console.warn(
|
|
28169
|
+
`[errata] llm: azure ${resp2.status} \u2014 ${(await resp2.text().catch(() => "")).slice(0, 200)}`
|
|
28170
|
+
);
|
|
28171
|
+
return null;
|
|
28172
|
+
}
|
|
28173
|
+
const json3 = await resp2.json();
|
|
28174
|
+
return json3.choices?.[0]?.message?.content ?? null;
|
|
28175
|
+
}
|
|
28176
|
+
const resp = await fetch("https://api.anthropic.com/v1/messages", {
|
|
28177
|
+
method: "POST",
|
|
28178
|
+
headers: {
|
|
28179
|
+
"x-api-key": process.env["ANTHROPIC_API_KEY"] ?? "",
|
|
28180
|
+
"anthropic-version": "2023-06-01",
|
|
28181
|
+
"content-type": "application/json"
|
|
28182
|
+
},
|
|
28183
|
+
body: JSON.stringify({
|
|
28184
|
+
model: req.model,
|
|
28185
|
+
max_tokens: req.maxTokens,
|
|
28186
|
+
...req.system ? { system: req.system } : {},
|
|
28187
|
+
messages: [{ role: "user", content: req.user }]
|
|
28188
|
+
})
|
|
28189
|
+
});
|
|
28190
|
+
if (!resp.ok) {
|
|
28191
|
+
console.warn(
|
|
28192
|
+
`[errata] llm: anthropic ${resp.status} \u2014 ${(await resp.text().catch(() => "")).slice(0, 200)}`
|
|
28193
|
+
);
|
|
28194
|
+
return null;
|
|
28195
|
+
}
|
|
28196
|
+
const json2 = await resp.json();
|
|
28197
|
+
return json2.content?.find((c) => c.type === "text")?.text ?? null;
|
|
28198
|
+
} catch (err2) {
|
|
28199
|
+
console.warn(
|
|
28200
|
+
`[errata] llm: ${provider} transport failed \u2014`,
|
|
28201
|
+
err2 instanceof Error ? err2.message : err2
|
|
28202
|
+
);
|
|
28203
|
+
return null;
|
|
28204
|
+
}
|
|
28205
|
+
}
|
|
28206
|
+
var init_llm_provider = __esm({
|
|
28207
|
+
"src/llm-provider.ts"() {
|
|
28208
|
+
"use strict";
|
|
28209
|
+
}
|
|
28210
|
+
});
|
|
28211
|
+
|
|
28122
28212
|
// src/symbol-summaries.ts
|
|
28123
28213
|
import { existsSync as existsSync8, readFileSync as readFileSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
28124
28214
|
import { join as join7 } from "node:path";
|
|
@@ -28179,55 +28269,32 @@ function parseSummaryJson(text, expected) {
|
|
|
28179
28269
|
}
|
|
28180
28270
|
return out2;
|
|
28181
28271
|
}
|
|
28182
|
-
function haikuIntentSummarizer(
|
|
28183
|
-
if (!
|
|
28272
|
+
function haikuIntentSummarizer(_apiKey) {
|
|
28273
|
+
if (!isChatConfigured(SUMMARY_MODEL)) return void 0;
|
|
28184
28274
|
return async (symbols) => {
|
|
28185
|
-
|
|
28186
|
-
|
|
28187
|
-
(s, i2) => `### ${i2 + 1}. kind: ${s.kind}
|
|
28275
|
+
const listing = symbols.map(
|
|
28276
|
+
(s, i2) => `### ${i2 + 1}. kind: ${s.kind}
|
|
28188
28277
|
name: ${s.name}
|
|
28189
28278
|
` + (s.doc ? `doc: ${s.doc}
|
|
28190
28279
|
` : "") + `${s.snippet ? `\`\`\`
|
|
28191
28280
|
${s.snippet}
|
|
28192
28281
|
\`\`\`` : "(no source available \u2014 describe from the name)"}`
|
|
28193
|
-
|
|
28194
|
-
|
|
28195
|
-
|
|
28196
|
-
|
|
28197
|
-
"x-api-key": apiKey,
|
|
28198
|
-
"anthropic-version": "2023-06-01",
|
|
28199
|
-
"content-type": "application/json"
|
|
28200
|
-
},
|
|
28201
|
-
body: JSON.stringify({
|
|
28202
|
-
model: SUMMARY_MODEL,
|
|
28203
|
-
max_tokens: 2e3,
|
|
28204
|
-
messages: [{ role: "user", content: `${SUMMARY_PROMPT}
|
|
28282
|
+
).join("\n\n");
|
|
28283
|
+
const text = await chat({
|
|
28284
|
+
model: SUMMARY_MODEL,
|
|
28285
|
+
user: `${SUMMARY_PROMPT}
|
|
28205
28286
|
|
|
28206
28287
|
SYMBOLS:
|
|
28207
|
-
${listing}
|
|
28208
|
-
|
|
28209
|
-
|
|
28210
|
-
|
|
28211
|
-
|
|
28212
|
-
console.warn(
|
|
28213
|
-
`[errata] symbol summaries: API ${resp.status} \u2014 sweep produced nothing this round. ${detail.slice(0, 200)}`
|
|
28214
|
-
);
|
|
28215
|
-
return symbols.map(() => null);
|
|
28216
|
-
}
|
|
28217
|
-
const json2 = await resp.json();
|
|
28218
|
-
return parseSummaryJson(json2.content?.find((c) => c.type === "text")?.text ?? "", symbols.length);
|
|
28219
|
-
} catch (err2) {
|
|
28220
|
-
console.warn(
|
|
28221
|
-
"[errata] symbol summaries: transport failed \u2014 sweep produced nothing this round:",
|
|
28222
|
-
err2 instanceof Error ? err2.message : err2
|
|
28223
|
-
);
|
|
28224
|
-
return symbols.map(() => null);
|
|
28225
|
-
}
|
|
28288
|
+
${listing}`,
|
|
28289
|
+
maxTokens: 2e3
|
|
28290
|
+
});
|
|
28291
|
+
if (text === null) return symbols.map(() => null);
|
|
28292
|
+
return parseSummaryJson(text, symbols.length);
|
|
28226
28293
|
};
|
|
28227
28294
|
}
|
|
28228
28295
|
function envIntentSummarizer() {
|
|
28229
28296
|
if (process.env["ERRATA_SYMBOL_SUMMARIES"] !== "1") return void 0;
|
|
28230
|
-
return haikuIntentSummarizer(
|
|
28297
|
+
return haikuIntentSummarizer();
|
|
28231
28298
|
}
|
|
28232
28299
|
function readSnippet(workspaceRoot, attrs) {
|
|
28233
28300
|
const relPath = attrs["relPath"];
|
|
@@ -28305,6 +28372,7 @@ var init_symbol_summaries = __esm({
|
|
|
28305
28372
|
"use strict";
|
|
28306
28373
|
init_src();
|
|
28307
28374
|
init_generalize_graph();
|
|
28375
|
+
init_llm_provider();
|
|
28308
28376
|
SUMMARY_LABELS = [
|
|
28309
28377
|
["Function", "function"],
|
|
28310
28378
|
["Method", "method"],
|
|
@@ -52938,7 +53006,7 @@ function startLoopLagMonitor(thresholdMs = 1e3) {
|
|
|
52938
53006
|
}
|
|
52939
53007
|
|
|
52940
53008
|
// src/engine.ts
|
|
52941
|
-
var DAEMON_VERSION = true ? "2.0.2-dev.
|
|
53009
|
+
var DAEMON_VERSION = true ? "2.0.2-dev.309" : "2.0.0-alpha.0";
|
|
52942
53010
|
var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
|
|
52943
53011
|
var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
|
|
52944
53012
|
var GIT_OP_MUTE_MS = 4e3;
|