opencode-knowledge 0.6.0-next.1 → 0.6.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/dist/index.js +10 -79
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12631,53 +12631,7 @@ function tool(input) {
|
|
|
12631
12631
|
return input;
|
|
12632
12632
|
}
|
|
12633
12633
|
tool.schema = exports_external;
|
|
12634
|
-
// src/lib/logger.ts
|
|
12635
|
-
var ENV_CONSOLE_LOG = "OPENCODE_KNOWLEDGE_CONSOLE_LOG";
|
|
12636
|
-
var _client = null;
|
|
12637
|
-
function isConsoleLogEnabled() {
|
|
12638
|
-
const val = process.env[ENV_CONSOLE_LOG];
|
|
12639
|
-
return val === "1" || val?.toLowerCase() === "true";
|
|
12640
|
-
}
|
|
12641
|
-
function initLogger(client) {
|
|
12642
|
-
_client = client;
|
|
12643
|
-
}
|
|
12644
|
-
function createLogger(module) {
|
|
12645
|
-
const service = `opencode-knowledge.${module}`;
|
|
12646
|
-
const log = (level, message, extra) => {
|
|
12647
|
-
const app = _client?.app;
|
|
12648
|
-
if (app && typeof app.log === "function") {
|
|
12649
|
-
app.log({
|
|
12650
|
-
body: { service, level, message, extra }
|
|
12651
|
-
}).catch(() => {});
|
|
12652
|
-
} else if (isConsoleLogEnabled()) {
|
|
12653
|
-
const prefix = `[${service}]`;
|
|
12654
|
-
const args = extra ? [prefix, message, extra] : [prefix, message];
|
|
12655
|
-
switch (level) {
|
|
12656
|
-
case "debug":
|
|
12657
|
-
console.debug(...args);
|
|
12658
|
-
break;
|
|
12659
|
-
case "info":
|
|
12660
|
-
console.info(...args);
|
|
12661
|
-
break;
|
|
12662
|
-
case "warn":
|
|
12663
|
-
console.warn(...args);
|
|
12664
|
-
break;
|
|
12665
|
-
case "error":
|
|
12666
|
-
console.error(...args);
|
|
12667
|
-
break;
|
|
12668
|
-
}
|
|
12669
|
-
}
|
|
12670
|
-
};
|
|
12671
|
-
return {
|
|
12672
|
-
debug: (message, extra) => log("debug", message, extra),
|
|
12673
|
-
info: (message, extra) => log("info", message, extra),
|
|
12674
|
-
warn: (message, extra) => log("warn", message, extra),
|
|
12675
|
-
error: (message, extra) => log("error", message, extra)
|
|
12676
|
-
};
|
|
12677
|
-
}
|
|
12678
|
-
|
|
12679
12634
|
// src/lib/tools/search.ts
|
|
12680
|
-
var log = createLogger("tools.search");
|
|
12681
12635
|
var knowledgeSearchTool = tool({
|
|
12682
12636
|
description: "Search the knowledge vault for packages matching specific tags. Returns a ranked list of relevant knowledge packages with their metadata.",
|
|
12683
12637
|
args: {
|
|
@@ -12685,16 +12639,12 @@ var knowledgeSearchTool = tool({
|
|
|
12685
12639
|
},
|
|
12686
12640
|
async execute(args) {
|
|
12687
12641
|
const tagArray = args.tags.split(",").map((t) => t.trim()).filter(Boolean);
|
|
12688
|
-
log.debug("knowledge_search called", { tags: args.tags, parsedTags: tagArray });
|
|
12689
12642
|
if (tagArray.length === 0) {
|
|
12690
|
-
log.debug("knowledge_search - no tags provided");
|
|
12691
12643
|
return "No tags provided. Please specify at least one tag.";
|
|
12692
12644
|
}
|
|
12693
12645
|
try {
|
|
12694
|
-
log.debug("knowledge_search - calling searchKnowledge", { tagCount: tagArray.length });
|
|
12695
12646
|
const results = await searchKnowledge(tagArray);
|
|
12696
12647
|
loadCatalog();
|
|
12697
|
-
log.debug("searchKnowledge completed", { resultsCount: results.length });
|
|
12698
12648
|
if (results.length === 0) {
|
|
12699
12649
|
return `No knowledge packages found matching [${tagArray.join(", ")}]`;
|
|
12700
12650
|
}
|
|
@@ -12716,7 +12666,6 @@ _...and ${results.length - 10} more results_`;
|
|
|
12716
12666
|
}
|
|
12717
12667
|
return output;
|
|
12718
12668
|
} catch (error45) {
|
|
12719
|
-
log.error("knowledge_search error", { error: String(error45) });
|
|
12720
12669
|
return "Failed to search knowledge vault. Please try again.";
|
|
12721
12670
|
}
|
|
12722
12671
|
}
|
|
@@ -12851,21 +12800,17 @@ var knowledgeIndexTool = tool({
|
|
|
12851
12800
|
});
|
|
12852
12801
|
|
|
12853
12802
|
// src/index.ts
|
|
12854
|
-
var
|
|
12855
|
-
var opencodeKnowledge = async (input) => {
|
|
12856
|
-
initLogger(input.client);
|
|
12857
|
-
log2.info("Plugin initialized");
|
|
12803
|
+
var opencodeKnowledge = async () => {
|
|
12858
12804
|
return {
|
|
12859
12805
|
tool: {
|
|
12860
12806
|
knowledge_search: knowledgeSearchTool,
|
|
12861
12807
|
knowledge_load: knowledgeLoadTool,
|
|
12862
12808
|
knowledge_index: knowledgeIndexTool
|
|
12863
12809
|
},
|
|
12864
|
-
"chat.message": async (
|
|
12810
|
+
"chat.message": async (input, output) => {
|
|
12865
12811
|
try {
|
|
12866
|
-
const state = getSessionState(
|
|
12812
|
+
const state = getSessionState(input.sessionID);
|
|
12867
12813
|
if (state.isFirstPrompt) {
|
|
12868
|
-
log2.debug("First message in session", { sessionID: input2.sessionID });
|
|
12869
12814
|
const vaultExists = existsSync5(".opencode/knowledge/vault");
|
|
12870
12815
|
if (vaultExists) {
|
|
12871
12816
|
const categoryTagMap = buildCategoryTagMap();
|
|
@@ -12883,52 +12828,38 @@ var opencodeKnowledge = async (input) => {
|
|
|
12883
12828
|
type: "text",
|
|
12884
12829
|
text: knowledgePrompt,
|
|
12885
12830
|
id: `knowledge-${Date.now()}`,
|
|
12886
|
-
sessionID:
|
|
12887
|
-
messageID:
|
|
12831
|
+
sessionID: input.sessionID,
|
|
12832
|
+
messageID: input.messageID || ""
|
|
12888
12833
|
});
|
|
12889
|
-
log2.debug("Knowledge map injected");
|
|
12890
12834
|
}
|
|
12891
|
-
updateSessionState(
|
|
12835
|
+
updateSessionState(input.sessionID, {
|
|
12892
12836
|
isFirstPrompt: false,
|
|
12893
12837
|
categoriesShown: vaultExists
|
|
12894
12838
|
});
|
|
12895
|
-
log2.debug("First message processed");
|
|
12896
12839
|
}
|
|
12897
|
-
} catch (error45) {
|
|
12898
|
-
log2.error("Error in chat.message", { error: String(error45) });
|
|
12899
|
-
}
|
|
12840
|
+
} catch (error45) {}
|
|
12900
12841
|
},
|
|
12901
12842
|
event: async ({ event }) => {
|
|
12902
12843
|
try {
|
|
12903
12844
|
if (event.type === "session.created") {
|
|
12904
|
-
log2.debug("session.created event");
|
|
12905
12845
|
const eventData = event;
|
|
12906
12846
|
const sessionId = eventData.properties?.info?.id;
|
|
12907
12847
|
if (!sessionId) {
|
|
12908
|
-
const errorMsg =
|
|
12909
|
-
log2.error(errorMsg);
|
|
12848
|
+
const errorMsg = `\u274C Could not extract session ID from session.created event`;
|
|
12910
12849
|
throw new Error(errorMsg);
|
|
12911
12850
|
}
|
|
12912
|
-
log2.debug("Extracted session ID", { sessionId });
|
|
12913
12851
|
clearJsonl("session-state.jsonl");
|
|
12914
12852
|
clearJsonl("knowledge-reads.jsonl");
|
|
12915
12853
|
if (existsSync5(".opencode/knowledge/vault")) {
|
|
12916
|
-
log2.debug("Building knowledge index...");
|
|
12917
12854
|
try {
|
|
12918
12855
|
const catalog = buildKnowledgeCatalog();
|
|
12919
12856
|
saveCatalog(catalog);
|
|
12920
12857
|
const packagesCount = Object.values(catalog.knowledge).reduce((sum, packages) => sum + Object.keys(packages).length, 0);
|
|
12921
|
-
|
|
12922
|
-
} catch (error45) {
|
|
12923
|
-
log2.warn("Failed to build knowledge catalog", { error: String(error45) });
|
|
12924
|
-
}
|
|
12858
|
+
} catch (error45) {}
|
|
12925
12859
|
}
|
|
12926
12860
|
await createSessionState(sessionId);
|
|
12927
|
-
log2.debug("Session state created");
|
|
12928
12861
|
}
|
|
12929
|
-
} catch (error45) {
|
|
12930
|
-
log2.error("Error in event", { error: String(error45) });
|
|
12931
|
-
}
|
|
12862
|
+
} catch (error45) {}
|
|
12932
12863
|
}
|
|
12933
12864
|
};
|
|
12934
12865
|
};
|