fix(memory-feedback): worksheet prints only a shell-safe repo path
This commit is contained in:
1 parent
027e5b3c21
commit
9ec5617725
3 files changed
+21
-3
No files matched your search
@@ -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)
|
||||
})
|
||||
@@ -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)' : ''}`
|
||||
}
|
||||
|
||||
|
||||
@@ -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 "<path>" index` + entry bodies) for
|
||||
(`bash ~/.claude/lib/memory.sh -C '<path>' 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:
|
||||
`<item> <id> missed <cause>`, cause `no-overlap` (no
|
||||
content word shared with the prompt) or `overlap`. A searched item with no
|
||||
|
||||
Reference in new issue
Block a user