akm-opencode 0.9.20202609302253 → 0.9.20202610010250
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 +2 -2
- package/dist/index.js +89 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ The plugin subscribes to OpenCode lifecycle events. Hook failures are logged thr
|
|
|
45
45
|
| --- | --- |
|
|
46
46
|
| `session.created` | Warms local data in the background, and prepares hints, an active-workflow summary, and curated context for the session. |
|
|
47
47
|
| `session.updated` | Backfills hints and the workflow summary for a session the plugin has not prepared yet. It does not re-run session-created work. |
|
|
48
|
-
| `chat.message` | Records feedback/memory intent, captures corrections, guardrails, preferences, explicit memories, and positive feedback, and can schedule non-blocking curation. High-confidence durable signals submit asynchronous AKM proposals; recurring task intent across distinct sessions can submit a skill proposal. |
|
|
48
|
+
| `chat.message` | Records feedback/memory intent, captures corrections, guardrails, preferences, explicit memories, and positive feedback, and can schedule non-blocking curation. High-confidence durable signals submit asynchronous AKM proposals; recurring task intent across distinct sessions can submit a skill proposal. Only the text you typed counts; the synthetic parts OpenCode adds (an attached file's contents, the Read call that fetched it) are ignored. |
|
|
49
49
|
| `experimental.chat.system.transform` | Injects the AKM guidance and cached curated context into the system prompt. The host rebuilds the system prompt on every request, so these blocks are re-injected each turn — including after a compaction — rather than once per session. |
|
|
50
50
|
| `tool.execute.before` | The format-declaration write gate (`AKM_WRITE_GATE`, `observe` by default). Blocks the first `edit`/`write` to an existing file that declares a format your bundle documents and hands the model the ref to read. Once per file per session, released unconditionally on the retry. |
|
|
51
51
|
| `tool.execute.after` | Tracks concepts used by AKM tools and checkpoints session observations. It also records what a file the session `read` declares about its own format, which is what the write gate above keys on. `write` is deliberately not a source: a file the session created is not one it needs the bundle to explain. The create itself is recorded on the write's `tool.execute.before` pass, so a later read-back of that file cannot re-arm the gate. |
|
|
@@ -56,7 +56,7 @@ The plugin subscribes to OpenCode lifecycle events. Hook failures are logged thr
|
|
|
56
56
|
|
|
57
57
|
The session observation buffer that retrospective feedback reads from survives every non-terminal event: it is bounded by `AKM_SESSION_BUFFER_MAX_ENTRIES` and dropped only on `session.deleted`. Discarding it at `session.idle` would empty it between turns, so "thanks, that worked" would credit nothing in exactly the sessions that used the most assets.
|
|
58
58
|
|
|
59
|
-
Automatic feedback skips references that AKM reports as ineligible, and no `akm_*` tool call submits feedback on its own. A *successful* `akm_show` / `akm_search` / `akm_curate` only inspected a concept, which is not evidence that it helped, so on OpenCode the positive signal comes from a retrospective confirmation instead. A *failed* call (an error result, a timeout, an ambiguous ref) is not feedback on the asset either, and is only logged. Same rules as the Claude plugin, which applies them to the `akm` subcommand of a Bash invocation.
|
|
59
|
+
Automatic feedback skips references that AKM reports as ineligible, and no `akm_*` tool call submits feedback on its own. A *successful* `akm_show` / `akm_search` / `akm_curate` only inspected a concept, which is not evidence that it helped, so on OpenCode the positive signal comes from a retrospective confirmation instead. A *failed* call (an error result, a timeout, an ambiguous ref) is not feedback on the asset either, and is only logged: its ref is not remembered as used, so a later "thanks, that worked" does not credit it and a later correction does not blame it. Same rules as the Claude plugin, which applies them to the `akm` subcommand of a Bash invocation.
|
|
60
60
|
|
|
61
61
|
### Automatic learning proposals
|
|
62
62
|
|
package/dist/index.js
CHANGED
|
@@ -119,6 +119,7 @@ function shouldSubmitAutomaticFeedback(signal) {
|
|
|
119
119
|
|
|
120
120
|
// ../claude/shared/memory-events.ts
|
|
121
121
|
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
|
122
|
+
import { homedir } from "os";
|
|
122
123
|
import path from "path";
|
|
123
124
|
|
|
124
125
|
// ../claude/shared/redaction.ts
|
|
@@ -376,7 +377,7 @@ function rotateIfOversized(filePath) {
|
|
|
376
377
|
|
|
377
378
|
// ../claude/shared/memory-events.ts
|
|
378
379
|
function getHarnessStateDir(harness) {
|
|
379
|
-
const root = process.env.XDG_STATE_HOME ?? path.join(
|
|
380
|
+
const root = process.env.XDG_STATE_HOME ?? path.join(homedir(), ".local", "state");
|
|
380
381
|
return path.join(root, harness === "claude-code" ? "akm-claude" : "akm-opencode");
|
|
381
382
|
}
|
|
382
383
|
function getEventLogPath(harness) {
|
|
@@ -1008,7 +1009,45 @@ function isFile(file) {
|
|
|
1008
1009
|
return false;
|
|
1009
1010
|
}
|
|
1010
1011
|
}
|
|
1012
|
+
var SCRIPT_EXTENSIONS = new Set([
|
|
1013
|
+
".sh",
|
|
1014
|
+
".ts",
|
|
1015
|
+
".js",
|
|
1016
|
+
".ps1",
|
|
1017
|
+
".cmd",
|
|
1018
|
+
".bat",
|
|
1019
|
+
".py",
|
|
1020
|
+
".rb",
|
|
1021
|
+
".go",
|
|
1022
|
+
".pl",
|
|
1023
|
+
".php",
|
|
1024
|
+
".lua",
|
|
1025
|
+
".r",
|
|
1026
|
+
".swift",
|
|
1027
|
+
".kt",
|
|
1028
|
+
".kts"
|
|
1029
|
+
]);
|
|
1030
|
+
function markdownFile(directPath) {
|
|
1031
|
+
return isFile(`${directPath}.md`) || directPath.endsWith(".md") && isFile(directPath);
|
|
1032
|
+
}
|
|
1033
|
+
function isAsset(type, directPath) {
|
|
1034
|
+
if (type === "skills")
|
|
1035
|
+
return isFile(path3.join(directPath, "SKILL.md"));
|
|
1036
|
+
if (type === "scripts")
|
|
1037
|
+
return SCRIPT_EXTENSIONS.has(path3.extname(directPath).toLowerCase()) && isFile(directPath);
|
|
1038
|
+
if (type === "secrets")
|
|
1039
|
+
return !/\.(lock|sensitive)$/.test(directPath) && isFile(directPath);
|
|
1040
|
+
if (type === "tasks")
|
|
1041
|
+
return isFile(`${directPath}.yml`);
|
|
1042
|
+
if (type === "env") {
|
|
1043
|
+
return isFile(`${directPath}.env`) || path3.basename(directPath) === "default" && isFile(path3.join(path3.dirname(directPath), ".env"));
|
|
1044
|
+
}
|
|
1045
|
+
return markdownFile(directPath) || type === "workflows" && isFile(`${directPath}.yml`);
|
|
1046
|
+
}
|
|
1047
|
+
var OUTSIDE_THEIR_DIRECTORY = new Set(["scripts", "agents", "commands", "facts", "instructions", "knowledge", "lessons", "memories", "sessions"]);
|
|
1011
1048
|
function conceptExistsInAnyBundle(conceptId, bundleRoots) {
|
|
1049
|
+
const type = conceptId.split("/", 1)[0];
|
|
1050
|
+
const rest = conceptId.slice(type.length + 1);
|
|
1012
1051
|
for (const root of bundleRoots) {
|
|
1013
1052
|
if (!root)
|
|
1014
1053
|
continue;
|
|
@@ -1016,12 +1055,12 @@ function conceptExistsInAnyBundle(conceptId, bundleRoots) {
|
|
|
1016
1055
|
const directPath = path3.resolve(resolvedRoot, conceptId);
|
|
1017
1056
|
if (directPath !== resolvedRoot && !directPath.startsWith(`${resolvedRoot}${path3.sep}`))
|
|
1018
1057
|
continue;
|
|
1019
|
-
if (
|
|
1020
|
-
return true;
|
|
1021
|
-
if (isFile(path3.join(directPath, "SKILL.md")))
|
|
1022
|
-
return true;
|
|
1023
|
-
if (conceptId.startsWith("memories/") && isFile(`${directPath}.derived.md`))
|
|
1058
|
+
if (isAsset(type, directPath))
|
|
1024
1059
|
return true;
|
|
1060
|
+
if (OUTSIDE_THEIR_DIRECTORY.has(type) && rest.includes("/") && !rest.startsWith(`${type}/`)) {
|
|
1061
|
+
if (isAsset(type, path3.resolve(resolvedRoot, rest)))
|
|
1062
|
+
return true;
|
|
1063
|
+
}
|
|
1025
1064
|
}
|
|
1026
1065
|
return false;
|
|
1027
1066
|
}
|
|
@@ -1042,14 +1081,40 @@ function validateRefCandidates(candidates, bundleRoots) {
|
|
|
1042
1081
|
|
|
1043
1082
|
// ../claude/shared/recall-policy.ts
|
|
1044
1083
|
var STASH_BOILERPLATE = "This is an **AKM stash** \u2014 a structured knowledge repository that stores reusable";
|
|
1084
|
+
var COMPACTION_CONTINUATION = "This session is being continued from a previous conversation";
|
|
1085
|
+
var TAG = /<(\/?)([A-Za-z][\w:.-]*)(?:\s[^<>]*)?>/g;
|
|
1086
|
+
function leadingBlockEnd(text) {
|
|
1087
|
+
const tags = new RegExp(TAG);
|
|
1088
|
+
let name;
|
|
1089
|
+
let depth = 0;
|
|
1090
|
+
for (let tag = tags.exec(text);tag; tag = tags.exec(text)) {
|
|
1091
|
+
if (name === undefined) {
|
|
1092
|
+
if (tag.index !== 0 || tag[1])
|
|
1093
|
+
return -1;
|
|
1094
|
+
name = tag[2];
|
|
1095
|
+
} else if (tag[2] !== name)
|
|
1096
|
+
continue;
|
|
1097
|
+
depth += tag[1] ? -1 : 1;
|
|
1098
|
+
if (depth === 0)
|
|
1099
|
+
return tag.index + tag[0].length;
|
|
1100
|
+
}
|
|
1101
|
+
return -1;
|
|
1102
|
+
}
|
|
1103
|
+
function stripLeadingEnvelopes(text) {
|
|
1104
|
+
let rest = text.trimStart();
|
|
1105
|
+
for (let end = leadingBlockEnd(rest);end > 0; end = leadingBlockEnd(rest))
|
|
1106
|
+
rest = rest.slice(end).trimStart();
|
|
1107
|
+
return rest;
|
|
1108
|
+
}
|
|
1045
1109
|
function isNonTaskPrompt(text) {
|
|
1046
|
-
const
|
|
1047
|
-
if (
|
|
1110
|
+
const typed = stripLeadingEnvelopes(text);
|
|
1111
|
+
if (typed === STASH_BOILERPLATE || typed.startsWith(COMPACTION_CONTINUATION))
|
|
1048
1112
|
return true;
|
|
1049
|
-
return
|
|
1113
|
+
return typed === "" ? text.trim() !== "" : typed.startsWith("<") && typed.includes("</");
|
|
1050
1114
|
}
|
|
1051
1115
|
function shouldRecall(prompt, options) {
|
|
1052
|
-
const
|
|
1116
|
+
const trimmed = prompt.trim();
|
|
1117
|
+
const text = stripLeadingEnvelopes(trimmed) || trimmed;
|
|
1053
1118
|
const lower = text.toLowerCase();
|
|
1054
1119
|
const scopeHints = [];
|
|
1055
1120
|
if (!text)
|
|
@@ -2927,7 +2992,7 @@ function extractText(parts) {
|
|
|
2927
2992
|
return "";
|
|
2928
2993
|
const segments = [];
|
|
2929
2994
|
for (const part of parts) {
|
|
2930
|
-
if (part?.type === "text" && typeof part.text === "string") {
|
|
2995
|
+
if (part?.type === "text" && !part.synthetic && typeof part.text === "string") {
|
|
2931
2996
|
const raw = part.text.trim();
|
|
2932
2997
|
let text = raw;
|
|
2933
2998
|
if (raw.startsWith('"') && raw.endsWith('"')) {
|
|
@@ -3268,6 +3333,7 @@ ${hint}` : hint;
|
|
|
3268
3333
|
const candidateRefs = [...new Set([...allArgRefs, ...allOutputRefs])];
|
|
3269
3334
|
const parsedForRefs = isAkmTool ? parseToolOutput(output.output) : null;
|
|
3270
3335
|
const allRefs = isAkmTool && parsedForRefs ? extractToolRefs(input.tool, input.args, parsedForRefs) : validateRefCandidates(candidateRefs, [await getAkmBundleDir(logClient) ?? ""]);
|
|
3336
|
+
const failedCall = classifyToolFeedback(parsedForRefs) === "negative";
|
|
3271
3337
|
if (allRefs.length > 0) {
|
|
3272
3338
|
writeStructuredEvent({
|
|
3273
3339
|
event: "tool_ref_observed",
|
|
@@ -3277,13 +3343,15 @@ ${hint}` : hint;
|
|
|
3277
3343
|
refs: allRefs,
|
|
3278
3344
|
outcome: { status: "ok" }
|
|
3279
3345
|
});
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3346
|
+
if (!failedCall) {
|
|
3347
|
+
for (const ref of allRefs) {
|
|
3348
|
+
addBufferEntry(input.sessionID, {
|
|
3349
|
+
kind: "tool-ref",
|
|
3350
|
+
toolName: input.tool,
|
|
3351
|
+
ref,
|
|
3352
|
+
status: "unknown"
|
|
3353
|
+
});
|
|
3354
|
+
}
|
|
3287
3355
|
}
|
|
3288
3356
|
}
|
|
3289
3357
|
if (input.tool === "read") {
|
|
@@ -3320,7 +3388,8 @@ ${hint}` : hint;
|
|
|
3320
3388
|
if ((input.tool === "akm_show" || input.tool === "akm_curate") && feedback !== "negative") {
|
|
3321
3389
|
noteShownRefs(input.sessionID, toolRefs);
|
|
3322
3390
|
}
|
|
3323
|
-
|
|
3391
|
+
if (!failedCall)
|
|
3392
|
+
noteRecentRefs(input.sessionID, toolRefs);
|
|
3324
3393
|
writeStructuredEvent({
|
|
3325
3394
|
event: "tool_observation",
|
|
3326
3395
|
sessionId: input.sessionID,
|
|
@@ -3329,7 +3398,7 @@ ${hint}` : hint;
|
|
|
3329
3398
|
refs: toolRefs,
|
|
3330
3399
|
outcome: { status: feedback === "negative" ? "failed" : "ok" }
|
|
3331
3400
|
});
|
|
3332
|
-
if (toolRefs.length > 0 && input.sessionID) {
|
|
3401
|
+
if (toolRefs.length > 0 && input.sessionID && !failedCall) {
|
|
3333
3402
|
for (const ref of toolRefs) {
|
|
3334
3403
|
addBufferEntry(input.sessionID, {
|
|
3335
3404
|
kind: "tool-ref",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akm-opencode",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.20202610010250",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenCode plugin for AKM with discovery tools, feedback, memory, and automatic learning proposals from corrections and recurring workflows.",
|
|
6
6
|
"keywords": [
|