From 9ec561772541e26e8a423b1de9f2dbc4a01d382e Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 8 Nov 2026 18:09:14 +0100 Subject: [PATCH] fix(memory-feedback): worksheet prints only a shell-safe repo path --- lib/memory-feedback/reader.test.ts | 10 +++++++++- lib/memory-feedback/reader.ts | 11 ++++++++++- skills/memory-feedback/SKILL.md | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/memory-feedback/reader.test.ts b/lib/memory-feedback/reader.test.ts index a56788a..c10de45 100644 --- a/lib/memory-feedback/reader.test.ts +++ b/lib/memory-feedback/reader.test.ts @@ -5,7 +5,8 @@ import * as os from 'node:os' import * as path from 'node:path' import { slugOf } from './transcripts.ts' import { - apply, checkDir, population, readLogs, sample, storeFile, worksheet, + apply, checkDir, population, readLogs, safePath, sample, storeFile, + worksheet, type Paths, } from './reader.ts' @@ -173,3 +174,10 @@ test('R9: sample picks entry lines of the draft', () => { draft(work, '1\tBDR-001\trelevant\n1\t-\tchecked\n') expect(sample(work, 5)).toEqual(['1\tBDR-001\trelevant']) }) + +test('safePath keeps plain paths and withholds shell-active ones', () => { + const w = 'path withheld: unsafe characters' + expect(safePath('/home/u/repo.x')).toBe('/home/u/repo.x') + for (const bad of ['/tmp/$(id)', '/tmp/`id`', "/tmp/a'b", '/a/../b']) + expect(safePath(bad)).toBe(w) +}) diff --git a/lib/memory-feedback/reader.ts b/lib/memory-feedback/reader.ts index 673ba27..d26b81c 100644 --- a/lib/memory-feedback/reader.ts +++ b/lib/memory-feedback/reader.ts @@ -107,6 +107,15 @@ const ENTRY_ID = /^(BDR|LRN|BLK)-\d{3,}$/ const citedIn = (ids: string[], text: string) => ids.filter(id => ENTRY_ID.test(id) && new RegExp(`\\b${id}\\b`).test(text)) +const WITHHELD = 'path withheld: unsafe characters' + +/** `p` if it is safe to paste inside single quotes in a shell command. */ +export function safePath(p: string): string { + const ok = /^\/[A-Za-z0-9._\/ -]*$/.test(p) && + !p.split('/').includes('..') + return ok ? p : WITHHELD +} + /** An item header; the absolute repo path is for STEP 4 (scratchpad * only: labels.tsv keeps the tag). */ function header(b: Base, repo: string, lost: boolean): string { @@ -115,7 +124,7 @@ function header(b: Base, repo: string, lost: boolean): string { ` · cands ${b.cands ?? '-'} · ms ${b.ms ?? '-'}` + ` · s:${b.session.slice(0, 8)}` + ` · ${new Date(b.at).toISOString().slice(11, 16)} UTC` + - ` · ${b.root} (${repo})` + + ` · ${b.root} (${safePath(repo)})` + ` · ids ${ids}${lost ? ' · LOST (no transcript turn)' : ''}` } diff --git a/skills/memory-feedback/SKILL.md b/skills/memory-feedback/SKILL.md index aaf8641..50a749c 100644 --- a/skills/memory-feedback/SKILL.md +++ b/skills/memory-feedback/SKILL.md @@ -56,7 +56,8 @@ user confirms or flips each. Apply the flips to the draft (LRN-168). On up to 5 prompt items whose outcome is injected or none, search the registries of that item's repo, whose absolute path is in the item header -(`bash ~/.claude/lib/memory.sh -C "" index` + entry bodies) for +(`bash ~/.claude/lib/memory.sh -C '' index` + entry bodies; an item whose header shows +`path withheld` is skipped here) for live entries that bore on the ask and were not injected. Each one: ` missed `, cause `no-overlap` (no content word shared with the prompt) or `overlap`. A searched item with no