agent-recall-core 3.4.48 → 3.4.49
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/README.md +25 -0
- package/dist/digest/store.d.ts +15 -6
- package/dist/digest/store.d.ts.map +1 -1
- package/dist/digest/store.js +33 -20
- package/dist/digest/store.js.map +1 -1
- package/dist/embeddings/chunker.d.ts +102 -0
- package/dist/embeddings/chunker.d.ts.map +1 -0
- package/dist/embeddings/chunker.js +260 -0
- package/dist/embeddings/chunker.js.map +1 -0
- package/dist/embeddings/config.d.ts +93 -0
- package/dist/embeddings/config.d.ts.map +1 -0
- package/dist/embeddings/config.js +174 -0
- package/dist/embeddings/config.js.map +1 -0
- package/dist/embeddings/index-store.d.ts +61 -0
- package/dist/embeddings/index-store.d.ts.map +1 -0
- package/dist/embeddings/index-store.js +158 -0
- package/dist/embeddings/index-store.js.map +1 -0
- package/dist/embeddings/indexer.d.ts +75 -0
- package/dist/embeddings/indexer.d.ts.map +1 -0
- package/dist/embeddings/indexer.js +196 -0
- package/dist/embeddings/indexer.js.map +1 -0
- package/dist/embeddings/runtime.d.ts +66 -0
- package/dist/embeddings/runtime.d.ts.map +1 -0
- package/dist/embeddings/runtime.js +197 -0
- package/dist/embeddings/runtime.js.map +1 -0
- package/dist/helpers/associative-link.d.ts.map +1 -1
- package/dist/helpers/associative-link.js +26 -1
- package/dist/helpers/associative-link.js.map +1 -1
- package/dist/helpers/tokenize.d.ts +1 -0
- package/dist/helpers/tokenize.d.ts.map +1 -1
- package/dist/helpers/tokenize.js +18 -0
- package/dist/helpers/tokenize.js.map +1 -1
- package/dist/index.d.ts +21 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -4
- package/dist/index.js.map +1 -1
- package/dist/palace/awareness.d.ts +34 -10
- package/dist/palace/awareness.d.ts.map +1 -1
- package/dist/palace/awareness.js +249 -180
- package/dist/palace/awareness.js.map +1 -1
- package/dist/palace/consolidate.d.ts +1 -1
- package/dist/palace/consolidate.d.ts.map +1 -1
- package/dist/palace/consolidate.js +9 -9
- package/dist/palace/consolidate.js.map +1 -1
- package/dist/palace/decay-pass.d.ts +1 -1
- package/dist/palace/decay-pass.d.ts.map +1 -1
- package/dist/palace/decay-pass.js +2 -2
- package/dist/palace/decay-pass.js.map +1 -1
- package/dist/palace/fan-out.d.ts +1 -1
- package/dist/palace/fan-out.d.ts.map +1 -1
- package/dist/palace/fan-out.js +5 -5
- package/dist/palace/fan-out.js.map +1 -1
- package/dist/palace/index-manager.d.ts +1 -1
- package/dist/palace/index-manager.d.ts.map +1 -1
- package/dist/palace/index-manager.js +1 -1
- package/dist/palace/index-manager.js.map +1 -1
- package/dist/palace/insights-index.d.ts +19 -6
- package/dist/palace/insights-index.d.ts.map +1 -1
- package/dist/palace/insights-index.js +36 -13
- package/dist/palace/insights-index.js.map +1 -1
- package/dist/palace/keystone.d.ts +1 -1
- package/dist/palace/keystone.d.ts.map +1 -1
- package/dist/palace/keystone.js +2 -2
- package/dist/palace/keystone.js.map +1 -1
- package/dist/palace/rooms.d.ts +3 -3
- package/dist/palace/rooms.d.ts.map +1 -1
- package/dist/palace/rooms.js +34 -6
- package/dist/palace/rooms.js.map +1 -1
- package/dist/retrieval/candidates.d.ts.map +1 -1
- package/dist/retrieval/candidates.js +17 -2
- package/dist/retrieval/candidates.js.map +1 -1
- package/dist/retrieval/query-memory.d.ts +65 -7
- package/dist/retrieval/query-memory.d.ts.map +1 -1
- package/dist/retrieval/query-memory.js +518 -78
- package/dist/retrieval/query-memory.js.map +1 -1
- package/dist/retrieval/semantic-leg.d.ts +74 -0
- package/dist/retrieval/semantic-leg.d.ts.map +1 -0
- package/dist/retrieval/semantic-leg.js +180 -0
- package/dist/retrieval/semantic-leg.js.map +1 -0
- package/dist/storage/archive-write.d.ts.map +1 -1
- package/dist/storage/archive-write.js +29 -8
- package/dist/storage/archive-write.js.map +1 -1
- package/dist/storage/capture-router.d.ts +1 -1
- package/dist/storage/capture-router.d.ts.map +1 -1
- package/dist/storage/capture-router.js +26 -9
- package/dist/storage/capture-router.js.map +1 -1
- package/dist/storage/consolidation-queue.d.ts +11 -2
- package/dist/storage/consolidation-queue.d.ts.map +1 -1
- package/dist/storage/consolidation-queue.js +45 -16
- package/dist/storage/consolidation-queue.js.map +1 -1
- package/dist/storage/corrections.d.ts +53 -5
- package/dist/storage/corrections.d.ts.map +1 -1
- package/dist/storage/corrections.js +412 -124
- package/dist/storage/corrections.js.map +1 -1
- package/dist/storage/durable-intent.d.ts.map +1 -1
- package/dist/storage/durable-intent.js +24 -1
- package/dist/storage/durable-intent.js.map +1 -1
- package/dist/storage/filelock.d.ts +84 -12
- package/dist/storage/filelock.d.ts.map +1 -1
- package/dist/storage/filelock.js +309 -47
- package/dist/storage/filelock.js.map +1 -1
- package/dist/storage/fs-utils.d.ts +20 -0
- package/dist/storage/fs-utils.d.ts.map +1 -1
- package/dist/storage/fs-utils.js +27 -0
- package/dist/storage/fs-utils.js.map +1 -1
- package/dist/storage/paths.d.ts +34 -0
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +71 -0
- package/dist/storage/paths.js.map +1 -1
- package/dist/storage/pending.d.ts +154 -0
- package/dist/storage/pending.d.ts.map +1 -0
- package/dist/storage/pending.js +454 -0
- package/dist/storage/pending.js.map +1 -0
- package/dist/storage/project.d.ts.map +1 -1
- package/dist/storage/project.js +68 -16
- package/dist/storage/project.js.map +1 -1
- package/dist/storage/session-card.d.ts +13 -0
- package/dist/storage/session-card.d.ts.map +1 -1
- package/dist/storage/session-card.js +34 -3
- package/dist/storage/session-card.js.map +1 -1
- package/dist/storage/unclaimed.d.ts +165 -0
- package/dist/storage/unclaimed.d.ts.map +1 -0
- package/dist/storage/unclaimed.js +442 -0
- package/dist/storage/unclaimed.js.map +1 -0
- package/dist/storage/working-memory.d.ts.map +1 -1
- package/dist/storage/working-memory.js +19 -1
- package/dist/storage/working-memory.js.map +1 -1
- package/dist/supabase/recall-backend.d.ts +28 -2
- package/dist/supabase/recall-backend.d.ts.map +1 -1
- package/dist/supabase/recall-backend.js +80 -23
- package/dist/supabase/recall-backend.js.map +1 -1
- package/dist/supabase/sync.d.ts.map +1 -1
- package/dist/supabase/sync.js +13 -0
- package/dist/supabase/sync.js.map +1 -1
- package/dist/tools-logic/alignment-check.js +1 -1
- package/dist/tools-logic/alignment-check.js.map +1 -1
- package/dist/tools-logic/awareness-update.d.ts.map +1 -1
- package/dist/tools-logic/awareness-update.js +25 -16
- package/dist/tools-logic/awareness-update.js.map +1 -1
- package/dist/tools-logic/check-action.js +1 -1
- package/dist/tools-logic/check-action.js.map +1 -1
- package/dist/tools-logic/check.d.ts +55 -1
- package/dist/tools-logic/check.d.ts.map +1 -1
- package/dist/tools-logic/check.js +230 -57
- package/dist/tools-logic/check.js.map +1 -1
- package/dist/tools-logic/confidence.d.ts +11 -6
- package/dist/tools-logic/confidence.d.ts.map +1 -1
- package/dist/tools-logic/confidence.js +11 -6
- package/dist/tools-logic/confidence.js.map +1 -1
- package/dist/tools-logic/context-synthesize.js +2 -2
- package/dist/tools-logic/context-synthesize.js.map +1 -1
- package/dist/tools-logic/digest-read.js +2 -2
- package/dist/tools-logic/digest-read.js.map +1 -1
- package/dist/tools-logic/digest-recall.js +1 -1
- package/dist/tools-logic/digest-recall.js.map +1 -1
- package/dist/tools-logic/insight-promotion.d.ts +1 -1
- package/dist/tools-logic/insight-promotion.d.ts.map +1 -1
- package/dist/tools-logic/insight-promotion.js +17 -6
- package/dist/tools-logic/insight-promotion.js.map +1 -1
- package/dist/tools-logic/journal-capture.js +3 -3
- package/dist/tools-logic/journal-capture.js.map +1 -1
- package/dist/tools-logic/journal-write.js +3 -3
- package/dist/tools-logic/journal-write.js.map +1 -1
- package/dist/tools-logic/knowledge-write.js +2 -2
- package/dist/tools-logic/knowledge-write.js.map +1 -1
- package/dist/tools-logic/palace-lint.js +1 -1
- package/dist/tools-logic/palace-lint.js.map +1 -1
- package/dist/tools-logic/palace-read.js +1 -1
- package/dist/tools-logic/palace-read.js.map +1 -1
- package/dist/tools-logic/palace-search.js +1 -1
- package/dist/tools-logic/palace-search.js.map +1 -1
- package/dist/tools-logic/palace-walk.js +3 -3
- package/dist/tools-logic/palace-walk.js.map +1 -1
- package/dist/tools-logic/palace-write.js +4 -4
- package/dist/tools-logic/palace-write.js.map +1 -1
- package/dist/tools-logic/predict-correction.js +1 -1
- package/dist/tools-logic/predict-correction.js.map +1 -1
- package/dist/tools-logic/recall-backend.d.ts +11 -2
- package/dist/tools-logic/recall-backend.d.ts.map +1 -1
- package/dist/tools-logic/recall-backend.js +2 -2
- package/dist/tools-logic/recall-backend.js.map +1 -1
- package/dist/tools-logic/resurrect.d.ts.map +1 -1
- package/dist/tools-logic/resurrect.js +9 -1
- package/dist/tools-logic/resurrect.js.map +1 -1
- package/dist/tools-logic/safety-consolidation.d.ts.map +1 -1
- package/dist/tools-logic/safety-consolidation.js +32 -30
- package/dist/tools-logic/safety-consolidation.js.map +1 -1
- package/dist/tools-logic/session-end.d.ts +8 -0
- package/dist/tools-logic/session-end.d.ts.map +1 -1
- package/dist/tools-logic/session-end.js +51 -13
- package/dist/tools-logic/session-end.js.map +1 -1
- package/dist/tools-logic/session-start.d.ts +23 -0
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +44 -1
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/tools-logic/smart-recall.d.ts +185 -10
- package/dist/tools-logic/smart-recall.d.ts.map +1 -1
- package/dist/tools-logic/smart-recall.js +363 -85
- package/dist/tools-logic/smart-recall.js.map +1 -1
- package/dist/tools-logic/store-doctor.d.ts.map +1 -1
- package/dist/tools-logic/store-doctor.js +7 -4
- package/dist/tools-logic/store-doctor.js.map +1 -1
- package/dist/tools-logic/store-repair.js +1 -1
- package/dist/tools-logic/store-repair.js.map +1 -1
- package/dist/tools-logic/supersession.d.ts +1 -1
- package/dist/tools-logic/supersession.d.ts.map +1 -1
- package/dist/tools-logic/supersession.js +2 -2
- package/dist/tools-logic/supersession.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/vector/embedding.d.ts +8 -0
- package/dist/vector/embedding.d.ts.map +1 -1
- package/dist/vector/embedding.js +8 -0
- package/dist/vector/embedding.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pending-corrections staging store — Fix #2 (dual-channel capture gate,
|
|
3
|
+
* 2026-09-11).
|
|
4
|
+
*
|
|
5
|
+
* Storage: ~/.agent-recall/projects/{project}/corrections/_pending/
|
|
6
|
+
* {id}.json — staged captures awaiting review
|
|
7
|
+
* _rejected.jsonl — hard-noise drops, cap evictions, TTL expiries, and
|
|
8
|
+
* explicit review rejections (append-only, capped)
|
|
9
|
+
* _resolved.jsonl — promotion audit trail (append-only, capped)
|
|
10
|
+
*
|
|
11
|
+
* WHY THIS EXISTS: every low-trust capture channel — check()'s legacy STRING
|
|
12
|
+
* human_correction, the CLI hook channel (correction-detector /
|
|
13
|
+
* hook-correction), and session_end insights that fail completeness
|
|
14
|
+
* validation — stages HERE instead of the active corrections ledger. The
|
|
15
|
+
* active ledger is reachable ONLY through check()'s validated STRUCTURED
|
|
16
|
+
* form {rule, why, applies_when} (or an explicit promote of a staged item).
|
|
17
|
+
*
|
|
18
|
+
* INVARIANTS
|
|
19
|
+
* - Nothing is silently dropped: a capture either becomes a *.json row here
|
|
20
|
+
* or an audit line in _rejected.jsonl, always with provenance.
|
|
21
|
+
* - Pending content NEVER enters the recall corpus, watch_for, session_start
|
|
22
|
+
* corrections, or any retrieval surface until promoted. Structurally
|
|
23
|
+
* guaranteed: readCorrections() readdirs the corrections dir non-recursively
|
|
24
|
+
* and `_pending` is a subdirectory (not a *.json file), so every existing
|
|
25
|
+
* reader skips it without modification.
|
|
26
|
+
* - Capped (PENDING_CAP) + TTL'd (PENDING_TTL_DAYS): the staging area can
|
|
27
|
+
* never grow unbounded; evictions/expiries are logged, not vanished.
|
|
28
|
+
* - Scrub-on-write: rows are written through corrections.ts's exported
|
|
29
|
+
* writeRecordAtomic — the SAME scrubForCloud choke point the active
|
|
30
|
+
* ledger uses (rider R2a) — and filenames derive from the already-scrubbed
|
|
31
|
+
* rule, mirroring writeCorrection's filename-leak fix.
|
|
32
|
+
* - Dedupe by DISTILLED rule identity (distillRuleIdentity — CJK-aware):
|
|
33
|
+
* a verbatim/reworded repeat bumps seen_count on the existing row instead
|
|
34
|
+
* of fanning out (the ×34 repeat exemplar dedupes to one row). seen_count
|
|
35
|
+
* is a pending-side visibility counter ONLY — it is never copied into
|
|
36
|
+
* proof_count on promote (proof accrual restarts from the active ledger's
|
|
37
|
+
* own consolidation rules).
|
|
38
|
+
*/
|
|
39
|
+
import * as fs from "node:fs";
|
|
40
|
+
import * as path from "node:path";
|
|
41
|
+
import * as crypto from "node:crypto";
|
|
42
|
+
import { ensureDir } from "./fs-utils.js";
|
|
43
|
+
import { byteCap, sanitizeName } from "./sanitize.js";
|
|
44
|
+
import { projectSubPath } from "./paths.js";
|
|
45
|
+
import { withLock } from "./filelock.js";
|
|
46
|
+
import { scrubForCloud } from "./content-guard.js";
|
|
47
|
+
import { detectSeverity, distillRuleIdentity, dropHardNoise, isLikelyRealCorrection, splitSentences, stripInterjections, writeRecordAtomic, } from "./corrections.js";
|
|
48
|
+
import { HAN_CHAR_RE, tokenizeWords } from "../helpers/tokenize.js";
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Constants
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/** Hard cap on staged rows per project — oldest are evicted (logged) beyond it. */
|
|
53
|
+
export const PENDING_CAP = 200;
|
|
54
|
+
/** Days a staged row may await review before it expires (logged, pruned). */
|
|
55
|
+
export const PENDING_TTL_DAYS = 14;
|
|
56
|
+
/** Cap for the append-only audit logs — mirrors corrections.ts's REJECTED_LOG_CAP. */
|
|
57
|
+
const AUDIT_LOG_CAP = 2000;
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Paths
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
export function pendingDir(project) {
|
|
62
|
+
return path.join(projectSubPath(project, "corrections"), "_pending");
|
|
63
|
+
}
|
|
64
|
+
function rejectedLogPath(project) {
|
|
65
|
+
return path.join(pendingDir(project), "_rejected.jsonl");
|
|
66
|
+
}
|
|
67
|
+
function resolvedLogPath(project) {
|
|
68
|
+
return path.join(pendingDir(project), "_resolved.jsonl");
|
|
69
|
+
}
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Audit logs — append-only, capped, never throw
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
function appendAuditLine(logPath, row) {
|
|
74
|
+
try {
|
|
75
|
+
ensureDir(path.dirname(logPath));
|
|
76
|
+
fs.appendFileSync(logPath, scrubForCloud(JSON.stringify(row)) + "\n", "utf-8");
|
|
77
|
+
// Best-effort rotation, mirroring corrections.ts's _rejected.jsonl cap.
|
|
78
|
+
const raw = fs.readFileSync(logPath, "utf-8");
|
|
79
|
+
const lines = raw.split("\n").filter(Boolean);
|
|
80
|
+
if (lines.length > AUDIT_LOG_CAP) {
|
|
81
|
+
fs.writeFileSync(logPath, lines.slice(-AUDIT_LOG_CAP).join("\n") + "\n", "utf-8");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// An audit write can NEVER throw into a capture/read path.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function logPendingRejection(project, detail) {
|
|
89
|
+
appendAuditLine(rejectedLogPath(project), {
|
|
90
|
+
ts: new Date().toISOString(),
|
|
91
|
+
project,
|
|
92
|
+
id: detail.id,
|
|
93
|
+
rule: detail.rule,
|
|
94
|
+
...(detail.context && detail.context !== detail.rule ? { context: detail.context } : {}),
|
|
95
|
+
reason: detail.reason,
|
|
96
|
+
channel: detail.channel,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Read / prune
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
function readPendingRaw(project) {
|
|
103
|
+
const dir = pendingDir(project);
|
|
104
|
+
if (!fs.existsSync(dir))
|
|
105
|
+
return [];
|
|
106
|
+
let files;
|
|
107
|
+
try {
|
|
108
|
+
files = fs.readdirSync(dir);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const out = [];
|
|
114
|
+
for (const file of files) {
|
|
115
|
+
if (!file.endsWith(".json") || file.startsWith("_"))
|
|
116
|
+
continue;
|
|
117
|
+
try {
|
|
118
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(dir, file), "utf-8"));
|
|
119
|
+
if (parsed && typeof parsed.id === "string")
|
|
120
|
+
out.push({ file, record: parsed });
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// skip malformed — never throw from a read helper
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
function isExpired(record, nowMs) {
|
|
129
|
+
const t = new Date(record.last_seen ?? record.ts).getTime();
|
|
130
|
+
if (Number.isNaN(t))
|
|
131
|
+
return false;
|
|
132
|
+
return nowMs - t > PENDING_TTL_DAYS * 24 * 60 * 60 * 1000;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* TTL + cap sweep. Expired rows and cap overflow (oldest-first by last_seen)
|
|
136
|
+
* are removed from disk and logged to _rejected.jsonl — pruned, never vanished.
|
|
137
|
+
* Best-effort: any error leaves the store as-is.
|
|
138
|
+
*/
|
|
139
|
+
function prunePending(project, nowMs = Date.now()) {
|
|
140
|
+
try {
|
|
141
|
+
const dir = pendingDir(project);
|
|
142
|
+
const all = readPendingRaw(project);
|
|
143
|
+
const keep = [];
|
|
144
|
+
for (const entry of all) {
|
|
145
|
+
if (isExpired(entry.record, nowMs)) {
|
|
146
|
+
logPendingRejection(project, {
|
|
147
|
+
id: entry.record.id,
|
|
148
|
+
rule: entry.record.rule,
|
|
149
|
+
reason: `pending TTL expired (>${PENDING_TTL_DAYS}d without review)`,
|
|
150
|
+
channel: entry.record.channel,
|
|
151
|
+
});
|
|
152
|
+
try {
|
|
153
|
+
fs.unlinkSync(path.join(dir, entry.file));
|
|
154
|
+
}
|
|
155
|
+
catch { /* best effort */ }
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
keep.push(entry);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (keep.length > PENDING_CAP) {
|
|
162
|
+
keep.sort((a, b) => new Date(a.record.last_seen ?? a.record.ts).getTime() -
|
|
163
|
+
new Date(b.record.last_seen ?? b.record.ts).getTime());
|
|
164
|
+
const evict = keep.slice(0, keep.length - PENDING_CAP);
|
|
165
|
+
for (const entry of evict) {
|
|
166
|
+
logPendingRejection(project, {
|
|
167
|
+
id: entry.record.id,
|
|
168
|
+
rule: entry.record.rule,
|
|
169
|
+
reason: `pending cap evicted (store held >${PENDING_CAP} rows)`,
|
|
170
|
+
channel: entry.record.channel,
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
fs.unlinkSync(path.join(dir, entry.file));
|
|
174
|
+
}
|
|
175
|
+
catch { /* best effort */ }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// pruning must never break a capture or a session_start read
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* List staged rows, newest (last_seen) first. Runs the TTL/cap sweep first so
|
|
185
|
+
* a reader never sees an expired row. Never throws.
|
|
186
|
+
*/
|
|
187
|
+
export async function listPendingCorrections(project) {
|
|
188
|
+
try {
|
|
189
|
+
return await withLock(`pending-${project}`, () => {
|
|
190
|
+
prunePending(project);
|
|
191
|
+
return readPendingRaw(project)
|
|
192
|
+
.map((e) => e.record)
|
|
193
|
+
.sort((a, b) => new Date(b.last_seen ?? b.ts).getTime() - new Date(a.last_seen ?? a.ts).getTime());
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// Stage
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
function pendingId(date, scrubbedRule, identity) {
|
|
204
|
+
const slug = byteCap(sanitizeName(stripInterjections(scrubbedRule) || scrubbedRule || "pending", 32), 32)
|
|
205
|
+
.replace(/-+$/g, "") || "pending";
|
|
206
|
+
const hash = crypto.createHash("sha256").update(identity || scrubbedRule).digest("hex").slice(0, 6);
|
|
207
|
+
return `${date}--${slug}-${hash}`;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Stage a capture into _pending/. Hard-noise input (corrections.ts's
|
|
211
|
+
* dropHardNoise floor, checked on rule AND context) goes straight to
|
|
212
|
+
* _rejected.jsonl with provenance — it is not worth a review row, but it is
|
|
213
|
+
* never silently dropped. Repeats (same distilled rule identity, same kind)
|
|
214
|
+
* fold into the existing row (seen_count++).
|
|
215
|
+
*/
|
|
216
|
+
export async function stagePendingCorrection(project, input) {
|
|
217
|
+
const contextRaw = (input.text ?? "").trim();
|
|
218
|
+
const ruleRaw = (input.rule ?? (splitSentences(contextRaw)[0] ?? contextRaw)).slice(0, 100).trim();
|
|
219
|
+
const rule = scrubForCloud(ruleRaw);
|
|
220
|
+
const context = scrubForCloud(contextRaw);
|
|
221
|
+
if (!dropHardNoise(ruleRaw) && !dropHardNoise(contextRaw)) {
|
|
222
|
+
const reason = `hard-noise capture (${input.reason})`;
|
|
223
|
+
logPendingRejection(project, { rule: context.length > rule.length ? context : rule, reason, channel: input.channel });
|
|
224
|
+
return { staged: false, rejected: true, reason };
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
return await withLock(`pending-${project}`, () => {
|
|
228
|
+
const dir = pendingDir(project);
|
|
229
|
+
ensureDir(dir);
|
|
230
|
+
const now = new Date();
|
|
231
|
+
const nowISO = now.toISOString();
|
|
232
|
+
const date = nowISO.slice(0, 10);
|
|
233
|
+
const identity = distillRuleIdentity(rule);
|
|
234
|
+
// Dedupe by distilled identity (same kind) — repeats gain visibility, not
|
|
235
|
+
// rows. Review fix (2026-09-11, HIGH-2 guard): an EMPTY identity (rule
|
|
236
|
+
// made entirely of stripped symbols) must never match anything — without
|
|
237
|
+
// this, distinct symbol-only captures would fold into one row.
|
|
238
|
+
for (const entry of identity ? readPendingRaw(project) : []) {
|
|
239
|
+
if (entry.record.kind !== input.kind)
|
|
240
|
+
continue;
|
|
241
|
+
if (distillRuleIdentity(entry.record.rule) !== identity)
|
|
242
|
+
continue;
|
|
243
|
+
const merged = {
|
|
244
|
+
...entry.record,
|
|
245
|
+
seen_count: (entry.record.seen_count ?? 1) + 1,
|
|
246
|
+
last_seen: nowISO,
|
|
247
|
+
};
|
|
248
|
+
writeRecordAtomic(path.join(dir, entry.file), merged);
|
|
249
|
+
return { staged: true, merged: true, id: merged.id };
|
|
250
|
+
}
|
|
251
|
+
const record = {
|
|
252
|
+
id: pendingId(date, rule, identity),
|
|
253
|
+
ts: nowISO,
|
|
254
|
+
last_seen: nowISO,
|
|
255
|
+
seen_count: 1,
|
|
256
|
+
project,
|
|
257
|
+
kind: input.kind,
|
|
258
|
+
channel: input.channel,
|
|
259
|
+
rule,
|
|
260
|
+
context,
|
|
261
|
+
// Same severity classifier a direct capture would get (S-M1 twin:
|
|
262
|
+
// the classifier sees ONLY what the caller scoped into `text`).
|
|
263
|
+
severity: detectSeverity(`${ruleRaw} ${contextRaw}`),
|
|
264
|
+
...(input.applies_when && input.applies_when.length > 0
|
|
265
|
+
? { applies_when: input.applies_when.map((t) => scrubForCloud(t)) }
|
|
266
|
+
: {}),
|
|
267
|
+
reason: input.reason,
|
|
268
|
+
provenance: { source: input.source ?? input.channel, mode: "told" },
|
|
269
|
+
};
|
|
270
|
+
writeRecordAtomic(path.join(dir, `${record.id}.json`), record);
|
|
271
|
+
prunePending(project);
|
|
272
|
+
return { staged: true, merged: false, id: record.id };
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
// Staging must never throw into check()/session_end/hook paths — but the
|
|
277
|
+
// failure is still not silent: log it to the audit trail if possible.
|
|
278
|
+
const reason = `staging failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
279
|
+
logPendingRejection(project, { rule, reason, channel: input.channel });
|
|
280
|
+
return { staged: false, reason };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
// Resolve (promote / reject)
|
|
285
|
+
// ---------------------------------------------------------------------------
|
|
286
|
+
/**
|
|
287
|
+
* Resolve a staged row by id. "promote" removes the row and writes a
|
|
288
|
+
* promotion audit line (the ACTIVE write itself is the caller's job — check()
|
|
289
|
+
* runs the validated structured write first, then resolves). "reject" removes
|
|
290
|
+
* the row and appends it to _rejected.jsonl with the reviewer's reason.
|
|
291
|
+
*/
|
|
292
|
+
export async function resolvePendingCorrection(project, id, action, detail) {
|
|
293
|
+
try {
|
|
294
|
+
return await withLock(`pending-${project}`, () => {
|
|
295
|
+
const dir = pendingDir(project);
|
|
296
|
+
const entry = readPendingRaw(project).find((e) => e.record.id === id);
|
|
297
|
+
if (!entry) {
|
|
298
|
+
return { success: false, error: `pending correction not found: ${id}` };
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
fs.unlinkSync(path.join(dir, entry.file));
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
return { success: false, error: `could not remove pending row: ${err instanceof Error ? err.message : String(err)}` };
|
|
305
|
+
}
|
|
306
|
+
if (action === "promote") {
|
|
307
|
+
appendAuditLine(resolvedLogPath(project), {
|
|
308
|
+
ts: new Date().toISOString(),
|
|
309
|
+
project,
|
|
310
|
+
id,
|
|
311
|
+
action: "promoted",
|
|
312
|
+
correction_id: detail?.correction_id,
|
|
313
|
+
rule: entry.record.rule,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
logPendingRejection(project, {
|
|
318
|
+
id,
|
|
319
|
+
rule: entry.record.rule,
|
|
320
|
+
reason: detail?.reason ?? "rejected at review",
|
|
321
|
+
channel: entry.record.channel,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return { success: true, record: entry.record };
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
328
|
+
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Connective/filler words that can never stand alone as an applies_when
|
|
333
|
+
* context token. English-only by design (CJK tokens carry content by
|
|
334
|
+
* construction); lowercase-compared.
|
|
335
|
+
*/
|
|
336
|
+
const FRAGMENT_WORDS = new Set([
|
|
337
|
+
"then", "don't", "dont", "good", "bad", "and", "or", "but", "the", "a", "an",
|
|
338
|
+
"so", "if", "it", "its", "this", "that", "these", "those", "also", "just",
|
|
339
|
+
"ok", "okay", "yes", "no", "not", "do", "don", "does", "did", "t", "of",
|
|
340
|
+
"to", "in", "on", "at", "is", "are", "was", "were", "be", "been", "being",
|
|
341
|
+
"with", "for", "as", "by", "very", "when", "how", "why", "what",
|
|
342
|
+
]);
|
|
343
|
+
/** Leading/trailing punctuation or symbol — "good," / "@thing" are fragments. */
|
|
344
|
+
const EDGE_PUNCT_RE = /^[\p{P}\p{S}]|[\p{P}\p{S}]$/u;
|
|
345
|
+
/**
|
|
346
|
+
* True when `token` is a REAL context keyword: non-empty, no stray edge
|
|
347
|
+
* punctuation, not a bare connective/filler, not a single ASCII character.
|
|
348
|
+
* Multi-word phrases ("rate limiting") qualify when at least one word is
|
|
349
|
+
* real; CJK entries qualify on Han content.
|
|
350
|
+
*/
|
|
351
|
+
export function isRealAppliesWhenToken(token) {
|
|
352
|
+
const t = (token ?? "").trim();
|
|
353
|
+
if (!t)
|
|
354
|
+
return false;
|
|
355
|
+
// Han check FIRST (review fix 2026-09-11, code-review LOW): a CJK entry
|
|
356
|
+
// qualifies on Han content even with trailing full-width punctuation
|
|
357
|
+
// ("版本决定。") — the edge-punctuation fragment signal is an ASCII heuristic.
|
|
358
|
+
if (HAN_CHAR_RE.test(t))
|
|
359
|
+
return true;
|
|
360
|
+
if (EDGE_PUNCT_RE.test(t))
|
|
361
|
+
return false;
|
|
362
|
+
const words = t.toLowerCase().split(/\s+/).filter(Boolean);
|
|
363
|
+
if (words.length === 0)
|
|
364
|
+
return false;
|
|
365
|
+
const realWords = words.filter((w) => w.length > 1 && !FRAGMENT_WORDS.has(w));
|
|
366
|
+
return realWords.length > 0;
|
|
367
|
+
}
|
|
368
|
+
function appliesWhenFailures(applies_when) {
|
|
369
|
+
if (!applies_when || applies_when.length === 0) {
|
|
370
|
+
return [{ field: "applies_when", reason: "applies_when is required — provide 1-5 REAL context keywords (topics/domains where this applies)" }];
|
|
371
|
+
}
|
|
372
|
+
const fragments = applies_when.filter((t) => !isRealAppliesWhenToken(t));
|
|
373
|
+
if (fragments.length > 0) {
|
|
374
|
+
return [{
|
|
375
|
+
field: "applies_when",
|
|
376
|
+
reason: `applies_when contains sentence fragments, not context keywords: ${JSON.stringify(fragments)} — use real topic words like ["git","deploy"] or ["版本决定"]`,
|
|
377
|
+
}];
|
|
378
|
+
}
|
|
379
|
+
return [];
|
|
380
|
+
}
|
|
381
|
+
function buildInstruction(kind, failures) {
|
|
382
|
+
const what = failures.map((f) => `${f.field}: ${f.reason}`).join(" | ");
|
|
383
|
+
if (kind === "correction") {
|
|
384
|
+
return (`NOT activated — fix and re-call check() with human_correction as an OBJECT ` +
|
|
385
|
+
`{rule, why, applies_when}. rule = ONE imperative, self-contained sentence stating the durable behavior ` +
|
|
386
|
+
`(e.g. "Never publish without explicit owner approval" / "发布前必须获得用户确认"); ` +
|
|
387
|
+
`why = the concrete evidence (what happened that makes this a rule); ` +
|
|
388
|
+
`applies_when = 1-5 real context keywords (e.g. ["git","deploy"]). ` +
|
|
389
|
+
`To confirm a staged item, include its pending_id; to discard one, pass {pending_id, resolution:"reject"}. ` +
|
|
390
|
+
`Problems found → ${what}`);
|
|
391
|
+
}
|
|
392
|
+
return (`Insight staged to _pending/, not added to awareness — restate it as ` +
|
|
393
|
+
`{title, evidence, applies_when}: title = one full sentence stating the reusable pattern; ` +
|
|
394
|
+
`evidence = what concretely happened; applies_when = 1-5 real context keywords. ` +
|
|
395
|
+
`Problems found → ${what}`);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* L1 — check()'s structured human_correction {rule, why, applies_when}.
|
|
399
|
+
* rule must be an actionable IMPERATIVE rule sentence (the same
|
|
400
|
+
* isLikelyRealCorrection classifier the capture gate runs — a question or
|
|
401
|
+
* business/status sentence fails); why must be non-empty; applies_when must
|
|
402
|
+
* be real tokens.
|
|
403
|
+
*/
|
|
404
|
+
export function validateStructuredCorrection(candidate) {
|
|
405
|
+
const failures = [];
|
|
406
|
+
const rule = (candidate.rule ?? "").trim();
|
|
407
|
+
if (!rule) {
|
|
408
|
+
failures.push({ field: "rule", reason: "rule is required — one imperative sentence stating the durable behavior" });
|
|
409
|
+
}
|
|
410
|
+
else if (!dropHardNoise(rule)) {
|
|
411
|
+
failures.push({ field: "rule", reason: "rule looks like noise (too short / system fragment / pasted header) — state the behavior in one full sentence" });
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
const gate = isLikelyRealCorrection(rule);
|
|
415
|
+
if (!gate.ok) {
|
|
416
|
+
failures.push({
|
|
417
|
+
field: "rule",
|
|
418
|
+
reason: `rule is not an imperative rule sentence (${gate.reason ?? "no actionable signal"}) — a question or status statement cannot become a correction`,
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (!(candidate.why ?? "").trim()) {
|
|
423
|
+
failures.push({ field: "why", reason: "why is required — the concrete evidence behind this rule (what happened / what the human said)" });
|
|
424
|
+
}
|
|
425
|
+
failures.push(...appliesWhenFailures(candidate.applies_when));
|
|
426
|
+
if (failures.length === 0)
|
|
427
|
+
return { ok: true, failures: [] };
|
|
428
|
+
return { ok: false, failures, agent_instruction: buildInstruction("correction", failures) };
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* L2 — session_end insights. Same completeness bar, calibrated for insight
|
|
432
|
+
* titles: a FULL-SENTENCE title (≥20 chars, ≥3 content tokens — declarative
|
|
433
|
+
* pattern statements qualify; fragments like "fixed bug" do not), non-empty
|
|
434
|
+
* evidence, and real applies_when tokens.
|
|
435
|
+
*/
|
|
436
|
+
export function validateInsightCompleteness(insight) {
|
|
437
|
+
const failures = [];
|
|
438
|
+
const title = (insight.title ?? "").trim();
|
|
439
|
+
const titleTokens = tokenizeWords(title, { minLength: 1 });
|
|
440
|
+
if (title.length < 20 || titleTokens.length < 3) {
|
|
441
|
+
failures.push({ field: "title", reason: "title must be one full sentence stating the reusable pattern (≥20 chars, ≥3 words) — not an event fragment" });
|
|
442
|
+
}
|
|
443
|
+
else if (!dropHardNoise(title)) {
|
|
444
|
+
failures.push({ field: "title", reason: "title looks like noise (system fragment / pasted header)" });
|
|
445
|
+
}
|
|
446
|
+
if (!(insight.evidence ?? "").trim()) {
|
|
447
|
+
failures.push({ field: "evidence", reason: "evidence is required — what concretely happened that confirmed this insight" });
|
|
448
|
+
}
|
|
449
|
+
failures.push(...appliesWhenFailures(insight.applies_when));
|
|
450
|
+
if (failures.length === 0)
|
|
451
|
+
return { ok: true, failures: [] };
|
|
452
|
+
return { ok: false, failures, agent_instruction: buildInstruction("insight", failures) };
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=pending.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending.js","sourceRoot":"","sources":["../../src/storage/pending.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B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QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC7D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAgC/C;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAyBxD;AAwFD;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CA+GrD;AAyBD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAmEjF;AAaD;;GAEG;AACH,wBAAgB,eAAe,IAAI,WAAW,EAAE,CA8D/C"}
|
package/dist/storage/project.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as path from "node:path";
|
|
|
6
6
|
import { execFile } from "node:child_process";
|
|
7
7
|
import { promisify } from "node:util";
|
|
8
8
|
import { getLegacyRoot } from "../types.js";
|
|
9
|
-
import { projectsRootDir } from "./paths.js";
|
|
9
|
+
import { projectsRootDir, UNCLAIMED_PROJECT, isUnclaimedProject } from "./paths.js";
|
|
10
10
|
const execFileAsync = promisify(execFile);
|
|
11
11
|
/**
|
|
12
12
|
* Common directory names that are not valid project slugs.
|
|
@@ -24,6 +24,14 @@ const BLOCKED_SLUGS = new Set([
|
|
|
24
24
|
const SLUG_DENY_LIST = new Set([
|
|
25
25
|
"build", "runtime", "palace", "mcp", "default",
|
|
26
26
|
"phase-1", "monitor", "test",
|
|
27
|
+
// fix5 (2026-09-11): the literal "auto" is the resolve-me API sentinel
|
|
28
|
+
// (`resolveProject` special-cases it BEFORE this list is consulted), never
|
|
29
|
+
// a legitimate project name — yet through v3.4.48 it passed this gate, so
|
|
30
|
+
// card/rescue writers that fell back to a literal "auto" slug materialized
|
|
31
|
+
// the projects/auto/ dumping ground (422+ journals on the live store).
|
|
32
|
+
// Same deny-class as "default"; adding the row here closes every gate that
|
|
33
|
+
// consults isValidProjectSlug at once (class-not-instance).
|
|
34
|
+
"auto",
|
|
27
35
|
]);
|
|
28
36
|
/**
|
|
29
37
|
* Validate whether a string is a legitimate project slug.
|
|
@@ -265,6 +273,29 @@ export async function detectProject() {
|
|
|
265
273
|
// 7. Final fallback: use the directory name even if it matches username
|
|
266
274
|
return candidate || "default";
|
|
267
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* fix5 (2026-09-11) — record provenance for a staged (failed) resolution.
|
|
278
|
+
* Fire-and-forget and NEVER throws/rejects: provenance is metadata about a
|
|
279
|
+
* failure, and it must never turn a working staged write into a broken one.
|
|
280
|
+
* Uses a dynamic import (the same pattern this file already uses for
|
|
281
|
+
* cwd-allowlist.js) so the unclaimed module's own static import of
|
|
282
|
+
* `isValidProjectSlug` from THIS file never forms a static cycle.
|
|
283
|
+
*/
|
|
284
|
+
async function stageFailedResolution(reason, candidate) {
|
|
285
|
+
try {
|
|
286
|
+
const { recordUnclaimedProvenance } = await import("./unclaimed.js");
|
|
287
|
+
const { getSessionId } = await import("./session.js");
|
|
288
|
+
recordUnclaimedProvenance(getSessionId(), {
|
|
289
|
+
cwd: process.cwd(),
|
|
290
|
+
reason,
|
|
291
|
+
slug_candidates: candidate ? [{ slug: candidate, count: 1 }] : [],
|
|
292
|
+
slug_confidence: 0,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
// provenance is best-effort — never let it break resolution
|
|
297
|
+
}
|
|
298
|
+
}
|
|
268
299
|
/**
|
|
269
300
|
* Resolve "auto" project to actual slug.
|
|
270
301
|
*
|
|
@@ -280,22 +311,36 @@ export async function detectProject() {
|
|
|
280
311
|
* invalid slugs still resolve so reads of legacy data don't break.
|
|
281
312
|
*/
|
|
282
313
|
export async function resolveProject(project) {
|
|
314
|
+
// fix5 (2026-09-11): the staging sentinel round-trips. A caller that
|
|
315
|
+
// already holds a staged resolution (e.g. `ar saveall` for a session with
|
|
316
|
+
// no project guess) must be able to pass it back through the normal
|
|
317
|
+
// resolution seam without tripping the invalid-slug throw below — the
|
|
318
|
+
// sentinel is deliberately NOT a valid slug so nothing else accepts it.
|
|
319
|
+
// No allowlist registration, no dir probe: it is not a project.
|
|
320
|
+
if (isUnclaimedProject(project))
|
|
321
|
+
return UNCLAIMED_PROJECT;
|
|
283
322
|
if (!project || project === "auto") {
|
|
284
|
-
|
|
285
|
-
//
|
|
323
|
+
// fix5 (2026-09-11, eval-standard S5 plan #5): a FAILED auto-detection no
|
|
324
|
+
// longer throws, and an INVALID auto-detected slug no longer resolves to
|
|
325
|
+
// a legacy junk dir — both return the staging sentinel instead, so the
|
|
326
|
+
// caller's write routes to `_unclaimed/<session>/` (projectSubPath's
|
|
327
|
+
// sentinel seam) and can NEVER materialize `projects/<garbage>`. This
|
|
328
|
+
// removes the old existing-dir escape hatch FOR AUTO-DETECTION ONLY: it
|
|
329
|
+
// let new writes keep landing in `default/`-class dumping grounds just
|
|
330
|
+
// because the dir already existed. Ghost/legacy dirs remain fully
|
|
331
|
+
// readable when EXPLICITLY scoped (the explicit-slug branch below is
|
|
332
|
+
// unchanged) — the eval's gq20 relies on exactly that.
|
|
333
|
+
let detected;
|
|
334
|
+
try {
|
|
335
|
+
detected = await detectProject();
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
await stageFailedResolution("detect-failed", null);
|
|
339
|
+
return UNCLAIMED_PROJECT;
|
|
340
|
+
}
|
|
286
341
|
if (!isValidProjectSlug(detected)) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
// creation unless legacy data already exists at this exact name) — running
|
|
290
|
-
// it through the sanitizing resolver would change what "exists" means for
|
|
291
|
-
// exactly the malformed inputs this gate exists to catch. Only the literal
|
|
292
|
-
// "projects" segment is routed through paths.ts (F2 fix, 2026-07-20).
|
|
293
|
-
const projectDir = path.join(projectsRootDir(), detected);
|
|
294
|
-
if (!fs.existsSync(projectDir)) {
|
|
295
|
-
throw new Error(`Auto-detected project slug "${detected}" is invalid (UUID, system dir, or deny-listed). ` +
|
|
296
|
-
`Set AGENT_RECALL_PROJECT env var or pass project explicitly.`);
|
|
297
|
-
}
|
|
298
|
-
// Existing dir — allow read but don't register into allowlist
|
|
342
|
+
await stageFailedResolution(`invalid-detected:${detected}`, detected);
|
|
343
|
+
return UNCLAIMED_PROJECT;
|
|
299
344
|
}
|
|
300
345
|
return detected;
|
|
301
346
|
}
|
|
@@ -352,7 +397,14 @@ export function listAllProjects() {
|
|
|
352
397
|
// New location
|
|
353
398
|
const projectsDir = projectsRootDir();
|
|
354
399
|
if (fs.existsSync(projectsDir)) {
|
|
355
|
-
|
|
400
|
+
// fix5 (2026-09-11): exclude the reserved `_` namespace BY NAME (leading
|
|
401
|
+
// underscore — the same class rule fix4 applies to `_pending/`/`_index.md`
|
|
402
|
+
// infra files, class-not-instance). `_unclaimed/` lives at the store ROOT
|
|
403
|
+
// and never appears here in normal operation; this guard is the
|
|
404
|
+
// belt-and-braces for an external script (registry regen, a manual copy)
|
|
405
|
+
// dropping an underscore dir INSIDE projects/ — it must never enumerate
|
|
406
|
+
// as a project.
|
|
407
|
+
const dirs = fs.readdirSync(projectsDir).filter((d) => !d.startsWith("_"));
|
|
356
408
|
for (const slug of dirs) {
|
|
357
409
|
const jDir = path.join(projectsDir, slug, "journal");
|
|
358
410
|
if (fs.existsSync(jDir)) {
|