matthewwong525/WongStack / .agents/plugins/memory
memory
Verifiedscripts/lib/documents/retrieve.mjs
View on GitHubimport { archiveReader } from '../store.mjs';
import { scanCorpus, verifyPassage } from './corpus.mjs';
import { interleaveSources, lexicalSearch } from './lexical.mjs';
// One path: scan the checkout, rank by words, then reopen each original before it is returned.
export async function retrieveDocuments(ctx, options, { archive, corpus, beforeVerify = () => {}, deadline = Date.now() + 16000 } = {}) {
archive ??= await archiveReader(ctx);
corpus ??= scanCorpus(ctx, { archive });
let lexicalPartial = false, reason = null;
const lookup = source => {
const hits = lexicalSearch(source, options.question, { ...options, deadline: Math.min(deadline + 1000, Date.now() + 1000) });
lexicalPartial ||= hits.partial;
return hits;
};
let rejected = 0;
const verified = interleaveSources(lookup(corpus), 32).map(candidate => {
const result = Date.now() >= deadline + 1500 ? null : verifyPassage(ctx, candidate, { beforeRead: beforeVerify, archive });
if (!result) rejected++; return result;
}).filter(Boolean);
// A race can invalidate a ranked hit; rescan for fresh keyword evidence once.
if (rejected) {
const fresh = scanCorpus(ctx, { archive, deadline: Math.min(deadline, Date.now() + 1500) });
verified.push(...interleaveSources(lookup(fresh), 32).map(hit => Date.now() >= deadline + 1500 ? null : verifyPassage(ctx, hit, { archive })).filter(Boolean));
reason = 'sources changed during lookup; refreshed keyword passages returned';
}
const documents = interleaveSources(verified, options.limit);
const partial = Boolean(corpus.omitted || lexicalPartial || rejected);
if (corpus.omitted && !reason) reason = 'document scan incomplete; some sources were not read';
if (lexicalPartial) reason = 'keyword ranking deadline reached; selected evidence is incomplete';
return { documents, documentSource: { state: partial ? 'partial' : documents.length ? 'ok' : 'empty', ...(reason ? { reason } : {}) } };
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |