thumbgate 1.39.0 → 1.40.1
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/.agents/skills/craft-playbook-gate/SKILL.md +51 -0
- package/.agents/skills/qwenwork-policy-group-honesty-not-clone/SKILL.md +36 -0
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/llms.txt +2 -2
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +11 -5
- package/adapters/claude/.mcp.json +6 -2
- package/adapters/codex/config.toml +5 -0
- package/adapters/forge/forge.yaml +4 -4
- package/adapters/future-agi/.mcp.json +1 -1
- package/adapters/future-agi/config.toml +1 -1
- package/adapters/future-agi/opencode.json +1 -1
- package/adapters/herdr/herdr-plugin.toml +2 -2
- package/adapters/mcp/server-stdio.js +104 -7
- package/adapters/opencode/opencode.json +1 -1
- package/adapters/strands/strands-middleware.js +31 -4
- package/bin/cli.js +191 -54
- package/config/brand-standards.json +131 -0
- package/config/gates/default.json +18 -1
- package/config/github-about.json +1 -1
- package/config/mcp-allowlists.json +16 -3
- package/config/merge-quality-checks.json +3 -1
- package/config/post-deploy-marketing-pages.json +4 -4
- package/config/schemas/task-outcome-receipt.schema.json +9 -0
- package/hooks/hooks.json +24 -0
- package/openapi/openapi.yaml +7 -3
- package/package.json +87 -33
- package/public/about.html +2 -2
- package/public/admin.html +771 -0
- package/public/agent-manager.html +3 -3
- package/public/agents-cost-savings.html +1 -1
- package/public/ai-malpractice-prevention.html +12 -12
- package/public/architecture.html +0 -1
- package/public/assets/diagrams/decision.svg +3 -3
- package/public/assets/diagrams/hero-thumbs.svg +2 -4
- package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
- package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
- package/public/blog/git-at-agent-scale.html +2 -2
- package/public/blog/inside-your-boundary.html +1 -1
- package/public/blog/process-over-outcome-gates.html +1 -1
- package/public/case-studies.html +5 -6
- package/public/codex-enterprise.html +1 -1
- package/public/codex-plugin.html +1 -1
- package/public/dashboard.html +775 -483
- package/public/diagnostic.html +15 -10
- package/public/enterprise-governance.html +26 -174
- package/public/eval-scorecard.html +3 -4
- package/public/eval-scorecard.json +2 -2
- package/public/evaluations.html +0 -1
- package/public/founders.html +3 -3
- package/public/gaming-playbook.html +4 -4
- package/public/guide.html +3 -5
- package/public/index.html +302 -97
- package/public/install.html +16 -10
- package/public/js/buyer-intent.js +49 -8
- package/public/lessons.html +246 -83
- package/public/numbers.html +32 -33
- package/public/operator-framework.html +44 -72
- package/public/peter.html +3 -3
- package/public/platform-partners.html +1 -1
- package/public/pricing.html +163 -66
- package/public/pro.html +3 -1
- package/public/project-switcher.js +76 -0
- package/public/whitepaper.html +1 -2
- package/scripts/action-receipts.js +393 -0
- package/scripts/activation-quickstart.js +15 -3
- package/scripts/activation-tracker.js +280 -3
- package/scripts/agent-action-inventory.js +235 -143
- package/scripts/agent-operations-planner.js +1 -1
- package/scripts/agent-readiness.js +36 -6
- package/scripts/agentic-prompt-pipelines.js +901 -0
- package/scripts/analytics-window.js +7 -1
- package/scripts/async-job-runner.js +66 -11
- package/scripts/audit-trail.js +37 -24
- package/scripts/auto-promote-gates.js +37 -27
- package/scripts/auto-wire-hooks.js +64 -25
- package/scripts/backfill-lesson-scopes.js +122 -0
- package/scripts/billing.js +889 -132
- package/scripts/bot-detection.js +112 -0
- package/scripts/brand-standards-gate.js +571 -0
- package/scripts/chatgpt-ads-readiness-pack.js +1 -1
- package/scripts/cli-demo.js +5 -27
- package/scripts/cli-schema.js +25 -1
- package/scripts/commercial-offer.js +2 -2
- package/scripts/contextfs.js +9 -3
- package/scripts/craft-playbook-gate.js +550 -0
- package/scripts/cross-encoder-reranker.js +4 -0
- package/scripts/dashboard-chat.js +11 -0
- package/scripts/dashboard.js +574 -167
- package/scripts/decision-journal.js +7 -4
- package/scripts/docker-sandbox-planner.js +3 -3
- package/scripts/export-dpo-pairs.js +12 -7
- package/scripts/failure-diagnostics.js +11 -0
- package/scripts/feedback-aggregate.js +4 -0
- package/scripts/feedback-attribution.js +6 -4
- package/scripts/feedback-history-distiller.js +18 -6
- package/scripts/feedback-loop.js +255 -89
- package/scripts/feedback-paths.js +8 -1
- package/scripts/feedback-sanitizer.js +5 -0
- package/scripts/feedback-scope.js +106 -0
- package/scripts/feedback-session.js +8 -2
- package/scripts/filesystem-search.js +13 -8
- package/scripts/financial-control-plane.js +707 -45
- package/scripts/gate-stats.js +38 -5
- package/scripts/gates-engine.js +1326 -240
- package/scripts/generate-eval-scorecard.js +0 -1
- package/scripts/gitlab-sdlc-prompts.js +397 -0
- package/scripts/harness-tool-names.js +31 -5
- package/scripts/hook-runtime.js +10 -0
- package/scripts/hybrid-feedback-context.js +7 -2
- package/scripts/intervention-policy.js +2 -1
- package/scripts/lesson-canonical.js +2 -2
- package/scripts/lesson-db.js +55 -14
- package/scripts/lesson-graph.js +2 -1
- package/scripts/lesson-retrieval.js +95 -9
- package/scripts/lesson-search.js +86 -22
- package/scripts/lesson-synthesis.js +21 -5
- package/scripts/mabl-failure-honesty.js +273 -0
- package/scripts/mailer/index.js +17 -1
- package/scripts/mailer/resend-mailer.js +213 -179
- package/scripts/migrate-project-scope.js +209 -0
- package/scripts/model-distress-detector.js +3 -3
- package/scripts/operational-integrity.js +436 -3
- package/scripts/override-audit.js +2 -0
- package/scripts/owner-admin.js +338 -0
- package/scripts/pr-manager.js +194 -1
- package/scripts/product-feedback.js +35 -0
- package/scripts/progressive-signoff.js +260 -0
- package/scripts/project-catalog.js +243 -0
- package/scripts/project-dashboard.js +61 -0
- package/scripts/project-evidence.js +172 -0
- package/scripts/project-identity.js +182 -0
- package/scripts/project-scope.js +381 -0
- package/scripts/prompt-eval.js +1 -1
- package/scripts/prompt-guard.js +446 -52
- package/scripts/proof-report.js +232 -0
- package/scripts/provider-action-normalizer.js +14 -6
- package/scripts/qwenwork-policy-group.js +413 -0
- package/scripts/rate-limiter.js +41 -0
- package/scripts/secret-redaction.js +171 -25
- package/scripts/secret-scanner.js +101 -42
- package/scripts/self-protection.js +2 -2
- package/scripts/seo-gsd.js +14 -14
- package/scripts/session-context-dedupe.js +66 -0
- package/scripts/settings-hierarchy.js +4 -2
- package/scripts/statusline-meta.js +34 -23
- package/scripts/tailscale-october-access.js +416 -0
- package/scripts/task-outcomes.js +58 -2
- package/scripts/telemetry-analytics.js +260 -16
- package/scripts/thumbgate-search.js +23 -9
- package/scripts/tool-kpi-tracker.js +5 -2
- package/scripts/tool-registry.js +42 -1
- package/scripts/triage-savings-calculator.js +1 -1
- package/scripts/vector-store.js +4 -1
- package/scripts/verified-lessons.js +270 -0
- package/scripts/verify-marketing-pages-deployed.js +2 -2
- package/scripts/workflow-sentinel.js +29 -10
- package/server.json +2 -2
- package/src/api/server.js +2478 -470
- package/src/feedback.js +21 -0
- package/src/hermes-sync-plane.js +2 -1
- package/src/index.js +2 -0
- package/src/lesson-search.js +9 -0
- package/src/mckinsey-top-company-ai-coding.js +493 -0
- package/src/mcp/email-triage-server/index.js +973 -0
- package/src/mcp/email-triage-server/package.json +12 -0
- package/src/mcp/server.js +3 -0
- package/src/mcp-writeguard.js +772 -11
- package/src/openshell-lovable-engine.js +1475 -0
- package/src/task-outcome.js +3 -0
- package/config/evals/agent-safety-eval.json +0 -447
- package/config/evals/retrieval-ranking-golden.json +0 -522
- package/config/progressive/01-wire-only.json +0 -11
- package/config/progressive/02-dashboard-empty-ok.json +0 -10
- package/config/progressive/03-one-lesson.json +0 -10
- package/config/progressive/04-warn-fires.json +0 -11
- package/config/progressive/05-strict-optional.json +0 -11
- package/config/progressive/README.md +0 -15
- package/public/assets/diagrams/agent-integration.png +0 -0
- package/public/assets/diagrams/thumbgate-architecture.png +0 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* project-scope.js — Fixed-schema project scoping and transcript filtering
|
|
5
|
+
* for ThumbGate lesson retrieval and feedback capture.
|
|
6
|
+
*
|
|
7
|
+
* Pattern: Dual-Model MoA & Agentic GraphRAG Playbook (Schema-Constrained Extraction).
|
|
8
|
+
*
|
|
9
|
+
* Principles:
|
|
10
|
+
* 1. Zero private client/project names or usernames in the public codebase.
|
|
11
|
+
* 2. Scope resolution derives strictly from cwd, package.json, and git remote origin.
|
|
12
|
+
* 3. Transport transcript tokens (<task-notification>, <tool-use-id>, etc.) are rejected.
|
|
13
|
+
* 4. Fast cached resolution: avoids spawning git subshells on every tool call (<0.1ms).
|
|
14
|
+
* 5. Unscoped/unknown lessons are excluded from PreToolUse injection unless explicitly global.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const fs = require('node:fs');
|
|
18
|
+
const os = require('node:os');
|
|
19
|
+
const path = require('node:path');
|
|
20
|
+
const { execFileSync } = require('node:child_process');
|
|
21
|
+
|
|
22
|
+
const TRANSCRIPT_XML_TAGS = Object.freeze([
|
|
23
|
+
'<task-notification>',
|
|
24
|
+
'</task-notification>',
|
|
25
|
+
'<task-id>',
|
|
26
|
+
'</task-id>',
|
|
27
|
+
'<tool-use-id>',
|
|
28
|
+
'</tool-use-id>',
|
|
29
|
+
'<output-file>',
|
|
30
|
+
'</output-file>',
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
const GLOBAL_RULE_REGEX = /\b(?:never\s+kill\s+processes|bypass\s+branch\s+protection|git\s+worktree|fail-closed|branch\s+protection)\b/i;
|
|
34
|
+
|
|
35
|
+
const CWD_CACHE = new Map();
|
|
36
|
+
let diskCacheLoaded = false;
|
|
37
|
+
let diskCache = {};
|
|
38
|
+
|
|
39
|
+
function getDiskCachePath() {
|
|
40
|
+
return path.join(os.tmpdir(), 'thumbgate-cwd-scope-cache.json');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function loadDiskCache() {
|
|
44
|
+
if (diskCacheLoaded) return diskCache;
|
|
45
|
+
try {
|
|
46
|
+
const cacheFile = getDiskCachePath();
|
|
47
|
+
if (fs.existsSync(cacheFile)) {
|
|
48
|
+
diskCache = JSON.parse(fs.readFileSync(cacheFile, 'utf8')) || {};
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
diskCache = {};
|
|
52
|
+
}
|
|
53
|
+
diskCacheLoaded = true;
|
|
54
|
+
return diskCache;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function saveDiskCache() {
|
|
58
|
+
try {
|
|
59
|
+
const cacheFile = getDiskCachePath();
|
|
60
|
+
fs.writeFileSync(cacheFile, JSON.stringify(diskCache), 'utf8');
|
|
61
|
+
} catch {
|
|
62
|
+
// Non-fatal cache write failure
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function clearCwdCache() {
|
|
67
|
+
CWD_CACHE.clear();
|
|
68
|
+
diskCache = {};
|
|
69
|
+
diskCacheLoaded = false;
|
|
70
|
+
try {
|
|
71
|
+
const cacheFile = getDiskCachePath();
|
|
72
|
+
if (fs.existsSync(cacheFile)) {
|
|
73
|
+
fs.unlinkSync(cacheFile);
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
// Non-fatal
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const SEPARATORS = ['-', '_'];
|
|
81
|
+
const SUFFIX_MARKERS = ['wt', 'poolside', 'branch'];
|
|
82
|
+
|
|
83
|
+
// Linear-time suffix truncation (no regex backtracking — CodeQL js/polynomial-redos).
|
|
84
|
+
function truncateAtMarker(value, marker) {
|
|
85
|
+
let cut = -1;
|
|
86
|
+
for (const pre of SEPARATORS) {
|
|
87
|
+
for (const post of SEPARATORS) {
|
|
88
|
+
const idx = value.indexOf(pre + marker + post);
|
|
89
|
+
if (idx !== -1 && (cut === -1 || idx < cut)) cut = idx;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return cut === -1 ? value : value.slice(0, cut);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function normalizeProjectName(name) {
|
|
96
|
+
if (!name || typeof name !== 'string') return '';
|
|
97
|
+
let cleaned = name.trim().toLowerCase();
|
|
98
|
+
// Strip worktree and branch suffixes like -wt-..., .worktrees, etc.
|
|
99
|
+
for (const marker of SUFFIX_MARKERS) cleaned = truncateAtMarker(cleaned, marker);
|
|
100
|
+
const worktreesIdx = cleaned.indexOf('.worktrees');
|
|
101
|
+
if (worktreesIdx !== -1) cleaned = cleaned.slice(0, worktreesIdx);
|
|
102
|
+
return cleaned;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Checks if a string or lesson object contains raw transport transcript tokens.
|
|
107
|
+
*/
|
|
108
|
+
function isTranscriptShaped(input) {
|
|
109
|
+
if (!input) return false;
|
|
110
|
+
if (typeof input === 'string') {
|
|
111
|
+
const trimmed = input.trim().toLowerCase();
|
|
112
|
+
if (trimmed.startsWith('<pasted_content') || trimmed.startsWith('it ignored a prior instruction: <')) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
const lower = trimmed;
|
|
116
|
+
for (const tag of TRANSCRIPT_XML_TAGS) {
|
|
117
|
+
if (lower.includes(tag.toLowerCase())) return true;
|
|
118
|
+
}
|
|
119
|
+
return /<\s*task-notification\b|<\s*tool-use-id\b|<\s*output-file\b|<\s*task-id\b/i.test(input);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof input === 'object') {
|
|
123
|
+
const fields = [
|
|
124
|
+
input.whatWentWrong,
|
|
125
|
+
input.whatToChange,
|
|
126
|
+
input.whatWorked,
|
|
127
|
+
input.title,
|
|
128
|
+
input.content,
|
|
129
|
+
input.context,
|
|
130
|
+
input.rule?.description,
|
|
131
|
+
...(Array.isArray(input.distillation?.evidence) ? input.distillation.evidence : []),
|
|
132
|
+
];
|
|
133
|
+
for (const field of fields) {
|
|
134
|
+
if (field && isTranscriptShaped(String(field))) return true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Prefer fixed absolute git paths (Sonar S4036 — avoid bare PATH lookup). */
|
|
142
|
+
function resolveGitBinary() {
|
|
143
|
+
const candidates = [
|
|
144
|
+
process.env.GIT_BINARY,
|
|
145
|
+
'/usr/bin/git',
|
|
146
|
+
'/opt/homebrew/bin/git',
|
|
147
|
+
'/usr/local/bin/git',
|
|
148
|
+
].filter(Boolean);
|
|
149
|
+
for (const candidate of candidates) {
|
|
150
|
+
try {
|
|
151
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
152
|
+
} catch {
|
|
153
|
+
/* ignore */
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return '/usr/bin/git';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Resolve the project name from a working directory or git root with caching.
|
|
161
|
+
*/
|
|
162
|
+
function resolveProjectFromCwd(dir, options = {}) {
|
|
163
|
+
const targetDir = dir ? path.resolve(dir) : process.cwd();
|
|
164
|
+
|
|
165
|
+
if (options.noCache !== true) {
|
|
166
|
+
if (CWD_CACHE.has(targetDir)) {
|
|
167
|
+
return CWD_CACHE.get(targetDir);
|
|
168
|
+
}
|
|
169
|
+
const dCache = loadDiskCache();
|
|
170
|
+
if (dCache[targetDir]) {
|
|
171
|
+
CWD_CACHE.set(targetDir, dCache[targetDir]);
|
|
172
|
+
return dCache[targetDir];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let resolved = null;
|
|
177
|
+
|
|
178
|
+
// 1. Check nearest package.json first (pure fs, <0.1ms, zero subshell overhead)
|
|
179
|
+
try {
|
|
180
|
+
let curr = targetDir;
|
|
181
|
+
while (curr && curr !== path.dirname(curr)) {
|
|
182
|
+
const pkgPath = path.join(curr, 'package.json');
|
|
183
|
+
if (fs.existsSync(pkgPath)) {
|
|
184
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
185
|
+
if (pkg.name) {
|
|
186
|
+
const pkgName = pkg.name.startsWith('@') ? pkg.name.split('/')[1] : pkg.name;
|
|
187
|
+
resolved = pkgName;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
curr = path.dirname(curr);
|
|
192
|
+
}
|
|
193
|
+
} catch {
|
|
194
|
+
// fall through
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 2. Try git remote origin URL
|
|
198
|
+
if (!resolved) {
|
|
199
|
+
try {
|
|
200
|
+
const gitBin = resolveGitBinary();
|
|
201
|
+
const gitOutput = execFileSync(gitBin, ['-C', targetDir, 'config', '--get', 'remote.origin.url'], {
|
|
202
|
+
encoding: 'utf8',
|
|
203
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
204
|
+
timeout: 1000,
|
|
205
|
+
}).trim();
|
|
206
|
+
if (gitOutput) {
|
|
207
|
+
const match = gitOutput.match(/[/:](\w[-\w]+)\/(\w[-\w]+?)(?:\.git)?$/);
|
|
208
|
+
if (match && match[2]) {
|
|
209
|
+
resolved = match[2];
|
|
210
|
+
} else {
|
|
211
|
+
const slashBase = path.basename(gitOutput.replace(/\.git$/, ''));
|
|
212
|
+
if (slashBase) resolved = slashBase;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
// Fall through
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 3. Try git top-level
|
|
221
|
+
if (!resolved) {
|
|
222
|
+
try {
|
|
223
|
+
const gitBin = resolveGitBinary();
|
|
224
|
+
const topLevel = execFileSync(gitBin, ['-C', targetDir, 'rev-parse', '--show-toplevel'], {
|
|
225
|
+
encoding: 'utf8',
|
|
226
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
227
|
+
timeout: 1000,
|
|
228
|
+
}).trim();
|
|
229
|
+
if (topLevel) {
|
|
230
|
+
resolved = path.basename(topLevel);
|
|
231
|
+
}
|
|
232
|
+
} catch {
|
|
233
|
+
// Fall through
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!resolved) {
|
|
238
|
+
resolved = path.basename(targetDir);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const normalized = normalizeProjectName(resolved) || resolved;
|
|
242
|
+
|
|
243
|
+
if (options.noCache !== true) {
|
|
244
|
+
CWD_CACHE.set(targetDir, normalized);
|
|
245
|
+
diskCache[targetDir] = normalized;
|
|
246
|
+
saveDiskCache();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return normalized;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Infer the project associated with a lesson from its declared scope, metadata, or tags.
|
|
254
|
+
* Unknown lessons return null (unscoped).
|
|
255
|
+
*/
|
|
256
|
+
function inferProjectFromLesson(lesson) {
|
|
257
|
+
if (!lesson || typeof lesson !== 'object') return null;
|
|
258
|
+
|
|
259
|
+
// 1. Explicit scope or metadata
|
|
260
|
+
const declaredProject = lesson.scope?.projectId || lesson.metadata?.project || lesson.metadata?.repo || lesson.metadata?.repoId;
|
|
261
|
+
if (declaredProject && typeof declaredProject === 'string' && declaredProject !== 'default' && declaredProject !== 'agent') {
|
|
262
|
+
return declaredProject;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 2. Check for global rules
|
|
266
|
+
if (
|
|
267
|
+
lesson.shared === true ||
|
|
268
|
+
lesson.scope?.shared === true ||
|
|
269
|
+
lesson.scope === 'global' ||
|
|
270
|
+
lesson.scope?.projectId === 'global' ||
|
|
271
|
+
lesson.metadata?.scope === 'global' ||
|
|
272
|
+
(Array.isArray(lesson.tags) && lesson.tags.includes('global'))
|
|
273
|
+
) {
|
|
274
|
+
return 'global';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const texts = [
|
|
278
|
+
lesson.title,
|
|
279
|
+
lesson.content,
|
|
280
|
+
lesson.whatWentWrong,
|
|
281
|
+
lesson.whatToChange,
|
|
282
|
+
lesson.whatWorked,
|
|
283
|
+
lesson.rule?.description,
|
|
284
|
+
lesson.structuredRule?.action?.description,
|
|
285
|
+
...(Array.isArray(lesson.tags) ? lesson.tags : []),
|
|
286
|
+
].filter(Boolean).join(' ');
|
|
287
|
+
|
|
288
|
+
if (GLOBAL_RULE_REGEX.test(texts)) {
|
|
289
|
+
return 'global';
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 3. Check tags for explicit repo or project annotations
|
|
293
|
+
if (Array.isArray(lesson.tags)) {
|
|
294
|
+
for (const tag of lesson.tags) {
|
|
295
|
+
const lower = String(tag).toLowerCase();
|
|
296
|
+
if (lower.startsWith('project:') || lower.startsWith('repo:')) {
|
|
297
|
+
const parts = lower.split(':');
|
|
298
|
+
if (parts[1]) return parts[1];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Determine if a lesson is relevant for the target project.
|
|
308
|
+
* Unscoped/unknown lessons are excluded unless explicitly global.
|
|
309
|
+
*/
|
|
310
|
+
function isLessonRelevantForProject(lesson, targetProject) {
|
|
311
|
+
if (!lesson) return false;
|
|
312
|
+
|
|
313
|
+
// Transcript-shaped lessons are ALWAYS rejected
|
|
314
|
+
if (isTranscriptShaped(lesson)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (!targetProject || targetProject === 'all') {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const normalizedTarget = normalizeProjectName(targetProject);
|
|
323
|
+
const inferred = inferProjectFromLesson(lesson);
|
|
324
|
+
|
|
325
|
+
// Global lessons are always permitted across all projects
|
|
326
|
+
if (inferred === 'global') {
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// If project is identified, compare
|
|
331
|
+
if (inferred) {
|
|
332
|
+
return normalizeProjectName(inferred) === normalizedTarget;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Unscoped/unknown lessons are excluded from project-specific injection
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Backfill scope and metadata on memory records.
|
|
341
|
+
* Unknown lessons are left unscoped (null) instead of guessing.
|
|
342
|
+
*/
|
|
343
|
+
function backfillLessonScopes(memories = []) {
|
|
344
|
+
return memories.map((mem) => {
|
|
345
|
+
if (!mem || typeof mem !== 'object') return mem;
|
|
346
|
+
const inferred = inferProjectFromLesson(mem);
|
|
347
|
+
const existingScope = mem.scope || {};
|
|
348
|
+
const updatedScope = {
|
|
349
|
+
...(existingScope.entityId ? { entityId: existingScope.entityId } : {}),
|
|
350
|
+
projectId: existingScope.projectId || inferred || null,
|
|
351
|
+
processId: existingScope.processId || 'agent',
|
|
352
|
+
...(existingScope.sessionId ? { sessionId: existingScope.sessionId } : {}),
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const existingMeta = mem.metadata || {};
|
|
356
|
+
const resolvedProject = existingMeta.project || updatedScope.projectId || null;
|
|
357
|
+
const updatedMetadata = {
|
|
358
|
+
...existingMeta,
|
|
359
|
+
...(resolvedProject ? { project: resolvedProject, repo: resolvedProject } : {}),
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
...mem,
|
|
364
|
+
scope: updatedScope,
|
|
365
|
+
metadata: updatedMetadata,
|
|
366
|
+
};
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
module.exports = {
|
|
371
|
+
TRANSCRIPT_XML_TAGS,
|
|
372
|
+
GLOBAL_RULE_REGEX,
|
|
373
|
+
normalizeProjectName,
|
|
374
|
+
isTranscriptShaped,
|
|
375
|
+
resolveProjectFromCwd,
|
|
376
|
+
inferProjectFromLesson,
|
|
377
|
+
isLessonRelevantForProject,
|
|
378
|
+
backfillLessonScopes,
|
|
379
|
+
clearCwdCache,
|
|
380
|
+
getDiskCachePath,
|
|
381
|
+
};
|
package/scripts/prompt-eval.js
CHANGED