total-recall-brain 3.41.5 → 3.41.6
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/bin/total-recall.mjs +7 -4
- package/frontend/dist/assets/index-4tGQfTa2.js +5605 -0
- package/frontend/dist/assets/index-DtwsDyFM.css +1 -0
- package/frontend/dist/index.html +2 -2
- package/frontend/package.json +11 -0
- package/frontend/src/App.tsx +47 -122
- package/frontend/src/components/plugins/plugin-frame.ts +1 -0
- package/frontend/src/index.css +152 -86
- package/frontend/src/pages/HelpPage.tsx +13 -10
- package/frontend/src/pages/MemoryPage.tsx +28 -30
- package/frontend/src/pages/NetworkPage.tsx +3 -3
- package/frontend/src/pages/PluginsPage.tsx +6 -5
- package/frontend/src/pages/RulesPage.tsx +16 -12
- package/package.json +3 -2
- package/scaffold/.agent/skills/total-recall/plugins/code-quality/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/code-quality/package.json +3 -0
- package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package.json +3 -0
- package/scaffold/.agent/skills/total-recall/plugins/embeddings/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/embeddings/package.json +3 -0
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package.json +3 -0
- package/scaffold/.agent/skills/total-recall/plugins/mesh/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/mesh/package.json +4 -1
- package/scaffold/.agent/skills/total-recall/plugins/mesh/src/core/mesh.mjs +1 -1
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/capability/index.mjs +136 -7
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/cli.mjs +135 -26
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/package.json +4 -1
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/plugin.json +228 -9
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/skills/meta-harness/SKILL.md +24 -30
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/alerts.mjs +29 -16
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/cascade.mjs +73 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/coordinator.mjs +182 -365
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/dispatch.mjs +33 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/documentation.mjs +9 -3
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/executor.mjs +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/agy.mjs +187 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/claude.mjs +275 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/cline.mjs +132 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/codex.mjs +187 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/cursor.mjs +158 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/devin.mjs +157 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/dsh.mjs +183 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/grok.mjs +132 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/hermes.mjs +173 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/index.mjs +87 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/openclaw.mjs +173 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate-adapters/pi.mjs +129 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/gate.mjs +12 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/json-reply.mjs +22 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/learner.mjs +72 -70
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/model-catalog.mjs +195 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/paths.mjs +11 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/pool.mjs +36 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/review.mjs +169 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/router.mjs +136 -346
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/runtime.mjs +1 -1
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/ssss-store.mjs +20 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/telemetry.mjs +43 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/threads.mjs +156 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/worker.mjs +117 -35
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/worktree.mjs +51 -0
- package/scaffold/.agent/skills/total-recall/plugins/meta-harness/ui/card.js +398 -57
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/cli.mjs +10 -0
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/package-lock.json +3 -3
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/package.json +3 -0
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/plugin.json +42 -190
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/vendor/openwiki.mjs +1 -1
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/vendor/skills/mermaid-diagrams/SKILL.md +44 -0
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/vendor/skills/write-connector/SKILL.md +56 -0
- package/scaffold/.agent/skills/total-recall/plugins/security/package-lock.json +8 -8
- package/scaffold/.agent/skills/total-recall/plugins/security/package.json +3 -0
- package/src/cli/agent.mjs +12 -1
- package/src/cli/compact.mjs +2 -2
- package/src/cli/connect.mjs +56 -1
- package/src/cli/context.mjs +10 -7
- package/src/cli/doctor.mjs +5 -2
- package/src/cli/harness.mjs +62 -50
- package/src/cli/memory-entry.mjs +2 -2
- package/src/cli/preflight.mjs +152 -16
- package/src/cli/remember.mjs +19 -1
- package/src/cli/rules.mjs +54 -12
- package/src/cli/startup.mjs +1 -1
- package/src/cli/status.mjs +12 -2
- package/src/core/claude-hooks.mjs +41 -3
- package/src/core/cli-semantic-index.mjs +3 -2
- package/src/core/conflict-detector.mjs +23 -12
- package/src/core/context-compactor.mjs +2 -0
- package/src/core/context-policy.mjs +20 -0
- package/src/core/duplicate-guard.mjs +350 -0
- package/src/core/meta-harness.mjs +31 -11
- package/src/core/preflight-gate.mjs +2 -2
- package/src/core/preflight-receipt.mjs +28 -0
- package/src/core/scaffold-plugins.mjs +7 -0
- package/src/core/stdio-flush.mjs +23 -0
- package/src/core/surface.mjs +33 -10
- package/src/server/routes/plugins.mjs +2 -2
- package/frontend/dist/assets/index-BIQmqDKP.css +0 -1
- package/frontend/dist/assets/index-WT3gs-x6.js +0 -5631
- package/frontend/src/components/DaemonLogsTab.tsx +0 -54
- package/frontend/src/components/ResearchAgendaTab.tsx +0 -712
- package/frontend/src/components/TaskQueueTab.tsx +0 -193
- package/frontend/src/components/VoiceInput.tsx +0 -112
- package/frontend/src/pages/ChatPage.tsx +0 -1059
- package/frontend/src/pages/CollabPage.tsx +0 -470
- package/frontend/src/pages/DesignDocsPage.tsx +0 -621
- package/frontend/src/pages/FilesPage.tsx +0 -393
- package/frontend/src/pages/HealthPage.tsx +0 -359
- package/frontend/src/pages/InboxPage.tsx +0 -83
- package/frontend/src/pages/InstructionsPage.tsx +0 -583
- package/frontend/src/pages/IntegrationsPage.tsx +0 -761
- package/frontend/src/pages/MeshPage.css +0 -58
- package/frontend/src/pages/MeshPage.tsx +0 -1219
- package/frontend/src/pages/OkfPage.tsx +0 -535
- package/frontend/src/pages/SandboxPage.tsx +0 -113
- package/frontend/src/pages/SkillsPage.tsx +0 -1994
- package/frontend/src/pages/TasksPage.tsx +0 -427
- package/frontend/src/pages/UsagePage.tsx +0 -702
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/README.md +0 -65
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/cli.mjs +0 -76
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/package.json +0 -19
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/plugin.json +0 -266
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/adapters/dsh.mjs +0 -446
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/documentation.mjs +0 -152
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/executor.mjs +0 -71
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/runtime.mjs +0 -36
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/setup.mjs +0 -35
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/src/worker.mjs +0 -175
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/ui/DESIGN.md +0 -32
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/ui/card.js +0 -575
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hermes-Grade Fail-Closed Duplicate Memory Guard
|
|
3
|
+
*
|
|
4
|
+
* Implements pre-write semantic collision checking co-opted from Nous Hermes / Hindsight
|
|
5
|
+
* (_find_related_observations).
|
|
6
|
+
*
|
|
7
|
+
* Prevents agents from polluting the vault with duplicate rules or disguising
|
|
8
|
+
* rule-violation incidents by re-recording existing invariants.
|
|
9
|
+
*
|
|
10
|
+
* Invariant:
|
|
11
|
+
* If an active rule or invariant with high token similarity or vector semantic proximity
|
|
12
|
+
* already exists, the write MUST FAIL CLOSED (Exit Code 1) with ZERO disk bytes written.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import { getNodes } from './vault-cache.mjs';
|
|
18
|
+
import { loadEmbeddingsIndex, cosineSimilarity } from './embeddings.mjs';
|
|
19
|
+
import { logger } from './logger.mjs';
|
|
20
|
+
|
|
21
|
+
const RULE_CATEGORIES = new Set(['invariants', 'anti-patterns', 'preferences', 'rules']);
|
|
22
|
+
|
|
23
|
+
const STOPWORDS = new Set([
|
|
24
|
+
'a', 'an', 'and', 'are', 'as', 'at', 'be', 'by', 'for', 'from', 'has', 'he',
|
|
25
|
+
'in', 'is', 'it', 'its', 'of', 'on', 'that', 'the', 'to', 'was', 'were',
|
|
26
|
+
'will', 'with', 'before', 'after', 'using', 'used', 'use', 'any', 'all',
|
|
27
|
+
'should', 'must', 'each', 'this', 'these', 'those', 'such', 'than', 'then'
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalize and stem a token to its canonical semantic root.
|
|
32
|
+
*/
|
|
33
|
+
export function stemToken(word) {
|
|
34
|
+
let w = word.toLowerCase();
|
|
35
|
+
// Strip trailing punctuation
|
|
36
|
+
w = w.replace(/[^a-z0-9_-]/g, '');
|
|
37
|
+
if (w.length <= 2) return w;
|
|
38
|
+
|
|
39
|
+
// Synonyms and domain stems
|
|
40
|
+
if (w === 'docs' || w === 'documentation') return 'doc';
|
|
41
|
+
if (w === 'apis' || w === 'api') return 'api';
|
|
42
|
+
if (w === 'models' || w === 'model') return 'model';
|
|
43
|
+
if (w === 'names' || w === 'strings' || w === 'string') return 'name';
|
|
44
|
+
if (w.startsWith('search')) return 'search';
|
|
45
|
+
if (w.startsWith('hardcod')) return 'hardcode';
|
|
46
|
+
if (w.startsWith('pretrain')) return 'pretrain';
|
|
47
|
+
if (w.startsWith('reli') || w.startsWith('rely')) return 'rely';
|
|
48
|
+
if (w.startsWith('specif')) return 'spec';
|
|
49
|
+
if (w.startsWith('push')) return 'push';
|
|
50
|
+
if (w.startsWith('commit')) return 'commit';
|
|
51
|
+
if (w.startsWith('verif')) return 'verify';
|
|
52
|
+
if (w.startsWith('check')) return 'check';
|
|
53
|
+
|
|
54
|
+
// Standard suffix stripping
|
|
55
|
+
if (w.endsWith('ing') && w.length > 5) return w.slice(0, -3);
|
|
56
|
+
if (w.endsWith('es') && w.length > 4) return w.slice(0, -2);
|
|
57
|
+
if (w.endsWith('s') && !w.endsWith('ss') && w.length > 3) return w.slice(0, -1);
|
|
58
|
+
if (w.endsWith('ed') && w.length > 4) return w.slice(0, -2);
|
|
59
|
+
if (w.endsWith('ly') && w.length > 4) return w.slice(0, -2);
|
|
60
|
+
|
|
61
|
+
return w;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Tokenize text into stemmed, stopword-filtered semantic tokens.
|
|
66
|
+
*/
|
|
67
|
+
export function tokenize(text) {
|
|
68
|
+
if (!text || typeof text !== 'string') return new Set();
|
|
69
|
+
const rawWords = text
|
|
70
|
+
.toLowerCase()
|
|
71
|
+
.replace(/[^a-z0-9\s_-]/g, ' ')
|
|
72
|
+
.split(/\s+/)
|
|
73
|
+
.filter((w) => w.length > 1 && !STOPWORDS.has(w));
|
|
74
|
+
|
|
75
|
+
const stems = new Set();
|
|
76
|
+
for (const word of rawWords) {
|
|
77
|
+
const s = stemToken(word);
|
|
78
|
+
if (s && !STOPWORDS.has(s)) {
|
|
79
|
+
stems.add(s);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return stems;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Compute Jaccard similarity between two token sets.
|
|
87
|
+
*/
|
|
88
|
+
export function jaccard(setA, setB) {
|
|
89
|
+
if (setA.size === 0 && setB.size === 0) return 1;
|
|
90
|
+
let intersection = 0;
|
|
91
|
+
for (const item of setA) {
|
|
92
|
+
if (setB.has(item)) intersection++;
|
|
93
|
+
}
|
|
94
|
+
const union = setA.size + setB.size - intersection;
|
|
95
|
+
return union === 0 ? 0 : intersection / union;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Compute containment ratio (how much of candidate's core tokens exist in target).
|
|
100
|
+
*/
|
|
101
|
+
export function containment(candidateSet, targetSet) {
|
|
102
|
+
if (candidateSet.size === 0) return 0;
|
|
103
|
+
let matches = 0;
|
|
104
|
+
for (const token of candidateSet) {
|
|
105
|
+
if (targetSet.has(token)) matches++;
|
|
106
|
+
}
|
|
107
|
+
return matches / candidateSet.size;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Find the location of an existing slug in compiled instruction surfaces.
|
|
112
|
+
*/
|
|
113
|
+
export function findSurfaceLocation(existingSlug, projectRoot = process.cwd()) {
|
|
114
|
+
const homeDir = process.env.HOME || '';
|
|
115
|
+
const candidates = [
|
|
116
|
+
path.join(projectRoot, 'AGENTS.md'),
|
|
117
|
+
path.join(projectRoot, 'INSTRUCTIONS.md'),
|
|
118
|
+
path.join(projectRoot, 'CLAUDE.md'),
|
|
119
|
+
path.join(projectRoot, '.cursorrules'),
|
|
120
|
+
path.join(homeDir, '.agent', 'INSTRUCTIONS.md'),
|
|
121
|
+
path.join(homeDir, '.agent', 'AGENTS.md'),
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
for (const candidatePath of candidates) {
|
|
125
|
+
if (fs.existsSync(candidatePath)) {
|
|
126
|
+
try {
|
|
127
|
+
const content = fs.readFileSync(candidatePath, 'utf8');
|
|
128
|
+
const lines = content.split('\n');
|
|
129
|
+
for (let i = 0; i < lines.length; i++) {
|
|
130
|
+
if (lines[i].includes(existingSlug)) {
|
|
131
|
+
return {
|
|
132
|
+
file: path.basename(candidatePath),
|
|
133
|
+
path: candidatePath,
|
|
134
|
+
line: i + 1,
|
|
135
|
+
snippet: lines[i].trim().slice(0, 100),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch {
|
|
140
|
+
// Ignore read errors
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Record a rule violation incident into the persistent incidents log.
|
|
149
|
+
*/
|
|
150
|
+
export function logIncident(incident, derivedDir) {
|
|
151
|
+
try {
|
|
152
|
+
fs.mkdirSync(derivedDir, { recursive: true });
|
|
153
|
+
const logPath = path.join(derivedDir, 'incidents.jsonl');
|
|
154
|
+
fs.appendFileSync(logPath, JSON.stringify(incident) + '\n', 'utf8');
|
|
155
|
+
} catch (err) {
|
|
156
|
+
logger.warn('duplicate-guard', `Failed to record incident to ${derivedDir}: ${err.message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Check if a candidate rule/invariant node is a duplicate of an existing active node.
|
|
162
|
+
*
|
|
163
|
+
* @param {object} candidate - The candidate node to be remembered.
|
|
164
|
+
* @param {object} options
|
|
165
|
+
* @param {string} options.vaultDir - Path to current vault directory.
|
|
166
|
+
* @param {string} [options.derivedDir] - Path to memory-derived directory.
|
|
167
|
+
* @param {string} [options.globalVaultDir] - Global vault, as resolved by the caller's brain owner. Also searched when it differs from vaultDir.
|
|
168
|
+
* @param {string} [options.projectRoot] - Repository root directory.
|
|
169
|
+
* @param {number} [options.jaccardThreshold=0.45] - Threshold for token overlap.
|
|
170
|
+
* @param {number} [options.containmentThreshold=0.60] - Threshold for candidate containment.
|
|
171
|
+
* @param {number} [options.cosineThreshold=0.82] - Threshold for embedding cosine similarity.
|
|
172
|
+
* @returns {object} { isDuplicate: boolean, matchedNode?: object, similarity?: number, surfaceLoc?: object }
|
|
173
|
+
*/
|
|
174
|
+
export function checkDuplicateRule(candidate, options = {}) {
|
|
175
|
+
const {
|
|
176
|
+
vaultDir,
|
|
177
|
+
derivedDir,
|
|
178
|
+
globalVaultDir,
|
|
179
|
+
projectRoot = process.cwd(),
|
|
180
|
+
jaccardThreshold = 0.45,
|
|
181
|
+
containmentThreshold = 0.60,
|
|
182
|
+
cosineThreshold = 0.82,
|
|
183
|
+
} = options;
|
|
184
|
+
|
|
185
|
+
if (!candidate || !RULE_CATEGORIES.has(candidate.category)) {
|
|
186
|
+
return { isDuplicate: false };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Load existing active nodes from the target vault
|
|
190
|
+
const vaultNodes = getNodes(vaultDir).filter(
|
|
191
|
+
(n) => n.status === 'active' && RULE_CATEGORIES.has(n.category) && n.slug !== candidate.slug
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// If in a project brain, also check global vault to prevent duplicating global invariants
|
|
195
|
+
let allNodes = [...vaultNodes];
|
|
196
|
+
if (globalVaultDir && vaultDir !== globalVaultDir && fs.existsSync(globalVaultDir)) {
|
|
197
|
+
try {
|
|
198
|
+
const globalNodes = getNodes(globalVaultDir).filter(
|
|
199
|
+
(n) => n.status === 'active' && RULE_CATEGORIES.has(n.category) && n.slug !== candidate.slug
|
|
200
|
+
);
|
|
201
|
+
allNodes = [...allNodes, ...globalNodes];
|
|
202
|
+
} catch {
|
|
203
|
+
// Ignore global load errors if any
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (allNodes.length === 0) {
|
|
208
|
+
return { isDuplicate: false };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const candidateBody = (candidate.body || '').trim();
|
|
212
|
+
const candidateNorm = candidateBody.toLowerCase().replace(/\s+/g, ' ');
|
|
213
|
+
const candidateTokens = tokenize(
|
|
214
|
+
`${candidate.title || ''} ${candidateBody} ${candidate.subject || ''} ${candidate.predicate || ''} ${candidate.object || ''}`
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// Optional vector index check
|
|
218
|
+
let embeddingsIndex = null;
|
|
219
|
+
if (derivedDir && fs.existsSync(path.join(derivedDir, 'embeddings.db'))) {
|
|
220
|
+
try {
|
|
221
|
+
embeddingsIndex = loadEmbeddingsIndex(derivedDir);
|
|
222
|
+
} catch {
|
|
223
|
+
embeddingsIndex = null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
for (const existing of allNodes) {
|
|
228
|
+
const existingBody = (existing.body || '').trim();
|
|
229
|
+
const existingNorm = existingBody.toLowerCase().replace(/\s+/g, ' ');
|
|
230
|
+
|
|
231
|
+
// 1. Exact or near-exact normalized body match
|
|
232
|
+
if (candidateNorm.length > 10 && (candidateNorm === existingNorm || existingNorm.includes(candidateNorm) || candidateNorm.includes(existingNorm))) {
|
|
233
|
+
const surfaceLoc = findSurfaceLocation(existing.slug, projectRoot);
|
|
234
|
+
return {
|
|
235
|
+
isDuplicate: true,
|
|
236
|
+
matchedNode: existing,
|
|
237
|
+
similarity: 1.0,
|
|
238
|
+
surfaceLoc,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 2. Token Jaccard similarity & Containment
|
|
243
|
+
const existingTokens = tokenize(
|
|
244
|
+
`${existing.title || ''} ${existingBody} ${existing.subject || ''} ${existing.predicate || ''} ${existing.object || ''}`
|
|
245
|
+
);
|
|
246
|
+
const tokenSim = jaccard(candidateTokens, existingTokens);
|
|
247
|
+
const containSim = containment(candidateTokens, existingTokens);
|
|
248
|
+
|
|
249
|
+
if (tokenSim >= jaccardThreshold || containSim >= containmentThreshold) {
|
|
250
|
+
const surfaceLoc = findSurfaceLocation(existing.slug, projectRoot);
|
|
251
|
+
const effectiveSim = Math.max(tokenSim, containSim);
|
|
252
|
+
return {
|
|
253
|
+
isDuplicate: true,
|
|
254
|
+
matchedNode: existing,
|
|
255
|
+
similarity: Math.round(effectiveSim * 1000) / 1000,
|
|
256
|
+
surfaceLoc,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 3. Vector Embedding similarity (if available)
|
|
261
|
+
if (embeddingsIndex && embeddingsIndex[candidate.slug] && embeddingsIndex[existing.slug]) {
|
|
262
|
+
try {
|
|
263
|
+
const vecSim = cosineSimilarity(
|
|
264
|
+
embeddingsIndex[candidate.slug].embedding,
|
|
265
|
+
embeddingsIndex[existing.slug].embedding
|
|
266
|
+
);
|
|
267
|
+
if (vecSim >= cosineThreshold) {
|
|
268
|
+
const surfaceLoc = findSurfaceLocation(existing.slug, projectRoot);
|
|
269
|
+
return {
|
|
270
|
+
isDuplicate: true,
|
|
271
|
+
matchedNode: existing,
|
|
272
|
+
similarity: Math.round(vecSim * 1000) / 1000,
|
|
273
|
+
surfaceLoc,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
} catch {
|
|
277
|
+
// Fall back to token match
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return { isDuplicate: false };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Enforces that a candidate rule is not a duplicate.
|
|
287
|
+
* Throws an Error and logs an incident if a collision occurs.
|
|
288
|
+
*/
|
|
289
|
+
export function assertNoDuplicateRule(candidate, options = {}) {
|
|
290
|
+
const check = checkDuplicateRule(candidate, options);
|
|
291
|
+
if (!check.isDuplicate) return;
|
|
292
|
+
|
|
293
|
+
const { matchedNode, similarity, surfaceLoc } = check;
|
|
294
|
+
const surfaceStr = surfaceLoc ? `${surfaceLoc.file} at Line ${surfaceLoc.line}` : 'Active Invariant Pool';
|
|
295
|
+
|
|
296
|
+
const incident = {
|
|
297
|
+
timestamp: new Date().toISOString(),
|
|
298
|
+
session_id: process.env.TR_SESSION_ID || 'unknown',
|
|
299
|
+
event: 'rule_write_rejected',
|
|
300
|
+
reason: 'An attempt was made to write a rule that already exists in active memory.',
|
|
301
|
+
attempted: {
|
|
302
|
+
category: candidate.category,
|
|
303
|
+
title: candidate.title,
|
|
304
|
+
body: candidate.body,
|
|
305
|
+
priority: candidate.priority || 'normal',
|
|
306
|
+
},
|
|
307
|
+
existing: {
|
|
308
|
+
slug: matchedNode.slug,
|
|
309
|
+
title: matchedNode.title,
|
|
310
|
+
body: matchedNode.body,
|
|
311
|
+
priority: matchedNode.priority || 'normal',
|
|
312
|
+
category: matchedNode.category,
|
|
313
|
+
},
|
|
314
|
+
similarity,
|
|
315
|
+
surface_location: surfaceStr,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
if (options.derivedDir) {
|
|
319
|
+
logIncident(incident, options.derivedDir);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const message = [
|
|
323
|
+
'',
|
|
324
|
+
'================================================================================',
|
|
325
|
+
'🚨 VIOLATION INCIDENT DETECTED: DUPLICATE RULE REJECTED',
|
|
326
|
+
'--------------------------------------------------------------------------------',
|
|
327
|
+
`Attempted Rule: "${candidate.body}"`,
|
|
328
|
+
`Existing Rule: [${matchedNode.slug}] "${matchedNode.body}"`,
|
|
329
|
+
`Similarity: ${Math.round(similarity * 100)}%`,
|
|
330
|
+
`Surface Status: Active (${surfaceStr})`,
|
|
331
|
+
'',
|
|
332
|
+
'ROOT-CAUSE ANALYSIS:',
|
|
333
|
+
'The agent attempted to write a rule that ALREADY exists in the active instruction',
|
|
334
|
+
'surface. This indicates the agent failed to follow an invariant that was already',
|
|
335
|
+
'active in its context.',
|
|
336
|
+
'',
|
|
337
|
+
'Refusing to write duplicate node. Zero disk bytes written.',
|
|
338
|
+
'Fix the agent\'s behavior at the source.',
|
|
339
|
+
'================================================================================',
|
|
340
|
+
'',
|
|
341
|
+
].join('\n');
|
|
342
|
+
|
|
343
|
+
console.error(message);
|
|
344
|
+
|
|
345
|
+
const error = new Error(`Rule already exists: [${matchedNode.slug}] "${matchedNode.body}" (${Math.round(similarity * 100)}% match)`);
|
|
346
|
+
error.code = 'ERR_DUPLICATE_RULE';
|
|
347
|
+
error.incident = incident;
|
|
348
|
+
error.matchedNode = matchedNode;
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
@@ -23,7 +23,9 @@ export const HARNESS_SPECS = {
|
|
|
23
23
|
category: 'frontier_reasoning',
|
|
24
24
|
defaultFlags: ['--output-format', 'json', '-p'],
|
|
25
25
|
execType: 'flag_last',
|
|
26
|
-
description: 'Frontier reasoning and research on Google AI Ultra plan.'
|
|
26
|
+
description: 'Frontier reasoning and research on Google AI Ultra plan.',
|
|
27
|
+
enforcement: 'enforced',
|
|
28
|
+
enforcementEvidence: 'PreToolUse deny hook verified live'
|
|
27
29
|
},
|
|
28
30
|
claude: {
|
|
29
31
|
id: 'claude',
|
|
@@ -38,7 +40,9 @@ export const HARNESS_SPECS = {
|
|
|
38
40
|
// Headless subscription auth (`claude setup-token`), read from the secret
|
|
39
41
|
// store when the caller's environment does not already carry it.
|
|
40
42
|
authSecrets: ['CLAUDE_CODE_OAUTH_TOKEN'],
|
|
41
|
-
description: 'Deep codebase editing, refactoring, and Unix command execution.'
|
|
43
|
+
description: 'Deep codebase editing, refactoring, and Unix command execution.',
|
|
44
|
+
enforcement: 'enforced',
|
|
45
|
+
enforcementEvidence: 'PreToolUse deny hook verified live'
|
|
42
46
|
},
|
|
43
47
|
codex: {
|
|
44
48
|
id: 'codex',
|
|
@@ -47,7 +51,9 @@ export const HARNESS_SPECS = {
|
|
|
47
51
|
category: 'code_synthesis',
|
|
48
52
|
defaultFlags: ['exec', '--sandbox', 'workspace-write', '--json', '--skip-git-repo-check'],
|
|
49
53
|
execType: 'subcommand',
|
|
50
|
-
description: 'Autonomous program synthesis and sandbox execution.'
|
|
54
|
+
description: 'Autonomous program synthesis and sandbox execution.',
|
|
55
|
+
enforcement: 'enforced',
|
|
56
|
+
enforcementEvidence: 'hooks.json PreToolUse block hook verified live'
|
|
51
57
|
},
|
|
52
58
|
ollama: {
|
|
53
59
|
id: 'ollama',
|
|
@@ -56,7 +62,9 @@ export const HARNESS_SPECS = {
|
|
|
56
62
|
category: 'local_neural',
|
|
57
63
|
defaultFlags: ['run', process.env.TR_OLLAMA_MODEL || 'gemma4:latest'],
|
|
58
64
|
execType: 'pipe_stdin',
|
|
59
|
-
description: 'Local neural inference, offline reasoning, zero API cost.'
|
|
65
|
+
description: 'Local neural inference, offline reasoning, zero API cost.',
|
|
66
|
+
enforcement: 'dispatch-only',
|
|
67
|
+
enforcementEvidence: 'No tool hooks; preflight checked before dispatch'
|
|
60
68
|
},
|
|
61
69
|
grok: {
|
|
62
70
|
id: 'grok',
|
|
@@ -65,7 +73,9 @@ export const HARNESS_SPECS = {
|
|
|
65
73
|
category: 'code_engineering',
|
|
66
74
|
defaultFlags: ['-p'],
|
|
67
75
|
execType: 'flag_last',
|
|
68
|
-
description: 'Autonomous coding, repo analysis, and shell execution via xAI Grok.'
|
|
76
|
+
description: 'Autonomous coding, repo analysis, and shell execution via xAI Grok.',
|
|
77
|
+
enforcement: 'enforced (unverified live)',
|
|
78
|
+
enforcementEvidence: 'PreToolUse hook adapter specification verified offline'
|
|
69
79
|
},
|
|
70
80
|
hermes: {
|
|
71
81
|
id: 'hermes',
|
|
@@ -74,7 +84,9 @@ export const HARNESS_SPECS = {
|
|
|
74
84
|
category: 'autonomous_agent',
|
|
75
85
|
defaultFlags: ['chat', '-p'],
|
|
76
86
|
execType: 'flag_last',
|
|
77
|
-
description: 'Supervised messaging gateway and multi-channel autonomous agent runtime.'
|
|
87
|
+
description: 'Supervised messaging gateway and multi-channel autonomous agent runtime.',
|
|
88
|
+
enforcement: 'enforced',
|
|
89
|
+
enforcementEvidence: 'pre_tool_call block hook verified live'
|
|
78
90
|
},
|
|
79
91
|
dsh: {
|
|
80
92
|
id: 'dsh',
|
|
@@ -83,7 +95,9 @@ export const HARNESS_SPECS = {
|
|
|
83
95
|
category: 'reasoning_engine',
|
|
84
96
|
defaultFlags: ['-p'],
|
|
85
97
|
execType: 'flag_last',
|
|
86
|
-
description: 'High-throughput DeepSeek reasoning and tool execution harness.'
|
|
98
|
+
description: 'High-throughput DeepSeek reasoning and tool execution harness.',
|
|
99
|
+
enforcement: 'enforced',
|
|
100
|
+
enforcementEvidence: 'PreToolUse deny hook verified live'
|
|
87
101
|
},
|
|
88
102
|
openclaw: {
|
|
89
103
|
id: 'openclaw',
|
|
@@ -92,7 +106,9 @@ export const HARNESS_SPECS = {
|
|
|
92
106
|
category: 'multichannel_bridge',
|
|
93
107
|
defaultFlags: ['status', '--json'],
|
|
94
108
|
execType: 'flag_last',
|
|
95
|
-
description: 'Multi-channel messaging bridge (WhatsApp, Telegram, Discord, Slack) and agent execution.'
|
|
109
|
+
description: 'Multi-channel messaging bridge (WhatsApp, Telegram, Discord, Slack) and agent execution.',
|
|
110
|
+
enforcement: 'enforced',
|
|
111
|
+
enforcementEvidence: 'before_tool_call block hook verified live'
|
|
96
112
|
}
|
|
97
113
|
};
|
|
98
114
|
|
|
@@ -567,6 +583,7 @@ export async function queryHarnessUsage() {
|
|
|
567
583
|
const reports = [];
|
|
568
584
|
|
|
569
585
|
for (const h of harnesses) {
|
|
586
|
+
const spec = HARNESS_SPECS[h.id];
|
|
570
587
|
if (!h.available) {
|
|
571
588
|
reports.push({
|
|
572
589
|
id: h.id,
|
|
@@ -582,7 +599,9 @@ export async function queryHarnessUsage() {
|
|
|
582
599
|
plan: '—',
|
|
583
600
|
rolling5hRemainingPct: '—',
|
|
584
601
|
weeklyRemainingPct: '—',
|
|
585
|
-
quotaRemaining: 'not installed'
|
|
602
|
+
quotaRemaining: 'not installed',
|
|
603
|
+
enforcement: spec?.enforcement || 'advisory',
|
|
604
|
+
enforcementEvidence: spec?.enforcementEvidence || null
|
|
586
605
|
});
|
|
587
606
|
continue;
|
|
588
607
|
}
|
|
@@ -610,7 +629,6 @@ export async function queryHarnessUsage() {
|
|
|
610
629
|
const acc = JSON.parse(fs.readFileSync(accPath, 'utf8'));
|
|
611
630
|
if (acc.active) identity = acc.active;
|
|
612
631
|
}
|
|
613
|
-
plan = 'Google AI Ultra / Pro';
|
|
614
632
|
} catch {}
|
|
615
633
|
} else if (h.id === 'claude') {
|
|
616
634
|
try {
|
|
@@ -722,7 +740,9 @@ export async function queryHarnessUsage() {
|
|
|
722
740
|
plan,
|
|
723
741
|
rolling5hRemainingPct,
|
|
724
742
|
weeklyRemainingPct,
|
|
725
|
-
quotaRemaining
|
|
743
|
+
quotaRemaining,
|
|
744
|
+
enforcement: spec?.enforcement || 'advisory',
|
|
745
|
+
enforcementEvidence: spec?.enforcementEvidence || null
|
|
726
746
|
});
|
|
727
747
|
}
|
|
728
748
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Rules, in order:
|
|
7
7
|
* 1. Tools that only display or discover (`meta`, `ui`) are always open.
|
|
8
8
|
* 2. Reads of skill files are open: reading them is how the preflight is earned.
|
|
9
|
-
* 3. A single plain Total Recall preflight, context, compact, recall or help command is
|
|
9
|
+
* 3. A single plain Total Recall preflight, context, compact, recall, rules or help command is
|
|
10
10
|
* open, so the gate can always be satisfied or repaired. Chaining, piping,
|
|
11
11
|
* substitution and redirects are not plain, so the exemption cannot carry
|
|
12
12
|
* other work and a capsule cannot be truncated through a pipe.
|
|
@@ -21,7 +21,7 @@ export const TOOL_CLASSES = ['shell', 'read', 'write', 'search', 'web', 'mcp', '
|
|
|
21
21
|
export const SWEEP_CONSULT_MS = 15 * 60 * 1000;
|
|
22
22
|
|
|
23
23
|
const SKILL_PATH = /\/\.(agent|claude)\/skills\//;
|
|
24
|
-
const SATISFYING = /^(cd\s+\S+\s*&&\s*)?(npx\s+)?(total-recall|node\s+\S*bin\/total-recall\.mjs)\s+(tr-preflight|preflight|context|compact|recall|help|--help)(\s+[^;&|`<>$\n]*)?$/;
|
|
24
|
+
const SATISFYING = /^(cd\s+\S+\s*&&\s*)?(npx\s+)?(total-recall|node\s+\S*bin\/total-recall\.mjs)\s+(tr-preflight|preflight|context|compact|recall|rules|help|--help)(\s+[^;&|`<>$\n]*)?$/;
|
|
25
25
|
|
|
26
26
|
/** True when the whole command is one plain Total Recall invocation that satisfies or repairs the gate. */
|
|
27
27
|
export function isSatisfyingCommand(command) {
|
|
@@ -121,3 +121,31 @@ export function touchConsult(root, { now = Date.now(), home = os.homedir() } = {
|
|
|
121
121
|
export function lastConsultMs(root, { home = os.homedir() } = {}) {
|
|
122
122
|
try { return Number(fs.readFileSync(consultPath(root, home), 'utf8')) || 0; } catch { return 0; }
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
export const decisionsLogPath = (home = os.homedir()) => path.join(stateDir(home), 'decisions.jsonl');
|
|
126
|
+
|
|
127
|
+
/** Append a real gate decision to the persistent decisions log (ENFORCE-R5). */
|
|
128
|
+
export function recordDecision(entry, { home = os.homedir(), now = Date.now() } = {}) {
|
|
129
|
+
try {
|
|
130
|
+
const file = decisionsLogPath(home);
|
|
131
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
132
|
+
const record = { at: new Date(now).toISOString(), ...entry };
|
|
133
|
+
fs.appendFileSync(file, `${JSON.stringify(record)}\n`, { mode: 0o600 });
|
|
134
|
+
return record;
|
|
135
|
+
} catch { return null; }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Read recent gate decisions for compliance reporting. */
|
|
139
|
+
export function readDecisions({ home = os.homedir(), limit = 1000 } = {}) {
|
|
140
|
+
try {
|
|
141
|
+
const file = decisionsLogPath(home);
|
|
142
|
+
if (!fs.existsSync(file)) return [];
|
|
143
|
+
const lines = fs.readFileSync(file, 'utf8').trim().split('\n').filter(Boolean);
|
|
144
|
+
const start = Math.max(0, lines.length - limit);
|
|
145
|
+
const records = [];
|
|
146
|
+
for (let i = start; i < lines.length; i++) {
|
|
147
|
+
try { records.push(JSON.parse(lines[i])); } catch {}
|
|
148
|
+
}
|
|
149
|
+
return records;
|
|
150
|
+
} catch { return []; }
|
|
151
|
+
}
|
|
@@ -84,6 +84,13 @@ export function syncScaffoldPlugins({ root, ids, write = false, run = spawnSync
|
|
|
84
84
|
};
|
|
85
85
|
walk(target);
|
|
86
86
|
}
|
|
87
|
+
// The release gate reads the pin, so a stale pin is drift even when every copied file matches its source.
|
|
88
|
+
const lockFile = path.join(root, 'scripts', 'scaffold-plugins.json');
|
|
89
|
+
if (!write && fs.existsSync(lockFile)) {
|
|
90
|
+
const pinned = JSON.parse(fs.readFileSync(lockFile, 'utf8'));
|
|
91
|
+
const stale = [...new Set([...Object.keys(pinned), ...Object.keys(lock)])].some(key => pinned[key] !== lock[key]);
|
|
92
|
+
if (stale) changes.push({ file: 'scripts/scaffold-plugins.json', change: 'stale pin' });
|
|
93
|
+
}
|
|
87
94
|
if (write) fs.writeFileSync(path.join(root, 'scripts', 'scaffold-plugins.json'), `${JSON.stringify(Object.fromEntries(Object.entries(lock).sort()), null, 2)}\n`);
|
|
88
95
|
return { changes, files: Object.keys(lock).length };
|
|
89
96
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit once everything already written to stdout and stderr has left the process.
|
|
3
|
+
*
|
|
4
|
+
* process.exit() drops whatever is still queued. On macOS a pipe write is
|
|
5
|
+
* asynchronous and the pipe takes 64 KiB at once, so `write(big); process.exit()`
|
|
6
|
+
* loses the rest with exit status 0, while a redirect to a file looks fine.
|
|
7
|
+
*
|
|
8
|
+
* The returned promise never settles, so `await exitAfterFlush(code)` stops the
|
|
9
|
+
* caller the way process.exit() does. A reader that has gone away (`| head`) is
|
|
10
|
+
* not an error here: the unwritten output has nowhere to go.
|
|
11
|
+
*/
|
|
12
|
+
function drained(stream) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
stream.on('error', resolve);
|
|
15
|
+
if (stream.destroyed || !stream.writable || stream.writableLength === 0) return resolve();
|
|
16
|
+
stream.write('', resolve);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function exitAfterFlush(code = process.exitCode ?? 0) {
|
|
21
|
+
Promise.all([drained(process.stdout), drained(process.stderr)]).then(() => process.exit(code));
|
|
22
|
+
return new Promise(() => {});
|
|
23
|
+
}
|
package/src/core/surface.mjs
CHANGED
|
@@ -390,17 +390,18 @@ export function buildInstalledPluginsSummary(projectRoot = process.cwd()) {
|
|
|
390
390
|
const plugins = discoverPlugins(projectRoot).filter((p) => p.valid);
|
|
391
391
|
if (!plugins.length) return '';
|
|
392
392
|
const lines = [
|
|
393
|
-
'## Installed Plugins
|
|
394
|
-
'
|
|
393
|
+
'## Mandatory Plugin Enforcement Table (Installed Plugins)\n',
|
|
394
|
+
'All tasks within these domains MUST use their owning Total Recall plugin CLI (`total-recall <namespace>`). Hand-rolling curl, ad-hoc scripts, raw bash, direct ssh, or manual file edits to bypass these plugins is a strict protocol violation. Discover operations with `total-recall plugin library --json` or run `total-recall <namespace> --help`.\n',
|
|
395
395
|
'Namespaces below run as `total-recall <namespace> [command]`; declarations do not prove provider readiness.\n'
|
|
396
396
|
];
|
|
397
|
-
if (plugins.some(plugin => plugin.id === 'composable-cli'))
|
|
397
|
+
if (plugins.some(plugin => plugin.id === 'composable-cli')) {
|
|
398
|
+
lines.push('Composed commands: run `total-recall composable-cli library --json` or `total-recall <command> --help`.\n');
|
|
399
|
+
}
|
|
398
400
|
for (const p of plugins) {
|
|
399
401
|
const cmd = p.manifest.cli?.command || p.id;
|
|
400
|
-
const desc = (p.manifest.description || 'Plugin capability').replace(/\s+/g, ' ').
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
lines.push(`- **${p.id}** v${p.manifest.version || 'unknown'} · ${pluginActivation(p, { projectRoot }).state} · \`total-recall ${cmd}\` ${shown ? `[${shown}]` : '(no operations)'}: ${desc}`);
|
|
402
|
+
const desc = (p.manifest.description || 'Plugin capability').replace(/\s+/g, ' ').trim();
|
|
403
|
+
const state = pluginActivation(p, { projectRoot }).state;
|
|
404
|
+
lines.push(`- **${p.id}** v${p.manifest.version || 'unknown'} · ${state} · \`total-recall ${cmd}\`: ${desc}`);
|
|
404
405
|
}
|
|
405
406
|
return lines.join('\n') + '\n';
|
|
406
407
|
} catch {
|
|
@@ -418,6 +419,19 @@ export async function buildRulesBlock(skillsDir, nodes = [], {
|
|
|
418
419
|
const contributions = [];
|
|
419
420
|
const counts = category => rules.filter(n => n.category === category).length;
|
|
420
421
|
const commands = buildCommandsSection(listSurfaceCommands(commandDirsFor(skillsDir)));
|
|
422
|
+
|
|
423
|
+
// Tier 1 Absolute Invariants & Top Operational Directives lead lines 1-50 so they are never truncated
|
|
424
|
+
const tier1Rules = rules.filter(r => r.priority === 'absolute' || r.immutable === true || r.slug === 'invariants-8cd098fd' || r.slug === 'invariants-dc116371');
|
|
425
|
+
const otherRules = rules.filter(r => !tier1Rules.includes(r));
|
|
426
|
+
|
|
427
|
+
for (const node of tier1Rules) {
|
|
428
|
+
contributions.push({
|
|
429
|
+
id: `${node._layer || 'project'}:${node.slug}`,
|
|
430
|
+
required: true,
|
|
431
|
+
text: node._directive ? `[${node.slug}] ${node._directive}` : `### ${node.title || node.slug} [${node.slug}]\n\n${node.body || node.content || ''}`
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
421
435
|
const header = bootstrap ? `${CLI_QUICK_REFERENCE}\n${buildInstalledPluginsSummary(root)}\n${commands}\n# 🔴 MANDATORY FIRST STEP: TOTAL RECALL CLI & TASK ROUTING
|
|
422
436
|
|
|
423
437
|
1. RUN TOTAL RECALL CLI HELP FIRST:
|
|
@@ -427,7 +441,7 @@ Inspect all core capabilities, installed plugins, and commands.
|
|
|
427
441
|
|
|
428
442
|
2. RUN TOTAL RECALL CONTEXT BEFORE ACTING:
|
|
429
443
|
\`total-recall context "task description" --action <actions>\`
|
|
430
|
-
Read the returned capsule and require ready:true.
|
|
444
|
+
Read the returned capsule and require ready:true. Rules of unknown applicability are required. Over budget it compacts; every listed rule still applies: expand one with \`total-recall compact "task" --expand <slug>\` before relying on it. If it exits 2, retry with the required_budget it reports.
|
|
431
445
|
|
|
432
446
|
Total Recall is the agent's working memory, toolset, and single source of truth across all decisions. Refresh at every changed task, action or project, and after a memory/skill edit. Do not infer applicability from semantic similarity. CLI retrieval is local and works without the server. Skills have compact entrypoints; load only relevant references. Canonical vault writes use the validated CLI.
|
|
433
447
|
|
|
@@ -435,13 +449,22 @@ DO NOT SKIP THIS. Run Total Recall CLI help and context first before doing anyth
|
|
|
435
449
|
|
|
436
450
|
` :
|
|
437
451
|
`## Active Rules: ${counts('invariants')} invariants, ${counts('preferences')} preferences, ${counts('anti-patterns')} corrections`;
|
|
452
|
+
|
|
438
453
|
contributions.push({ id: 'routing', text: header, required: true });
|
|
454
|
+
|
|
439
455
|
const pluginsSummary = buildInstalledPluginsSummary(root);
|
|
440
456
|
if (pluginsSummary && !bootstrap) {
|
|
441
457
|
contributions.push({ id: 'installed-plugins', text: pluginsSummary, required: true });
|
|
442
458
|
}
|
|
443
|
-
|
|
444
|
-
|
|
459
|
+
|
|
460
|
+
for (const node of otherRules) {
|
|
461
|
+
contributions.push({
|
|
462
|
+
id: `${node._layer || 'project'}:${node.slug}`,
|
|
463
|
+
required: true,
|
|
464
|
+
text: node._directive ? `[${node.slug}] ${node._directive}` : `### ${node.title || node.slug} [${node.slug}]\n\n${node.body || node.content || ''}`
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
445
468
|
if (!bootstrap) contributions.push({ id: 'commands', text: commands });
|
|
446
469
|
if (!bootstrap) {
|
|
447
470
|
if (skillsDir) {
|
|
@@ -35,7 +35,7 @@ const projectRoot = () => process.cwd();
|
|
|
35
35
|
router.get('/api/plugins/execution-targets', requireAuth, requireScope('config:read'), async (req, res) => {
|
|
36
36
|
try {
|
|
37
37
|
const { loadPluginModule } = await import('../../core/plugin-runtime.mjs');
|
|
38
|
-
const owner = await loadPluginModule('
|
|
38
|
+
const owner = await loadPluginModule('meta-harness', 'command-executor', { activeRequired: true });
|
|
39
39
|
const result = req.query.node ? await owner.inspectNode(String(req.query.node)) : await owner.listTargets();
|
|
40
40
|
res.json({ success: true, ...result });
|
|
41
41
|
} catch (err) { badRequest(res, err.message); }
|
|
@@ -338,7 +338,7 @@ router.post("/api/plugins/:id/run", requireAuth, (req, res, next) => {
|
|
|
338
338
|
if (stdin !== undefined) return badRequest(res, 'Credential operations require direct local execution');
|
|
339
339
|
if (!pluginActivation(plugin, { projectRoot: projectRoot() }).enabled && !['on', 'off', 'status', 'health', 'jobs', '--help', 'help'].includes(subcommand)) return badRequest(res, `Plugin ${plugin.id} is inactive`);
|
|
340
340
|
const { loadPluginModule } = await import('../../core/plugin-runtime.mjs');
|
|
341
|
-
const owner = await loadPluginModule('
|
|
341
|
+
const owner = await loadPluginModule('meta-harness', 'command-executor', { activeRequired: true });
|
|
342
342
|
const result = await owner.executeCommand({ plugin, subcommand, args, execution, projectRoot: projectRoot() });
|
|
343
343
|
return res.json({ success: result.ok, pluginId: plugin.id, ...result });
|
|
344
344
|
}
|