johns-harness 2026.11.23 → 2026.11.29
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/CHANGELOG.md +14 -0
- package/dist/update-command.js +89 -0
- package/docs/PATCHES.md +26 -0
- package/node_modules/mr-memory/index.js +17 -1
- package/package.json +1 -1
- package/vendor/patched-deps/mr-memory/index.js +1852 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026.11.29
|
|
4
|
+
|
|
5
|
+
### MemoryRouter saves only the main chat
|
|
6
|
+
|
|
7
|
+
- **`mr-memory` no longer stores subagent, cron, hook or swarm-member turns (Family 100).** Its `agent_end` hook used to store the last user+assistant exchange of every run. The only guards were `isReadOnlyAgent` (agent-scoped) and the auto-consolidation session, and worker runs share the same agent id and workspace as the main chat, so neither could separate them.
|
|
8
|
+
- **Capture is now scoped to the primary session**, `agent:<id>:main`. `isNonPrimarySession(sessionKey)` decides it and `agent_end` returns before the vault key is resolved.
|
|
9
|
+
- **A `[cron:…]` prompt is no longer laundered into a user turn.** The noise check now runs on the raw text before `stripSystemPrefixes` deletes the only marker the cron pattern matches.
|
|
10
|
+
- **Reads are unchanged on purpose.** Subagents, crons, hooks and swarm members still receive vault context from both prompt hooks; only the write path is limited. `readOnlyAgents` and every other plugin feature keep working.
|
|
11
|
+
- **`/update` delivers the fix to an existing installed copy.** An installed `<state>/extensions/mr-memory` stays authoritative over the bundled copy and `updateNpmInstalledPlugins` only reinstalls the pinned npm spec, so `/update` now ports these three edits into that copy in place after a successful install and before the restart. It keeps whatever else the copy carries (today: a hand-backported `readOnlyAgents` guard), writes a `.bak` first, is idempotent, and skips with a log line rather than guessing if the file has drifted.
|
|
12
|
+
- Also fills in the missed manifest flag: the installed copy's manifest now declares `kind: "memory"`, so the memory slot matches without a per-deployment edit.
|
|
13
|
+
- **Scope:** the bundled dependency patch, one `/update` step, its manifest flag, tests, verifier and docs. No model, channel, credential, tool-surface or default-model change; no global install, no restart.
|
|
14
|
+
- **Gates:** verifier **610 pass, 0 fail**; full suite **1,426 pass, 0 fail, 5 skip** (1,431 tests); Family 100 patcher replays `dist/update-command.js` byte for byte; packed-artifact and secret checks clean.
|
|
15
|
+
- **Rollback:** `npm i -g johns-harness@2026.11.23`.
|
|
16
|
+
|
|
3
17
|
## 2026.11.23
|
|
4
18
|
|
|
5
19
|
### The OpenAI Whisper API is the standard audio transcription method
|
package/dist/update-command.js
CHANGED
|
@@ -13,6 +13,7 @@ import { installVolumeRuntime } from "./volume-update.js";
|
|
|
13
13
|
import fs from "node:fs";
|
|
14
14
|
import fsp from "node:fs/promises";
|
|
15
15
|
import path from "node:path";
|
|
16
|
+
import os from "node:os"; // JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100
|
|
16
17
|
import { fileURLToPath } from "node:url";
|
|
17
18
|
|
|
18
19
|
const PACKAGE = "johns-harness";
|
|
@@ -126,6 +127,86 @@ export async function fetchLatestVersion(fetchImpl = fetch, timeoutMs = 8000) {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
// JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100
|
|
131
|
+
// A state-dir install (plugins.installs -> <state>/extensions/<id>) stays
|
|
132
|
+
// authoritative over the bundled copy, and `updateNpmInstalledPlugins` only ever
|
|
133
|
+
// reinstalls the exact pinned npm spec. So a fixed bundled mr-memory would never
|
|
134
|
+
// reach an existing state-dir copy. `/update` therefore ports this one behaviour
|
|
135
|
+
// change into the installed copy in place, keeping whatever else that copy
|
|
136
|
+
// carries (its hand-backported readOnlyAgents support, local edits and layout).
|
|
137
|
+
export const PRIMARY_SESSION_CAPTURE_MARKER = "JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100";
|
|
138
|
+
const MEMORY_EXTENSION_ID = "mr-memory";
|
|
139
|
+
|
|
140
|
+
const PRIMARY_SESSION_HELPER = `/** JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100: only the primary chat session (agent:<id>:main) is a real
|
|
141
|
+
* conversation with the user. Subagent, cron, hook and swarm-member runs share
|
|
142
|
+
* the same agent id and workspace, so an agent-scoped filter cannot separate
|
|
143
|
+
* them. Retrieval/injection are untouched: every session still reads the
|
|
144
|
+
* vault, only the write path is limited. */
|
|
145
|
+
export function isNonPrimarySession(sessionKey) {
|
|
146
|
+
const k = typeof sessionKey === "string" ? sessionKey.trim().toLowerCase() : "";
|
|
147
|
+
if (!k)
|
|
148
|
+
return false;
|
|
149
|
+
return !/^agent:[a-z0-9._-]+:main$/.test(k);
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
/** The three edits, anchored on code rather than formatting so a reformatted or
|
|
154
|
+
* hand-edited copy is patched instead of skipped. Every anchor must appear
|
|
155
|
+
* exactly once; anything else means drift and we refuse rather than guess. */
|
|
156
|
+
export function primarySessionCaptureEdits(text) {
|
|
157
|
+
const count = (needle) => text.split(needle).length - 1;
|
|
158
|
+
const noiseAnchor = "function isSystemNoise(text) {";
|
|
159
|
+
const stripAnchor = "const taskText = stripSystemPrefixes(userText);";
|
|
160
|
+
const handlerRe = /api\.on\(\s*"agent_end"\s*,\s*async\s*\(event,\s*ctx\)\s*=>\s*\{/;
|
|
161
|
+
if (!handlerRe.test(text)) return { ok: false, reason: "agent_end handler not found" };
|
|
162
|
+
if (count(noiseAnchor) !== 1) return { ok: false, reason: `isSystemNoise anchor x${count(noiseAnchor)}` };
|
|
163
|
+
if (count(stripAnchor) !== 1) return { ok: false, reason: `taskText anchor x${count(stripAnchor)}` };
|
|
164
|
+
// Insert the helper first, then re-locate the handler in the edited text so the
|
|
165
|
+
// index stays correct.
|
|
166
|
+
let next = text.replace(noiseAnchor, PRIMARY_SESSION_HELPER + noiseAnchor);
|
|
167
|
+
const handler = handlerRe.exec(next);
|
|
168
|
+
if (!handler) return { ok: false, reason: "agent_end handler lost after helper insert" };
|
|
169
|
+
const guard = handler[0] + `
|
|
170
|
+
// JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100: store only the primary chat session.
|
|
171
|
+
if (isNonPrimarySession(ctx?.sessionKey))
|
|
172
|
+
return;`;
|
|
173
|
+
next = next.slice(0, handler.index) + guard + next.slice(handler.index + handler[0].length);
|
|
174
|
+
next = next.replace(stripAnchor,
|
|
175
|
+
`// JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100: a [cron:...] prompt is noise; stripping the prefix first
|
|
176
|
+
// would delete the only marker and store it as a user turn.
|
|
177
|
+
const taskText = isSystemNoise(userText) ? "" : stripSystemPrefixes(userText);`);
|
|
178
|
+
return { ok: true, text: next };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The installed copy predates the `kind` field the bundled manifest carries, so
|
|
182
|
+
* the memory slot is only satisfied by the plugin's own export. Additive fix. */
|
|
183
|
+
export function ensureMemoryKind(dir, { dryRun = false } = {}) {
|
|
184
|
+
const manifest = path.join(dir, "johnness.plugin.json");
|
|
185
|
+
let parsed;
|
|
186
|
+
try { parsed = JSON.parse(fs.readFileSync(manifest, "utf8")); } catch { return "absent"; }
|
|
187
|
+
if (parsed?.kind === "memory") return "current";
|
|
188
|
+
if (!dryRun) fs.writeFileSync(manifest, `${JSON.stringify({ ...parsed, kind: "memory" }, null, 2)}\n`);
|
|
189
|
+
return dryRun ? "would-set" : "set";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Port the primary-session capture fix into <state>/extensions/mr-memory. */
|
|
193
|
+
export function applyPrimarySessionCaptureFix({ env = process.env, dryRun = false } = {}) {
|
|
194
|
+
const stateDir = env.JOHNNESS_STATE_DIR?.trim() ? path.resolve(env.JOHNNESS_STATE_DIR) : path.join(os.homedir(), ".johnness");
|
|
195
|
+
const dir = path.join(stateDir, "extensions", MEMORY_EXTENSION_ID);
|
|
196
|
+
const file = path.join(dir, "index.js");
|
|
197
|
+
const kind = ensureMemoryKind(dir, { dryRun });
|
|
198
|
+
let text;
|
|
199
|
+
try { text = fs.readFileSync(file, "utf8"); } catch { return { status: "absent", file, kind }; }
|
|
200
|
+
if (text.includes(PRIMARY_SESSION_CAPTURE_MARKER)) return { status: "current", file, kind };
|
|
201
|
+
const edits = primarySessionCaptureEdits(text);
|
|
202
|
+
if (!edits.ok) return { status: "skipped", file, reason: edits.reason, kind };
|
|
203
|
+
if (!dryRun) {
|
|
204
|
+
try { fs.writeFileSync(`${file}.pre-${PRIMARY_SESSION_CAPTURE_MARKER}.bak`, text); } catch {}
|
|
205
|
+
fs.writeFileSync(file, edits.text);
|
|
206
|
+
}
|
|
207
|
+
return { status: dryRun ? "would-patch" : "patched", file, kind };
|
|
208
|
+
}
|
|
209
|
+
|
|
129
210
|
const SECRET_RE = /(npm_[A-Za-z0-9]{20,}|Bearer\s+\S+|_authToken\s*=\s*\S+|[A-Za-z0-9_-]{40,})/g;
|
|
130
211
|
export function redactTail(text, lines = 5) {
|
|
131
212
|
const rows = String(text ?? "").replace(SECRET_RE, "<redacted>").split(/\r?\n/).filter((l) => l.trim());
|
|
@@ -265,6 +346,13 @@ export async function handleUpdateCommand(params, allowTextCommands, { routeRepl
|
|
|
265
346
|
await deliver(`Update failed (${result.target.mode} prefix ${result.target.prefix ?? "unknown"}).\n${result.tail}\nFix by hand: ${result.manual}`);
|
|
266
347
|
return;
|
|
267
348
|
}
|
|
349
|
+
let captureFix = null;
|
|
350
|
+
try {
|
|
351
|
+
captureFix = (deps.applyPrimarySessionCaptureFix ?? applyPrimarySessionCaptureFix)({ env });
|
|
352
|
+
} catch (error) {
|
|
353
|
+
log(`[update] memory capture fix skipped: ${error?.message ?? error}`);
|
|
354
|
+
}
|
|
355
|
+
if (captureFix?.status === "skipped") log(`[update] memory capture fix skipped: ${captureFix.reason} (${captureFix.file})`);
|
|
268
356
|
if (typeof deps.writeRestartSentinel === "function") {
|
|
269
357
|
const delivery = typeof deps.extractDeliveryInfo === "function" ? deps.extractDeliveryInfo(params.sessionKey) : {};
|
|
270
358
|
try {
|
|
@@ -281,6 +369,7 @@ export async function handleUpdateCommand(params, allowTextCommands, { routeRepl
|
|
|
281
369
|
} catch {}
|
|
282
370
|
}
|
|
283
371
|
const how = await restartIntoUpdate({ target: result.target, deps, log });
|
|
372
|
+
if (captureFix?.status === "patched") await deliver("MemoryRouter memory: capture is now limited to the main chat session, so subagent, cron and swarm runs no longer write memories.");
|
|
284
373
|
const restartText = how === "supervisor"
|
|
285
374
|
? "Restarting through the supervisor; the entrypoint will start the new runtime."
|
|
286
375
|
: how === "service" ? "Restarting the gateway service." : how === "gateway" ? "Restarting the gateway." : "Restart the gateway to finish (johnness gateway restart).";
|
package/docs/PATCHES.md
CHANGED
|
@@ -3337,3 +3337,29 @@ Rollback: `npm i -g johns-harness@2026.11.9`.
|
|
|
3337
3337
|
**Tests:** `tests/whisper-api-99.test.mjs` (8): Whisper API chosen with `OPENAI_API_KEY`; chosen with the key only in config; the real provider path posts `multipart/form-data` with `model=whisper-1` and `Bearer` auth to `/v1/audio/transcriptions` on a loopback server and returns its transcript; a `whisper`/`whisper-cli`/`sherpa-onnx-offline` binary on `PATH` is never selected and never executed; with no OpenAI auth the order falls to the next provider and still never runs a local CLI; an explicit CLI entry still wins; patcher replay is byte-identical and drift fails closed; all ten bundles carry the default with no local auto-selection. The loopback run is the real transport: no hosted OpenAI call is claimed.
|
|
3338
3338
|
|
|
3339
3339
|
**Rollback:** `npm i -g johns-harness@2026.11.20`.
|
|
3340
|
+
|
|
3341
|
+
## Family 100: MemoryRouter capture is limited to the primary chat session (2026-11-29)
|
|
3342
|
+
|
|
3343
|
+
**Marker:** `JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100`. **Release:** `johns-harness@2026.11.29`.
|
|
3344
|
+
|
|
3345
|
+
**Request:** "fix MemoryRouter capture so only the main chat is saved" - subagent, cron, hook and swarm-member runs were writing their working text into John's vault.
|
|
3346
|
+
|
|
3347
|
+
**Before:** `mr-memory`'s `agent_end` hook stored the last user+assistant exchange of **every** run the harness executes. Its only guards were `isReadOnlyAgent` (agent-scoped) and the auto-consolidation session, and subagents, cron jobs, hooks and swarm members all run as the same agent id in the same workspace, so neither guard could separate them. A second gap: `stripSystemPrefixes` removed the `^[cron:…]` marker *before* `isSystemNoise` ran, so a scheduled task prompt was stored as a clean user turn with its only identifying text deleted. The plugin's own README claimed the exclusion already existed.
|
|
3348
|
+
|
|
3349
|
+
**Change:**
|
|
3350
|
+
- `isNonPrimarySession(sessionKey)` (exported, next to `isReadOnlyAgent`) accepts only `agent:<id>:main`. `agent_end` returns before `resolveKey`, so nothing else reaches the vault.
|
|
3351
|
+
- The user-message noise check now runs on the raw text before the prefix strip (`isSystemNoise(userText) ? "" : stripSystemPrefixes(userText)`), so a `[cron:…]` prompt is skipped instead of being laundered.
|
|
3352
|
+
- **Reads are untouched.** Both `before_prompt_build` hooks and every `prepareMemory` call are unchanged: subagents and crons still receive vault context. Only the write path is scoped. `readOnlyAgents` behaviour and every other plugin feature are unchanged.
|
|
3353
|
+
|
|
3354
|
+
**Delivery, two halves.** Shipping a fixed bundled copy is not enough, because an existing `<state>/extensions/mr-memory` install stays authoritative over the bundled copy (family 59) and `updateNpmInstalledPlugins` only ever reinstalls the exact pinned npm spec, with its recorded integrity. So:
|
|
3355
|
+
- `vendor/patched-deps/mr-memory/index.js` carries the fixed 3.13.2 package (the same version `postinstall` already patches and `adaptPluginDirectory` already adapts), so every fresh install and upgrade gets it.
|
|
3356
|
+
- `dist/update-command.js` gains `applyPrimarySessionCaptureFix`, which `/update` runs **after a successful install and before the restart**. It ports the same three edits into `<state>/extensions/mr-memory/index.js` in place, keeping whatever else that copy carries (today: a hand-backported `readOnlyAgents` guard), writes a `.pre-JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100.bak` first, and is idempotent (the marker makes the second run a no-op). Anchors are code, not formatting, so a reformatted copy still patches; if an anchor is missing or ambiguous the step **skips and logs** - it never guesses and never fails the update.
|
|
3357
|
+
- The same `/update` step adds the missing `"kind": "memory"` to the installed copy's `johnness.plugin.json`, so the memory slot matches without a per-deployment manifest edit (the bundled `extensions/mr-memory/johnness.plugin.json` already declared it). The field is additive: the rest of the manifest is preserved and the adapter leaves the file alone.
|
|
3358
|
+
|
|
3359
|
+
**Tests:** `tests/primary-session-capture-100.test.mjs` (6): the vendored file carries three marked edits with the guard inside `agent_end` and nothing in the read path; the vendored package boots and, across five session keys, prepares five times but ingests once (`agent:main:main` only); `/update` patches a pristine 3.13.2 copy that carries an extra `readOnlyAgents` guard, keeps that guard, backs the file up and is idempotent; a drifted copy is skipped untouched and a missing copy is a no-op; the installed copy gains `kind: memory` with the rest of its manifest intact and the adapter is left with nothing to rewrite; and `/update` calls the fix between the install and the restart.
|
|
3360
|
+
|
|
3361
|
+
**Replay:** `scripts/patch-primary-session-capture-100.py` (`--check` read-only) replays the `dist/update-command.js` half from exact anchors, all-or-nothing; the 9.17 reconstruction in `tests/volume-update-safety.test.mjs` layers it after families 76/79/89/95 so the chain still reaches the current bytes. The vendored plugin file ships as an artifact beside `vendor/patched-deps/mr-memory/upload.js`.
|
|
3362
|
+
|
|
3363
|
+
**Verifier:** checks 100.1 to 100.7.
|
|
3364
|
+
|
|
3365
|
+
**Rollback:** `npm i -g johns-harness@2026.11.23`. A state-dir copy already patched by `/update` keeps working: the change is additive, and `<state>/extensions/mr-memory/index.js.pre-JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100.bak` restores the previous file byte for byte.
|
|
@@ -258,6 +258,17 @@ function sanitizeForIngest(text) {
|
|
|
258
258
|
return cleaned;
|
|
259
259
|
}
|
|
260
260
|
/** Check if a message is system noise that should not be stored */
|
|
261
|
+
/** JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100: only the primary chat session (agent:<id>:main) is a real
|
|
262
|
+
* conversation with the user. Subagent, cron, hook and swarm-member runs share
|
|
263
|
+
* the same agent id and workspace, so an agent-scoped filter cannot separate
|
|
264
|
+
* them. Retrieval/injection are untouched: every session still reads the
|
|
265
|
+
* vault, only the write path is limited. */
|
|
266
|
+
export function isNonPrimarySession(sessionKey) {
|
|
267
|
+
const k = typeof sessionKey === "string" ? sessionKey.trim().toLowerCase() : "";
|
|
268
|
+
if (!k)
|
|
269
|
+
return false;
|
|
270
|
+
return !/^agent:[a-z0-9._-]+:main$/.test(k);
|
|
271
|
+
}
|
|
261
272
|
function isSystemNoise(text) {
|
|
262
273
|
const trimmed = text.trim();
|
|
263
274
|
if (!trimmed)
|
|
@@ -926,6 +937,9 @@ If setting up MemoryRouter for another agent:
|
|
|
926
937
|
// Core: agent_end — store this turn's conversation
|
|
927
938
|
// ==================================================================
|
|
928
939
|
api.on("agent_end", async (event, ctx) => {
|
|
940
|
+
// JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100: store only the primary chat session.
|
|
941
|
+
if (isNonPrimarySession(ctx?.sessionKey))
|
|
942
|
+
return;
|
|
929
943
|
// Never store the auto-consolidation session's own chatter as memory.
|
|
930
944
|
if (isAutoConsolidationSession(ctx?.sessionKey))
|
|
931
945
|
return;
|
|
@@ -969,7 +983,9 @@ If setting up MemoryRouter for another agent:
|
|
|
969
983
|
userText = sanitizeForIngest(stripMediaReferences(userText));
|
|
970
984
|
if (userText) {
|
|
971
985
|
// Strip cron/system prefixes but keep the task content for storage
|
|
972
|
-
|
|
986
|
+
// JOHNNESS_PATCH_PRIMARY_SESSION_CAPTURE_100: a [cron:...] prompt is noise; stripping the prefix first
|
|
987
|
+
// would delete the only marker and store it as a user turn.
|
|
988
|
+
const taskText = isSystemNoise(userText) ? "" : stripSystemPrefixes(userText);
|
|
973
989
|
if (taskText && !isSystemNoise(taskText)) {
|
|
974
990
|
toStore.push({ role: "user", content: taskText });
|
|
975
991
|
}
|