@sanqianx/project-knowledge 4.6.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.
Files changed (218) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.claude-plugin/marketplace.json +17 -0
  3. package/CHANGELOG.md +780 -0
  4. package/LICENSE +201 -0
  5. package/NOTICE +5 -0
  6. package/README.md +266 -0
  7. package/_site/README.md +30 -0
  8. package/_site/_test/ai-profile-resolver-test.js +137 -0
  9. package/_site/_test/ai-profile-test.js +75 -0
  10. package/_site/_test/ai-vendor-presets-test.js +91 -0
  11. package/_site/_test/automation-queue-test.js +14 -0
  12. package/_site/_test/automation-ui-test.js +40 -0
  13. package/_site/_test/background-task-registry-test.js +43 -0
  14. package/_site/_test/baseline-schema-test.js +91 -0
  15. package/_site/_test/bin-cli-test.js +218 -0
  16. package/_site/_test/bridge-adapter-test.js +95 -0
  17. package/_site/_test/bridge-consumer-service-test.js +310 -0
  18. package/_site/_test/cdp-browser-failure-test.js +100 -0
  19. package/_site/_test/chat-claudecodeui-match-test.js +92 -0
  20. package/_site/_test/claude-executable-discovery-test.js +90 -0
  21. package/_site/_test/claude-session-lifecycle-sweep-test.js +252 -0
  22. package/_site/_test/claude-workbench-test.js +170 -0
  23. package/_site/_test/client-capture-restart-e2e-test.js +189 -0
  24. package/_site/_test/codex-conversation-projection-test.js +59 -0
  25. package/_site/_test/codex-notify-fanout-test.js +45 -0
  26. package/_site/_test/commit-boundary-freeze-test.js +147 -0
  27. package/_site/_test/commit-conversation-binding-test.js +99 -0
  28. package/_site/_test/commit-evidence-test.js +110 -0
  29. package/_site/_test/context-pack-test.js +198 -0
  30. package/_site/_test/conversation-api-test.js +119 -0
  31. package/_site/_test/conversation-store-test.js +136 -0
  32. package/_site/_test/cross-repo-isolation-e2e-test.js +187 -0
  33. package/_site/_test/data-dir-migration-test.js +77 -0
  34. package/_site/_test/desktop-browser-compat-test.js +28 -0
  35. package/_site/_test/desktop-hook-runtime-regression-test.js +204 -0
  36. package/_site/_test/embedding-config-test.js +32 -0
  37. package/_site/_test/explicit-commit-processor-test.js +37 -0
  38. package/_site/_test/fixtures/fake-browser-exit.js +10 -0
  39. package/_site/_test/fixtures/fake-browser-hang.js +10 -0
  40. package/_site/_test/fixtures/make-git-repos.js +89 -0
  41. package/_site/_test/folder-picker-output-test.js +19 -0
  42. package/_site/_test/full-integration-e2e-test.js +165 -0
  43. package/_site/_test/git-validation-test.js +81 -0
  44. package/_site/_test/hook-runtime-endpoint-test.js +88 -0
  45. package/_site/_test/hook-status-repair-api-test.js +152 -0
  46. package/_site/_test/hook-trigger-test.js +85 -0
  47. package/_site/_test/hook-worktree-test.js +42 -0
  48. package/_site/_test/import-preflight-api-test.js +233 -0
  49. package/_site/_test/import-ui-flow-test.js +171 -0
  50. package/_site/_test/index-builder-test.js +41 -0
  51. package/_site/_test/index-writer-concurrency-test.js +135 -0
  52. package/_site/_test/integration-adapters-test.js +243 -0
  53. package/_site/_test/integration-capture-setup-test.js +108 -0
  54. package/_site/_test/integration-surface-coverage-test.js +165 -0
  55. package/_site/_test/kb-framework-test.js +57 -0
  56. package/_site/_test/kbpath-follow-test.js +63 -0
  57. package/_site/_test/knowledge-db-test.js +144 -0
  58. package/_site/_test/knowledge-language-control-test.js +170 -0
  59. package/_site/_test/knowledge-maintenance-test.js +40 -0
  60. package/_site/_test/knowledge-migration-test.js +75 -0
  61. package/_site/_test/knowledge-promotion-recovery-test.js +260 -0
  62. package/_site/_test/knowledge-query-test.js +54 -0
  63. package/_site/_test/knowledge-retrieval-service-test.js +77 -0
  64. package/_site/_test/knowledge-scopes-test.js +37 -0
  65. package/_site/_test/knowledge-storage-location-test.js +28 -0
  66. package/_site/_test/knowledge-storage-startup-test.js +52 -0
  67. package/_site/_test/knowledge-store-logs-supervision-test.js +89 -0
  68. package/_site/_test/legacy-claude-session-alias-test.js +106 -0
  69. package/_site/_test/legacy-forward-compat-test.js +257 -0
  70. package/_site/_test/legacy-project-upgrade-e2e-test.js +363 -0
  71. package/_site/_test/legacy-routes-removed-test.js +47 -0
  72. package/_site/_test/legacy-workbench-exclusion-test.js +92 -0
  73. package/_site/_test/log-redaction-test.js +58 -0
  74. package/_site/_test/logging-api-test.js +89 -0
  75. package/_site/_test/logging-sse-no-gap-test.js +88 -0
  76. package/_site/_test/logging-ui-test.js +104 -0
  77. package/_site/_test/markdown-delta-overlay-test.js +85 -0
  78. package/_site/_test/markdown-maintenance-api-test.js +75 -0
  79. package/_site/_test/markdown-maintenance-test.js +11 -0
  80. package/_site/_test/mcp-server-test.js +149 -0
  81. package/_site/_test/model-context-windows-test.js +89 -0
  82. package/_site/_test/module-bridge-eventbridge-test.js +193 -0
  83. package/_site/_test/non-release-ci-test.js +34 -0
  84. package/_site/_test/offline-boundary-isolation-test.js +32 -0
  85. package/_site/_test/orphaned-claim-recovery-test.js +80 -0
  86. package/_site/_test/p0-data-migration-characterization-test.js +37 -0
  87. package/_site/_test/p0-e2e-gate-test.js +347 -0
  88. package/_site/_test/package-boundary-test.js +42 -0
  89. package/_site/_test/package-startup-test.js +56 -0
  90. package/_site/_test/packaged-ui-smoke-test.js +79 -0
  91. package/_site/_test/path-consistency-test.js +151 -0
  92. package/_site/_test/pending-sweep-test.js +9 -0
  93. package/_site/_test/post-commit-automation-test.js +87 -0
  94. package/_site/_test/pr-consumer-contract-test.js +55 -0
  95. package/_site/_test/project-control-panel-task14-test.js +63 -0
  96. package/_site/_test/project-delete-recovery-test.js +64 -0
  97. package/_site/_test/project-goal-editor-test.js +145 -0
  98. package/_site/_test/project-layout-v2-migration-test.js +127 -0
  99. package/_site/_test/project-lifecycle-transaction-test.js +106 -0
  100. package/_site/_test/project-remove-running-guard-test.js +79 -0
  101. package/_site/_test/project-store-test.js +90 -0
  102. package/_site/_test/prompt-settings-test.js +115 -0
  103. package/_site/_test/protected-architecture-gate-test.js +123 -0
  104. package/_site/_test/refactor-characterization-test.js +36 -0
  105. package/_site/_test/release-version-sync-test.js +98 -0
  106. package/_site/_test/requirement-binding-test.js +113 -0
  107. package/_site/_test/requirement-recorder-test.js +173 -0
  108. package/_site/_test/run-all-tests.js +156 -0
  109. package/_site/_test/runtime-endpoint-test.js +64 -0
  110. package/_site/_test/scanner-test.js +83 -0
  111. package/_site/_test/server-runtime-migration-safety-test.js +27 -0
  112. package/_site/_test/server-security-test.js +96 -0
  113. package/_site/_test/sessions-stream-test.js +92 -0
  114. package/_site/_test/shared-contracts-test.js +58 -0
  115. package/_site/_test/simple-import-test.js +97 -0
  116. package/_site/_test/startup-analysis-disabled-test.js +16 -0
  117. package/_site/_test/storage-foundation-test.js +78 -0
  118. package/_site/_test/structured-logger-test.js +101 -0
  119. package/_site/_test/task15-20-ui-flow-test.js +148 -0
  120. package/_site/_test/team-knowledge-store-sparse-checkout-test.js +196 -0
  121. package/_site/_test/team-knowledge-store-test.js +131 -0
  122. package/_site/_test/tracking-start-test.js +143 -0
  123. package/_site/_test/ui-i18n-toggle-test.js +114 -0
  124. package/_site/_test/ui-smoke-test.js +73 -0
  125. package/_site/_test/v4122-upgrade-data-contract-test.js +56 -0
  126. package/_site/_test/workbench-permission-test.js +118 -0
  127. package/_site/_test/workspace-ui-contract-test.js +43 -0
  128. package/_site/lib/ai-profile-resolver.js +78 -0
  129. package/_site/lib/ai-vendor-presets.js +83 -0
  130. package/_site/lib/ai-workspace.js +104 -0
  131. package/_site/lib/atomic-file.js +204 -0
  132. package/_site/lib/automation-config.js +140 -0
  133. package/_site/lib/bridge-adapter.js +256 -0
  134. package/_site/lib/bridge-consumer-service.js +402 -0
  135. package/_site/lib/claude-cli-runner.js +1599 -0
  136. package/_site/lib/commit-conversation-binder.js +246 -0
  137. package/_site/lib/commit-processing-ledger.js +27 -0
  138. package/_site/lib/commit-prompt.js +202 -0
  139. package/_site/lib/commit-reconciler.js +444 -0
  140. package/_site/lib/context-pack-builder.js +299 -0
  141. package/_site/lib/contracts.js +279 -0
  142. package/_site/lib/conversation-exclusions.js +204 -0
  143. package/_site/lib/conversation-query-service.js +161 -0
  144. package/_site/lib/conversation-store.js +385 -0
  145. package/_site/lib/data-dir.js +81 -0
  146. package/_site/lib/data-state-classifier.js +40 -0
  147. package/_site/lib/embedding-service.js +85 -0
  148. package/_site/lib/evidence-bundle.js +228 -0
  149. package/_site/lib/folder-picker-output.js +24 -0
  150. package/_site/lib/git-runner.js +62 -0
  151. package/_site/lib/github-team-store.js +1175 -0
  152. package/_site/lib/hook-manager.js +202 -0
  153. package/_site/lib/index-builder.js +157 -0
  154. package/_site/lib/index-service.js +173 -0
  155. package/_site/lib/integration-installer.js +907 -0
  156. package/_site/lib/kb-framework.js +191 -0
  157. package/_site/lib/kb-validator.js +124 -0
  158. package/_site/lib/knowledge-db.js +363 -0
  159. package/_site/lib/knowledge-promotion.js +435 -0
  160. package/_site/lib/knowledge-retrieval-service.js +401 -0
  161. package/_site/lib/knowledge-schema.js +121 -0
  162. package/_site/lib/knowledge-tool-runtime.js +359 -0
  163. package/_site/lib/legacy-data-manifest.js +26 -0
  164. package/_site/lib/llm-client.js +173 -0
  165. package/_site/lib/markdown-knowledge-indexer.js +230 -0
  166. package/_site/lib/migration-service.js +442 -0
  167. package/_site/lib/model-context-windows.js +82 -0
  168. package/_site/lib/module-bridge.js +496 -0
  169. package/_site/lib/post-commit-automation.js +141 -0
  170. package/_site/lib/project-lifecycle-service.js +511 -0
  171. package/_site/lib/project-registry-store.js +129 -0
  172. package/_site/lib/project-store.js +262 -0
  173. package/_site/lib/prompt-registry.js +148 -0
  174. package/_site/lib/requirement-adapters.js +10 -0
  175. package/_site/lib/requirement-binder.js +112 -0
  176. package/_site/lib/requirement-recorder.js +278 -0
  177. package/_site/lib/runtime-endpoint.js +160 -0
  178. package/_site/lib/scanner.js +298 -0
  179. package/_site/lib/server-app.js +1520 -0
  180. package/_site/lib/settings-store.js +113 -0
  181. package/_site/lib/storage-layout.js +162 -0
  182. package/_site/lib/structured-logger.js +574 -0
  183. package/_site/scripts/codex-notify-fanout.cjs +51 -0
  184. package/_site/scripts/folder-picker.ps1 +156 -0
  185. package/_site/scripts/hook-trigger.js +156 -0
  186. package/_site/scripts/sync-release-version.js +158 -0
  187. package/_site/server.js +12 -0
  188. package/_site/start.bat +26 -0
  189. package/_site/stop.bat +11 -0
  190. package/bin/project-knowledge-integrations.js +241 -0
  191. package/bin/project-knowledge-kb.js +65 -0
  192. package/bin/project-knowledge-mcp.js +195 -0
  193. package/bin/project-knowledge.js +439 -0
  194. package/claude-prompts.json +21 -0
  195. package/docs/README.zh-CN.md +175 -0
  196. package/docs/assets/architecture.svg +182 -0
  197. package/docs/assets/dashboard.png +0 -0
  198. package/docs/assets/draft-review.png +0 -0
  199. package/docs/assets/logo.svg +50 -0
  200. package/docs/assets/runs-drafts.png +0 -0
  201. package/docs/assets/settings.png +0 -0
  202. package/docs/project-registry-schema.md +33 -0
  203. package/docs/team-knowledge-mode-a-plan.md +73 -0
  204. package/docs/testing-strategy.md +33 -0
  205. package/package.json +100 -0
  206. package/plugins/project-knowledge/.claude-plugin/plugin.json +19 -0
  207. package/plugins/project-knowledge/.codex-plugin/plugin.json +38 -0
  208. package/plugins/project-knowledge/.mcp.json +14 -0
  209. package/plugins/project-knowledge/opencode/project-knowledge.md +3 -0
  210. package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +28 -0
  211. package/plugins/project-knowledge/skills/project-knowledge/agents/openai.yaml +11 -0
  212. package/templates/change.md +30 -0
  213. package/templates/project-readme.md +52 -0
  214. package/ui/app.css +58 -0
  215. package/ui/app.js +607 -0
  216. package/ui/favicon.svg +38 -0
  217. package/ui/i18n.js +146 -0
  218. package/ui/index.html +162 -0
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env node
2
+
3
+ const {
4
+ IntegrationManager,
5
+ SUPPORTED_CLIENTS,
6
+ normalizeClient,
7
+ } = require('../_site/lib/integration-installer');
8
+
9
+ function printHelp() {
10
+ console.log(`project-knowledge-integrations
11
+
12
+ Install Project Knowledge for coding agents: Knowledge Integration (MCP +
13
+ Skill / plugin) and Development Capture (Bridge hooks / notify / plugin).
14
+
15
+ Usage:
16
+ project-knowledge-integrations install [--ide <client>] [--scope <scope>] [--knowledge-only|--capture-only]
17
+ project-knowledge-integrations update [--ide <client>] [--scope <scope>]
18
+ project-knowledge-integrations uninstall [--ide <client>] [--scope <scope>] [--knowledge-only|--capture-only]
19
+ project-knowledge-integrations status [--ide <client>]
20
+ project-knowledge-integrations disable-capture
21
+
22
+ Clients:
23
+ claude Claude Code plugin (MCP + Skill) + managed Bridge hooks
24
+ opencode OpenCode MCP + global Skill + managed Bridge plugin
25
+ codex Codex plugin (MCP + Skill) + managed Bridge notify
26
+ all All supported clients
27
+
28
+ Options:
29
+ --ide <client> Repeat or use a comma-separated list
30
+ --scope <scope> Claude scope: user, project, or local (default: user)
31
+ --marketplace <src> Marketplace GitHub repo, Git URL, or local path
32
+ --knowledge-only Only install/uninstall the Knowledge Integration
33
+ --capture-only Only install/uninstall the Development Capture
34
+ --dry-run Show intended operations without changing config
35
+ --json Print machine-readable results
36
+ -h, --help Show this help
37
+
38
+ Without --ide, installed clients are detected automatically. One install
39
+ action configures both capabilities; no client UI needs to be opened.`);
40
+ }
41
+
42
+ function parseArgs(argv) {
43
+ const operation = argv[0] && !argv[0].startsWith('-') ? argv[0] : 'status';
44
+ const start = operation === 'status' && (!argv[0] || argv[0].startsWith('-')) ? 0 : 1;
45
+ const options = {
46
+ operation,
47
+ clients: [],
48
+ scope: 'user',
49
+ dryRun: false,
50
+ json: false,
51
+ help: false,
52
+ marketplaceSource: '',
53
+ knowledgeOnly: false,
54
+ captureOnly: false,
55
+ };
56
+ for (let i = start; i < argv.length; i++) {
57
+ const arg = argv[i];
58
+ if (arg === '--ide' && argv[i + 1]) {
59
+ options.clients.push(...argv[++i].split(',').filter(Boolean));
60
+ } else if (arg === '--all') {
61
+ options.clients.push('all');
62
+ } else if (arg === '--scope' && argv[i + 1]) {
63
+ options.scope = argv[++i];
64
+ } else if (arg === '--marketplace' && argv[i + 1]) {
65
+ options.marketplaceSource = argv[++i];
66
+ } else if (arg === '--knowledge-only') {
67
+ options.knowledgeOnly = true;
68
+ } else if (arg === '--capture-only') {
69
+ options.captureOnly = true;
70
+ } else if (arg === '--dry-run') {
71
+ options.dryRun = true;
72
+ } else if (arg === '--json') {
73
+ options.json = true;
74
+ } else if (arg === '--help' || arg === '-h') {
75
+ options.help = true;
76
+ } else {
77
+ throw new Error(`unknown option: ${arg}`);
78
+ }
79
+ }
80
+ if (options.knowledgeOnly && options.captureOnly) {
81
+ throw new Error('--knowledge-only and --capture-only are mutually exclusive');
82
+ }
83
+ if (!['install', 'update', 'uninstall', 'status', 'disable-capture'].includes(options.operation)) {
84
+ throw new Error(`unknown operation: ${options.operation}`);
85
+ }
86
+ if (!['user', 'project', 'local'].includes(options.scope)) {
87
+ throw new Error(`unsupported scope: ${options.scope}`);
88
+ }
89
+ return options;
90
+ }
91
+
92
+ function selectClients(requested, manager) {
93
+ if (requested.some(item => String(item).toLowerCase() === 'all')) return [...SUPPORTED_CLIENTS];
94
+ if (requested.length) return [...new Set(requested.map(normalizeClient))];
95
+ const detected = manager.detectClients();
96
+ if (detected.length) return detected;
97
+ return [...SUPPORTED_CLIENTS];
98
+ }
99
+
100
+ function printCapabilityLine(prefix, capability) {
101
+ if (!capability) return;
102
+ const mark = capability.ok ? 'OK' : 'FAIL';
103
+ console.log(` [${mark}] ${prefix}: ${capability.state} - ${capability.detail}`);
104
+ }
105
+
106
+ async function runCli(argv = process.argv.slice(2), dependencies = {}) {
107
+ const options = parseArgs(argv);
108
+ if (options.help) {
109
+ printHelp();
110
+ return 0;
111
+ }
112
+ const manager = dependencies.manager || new IntegrationManager({
113
+ dryRun: options.dryRun,
114
+ marketplaceSource: options.marketplaceSource || undefined,
115
+ });
116
+ const clients = selectClients(options.clients, manager);
117
+
118
+ if (options.operation === 'disable-capture') {
119
+ const summary = await manager.disableAllCapture({ clients });
120
+ if (options.json) {
121
+ console.log(JSON.stringify({ operation: 'disable-capture', ...summary, planned: manager.planned }, null, 2));
122
+ } else {
123
+ for (const result of summary.clients) {
124
+ const mark = result.ok ? 'OK' : 'FAIL';
125
+ console.log(`[${mark}] ${result.label}: ${result.state} - ${result.detail}`);
126
+ }
127
+ const consumerMark = summary.consumer.ok ? 'OK' : 'FAIL';
128
+ console.log(`[${consumerMark}] Bridge consumer: ${summary.consumer.state || summary.consumer.detail}`);
129
+ }
130
+ return summary.clients.some(result => !result.ok) || !summary.consumer.ok ? 1 : 0;
131
+ }
132
+
133
+ if (options.operation === 'install') {
134
+ // One action configures Knowledge Integration + Development Capture
135
+ // together (per-client flags narrow the scope). No client UI is needed.
136
+ const summary = await manager.installAll({ clients, knowledgeOnly: options.knowledgeOnly, captureOnly: options.captureOnly, scope: options.scope });
137
+ if (options.json) {
138
+ console.log(JSON.stringify({ operation: 'install', ...summary, planned: manager.planned }, null, 2));
139
+ } else {
140
+ const bridgeMark = summary.bridge.ok ? 'OK' : 'FAIL';
141
+ console.log(`[${bridgeMark}] Bridge: ${summary.bridge.state} - consumer ${manager.bridgeConsumerName}`);
142
+ for (const entry of summary.clients) {
143
+ printCapabilityLine(`${entry.label} Knowledge Integration`, entry.knowledgeIntegration);
144
+ printCapabilityLine(`${entry.label} Development Capture`, entry.developmentCapture);
145
+ }
146
+ if (options.dryRun && manager.planned.length) {
147
+ console.log('\nPlanned operations:');
148
+ for (const item of manager.planned) {
149
+ if (item.command) console.log(` ${item.command} ${item.args.join(' ')}`);
150
+ else if (item.copy) console.log(` copy ${item.copy} -> ${item.destination}`);
151
+ else console.log(` remove ${item.removeConfig} and ${item.removeDirectory}`);
152
+ }
153
+ }
154
+ }
155
+ return summary.clients.some(entry =>
156
+ (entry.knowledgeIntegration && !entry.knowledgeIntegration.ok)
157
+ || (entry.developmentCapture && !entry.developmentCapture.ok)
158
+ ) || !summary.bridge.ok ? 1 : 0;
159
+ }
160
+
161
+ if (options.operation === 'uninstall') {
162
+ if (options.captureOnly) {
163
+ const results = await manager.operateCapture('uninstall', clients, {});
164
+ if (options.json) {
165
+ console.log(JSON.stringify({ operation: 'uninstall', captureOnly: true, results, planned: manager.planned }, null, 2));
166
+ } else {
167
+ for (const result of results) {
168
+ const mark = result.ok ? 'OK' : 'FAIL';
169
+ console.log(`[${mark}] ${result.label}: ${result.state} - ${result.detail}`);
170
+ }
171
+ }
172
+ return results.some(result => !result.ok) ? 1 : 0;
173
+ }
174
+ // Default uninstall removes both capabilities but KEEPS the host Bridge
175
+ // consumer; use disable-capture for the global consumer unregister.
176
+ const knowledgeResults = await manager.operate('uninstall', clients, { scope: options.scope });
177
+ const captureResults = options.knowledgeOnly ? [] : await manager.operateCapture('uninstall', clients, {});
178
+ if (options.json) {
179
+ console.log(JSON.stringify({ operation: 'uninstall', knowledgeResults, captureResults, planned: manager.planned }, null, 2));
180
+ } else {
181
+ for (const result of [...knowledgeResults, ...captureResults]) {
182
+ const mark = result.ok ? 'OK' : 'FAIL';
183
+ console.log(`[${mark}] ${result.label}: ${result.state} - ${result.detail}`);
184
+ }
185
+ }
186
+ return [...knowledgeResults, ...captureResults].some(result => !result.ok) ? 1 : 0;
187
+ }
188
+
189
+ if (options.operation === 'status') {
190
+ const summary = await manager.statusAll({ clients });
191
+ if (options.json) {
192
+ console.log(JSON.stringify({ operation: 'status', ...summary, planned: manager.planned }, null, 2));
193
+ } else {
194
+ const bridgeMark = summary.bridge.ok ? 'OK' : 'FAIL';
195
+ console.log(`[${bridgeMark}] Bridge: consumer ${summary.bridge.consumerRegistered ? 'registered' : 'not registered'}, journal ${summary.bridge.bridgeHealthy ? 'healthy' : 'unavailable'}`);
196
+ for (const entry of summary.clients) {
197
+ printCapabilityLine(`${entry.label} Knowledge Integration`, entry.knowledgeIntegration);
198
+ printCapabilityLine(`${entry.label} Development Capture`, entry.developmentCapture);
199
+ }
200
+ }
201
+ return 0;
202
+ }
203
+
204
+ const results = await manager.operate(options.operation, clients, { scope: options.scope });
205
+ if (options.json) {
206
+ console.log(JSON.stringify({
207
+ operation: options.operation,
208
+ results,
209
+ planned: manager.planned,
210
+ }, null, 2));
211
+ } else {
212
+ for (const result of results) {
213
+ const mark = result.ok ? 'OK' : 'FAIL';
214
+ console.log(`[${mark}] ${result.label}: ${result.state} - ${result.detail}`);
215
+ }
216
+ if (options.dryRun && manager.planned.length) {
217
+ console.log('\nPlanned operations:');
218
+ for (const item of manager.planned) {
219
+ if (item.command) console.log(` ${item.command} ${item.args.join(' ')}`);
220
+ else if (item.copy) console.log(` copy ${item.copy} -> ${item.destination}`);
221
+ else console.log(` remove ${item.removeConfig} and ${item.removeDirectory}`);
222
+ }
223
+ }
224
+ }
225
+ return results.some(result => !result.ok) ? 1 : 0;
226
+ }
227
+
228
+ if (require.main === module) {
229
+ runCli().then(code => {
230
+ process.exitCode = code;
231
+ }).catch(error => {
232
+ console.error(`project-knowledge-integrations: ${error.message}`);
233
+ process.exitCode = 1;
234
+ });
235
+ }
236
+
237
+ module.exports = {
238
+ parseArgs,
239
+ runCli,
240
+ selectClients,
241
+ };
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { KnowledgeToolRuntime } = require('../_site/lib/knowledge-tool-runtime');
4
+ const { serializeErrorEnvelope, createId } = require('../_site/lib/contracts');
5
+
6
+ function parseOptions(args) {
7
+ const first = args[0] || 'help';
8
+ const output = { command: first === '--help' || first === '-h' ? 'help' : first };
9
+ for (let index = 1; index < args.length; index += 1) {
10
+ const key = args[index];
11
+ if (!key.startsWith('--')) continue;
12
+ const name = key.slice(2).replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
13
+ if (args[index + 1] && !args[index + 1].startsWith('--')) output[name] = args[++index];
14
+ else output[name] = true;
15
+ }
16
+ return output;
17
+ }
18
+
19
+ function help() {
20
+ process.stdout.write(`project-knowledge-kb
21
+
22
+ Read-only local knowledge tools:
23
+ project-knowledge-kb search --project <projectId-or-legacy-slug> --query <text> [--limit 8]
24
+ project-knowledge-kb ask --project <projectId-or-legacy-slug> --query <text> [--limit 8]
25
+ project-knowledge-kb get --project <projectId-or-legacy-slug> --entry <path>
26
+ project-knowledge-kb history --project <projectId-or-legacy-slug> [--limit 20]
27
+
28
+ Add --json for machine-readable output. These commands never modify knowledge or project configuration.\n`);
29
+ }
30
+
31
+ async function main(argv = process.argv.slice(2), options = {}) {
32
+ const args = parseOptions(argv);
33
+ if (args.command === 'help' || args.help) {
34
+ help();
35
+ return 0;
36
+ }
37
+ if (!['search', 'ask', 'get', 'history'].includes(args.command)) throw new Error(`unknown command: ${args.command}`);
38
+ if (!args.project) throw new Error('--project is required');
39
+ const runtime = options.runtime || new KnowledgeToolRuntime(options);
40
+ try {
41
+ const input = { project: args.project, query: args.query, limit: args.limit, entry: args.entry };
42
+ let result;
43
+ if (args.command === 'search') result = await runtime.search(input);
44
+ else if (args.command === 'ask') result = await runtime.ask(input);
45
+ else if (args.command === 'get') result = await runtime.get(input);
46
+ else result = await runtime.history(input);
47
+ if (args.json || args.command !== 'ask') process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
48
+ else process.stdout.write(`${result.answer}\n`);
49
+ return 0;
50
+ } finally {
51
+ await runtime.close();
52
+ }
53
+ }
54
+
55
+ if (require.main === module) {
56
+ const jsonMode = process.argv.includes('--json');
57
+ const operationId = createId('op');
58
+ main().catch(error => {
59
+ if (jsonMode) process.stderr.write(`${JSON.stringify(serializeErrorEnvelope(error, operationId))}\n`);
60
+ else process.stderr.write(`project-knowledge-kb: ${String(error && error.message || 'The operation failed.')} [${operationId}]\n`);
61
+ process.exitCode = 1;
62
+ });
63
+ }
64
+
65
+ module.exports = { main, parseOptions };
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env node
2
+
3
+ const packageInfo = require('../package.json');
4
+ const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
5
+ const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
6
+ const {
7
+ CallToolRequestSchema,
8
+ ListToolsRequestSchema,
9
+ } = require('@modelcontextprotocol/sdk/types.js');
10
+ const { KnowledgeToolRuntime } = require('../_site/lib/knowledge-tool-runtime');
11
+ const { serializeErrorEnvelope, createId } = require('../_site/lib/contracts');
12
+
13
+ const SERVER_NAME = 'project-knowledge';
14
+ const SERVER_INSTRUCTIONS = `Project Knowledge is the durable source of prior project decisions and implementation history. Knowledge content is read-only; the only write operation appends an explicit supplemental Prompt event to the shared conversation truth.
15
+
16
+ At the start of work in a registered Git repository, and before answering questions about prior work or implementing a non-trivial change:
17
+ 1. Call project_knowledge_resolve with the current Git root.
18
+ 2. Use project_knowledge_search or project_knowledge_ask for relevant prior decisions.
19
+ 3. Use project_knowledge_get only for the most relevant complete entry and project_knowledge_history when change history matters.
20
+ 4. Call project_knowledge_record_requirement only when the user explicitly asks to supplement capture or automatic client capture is known to be unavailable; it is not a mandatory pre-work call.
21
+
22
+ Treat all returned knowledge as read-only. Verify it against current source code when necessary. The supplemental requirement tool writes the same ConversationStore used by automatic capture and never starts analysis. Do not write directly to the knowledge database; project-knowledge updates it automatically after successful Git commits.`;
23
+
24
+ const TOOLS = [
25
+ {
26
+ name: 'project_knowledge_resolve',
27
+ description: 'Resolve the registered Project Knowledge project for a Git repository. Call this first before using other knowledge tools.',
28
+ inputSchema: {
29
+ type: 'object',
30
+ properties: {
31
+ repoPath: { type: 'string', description: 'Current Git repository root or any path inside it. Defaults to the MCP process working directory.' },
32
+ projectId: { type: 'string', description: 'Stable projectId when it is already known.' },
33
+ project: { type: 'string', description: 'Optional registered project slug when it is already known.' },
34
+ },
35
+ additionalProperties: false,
36
+ },
37
+ },
38
+ {
39
+ name: 'project_knowledge_record_requirement',
40
+ description: 'Explicitly supplement automatic capture with one project-scoped user Prompt event. This is the only write-capable tool; it never starts analysis or writes knowledge Markdown.',
41
+ inputSchema: {
42
+ type: 'object',
43
+ required: ['text', 'client', 'sessionId'],
44
+ properties: {
45
+ text: { type: 'string', minLength: 1, maxLength: 131072, description: 'The user request exactly as received; do not include system prompts or tool transcripts.' },
46
+ client: { type: 'string', enum: ['claude', 'codex', 'opencode'] },
47
+ sessionId: { type: 'string', minLength: 1, maxLength: 512, description: 'Stable identifier for the current client session.' },
48
+ conversationId: { type: 'string', minLength: 1, maxLength: 512 },
49
+ projectId: { type: 'string', description: 'Stable projectId returned by project_knowledge_resolve.' },
50
+ repoPath: { type: 'string', description: 'Current Git root. Used for exact project resolution when projectId is omitted.' },
51
+ explicitCommit: { type: 'string', description: 'Optional Git commit explicitly associated with this requirement.' },
52
+ },
53
+ anyOf: [{ required: ['projectId'] }, { required: ['repoPath'] }],
54
+ additionalProperties: false,
55
+ },
56
+ },
57
+ {
58
+ name: 'project_knowledge_search',
59
+ description: 'Search durable project knowledge using the current project and its explicitly related-project scope. This tool is read-only.',
60
+ inputSchema: {
61
+ type: 'object',
62
+ required: ['query'],
63
+ properties: {
64
+ query: { type: 'string', minLength: 1 },
65
+ repoPath: { type: 'string', description: 'Current Git repository root or a path inside it.' },
66
+ projectId: { type: 'string', description: 'Stable projectId returned by project_knowledge_resolve.' },
67
+ project: { type: 'string', description: 'Optional registered project slug.' },
68
+ limit: { type: 'integer', minimum: 1, maximum: 30, default: 8 },
69
+ },
70
+ additionalProperties: false,
71
+ },
72
+ },
73
+ {
74
+ name: 'project_knowledge_ask',
75
+ description: 'Return a compact answer with citations from durable project knowledge. This tool is read-only.',
76
+ inputSchema: {
77
+ type: 'object',
78
+ required: ['query'],
79
+ properties: {
80
+ query: { type: 'string', minLength: 1 },
81
+ repoPath: { type: 'string' },
82
+ projectId: { type: 'string' },
83
+ project: { type: 'string' },
84
+ limit: { type: 'integer', minimum: 1, maximum: 30, default: 8 },
85
+ },
86
+ additionalProperties: false,
87
+ },
88
+ },
89
+ {
90
+ name: 'project_knowledge_get',
91
+ description: 'Read one complete knowledge entry selected from search results. This tool is read-only and scope checked.',
92
+ inputSchema: {
93
+ type: 'object',
94
+ required: ['entry'],
95
+ properties: {
96
+ entry: { type: 'string', minLength: 1, description: 'Entry identifier returned by search.' },
97
+ space: { type: 'string', description: 'Optional scoped knowledge space identifier.' },
98
+ repoPath: { type: 'string' },
99
+ projectId: { type: 'string' },
100
+ project: { type: 'string' },
101
+ },
102
+ additionalProperties: false,
103
+ },
104
+ },
105
+ {
106
+ name: 'project_knowledge_history',
107
+ description: 'Read recent durable change history for the current project and its allowed scope. This tool is read-only.',
108
+ inputSchema: {
109
+ type: 'object',
110
+ properties: {
111
+ repoPath: { type: 'string' },
112
+ projectId: { type: 'string' },
113
+ project: { type: 'string' },
114
+ limit: { type: 'integer', minimum: 1, maximum: 100, default: 20 },
115
+ },
116
+ additionalProperties: false,
117
+ },
118
+ },
119
+ ];
120
+
121
+ function toolContent(result) {
122
+ return {
123
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
124
+ structuredContent: result,
125
+ isError: false,
126
+ };
127
+ }
128
+
129
+ function callTool(runtime, name, args) {
130
+ if (name === 'project_knowledge_resolve') return runtime.resolveProject(args);
131
+ if (name === 'project_knowledge_record_requirement') return runtime.recordRequirement(args);
132
+ if (name === 'project_knowledge_search') return runtime.search(args);
133
+ if (name === 'project_knowledge_ask') return runtime.ask(args);
134
+ if (name === 'project_knowledge_get') return runtime.get(args);
135
+ if (name === 'project_knowledge_history') return runtime.history(args);
136
+ throw new Error(`unknown tool: ${name}`);
137
+ }
138
+
139
+ function createServer(options = {}) {
140
+ const runtime = options.runtime || new KnowledgeToolRuntime();
141
+ const server = new Server(
142
+ { name: SERVER_NAME, version: packageInfo.version },
143
+ {
144
+ capabilities: { tools: { listChanged: false } },
145
+ instructions: SERVER_INSTRUCTIONS,
146
+ },
147
+ );
148
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
149
+ server.setRequestHandler(CallToolRequestSchema, async request => {
150
+ const name = String(request.params?.name || '');
151
+ const args = request.params?.arguments && typeof request.params.arguments === 'object'
152
+ ? request.params.arguments
153
+ : {};
154
+ try {
155
+ return toolContent(await callTool(runtime, name, args));
156
+ } catch (error) {
157
+ const operationId = createId('op');
158
+ return {
159
+ content: [{ type: 'text', text: JSON.stringify(serializeErrorEnvelope(error, operationId)) }],
160
+ isError: true,
161
+ };
162
+ }
163
+ });
164
+ return { server, runtime };
165
+ }
166
+
167
+ async function main() {
168
+ const { server, runtime } = createServer();
169
+ const transport = new StdioServerTransport();
170
+ let closing = false;
171
+ const close = async () => {
172
+ if (closing) return;
173
+ closing = true;
174
+ await runtime.close();
175
+ await server.close();
176
+ };
177
+ process.once('SIGINT', () => close().finally(() => process.exit(0)));
178
+ process.once('SIGTERM', () => close().finally(() => process.exit(0)));
179
+ await server.connect(transport);
180
+ }
181
+
182
+ if (require.main === module) {
183
+ main().catch(error => {
184
+ process.stderr.write(`[project-knowledge-mcp] ${JSON.stringify(serializeErrorEnvelope(error, createId('op')))}\n`);
185
+ process.exit(1);
186
+ });
187
+ }
188
+
189
+ module.exports = {
190
+ callTool,
191
+ createServer,
192
+ SERVER_INSTRUCTIONS,
193
+ SERVER_NAME,
194
+ TOOLS,
195
+ };