@sanqianx/project-knowledge 5.0.18 → 5.0.20-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +3 -3
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +14 -0
- package/LICENSE +201 -201
- package/NOTICE +5 -5
- package/README.md +349 -349
- package/_modules/knowledge-engine/README.md +4 -0
- package/_modules/knowledge-engine/src/analysis-contract.js +4 -3
- package/_modules/knowledge-engine/src/analysis-failures.js +39 -0
- package/_modules/knowledge-engine/src/analysis-worker.js +6 -2
- package/_modules/knowledge-engine/src/coordinator.js +8 -0
- package/_modules/knowledge-engine/src/headless-analyzer.js +2 -1
- package/_modules/knowledge-engine/src/memories.js +10 -5
- package/_modules/knowledge-engine/src/memory-eligibility.js +74 -0
- package/_modules/knowledge-engine/src/retrieval-ranking.js +19 -1
- package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +1 -0
- package/_modules/knowledge-engine/src/runtime/commit-prompt.js +12 -9
- package/_modules/knowledge-engine/src/runtime/conversation-store.js +2 -0
- package/_modules/knowledge-engine/src/server.js +1 -1
- package/_site/_test/agent-capture-mcp-ui-test.js +67 -67
- package/_site/_test/ai-profile-test.js +75 -75
- package/_site/_test/ai-vendor-presets-test.js +91 -91
- package/_site/_test/automatic-context-test.js +70 -70
- package/_site/_test/bin-cli-test.js +230 -230
- package/_site/_test/bridge-adapter-test.js +95 -95
- package/_site/_test/bridge-consumer-service-test.js +310 -310
- package/_site/_test/candidate-bin-content-test.js +35 -0
- package/_site/_test/candidate-product-assets-test.js +13 -0
- package/_site/_test/candidate-release-contract-test.js +14 -14
- package/_site/_test/capture-hook-dedup-test.js +158 -158
- package/_site/_test/claude-executable-discovery-test.js +28 -28
- package/_site/_test/claude-session-lifecycle-sweep-test.js +252 -252
- package/_site/_test/cli-instance-management-test.js +62 -62
- package/_site/_test/client-capture-restart-e2e-test.js +189 -189
- package/_site/_test/codex-conversation-projection-test.js +60 -60
- package/_site/_test/codex-marketplace-scoped-path-test.js +186 -186
- package/_site/_test/codex-notify-capture-e2e-test.js +101 -101
- package/_site/_test/codex-notify-fanout-test.js +134 -134
- package/_site/_test/codex-notify-upgrade-test.js +253 -253
- package/_site/_test/commit-boundary-freeze-test.js +147 -147
- package/_site/_test/commit-conversation-binding-test.js +4 -4
- package/_site/_test/configuration-generation-test.js +22 -22
- package/_site/_test/context-pack-test.js +200 -200
- package/_site/_test/conversation-api-test.js +10 -10
- package/_site/_test/conversation-origin-test.js +15 -0
- package/_site/_test/cross-repo-isolation-e2e-test.js +187 -187
- package/_site/_test/embedding-config-test.js +32 -32
- package/_site/_test/fixtures/fake-browser-exit.js +10 -10
- package/_site/_test/fixtures/fake-browser-hang.js +10 -10
- package/_site/_test/fixtures/integration-busy-worker.cjs +6 -6
- package/_site/_test/fixtures/make-git-repos.js +92 -92
- package/_site/_test/fixtures/retrieval-gold-queries.json +32 -0
- package/_site/_test/fresh-hook-reimport-test.js +53 -53
- package/_site/_test/fresh-product-data-test.js +56 -56
- package/_site/_test/git-path-compatibility-test.js +80 -80
- package/_site/_test/git-validation-test.js +81 -81
- package/_site/_test/hook-worktree-test.js +42 -42
- package/_site/_test/index-builder-test.js +41 -41
- package/_site/_test/index-error-display-contract-test.js +10 -10
- package/_site/_test/integration-adapters-test.js +67 -67
- package/_site/_test/integration-capture-setup-test.js +118 -118
- package/_site/_test/integration-runtime-binding-a2-test.js +566 -566
- package/_site/_test/integration-runtime-binding-a3-test.js +227 -227
- package/_site/_test/integration-runtime-binding-test.js +473 -473
- package/_site/_test/integration-status-scan-test.js +29 -29
- package/_site/_test/kb-framework-test.js +57 -57
- package/_site/_test/kbpath-follow-test.js +63 -63
- package/_site/_test/knowledge-db-test.js +144 -144
- package/_site/_test/knowledge-engine-client-test.js +109 -109
- package/_site/_test/knowledge-maintenance-test.js +40 -40
- package/_site/_test/knowledge-panel-ui-contract-test.js +112 -0
- package/_site/_test/knowledge-scopes-test.js +37 -37
- package/_site/_test/knowledge-storage-location-test.js +28 -28
- package/_site/_test/launcher-readiness-test.js +80 -80
- package/_site/_test/legacy-claude-session-alias-test.js +106 -106
- package/_site/_test/legacy-routes-removed-test.js +47 -47
- package/_site/_test/legacy-workbench-exclusion-test.js +92 -92
- package/_site/_test/live-gateway-test.js +48 -48
- package/_site/_test/local-marketplace-test.js +16 -16
- package/_site/_test/log-redaction-test.js +58 -58
- package/_site/_test/markdown-maintenance-test.js +11 -11
- package/_site/_test/model-context-windows-test.js +89 -89
- package/_site/_test/module-agent-start-proxy-test.js +65 -65
- package/_site/_test/module-artifact-integrity-test.js +27 -27
- package/_site/_test/module-boundary-test.js +30 -30
- package/_site/_test/module-bridge-eventbridge-test.js +202 -202
- package/_site/_test/module-dynamic-port-test.js +118 -118
- package/_site/_test/module-index-proxy-test.js +33 -0
- package/_site/_test/module-model-configuration-test.js +44 -44
- package/_site/_test/module-process-lifecycle-test.js +35 -35
- package/_site/_test/module-stream-proxy-test.js +34 -34
- package/_site/_test/module-terminal-restart-test.js +63 -0
- package/_site/_test/module-wiring-unbind-race-test.js +59 -59
- package/_site/_test/native-context-integrations-test.js +86 -86
- package/_site/_test/orphaned-claim-recovery-test.js +80 -80
- package/_site/_test/package-boundary-test.js +43 -42
- package/_site/_test/package-startup-test.js +56 -56
- package/_site/_test/packaged-ui-smoke-test.js +88 -88
- package/_site/_test/pr-consumer-contract-test.js +55 -55
- package/_site/_test/product-brand-contract-test.js +25 -25
- package/_site/_test/product-diagnostics-ui-test.js +93 -93
- package/_site/_test/product-import-ui-test.js +104 -104
- package/_site/_test/product-progress-status-test.js +12 -1
- package/_site/_test/project-remove-running-guard-test.js +79 -79
- package/_site/_test/project-store-test.js +90 -90
- package/_site/_test/registry-events-test.js +38 -0
- package/_site/_test/release-version-sync-test.js +115 -115
- package/_site/_test/requirement-binding-test.js +113 -113
- package/_site/_test/runtime-endpoint-test.js +64 -64
- package/_site/_test/scanner-test.js +83 -83
- package/_site/_test/server-security-test.js +96 -96
- package/_site/_test/sessions-stream-test.js +93 -93
- package/_site/_test/shared-scope-root-binding-test.js +67 -67
- package/_site/_test/simple-import-test.js +98 -98
- package/_site/_test/startup-analysis-disabled-test.js +6 -6
- package/_site/_test/team-knowledge-store-sparse-checkout-test.js +196 -196
- package/_site/_test/team-knowledge-store-test.js +132 -132
- package/_site/_test/test-server-cleanup-test.js +35 -35
- package/_site/_test/test-server-module-isolation-test.js +37 -37
- package/_site/_test/tracking-start-test.js +35 -35
- package/_site/_test/workbench-context-receipts-test.js +22 -0
- package/_site/_test/workspace-ui-contract-test.js +31 -31
- package/_site/_test/zcode-capture-integration-test.js +108 -108
- package/_site/lib/ai-vendor-presets.js +83 -83
- package/_site/lib/ai-workspace.js +3 -3
- package/_site/lib/atomic-file.js +204 -204
- package/_site/lib/bridge-adapter.js +260 -260
- package/_site/lib/capture-hook-config.js +108 -108
- package/_site/lib/claude-cli-runner.js +89 -89
- package/_site/lib/cli-instances.js +43 -43
- package/_site/lib/codex-context-status.js +17 -17
- package/_site/lib/codex-notify-config.js +193 -193
- package/_site/lib/commit-conversation-binder.js +13 -12
- package/_site/lib/commit-reconciler.js +38 -38
- package/_site/lib/context-pack-builder.js +299 -299
- package/_site/lib/conversation-exclusions.js +204 -204
- package/_site/lib/conversation-query-service.js +17 -17
- package/_site/lib/conversation-store.js +2 -0
- package/_site/lib/data-dir.js +13 -13
- package/_site/lib/embedding-service.js +85 -85
- package/_site/lib/engine-connection.js +93 -90
- package/_site/lib/engine-knowledge-client.js +72 -72
- package/_site/lib/folder-picker-output.js +3 -3
- package/_site/lib/git-path.js +14 -14
- package/_site/lib/github-team-store.js +3 -3
- package/_site/lib/index-builder.js +157 -157
- package/_site/lib/integration-status-scan.js +99 -99
- package/_site/lib/integration-status-worker.js +14 -14
- package/_site/lib/kb-framework.js +15 -15
- package/_site/lib/knowledge-db.js +363 -363
- package/_site/lib/knowledge-schema.js +121 -121
- package/_site/lib/live-gateway.js +78 -76
- package/_site/lib/llm-client.js +12 -12
- package/_site/lib/model-context-windows.js +82 -82
- package/_site/lib/module-bridge.js +874 -865
- package/_site/lib/module-port-resolver.js +57 -57
- package/_site/lib/post-commit-automation.js +54 -54
- package/_site/lib/product-data.js +35 -35
- package/_site/lib/project-lifecycle-service.js +14 -14
- package/_site/lib/project-registry-store.js +129 -129
- package/_site/lib/prompt-registry.js +148 -148
- package/_site/lib/registry-events.js +16 -0
- package/_site/lib/requirement-adapters.js +10 -10
- package/_site/lib/requirement-binder.js +112 -112
- package/_site/lib/runtime-control.js +89 -89
- package/_site/lib/runtime-endpoint.js +5 -5
- package/_site/lib/server-app.js +10 -1
- package/_site/lib/zcode-context-integration.js +60 -60
- package/_site/scripts/codex-notify-fanout.cjs +95 -95
- package/_site/scripts/install-module-candidates.js +69 -69
- package/_site/scripts/pack-module-candidates.js +89 -72
- package/_site/scripts/sync-product-content.js +28 -28
- package/_site/scripts/sync-release-version.js +164 -164
- package/_site/scripts/vendor-modules.js +49 -49
- package/_site/scripts/verify-module-runtime.js +50 -50
- package/_site/scripts/verify-product-runtime.js +36 -36
- package/_site/scripts/verify-retrieval-gold.js +83 -0
- package/_site/server.js +15 -15
- package/_site/start.bat +26 -26
- package/_site/stop.bat +11 -11
- package/bin/project-knowledge-integrations.js +254 -254
- package/bin/project-knowledge-kb.js +67 -67
- package/bin/project-knowledge-mcp.js +8 -8
- package/bin/project-knowledge.js +170 -170
- package/claude-prompts.json +21 -21
- package/docs/README.zh-CN.md +205 -205
- package/docs/assets/architecture.svg +181 -181
- package/docs/assets/logo.svg +49 -49
- package/docs/fresh-v5-start.md +42 -42
- package/docs/leader-glm-workbench-playbook.md +122 -119
- package/docs/project-registry-schema.md +11 -11
- package/docs/release-5.0.16-acceptance.md +176 -176
- package/docs/release-5.0.17-acceptance.md +117 -117
- package/docs/release-5.0.19-acceptance.md +39 -0
- package/docs/team-knowledge-mode-a-plan.md +73 -73
- package/module-runtime-manifest.json +126 -104
- package/package.json +110 -108
- 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/plugins/project-knowledge/opencode/project-knowledge.md +3 -3
- package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +28 -28
- package/templates/change.md +30 -30
- package/templates/project-readme.md +18 -18
- package/ui/index.html +1 -1
- package/ui/knowledge-panel.html +118 -0
- package/ui/product.css +8 -0
- package/ui/product.js +175 -8
- package/vendor-manifest.json +55 -53
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const MAX_INDEX_ITEMS = 40;
|
|
5
|
-
const MAX_MODULE_ITEMS = 80;
|
|
6
|
-
const MAX_TAGS = 4;
|
|
7
|
-
const MAX_SOURCE_PATHS = 3;
|
|
8
|
-
const MAX_LOOKUPS = 4;
|
|
9
|
-
const MAX_CELL_CHARS = 120;
|
|
10
|
-
const GENERATED_NOTICE = '<!-- Generated by project-knowledge. Do not edit manually. -->';
|
|
11
|
-
|
|
12
|
-
function parseFrontmatter(text) {
|
|
13
|
-
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(String(text || ''));
|
|
14
|
-
if (!match) return {};
|
|
15
|
-
const meta = {};
|
|
16
|
-
for (const line of match[1].split(/\r?\n/)) {
|
|
17
|
-
const m = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line.trim());
|
|
18
|
-
if (!m) continue;
|
|
19
|
-
let value = m[2].trim();
|
|
20
|
-
if (/^\[.*\]$/.test(value)) {
|
|
21
|
-
value = value.slice(1, -1).split(',').map(s => s.trim()).filter(Boolean);
|
|
22
|
-
}
|
|
23
|
-
meta[m[1]] = value;
|
|
24
|
-
}
|
|
25
|
-
return meta;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function listMarkdown(dir) {
|
|
29
|
-
if (!fs.existsSync(dir)) return [];
|
|
30
|
-
return fs.readdirSync(dir, { withFileTypes: true })
|
|
31
|
-
.filter(entry => entry.isFile() && entry.name.endsWith('.md') && entry.name !== '00-index.md')
|
|
32
|
-
.map(entry => {
|
|
33
|
-
const rel = entry.name;
|
|
34
|
-
const full = path.join(dir, entry.name);
|
|
35
|
-
const text = fs.readFileSync(full, 'utf-8');
|
|
36
|
-
const meta = parseFrontmatter(text);
|
|
37
|
-
const title = meta.title || text.match(/^#\s+(.+)$/m)?.[1] || entry.name.replace(/\.md$/, '');
|
|
38
|
-
return { rel, full, meta, title, updatedAt: meta.updatedAt || meta.period || '' };
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function metaList(value) {
|
|
43
|
-
if (Array.isArray(value)) return value.filter(Boolean);
|
|
44
|
-
if (!value) return [];
|
|
45
|
-
return String(value).split(',').map(s => s.trim()).filter(Boolean);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function compactList(value, limit) {
|
|
49
|
-
const items = metaList(value);
|
|
50
|
-
if (items.length <= limit) return items.join(', ');
|
|
51
|
-
return `${items.slice(0, limit).join(', ')} (+${items.length - limit})`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function cell(value, maxChars = MAX_CELL_CHARS) {
|
|
55
|
-
const text = Array.isArray(value) ? value.join(', ') : String(value || '');
|
|
56
|
-
const clean = text.replace(/\r?\n/g, ' ').replace(/\|/g, '\\|').trim();
|
|
57
|
-
if (!clean) return '-';
|
|
58
|
-
return clean.length > maxChars ? `${clean.slice(0, Math.max(1, maxChars - 1)).trimEnd()}…` : clean;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function indexSummary(total, shown) {
|
|
62
|
-
return shown < total
|
|
63
|
-
? `Items: ${total} (showing ${shown}; use knowledge search or file search for older entries)`
|
|
64
|
-
: `Items: ${total}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function markdownLink(title, rel) {
|
|
68
|
-
const label = cell(title, 80).replace(/\[/g, '\\[').replace(/\]/g, '\\]');
|
|
69
|
-
const target = encodeURI(String(rel || '')).replace(/\(/g, '%28').replace(/\)/g, '%29');
|
|
70
|
-
return `[${label}](./${target})`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function renderModuleIndex(kbPath) {
|
|
74
|
-
const dir = path.join(kbPath, 'modules');
|
|
75
|
-
const items = listMarkdown(dir).sort((a, b) => a.title.localeCompare(b.title));
|
|
76
|
-
const visible = items.slice(0, MAX_MODULE_ITEMS);
|
|
77
|
-
const lines = [
|
|
78
|
-
GENERATED_NOTICE,
|
|
79
|
-
'',
|
|
80
|
-
'# Modules Index',
|
|
81
|
-
'',
|
|
82
|
-
indexSummary(items.length, visible.length),
|
|
83
|
-
'',
|
|
84
|
-
'| Module | Tags | Source Paths | Routes / Symbols | Updated |',
|
|
85
|
-
'|---|---|---|---|---|',
|
|
86
|
-
];
|
|
87
|
-
for (const item of visible) {
|
|
88
|
-
const tagsText = compactList(item.meta.tags, MAX_TAGS);
|
|
89
|
-
const sourcePaths = compactList(item.meta.sourcePaths, MAX_SOURCE_PATHS);
|
|
90
|
-
const routes = metaList(item.meta.routes);
|
|
91
|
-
const symbols = metaList(item.meta.symbols);
|
|
92
|
-
const lookup = compactList([...routes, ...symbols], MAX_LOOKUPS);
|
|
93
|
-
lines.push(`| ${markdownLink(item.title, item.rel)} | ${cell(tagsText)} | ${cell(sourcePaths)} | ${cell(lookup)} | ${cell(item.updatedAt)} |`);
|
|
94
|
-
}
|
|
95
|
-
if (!items.length) lines.push('| No modules yet | - | - | - | - |');
|
|
96
|
-
return { path: 'modules/00-index.md', count: items.length, content: lines.join('\n') + '\n' };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function writeModuleIndex(kbPath) {
|
|
100
|
-
const rendered = renderModuleIndex(kbPath);
|
|
101
|
-
const dest = path.join(kbPath, rendered.path);
|
|
102
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
103
|
-
fs.writeFileSync(dest, rendered.content, 'utf-8');
|
|
104
|
-
return { path: rendered.path, count: rendered.count };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function renderChangesIndex(kbPath) {
|
|
108
|
-
const dir = path.join(kbPath, 'changes');
|
|
109
|
-
const items = listMarkdown(dir).sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt)) || a.title.localeCompare(b.title));
|
|
110
|
-
const visible = items.slice(0, MAX_INDEX_ITEMS);
|
|
111
|
-
const lines = [
|
|
112
|
-
GENERATED_NOTICE,
|
|
113
|
-
'',
|
|
114
|
-
'# Changes Index',
|
|
115
|
-
'',
|
|
116
|
-
indexSummary(items.length, visible.length),
|
|
117
|
-
'',
|
|
118
|
-
'| Change | Tags | Affected Modules | Period / Updated | Intent |',
|
|
119
|
-
'|---|---|---|---|---|',
|
|
120
|
-
];
|
|
121
|
-
for (const item of visible) {
|
|
122
|
-
const tagsText = compactList(item.meta.tags, MAX_TAGS);
|
|
123
|
-
const affected = compactList(item.meta.affectedModules, MAX_SOURCE_PATHS);
|
|
124
|
-
const intent = item.meta.developmentIntent || item.meta.intent || '';
|
|
125
|
-
lines.push(`| ${markdownLink(item.title, item.rel)} | ${cell(tagsText)} | ${cell(affected)} | ${cell(item.updatedAt)} | ${cell(intent)} |`);
|
|
126
|
-
}
|
|
127
|
-
if (!items.length) lines.push('| No changes yet | - | - | - | - |');
|
|
128
|
-
return { path: 'changes/00-index.md', count: items.length, content: lines.join('\n') + '\n' };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function writeChangesIndex(kbPath) {
|
|
132
|
-
const rendered = renderChangesIndex(kbPath);
|
|
133
|
-
const dest = path.join(kbPath, rendered.path);
|
|
134
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
135
|
-
fs.writeFileSync(dest, rendered.content, 'utf-8');
|
|
136
|
-
return { path: rendered.path, count: rendered.count };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function regenerateIndexes(kbPath) {
|
|
140
|
-
return {
|
|
141
|
-
modules: writeModuleIndex(kbPath),
|
|
142
|
-
changes: writeChangesIndex(kbPath),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
module.exports = {
|
|
147
|
-
parseFrontmatter,
|
|
148
|
-
compactList,
|
|
149
|
-
cell,
|
|
150
|
-
markdownLink,
|
|
151
|
-
GENERATED_NOTICE,
|
|
152
|
-
renderModuleIndex,
|
|
153
|
-
renderChangesIndex,
|
|
154
|
-
regenerateIndexes,
|
|
155
|
-
writeModuleIndex,
|
|
156
|
-
writeChangesIndex,
|
|
157
|
-
};
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const MAX_INDEX_ITEMS = 40;
|
|
5
|
+
const MAX_MODULE_ITEMS = 80;
|
|
6
|
+
const MAX_TAGS = 4;
|
|
7
|
+
const MAX_SOURCE_PATHS = 3;
|
|
8
|
+
const MAX_LOOKUPS = 4;
|
|
9
|
+
const MAX_CELL_CHARS = 120;
|
|
10
|
+
const GENERATED_NOTICE = '<!-- Generated by project-knowledge. Do not edit manually. -->';
|
|
11
|
+
|
|
12
|
+
function parseFrontmatter(text) {
|
|
13
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(String(text || ''));
|
|
14
|
+
if (!match) return {};
|
|
15
|
+
const meta = {};
|
|
16
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
17
|
+
const m = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line.trim());
|
|
18
|
+
if (!m) continue;
|
|
19
|
+
let value = m[2].trim();
|
|
20
|
+
if (/^\[.*\]$/.test(value)) {
|
|
21
|
+
value = value.slice(1, -1).split(',').map(s => s.trim()).filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
meta[m[1]] = value;
|
|
24
|
+
}
|
|
25
|
+
return meta;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function listMarkdown(dir) {
|
|
29
|
+
if (!fs.existsSync(dir)) return [];
|
|
30
|
+
return fs.readdirSync(dir, { withFileTypes: true })
|
|
31
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.md') && entry.name !== '00-index.md')
|
|
32
|
+
.map(entry => {
|
|
33
|
+
const rel = entry.name;
|
|
34
|
+
const full = path.join(dir, entry.name);
|
|
35
|
+
const text = fs.readFileSync(full, 'utf-8');
|
|
36
|
+
const meta = parseFrontmatter(text);
|
|
37
|
+
const title = meta.title || text.match(/^#\s+(.+)$/m)?.[1] || entry.name.replace(/\.md$/, '');
|
|
38
|
+
return { rel, full, meta, title, updatedAt: meta.updatedAt || meta.period || '' };
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function metaList(value) {
|
|
43
|
+
if (Array.isArray(value)) return value.filter(Boolean);
|
|
44
|
+
if (!value) return [];
|
|
45
|
+
return String(value).split(',').map(s => s.trim()).filter(Boolean);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function compactList(value, limit) {
|
|
49
|
+
const items = metaList(value);
|
|
50
|
+
if (items.length <= limit) return items.join(', ');
|
|
51
|
+
return `${items.slice(0, limit).join(', ')} (+${items.length - limit})`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function cell(value, maxChars = MAX_CELL_CHARS) {
|
|
55
|
+
const text = Array.isArray(value) ? value.join(', ') : String(value || '');
|
|
56
|
+
const clean = text.replace(/\r?\n/g, ' ').replace(/\|/g, '\\|').trim();
|
|
57
|
+
if (!clean) return '-';
|
|
58
|
+
return clean.length > maxChars ? `${clean.slice(0, Math.max(1, maxChars - 1)).trimEnd()}…` : clean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function indexSummary(total, shown) {
|
|
62
|
+
return shown < total
|
|
63
|
+
? `Items: ${total} (showing ${shown}; use knowledge search or file search for older entries)`
|
|
64
|
+
: `Items: ${total}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function markdownLink(title, rel) {
|
|
68
|
+
const label = cell(title, 80).replace(/\[/g, '\\[').replace(/\]/g, '\\]');
|
|
69
|
+
const target = encodeURI(String(rel || '')).replace(/\(/g, '%28').replace(/\)/g, '%29');
|
|
70
|
+
return `[${label}](./${target})`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function renderModuleIndex(kbPath) {
|
|
74
|
+
const dir = path.join(kbPath, 'modules');
|
|
75
|
+
const items = listMarkdown(dir).sort((a, b) => a.title.localeCompare(b.title));
|
|
76
|
+
const visible = items.slice(0, MAX_MODULE_ITEMS);
|
|
77
|
+
const lines = [
|
|
78
|
+
GENERATED_NOTICE,
|
|
79
|
+
'',
|
|
80
|
+
'# Modules Index',
|
|
81
|
+
'',
|
|
82
|
+
indexSummary(items.length, visible.length),
|
|
83
|
+
'',
|
|
84
|
+
'| Module | Tags | Source Paths | Routes / Symbols | Updated |',
|
|
85
|
+
'|---|---|---|---|---|',
|
|
86
|
+
];
|
|
87
|
+
for (const item of visible) {
|
|
88
|
+
const tagsText = compactList(item.meta.tags, MAX_TAGS);
|
|
89
|
+
const sourcePaths = compactList(item.meta.sourcePaths, MAX_SOURCE_PATHS);
|
|
90
|
+
const routes = metaList(item.meta.routes);
|
|
91
|
+
const symbols = metaList(item.meta.symbols);
|
|
92
|
+
const lookup = compactList([...routes, ...symbols], MAX_LOOKUPS);
|
|
93
|
+
lines.push(`| ${markdownLink(item.title, item.rel)} | ${cell(tagsText)} | ${cell(sourcePaths)} | ${cell(lookup)} | ${cell(item.updatedAt)} |`);
|
|
94
|
+
}
|
|
95
|
+
if (!items.length) lines.push('| No modules yet | - | - | - | - |');
|
|
96
|
+
return { path: 'modules/00-index.md', count: items.length, content: lines.join('\n') + '\n' };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function writeModuleIndex(kbPath) {
|
|
100
|
+
const rendered = renderModuleIndex(kbPath);
|
|
101
|
+
const dest = path.join(kbPath, rendered.path);
|
|
102
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
103
|
+
fs.writeFileSync(dest, rendered.content, 'utf-8');
|
|
104
|
+
return { path: rendered.path, count: rendered.count };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function renderChangesIndex(kbPath) {
|
|
108
|
+
const dir = path.join(kbPath, 'changes');
|
|
109
|
+
const items = listMarkdown(dir).sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt)) || a.title.localeCompare(b.title));
|
|
110
|
+
const visible = items.slice(0, MAX_INDEX_ITEMS);
|
|
111
|
+
const lines = [
|
|
112
|
+
GENERATED_NOTICE,
|
|
113
|
+
'',
|
|
114
|
+
'# Changes Index',
|
|
115
|
+
'',
|
|
116
|
+
indexSummary(items.length, visible.length),
|
|
117
|
+
'',
|
|
118
|
+
'| Change | Tags | Affected Modules | Period / Updated | Intent |',
|
|
119
|
+
'|---|---|---|---|---|',
|
|
120
|
+
];
|
|
121
|
+
for (const item of visible) {
|
|
122
|
+
const tagsText = compactList(item.meta.tags, MAX_TAGS);
|
|
123
|
+
const affected = compactList(item.meta.affectedModules, MAX_SOURCE_PATHS);
|
|
124
|
+
const intent = item.meta.developmentIntent || item.meta.intent || '';
|
|
125
|
+
lines.push(`| ${markdownLink(item.title, item.rel)} | ${cell(tagsText)} | ${cell(affected)} | ${cell(item.updatedAt)} | ${cell(intent)} |`);
|
|
126
|
+
}
|
|
127
|
+
if (!items.length) lines.push('| No changes yet | - | - | - | - |');
|
|
128
|
+
return { path: 'changes/00-index.md', count: items.length, content: lines.join('\n') + '\n' };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function writeChangesIndex(kbPath) {
|
|
132
|
+
const rendered = renderChangesIndex(kbPath);
|
|
133
|
+
const dest = path.join(kbPath, rendered.path);
|
|
134
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
135
|
+
fs.writeFileSync(dest, rendered.content, 'utf-8');
|
|
136
|
+
return { path: rendered.path, count: rendered.count };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function regenerateIndexes(kbPath) {
|
|
140
|
+
return {
|
|
141
|
+
modules: writeModuleIndex(kbPath),
|
|
142
|
+
changes: writeChangesIndex(kbPath),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = {
|
|
147
|
+
parseFrontmatter,
|
|
148
|
+
compactList,
|
|
149
|
+
cell,
|
|
150
|
+
markdownLink,
|
|
151
|
+
GENERATED_NOTICE,
|
|
152
|
+
renderModuleIndex,
|
|
153
|
+
renderChangesIndex,
|
|
154
|
+
regenerateIndexes,
|
|
155
|
+
writeModuleIndex,
|
|
156
|
+
writeChangesIndex,
|
|
157
|
+
};
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const path = require('node:path');
|
|
3
|
-
const { fork, spawn } = require('node:child_process');
|
|
4
|
-
const { IntegrationManager, SUPPORTED_CLIENTS, CLIENT_LABELS } = require('./integration-installer');
|
|
5
|
-
|
|
6
|
-
class IntegrationStatusScan {
|
|
7
|
-
constructor({ workerFile, timeoutMs = 20000 } = {}) {
|
|
8
|
-
this.workerFile = workerFile || path.join(__dirname, 'integration-status-worker.js');
|
|
9
|
-
this.timeoutMs = timeoutMs; this.entries = new Map(); this.children = new Set(); this.generation = 0;
|
|
10
|
-
this.queue = []; this.running = 0; this.closed = false;
|
|
11
|
-
}
|
|
12
|
-
async read(managerOptions, statusOptions = {}, { force = false, waitMs = 500 } = {}) {
|
|
13
|
-
if (managerOptions.runner || managerOptions.commandResolver || managerOptions.bridgeModule || managerOptions.codexHookProbe) return new IntegrationManager(managerOptions).statusAll(statusOptions);
|
|
14
|
-
const key = JSON.stringify([managerOptions.rootDir, managerOptions.homeDir, managerOptions.bridgeHomeDir, statusOptions.cwd, statusOptions.captureOnly, statusOptions.clients]);
|
|
15
|
-
let entry = this.entries.get(key);
|
|
16
|
-
if (!entry || !entry.promise && (force || Date.now() - entry.at > 30000)) {
|
|
17
|
-
entry = { at: Date.now(), generation: ++this.generation, summary: entry?.summary || null, promise: null };
|
|
18
|
-
entry.promise = this.run(managerOptions, statusOptions).then(summary => { entry.summary = summary; entry.at = Date.now(); return summary; }, error => {
|
|
19
|
-
if (entry.summary) {
|
|
20
|
-
entry.summary = { ...entry.summary, stale: true, error: { code: error.code || 'INTEGRATION_STATUS_FAILED' } };
|
|
21
|
-
return entry.summary;
|
|
22
|
-
}
|
|
23
|
-
entry.summary = { bridge: { ok: false, state: 'check-failed', detail: '接入状态检查失败或超时,未将其判为未安装。' },
|
|
24
|
-
clients: (statusOptions.clients || SUPPORTED_CLIENTS).map(client => ({ client, label: CLIENT_LABELS[client],
|
|
25
|
-
knowledgeIntegration: { ok: false, state: 'check-failed', detail: '检查未完成,请重试。' }, automaticContext: { supported: client !== 'opencode', configured: false, state: 'check-failed', detail: '检查未完成,不代表客户端未接入。' },
|
|
26
|
-
developmentCapture: { ok: false, state: 'check-failed', detail: '采集状态尚未核实。' } })), error: { code: error.code || 'INTEGRATION_STATUS_FAILED' } };
|
|
27
|
-
return entry.summary;
|
|
28
|
-
}).finally(() => { entry.promise = null; });
|
|
29
|
-
this.entries.set(key, entry);
|
|
30
|
-
if (this.entries.size > 100) for (const [oldKey, old] of this.entries) { if (!old.promise && oldKey !== key) { this.entries.delete(oldKey); break; } }
|
|
31
|
-
}
|
|
32
|
-
if (entry.promise && waitMs > 0) {
|
|
33
|
-
let timer;
|
|
34
|
-
await Promise.race([entry.promise, new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]); clearTimeout(timer);
|
|
35
|
-
}
|
|
36
|
-
const pending = entry.promise !== null;
|
|
37
|
-
if (entry.summary) return { ...entry.summary, scan: { state: pending ? 'refreshing' : 'ready', generation: entry.generation, updatedAt: entry.at } };
|
|
38
|
-
return { bridge: { ok: true, state: 'checking' }, clients: (statusOptions.clients || SUPPORTED_CLIENTS).map(client => ({ client, label: CLIENT_LABELS[client],
|
|
39
|
-
configFound: new IntegrationManager(managerOptions).captureConfigFound(client),
|
|
40
|
-
knowledgeIntegration: { ok: true, state: 'checking', detail: '正在检查接入状态…' },
|
|
41
|
-
automaticContext: { supported: client !== 'opencode', configured: false, state: 'checking', detail: '正在检查开发前知识读取…' },
|
|
42
|
-
developmentCapture: { ok: true, state: 'checking', detail: '正在检查采集…' } })), scan: { state: 'checking', generation: entry.generation } };
|
|
43
|
-
}
|
|
44
|
-
run(managerOptions, statusOptions) {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
if (this.closed || this.queue.length >= 64) { reject(Object.assign(new Error('状态检查暂不可用。'), { code: this.closed ? 'INTEGRATION_STATUS_CLOSED' : 'INTEGRATION_STATUS_BUSY' })); return; }
|
|
47
|
-
this.queue.push({ managerOptions, statusOptions, resolve, reject }); this.drain();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
drain() {
|
|
51
|
-
while (!this.closed && this.running < 2 && this.queue.length) {
|
|
52
|
-
const next = this.queue.shift(); this.running++;
|
|
53
|
-
this.probe(next.managerOptions, next.statusOptions).then(next.resolve, next.reject).finally(() => { this.running--; this.drain(); });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
probe(managerOptions, statusOptions) {
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
const child = fork(this.workerFile, [], { stdio: ['ignore', 'ignore', 'ignore', 'ipc'], windowsHide: true, env: { ...process.env, KB_INTEGRATION_STATUS_WORKER: '1' } });
|
|
59
|
-
this.children.add(child);
|
|
60
|
-
let settled = false;
|
|
61
|
-
const finish = (error, summary) => { if (settled) return; settled = true; clearTimeout(timer); error ? reject(error) : resolve(summary); };
|
|
62
|
-
const timer = setTimeout(() => {
|
|
63
|
-
Promise.resolve(managerOptions.logger?.warn?.('integration.status.timeout', '客户端接入状态检查超时;未将其判为未安装。', {
|
|
64
|
-
operationId: managerOptions.operationId, component: 'integration', phase: 'status',
|
|
65
|
-
context: { clients: statusOptions.clients || SUPPORTED_CLIENTS, timeoutMs: this.timeoutMs },
|
|
66
|
-
})).catch(() => {});
|
|
67
|
-
this.terminate(child); finish(Object.assign(new Error('状态检查超时。'), { code: 'INTEGRATION_STATUS_TIMEOUT' }));
|
|
68
|
-
}, this.timeoutMs);
|
|
69
|
-
child.on('message', message => {
|
|
70
|
-
if (message?.kind === 'log') {
|
|
71
|
-
if (['info', 'warn', 'error'].includes(message.level) && Array.isArray(message.args) && /^integration\./.test(message.args[0] || '')) Promise.resolve(managerOptions.logger?.[message.level]?.(...message.args)).catch(() => {});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
finish(message?.ok ? null : Object.assign(new Error('状态检查失败。'), { code: message?.code }), message?.summary);
|
|
75
|
-
});
|
|
76
|
-
child.once('error', error => finish(error));
|
|
77
|
-
child.once('exit', () => { this.children.delete(child); if (!settled) finish(Object.assign(new Error('状态检查进程提前退出。'), { code: 'INTEGRATION_STATUS_EXITED' })); });
|
|
78
|
-
const allowed = ['rootDir', 'homeDir', 'version', 'packageSpec', 'operationId', 'bridgeHomeDir', 'bridgeConsumerName', 'claudeSettingsFile', 'codexConfigFile', 'zcodeConfigFile', 'openCodePluginsDir'];
|
|
79
|
-
child.send({ managerOptions: Object.fromEntries(allowed.filter(k => managerOptions[k] !== undefined).map(k => [k, managerOptions[k]])), statusOptions });
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
terminate(child) {
|
|
83
|
-
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
84
|
-
if (process.platform === 'win32') {
|
|
85
|
-
// Only the live worker we created, including its probe children. Never
|
|
86
|
-
// terminate by executable name or scan unrelated Node processes.
|
|
87
|
-
const killer = spawn('taskkill.exe', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
88
|
-
killer.on('error', () => child.kill());
|
|
89
|
-
} else child.kill('SIGTERM');
|
|
90
|
-
}
|
|
91
|
-
invalidate() { for (const entry of this.entries.values()) entry.at = 0; }
|
|
92
|
-
close() {
|
|
93
|
-
this.closed = true;
|
|
94
|
-
for (const child of this.children) this.terminate(child);
|
|
95
|
-
for (const item of this.queue) item.reject(Object.assign(new Error('扫描已关闭。'), { code: 'INTEGRATION_STATUS_CLOSED' }));
|
|
96
|
-
this.queue = []; this.entries.clear();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
module.exports = { IntegrationStatusScan };
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { fork, spawn } = require('node:child_process');
|
|
4
|
+
const { IntegrationManager, SUPPORTED_CLIENTS, CLIENT_LABELS } = require('./integration-installer');
|
|
5
|
+
|
|
6
|
+
class IntegrationStatusScan {
|
|
7
|
+
constructor({ workerFile, timeoutMs = 20000 } = {}) {
|
|
8
|
+
this.workerFile = workerFile || path.join(__dirname, 'integration-status-worker.js');
|
|
9
|
+
this.timeoutMs = timeoutMs; this.entries = new Map(); this.children = new Set(); this.generation = 0;
|
|
10
|
+
this.queue = []; this.running = 0; this.closed = false;
|
|
11
|
+
}
|
|
12
|
+
async read(managerOptions, statusOptions = {}, { force = false, waitMs = 500 } = {}) {
|
|
13
|
+
if (managerOptions.runner || managerOptions.commandResolver || managerOptions.bridgeModule || managerOptions.codexHookProbe) return new IntegrationManager(managerOptions).statusAll(statusOptions);
|
|
14
|
+
const key = JSON.stringify([managerOptions.rootDir, managerOptions.homeDir, managerOptions.bridgeHomeDir, statusOptions.cwd, statusOptions.captureOnly, statusOptions.clients]);
|
|
15
|
+
let entry = this.entries.get(key);
|
|
16
|
+
if (!entry || !entry.promise && (force || Date.now() - entry.at > 30000)) {
|
|
17
|
+
entry = { at: Date.now(), generation: ++this.generation, summary: entry?.summary || null, promise: null };
|
|
18
|
+
entry.promise = this.run(managerOptions, statusOptions).then(summary => { entry.summary = summary; entry.at = Date.now(); return summary; }, error => {
|
|
19
|
+
if (entry.summary) {
|
|
20
|
+
entry.summary = { ...entry.summary, stale: true, error: { code: error.code || 'INTEGRATION_STATUS_FAILED' } };
|
|
21
|
+
return entry.summary;
|
|
22
|
+
}
|
|
23
|
+
entry.summary = { bridge: { ok: false, state: 'check-failed', detail: '接入状态检查失败或超时,未将其判为未安装。' },
|
|
24
|
+
clients: (statusOptions.clients || SUPPORTED_CLIENTS).map(client => ({ client, label: CLIENT_LABELS[client],
|
|
25
|
+
knowledgeIntegration: { ok: false, state: 'check-failed', detail: '检查未完成,请重试。' }, automaticContext: { supported: client !== 'opencode', configured: false, state: 'check-failed', detail: '检查未完成,不代表客户端未接入。' },
|
|
26
|
+
developmentCapture: { ok: false, state: 'check-failed', detail: '采集状态尚未核实。' } })), error: { code: error.code || 'INTEGRATION_STATUS_FAILED' } };
|
|
27
|
+
return entry.summary;
|
|
28
|
+
}).finally(() => { entry.promise = null; });
|
|
29
|
+
this.entries.set(key, entry);
|
|
30
|
+
if (this.entries.size > 100) for (const [oldKey, old] of this.entries) { if (!old.promise && oldKey !== key) { this.entries.delete(oldKey); break; } }
|
|
31
|
+
}
|
|
32
|
+
if (entry.promise && waitMs > 0) {
|
|
33
|
+
let timer;
|
|
34
|
+
await Promise.race([entry.promise, new Promise(resolve => { timer = setTimeout(resolve, waitMs); })]); clearTimeout(timer);
|
|
35
|
+
}
|
|
36
|
+
const pending = entry.promise !== null;
|
|
37
|
+
if (entry.summary) return { ...entry.summary, scan: { state: pending ? 'refreshing' : 'ready', generation: entry.generation, updatedAt: entry.at } };
|
|
38
|
+
return { bridge: { ok: true, state: 'checking' }, clients: (statusOptions.clients || SUPPORTED_CLIENTS).map(client => ({ client, label: CLIENT_LABELS[client],
|
|
39
|
+
configFound: new IntegrationManager(managerOptions).captureConfigFound(client),
|
|
40
|
+
knowledgeIntegration: { ok: true, state: 'checking', detail: '正在检查接入状态…' },
|
|
41
|
+
automaticContext: { supported: client !== 'opencode', configured: false, state: 'checking', detail: '正在检查开发前知识读取…' },
|
|
42
|
+
developmentCapture: { ok: true, state: 'checking', detail: '正在检查采集…' } })), scan: { state: 'checking', generation: entry.generation } };
|
|
43
|
+
}
|
|
44
|
+
run(managerOptions, statusOptions) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
if (this.closed || this.queue.length >= 64) { reject(Object.assign(new Error('状态检查暂不可用。'), { code: this.closed ? 'INTEGRATION_STATUS_CLOSED' : 'INTEGRATION_STATUS_BUSY' })); return; }
|
|
47
|
+
this.queue.push({ managerOptions, statusOptions, resolve, reject }); this.drain();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
drain() {
|
|
51
|
+
while (!this.closed && this.running < 2 && this.queue.length) {
|
|
52
|
+
const next = this.queue.shift(); this.running++;
|
|
53
|
+
this.probe(next.managerOptions, next.statusOptions).then(next.resolve, next.reject).finally(() => { this.running--; this.drain(); });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
probe(managerOptions, statusOptions) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const child = fork(this.workerFile, [], { stdio: ['ignore', 'ignore', 'ignore', 'ipc'], windowsHide: true, env: { ...process.env, KB_INTEGRATION_STATUS_WORKER: '1' } });
|
|
59
|
+
this.children.add(child);
|
|
60
|
+
let settled = false;
|
|
61
|
+
const finish = (error, summary) => { if (settled) return; settled = true; clearTimeout(timer); error ? reject(error) : resolve(summary); };
|
|
62
|
+
const timer = setTimeout(() => {
|
|
63
|
+
Promise.resolve(managerOptions.logger?.warn?.('integration.status.timeout', '客户端接入状态检查超时;未将其判为未安装。', {
|
|
64
|
+
operationId: managerOptions.operationId, component: 'integration', phase: 'status',
|
|
65
|
+
context: { clients: statusOptions.clients || SUPPORTED_CLIENTS, timeoutMs: this.timeoutMs },
|
|
66
|
+
})).catch(() => {});
|
|
67
|
+
this.terminate(child); finish(Object.assign(new Error('状态检查超时。'), { code: 'INTEGRATION_STATUS_TIMEOUT' }));
|
|
68
|
+
}, this.timeoutMs);
|
|
69
|
+
child.on('message', message => {
|
|
70
|
+
if (message?.kind === 'log') {
|
|
71
|
+
if (['info', 'warn', 'error'].includes(message.level) && Array.isArray(message.args) && /^integration\./.test(message.args[0] || '')) Promise.resolve(managerOptions.logger?.[message.level]?.(...message.args)).catch(() => {});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
finish(message?.ok ? null : Object.assign(new Error('状态检查失败。'), { code: message?.code }), message?.summary);
|
|
75
|
+
});
|
|
76
|
+
child.once('error', error => finish(error));
|
|
77
|
+
child.once('exit', () => { this.children.delete(child); if (!settled) finish(Object.assign(new Error('状态检查进程提前退出。'), { code: 'INTEGRATION_STATUS_EXITED' })); });
|
|
78
|
+
const allowed = ['rootDir', 'homeDir', 'version', 'packageSpec', 'operationId', 'bridgeHomeDir', 'bridgeConsumerName', 'claudeSettingsFile', 'codexConfigFile', 'zcodeConfigFile', 'openCodePluginsDir'];
|
|
79
|
+
child.send({ managerOptions: Object.fromEntries(allowed.filter(k => managerOptions[k] !== undefined).map(k => [k, managerOptions[k]])), statusOptions });
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
terminate(child) {
|
|
83
|
+
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
84
|
+
if (process.platform === 'win32') {
|
|
85
|
+
// Only the live worker we created, including its probe children. Never
|
|
86
|
+
// terminate by executable name or scan unrelated Node processes.
|
|
87
|
+
const killer = spawn('taskkill.exe', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
88
|
+
killer.on('error', () => child.kill());
|
|
89
|
+
} else child.kill('SIGTERM');
|
|
90
|
+
}
|
|
91
|
+
invalidate() { for (const entry of this.entries.values()) entry.at = 0; }
|
|
92
|
+
close() {
|
|
93
|
+
this.closed = true;
|
|
94
|
+
for (const child of this.children) this.terminate(child);
|
|
95
|
+
for (const item of this.queue) item.reject(Object.assign(new Error('扫描已关闭。'), { code: 'INTEGRATION_STATUS_CLOSED' }));
|
|
96
|
+
this.queue = []; this.entries.clear();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
module.exports = { IntegrationStatusScan };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const { IntegrationManager } = require('./integration-installer');
|
|
3
|
-
process.once('message', async input => {
|
|
4
|
-
try {
|
|
5
|
-
const logger = Object.fromEntries(['info', 'warn', 'error'].map(level => [level, (...args) => {
|
|
6
|
-
if (process.connected) process.send({ kind: 'log', level, args: args.map(value => value instanceof Error ? { name: value.name, code: value.code, message: 'Integration command failed.' } : value) });
|
|
7
|
-
}]));
|
|
8
|
-
const manager = new IntegrationManager({ ...input.managerOptions, logger });
|
|
9
|
-
const summary = await manager.statusAll(input.statusOptions);
|
|
10
|
-
process.send({ ok: true, summary }, () => process.disconnect());
|
|
11
|
-
} catch (error) {
|
|
12
|
-
process.send({ ok: false, code: error.code || 'INTEGRATION_STATUS_FAILED' }, () => process.disconnect());
|
|
13
|
-
}
|
|
14
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
const { IntegrationManager } = require('./integration-installer');
|
|
3
|
+
process.once('message', async input => {
|
|
4
|
+
try {
|
|
5
|
+
const logger = Object.fromEntries(['info', 'warn', 'error'].map(level => [level, (...args) => {
|
|
6
|
+
if (process.connected) process.send({ kind: 'log', level, args: args.map(value => value instanceof Error ? { name: value.name, code: value.code, message: 'Integration command failed.' } : value) });
|
|
7
|
+
}]));
|
|
8
|
+
const manager = new IntegrationManager({ ...input.managerOptions, logger });
|
|
9
|
+
const summary = await manager.statusAll(input.statusOptions);
|
|
10
|
+
process.send({ ok: true, summary }, () => process.disconnect());
|
|
11
|
+
} catch (error) {
|
|
12
|
+
process.send({ ok: false, code: error.code || 'INTEGRATION_STATUS_FAILED' }, () => process.disconnect());
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -42,21 +42,21 @@ function ensureFile(file, content, created, base) {
|
|
|
42
42
|
if (created) created.push(path.relative(base, file).replace(/\\/g, '/'));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function initProjectDirs(slug, kbPath) {
|
|
46
|
-
const base = path.resolve(kbPath);
|
|
47
|
-
// Import only declares the external project directory. Real Markdown and
|
|
48
|
-
// collection directories are created lazily by validated promotion; an
|
|
49
|
-
// empty/TODO skeleton would turn guesses into durable project knowledge.
|
|
50
|
-
fs.mkdirSync(base, { recursive: true });
|
|
51
|
-
return {
|
|
52
|
-
created: [],
|
|
53
|
-
basePath: base,
|
|
54
|
-
kbSchemaVersion: PROJECT_SCHEMA_VERSION,
|
|
55
|
-
frameworkSchema: KB_FRAMEWORK_SCHEMA,
|
|
56
|
-
topLevel: TOP_LEVEL.slice(),
|
|
57
|
-
lazy: true,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
45
|
+
function initProjectDirs(slug, kbPath) {
|
|
46
|
+
const base = path.resolve(kbPath);
|
|
47
|
+
// Import only declares the external project directory. Real Markdown and
|
|
48
|
+
// collection directories are created lazily by validated promotion; an
|
|
49
|
+
// empty/TODO skeleton would turn guesses into durable project knowledge.
|
|
50
|
+
fs.mkdirSync(base, { recursive: true });
|
|
51
|
+
return {
|
|
52
|
+
created: [],
|
|
53
|
+
basePath: base,
|
|
54
|
+
kbSchemaVersion: PROJECT_SCHEMA_VERSION,
|
|
55
|
+
frameworkSchema: KB_FRAMEWORK_SCHEMA,
|
|
56
|
+
topLevel: TOP_LEVEL.slice(),
|
|
57
|
+
lazy: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
60
|
|
|
61
61
|
function readIfExists(file) {
|
|
62
62
|
return fs.existsSync(file) ? fs.readFileSync(file, 'utf-8') : '';
|