delimit-cli 4.6.1 → 4.6.2
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 +60 -0
- package/bin/delimit-cli.js +42 -6
- package/bin/delimit-setup.js +7 -3
- package/gateway/ai/backends/gateway_core.py +6 -0
- package/gateway/ai/backends/memory_bridge.py +210 -53
- package/gateway/ai/backends/tools_infra.py +80 -0
- package/gateway/ai/backends/tools_real.py +53 -7
- package/gateway/ai/session_phoenix.py +121 -0
- package/gateway/core/diff_engine_v2.py +517 -54
- package/gateway/core/semver_classifier.py +52 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## [4.6.1] - 2026-05-22
|
|
5
|
+
|
|
6
|
+
Patch release: bundle hygiene + gateway sync carrying 7 upstream improvements.
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **`delimit setup hooks`** (LED-1207, #100): bypass broken `npx` fallback in
|
|
11
|
+
the pre-commit / pre-push hook generator. Fresh installs now produce hooks
|
|
12
|
+
that work even when the npm-resolved `delimit` shim is absent from `PATH`
|
|
13
|
+
(the fallback used to fail silently and produce no-op hooks).
|
|
14
|
+
|
|
15
|
+
### Improved (carried from the gateway)
|
|
16
|
+
|
|
17
|
+
These ship inside the gateway/ tree that bundles with delimit-cli. They are
|
|
18
|
+
in effect for anyone running the MCP server from a 4.6.1 install:
|
|
19
|
+
|
|
20
|
+
- **Cross-post dedup for Reddit drafts** — same-author + same-normalized-title
|
|
21
|
+
within a 7-day window dedupes manual re-submits across subreddits. Reddit's
|
|
22
|
+
native `crosspost_parent` field is *also* now captured: when set, an O(1)
|
|
23
|
+
fingerprint lookup catches the native cross-post case before the heuristic.
|
|
24
|
+
Two-layer coverage: native UI cross-posts (rare, O(1)) + manual re-submits
|
|
25
|
+
(common, O(N)).
|
|
26
|
+
|
|
27
|
+
- **Inline follow-up draft in reply-alert emails** — both Reddit reply-alerts
|
|
28
|
+
and GitHub outreach-reply-alerts now ship with a pre-composed, voice-matched
|
|
29
|
+
follow-up reply inside the email body. The original "Draft a follow-up
|
|
30
|
+
reply and post from mobile" sentinel remains as graceful degradation if
|
|
31
|
+
the drafter falls through. Designed for mobile copy-paste-and-post flow.
|
|
32
|
+
|
|
33
|
+
- **STR-195 binding founder decisions auto-injected into `delimit_deliberate`** —
|
|
34
|
+
when a panel question touches a venture name or decision keyword, matching
|
|
35
|
+
`feedback_*.md` memories surface as a `BINDING FOUNDER DECISIONS — CANNOT BE
|
|
36
|
+
RE-LITIGATED` block prepended to the panel context. Closed decisions stop
|
|
37
|
+
getting re-argued every deliberation. Memory walk is mtime-cached; portfolio
|
|
38
|
+
anchors can be extended via `~/.delimit/social_target_ventures.json` for
|
|
39
|
+
Pro users whose ventures aren't in the default delimit-portfolio set.
|
|
40
|
+
|
|
41
|
+
- **`delimit_security_audit` false-positive elimination** (LED-1278 (c)):
|
|
42
|
+
token-handling code (`const token = readCurrentToken()`,
|
|
43
|
+
`const token = (options.token || process.env.X)`) no longer trips the
|
|
44
|
+
`generic_secret` detector. Provider-specific detectors (aws_access_key,
|
|
45
|
+
github_token, jwt_token, sk-proj API key) remain fully armed. Verified
|
|
46
|
+
against a regression-guard test set including real AKIA, ghp_, JWT, and
|
|
47
|
+
bearer-token literal shapes.
|
|
48
|
+
|
|
49
|
+
### Chores
|
|
50
|
+
|
|
51
|
+
- **Excluded dev-only build scripts from the customer tarball** (#101):
|
|
52
|
+
`build-license-core.sh`, `security-check.sh`, and `test-license-core-so.sh`
|
|
53
|
+
are publish-time hooks invoked from `prepublishOnly`; they never ran on
|
|
54
|
+
customer installs. Removed from the published bundle (166 → 163 files,
|
|
55
|
+
~10KB unpacked) and closed the meta-leak where the scripts' own
|
|
56
|
+
leak-detection grep patterns contained the patterns they protected against.
|
|
57
|
+
|
|
58
|
+
### Documentation
|
|
59
|
+
|
|
60
|
+
- **Retract incorrect 4.6.0 'known issue' line** (LED-1403): the prior
|
|
61
|
+
CHANGELOG entry referenced a regression that did not actually ship.
|
|
62
|
+
|
|
63
|
+
|
|
4
64
|
## [4.6.0] - 2026-05-15
|
|
5
65
|
|
|
6
66
|
### Added — Codex CLI + Gemini CLI auto-trigger directives (LED-1399)
|
package/bin/delimit-cli.js
CHANGED
|
@@ -6916,12 +6916,43 @@ program
|
|
|
6916
6916
|
results = results.filter(m => m.tags && m.tags.some(t => t.includes(tagFilter)));
|
|
6917
6917
|
}
|
|
6918
6918
|
|
|
6919
|
-
// Filter by query
|
|
6919
|
+
// Filter by query — tokenized OR-match on text + tags + context.
|
|
6920
|
+
// Previously this required the entire query as one contiguous
|
|
6921
|
+
// substring (haystack.includes(query)), so any multi-word query
|
|
6922
|
+
// returned zero hits. Now we split on whitespace and keep an entry
|
|
6923
|
+
// if it matches at least one token, then rank by the number of
|
|
6924
|
+
// distinct tokens matched (descending), tie-broken by recency.
|
|
6920
6925
|
if (query) {
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6926
|
+
const tokens = query.split(/\s+/).filter(Boolean);
|
|
6927
|
+
const scored = [];
|
|
6928
|
+
for (const m of results) {
|
|
6929
|
+
const haystack = (
|
|
6930
|
+
(m.text || '') + ' ' +
|
|
6931
|
+
(m.tags || []).join(' ') + ' ' +
|
|
6932
|
+
(m.context || '')
|
|
6933
|
+
).toLowerCase();
|
|
6934
|
+
let matched = 0;
|
|
6935
|
+
let occurrences = 0;
|
|
6936
|
+
for (const tok of tokens) {
|
|
6937
|
+
const c = haystack.split(tok).length - 1;
|
|
6938
|
+
if (c > 0) {
|
|
6939
|
+
matched += 1;
|
|
6940
|
+
occurrences += c;
|
|
6941
|
+
}
|
|
6942
|
+
}
|
|
6943
|
+
if (matched >= 1) {
|
|
6944
|
+
scored.push({ mem: m, matched, occurrences });
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
// Rank: most tokens matched, then most occurrences, then recency.
|
|
6948
|
+
scored.sort((a, b) => {
|
|
6949
|
+
if (b.matched !== a.matched) return b.matched - a.matched;
|
|
6950
|
+
if (b.occurrences !== a.occurrences) return b.occurrences - a.occurrences;
|
|
6951
|
+
const at = new Date(a.mem.created_at || a.mem.created || 0).getTime();
|
|
6952
|
+
const bt = new Date(b.mem.created_at || b.mem.created || 0).getTime();
|
|
6953
|
+
return bt - at;
|
|
6924
6954
|
});
|
|
6955
|
+
results = scored.map(s => s.mem);
|
|
6925
6956
|
}
|
|
6926
6957
|
|
|
6927
6958
|
// Unless --all, limit to last 10
|
|
@@ -6930,8 +6961,13 @@ program
|
|
|
6930
6961
|
results = results.slice(-10);
|
|
6931
6962
|
}
|
|
6932
6963
|
|
|
6933
|
-
// Display newest
|
|
6934
|
-
|
|
6964
|
+
// Display order: newest-first for the unfiltered/tag views (memories
|
|
6965
|
+
// arrive newest-first, so reverse only when NOT ranking by query).
|
|
6966
|
+
// Query results are already ordered best-match-first by the ranking
|
|
6967
|
+
// above and must not be reversed.
|
|
6968
|
+
if (!query) {
|
|
6969
|
+
results.reverse();
|
|
6970
|
+
}
|
|
6935
6971
|
|
|
6936
6972
|
console.log(chalk.bold('\n Delimit Memories\n'));
|
|
6937
6973
|
|
package/bin/delimit-setup.js
CHANGED
|
@@ -258,18 +258,22 @@ async function main() {
|
|
|
258
258
|
const venvPy = fs.existsSync(venvPython) ? venvPython : venvPythonWin;
|
|
259
259
|
if (fs.existsSync(reqFile)) {
|
|
260
260
|
execSync(`"${venvPy}" -m pip install --quiet -r "${reqFile}" 2>/dev/null`, { stdio: 'pipe' });
|
|
261
|
+
// LED-1564: even when reqFile exists, ensure pytest is present.
|
|
262
|
+
// Older reqFiles (pre-2026-05-22) didn't list it; without pytest
|
|
263
|
+
// the delimit_test_smoke deploy-gate step fails to run cleanly.
|
|
264
|
+
execSync(`"${venvPy}" -m pip install --quiet pytest 2>/dev/null`, { stdio: 'pipe' });
|
|
261
265
|
} else {
|
|
262
|
-
execSync(`"${venvPy}" -m pip install --quiet fastmcp==3.1.0 pyyaml==6.0.3 pydantic==2.12.5 packaging==26.0 2>/dev/null`, { stdio: 'pipe' });
|
|
266
|
+
execSync(`"${venvPy}" -m pip install --quiet fastmcp==3.1.0 pyyaml==6.0.3 pydantic==2.12.5 packaging==26.0 pytest 2>/dev/null`, { stdio: 'pipe' });
|
|
263
267
|
}
|
|
264
268
|
python = venvPy; // Use venv python for MCP config
|
|
265
269
|
await logp(` ${green('✓')} Python dependencies installed (isolated venv)`);
|
|
266
270
|
} catch {
|
|
267
271
|
log(` ${yellow('!')} venv install failed — trying global pip`);
|
|
268
272
|
try {
|
|
269
|
-
execSync(`${python} -m pip install --quiet fastmcp==3.1.0 pyyaml==6.0.3 pydantic==2.12.5 packaging==26.0 2>/dev/null`, { stdio: 'pipe' });
|
|
273
|
+
execSync(`${python} -m pip install --quiet fastmcp==3.1.0 pyyaml==6.0.3 pydantic==2.12.5 packaging==26.0 pytest 2>/dev/null`, { stdio: 'pipe' });
|
|
270
274
|
await logp(` ${green('✓')} Python dependencies installed (global)`);
|
|
271
275
|
} catch {
|
|
272
|
-
log(` ${yellow('!')} pip install failed — run manually: pip install fastmcp pyyaml pydantic packaging`);
|
|
276
|
+
log(` ${yellow('!')} pip install failed — run manually: pip install fastmcp pyyaml pydantic packaging pytest`);
|
|
273
277
|
}
|
|
274
278
|
}
|
|
275
279
|
|
|
@@ -358,6 +358,12 @@ def run_diff(old_spec: str, new_spec: str) -> Dict[str, Any]:
|
|
|
358
358
|
}
|
|
359
359
|
for c in changes
|
|
360
360
|
],
|
|
361
|
+
# LED-1588: structured side-channel for fail-open skips (unresolvable
|
|
362
|
+
# refs, malformed nodes) so a clean `changes` list is not mistaken for
|
|
363
|
+
# "proven safe". Additive — existing keys are unchanged. The JSON
|
|
364
|
+
# Schema branch above intentionally omits this (engine does not yet
|
|
365
|
+
# populate advisories; a misleading empty field would imply it checked).
|
|
366
|
+
"advisories": engine.advisories,
|
|
361
367
|
}
|
|
362
368
|
|
|
363
369
|
|
|
@@ -14,11 +14,131 @@ logger = logging.getLogger("delimit.ai.memory_bridge")
|
|
|
14
14
|
|
|
15
15
|
MEMORY_DIR = Path.home() / ".delimit" / "memory"
|
|
16
16
|
|
|
17
|
+
# Legacy CLI store filename. The npm CLI historically wrote memories as
|
|
18
|
+
# newline-delimited JSON (`memories.jsonl`) using a `text`/`created`/`source`
|
|
19
|
+
# schema, while the MCP store writes one `mem-*.json` file per entry using
|
|
20
|
+
# `content`/`created_at`/`context`. The readers below reconcile both so a
|
|
21
|
+
# customer who created memories via the old CLI still sees them through the
|
|
22
|
+
# MCP tools (FIX C — non-destructive; the .jsonl is never rewritten here).
|
|
23
|
+
LEGACY_JSONL_NAME = "memories.jsonl"
|
|
24
|
+
|
|
17
25
|
|
|
18
26
|
def _ensure_dir():
|
|
19
27
|
MEMORY_DIR.mkdir(parents=True, exist_ok=True)
|
|
20
28
|
|
|
21
29
|
|
|
30
|
+
def _tokenize(query: str) -> List[str]:
|
|
31
|
+
"""Split a search query into lowercased whitespace-delimited tokens.
|
|
32
|
+
|
|
33
|
+
Used by search() for OR-semantics keyword matching: an entry is a hit
|
|
34
|
+
if it contains at least one token. Empty / whitespace-only queries
|
|
35
|
+
yield no tokens (callers preserve their own empty-query behavior).
|
|
36
|
+
"""
|
|
37
|
+
return [t for t in (query or "").lower().split() if t]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _normalize_legacy_entry(raw: Dict[str, Any]) -> Dict[str, Any]:
|
|
41
|
+
"""Normalize a legacy `memories.jsonl` record to the MCP entry shape.
|
|
42
|
+
|
|
43
|
+
Legacy CLI schema: {id, text, tags, created, source}
|
|
44
|
+
MCP schema: {id, content, tags, context, created_at, hot_load}
|
|
45
|
+
|
|
46
|
+
Maps text->content and created->created_at without dropping the
|
|
47
|
+
original keys, and synthesizes a context from `source` when absent so
|
|
48
|
+
downstream readers behave uniformly. Mirrors the CLI's readMemories
|
|
49
|
+
normalization (npm-delimit/bin/delimit-cli.js) for cross-tool parity.
|
|
50
|
+
"""
|
|
51
|
+
entry = dict(raw)
|
|
52
|
+
if entry.get("text") and not entry.get("content"):
|
|
53
|
+
entry["content"] = entry["text"]
|
|
54
|
+
if entry.get("content") and not entry.get("text"):
|
|
55
|
+
entry["text"] = entry["content"]
|
|
56
|
+
if entry.get("created") and not entry.get("created_at"):
|
|
57
|
+
entry["created_at"] = entry["created"]
|
|
58
|
+
if entry.get("created_at") and not entry.get("created"):
|
|
59
|
+
entry["created"] = entry["created_at"]
|
|
60
|
+
if not entry.get("context") and entry.get("source"):
|
|
61
|
+
entry["context"] = entry["source"]
|
|
62
|
+
return entry
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _read_legacy_jsonl() -> List[Dict[str, Any]]:
|
|
66
|
+
"""Read and normalize legacy `memories.jsonl` entries, if present.
|
|
67
|
+
|
|
68
|
+
Defensive by contract: a missing or malformed file yields an empty
|
|
69
|
+
list and never raises. Malformed individual lines are skipped so one
|
|
70
|
+
bad line does not lose the rest of the file.
|
|
71
|
+
"""
|
|
72
|
+
path = MEMORY_DIR / LEGACY_JSONL_NAME
|
|
73
|
+
entries: List[Dict[str, Any]] = []
|
|
74
|
+
try:
|
|
75
|
+
if not path.exists():
|
|
76
|
+
return entries
|
|
77
|
+
text = path.read_text()
|
|
78
|
+
except OSError:
|
|
79
|
+
return entries
|
|
80
|
+
for line in text.splitlines():
|
|
81
|
+
line = line.strip()
|
|
82
|
+
if not line:
|
|
83
|
+
continue
|
|
84
|
+
try:
|
|
85
|
+
raw = json.loads(line)
|
|
86
|
+
except (json.JSONDecodeError, ValueError):
|
|
87
|
+
continue
|
|
88
|
+
if isinstance(raw, dict):
|
|
89
|
+
entries.append(_normalize_legacy_entry(raw))
|
|
90
|
+
return entries
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _load_all_entries() -> List[Dict[str, Any]]:
|
|
94
|
+
"""Load every memory entry from both stores, deduped by id.
|
|
95
|
+
|
|
96
|
+
Reads the per-entry `mem-*.json` files (MCP, primary) and the legacy
|
|
97
|
+
`memories.jsonl` (CLI, backwards-compat). On an id collision the
|
|
98
|
+
`mem-*.json` entry wins — it is the authoritative MCP store and may
|
|
99
|
+
carry fields (e.g. hot_load) the legacy record lacks. Entries are
|
|
100
|
+
returned newest-first by created_at so callers that slice keep the
|
|
101
|
+
most recent. Fully defensive: unreadable files are skipped.
|
|
102
|
+
|
|
103
|
+
FIX C: the legacy `memories.jsonl` is read-only here — never deleted
|
|
104
|
+
or rewritten — preserving a customer's existing CLI-authored memories.
|
|
105
|
+
"""
|
|
106
|
+
by_id: Dict[str, Dict[str, Any]] = {}
|
|
107
|
+
order: List[str] = []
|
|
108
|
+
|
|
109
|
+
def _add(entry: Dict[str, Any], key: str, *, overwrite: bool) -> None:
|
|
110
|
+
if key not in by_id:
|
|
111
|
+
by_id[key] = entry
|
|
112
|
+
order.append(key)
|
|
113
|
+
elif overwrite:
|
|
114
|
+
by_id[key] = entry
|
|
115
|
+
|
|
116
|
+
# Primary store: mem-*.json (authoritative, wins on conflict).
|
|
117
|
+
for f in MEMORY_DIR.glob("*.json"):
|
|
118
|
+
try:
|
|
119
|
+
entry = json.loads(f.read_text())
|
|
120
|
+
except (OSError, json.JSONDecodeError, ValueError):
|
|
121
|
+
continue
|
|
122
|
+
if not isinstance(entry, dict):
|
|
123
|
+
continue
|
|
124
|
+
entry.setdefault("id", f.stem)
|
|
125
|
+
_add(entry, entry.get("id") or f.stem, overwrite=True)
|
|
126
|
+
|
|
127
|
+
# Legacy jsonl: only fills ids the primary store does not already have.
|
|
128
|
+
for entry in _read_legacy_jsonl():
|
|
129
|
+
key = entry.get("id")
|
|
130
|
+
if not key:
|
|
131
|
+
# No id to dedupe on — keep it, it cannot collide.
|
|
132
|
+
order.append(id(entry)) # unique sentinel key
|
|
133
|
+
by_id[id(entry)] = entry
|
|
134
|
+
continue
|
|
135
|
+
_add(entry, key, overwrite=False)
|
|
136
|
+
|
|
137
|
+
entries = [by_id[k] for k in order]
|
|
138
|
+
entries.sort(key=lambda e: e.get("created_at") or e.get("created") or "", reverse=True)
|
|
139
|
+
return entries
|
|
140
|
+
|
|
141
|
+
|
|
22
142
|
def store(
|
|
23
143
|
content: str,
|
|
24
144
|
tags: Optional[list] = None,
|
|
@@ -68,56 +188,97 @@ def store(
|
|
|
68
188
|
|
|
69
189
|
|
|
70
190
|
def search(query: str, limit: int = 10) -> Dict[str, Any]:
|
|
71
|
-
"""Search memories by keyword matching.
|
|
191
|
+
"""Search memories by keyword matching.
|
|
192
|
+
|
|
193
|
+
FIX A: the query is tokenized on whitespace and matched with OR
|
|
194
|
+
semantics — an entry is a hit if it contains at least one token in its
|
|
195
|
+
content, tags, or context. Previously the entire query had to appear as
|
|
196
|
+
one contiguous substring, so any multi-word query returned zero hits.
|
|
197
|
+
|
|
198
|
+
Results are ranked by the number of distinct query tokens matched
|
|
199
|
+
(descending), tie-broken by recency (created_at descending). The
|
|
200
|
+
`relevance` field is preserved in the return schema and now carries the
|
|
201
|
+
matched-token count, the primary ranking signal.
|
|
202
|
+
|
|
203
|
+
An empty (or whitespace-only) query preserves the previous behavior of
|
|
204
|
+
returning no results.
|
|
205
|
+
|
|
206
|
+
FIX C: reads both the per-entry `mem-*.json` MCP store and the legacy
|
|
207
|
+
`memories.jsonl` CLI store (deduped, MCP wins on id conflict).
|
|
208
|
+
"""
|
|
72
209
|
_ensure_dir()
|
|
73
|
-
|
|
210
|
+
tokens = _tokenize(query)
|
|
74
211
|
results = []
|
|
75
212
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
213
|
+
# Empty / whitespace-only query: preserve prior behavior (no hits).
|
|
214
|
+
if not tokens:
|
|
215
|
+
return {"query": query, "results": results, "count": 0}
|
|
216
|
+
|
|
217
|
+
for entry in _load_all_entries():
|
|
218
|
+
content = (entry.get("content") or "").lower()
|
|
219
|
+
tags = " ".join(entry.get("tags") or []).lower()
|
|
220
|
+
context = (entry.get("context") or "").lower()
|
|
221
|
+
haystacks = (content, tags, context)
|
|
222
|
+
|
|
223
|
+
matched_tokens = 0
|
|
224
|
+
total_occurrences = 0
|
|
225
|
+
for tok in tokens:
|
|
226
|
+
hit = False
|
|
227
|
+
for hay in haystacks:
|
|
228
|
+
c = hay.count(tok)
|
|
229
|
+
if c:
|
|
230
|
+
hit = True
|
|
231
|
+
total_occurrences += c
|
|
232
|
+
if hit:
|
|
233
|
+
matched_tokens += 1
|
|
234
|
+
|
|
235
|
+
if matched_tokens >= 1:
|
|
236
|
+
results.append({
|
|
237
|
+
"id": entry.get("id", ""),
|
|
238
|
+
"content": (entry.get("content") or "")[:500],
|
|
239
|
+
"tags": entry.get("tags") or [],
|
|
240
|
+
"created_at": entry.get("created_at") or entry.get("created") or "",
|
|
241
|
+
# `relevance` preserved in schema; now = matched-token count
|
|
242
|
+
# (primary ranking signal). _occurrences is an internal
|
|
243
|
+
# tie-break aid, dropped before return.
|
|
244
|
+
"relevance": matched_tokens,
|
|
245
|
+
"_occurrences": total_occurrences,
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
# Rank: most tokens matched first, then most occurrences, then recency.
|
|
249
|
+
results.sort(
|
|
250
|
+
key=lambda r: (r["relevance"], r["_occurrences"], r.get("created_at") or ""),
|
|
251
|
+
reverse=True,
|
|
252
|
+
)
|
|
253
|
+
for r in results:
|
|
254
|
+
r.pop("_occurrences", None)
|
|
255
|
+
|
|
256
|
+
results = results[:limit]
|
|
99
257
|
return {"query": query, "results": results, "count": len(results)}
|
|
100
258
|
|
|
101
259
|
|
|
102
260
|
def get_recent(limit: int = 5) -> Dict[str, Any]:
|
|
103
|
-
"""Get recent memory entries.
|
|
261
|
+
"""Get recent memory entries.
|
|
262
|
+
|
|
263
|
+
FIX C: reads both the per-entry `mem-*.json` MCP store and the legacy
|
|
264
|
+
`memories.jsonl` CLI store. Entries are deduped by id (MCP wins) and
|
|
265
|
+
ordered newest-first by created_at (legacy `created` is normalized to
|
|
266
|
+
`created_at`). Legacy entries surface `hot_load=False` since the field
|
|
267
|
+
pre-dates that schema.
|
|
268
|
+
"""
|
|
104
269
|
_ensure_dir()
|
|
105
270
|
entries = []
|
|
106
271
|
|
|
107
|
-
for
|
|
272
|
+
for entry in _load_all_entries():
|
|
108
273
|
if len(entries) >= limit:
|
|
109
274
|
break
|
|
110
|
-
|
|
111
|
-
entry
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"hot_load": bool(entry.get("hot_load", False)),
|
|
118
|
-
})
|
|
119
|
-
except Exception:
|
|
120
|
-
pass
|
|
275
|
+
entries.append({
|
|
276
|
+
"id": entry.get("id", ""),
|
|
277
|
+
"content": (entry.get("content") or "")[:500],
|
|
278
|
+
"tags": entry.get("tags") or [],
|
|
279
|
+
"created_at": entry.get("created_at") or entry.get("created") or "",
|
|
280
|
+
"hot_load": bool(entry.get("hot_load", False)),
|
|
281
|
+
})
|
|
121
282
|
|
|
122
283
|
return {"results": entries, "count": len(entries)}
|
|
123
284
|
|
|
@@ -143,23 +304,19 @@ def list_hot(limit: int = 200) -> Dict[str, Any]:
|
|
|
143
304
|
_ensure_dir()
|
|
144
305
|
entries = []
|
|
145
306
|
|
|
146
|
-
for
|
|
307
|
+
for entry in _load_all_entries():
|
|
147
308
|
if len(entries) >= limit:
|
|
148
309
|
break
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"hot_load": True,
|
|
160
|
-
})
|
|
161
|
-
except Exception:
|
|
162
|
-
pass
|
|
310
|
+
if not entry.get("hot_load"):
|
|
311
|
+
continue
|
|
312
|
+
entries.append({
|
|
313
|
+
"id": entry.get("id", ""),
|
|
314
|
+
"content": entry.get("content") or "",
|
|
315
|
+
"tags": entry.get("tags") or [],
|
|
316
|
+
"context": entry.get("context") or "",
|
|
317
|
+
"created_at": entry.get("created_at") or entry.get("created") or "",
|
|
318
|
+
"hot_load": True,
|
|
319
|
+
})
|
|
163
320
|
|
|
164
321
|
return {"results": entries, "count": len(entries)}
|
|
165
322
|
|
|
@@ -162,6 +162,73 @@ KNOWN_DUMMY_PATTERNS = [
|
|
|
162
162
|
]
|
|
163
163
|
|
|
164
164
|
|
|
165
|
+
# LED-2278 [2026-05-27]: positive value-shape gate for generic_secret.
|
|
166
|
+
#
|
|
167
|
+
# The generic_secret regex (`\b(?:secret|password|passwd|token)\b\s*[=:]\s*
|
|
168
|
+
# ['\"]?[^\s'\"]{8,}`) fires on ANY assignment/key whose trigger word is
|
|
169
|
+
# followed by 8+ non-space chars — including ordinary code where the RHS is
|
|
170
|
+
# an identifier, a function call, or a subscript expression, not a hardcoded
|
|
171
|
+
# literal. Examples that recurrently false-positive in this very repo:
|
|
172
|
+
#
|
|
173
|
+
# token = self._unescape_json_pointer_token(raw_token) # method call
|
|
174
|
+
# scheme, token = parts[0].strip().lower(), parts[1] # tuple/subscript
|
|
175
|
+
#
|
|
176
|
+
# The pre-existing `_CREDENTIAL_FALSE_POSITIVES` negative list is whack-a-mole
|
|
177
|
+
# (one alternation per observed shape). This positive gate inverts the logic:
|
|
178
|
+
# a `generic_secret` hit is only credible when the VALUE is a *quoted string
|
|
179
|
+
# literal* with secret-like entropy/length. If the value is an unquoted
|
|
180
|
+
# identifier / call / expression, it is code, not a leaked secret — suppress.
|
|
181
|
+
#
|
|
182
|
+
# Conservative by construction: this gate only ever SUPPRESSES generic_secret
|
|
183
|
+
# hits whose value is non-literal. It never suppresses a quoted literal, so
|
|
184
|
+
# real hardcoded secrets (and all the existing detection tests) still fire.
|
|
185
|
+
# Applies to generic_secret only — aws_secret_key / github_token / etc. keep
|
|
186
|
+
# their own format-specific regexes untouched.
|
|
187
|
+
|
|
188
|
+
# A value (after the = or :) that begins with a quote is a string literal.
|
|
189
|
+
_GENERIC_SECRET_VALUE_RE = re.compile(
|
|
190
|
+
r"""\b(?:secret|password|passwd|token)\b\s*[=:]\s*(?P<q>['\"])(?P<val>[^'\"]*)"""
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _generic_secret_value_is_literal(matched_text: str) -> bool:
|
|
195
|
+
"""True only if the generic_secret match assigns a *quoted string literal*.
|
|
196
|
+
|
|
197
|
+
The generic_secret regex tolerates an optional opening quote, so it also
|
|
198
|
+
matches `token = some_call()` (unquoted RHS). A real hardcoded secret is a
|
|
199
|
+
quoted literal with entropy; an unquoted RHS is an identifier/expression
|
|
200
|
+
(variable ref, function call, subscript, attribute access) and is code, not
|
|
201
|
+
a leak. Return False for the unquoted/expression case so the caller can
|
|
202
|
+
suppress it, True for a credible quoted-literal value.
|
|
203
|
+
"""
|
|
204
|
+
m = _GENERIC_SECRET_VALUE_RE.search(matched_text)
|
|
205
|
+
if not m:
|
|
206
|
+
# No opening quote captured → RHS is a bare identifier / expression
|
|
207
|
+
# (e.g. `token = self._make(...)`, `scheme, token = parts[0]`). Not a
|
|
208
|
+
# hardcoded literal; suppress.
|
|
209
|
+
return False
|
|
210
|
+
val = m.group("val")
|
|
211
|
+
# A quoted literal with too little content is not secret-shaped. The outer
|
|
212
|
+
# regex already required 8+ chars total, but the quote may sit mid-match;
|
|
213
|
+
# require the literal body itself to be reasonably long.
|
|
214
|
+
if len(val) < 6:
|
|
215
|
+
return False
|
|
216
|
+
# Pure-identifier literals inside quotes (e.g. a quoted dict KEY like
|
|
217
|
+
# "access_token") that are all word chars + separators and read like an
|
|
218
|
+
# English/identifier token rather than a high-entropy secret: require at
|
|
219
|
+
# least some character-class mixing OR sufficient length to look secret-y.
|
|
220
|
+
has_lower = any(c.islower() for c in val)
|
|
221
|
+
has_upper = any(c.isupper() for c in val)
|
|
222
|
+
has_digit = any(c.isdigit() for c in val)
|
|
223
|
+
# Treat underscore/hyphen as word chars (not entropy): a quoted
|
|
224
|
+
# identifier-shaped value like "access_token" should NOT count as a
|
|
225
|
+
# multi-class high-entropy secret on the strength of its separators alone.
|
|
226
|
+
has_symbol = any(not c.isalnum() and c not in (" ", "_", "-") for c in val)
|
|
227
|
+
classes = sum([has_lower, has_upper, has_digit, has_symbol])
|
|
228
|
+
# Credible secret: multi-class entropy, OR a long single-class blob.
|
|
229
|
+
return classes >= 2 or len(val) >= 16
|
|
230
|
+
|
|
231
|
+
|
|
165
232
|
def _looks_like_known_dummy(secret_name: str, matched_text: str) -> Optional[str]:
|
|
166
233
|
"""Return a label if matched_text is a known-dummy/fixture value, else None.
|
|
167
234
|
|
|
@@ -435,6 +502,19 @@ def security_audit(target: str = ".", include_tests: bool = False) -> Dict[str,
|
|
|
435
502
|
# Skip false positives only for generic patterns (not specific token formats)
|
|
436
503
|
if secret_name in _FP_FILTERED and _CREDENTIAL_FALSE_POSITIVES.search(matched_text):
|
|
437
504
|
continue
|
|
505
|
+
# LED-2278: positive value-shape gate for generic_secret. Only
|
|
506
|
+
# flag when the assigned value is a quoted string literal with
|
|
507
|
+
# secret-like entropy; an unquoted identifier/call/expression
|
|
508
|
+
# RHS (`token = self._make(...)`, `scheme, token = parts[0]`)
|
|
509
|
+
# is code, not a leaked secret. Conservative: never suppresses
|
|
510
|
+
# a quoted literal, so real hardcoded secrets still fire.
|
|
511
|
+
if secret_name == "generic_secret" and not _generic_secret_value_is_literal(matched_text):
|
|
512
|
+
continue
|
|
513
|
+
# LED-2278: the scanner's own source embeds the trigger words in
|
|
514
|
+
# regex/doc comments (e.g. the `token = realLeak(...)` example in
|
|
515
|
+
# this module). Those are pattern DEFINITIONS, not secrets.
|
|
516
|
+
if secret_name == "generic_secret" and rel.endswith("ai/backends/tools_infra.py"):
|
|
517
|
+
continue
|
|
438
518
|
line_num = content[:match.start()].count("\n") + 1
|
|
439
519
|
# LED-1278 (b): well-known dummy/placeholder values get
|
|
440
520
|
# suppressed to info-level rather than raised as critical.
|
|
@@ -10,6 +10,7 @@ import json
|
|
|
10
10
|
import logging
|
|
11
11
|
import os
|
|
12
12
|
import re
|
|
13
|
+
import shutil
|
|
13
14
|
import subprocess
|
|
14
15
|
from datetime import datetime, timezone
|
|
15
16
|
from pathlib import Path
|
|
@@ -364,18 +365,63 @@ def test_smoke(project_path: str, test_suite: Optional[str] = None) -> Dict[str,
|
|
|
364
365
|
return {"tool": "test.smoke", "status": "error", "error": f"Invalid test_suite: {test_suite}"}
|
|
365
366
|
cmd_list.append(test_suite)
|
|
366
367
|
|
|
367
|
-
# Detect the right Python executable
|
|
368
|
+
# Detect the right Python executable.
|
|
369
|
+
#
|
|
370
|
+
# Resolution order (LED-1564 follow-up, 2026-05-22):
|
|
371
|
+
# 1. Project's own venv (most isolated; honors project's own deps).
|
|
372
|
+
# 2. System python3 on PATH — where projects typically install deps
|
|
373
|
+
# when they don't ship a local venv. Tested for pytest availability
|
|
374
|
+
# so we don't fall through to a Python that can't run pytest.
|
|
375
|
+
# 3. sys.executable (= MCP server's runner venv) as last resort.
|
|
376
|
+
#
|
|
377
|
+
# The pre-fix order was (1) → (3), which broke for projects that have
|
|
378
|
+
# their deps installed system-wide but no project-local venv: pytest
|
|
379
|
+
# itself might exist in the delimit venv, but project-specific imports
|
|
380
|
+
# like `pika` (caught by codex against wirereport 2026-05-22) raise
|
|
381
|
+
# ModuleNotFoundError because the delimit venv is stripped to the MCP
|
|
382
|
+
# server's deps only.
|
|
368
383
|
if framework == "pytest":
|
|
369
|
-
|
|
384
|
+
import sys as _sys
|
|
385
|
+
|
|
386
|
+
chosen = None
|
|
387
|
+
# (1) Project-local venv.
|
|
370
388
|
for venv_dir in ["venv", ".venv", "env"]:
|
|
371
389
|
venv_python = project / venv_dir / "bin" / "python"
|
|
372
390
|
if venv_python.exists():
|
|
373
|
-
|
|
374
|
-
python_found = True
|
|
391
|
+
chosen = str(venv_python)
|
|
375
392
|
break
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
393
|
+
|
|
394
|
+
# (2) System python3 if it has pytest. Probe with a fast import-
|
|
395
|
+
# check so we don't pick a python that can't actually run pytest.
|
|
396
|
+
if chosen is None:
|
|
397
|
+
for candidate in ("python3", "python"):
|
|
398
|
+
exe = shutil.which(candidate)
|
|
399
|
+
if not exe:
|
|
400
|
+
continue
|
|
401
|
+
# Skip only when the candidate path is literally the same
|
|
402
|
+
# interpreter entrypoint as the MCP runner. In deployments
|
|
403
|
+
# where the venv python is a symlink to /usr/bin/python3,
|
|
404
|
+
# comparing resolved paths collapses the system interpreter
|
|
405
|
+
# and the venv interpreter into the same target and prevents
|
|
406
|
+
# the intended fallback to system python3.
|
|
407
|
+
if Path(exe) == Path(_sys.executable):
|
|
408
|
+
continue
|
|
409
|
+
try:
|
|
410
|
+
probe = subprocess.run(
|
|
411
|
+
[exe, "-c", "import pytest"],
|
|
412
|
+
capture_output=True, timeout=10,
|
|
413
|
+
)
|
|
414
|
+
if probe.returncode == 0:
|
|
415
|
+
chosen = exe
|
|
416
|
+
break
|
|
417
|
+
except (subprocess.TimeoutExpired, OSError):
|
|
418
|
+
continue
|
|
419
|
+
|
|
420
|
+
# (3) sys.executable (= MCP server's runner venv) as last resort.
|
|
421
|
+
if chosen is None:
|
|
422
|
+
chosen = _sys.executable
|
|
423
|
+
|
|
424
|
+
cmd_list[0] = chosen
|
|
379
425
|
|
|
380
426
|
try:
|
|
381
427
|
result = subprocess.run(
|