@codemem/opencode-plugin 0.25.0 → 0.25.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.
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
|
|
16
16
|
const TRUTHY_VALUES = ["1", "true", "yes"];
|
|
17
17
|
const DISABLED_VALUES = ["0", "false", "off"];
|
|
18
|
-
const PINNED_BACKEND_VERSION = "0.25.
|
|
18
|
+
const PINNED_BACKEND_VERSION = "0.25.1";
|
|
19
19
|
const COMPAT_CHECK_DELAY_MS = 1500;
|
|
20
20
|
const COMPAT_CHECK_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
21
21
|
|
|
@@ -203,7 +203,7 @@ const buildPackArgs = ({ query, filesModified, injectLimit, injectTokenBudget })
|
|
|
203
203
|
.slice(-8)
|
|
204
204
|
.map((value) => String(value || "").trim())
|
|
205
205
|
.filter(Boolean);
|
|
206
|
-
const args = ["pack", query];
|
|
206
|
+
const args = ["pack", query, "--json"];
|
|
207
207
|
if (injectLimit !== null && Number.isFinite(injectLimit) && injectLimit > 0) {
|
|
208
208
|
args.push("--limit", String(injectLimit));
|
|
209
209
|
}
|
|
@@ -233,7 +233,8 @@ const applyInjectedContextToOutput = async ({
|
|
|
233
233
|
|
|
234
234
|
const query = resolveInjectQuery();
|
|
235
235
|
const cached = injectedSessions.get(input.sessionID);
|
|
236
|
-
|
|
236
|
+
const queryMatchesCache = cached?.query === query;
|
|
237
|
+
let contextText = queryMatchesCache ? cached?.text || "" : "";
|
|
237
238
|
|
|
238
239
|
if (!contextText || cached?.query !== query) {
|
|
239
240
|
const injected = await buildInjectedContext(query);
|
|
@@ -1448,6 +1449,18 @@ export const OpencodeMemPlugin = async ({
|
|
|
1448
1449
|
filesModified: sessionContext.filesModified,
|
|
1449
1450
|
});
|
|
1450
1451
|
|
|
1452
|
+
const describeInjectQuery = (query) => {
|
|
1453
|
+
const safeQuery = redactLog((query || "").trim(), 240);
|
|
1454
|
+
const projectName = resolveProjectName(project, cwd) || "";
|
|
1455
|
+
return {
|
|
1456
|
+
safeQuery,
|
|
1457
|
+
firstPromptLen: sessionContext.firstPrompt?.trim()?.length || 0,
|
|
1458
|
+
lastPromptLen: lastPromptText?.trim()?.length || 0,
|
|
1459
|
+
projectName,
|
|
1460
|
+
filesModifiedCount: sessionContext.filesModified.size,
|
|
1461
|
+
};
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1451
1464
|
const parsePackText = (stdout) => {
|
|
1452
1465
|
if (!stdout || !stdout.trim()) {
|
|
1453
1466
|
return "";
|
|
@@ -1500,9 +1513,27 @@ export const OpencodeMemPlugin = async ({
|
|
|
1500
1513
|
}
|
|
1501
1514
|
const packText = parsePackText(result.stdout);
|
|
1502
1515
|
if (!packText) {
|
|
1516
|
+
if (debug) {
|
|
1517
|
+
const { safeQuery, firstPromptLen, lastPromptLen, projectName, filesModifiedCount } =
|
|
1518
|
+
describeInjectQuery(query);
|
|
1519
|
+
await logLine(
|
|
1520
|
+
`inject.pack.empty query_len=${query ? query.length : 0} query=${JSON.stringify(safeQuery)} first_prompt_len=${firstPromptLen} last_prompt_len=${lastPromptLen} project=${JSON.stringify(projectName)} files_modified=${filesModifiedCount} stdout=${JSON.stringify(redactLog((result.stdout || "").trim(), 240))}`
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1503
1523
|
return "";
|
|
1504
1524
|
}
|
|
1505
1525
|
const metrics = parsePackMetrics(result.stdout);
|
|
1526
|
+
if (debug) {
|
|
1527
|
+
const itemCount = Number.isFinite(Number(metrics?.items))
|
|
1528
|
+
? Number(metrics.items)
|
|
1529
|
+
: 0;
|
|
1530
|
+
const packTokens = Number.isFinite(Number(metrics?.pack_tokens))
|
|
1531
|
+
? Number(metrics.pack_tokens)
|
|
1532
|
+
: 0;
|
|
1533
|
+
await logLine(
|
|
1534
|
+
`inject.pack.ok query_len=${query ? query.length : 0} items=${itemCount} pack_tokens=${packTokens}`
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1506
1537
|
if (metrics) {
|
|
1507
1538
|
return {
|
|
1508
1539
|
text: `[codemem context]\n${packText}`,
|
|
@@ -1743,13 +1774,15 @@ export const OpencodeMemPlugin = async ({
|
|
|
1743
1774
|
"experimental.chat.system.transform": async (input, output) => {
|
|
1744
1775
|
const query = resolveInjectQuery();
|
|
1745
1776
|
if (debug) {
|
|
1777
|
+
const { safeQuery, firstPromptLen, lastPromptLen, projectName, filesModifiedCount } =
|
|
1778
|
+
describeInjectQuery(query);
|
|
1746
1779
|
await logLine(
|
|
1747
1780
|
`inject.transform sessionID=${input.sessionID} query_len=${
|
|
1748
1781
|
query ? query.length : 0
|
|
1749
|
-
} tui_toast=${Boolean(client.tui?.showToast)}`
|
|
1782
|
+
} inject_enabled=${injectEnabled} tui_toast=${Boolean(client.tui?.showToast)} query=${JSON.stringify(safeQuery)} first_prompt_len=${firstPromptLen} last_prompt_len=${lastPromptLen} project=${JSON.stringify(projectName)} files_modified=${filesModifiedCount}`
|
|
1750
1783
|
);
|
|
1751
1784
|
}
|
|
1752
|
-
await applyInjectedContextToOutput({
|
|
1785
|
+
const applied = await applyInjectedContextToOutput({
|
|
1753
1786
|
injectEnabled,
|
|
1754
1787
|
input,
|
|
1755
1788
|
output,
|
|
@@ -1768,6 +1801,11 @@ export const OpencodeMemPlugin = async ({
|
|
|
1768
1801
|
resolveInjectQuery,
|
|
1769
1802
|
buildInjectedContext,
|
|
1770
1803
|
});
|
|
1804
|
+
if (debug) {
|
|
1805
|
+
await logLine(
|
|
1806
|
+
`inject.transform.result sessionID=${input.sessionID} applied=${Boolean(applied)} system_entries=${Array.isArray(output.system) ? output.system.length : 0}`
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1771
1809
|
},
|
|
1772
1810
|
event: async ({ event }) => {
|
|
1773
1811
|
const eventType = event?.type || "unknown";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./codemem.js";
|