total-recall-brain 3.40.7 → 3.41.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/bin/total-recall-memory.mjs +0 -0
- package/bin/total-recall.mjs +9 -40
- package/docs/reference/cli-reference.md +65 -1
- package/frontend/dist/assets/{index-AGUes-VG.css → index-BG9NkVUy.css} +1 -1
- package/frontend/dist/assets/{index-Bt5iVPZj.js → index-BtuiZqwP.js} +20 -7
- package/frontend/dist/index.html +2 -2
- package/frontend/src/components/plugins/PluginPanel.tsx +31 -5
- package/frontend/src/components/plugins/card/CardEngine.tsx +15 -23
- package/frontend/src/components/plugins/card/CardScenes.tsx +52 -23
- package/frontend/src/components/plugins/card/card.css +2 -5
- package/frontend/src/components/plugins/card/contract.ts +13 -19
- package/frontend/src/components/plugins/card/format.ts +8 -1
- package/frontend/src/components/plugins/card/widgets.tsx +4 -35
- package/frontend/src/components/plugins/plugin-frame.ts +30 -3
- package/frontend/src/pages/PluginsPage.tsx +3 -2
- package/package.json +1 -1
- package/scaffold/.agent/skills/meta-harness/references/optimized/original.md +1 -1
- package/scaffold/.agent/skills/plugin/SKILL.md +110 -0
- package/scaffold/.agent/skills/plugin/evals/README.md +53 -0
- package/scaffold/.agent/skills/plugin/evals/cases/01-fabricated-seed.mjs +42 -0
- package/scaffold/.agent/skills/plugin/evals/cases/02-reassuring-default.mjs +39 -0
- package/scaffold/.agent/skills/plugin/evals/cases/03-declared-template.mjs +32 -0
- package/scaffold/.agent/skills/plugin/evals/cases/04-card-collects-credential.mjs +46 -0
- package/scaffold/.agent/skills/plugin/evals/cases/05-host-leak-in-scaffold.mjs +55 -0
- package/scaffold/.agent/skills/plugin/evals/cases/06-correct-plugin.mjs +92 -0
- package/scaffold/.agent/skills/plugin/evals/run.mjs +118 -0
- package/scaffold/.agent/skills/plugin/prompts/01-function.md +29 -0
- package/scaffold/.agent/skills/plugin/prompts/02-surfaces.md +43 -0
- package/scaffold/.agent/skills/plugin/prompts/03-scaffold.md +31 -0
- package/scaffold/.agent/skills/plugin/prompts/04-cli.md +49 -0
- package/scaffold/.agent/skills/plugin/prompts/05-credentials.md +41 -0
- package/scaffold/.agent/skills/plugin/prompts/06-card.md +46 -0
- package/scaffold/.agent/skills/plugin/prompts/07-scaffold.md +52 -0
- package/scaffold/.agent/skills/plugin/prompts/08-verify.md +43 -0
- package/scaffold/.agent/skills/plugin/references/anti-patterns.md +123 -0
- package/scaffold/.agent/skills/plugin/references/card.md +90 -0
- package/scaffold/.agent/skills/plugin/references/scaffold.md +120 -0
- package/scaffold/.agent/skills/plugin/references/surfaces.md +206 -0
- package/scaffold/.agent/skills/plugin/scripts/record.mjs +360 -0
- package/scaffold/.agent/skills/plugin/subagents/card-designer.md +60 -0
- package/scaffold/.agent/skills/plugin/subagents/plugin-reviewer.md +55 -0
- package/scaffold/.agent/skills/plugin/subagents/scaffold-extractor.md +71 -0
- package/scaffold/.agent/skills/total-recall/plugins/auth/package-lock.json +71 -1441
- package/scaffold/.agent/skills/total-recall/plugins/auth/package.json +7 -5
- package/scaffold/.agent/skills/total-recall/plugins/auth/plugin.json +3 -44
- package/scaffold/.agent/skills/total-recall/plugins/auth/scripts/agent-login-pty.py +185 -0
- package/scaffold/.agent/skills/total-recall/plugins/auth/src/cli-secret.mjs +20 -1
- package/scaffold/.agent/skills/total-recall/plugins/auth/src/host-secrets-store.mjs +15 -0
- package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-env-export.mjs +6 -4
- package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-remote-deploy.mjs +1 -0
- package/scaffold/.agent/skills/total-recall/plugins/cli-agents/plugin.json +0 -24
- package/scaffold/.agent/skills/total-recall/plugins/code-quality/package-lock.json +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/code-quality/plugin.json +0 -21
- package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package-lock.json +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/composable-cli/plugin.json +0 -32
- package/scaffold/.agent/skills/total-recall/plugins/embeddings/package-lock.json +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/embeddings/plugin.json +11 -0
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/README.md +5 -2
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package-lock.json +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/plugin.json +1 -28
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/ui/DESIGN.md +95 -13
- package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/ui/card.js +553 -340
- package/scaffold/.agent/skills/total-recall/plugins/mesh/plugin.json +0 -36
- package/scaffold/.agent/skills/total-recall/plugins/mesh/ui/card.js +383 -400
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/package-lock.json +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/package.json +0 -1
- package/scaffold/.agent/skills/total-recall/plugins/openwiki/plugin.json +0 -28
- package/scaffold/.agent/skills/total-recall/plugins/security/package-lock.json +4 -4
- package/scaffold/.agent/skills/total-recall/plugins/security/plugin.json +0 -32
- package/scaffold/.agent/skills/total-recall/references/auth.md +3 -1
- package/scaffold/.agent/skills/total-recall/references/memory.md +4 -0
- package/scaffold/.agent/skills/total-recall/references/openwiki.md +2 -0
- package/scaffold/.agent/skills/total-recall/references/operations.md +12 -0
- package/src/cli/brain.mjs +72 -2
- package/src/cli/connect.mjs +10 -39
- package/src/cli/context-stats.mjs +104 -0
- package/src/cli/context.mjs +8 -0
- package/src/cli/daemon.mjs +10 -1
- package/src/cli/export.mjs +3 -2
- package/src/cli/ingest-okf.mjs +12 -15
- package/src/cli/init.mjs +0 -85
- package/src/cli/lint.mjs +3 -2
- package/src/cli/plugin/copies.mjs +68 -0
- package/src/cli/plugin/create.mjs +22 -24
- package/src/cli/plugin/index.mjs +49 -3
- package/src/cli/plugin/search.mjs +19 -2
- package/src/cli/rebuild.mjs +2 -0
- package/src/cli/remember.mjs +23 -0
- package/src/cli/status.mjs +10 -3
- package/src/cli/update.mjs +3 -2
- package/src/core/action-predictor.mjs +161 -0
- package/src/core/app-deploy/runtime-cli/node.mjs.tmpl +20 -3
- package/src/core/app-deploy/source.mjs +16 -9
- package/src/core/automatic-brain-updates.mjs +6 -3
- package/src/core/brain-registry.mjs +19 -2
- package/src/core/brain-state.mjs +23 -0
- package/src/core/cli-commands.mjs +1 -0
- package/src/core/cli-maintenance.mjs +1 -1
- package/src/core/cli-semantic-index.mjs +1 -1
- package/src/core/command-surface.mjs +3 -3
- package/src/core/composed-command-resolution.mjs +21 -0
- package/src/core/config.mjs +84 -0
- package/src/core/confined-memory.mjs +93 -0
- package/src/core/context-telemetry.mjs +214 -0
- package/src/core/daemon-control.mjs +14 -43
- package/src/core/fast-recall.mjs +1 -1
- package/src/core/memory-brain.mjs +2 -0
- package/src/core/plugin-activation.mjs +38 -6
- package/src/core/plugin-bundle.mjs +54 -0
- package/src/core/plugin-catalog.mjs +1 -1
- package/src/core/plugin-context.mjs +1 -1
- package/src/core/plugin-contracts/card.mjs +69 -37
- package/src/core/plugin-loader.mjs +5 -6
- package/src/core/plugin-runner.mjs +13 -6
- package/src/core/plugin-runtime.mjs +5 -4
- package/src/core/plugin-setup.mjs +5 -3
- package/src/core/plugin-state-store.mjs +12 -1
- package/src/core/plugin-state.mjs +46 -5
- package/src/core/plugin-store.mjs +78 -3
- package/src/core/plugin-tasks.mjs +3 -1
- package/src/core/plugin-updates.mjs +117 -0
- package/src/core/plugin-vendor.mjs +10 -4
- package/src/core/project-brain.mjs +14 -41
- package/src/core/project-id.mjs +4 -1
- package/src/core/required-plugins.mjs +151 -13
- package/src/core/skills-registry.mjs +27 -3
- package/src/core/ssss-kernel-bridge.mjs +3 -1
- package/src/core/startup-health.mjs +66 -16
- package/src/core/surface.mjs +53 -46
- package/src/core/testing/plugin-fixture.mjs +69 -0
- package/src/core/vault-files.mjs +13 -0
- package/src/core/vault.mjs +4 -30
- package/src/server/index.mjs +13 -1
- package/src/server/invoke-decision-child.mjs +49 -0
- package/src/server/invoke-execution.mjs +87 -0
- package/src/server/invoke-policy.mjs +64 -0
- package/src/server/invoke-read-child.mjs +26 -0
- package/src/server/invoke-targets.mjs +49 -0
- package/src/server/invoke-write-child.mjs +19 -0
- package/src/server/routes/invoke.mjs +314 -0
- package/src/server/routes/plugins.mjs +1 -1
- package/scaffold/.agent/skills/plugins/SKILL.md +0 -57
- package/scaffold/.agent/skills/plugins/references/card-design.md +0 -55
- package/scaffold/.agent/skills/plugins/references/distribution.md +0 -23
- package/scaffold/.agent/skills/plugins/references/manifest-contract.md +0 -90
- package/scaffold/.agent/skills/plugins/references/optimized/index.md +0 -9
- package/scaffold/.agent/skills/plugins/references/optimized/manifest.json +0 -35
- package/scaffold/.agent/skills/plugins/references/optimized/original.md +0 -58
- package/scaffold/.agent/skills/plugins/references/optimized/section-01.md +0 -5
- package/scaffold/.agent/skills/plugins/references/optimized/section-02.md +0 -25
- package/scaffold/.agent/skills/plugins/references/optimized/section-03.md +0 -12
- package/scaffold/.agent/skills/plugins/references/optimized/section-04.md +0 -7
- package/scaffold/.agent/skills/plugins/references/optimized/section-05.md +0 -5
- package/scaffold/.agent/skills/total-recall/openwiki/README.md +0 -10
- package/scaffold/.agent/skills/total-recall/openwiki/architecture.md +0 -5
- package/scaffold/.agent/skills/total-recall/openwiki/ide.md +0 -10
- package/scaffold/.agent/skills/total-recall/openwiki/memory.md +0 -11
- package/scaffold/.agent/skills/total-recall/openwiki/secrets.md +0 -7
- package/scaffold/.agent/skills/total-recall/openwiki/skills.md +0 -7
- package/scaffold/openwiki/README.md +0 -10
- package/scaffold/openwiki/architecture.md +0 -5
- package/scaffold/openwiki/ide.md +0 -10
- package/scaffold/openwiki/memory.md +0 -11
- package/scaffold/openwiki/secrets.md +0 -7
- package/scaffold/openwiki/skills.md +0 -7
- package/src/core/okf-adapter.mjs +0 -559
- package/templates/openwiki/README.md +0 -10
- package/templates/openwiki/architecture.md +0 -5
- package/templates/openwiki/ide.md +0 -10
- package/templates/openwiki/memory.md +0 -11
- package/templates/openwiki/secrets.md +0 -7
- package/templates/openwiki/skills.md +0 -7
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context-telemetry — measurement for the one number that governs every session.
|
|
3
|
+
*
|
|
4
|
+
* `compileContext` already computed everything needed to judge the context
|
|
5
|
+
* policy (total tokens, required tokens, overflow, which rules were included,
|
|
6
|
+
* which were dropped) and then threw it away. Without a record, the budget
|
|
7
|
+
* question could only ever be argued from a point-in-time anecdote — TR-003
|
|
8
|
+
* recorded "12 of 13 capsules overflow" once and nobody could later say whether
|
|
9
|
+
* a change helped, or whether the gate still failed at all.
|
|
10
|
+
*
|
|
11
|
+
* This records one line per capsule so the policy is decided from a trend
|
|
12
|
+
* rather than a memory.
|
|
13
|
+
*
|
|
14
|
+
* Bounded by construction. An append-only event log in this project once
|
|
15
|
+
* reached 306 MB, GitHub silently rejected every backup for five weeks, and the
|
|
16
|
+
* cause was invisible until someone looked. So this file carries its own size
|
|
17
|
+
* cap and retention, enforced on write, and it records counts and identifiers
|
|
18
|
+
* ONLY: never rule text, never capsule content, never a credential. Identifiers
|
|
19
|
+
* are slugs that already appear in the vault.
|
|
20
|
+
*/
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
|
|
24
|
+
/** Append-only ledger for capsule measurements, inside the brain's derived space. */
|
|
25
|
+
export const LEDGER_NAME = 'context-ledger.jsonl';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Fraction of the cap retained when trimming (TR_CONTEXT_LEDGER_RETAIN, default
|
|
29
|
+
* 0.5). Trimming to the cap on every crossing would re-trim constantly; leaving
|
|
30
|
+
* headroom makes the trim rare and keeps a real window of history.
|
|
31
|
+
*/
|
|
32
|
+
const RETAIN_FRACTION = (() => {
|
|
33
|
+
const n = Number(process.env.TR_CONTEXT_LEDGER_RETAIN ?? 0.5);
|
|
34
|
+
return Number.isFinite(n) && n > 0 && n <= 1 ? n : 0.5;
|
|
35
|
+
})();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Max bytes the ledger may reach (TR_CONTEXT_LEDGER_MAX_BYTES, default 8 MiB,
|
|
39
|
+
* 0 disables). Small on purpose: this is telemetry, not memory, and it must
|
|
40
|
+
* never be able to threaten a backup or a disk the way default.jsonl did.
|
|
41
|
+
*/
|
|
42
|
+
const maxBytes = () => {
|
|
43
|
+
const n = Number(process.env.TR_CONTEXT_LEDGER_MAX_BYTES ?? 8 * 1024 * 1024);
|
|
44
|
+
return Number.isFinite(n) && n >= 0 ? n : 8 * 1024 * 1024;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Whether telemetry is recorded at all (TR_CONTEXT_TELEMETRY=off disables). */
|
|
48
|
+
export const telemetryEnabled = () => String(process.env.TR_CONTEXT_TELEMETRY || '').toLowerCase() !== 'off';
|
|
49
|
+
|
|
50
|
+
/** Ledger path for a brain's derived directory. */
|
|
51
|
+
export function ledgerPath(derivedDir) {
|
|
52
|
+
return derivedDir ? path.join(derivedDir, LEDGER_NAME) : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Keep the ledger bounded while preserving a usable trend.
|
|
57
|
+
*
|
|
58
|
+
* Two failure modes, both observed rather than imagined:
|
|
59
|
+
* 1. An append-only log in this project reached 306 MB and silently broke
|
|
60
|
+
* every backup for five weeks. So growth must be bounded by construction.
|
|
61
|
+
* 2. The first attempt here renamed the live file over the previous
|
|
62
|
+
* generation, so 40 writes under a small cap left 4 records — the trend
|
|
63
|
+
* the ledger exists for was destroyed by its own housekeeping.
|
|
64
|
+
*
|
|
65
|
+
* The ledger therefore trims to a retained fraction of the cap rather than
|
|
66
|
+
* collapsing: the newest half survives, the rest is dropped. Trimming runs only
|
|
67
|
+
* once the cap is crossed (not on every write), so the common path stays a
|
|
68
|
+
* single append.
|
|
69
|
+
*/
|
|
70
|
+
function enforceBound(file, cap, fsImpl = fs) {
|
|
71
|
+
if (cap <= 0) return;
|
|
72
|
+
let size;
|
|
73
|
+
try { size = fsImpl.statSync(file).size; } catch { return; }
|
|
74
|
+
if (size <= cap) return;
|
|
75
|
+
try {
|
|
76
|
+
const lines = fsImpl.readFileSync(file, 'utf8').split('\n').filter(Boolean);
|
|
77
|
+
const keep = [];
|
|
78
|
+
let bytes = 0;
|
|
79
|
+
const retainBytes = Math.floor(cap * RETAIN_FRACTION);
|
|
80
|
+
// Walk backwards so the most recent measurements are the ones retained.
|
|
81
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
82
|
+
const next = Buffer.byteLength(lines[i]) + 1;
|
|
83
|
+
if (bytes + next > retainBytes && keep.length) break;
|
|
84
|
+
bytes += next;
|
|
85
|
+
keep.unshift(lines[i]);
|
|
86
|
+
}
|
|
87
|
+
fsImpl.writeFileSync(file, keep.length ? `${keep.join('\n')}\n` : '');
|
|
88
|
+
} catch { /* a concurrent writer or an unreadable file: leave it alone */ }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Record one capsule measurement.
|
|
93
|
+
*
|
|
94
|
+
* Returns the record written, or null when telemetry is off or the write
|
|
95
|
+
* failed. Never throws: measurement must never be able to break a session.
|
|
96
|
+
*/
|
|
97
|
+
export function recordCapsule(stats, { derivedDir, action = [], query, consumer = 'cli', now = Date.now(), fsImpl = fs } = {}) {
|
|
98
|
+
if (!telemetryEnabled() || !stats || !derivedDir) return null;
|
|
99
|
+
try {
|
|
100
|
+
const file = ledgerPath(derivedDir);
|
|
101
|
+
fsImpl.mkdirSync(path.dirname(file), { recursive: true });
|
|
102
|
+
enforceBound(file, maxBytes(), fsImpl);
|
|
103
|
+
const contributions = Array.isArray(stats.contributions) ? stats.contributions : [];
|
|
104
|
+
const record = {
|
|
105
|
+
at: new Date(now).toISOString(),
|
|
106
|
+
consumer,
|
|
107
|
+
// Actions and the query are what make a measurement interpretable; the
|
|
108
|
+
// query is truncated because it is free text, not an identifier.
|
|
109
|
+
actions: Array.isArray(action) ? action : [action].filter(Boolean),
|
|
110
|
+
query_chars: typeof query === 'string' ? query.length : 0,
|
|
111
|
+
total_tokens: stats.total_tokens ?? null,
|
|
112
|
+
// `budget` is added by the caller's capsuleResponse wrapper; absent here.
|
|
113
|
+
required_tokens: stats.required_tokens ?? null,
|
|
114
|
+
overflow_tokens: stats.overflow_tokens ?? null,
|
|
115
|
+
ready: typeof stats.overflow_tokens === 'number' ? stats.overflow_tokens === 0 : null,
|
|
116
|
+
required_count: Array.isArray(stats.required_ids) ? stats.required_ids.length : contributions.filter(c => c.required).length,
|
|
117
|
+
excluded_count: Array.isArray(stats.excluded_ids) ? stats.excluded_ids.length : 0,
|
|
118
|
+
// Identifier lists only, and only the ones that decided the budget.
|
|
119
|
+
required_ids: Array.isArray(stats.required_ids) ? stats.required_ids : [],
|
|
120
|
+
excluded_ids: Array.isArray(stats.excluded_ids) ? stats.excluded_ids.slice(0, 40) : [],
|
|
121
|
+
version: stats.version || null,
|
|
122
|
+
};
|
|
123
|
+
// A torn final line — an interrupted write, a full disk — would otherwise
|
|
124
|
+
// have the next record appended onto it, corrupting both. Repair the tail
|
|
125
|
+
// before appending so one bad write costs one measurement, not two.
|
|
126
|
+
repairTornTail(file, fsImpl);
|
|
127
|
+
fsImpl.appendFileSync(file, JSON.stringify(record) + '\n');
|
|
128
|
+
return record;
|
|
129
|
+
} catch { return null; }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Give a torn final line its own terminator.
|
|
134
|
+
*
|
|
135
|
+
* An append-only ledger assumes the file ends at a record boundary. When it
|
|
136
|
+
* does not — the process died mid-write — the next append lands on that line
|
|
137
|
+
* and both records become unparseable. Dropping the damaged tail keeps the loss
|
|
138
|
+
* at exactly the one measurement that failed.
|
|
139
|
+
*/
|
|
140
|
+
function repairTornTail(file, fsImpl = fs) {
|
|
141
|
+
let text;
|
|
142
|
+
try { text = fsImpl.readFileSync(file, 'utf8'); } catch { return; }
|
|
143
|
+
if (!text || text.endsWith('\n')) return;
|
|
144
|
+
const lastBreak = text.lastIndexOf('\n');
|
|
145
|
+
const tail = lastBreak === -1 ? text : text.slice(lastBreak + 1);
|
|
146
|
+
try { JSON.parse(tail); return; } catch { /* the tail is torn */ }
|
|
147
|
+
try { fsImpl.writeFileSync(file, lastBreak === -1 ? '' : text.slice(0, lastBreak + 1)); } catch { /* leave it alone */ }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Read ledger records, oldest first.
|
|
152
|
+
*
|
|
153
|
+
* Skips a malformed line individually. A torn write must cost one measurement,
|
|
154
|
+
* never the whole ledger — an earlier version discarded every valid record that
|
|
155
|
+
* followed the torn one.
|
|
156
|
+
*/
|
|
157
|
+
export function readLedger(derivedDir, { limit = 0, fsImpl = fs } = {}) {
|
|
158
|
+
const file = ledgerPath(derivedDir);
|
|
159
|
+
if (!file) return [];
|
|
160
|
+
const records = [];
|
|
161
|
+
for (const candidate of [file]) {
|
|
162
|
+
let text;
|
|
163
|
+
try { text = fsImpl.readFileSync(candidate, 'utf8'); } catch { continue; }
|
|
164
|
+
for (const line of text.split('\n')) {
|
|
165
|
+
if (!line.trim()) continue;
|
|
166
|
+
try { records.push(JSON.parse(line)); } catch { /* skip this line only */ }
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return limit > 0 ? records.slice(-limit) : records;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Summarise a ledger into the numbers a design decision needs.
|
|
174
|
+
*
|
|
175
|
+
* Reports per action, because "the capsule is too big" is not actionable while
|
|
176
|
+
* "read overflows and edit does not" is. `top_required` answers which rules
|
|
177
|
+
* carry the cost, which is the input to action-scoping a rule.
|
|
178
|
+
*/
|
|
179
|
+
export function summariseLedger(records = []) {
|
|
180
|
+
const byAction = new Map();
|
|
181
|
+
const ruleTokens = new Map();
|
|
182
|
+
const ruleAppearances = new Map();
|
|
183
|
+
for (const r of records) {
|
|
184
|
+
const actions = r.actions?.length ? r.actions : ['(none)'];
|
|
185
|
+
for (const action of actions) {
|
|
186
|
+
const entry = byAction.get(action) || { action, samples: 0, overflow: 0, required_max: 0, required_sum: 0, total_max: 0, excluded_total: 0 };
|
|
187
|
+
entry.samples++;
|
|
188
|
+
if (r.overflow_tokens > 0) entry.overflow++;
|
|
189
|
+
entry.required_sum += r.required_tokens || 0;
|
|
190
|
+
entry.required_max = Math.max(entry.required_max, r.required_tokens || 0);
|
|
191
|
+
entry.total_max = Math.max(entry.total_max, r.total_tokens || 0);
|
|
192
|
+
entry.excluded_total += r.excluded_count || 0;
|
|
193
|
+
byAction.set(action, entry);
|
|
194
|
+
}
|
|
195
|
+
for (const id of r.required_ids || []) {
|
|
196
|
+
ruleAppearances.set(id, (ruleAppearances.get(id) || 0) + 1);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const actions = [...byAction.values()]
|
|
200
|
+
.map(e => ({ ...e, required_avg: e.samples ? Math.round(e.required_sum / e.samples) : 0, overflow_rate: e.samples ? +(e.overflow / e.samples).toFixed(3) : 0 }))
|
|
201
|
+
.sort((a, b) => b.overflow_rate - a.overflow_rate || b.required_max - a.required_max);
|
|
202
|
+
const mostRequired = [...ruleAppearances.entries()]
|
|
203
|
+
.map(([id, appearances]) => ({ id, appearances }))
|
|
204
|
+
.sort((a, b) => b.appearances - a.appearances)
|
|
205
|
+
.slice(0, 25);
|
|
206
|
+
return {
|
|
207
|
+
samples: records.length,
|
|
208
|
+
first_at: records.length ? records[0].at : null,
|
|
209
|
+
last_at: records.length ? records[records.length - 1].at : null,
|
|
210
|
+
actions,
|
|
211
|
+
most_required: mostRequired,
|
|
212
|
+
rule_tokens: [...ruleTokens.entries()].map(([id, tokens]) => ({ id, tokens })),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
@@ -5,7 +5,7 @@ import path from 'node:path';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { logger } from './logger.mjs';
|
|
7
7
|
import { agentDir, brainDir } from './config.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { observeDaemon } from './startup-health.mjs';
|
|
9
9
|
|
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const ROOT = path.join(__dirname, '..', '..');
|
|
@@ -22,46 +22,19 @@ const LOG_FILE = path.join(brainDir, 'logs', 'daemon.log');
|
|
|
22
22
|
* @returns {number|null} The active PID, or null if not running/invalid.
|
|
23
23
|
*/
|
|
24
24
|
export function readPid() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const pid = parseInt(fs.readFileSync(PID_FILE, 'utf8').trim(), 10);
|
|
28
|
-
if (isNaN(pid) || pid <= 0) return null;
|
|
29
|
-
|
|
30
|
-
// Check if the process is alive using signal 0
|
|
31
|
-
try {
|
|
32
|
-
process.kill(pid, 0);
|
|
33
|
-
const command=readProcessCommand(pid);
|
|
34
|
-
if(!command)throw new Error('Cannot verify daemon process identity');
|
|
35
|
-
if(!command.includes(path.join('core','daemon-loop.mjs')) && !command.includes(path.join('core','dream.mjs')))return null;
|
|
36
|
-
return pid;
|
|
37
|
-
} catch {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
} catch {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
25
|
+
const observation = getDaemonObservation();
|
|
26
|
+
return observation.status === 'running' ? observation.pid : null;
|
|
43
27
|
}
|
|
44
28
|
|
|
29
|
+
export function getDaemonObservation() { return observeDaemon(brainDir); }
|
|
30
|
+
|
|
45
31
|
/**
|
|
46
32
|
* Returns the status of the daemon process.
|
|
47
|
-
* @returns {'running'|'dead'|'not_started'}
|
|
33
|
+
* @returns {'running'|'dead'|'not_started'|'conflict'|'unknown'}
|
|
48
34
|
*/
|
|
49
35
|
export function getDaemonStatus() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (pid) {
|
|
53
|
-
return 'running';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// If process is not running but PID file exists, it's considered dead
|
|
57
|
-
if (fs.existsSync(PID_FILE)) {
|
|
58
|
-
return 'dead';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return 'not_started';
|
|
62
|
-
} catch {
|
|
63
|
-
return 'not_started';
|
|
64
|
-
}
|
|
36
|
+
const { status } = getDaemonObservation();
|
|
37
|
+
return status === 'not-started' ? 'not_started' : status === 'stopped' ? 'dead' : status;
|
|
65
38
|
}
|
|
66
39
|
|
|
67
40
|
/**
|
|
@@ -69,7 +42,11 @@ export function getDaemonStatus() {
|
|
|
69
42
|
* @returns {number} The PID of the newly spawned daemon.
|
|
70
43
|
*/
|
|
71
44
|
export function startDaemon() {
|
|
72
|
-
const
|
|
45
|
+
const observation = getDaemonObservation();
|
|
46
|
+
if (['conflict', 'unknown'].includes(observation.status)) {
|
|
47
|
+
throw new Error(`Daemon start refused: ${observation.reason || observation.status}; expected ${observation.expected_entry}${observation.entry ? `, observed ${observation.entry}` : ''}`);
|
|
48
|
+
}
|
|
49
|
+
const existingPid = observation.status === 'running' ? observation.pid : null;
|
|
73
50
|
if (existingPid) {
|
|
74
51
|
logger.warn('daemon-control', `Daemon already running under PID ${existingPid}.`);
|
|
75
52
|
return existingPid;
|
|
@@ -77,13 +54,7 @@ export function startDaemon() {
|
|
|
77
54
|
|
|
78
55
|
const dreamScript = path.join(ROOT, 'src', 'core', 'daemon-loop.mjs');
|
|
79
56
|
if (!fs.existsSync(dreamScript)) {
|
|
80
|
-
|
|
81
|
-
const fallback = path.join(ROOT, 'src', 'core', 'dream.mjs');
|
|
82
|
-
if (fs.existsSync(fallback)) {
|
|
83
|
-
logger.warn('daemon-control', 'daemon-loop.mjs not found, falling back to dream.mjs');
|
|
84
|
-
} else {
|
|
85
|
-
throw new Error(`Daemon script not found at ${dreamScript}`);
|
|
86
|
-
}
|
|
57
|
+
throw new Error(`Daemon script not found at ${dreamScript}`);
|
|
87
58
|
}
|
|
88
59
|
|
|
89
60
|
const logsDir = path.dirname(LOG_FILE);
|
package/src/core/fast-recall.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import matter from './frontmatter.mjs';
|
|
5
|
-
import { atomicWrite, isSafeVaultName } from './vault.mjs';
|
|
5
|
+
import { atomicWrite, isSafeVaultName } from './vault-files.mjs';
|
|
6
6
|
|
|
7
7
|
const caches = new Map();
|
|
8
8
|
const words = text => [...new Set(String(text).toLowerCase().match(/[\p{L}\p{N}_-]+/gu) || [])];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { writeFileSecure } from './secure-file.mjs';
|
|
5
|
+
import { ensureProjectId } from './project-id.mjs';
|
|
5
6
|
|
|
6
7
|
function ensureDir(dir) { fs.mkdirSync(dir, { recursive: true }); }
|
|
7
8
|
|
|
@@ -58,6 +59,7 @@ export function registerProjectBrain(globalBrainDir, entry) {
|
|
|
58
59
|
name: entry.name,
|
|
59
60
|
path: abs,
|
|
60
61
|
brainDir: entry.brainDir,
|
|
62
|
+
project_id: ensureProjectId(entry.brainDir).project_id,
|
|
61
63
|
full_brain: true,
|
|
62
64
|
layer: 'project',
|
|
63
65
|
tags: entry.tags || ['project-brain'],
|
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
/** Host activation policy; never pretends a provider or external daemon is healthy. */
|
|
2
2
|
import { getPlugin } from './plugin-loader.mjs';
|
|
3
|
-
import { patchPluginRecord, emit, vaultFor, recompileAfterPluginMutation } from './plugin-store.mjs';
|
|
3
|
+
import { patchPluginRecord, patchProjectActivationRecord, emit, vaultFor, recompileAfterPluginMutation } from './plugin-store.mjs';
|
|
4
4
|
import { pluginActivation } from './plugin-state.mjs';
|
|
5
5
|
export { pluginActivation };
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Switch one plugin on or off.
|
|
9
|
+
*
|
|
10
|
+
* A plugin installed in one repository alone (a project copy) carries its own
|
|
11
|
+
* setting. A plugin in the shared folder is switched for the whole machine
|
|
12
|
+
* (`scope: 'shared'`), for the current repository alone (the default), or back to
|
|
13
|
+
* following the shared setting (`clear: true`).
|
|
14
|
+
*/
|
|
15
|
+
export async function setPluginActive(id, enabled, { projectRoot = process.cwd(), scope = 'project', clear = false } = {}) {
|
|
16
|
+
if (clear === true) {
|
|
17
|
+
const plugin = getPlugin(id, projectRoot);
|
|
18
|
+
if (!plugin?.valid) throw new Error(`Plugin ${id} is missing or invalid`);
|
|
19
|
+
await patchProjectActivationRecord(id, projectRoot, null);
|
|
20
|
+
await emit(vaultFor(plugin), id, 'activation-cleared', { projectRoot });
|
|
21
|
+
const compilation = await recompileAfterPluginMutation(projectRoot, false);
|
|
22
|
+
return { pluginId: id, activation: pluginActivation(plugin, { projectRoot }), scope: 'shared', compilation };
|
|
23
|
+
}
|
|
8
24
|
if (typeof enabled !== 'boolean') throw new Error('Plugin activation requires a boolean');
|
|
9
25
|
const plugin = getPlugin(id, projectRoot);
|
|
10
26
|
if (!plugin?.valid) throw new Error(`Plugin ${id} is missing or invalid`);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
if (scope === 'shared') {
|
|
28
|
+
if (plugin.scope !== 'global') throw new Error(`Plugin ${id} is a ${plugin.scope} copy without a shared setting to change`);
|
|
29
|
+
await patchPluginRecord(plugin, { runtime_enabled: enabled });
|
|
30
|
+
await emit(vaultFor(plugin), id, enabled ? 'activated' : 'deactivated', { enabled, scope: 'shared' });
|
|
31
|
+
const compilation = await recompileAfterPluginMutation(projectRoot, true);
|
|
32
|
+
return { pluginId: id, activation: pluginActivation(plugin, { projectRoot }), scope: 'shared', compilation };
|
|
33
|
+
}
|
|
34
|
+
// Repository scope. A repository-owned copy already is that repository's setting.
|
|
35
|
+
if (plugin.scope !== 'global') {
|
|
36
|
+
await patchPluginRecord(plugin, { runtime_enabled: enabled });
|
|
37
|
+
await emit(vaultFor(plugin), id, enabled ? 'activated' : 'deactivated', { enabled, scope: plugin.scope });
|
|
38
|
+
// A project copy compiles the project's own surface and catalog. Only the
|
|
39
|
+
// shared (scaffold) layer also rebuilds every registered project.
|
|
40
|
+
const compilation = await recompileAfterPluginMutation(projectRoot, plugin.scope === 'scaffold');
|
|
41
|
+
return { pluginId: id, activation: pluginActivation(plugin, { projectRoot }), scope: plugin.scope, compilation };
|
|
42
|
+
}
|
|
43
|
+
await patchProjectActivationRecord(id, projectRoot, enabled, { manifest: plugin.manifest });
|
|
44
|
+
await emit(vaultFor(plugin), id, enabled ? 'activated' : 'deactivated', { enabled, projectRoot, scope: 'project' });
|
|
45
|
+
const compilation = await recompileAfterPluginMutation(projectRoot, false);
|
|
46
|
+
return { pluginId: id, activation: pluginActivation(plugin, { projectRoot }), scope: 'project', compilation };
|
|
15
47
|
}
|
|
@@ -49,6 +49,60 @@ export function listPluginFiles(pluginDir) {
|
|
|
49
49
|
return out;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const BRICK_ROOT_FILES = /^LICENSE[^/]*$/i;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Files a plugin distributes to one audience.
|
|
56
|
+
*
|
|
57
|
+
* `host` is every file, for a mesh peer or a Total Recall installation.
|
|
58
|
+
* `brick` is the host-free capability only: the directory holding
|
|
59
|
+
* `capability.entry`, plus LICENSE. package.json is regenerated with only its
|
|
60
|
+
* runtime fields, and the README is left behind because it documents the host. The UI, the CLI
|
|
61
|
+
* handler and the host manifest never leave with a brick, so a vendored copy
|
|
62
|
+
* has no UI and no path back to Total Recall. Its plugin.json and package.json
|
|
63
|
+
* are reduced copies, returned as `data` rather than read from disk.
|
|
64
|
+
* @returns {Array<{ path: string, abs: string, size: number, mode: number, data?: Buffer }>}
|
|
65
|
+
*/
|
|
66
|
+
export function pluginBundleFiles(pluginDir, { audience = 'host' } = {}) {
|
|
67
|
+
const files = listPluginFiles(pluginDir);
|
|
68
|
+
if (audience === 'host') return files;
|
|
69
|
+
if (audience !== 'brick') throw new Error(`Unknown bundle audience '${audience}'`);
|
|
70
|
+
const root = fs.realpathSync(pluginDir);
|
|
71
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'plugin.json'), 'utf8'));
|
|
72
|
+
const entry = manifest.capability?.entry;
|
|
73
|
+
if (typeof entry !== 'string') throw new Error(`Plugin '${manifest.id}' declares no capability.entry, so it cannot be vendored as a brick`);
|
|
74
|
+
const capDir = path.posix.dirname(entry);
|
|
75
|
+
const inCap = (p) => (capDir === '.' ? p === entry : p.startsWith(`${capDir}/`));
|
|
76
|
+
const kept = files.filter((f) => f.path.split('/')[0] !== 'ui' && (inCap(f.path) || BRICK_ROOT_FILES.test(f.path)));
|
|
77
|
+
if (!kept.some((f) => f.path === entry)) throw new Error(`capability.entry '${entry}' does not exist in plugin '${manifest.id}'`);
|
|
78
|
+
const reduced = Buffer.from(`${JSON.stringify({
|
|
79
|
+
id: manifest.id, name: manifest.name, version: manifest.version, description: manifest.description,
|
|
80
|
+
brick: true, capability: manifest.capability,
|
|
81
|
+
...(manifest.requires ? { requires: manifest.requires } : {})
|
|
82
|
+
}, null, 2)}\n`);
|
|
83
|
+
const generated = [{ path: 'plugin.json', abs: null, size: reduced.length, mode: 0o644, data: reduced }];
|
|
84
|
+
const pkgFile = path.join(root, 'package.json');
|
|
85
|
+
if (fs.existsSync(pkgFile)) {
|
|
86
|
+
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
|
|
87
|
+
const runtime = {};
|
|
88
|
+
for (const k of ['name', 'version', 'type', 'description', 'license', 'dependencies']) if (pkg[k] !== undefined) runtime[k] = pkg[k];
|
|
89
|
+
// A capability that declares its own dependencies keeps only those: the plugin's other
|
|
90
|
+
// dependencies serve the host side (routes, CLI) and never leave with the brick.
|
|
91
|
+
const own = manifest.capability.dependencies;
|
|
92
|
+
if (own !== undefined) {
|
|
93
|
+
if (!Array.isArray(own) || own.some((d) => typeof d !== 'string')) throw new Error(`Plugin '${manifest.id}' capability.dependencies must be an array of package names`);
|
|
94
|
+
const missing = own.filter((d) => !pkg.dependencies?.[d]);
|
|
95
|
+
if (missing.length) throw new Error(`Plugin '${manifest.id}' capability.dependencies names packages its package.json does not depend on: ${missing.join(', ')}`);
|
|
96
|
+
const kept = Object.fromEntries(own.map((d) => [d, pkg.dependencies[d]]));
|
|
97
|
+
if (Object.keys(kept).length) runtime.dependencies = kept; else delete runtime.dependencies;
|
|
98
|
+
}
|
|
99
|
+
const data = Buffer.from(`${JSON.stringify(runtime, null, 2)}\n`);
|
|
100
|
+
generated.push({ path: 'package.json', abs: null, size: data.length, mode: 0o644, data });
|
|
101
|
+
}
|
|
102
|
+
return [...kept, ...generated]
|
|
103
|
+
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
104
|
+
}
|
|
105
|
+
|
|
52
106
|
function hashEntries(entries) {
|
|
53
107
|
const h = crypto.createHash('sha256');
|
|
54
108
|
for (const e of entries) {
|
|
@@ -15,7 +15,7 @@ export function buildPluginCatalog(projectRoot = process.cwd(), { discover = dis
|
|
|
15
15
|
return {
|
|
16
16
|
id: plugin.id, name: manifest.name || plugin.id, version: manifest.version || null,
|
|
17
17
|
scope: plugin.scope, valid: plugin.valid === true, errors: plugin.errors || [],
|
|
18
|
-
activation: pluginActivation(plugin),
|
|
18
|
+
activation: pluginActivation(plugin, { projectRoot }),
|
|
19
19
|
description: manifest.description || '', namespace: manifest.cli?.command || null,
|
|
20
20
|
callable, operations: [...(manifest.cli?.subcommands || []).filter(command => !['on', 'off'].includes(command.name)),
|
|
21
21
|
...['on', 'off'].map(name => ({ name, description: `${name === 'on' ? 'Enable' : 'Disable'} host execution and compile surfaces`, effect: 'write', output: 'json', args: [] }))].map(command => ({
|
|
@@ -18,7 +18,7 @@ export async function assemblePluginContexts({ projectRoot = process.cwd(), vaul
|
|
|
18
18
|
const blocks = [];
|
|
19
19
|
|
|
20
20
|
for (const plugin of plugins) {
|
|
21
|
-
if (!plugin.valid || !pluginActivation(plugin).enabled) continue;
|
|
21
|
+
if (!plugin.valid || !pluginActivation(plugin, { projectRoot: resolvedProjectRoot }).enabled) continue;
|
|
22
22
|
const { manifest, dir, id } = plugin;
|
|
23
23
|
const name = manifest.name || id;
|
|
24
24
|
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Functional card contract.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Functional card contract. A plugin's card face is its own bespoke Web
|
|
3
|
+
* Component, declared as a `ui.elements[]` entry of kind `card`. There is no
|
|
4
|
+
* template: no shared layout, no widget vocabulary, no allowlist of shapes.
|
|
5
|
+
* Core validates that the face exists and that the commands behind it are
|
|
6
|
+
* declared; it never dictates how the face is arranged.
|
|
7
|
+
*
|
|
8
|
+
* A plugin carries exactly one face and AS MANY secondary screens as it needs,
|
|
9
|
+
* each declared `kind: 'panel'`. Screens are the plugin's own design: it names
|
|
10
|
+
* them, orders them and decides what is on them. The host imposes no count and
|
|
11
|
+
* no screen set, and never derives a screen from the command list.
|
|
7
12
|
*/
|
|
8
13
|
const plain = (v) => v && typeof v === 'object' && !Array.isArray(v);
|
|
9
14
|
const COMMAND = /^[a-z][a-z0-9-]{0,63}$/;
|
|
@@ -15,14 +20,10 @@ export const OUTPUT_KINDS = ['json', 'text'];
|
|
|
15
20
|
export const TIERS = ['core', 'official', 'personal', 'community'];
|
|
16
21
|
export const LICENSE_CLASSES = ['open', 'closed'];
|
|
17
22
|
const STATUS_STATES = ['ok', 'warn', 'error', 'unknown'];
|
|
18
|
-
export const CARD_TEMPLATES = ['console', 'ledger', 'monitor', 'inbox', 'dashboard', 'workbench', 'vault'];
|
|
19
|
-
export const CARD_WIDGETS = ['status', 'actions', 'table', 'detail', 'log', 'form', 'keypad', 'gauge', 'list', 'settings', 'credentials', 'activity', 'live'];
|
|
20
|
-
export const WIDGETS_NEEDING_SOURCE = ['table', 'detail', 'list', 'gauge', 'log'];
|
|
21
23
|
export const CARD_FONTS = ['system', 'inter', 'ibm-plex', 'space-grotesk', 'jetbrains-mono', 'dm-sans', 'outfit', 'fraunces', 'newsreader', 'chivo-mono'];
|
|
22
24
|
export const CARD_DENSITIES = ['compact', 'comfortable', 'spacious'];
|
|
23
25
|
export const CARD_RADII = ['none', 'sm', 'md', 'lg', 'pill'];
|
|
24
26
|
export const CARD_HEADERS = ['plain', 'ledger-rule', 'band', 'tab-strip', 'badge-left'];
|
|
25
|
-
export const CELL_FORMATS = ['text', 'number', 'money', 'date', 'datetime', 'bytes', 'percent', 'status'];
|
|
26
27
|
export const WORKSPACE_PERMISSIONS = ['microphone', 'camera', 'notifications'];
|
|
27
28
|
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
28
29
|
|
|
@@ -87,7 +88,7 @@ export function validateCardContract(manifest) {
|
|
|
87
88
|
if (!LICENSE_CLASSES.includes(manifest.distribution.license)) errors.push(`'distribution.license' must be one of: ${LICENSE_CLASSES.join(', ')}`);
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
+
validateCardFace(manifest, errors, warnings);
|
|
91
92
|
validateBranding(manifest.branding, errors, warnings);
|
|
92
93
|
validateWorkspace(manifest.workspace, errors);
|
|
93
94
|
if (Array.isArray(manifest.secrets)) {
|
|
@@ -101,36 +102,67 @@ export function validateCardContract(manifest) {
|
|
|
101
102
|
return { errors, warnings, states: STATUS_STATES };
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Every plugin has a card face: bespoke owner code, declared once in
|
|
107
|
+
* ui.elements[]. A plugin without one is incomplete, and a plugin that declares
|
|
108
|
+
* a shared template is invalid.
|
|
109
|
+
*
|
|
110
|
+
* The *scaffold* emitted by `plugin create` deliberately contains no card: a
|
|
111
|
+
* face is authored by hand once the plugin's function is understood. A scaffold
|
|
112
|
+
* declares `scaffold: true`, so it installs while the author works and reports
|
|
113
|
+
* its missing face as a warning rather than an error. Any other plugin without
|
|
114
|
+
* a face is an error, because nothing else explains why it is missing.
|
|
115
|
+
*/
|
|
116
|
+
function validateCardFace(manifest, errors, warnings) {
|
|
117
|
+
if (manifest.card_layout !== undefined) {
|
|
118
|
+
errors.push("'card_layout' is not supported: a card face is bespoke owner code in ui.elements[], never a shared template");
|
|
112
119
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
if (region.widget === 'form' && !commandNames.has(region.command)) errors.push(`${where}.command must name a declared cli subcommand`);
|
|
122
|
-
if (region.commands !== undefined) {
|
|
123
|
-
if (!Array.isArray(region.commands) || region.commands.some((c) => !commandNames.has(c))) errors.push(`${where}.commands must list declared cli subcommands`);
|
|
120
|
+
const elements = manifest.ui?.elements;
|
|
121
|
+
// A brick is distributed as capability code alone. It carries no UI, so it
|
|
122
|
+
// has no face; every other plugin still requires exactly one.
|
|
123
|
+
if (manifest.brick === true) {
|
|
124
|
+
validateCapability(manifest, errors);
|
|
125
|
+
if (manifest.ui !== undefined && Array.isArray(elements) && elements.length > 0) {
|
|
126
|
+
errors.push("a brick ships without UI: remove 'ui.elements' or drop 'brick: true'");
|
|
124
127
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (manifest.capability !== undefined) validateCapability(manifest, errors);
|
|
131
|
+
if (!Array.isArray(elements) || elements.length === 0) {
|
|
132
|
+
// A scaffold is a freshly created plugin whose face has not been authored
|
|
133
|
+
// yet. It must be installable so the author can iterate, but it is not a
|
|
134
|
+
// shippable plugin, so the missing face is reported and stays visible.
|
|
135
|
+
if (manifest.scaffold === true) {
|
|
136
|
+
warnings.push("'ui.elements' declares no card face yet: author ui/card.js and ui/DESIGN.md by hand for this plugin's own function, then declare the face in ui.elements[]");
|
|
137
|
+
return;
|
|
131
138
|
}
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
errors.push("'ui.elements' must declare the plugin's card face; every plugin has one, authored by hand");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// One face, and as many secondary screens as the plugin needs. Cardinality is
|
|
143
|
+
// checked for `card` alone, so panels may be declared in any number and on
|
|
144
|
+
// either side of the face.
|
|
145
|
+
const faces = elements.filter((element) => plain(element) && element.kind === 'card');
|
|
146
|
+
if (faces.length === 0) errors.push("'ui.elements' must declare an element of kind 'card'");
|
|
147
|
+
if (faces.length > 1) errors.push("'ui.elements' must declare exactly one card face; further screens use kind 'panel'");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* `capability {entry, exports}` names the host-free module a project vendors:
|
|
152
|
+
* a relative path inside the plugin, and the exported names it promises.
|
|
153
|
+
*/
|
|
154
|
+
function validateCapability(manifest, errors) {
|
|
155
|
+
const cap = manifest.capability;
|
|
156
|
+
if (!plain(cap)) { errors.push("'capability' must declare {entry, exports}"); return; }
|
|
157
|
+
const entry = cap.entry;
|
|
158
|
+
if (typeof entry !== 'string' || !/^[A-Za-z0-9._\/-]{1,200}\.m?js$/.test(entry) || entry.startsWith('/') || entry.split('/').includes('..')) {
|
|
159
|
+
errors.push("capability.entry must be a relative .js or .mjs path inside the plugin");
|
|
160
|
+
} else if (entry.split('/')[0] === 'ui') {
|
|
161
|
+
errors.push('capability.entry must not live under ui/: a brick contains no UI');
|
|
162
|
+
}
|
|
163
|
+
if (!Array.isArray(cap.exports) || cap.exports.length === 0 || cap.exports.some((n) => typeof n !== 'string' || !/^[A-Za-z_$][\w$]*$/.test(n))) {
|
|
164
|
+
errors.push('capability.exports must be a non-empty array of export names');
|
|
165
|
+
}
|
|
134
166
|
}
|
|
135
167
|
|
|
136
168
|
function validateBranding(branding, errors, warnings) {
|
|
@@ -29,7 +29,7 @@ export function globalPluginsDir() {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function bundledPluginsDir() {
|
|
32
|
-
return
|
|
32
|
+
return path.join(PACKAGE_ROOT, 'scaffold', '.agent', 'skills', 'total-recall', 'plugins');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** The vault that owns records for plugins installed in `pluginsDir` (`<brain>/plugins` → `<brain>/memory-vault`). */
|
|
@@ -434,11 +434,10 @@ export function discoverPlugins(projectRoot = process.cwd()) {
|
|
|
434
434
|
export function listBundledPlugins(projectRoot = process.cwd()) {
|
|
435
435
|
const seen = new Set();
|
|
436
436
|
const out = [];
|
|
437
|
-
//
|
|
438
|
-
//
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
: [bundledPluginsDir(), path.join(PACKAGE_ROOT, '.agent', 'skills', 'total-recall', 'plugins')];
|
|
437
|
+
// Each plugin repository owns its own manifest, and nothing keeps a second
|
|
438
|
+
// copy of it. A shared fixture describing a plugin would be a competing
|
|
439
|
+
// definition of that plugin, and it drifts.
|
|
440
|
+
const dirs = [bundledPluginsDir(), path.join(PACKAGE_ROOT, '.agent', 'skills', 'total-recall', 'plugins')];
|
|
442
441
|
for (const dir of dirs) {
|
|
443
442
|
if (!fs.existsSync(dir)) continue;
|
|
444
443
|
for (const p of readPluginsDir(dir, 'bundled')) {
|