@sanqianx/project-knowledge 5.0.30 → 5.0.31
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/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +21 -0
- package/_site/_test/appearance-settings-test.js +148 -0
- package/_site/_test/helpers/parallel-capture-safety-r5-cap-shell.js +606 -0
- package/_site/_test/helpers/parallel-capture-safety-r5-memory-shell.js +464 -0
- package/_site/_test/helpers/parallel-dock-acceptance-env.js +301 -0
- package/_site/_test/helpers/parallel-dock-acceptance-r2-env.js +378 -0
- package/_site/_test/helpers/parallel-dock-acceptance-r2-ui.js +314 -0
- package/_site/_test/helpers/parallel-dock-acceptance-ui.js +195 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-credential-preload.js +113 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-env.js +307 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-fixture.js +373 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-ui.js +314 -0
- package/_site/_test/helpers/parallel-engine-reconcile-r4-harness.js +340 -0
- package/_site/_test/helpers/parallel-engine-reconcile-r4-standin-analyzer.js +82 -0
- package/_site/_test/helpers/parallel-memory-capture-r3-cap-shell.js +605 -0
- package/_site/_test/helpers/parallel-memory-capture-r3-shell.js +176 -0
- package/_site/_test/helpers/parallel-memory-capture-r4-cap-shell.js +577 -0
- package/_site/_test/helpers/parallel-memory-injection-shell.js +723 -0
- package/_site/_test/helpers/parallel-memory-injection-wb-host.js +81 -0
- package/_site/_test/helpers/parallel-workbench-drafts-r5-fixture.js +295 -0
- package/_site/_test/helpers/parallel-workbench-drafts-r5-harness.js +573 -0
- package/_site/_test/helpers/parallel-workbench-drafts-r5-host.js +69 -0
- package/_site/_test/helpers/parallel-workbench-runtime-harness.js +587 -0
- package/_site/_test/helpers/qa-r45-harness.js +94 -0
- package/_site/_test/helpers/qa-r48-env.js +64 -0
- package/_site/_test/helpers/qa-r51-env.cjs +77 -0
- package/_site/_test/parallel-capture-safety-r5-cap006-probe.js +524 -0
- package/_site/_test/parallel-capture-safety-r5-cap008e-probe.js +577 -0
- package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +320 -0
- package/_site/_test/parallel-engine-reconcile-r4-eng007-probe.js +304 -0
- package/_site/_test/parallel-logging-acceptance-log003-probe.js +78 -0
- package/_site/_test/parallel-logging-acceptance-log004-probe.js +85 -0
- package/_site/_test/parallel-memory-capture-r3-cap001-probe.js +238 -0
- package/_site/_test/parallel-memory-capture-r3-cap006-probe.js +371 -0
- package/_site/_test/parallel-memory-capture-r3-cap008-probe.js +439 -0
- package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +271 -0
- package/_site/_test/parallel-memory-capture-r4-cap006-probe.js +519 -0
- package/_site/_test/parallel-memory-capture-r4-cap008e-probe.js +569 -0
- package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +314 -0
- package/_site/_test/parallel-memory-injection-origin-probe.js +412 -0
- package/_site/_test/parallel-memory-injection-probe.js +411 -0
- package/_site/_test/parallel-workbench-drafts-r4-probe.js +477 -0
- package/_site/_test/parallel-workbench-drafts-r5-chrome-env-bisect.js +89 -0
- package/_site/_test/parallel-workbench-drafts-r5-probe.js +593 -0
- package/_site/_test/parallel-workbench-runtime-minimax-probe.js +321 -0
- package/_site/_test/parallel-workbench-runtime-wb004-ordering.js +307 -0
- package/_site/_test/parallel-workbench-runtime-wb005-drafts.js +313 -0
- package/_site/_test/parallel-workbench-runtime-wb008-abort.js +321 -0
- package/_site/_test/qa-r45-offline-backfill-test.js +279 -0
- package/_site/_test/qa-r48-sys003-blank-secret-test.js +258 -0
- package/_site/_test/t07c-cln-001-002-007-coverage-test.js +135 -0
- package/_site/_test/t07d-git-rel-coverage-test.js +224 -0
- package/_site/_test/t07e-qta-coverage-test.js +195 -0
- package/_site/_test/t07f-mem-008-coverage-test.js +101 -0
- package/_site/lib/server-app.js +11 -2
- package/_site/lib/settings-store.js +43 -1
- package/module-runtime-manifest.json +6 -6
- package/package.json +1 -1
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/ui/index.html +18 -1
- package/ui/product.css +6 -2
- package/ui/product.js +86 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// _site/_test/t07f-mem-008-coverage-test.js
|
|
2
|
+
//
|
|
3
|
+
// T07F ledger coverage for MEM-008 来源边界 (memory candidate provenance):
|
|
4
|
+
//
|
|
5
|
+
// steps: 委派Agent指令/系统维护输出诱发记忆候选。
|
|
6
|
+
// expected: 不得自动当作人类长期偏好。/ C01未解决项明确阻断。
|
|
7
|
+
//
|
|
8
|
+
// The behaviour under test is the REAL vendored engine's MemoryEligibility
|
|
9
|
+
// gate (_modules/knowledge-engine/src/memory-eligibility.js): every candidate
|
|
10
|
+
// must be vouched for by a conversation snapshot that is bound to THIS run's
|
|
11
|
+
// promoted evidence references, and the quoted source event must be HUMAN
|
|
12
|
+
// input with a matching content hash. Delegated-agent instructions and
|
|
13
|
+
// system/maintenance outputs are refused with explicit codes; an unresolved
|
|
14
|
+
// provenance chain (the C01-class boundary case) blocks explicitly instead
|
|
15
|
+
// of admitting silently.
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const assert = require('node:assert/strict');
|
|
20
|
+
const path = require('node:path');
|
|
21
|
+
const crypto = require('node:crypto');
|
|
22
|
+
|
|
23
|
+
const REPO = path.resolve(__dirname, '..', '..');
|
|
24
|
+
const { MemoryEligibility } = require(path.join(REPO, '_modules', 'knowledge-engine', 'src', 'memory-eligibility.js'));
|
|
25
|
+
|
|
26
|
+
const sha = text => crypto.createHash('sha256').update(text).digest('hex');
|
|
27
|
+
|
|
28
|
+
const HUMAN_TEXT = '我以后所有项目的提交信息都用中文写,这是我自己的长期习惯。';
|
|
29
|
+
const AGENT_TEXT = '以最小改动修复该测试,不要重构。';
|
|
30
|
+
const SYSTEM_TEXT = '索引重建完成:重建了 3 个项目的知识索引。';
|
|
31
|
+
|
|
32
|
+
const snapshot = {
|
|
33
|
+
snapshotHash: 'snap-1',
|
|
34
|
+
turns: [{
|
|
35
|
+
userEvents: [
|
|
36
|
+
{ eventId: 'ev-human', inputOrigin: 'human', content: HUMAN_TEXT, contentHash: sha(HUMAN_TEXT) },
|
|
37
|
+
{ eventId: 'ev-agent', inputOrigin: 'agent', content: AGENT_TEXT, contentHash: sha(AGENT_TEXT) },
|
|
38
|
+
{ eventId: 'ev-system', inputOrigin: 'system', content: SYSTEM_TEXT, contentHash: sha(SYSTEM_TEXT) },
|
|
39
|
+
],
|
|
40
|
+
}],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function runWith(refs) {
|
|
44
|
+
return { projectId: 'p1', commitSha: 'c1', staging: { operations: [{ evidenceReferences: refs }] } };
|
|
45
|
+
}
|
|
46
|
+
const candidate = over => ({
|
|
47
|
+
text: HUMAN_TEXT,
|
|
48
|
+
quote: HUMAN_TEXT,
|
|
49
|
+
sourceEventId: 'ev-human',
|
|
50
|
+
sourceHash: sha(HUMAN_TEXT),
|
|
51
|
+
eligibility: { durable: true, crossProject: true, reason: 'owner-stated long-term habit', scopeReason: 'applies across all projects' },
|
|
52
|
+
scopeType: 'global',
|
|
53
|
+
...over,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function main() {
|
|
57
|
+
const gate = new MemoryEligibility({ readSnapshot: () => snapshot });
|
|
58
|
+
const boundRun = runWith(['conversation:snap-1']);
|
|
59
|
+
|
|
60
|
+
// 1. A delegated-agent instruction can never become a long-term preference.
|
|
61
|
+
const agentClaim = gate.verify(
|
|
62
|
+
candidate({ text: AGENT_TEXT, quote: AGENT_TEXT, sourceEventId: 'ev-agent', sourceHash: sha(AGENT_TEXT) }),
|
|
63
|
+
gate.resolve(boundRun), 'p1');
|
|
64
|
+
assert.ok(agentClaim.ok === false && agentClaim.code === 'SOURCE_NOT_HUMAN',
|
|
65
|
+
`QA-SPEC-MEM-008: a delegated-agent instruction is refused as a memory source (${agentClaim.code})`);
|
|
66
|
+
|
|
67
|
+
// 2. System/maintenance output likewise.
|
|
68
|
+
const systemClaim = gate.verify(
|
|
69
|
+
candidate({ text: SYSTEM_TEXT, quote: SYSTEM_TEXT, sourceEventId: 'ev-system', sourceHash: sha(SYSTEM_TEXT) }),
|
|
70
|
+
gate.resolve(boundRun), 'p1');
|
|
71
|
+
assert.ok(systemClaim.ok === false && systemClaim.code === 'SOURCE_NOT_HUMAN',
|
|
72
|
+
`QA-SPEC-MEM-008: system maintenance output is refused as a memory source (${systemClaim.code})`);
|
|
73
|
+
|
|
74
|
+
// 3. The C01-class unresolved chain: no conversation boundary reference (or
|
|
75
|
+
// a reference to a foreign snapshot) resolves -> SNAPSHOT_UNAVAILABLE, an
|
|
76
|
+
// EXPLICIT block, never a silent admission.
|
|
77
|
+
const unresolvedRun = runWith([]); // boundary record never persisted/linked
|
|
78
|
+
assert.strictEqual(gate.resolve(unresolvedRun), null,
|
|
79
|
+
'QA-SPEC-MEM-008: a run without a persisted conversation boundary resolves NO snapshot');
|
|
80
|
+
const foreignRun = runWith(['conversation:some-other-hash']);
|
|
81
|
+
assert.strictEqual(gate.resolve(foreignRun), null,
|
|
82
|
+
'QA-SPEC-MEM-008: a foreign/later-frozen snapshot can never vouch for this claim');
|
|
83
|
+
const blocked = gate.verify(candidate({}), gate.resolve(unresolvedRun), 'p1');
|
|
84
|
+
assert.ok(blocked.ok === false && blocked.code === 'SNAPSHOT_UNAVAILABLE',
|
|
85
|
+
`QA-SPEC-MEM-008: the unresolved C01-class chain blocks the candidate EXPLICITLY (${blocked.code})`);
|
|
86
|
+
|
|
87
|
+
// 4. Hash/quote chain integrity.
|
|
88
|
+
const hashMismatch = gate.verify(candidate({ sourceHash: 'deadbeef' }), gate.resolve(boundRun), 'p1');
|
|
89
|
+
assert.ok(hashMismatch.code === 'SOURCE_HASH_MISMATCH', 'QA-SPEC-MEM-008: a rewritten source is refused (hash mismatch)');
|
|
90
|
+
const quoteMismatch = gate.verify(candidate({ quote: '从未说过的偏好' }), gate.resolve(boundRun), 'p1');
|
|
91
|
+
assert.ok(quoteMismatch.code === 'QUOTE_NOT_IN_SOURCE', 'QA-SPEC-MEM-008: a fabricated quote is refused');
|
|
92
|
+
|
|
93
|
+
// 5. Positive control: the real human sentence with its frozen chain passes.
|
|
94
|
+
const ok = gate.verify(candidate({}), gate.resolve(boundRun), 'p1');
|
|
95
|
+
assert.ok(ok.ok === true, `QA-SPEC-MEM-008: a genuine human long-term preference with a verified chain passes (${JSON.stringify(ok)})`);
|
|
96
|
+
|
|
97
|
+
console.log('QA-SPEC-MEM-008: agent/system sources refused; unresolved provenance blocks explicitly; genuine human chain passes');
|
|
98
|
+
console.log('t07f-mem-008-coverage-test PASS');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
main();
|
package/_site/lib/server-app.js
CHANGED
|
@@ -9,7 +9,7 @@ const runtimeControl = require('./runtime-control');
|
|
|
9
9
|
const hookManager = require('./hook-manager');
|
|
10
10
|
const claudeCliRunner = require('./claude-cli-runner');
|
|
11
11
|
const { StorageLayout } = require('./storage-layout');
|
|
12
|
-
const { SettingsStore } = require('./settings-store');
|
|
12
|
+
const { SettingsStore, defaultAppearance } = require('./settings-store');
|
|
13
13
|
const { ProjectRegistryStore } = require('./project-registry-store');
|
|
14
14
|
const { ProjectStore } = require('./project-store');
|
|
15
15
|
const { ProjectLifecycleService } = require('./project-lifecycle-service');
|
|
@@ -870,7 +870,7 @@ function createRequestHandler(runtime, options = {}) {
|
|
|
870
870
|
res.once('finish', () => {
|
|
871
871
|
if (requestFailed || res.statusCode >= 400) return;
|
|
872
872
|
if (['POST', 'PATCH', 'PUT', 'DELETE'].includes(req.method)
|
|
873
|
-
&& /^\/api\/(?:projects(?:\/|$)|domains(?:\/|$)|brain$|settings$|modules\/configure$)/.test(requestPathname)
|
|
873
|
+
&& /^\/api\/(?:projects(?:\/|$)|domains(?:\/|$)|brain$|settings$|appearance$|modules\/configure$)/.test(requestPathname)
|
|
874
874
|
&& requestPathname !== '/api/projects/preflight-import') runtime.registryEvents?.publish();
|
|
875
875
|
Promise.resolve(runtime.logger.info('http.request_completed', 'HTTP request completed.', {
|
|
876
876
|
operationId: requestOperationId,
|
|
@@ -943,6 +943,15 @@ function createRequestHandler(runtime, options = {}) {
|
|
|
943
943
|
const configuration = await runtime.moduleBridge.syncEngineConfiguration();
|
|
944
944
|
return send(res, 200, { ok: true, brain: settings.brain, configuration });
|
|
945
945
|
}
|
|
946
|
+
if (method === 'GET' && pathname === '/api/appearance') {
|
|
947
|
+
const settings = runtime.settingsStore.read({ allowMissing: true });
|
|
948
|
+
return send(res, 200, { ok: true, appearance: settings.appearance || defaultAppearance() });
|
|
949
|
+
}
|
|
950
|
+
if (method === 'PATCH' && pathname === '/api/appearance') {
|
|
951
|
+
const body = await readJsonBody(req);
|
|
952
|
+
const appearance = await runtime.settingsStore.replaceAppearance(body?.appearance || body);
|
|
953
|
+
return send(res, 200, { ok: true, appearance });
|
|
954
|
+
}
|
|
946
955
|
if (method === 'POST' && pathname === '/api/domains') {
|
|
947
956
|
const body = await readJsonBody(req);
|
|
948
957
|
if (typeof body.name !== 'string' || !body.name.trim() || body.name.length > 100) throw new DomainError('INVALID_ARGUMENT', '请输入 1–100 个字符的领域名称。');
|
|
@@ -9,6 +9,7 @@ function defaultSettings() {
|
|
|
9
9
|
schemaVersion: 2,
|
|
10
10
|
knowledge: { rootPath: '' },
|
|
11
11
|
brain: { id: 'brain-default', name: '我的智脑', domains: [] },
|
|
12
|
+
appearance: defaultAppearance(),
|
|
12
13
|
ai: { schema: 'ai-profiles/v1', profiles: [] },
|
|
13
14
|
embedding: {},
|
|
14
15
|
logging: {
|
|
@@ -21,6 +22,34 @@ function defaultSettings() {
|
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
const APPEARANCE_PRESETS = ['pure', 'oled', 'steel'];
|
|
26
|
+
const APPEARANCE_TOKENS = ['page', 'surface', 'surface2', 'surface3', 'line', 'text', 'muted', 'faint', 'nav', 'accent', 'accent-soft', 'good', 'bad', 'bad-soft'];
|
|
27
|
+
const APPEARANCE_HEX = /^#[0-9a-fA-F]{6}$/;
|
|
28
|
+
|
|
29
|
+
function defaultAppearance() {
|
|
30
|
+
return { preset: 'pure', overrides: { light: {}, dark: {} } };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function validateAppearance(value) {
|
|
34
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new DomainError('INVALID_ARGUMENT', '皮肤配置无效。', { status: 400 });
|
|
35
|
+
const allowed = new Set(['preset', 'overrides']);
|
|
36
|
+
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new DomainError('INVALID_ARGUMENT', `皮肤配置不支持字段:${key}。`, { status: 400, details: { field: key } });
|
|
37
|
+
const preset = value.preset === undefined ? 'pure' : value.preset;
|
|
38
|
+
if (!APPEARANCE_PRESETS.includes(preset)) throw new DomainError('INVALID_ARGUMENT', '未知的配色预设。', { status: 400 });
|
|
39
|
+
const overrides = value.overrides === undefined ? { light: {}, dark: {} } : value.overrides;
|
|
40
|
+
if (!overrides || typeof overrides !== 'object' || Array.isArray(overrides)) throw new DomainError('INVALID_ARGUMENT', '皮肤颜色覆盖无效。', { status: 400 });
|
|
41
|
+
for (const key of Object.keys(overrides)) if (!['light', 'dark'].includes(key)) throw new DomainError('INVALID_ARGUMENT', `皮肤颜色覆盖不支持主题:${key}。`, { status: 400, details: { field: key } });
|
|
42
|
+
for (const theme of ['light', 'dark']) {
|
|
43
|
+
const entries = overrides[theme] === undefined ? {} : overrides[theme];
|
|
44
|
+
if (!entries || typeof entries !== 'object' || Array.isArray(entries)) throw new DomainError('INVALID_ARGUMENT', `皮肤 ${theme} 主题颜色无效。`, { status: 400 });
|
|
45
|
+
for (const token of Object.keys(entries)) {
|
|
46
|
+
if (!APPEARANCE_TOKENS.includes(token)) throw new DomainError('INVALID_ARGUMENT', `不支持的皮肤颜色项:${token}。`, { status: 400, details: { field: token } });
|
|
47
|
+
if (!APPEARANCE_HEX.test(String(entries[token]))) throw new DomainError('INVALID_ARGUMENT', `皮肤颜色 ${token} 必须是 #RRGGBB 格式。`, { status: 400, details: { field: token } });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { preset, overrides: { light: { ...overrides.light }, dark: { ...overrides.dark } } };
|
|
51
|
+
}
|
|
52
|
+
|
|
24
53
|
function mergeObjects(base, patch) {
|
|
25
54
|
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) return patch;
|
|
26
55
|
const output = { ...(base && typeof base === 'object' && !Array.isArray(base) ? base : {}) };
|
|
@@ -56,6 +85,8 @@ function validateSettings(settings) {
|
|
|
56
85
|
if (!Array.isArray(logging.levels) || !logging.levels.length || logging.levels.some(level => !['trace', 'debug', 'info', 'warn', 'error', 'fatal'].includes(level))) {
|
|
57
86
|
throw new DomainError('DATA_CORRUPT', 'Settings logging configuration is invalid.', { status: 500 });
|
|
58
87
|
}
|
|
88
|
+
settings.appearance = settings.appearance || defaultAppearance();
|
|
89
|
+
settings.appearance = validateAppearance(settings.appearance);
|
|
59
90
|
return settings;
|
|
60
91
|
}
|
|
61
92
|
|
|
@@ -113,6 +144,17 @@ class SettingsStore {
|
|
|
113
144
|
});
|
|
114
145
|
}
|
|
115
146
|
|
|
147
|
+
async replaceAppearance(appearance) {
|
|
148
|
+
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
149
|
+
const settings = this.read();
|
|
150
|
+
settings.appearance = validateAppearance(appearance);
|
|
151
|
+
settings.updatedAt = new Date().toISOString();
|
|
152
|
+
validateSettings(settings);
|
|
153
|
+
this.atomic.writeJsonAtomic(this.filePath, settings);
|
|
154
|
+
return settings.appearance;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
116
158
|
async addDomain(domain) {
|
|
117
159
|
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
118
160
|
const settings = this.read();
|
|
@@ -150,4 +192,4 @@ class SettingsStore {
|
|
|
150
192
|
}
|
|
151
193
|
}
|
|
152
194
|
|
|
153
|
-
module.exports = { SettingsStore, defaultSettings, validateSettings, mergeObjects };
|
|
195
|
+
module.exports = { SettingsStore, defaultSettings, defaultAppearance, validateAppearance, validateSettings, mergeObjects };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": "project-knowledge/module-content/v1",
|
|
3
3
|
"productFiles": {
|
|
4
|
-
"ui/index.html": "
|
|
4
|
+
"ui/index.html": "cdeddfeeb73866a270472414d39bf58ffd2bed960a2e9b79fb02e8f2539dc414",
|
|
5
5
|
"ui/knowledge-panel.html": "dfd85f15759472252d797853263e9da0054b251c56bb9ccdc8a75e6301334ca8",
|
|
6
|
-
"ui/product.js": "
|
|
6
|
+
"ui/product.js": "e82131bcb22cfd7b7ca3b0e32d3bd1bc924f59b2c1c44110388e5b9086e40157",
|
|
7
7
|
"ui/live-client.js": "0d81fa894c629bb839e1931fc3c5ebad4d831aae8232d6ce8c0f542e9e3559e8",
|
|
8
|
-
"ui/product.css": "
|
|
8
|
+
"ui/product.css": "0fa06692949636fabea589a4b093969bc36ca49c48dcfb4ba0b2415d6ec7f3b5",
|
|
9
9
|
"ui/favicon.svg": "c48be946b224112ebb0238b44263f7a61bda31e531afa895c2e9801c0ff24f32",
|
|
10
10
|
"plugins/project-knowledge/hooks/claude.json": "d61510327e3e1facbb4c645228e9f50cad05a88b33d80c4c22e5ba9f8b9f5359",
|
|
11
11
|
"plugins/project-knowledge/hooks/codex.json": "216e03c07295606ef6ebb2c4f669ad0d790b5e7c4f3f34600488033db75e4239",
|
|
12
12
|
"plugins/project-knowledge/scripts/context-hook.cjs": "da666153ad5723592cce42d25337ae649f7d93e43fab76b3c6d1263933de063f",
|
|
13
13
|
"plugins/project-knowledge/scripts/mcp-launcher.cjs": "7c68830b5c73eb53ef030756a4de33987f7eab6b1a6cc15602835aac3f954893",
|
|
14
|
-
"plugins/project-knowledge/.claude-plugin/plugin.json": "
|
|
15
|
-
"plugins/project-knowledge/.codex-plugin/plugin.json": "
|
|
16
|
-
"plugins/project-knowledge/.mcp.json": "
|
|
14
|
+
"plugins/project-knowledge/.claude-plugin/plugin.json": "59ad3f272ded6a27ef41cf1d708627d65a7051f484569bc0e1f39534223aed8b",
|
|
15
|
+
"plugins/project-knowledge/.codex-plugin/plugin.json": "64535429df3c28f911d0eb612cadf4aac7b3976d81bd92d6d18d3d5612e5915a",
|
|
16
|
+
"plugins/project-knowledge/.mcp.json": "cff99a572f83892725f27b7389ed03af2971546121a26a823cfa367a60b2e5c4",
|
|
17
17
|
"ui/version-info.js": "01a82217b031de54b80d6c7974da9c70888c4c90a046bd4248a808f7989ddce7",
|
|
18
18
|
"ui/version-info.css": "209fad8e42b661f72d2aba3280e1ca47768b5cefb776fe5459538d34fbad120f"
|
|
19
19
|
},
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
3
|
"name": "project-knowledge",
|
|
4
4
|
"hooks": "./hooks/claude.json",
|
|
5
|
-
"version": "5.0.
|
|
5
|
+
"version": "5.0.31",
|
|
6
6
|
"description": "Read durable project decisions and implementation history from Project Knowledge.",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "SanQianX",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"const fs=require('fs'),path=require('path'),os=require('os');const PKG='@sanqianx/project-knowledge',SC='project-knowledge/integration-runtime/v1';let f='';const root=process.env.CLAUDE_PLUGIN_ROOT||process.env.PLUGIN_ROOT;if(root){f=path.join(root,'scripts','mcp-launcher.cjs');if(!fs.existsSync(f))f=''}if(!f){const dd=process.env.KB_DATA_DIR||path.join(os.homedir(),'.project-knowledge-v5');try{const bp=path.join(dd,'integration-runtime.json');const st=fs.statSync(bp);if(st.isFile()&&st.size<=32768){const b=JSON.parse(fs.readFileSync(bp,'utf8'));if(b&&b.schema===SC&&b.packageName===PKG&&typeof b.packageRoot==='string'&&path.isAbsolute(b.packageRoot)){const c=path.join(b.packageRoot,'plugins','project-knowledge','scripts','mcp-launcher.cjs');const rr=fs.realpathSync(b.packageRoot),cr=fs.realpathSync(c);const rel=path.relative(rr,cr);if(rel&&rel!=='..'&&!rel.startsWith('..'+path.sep)&&!path.isAbsolute(rel)&&fs.statSync(cr).isFile())f=cr}}}catch(e){}}if(!f){console.error('[project-knowledge-mcp] 未能通过受信任插件根或已验证的安装绑定定位启动器,已停止;不访问网络,也不加载工作目录源码。');process.exit(127)}require(f);"
|
|
9
9
|
],
|
|
10
10
|
"env": {
|
|
11
|
-
"KB_PLUGIN_VERSION": "5.0.
|
|
11
|
+
"KB_PLUGIN_VERSION": "5.0.31"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
package/ui/index.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html lang="zh-CN" data-theme="light">
|
|
2
|
+
<html lang="zh-CN" data-theme="light" data-skin="pure">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark">
|
|
5
5
|
<title>Project Knowledge · 我的智脑</title><link rel="icon" type="image/svg+xml" href="/favicon.svg?v=folded-k-1"><link rel="stylesheet" href="/product.css"><link rel="stylesheet" href="/version-info.css">
|
|
@@ -41,6 +41,23 @@
|
|
|
41
41
|
<section><h3>后台维护模型</h3><p class="muted">使用持久化默认模型,不跟随聊天中的临时切换。</p><select id="maintenanceModel" aria-label="后台维护默认模型"></select><div class="actions"><button id="saveMaintenance">保存默认模型</button><button id="configureProviders">管理模型供应商</button></div><p id="configurationStatus" class="muted"></p></section>
|
|
42
42
|
<section><h3>向量检索模型</h3><p id="embeddingStatus" class="muted">正在读取配置。</p><button id="openEmbedding">配置向量模型</button><p class="muted">凭据由工作台统一保存。未配置时仍可使用文本检索。</p></section>
|
|
43
43
|
<section><h3>智脑设置</h3><label>名称<input id="brainName" maxlength="100"></label><label>知识根目录<div class="input-with-action"><input id="knowledgeRoot"><button id="pickRoot">选择</button></div></label><label>向量索引目录<output id="indexStoragePath" class="detail-path"></output></label><p id="indexStorageStatus" class="muted"></p><p class="muted">索引跟随知识根目录,可重新构建;切换时原索引保留,已有项目知识与共享知识不移动。</p><button id="saveBrainSettings">保存设置</button></section>
|
|
44
|
+
<section><h3>外观与皮肤</h3><p class="muted">预设与自定义颜色分浅色、深色两套;改动即时预览,保存后对本机所有入口生效。</p>
|
|
45
|
+
<label>配色预设<select id="skinPreset"><option value="pure">纯净黑白</option><option value="oled">OLED 纯黑</option><option value="steel">钢青(旧版配色)</option></select></label>
|
|
46
|
+
<div class="segmented" id="skinThemeTabs"><button data-skin-theme="light" class="active">浅色主题</button><button data-skin-theme="dark">深色主题</button></div>
|
|
47
|
+
<div class="skin-colors" id="skinColors">
|
|
48
|
+
<label class="skin-color">页面底色<input type="color" data-token="page"></label>
|
|
49
|
+
<label class="skin-color">卡片底色<input type="color" data-token="surface"></label>
|
|
50
|
+
<label class="skin-color">正文文字<input type="color" data-token="text"></label>
|
|
51
|
+
<label class="skin-color">强调色<input type="color" data-token="accent"></label>
|
|
52
|
+
</div>
|
|
53
|
+
<details class="skin-more"><summary>更多颜色</summary><div class="skin-colors">
|
|
54
|
+
<label class="skin-color">分隔线<input type="color" data-token="line"></label>
|
|
55
|
+
<label class="skin-color">次要文字<input type="color" data-token="muted"></label>
|
|
56
|
+
<label class="skin-color">成功色<input type="color" data-token="good"></label>
|
|
57
|
+
<label class="skin-color">危险色<input type="color" data-token="bad"></label>
|
|
58
|
+
</div></details>
|
|
59
|
+
<div class="actions"><button id="saveAppearance" class="primary">保存皮肤</button><button id="resetAppearance">恢复默认</button><button id="exportSkin">导出皮肤</button><button id="importSkin">导入皮肤</button><input type="file" id="importSkinFile" accept=".json,application/json" hidden></div>
|
|
60
|
+
<p id="appearanceStatus" class="muted"></p></section>
|
|
44
61
|
<section><div class="actions"><button id="openEngine">知识引擎诊断</button><button id="openLogs">系统诊断记录</button></div><p class="muted">诊断不影响正在进行的会话与维护。</p></section>
|
|
45
62
|
</div>
|
|
46
63
|
</aside>
|
package/ui/product.css
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
:root{--page:#
|
|
1
|
+
:root{--page:#ffffff;--surface:#ffffff;--surface2:#f6f6f7;--surface3:#ececee;--line:#e2e2e5;--text:#1a1a1e;--muted:#6d6d75;--faint:#8a8a92;--nav:#fafafa;--accent:#2f6db5;--accent-soft:#e2ecf8;--good:#2e7d5b;--bad:#b04a4a;--bad-soft:#f7ecec;color-scheme:light}
|
|
2
2
|
label>.detail-path{display:block;width:100%;margin:8px 0 0;color:var(--text)}
|
|
3
|
+
.skin-colors{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 16px;margin:12px 0}.skin-color{display:flex;align-items:center;gap:8px;margin:0;font-size:12px;color:var(--muted)}.skin-color input{width:40px;height:28px;padding:2px;flex:none}.skin-more{margin:8px 0}.skin-more summary{cursor:pointer;color:var(--muted);font-size:12px}#skinThemeTabs{margin:4px 0 8px}
|
|
3
4
|
.memory-toolbar{display:flex;justify-content:space-between;align-items:center;gap:24px}.memory-meta{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:16px}.memory-evidence{margin-top:24px;border-top:1px solid var(--line);padding-top:16px}.memory-evidence summary{cursor:pointer;color:var(--muted)}.memory-evidence p,.memory-evidence blockquote{white-space:pre-wrap;overflow-wrap:anywhere}.memory-evidence blockquote{margin:16px 0;border-left:2px solid var(--line);padding-left:16px;color:var(--muted)}
|
|
4
5
|
.agent-capture-row{display:flex;align-items:center;gap:16px;padding:16px 0;border-bottom:1px solid var(--line)}.agent-capture-row>div:first-child{flex:1;min-width:0}.agent-capture-row small{display:block;color:var(--muted);margin-top:8px;overflow-wrap:anywhere}.agent-capture-row .actions{flex-shrink:0}#agentCaptureFeedback{white-space:pre-wrap}
|
|
5
6
|
.agent-detail{margin-top:8px}.agent-detail summary{cursor:pointer;color:var(--muted);font-size:12px;user-select:none}.agent-detail[open] summary{margin-bottom:2px}.agent-detail .actions{margin-top:8px}
|
|
6
7
|
#logsDialog{display:flex;flex-direction:column;overflow:hidden}#logsDialog:not([open]){display:none}#logsContent{overflow:auto;min-height:0;flex:1;margin-top:16px}#logsContent .row{align-items:flex-start;cursor:pointer}#logsContent pre{flex:1;min-width:0;margin:0}#logsContent .log-entry{border-bottom:1px solid var(--line)}#logsContent .log-detail{padding:16px;background:var(--surface2);max-height:320px;overflow:auto}#logsContent [data-level=warn],#logsContent [data-level=error],#logsContent [data-level=fatal]{color:var(--bad)}#logsContent .row time,#logsContent .row pre{color:inherit}
|
|
7
8
|
@media(prefers-reduced-motion:reduce){*,*::before,*::after{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
|
|
8
9
|
.reference{overflow-wrap:anywhere}.reference small{min-width:0;max-width:100%}
|
|
9
|
-
html[data-theme=dark]{--page:#
|
|
10
|
+
html[data-theme=dark]{--page:#0e0e10;--surface:#1a1c26;--surface2:#20222e;--surface3:#2a2c3c;--line:#343644;--text:#eef0f6;--muted:#b3bad0;--faint:#8b91a6;--nav:#131319;--accent:#7da2ff;--accent-soft:#242e48;--good:#8cc8a8;--bad:#e89898;--bad-soft:#3a272b;color-scheme:dark}
|
|
11
|
+
html[data-skin=oled][data-theme=dark]{--page:#000000;--surface:#101118;--surface2:#16171e;--surface3:#1e1f26;--line:#2e2f3a;--text:#f2f2f5;--muted:#b3bad0;--faint:#8b91a6;--nav:#050506;--accent:#7da2ff;--accent-soft:#1e263c;--good:#8cc8a8;--bad:#e89898;--bad-soft:#352428;color-scheme:dark}
|
|
12
|
+
html[data-skin=steel]{--page:#f3f5f7;--surface:#fff;--surface2:#f8f9fb;--surface3:#edf1f4;--line:#dce2e8;--text:#202733;--muted:#687587;--faint:#8e99a7;--nav:#eef1f4;--accent:#516f89;--accent-soft:#e6edf3;--good:#397761;--bad:#a05252;--bad-soft:#fbeeee;color-scheme:light}
|
|
13
|
+
html[data-skin=steel][data-theme=dark]{--page:#171a1f;--surface:#20252d;--surface2:#252b34;--surface3:#2c333e;--line:#39424f;--text:#e6ebf0;--muted:#a0aaba;--faint:#788393;--nav:#1b2028;--accent:#8aa8cf;--accent-soft:#293748;--good:#81b29a;--bad:#d88b8b;--bad-soft:#39292d;color-scheme:dark}
|
|
10
14
|
*{box-sizing:border-box}[hidden]{display:none!important}html,body{height:100%}body{margin:0;overflow:hidden;background:var(--page);color:var(--text);font:13px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif}button,input,select,textarea{font:inherit;color:inherit}button{cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:34px;padding:6px 12px;border:1px solid var(--line);border-radius:8px;background:var(--surface)}button:hover{background:var(--surface3)}button:disabled{opacity:.5;cursor:not-allowed}button.primary{background:var(--accent);color:#fff;border-color:var(--accent)}button.danger{background:var(--bad);color:#fff;border-color:var(--bad)}button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:3px}svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;flex:none}h1,h2,h3,p{margin:0}h1{font-size:18px;font-weight:650}h2{font-size:16px;font-weight:600}h3{font-size:13px;font-weight:600}small,.muted{color:var(--muted)}small{font-size:11px}p{color:var(--muted);margin-top:8px}input,select,textarea{background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:8px 12px;min-width:0}label{display:block;font-size:12px;margin:16px 0;color:var(--muted)}label>input,label>select,label>textarea{display:block;width:100%;margin-top:8px;color:var(--text)}pre{font:12px/1.8 Consolas,"Microsoft YaHei",monospace;white-space:pre-wrap;overflow-wrap:anywhere;color:var(--text)}
|
|
11
15
|
.app{height:100%;display:grid;grid-template-columns:232px minmax(0,1fr)}.sidebar{display:flex;flex-direction:column;border-right:1px solid var(--line);background:var(--nav);min-height:0}.brand{display:flex;align-items:center;gap:8px;padding:24px 20px 16px}.brand-mark{width:32px;height:32px;display:block;flex:none;object-fit:contain}.brand strong{font-size:14px}.brand small{display:block}.brain-label{padding:0 20px 16px;color:var(--muted);overflow-wrap:anywhere}.sidebar nav{display:grid;gap:8px;padding:8px 12px}.sidebar nav button{justify-content:flex-start;min-height:40px;text-align:left;border-color:transparent;background:transparent;color:var(--muted)}.sidebar nav button.active{border-color:var(--line);background:var(--surface);color:var(--text)}.count{margin-left:auto;background:var(--surface3);padding:0 6px;border-radius:4px}.system-button{margin: auto 12px 16px;justify-content:flex-start;min-height:56px;background:transparent;border-color:transparent;padding:8px}.system-button>span:nth-child(2){flex:1;text-align:left}.system-button b,.system-button small{display:block;font-size:11px}.dot{width:7px;height:7px;border-radius:50%;background:var(--faint);flex:none}.dot.up{background:var(--good)}.dot.issue{background:var(--bad)}main{min-width:0;min-height:0;display:flex;flex-direction:column}.topbar{height:72px;flex:none;display:flex;align-items:center;gap:16px;padding:0 24px;background:var(--surface);border-bottom:1px solid var(--line)}.spacer{flex:1}.topbar select{width:240px}.icon-button{padding:8px;min-width:34px}.content{position:relative;flex:1;min-height:0}.view{display:none;height:100%;overflow:auto;padding:32px}.view.active{display:block}.view.module-view{padding:0;overflow:hidden}.module-view.active{display:flex;flex-direction:column}.frame-container{position:relative;flex:1;min-width:0;min-height:0;overflow:hidden;background:var(--surface)}iframe{display:block;width:100%;height:100%;border:0;background:var(--surface)}.work-layout{display:grid;grid-template-columns:minmax(0,1fr);height:100%;min-height:0}.module-toolbar{flex:none;min-height:56px;display:flex;justify-content:space-between;align-items:center;gap:16px;padding:8px 24px;border-bottom:1px solid var(--line);background:var(--surface)}.segmented{display:flex;gap:4px}.segmented button{background:transparent;border-color:transparent;color:var(--muted)}.segmented button.active{background:var(--surface);border-color:var(--line);color:var(--text)}
|
|
12
16
|
.welcome{display:flex;align-items:center;justify-content:space-between;gap:24px;margin-bottom:32px}.welcome h2{font-size:24px;margin-top:8px}.actions{display:flex;gap:8px;align-items:center}.grid2{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(320px,1fr);gap:24px}.stack{display:grid;gap:24px}.panel{border:1px solid var(--line);background:var(--surface);border-radius:8px;padding:24px;min-width:0}.panel h2{margin-bottom:16px}.section-heading{display:flex;align-items:center;justify-content:space-between;gap:24px;margin-bottom:24px}.section-heading p{font-size:12px}.row{display:flex;align-items:center;gap:16px;padding:16px 0;border-bottom:1px solid var(--line)}.row:last-child{border-bottom:0}.row>div{flex:1;min-width:0}.row b{font-weight:600}.row small{display:block;margin-top:4px;overflow-wrap:anywhere}.row time{color:var(--muted);font-size:11px;flex:none}.status{font-size:11px;border:1px solid var(--line);border-radius:4px;padding:2px 8px;white-space:nowrap;color:var(--muted)}.status.up{color:var(--good)}.status.issue{color:var(--bad);background:var(--bad-soft)}.empty{padding:64px 24px;text-align:center;color:var(--muted);background:var(--surface);border-radius:8px;line-height:1.9}.empty button{display:block;margin:16px auto 0}.small-empty{padding:16px 0;text-align:left;background:transparent;font-size:12px}.hierarchy{display:grid;grid-template-columns:296px minmax(0,1fr);gap:24px}.tree h3{margin:24px 0 8px;color:var(--muted);font-size:11px}.tree button{width:100%;justify-content:flex-start;text-align:left;background:transparent;border-color:transparent;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tree button.active{background:var(--accent-soft);color:var(--accent)}.detail-path{padding:12px 16px;background:var(--surface2);border:1px solid var(--line);border-radius:8px;margin:8px 0 24px;font:12px/1.8 Consolas,"Microsoft YaHei",monospace;overflow-wrap:anywhere}.detail-label{color:var(--muted);font-size:11px}.memory-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:24px;margin-top:24px}.memory-card{padding:24px;border:1px solid var(--line);border-radius:8px;background:var(--surface)}.memory-card p{color:var(--text);margin:0 0 16px;white-space:pre-wrap}.memory-card .actions{margin-top:16px}.reference{display:block;text-align:left;width:100%;background:transparent;border:0;border-bottom:1px solid var(--line);border-radius:0;padding:16px 0}.reference b,.reference small{display:block;text-align:left}.reference p{font-size:12px;text-align:left}.activity-updates{flex:1;overflow:auto;padding:24px 32px}.run{margin-bottom:16px;background:var(--surface);border:1px solid var(--line);border-radius:8px}.run summary{padding:16px 24px;cursor:pointer;display:flex;align-items:center;gap:16px}.run summary strong{flex:1}.run>div{padding:0 24px 24px}.run .error{color:var(--bad)}.operation{padding:8px 0;color:var(--muted)}
|
package/ui/product.js
CHANGED
|
@@ -711,7 +711,91 @@
|
|
|
711
711
|
}
|
|
712
712
|
});
|
|
713
713
|
on('projectSelect', 'change', e => selectProject(e.target.value));
|
|
714
|
-
on('themeToggle', 'click', () => { document.documentElement.dataset.theme = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'; localStorage.setItem('kb.theme', document.documentElement.dataset.theme); Object.keys(frames).forEach(key => post(key, { type: 'kb:theme', theme: document.documentElement.dataset.theme })); void pushKnowledgeToPanel(); });
|
|
714
|
+
on('themeToggle', 'click', () => { document.documentElement.dataset.theme = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'; localStorage.setItem('kb.theme', document.documentElement.dataset.theme); applyAppearance(); Object.keys(frames).forEach(key => post(key, { type: 'kb:theme', theme: document.documentElement.dataset.theme })); void pushKnowledgeToPanel(); });
|
|
715
|
+
// Appearance skin: preset palettes plus per-theme token overrides (kb-skin/v1).
|
|
716
|
+
const appearanceTokens = ['page','surface','surface2','surface3','line','text','muted','faint','nav','accent','accent-soft','good','bad','bad-soft'];
|
|
717
|
+
const appearanceDefaults = {
|
|
718
|
+
pure: {
|
|
719
|
+
light: { page:'#ffffff',surface:'#ffffff',surface2:'#f6f6f7',surface3:'#ececee',line:'#e2e2e5',text:'#1a1a1e',muted:'#6d6d75',faint:'#8a8a92',nav:'#fafafa',accent:'#2f6db5','accent-soft':'#e2ecf8',good:'#2e7d5b',bad:'#b04a4a','bad-soft':'#f7ecec' },
|
|
720
|
+
dark: { page:'#0e0e10',surface:'#1a1c26',surface2:'#20222e',surface3:'#2a2c3c',line:'#343644',text:'#eef0f6',muted:'#b3bad0',faint:'#8b91a6',nav:'#131319',accent:'#7da2ff','accent-soft':'#242e48',good:'#8cc8a8',bad:'#e89898','bad-soft':'#3a272b' },
|
|
721
|
+
},
|
|
722
|
+
oled: {
|
|
723
|
+
light: { page:'#ffffff',surface:'#ffffff',surface2:'#f6f6f7',surface3:'#ececee',line:'#e2e2e5',text:'#1a1a1e',muted:'#6d6d75',faint:'#8a8a92',nav:'#fafafa',accent:'#2f6db5','accent-soft':'#e2ecf8',good:'#2e7d5b',bad:'#b04a4a','bad-soft':'#f7ecec' },
|
|
724
|
+
dark: { page:'#000000',surface:'#101118',surface2:'#16171e',surface3:'#1e1f26',line:'#2e2f3a',text:'#f2f2f5',muted:'#b3bad0',faint:'#8b91a6',nav:'#050506',accent:'#7da2ff','accent-soft':'#1e263c',good:'#8cc8a8',bad:'#e89898','bad-soft':'#352428' },
|
|
725
|
+
},
|
|
726
|
+
steel: {
|
|
727
|
+
light: { page:'#f3f5f7',surface:'#ffffff',surface2:'#f8f9fb',surface3:'#edf1f4',line:'#dce2e8',text:'#202733',muted:'#687587',faint:'#8e99a7',nav:'#eef1f4',accent:'#516f89','accent-soft':'#e6edf3',good:'#397761',bad:'#a05252','bad-soft':'#fbeeee' },
|
|
728
|
+
dark: { page:'#171a1f',surface:'#20252d',surface2:'#252b34',surface3:'#2c333e',line:'#39424f',text:'#e6ebf0',muted:'#a0aaba',faint:'#788393',nav:'#1b2028',accent:'#8aa8cf','accent-soft':'#293748',good:'#81b29a',bad:'#d88b8b','bad-soft':'#39292d' },
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
const appearance = { preset: 'pure', overrides: { light: {}, dark: {} }, skinTheme: 'light' };
|
|
732
|
+
const sanitizeSkinTokens = source => {
|
|
733
|
+
const themes = {};
|
|
734
|
+
for (const theme of ['light', 'dark']) {
|
|
735
|
+
themes[theme] = {};
|
|
736
|
+
const entries = source?.[theme] && typeof source[theme] === 'object' ? source[theme] : {};
|
|
737
|
+
for (const token of appearanceTokens) if (/^#[0-9a-fA-F]{6}$/.test(String(entries[token] || ''))) themes[theme][token] = String(entries[token]).toLowerCase();
|
|
738
|
+
}
|
|
739
|
+
return themes;
|
|
740
|
+
};
|
|
741
|
+
function applyAppearance() {
|
|
742
|
+
const root = document.documentElement;
|
|
743
|
+
root.dataset.skin = appearanceDefaults[appearance.preset] ? appearance.preset : 'pure';
|
|
744
|
+
if (!root.style) return;
|
|
745
|
+
const theme = root.dataset.theme === 'dark' ? 'dark' : 'light';
|
|
746
|
+
for (const token of appearanceTokens) root.style.removeProperty(`--${token}`);
|
|
747
|
+
for (const [token, value] of Object.entries(appearance.overrides[theme] || {})) if (appearanceTokens.includes(token)) root.style.setProperty(`--${token}`, value);
|
|
748
|
+
}
|
|
749
|
+
function syncAppearanceControls() {
|
|
750
|
+
if (!$('skinPreset')) return;
|
|
751
|
+
$('skinPreset').value = appearance.preset;
|
|
752
|
+
all('#skinThemeTabs button').forEach(button => button.classList.toggle('active', button.dataset.skinTheme === appearance.skinTheme));
|
|
753
|
+
all('#skinColors input[data-token], .skin-more input[data-token]').forEach(input => {
|
|
754
|
+
const token = input.dataset.token;
|
|
755
|
+
const fallback = appearanceDefaults[appearance.preset]?.[appearance.skinTheme]?.[token] || '#000000';
|
|
756
|
+
input.value = (appearance.overrides[appearance.skinTheme]?.[token] || fallback).toLowerCase();
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
async function saveAppearance() {
|
|
760
|
+
const result = await api('/api/appearance', { method: 'PATCH', body: { appearance: { preset: appearance.preset, overrides: appearance.overrides } } });
|
|
761
|
+
appearance.preset = result.appearance.preset; appearance.overrides = sanitizeSkinTokens(result.appearance.overrides);
|
|
762
|
+
applyAppearance(); syncAppearanceControls();
|
|
763
|
+
$('appearanceStatus').textContent = '皮肤已保存,对本机所有入口生效。';
|
|
764
|
+
}
|
|
765
|
+
async function loadAppearance() {
|
|
766
|
+
try {
|
|
767
|
+
const result = await api('/api/appearance', { allowNotReady: true });
|
|
768
|
+
if (result.appearance) { appearance.preset = result.appearance.preset || 'pure'; appearance.overrides = sanitizeSkinTokens(result.appearance.overrides); }
|
|
769
|
+
} catch { /* 服务未就绪时保持默认皮肤,不阻塞启动 */ }
|
|
770
|
+
applyAppearance(); syncAppearanceControls();
|
|
771
|
+
}
|
|
772
|
+
on('skinPreset', 'change', () => { appearance.preset = $('skinPreset').value; applyAppearance(); syncAppearanceControls(); $('appearanceStatus').textContent = '预设已切换(即时预览),记得保存。'; });
|
|
773
|
+
all('#skinThemeTabs button').forEach(button => button.addEventListener('click', () => { appearance.skinTheme = button.dataset.skinTheme; syncAppearanceControls(); }));
|
|
774
|
+
all('#skinColors input[data-token], .skin-more input[data-token]').forEach(input => input.addEventListener('input', () => {
|
|
775
|
+
appearance.overrides[appearance.skinTheme] = { ...appearance.overrides[appearance.skinTheme], [input.dataset.token]: input.value.toLowerCase() };
|
|
776
|
+
applyAppearance(); $('appearanceStatus').textContent = '颜色已应用(即时预览),记得保存。';
|
|
777
|
+
}));
|
|
778
|
+
on('saveAppearance', 'click', saveAppearance);
|
|
779
|
+
on('resetAppearance', 'click', async () => { appearance.preset = 'pure'; appearance.overrides = { light: {}, dark: {} }; await saveAppearance(); toast('已恢复默认皮肤。'); });
|
|
780
|
+
on('exportSkin', 'click', () => {
|
|
781
|
+
const tokens = {};
|
|
782
|
+
for (const theme of ['light', 'dark']) tokens[theme] = { ...appearanceDefaults[appearance.preset][theme], ...appearance.overrides[theme] };
|
|
783
|
+
const skin = { schema: 'kb-skin/v1', name: '我的皮肤', preset: appearance.preset, tokens };
|
|
784
|
+
const url = URL.createObjectURL(new Blob([JSON.stringify(skin, null, 2)], { type: 'application/json' }));
|
|
785
|
+
const link = document.createElement('a'); link.href = url; link.download = 'kb-skin.json'; link.click(); URL.revokeObjectURL(url);
|
|
786
|
+
});
|
|
787
|
+
on('importSkin', 'click', () => $('importSkinFile').click());
|
|
788
|
+
$('importSkinFile').addEventListener('change', async event => {
|
|
789
|
+
const file = event.target.files?.[0]; event.target.value = '';
|
|
790
|
+
if (!file) return;
|
|
791
|
+
try {
|
|
792
|
+
const skin = JSON.parse(await file.text());
|
|
793
|
+
if (skin.schema !== 'kb-skin/v1') throw new Error('不是有效的 kb-skin/v1 皮肤文件。');
|
|
794
|
+
if (appearanceDefaults[skin.preset]) appearance.preset = skin.preset;
|
|
795
|
+
appearance.overrides = sanitizeSkinTokens(skin.tokens);
|
|
796
|
+
await saveAppearance(); toast(`已导入皮肤「${String(skin.name || '未命名').slice(0, 40)}」。`);
|
|
797
|
+
} catch (error) { toast(`导入失败:${error.message}`); }
|
|
798
|
+
});
|
|
715
799
|
on('openSystem', 'click', openSystem); on('closeSystem', 'click', closeSystem); on('drawerBackdrop', 'click', closeSystem);
|
|
716
800
|
on('repairWiring', 'click', repair);
|
|
717
801
|
on('configureProviders', 'click', () => { closeSystem(); setView('work'); initializeFrame('terminal'); if (frames.terminal.ready) post('terminal', { type: 'kb:open-settings' }); else frames.terminal.openSettings = true; });
|
|
@@ -833,6 +917,7 @@
|
|
|
833
917
|
document.addEventListener('visibilitychange', () => { if (!document.hidden) { connectRegistryEvents(); void refreshRegistry(); } });
|
|
834
918
|
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeSystem(); });
|
|
835
919
|
document.documentElement.dataset.theme = localStorage.getItem('kb.theme') === 'dark' ? 'dark' : 'light';
|
|
920
|
+
applyAppearance(); void loadAppearance();
|
|
836
921
|
all('[data-scope]').forEach(button => button.classList.toggle('active', button.dataset.scope === state.scope));
|
|
837
922
|
state.view = titles[location.hash.slice(1)] ? location.hash.slice(1) : 'home';
|
|
838
923
|
setView(state.view); refreshRegistry();
|