@sanqianx/project-knowledge 4.7.0 → 4.8.0
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 +17 -17
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +817 -799
- package/README.md +48 -36
- package/_modules/knowledge-engine/README.md +88 -0
- package/_modules/knowledge-engine/package.json +38 -0
- package/_modules/knowledge-engine/src/analysis-contract.js +25 -0
- package/_modules/knowledge-engine/src/analysis-worker.js +54 -0
- package/_modules/knowledge-engine/src/bin.js +52 -0
- package/_modules/knowledge-engine/src/bridge-client.js +24 -0
- package/_modules/knowledge-engine/src/coordinator.js +255 -0
- package/_modules/knowledge-engine/src/headless-analyzer.js +75 -0
- package/_modules/knowledge-engine/src/memories.js +85 -0
- package/_modules/knowledge-engine/src/migration.js +88 -0
- package/_modules/knowledge-engine/src/retrieval.js +116 -0
- package/_modules/knowledge-engine/src/runtime/README.md +7 -0
- package/_modules/knowledge-engine/src/runtime/atomic-file.js +204 -0
- package/_modules/knowledge-engine/src/runtime/automation-config.js +140 -0
- package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +249 -0
- package/_modules/knowledge-engine/src/runtime/commit-processing-ledger.js +26 -0
- package/_modules/knowledge-engine/src/runtime/commit-prompt.js +202 -0
- package/_modules/knowledge-engine/src/runtime/commit-reconciler.js +432 -0
- package/_modules/knowledge-engine/src/runtime/content-hash.js +4 -0
- package/_modules/knowledge-engine/src/runtime/contracts.js +279 -0
- package/_modules/knowledge-engine/src/runtime/conversation-exclusions.js +204 -0
- package/_modules/knowledge-engine/src/runtime/conversation-store.js +387 -0
- package/_modules/knowledge-engine/src/runtime/evidence-bundle.js +228 -0
- package/_modules/knowledge-engine/src/runtime/git-runner.js +62 -0
- package/_modules/knowledge-engine/src/runtime/knowledge-promotion.js +444 -0
- package/_modules/knowledge-engine/src/runtime/knowledge-retrieval-service.js +402 -0
- package/_modules/knowledge-engine/src/runtime/layout.js +44 -0
- package/_modules/knowledge-engine/src/runtime/markdown-knowledge-indexer.js +230 -0
- package/_modules/knowledge-engine/src/runtime/scanner.js +298 -0
- package/_modules/knowledge-engine/src/server.js +155 -0
- package/_modules/knowledge-engine/src/store.js +239 -0
- package/_modules/knowledge-engine/ui/app.css +172 -0
- package/_modules/knowledge-engine/ui/app.js +297 -0
- package/_modules/knowledge-engine/ui/index.html +95 -0
- package/_site/README.md +30 -30
- package/_site/_test/ai-profile-resolver-test.js +137 -137
- package/_site/_test/automation-queue-test.js +14 -14
- package/_site/_test/automation-ui-test.js +40 -40
- package/_site/_test/background-task-registry-test.js +43 -43
- package/_site/_test/baseline-schema-test.js +91 -91
- package/_site/_test/chat-claudecodeui-match-test.js +92 -92
- package/_site/_test/claude-executable-discovery-test.js +62 -62
- package/_site/_test/claude-workbench-test.js +170 -170
- package/_site/_test/codex-conversation-projection-test.js +2 -1
- package/_site/_test/commit-conversation-binding-test.js +95 -95
- package/_site/_test/commit-evidence-test.js +110 -110
- package/_site/_test/conversation-api-test.js +109 -109
- package/_site/_test/conversation-store-test.js +136 -136
- package/_site/_test/data-dir-migration-test.js +57 -57
- package/_site/_test/desktop-browser-compat-test.js +28 -28
- package/_site/_test/desktop-hook-runtime-regression-test.js +204 -204
- package/_site/_test/explicit-commit-processor-test.js +37 -37
- package/_site/_test/fixtures/make-git-repos.js +12 -1
- package/_site/_test/folder-picker-output-test.js +19 -19
- package/_site/_test/full-integration-e2e-test.js +165 -165
- package/_site/_test/git-validation-test.js +2 -2
- package/_site/_test/hook-runtime-endpoint-test.js +88 -88
- package/_site/_test/hook-status-repair-api-test.js +152 -152
- package/_site/_test/hook-trigger-test.js +85 -85
- package/_site/_test/import-preflight-api-test.js +234 -233
- package/_site/_test/index-writer-concurrency-test.js +135 -135
- package/_site/_test/integration-adapters-test.js +171 -171
- package/_site/_test/integration-surface-coverage-test.js +164 -164
- package/_site/_test/knowledge-language-control-test.js +170 -170
- package/_site/_test/knowledge-promotion-recovery-test.js +260 -260
- package/_site/_test/knowledge-query-test.js +54 -54
- package/_site/_test/knowledge-retrieval-service-test.js +77 -77
- package/_site/_test/knowledge-storage-startup-test.js +52 -52
- package/_site/_test/knowledge-store-logs-supervision-test.js +89 -89
- package/_site/_test/legacy-forward-compat-test.js +257 -257
- package/_site/_test/legacy-project-upgrade-e2e-test.js +363 -363
- package/_site/_test/logging-api-test.js +89 -89
- package/_site/_test/logging-sse-no-gap-test.js +88 -88
- package/_site/_test/logging-ui-test.js +106 -104
- package/_site/_test/markdown-delta-overlay-test.js +85 -85
- package/_site/_test/markdown-maintenance-api-test.js +75 -75
- package/_site/_test/mcp-server-test.js +149 -149
- package/_site/_test/module-artifact-integrity-test.js +27 -0
- package/_site/_test/module-boundary-test.js +30 -0
- package/_site/_test/module-bridge-eventbridge-test.js +7 -0
- package/_site/_test/module-model-configuration-test.js +43 -0
- package/_site/_test/module-process-lifecycle-test.js +24 -0
- package/_site/_test/module-stream-proxy-test.js +34 -0
- package/_site/_test/non-release-ci-test.js +34 -34
- package/_site/_test/offline-boundary-isolation-test.js +32 -32
- package/_site/_test/p0-data-migration-characterization-test.js +37 -37
- package/_site/_test/p0-e2e-gate-test.js +347 -347
- package/_site/_test/packaged-ui-smoke-test.js +11 -9
- package/_site/_test/path-consistency-test.js +151 -151
- package/_site/_test/pending-sweep-test.js +9 -9
- package/_site/_test/post-commit-automation-test.js +87 -87
- package/_site/_test/product-diagnostics-ui-test.js +75 -0
- package/_site/_test/product-import-ui-test.js +92 -0
- package/_site/_test/project-delete-recovery-test.js +64 -64
- package/_site/_test/project-goal-editor-test.js +144 -144
- package/_site/_test/project-layout-v2-migration-test.js +127 -127
- package/_site/_test/project-lifecycle-transaction-test.js +106 -106
- package/_site/_test/prompt-settings-test.js +115 -115
- package/_site/_test/protected-architecture-gate-test.js +122 -122
- package/_site/_test/refactor-characterization-test.js +36 -36
- package/_site/_test/release-version-sync-test.js +1 -1
- package/_site/_test/requirement-recorder-test.js +173 -173
- package/_site/_test/run-all-tests.js +159 -156
- package/_site/_test/server-runtime-migration-safety-test.js +27 -27
- package/_site/_test/shared-contracts-test.js +58 -58
- package/_site/_test/startup-analysis-disabled-test.js +10 -10
- package/_site/_test/storage-foundation-test.js +78 -78
- package/_site/_test/structured-logger-test.js +101 -101
- package/_site/_test/tracking-start-test.js +108 -108
- package/_site/_test/v4122-upgrade-data-contract-test.js +56 -56
- package/_site/_test/workbench-permission-test.js +117 -117
- package/_site/_test/workspace-ui-contract-test.js +28 -43
- package/_site/lib/ai-profile-resolver.js +78 -78
- package/_site/lib/ai-workspace.js +101 -101
- package/_site/lib/automation-config.js +140 -140
- package/_site/lib/bridge-adapter.js +1 -0
- package/_site/lib/bridge-consumer-service.js +402 -402
- package/_site/lib/claude-cli-runner.js +1510 -1510
- package/_site/lib/commit-conversation-binder.js +234 -234
- package/_site/lib/commit-processing-ledger.js +27 -27
- package/_site/lib/commit-prompt.js +202 -202
- package/_site/lib/commit-reconciler.js +406 -406
- package/_site/lib/contracts.js +284 -279
- package/_site/lib/conversation-query-service.js +144 -144
- package/_site/lib/conversation-store.js +385 -385
- package/_site/lib/data-dir.js +74 -74
- package/_site/lib/data-state-classifier.js +40 -40
- package/_site/lib/engine-cutover.js +97 -0
- package/_site/lib/evidence-bundle.js +228 -228
- package/_site/lib/folder-picker-output.js +21 -21
- package/_site/lib/git-runner.js +62 -62
- package/_site/lib/github-team-store.js +1172 -1172
- package/_site/lib/hook-manager.js +203 -202
- package/_site/lib/index-service.js +173 -173
- package/_site/lib/integration-installer.js +907 -907
- package/_site/lib/kb-framework.js +176 -176
- package/_site/lib/kb-validator.js +124 -124
- package/_site/lib/knowledge-promotion.js +435 -435
- package/_site/lib/knowledge-retrieval-service.js +401 -401
- package/_site/lib/knowledge-tool-runtime.js +359 -359
- package/_site/lib/legacy-data-manifest.js +26 -26
- package/_site/lib/llm-client.js +161 -161
- package/_site/lib/markdown-knowledge-indexer.js +230 -230
- package/_site/lib/migration-service.js +442 -442
- package/_site/lib/module-bridge.js +198 -33
- package/_site/lib/post-commit-automation.js +87 -87
- package/_site/lib/project-lifecycle-service.js +519 -497
- package/_site/lib/project-store.js +268 -262
- package/_site/lib/requirement-recorder.js +278 -278
- package/_site/lib/runtime-endpoint.js +155 -155
- package/_site/lib/scanner.js +298 -298
- package/_site/lib/server-app.js +1590 -1520
- package/_site/lib/settings-store.js +133 -113
- package/_site/lib/storage-layout.js +162 -162
- package/_site/lib/structured-logger.js +574 -574
- package/_site/scripts/folder-picker.ps1 +156 -156
- package/_site/scripts/hook-trigger.js +157 -156
- package/_site/scripts/install-module-candidates.js +69 -0
- package/_site/scripts/pack-module-candidates.js +72 -0
- package/_site/scripts/sync-release-version.js +2 -2
- package/_site/scripts/vendor-modules.js +47 -0
- package/_site/scripts/verify-module-runtime.js +45 -0
- package/_site/scripts/verify-product-runtime.js +34 -0
- package/bin/project-knowledge-mcp.js +194 -194
- package/docs/README.zh-CN.md +34 -25
- package/docs/project-registry-schema.md +22 -22
- package/docs/testing-strategy.md +33 -33
- package/module-runtime-manifest.json +220 -0
- package/package.json +13 -9
- 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/project-readme.md +34 -34
- package/ui/favicon.svg +38 -38
- package/ui/index.html +51 -149
- package/ui/product.css +9 -0
- package/ui/product.js +386 -0
- package/vendor-manifest.json +46 -0
- package/_site/_test/import-ui-flow-test.js +0 -171
- package/_site/_test/project-control-panel-task14-test.js +0 -63
- package/_site/_test/task15-20-ui-flow-test.js +0 -148
- package/_site/_test/ui-i18n-toggle-test.js +0 -114
- package/_site/_test/ui-smoke-test.js +0 -73
- package/ui/app.css +0 -58
- package/ui/app.js +0 -607
- package/ui/i18n.js +0 -146
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
const SCHEMAS = Object.freeze({
|
|
4
|
+
settings: 'settings/v2',
|
|
5
|
+
projectRegistry: 'project-registry/v2',
|
|
6
|
+
projectConfig: 'project-config/v2',
|
|
7
|
+
projectState: 'project-state/v2',
|
|
8
|
+
requirement: 'requirement/v1',
|
|
9
|
+
aiCodingEvent: 'ai-coding-event/v1',
|
|
10
|
+
gitCommitBoundary: 'git-commit-boundary/v1',
|
|
11
|
+
commitConversationSnapshot: 'commit-conversation-snapshot/v1',
|
|
12
|
+
commitClaim: 'commit-claim/v1',
|
|
13
|
+
promotionJournal: 'promotion-journal/v1',
|
|
14
|
+
migrationJournal: 'migration-journal/v1',
|
|
15
|
+
log: 'log/v2',
|
|
16
|
+
hookEvent: 'hook-event/v2',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const SCHEMA_VERSIONS = Object.freeze({
|
|
20
|
+
settings: 2,
|
|
21
|
+
projectRegistry: 2,
|
|
22
|
+
projectConfig: 2,
|
|
23
|
+
projectState: 2,
|
|
24
|
+
hookManaged: 2,
|
|
25
|
+
layoutMigration: 'layout-v2',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const TRIGGERS = Object.freeze(['git-hook']);
|
|
29
|
+
const TRIGGER_SET = new Set(TRIGGERS);
|
|
30
|
+
const LOG_LEVELS = Object.freeze(['trace', 'debug', 'info', 'warn', 'error', 'fatal']);
|
|
31
|
+
const LOG_LEVEL_SET = new Set(LOG_LEVELS);
|
|
32
|
+
const ANALYSIS_PHASES = Object.freeze([
|
|
33
|
+
'idle',
|
|
34
|
+
'scanning',
|
|
35
|
+
'claim.created',
|
|
36
|
+
'requirement.bound',
|
|
37
|
+
'evidence.prepared',
|
|
38
|
+
'ai.running',
|
|
39
|
+
'output.validated',
|
|
40
|
+
'promotion.prepared',
|
|
41
|
+
'markdown.promoted',
|
|
42
|
+
'state.advanced',
|
|
43
|
+
'index.queued',
|
|
44
|
+
'index.applied',
|
|
45
|
+
'history-diverged',
|
|
46
|
+
'failed',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const ERROR_CODES = Object.freeze([
|
|
50
|
+
'INVALID_ARGUMENT',
|
|
51
|
+
'INVALID_TRIGGER',
|
|
52
|
+
'SCHEMA_UNSUPPORTED',
|
|
53
|
+
'DATA_CORRUPT',
|
|
54
|
+
'IMMUTABLE_FIELD',
|
|
55
|
+
'PROJECT_BUSY',
|
|
56
|
+
'PROJECT_NOT_FOUND',
|
|
57
|
+
'PROJECT_AMBIGUOUS',
|
|
58
|
+
'HOOK_CONFLICT',
|
|
59
|
+
'HOOK_INVALID',
|
|
60
|
+
'HISTORY_DIVERGED',
|
|
61
|
+
'MIGRATION_SOURCE_CHANGED',
|
|
62
|
+
'MIGRATION_TARGET_CONFLICT',
|
|
63
|
+
'MIGRATION_FAILED',
|
|
64
|
+
'PATH_OUTSIDE_ROOT',
|
|
65
|
+
'AUTH_REQUIRED',
|
|
66
|
+
'ORIGIN_FORBIDDEN',
|
|
67
|
+
'LOGGER_UNAVAILABLE',
|
|
68
|
+
'LOG_CURSOR_EXPIRED',
|
|
69
|
+
'EVIDENCE_INTEGRITY_FAILED',
|
|
70
|
+
'AI_PROFILE_REQUIRED',
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
const IMMUTABLE_PROJECT_FIELDS = Object.freeze([
|
|
74
|
+
'schema',
|
|
75
|
+
'schemaVersion',
|
|
76
|
+
'projectId',
|
|
77
|
+
'storageName',
|
|
78
|
+
'createdAt',
|
|
79
|
+
'knowledgePath',
|
|
80
|
+
]);
|
|
81
|
+
const MUTABLE_PROJECT_FIELDS = Object.freeze([
|
|
82
|
+
'displayName',
|
|
83
|
+
'enabled',
|
|
84
|
+
'aiProfileId',
|
|
85
|
+
'knowledgeLanguage',
|
|
86
|
+
'relatedProjectIds',
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const REDACTED_VALUE = '[REDACTED]';
|
|
90
|
+
const REDACTION_KEY_PATTERN = /(?:api[-_]?key|auth(?:orization|token)?|access[-_]?token|refresh[-_]?token|bearer|password|passwd|secret|client[-_]?secret|private[-_]?key|cookie|set-cookie)/i;
|
|
91
|
+
const FIELD_LIMITS = Object.freeze({
|
|
92
|
+
message: 4096,
|
|
93
|
+
stack: 16384,
|
|
94
|
+
path: 4096,
|
|
95
|
+
contextString: 8192,
|
|
96
|
+
requirement: 131072,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
class DomainError extends Error {
|
|
100
|
+
constructor(code, message, options = {}) {
|
|
101
|
+
super(String(message || code || 'Domain error'), options.cause ? { cause: options.cause } : undefined);
|
|
102
|
+
this.name = 'DomainError';
|
|
103
|
+
this.code = ERROR_CODES.includes(code) ? code : 'INVALID_ARGUMENT';
|
|
104
|
+
this.status = Number.isInteger(options.status) ? options.status : 400;
|
|
105
|
+
this.retryable = options.retryable === true;
|
|
106
|
+
this.operationId = options.operationId || '';
|
|
107
|
+
this.details = sanitizePublicDetails(options.details);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function createId(prefix) {
|
|
112
|
+
const base = typeof crypto.randomUUID === 'function'
|
|
113
|
+
? crypto.randomUUID().replace(/-/g, '')
|
|
114
|
+
: crypto.randomBytes(16).toString('hex');
|
|
115
|
+
return `${prefix}-${base}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function assertSchema(actual, expected, category = 'data') {
|
|
119
|
+
if (actual !== expected) {
|
|
120
|
+
throw new DomainError('SCHEMA_UNSUPPORTED', `Unsupported ${category} schema.`, {
|
|
121
|
+
status: 409,
|
|
122
|
+
details: { category, expected, actual: String(actual || '') },
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function validateTrigger(trigger) {
|
|
129
|
+
if (!TRIGGER_SET.has(trigger)) {
|
|
130
|
+
throw new DomainError('INVALID_TRIGGER', 'Trigger must be git-hook.', {
|
|
131
|
+
details: { trigger: String(trigger || '') },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return trigger;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function validateLogLevel(level) {
|
|
138
|
+
if (!LOG_LEVEL_SET.has(level)) {
|
|
139
|
+
throw new DomainError('INVALID_ARGUMENT', 'Invalid log level.', {
|
|
140
|
+
details: { level: String(level || '') },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return level;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function validateProjectId(projectId) {
|
|
147
|
+
const value = String(projectId || '');
|
|
148
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{2,127}$/.test(value)) {
|
|
149
|
+
throw new DomainError('INVALID_ARGUMENT', 'Invalid projectId.');
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function validateStateTransition(from, to) {
|
|
155
|
+
if (!ANALYSIS_PHASES.includes(from) || !ANALYSIS_PHASES.includes(to)) {
|
|
156
|
+
throw new DomainError('INVALID_ARGUMENT', 'Unknown analysis phase.', { details: { from, to } });
|
|
157
|
+
}
|
|
158
|
+
if (from === to) return true;
|
|
159
|
+
const allowed = {
|
|
160
|
+
idle: ['scanning', 'index.queued', 'failed'],
|
|
161
|
+
scanning: ['claim.created', 'idle', 'history-diverged', 'failed'],
|
|
162
|
+
'claim.created': ['requirement.bound', 'failed'],
|
|
163
|
+
'requirement.bound': ['evidence.prepared', 'failed'],
|
|
164
|
+
'evidence.prepared': ['ai.running', 'failed'],
|
|
165
|
+
'ai.running': ['output.validated', 'failed'],
|
|
166
|
+
'output.validated': ['promotion.prepared', 'failed'],
|
|
167
|
+
'promotion.prepared': ['markdown.promoted', 'failed'],
|
|
168
|
+
'markdown.promoted': ['state.advanced', 'failed'],
|
|
169
|
+
'state.advanced': ['index.queued', 'scanning', 'idle', 'failed'],
|
|
170
|
+
'index.queued': ['index.applied', 'failed'],
|
|
171
|
+
'index.applied': ['idle', 'scanning'],
|
|
172
|
+
'history-diverged': ['scanning', 'idle'],
|
|
173
|
+
failed: ['scanning', 'ai.running', 'promotion.prepared', 'index.queued', 'idle'],
|
|
174
|
+
};
|
|
175
|
+
if (!(allowed[from] || []).includes(to)) {
|
|
176
|
+
throw new DomainError('INVALID_ARGUMENT', `Invalid analysis transition: ${from} -> ${to}.`, {
|
|
177
|
+
details: { from, to },
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function sanitizePublicDetails(value, seen = new WeakSet()) {
|
|
184
|
+
if (value == null || typeof value === 'boolean' || typeof value === 'number') return value;
|
|
185
|
+
if (typeof value === 'string') return value.slice(0, FIELD_LIMITS.contextString);
|
|
186
|
+
if (value instanceof Error) return { name: value.name, code: value.code || '', message: String(value.message || '').slice(0, FIELD_LIMITS.message) };
|
|
187
|
+
if (typeof value !== 'object') return String(value).slice(0, FIELD_LIMITS.contextString);
|
|
188
|
+
if (seen.has(value)) return '[Circular]';
|
|
189
|
+
seen.add(value);
|
|
190
|
+
if (Array.isArray(value)) return value.slice(0, 100).map(item => sanitizePublicDetails(item, seen));
|
|
191
|
+
const out = {};
|
|
192
|
+
for (const [key, child] of Object.entries(value)) {
|
|
193
|
+
if (REDACTION_KEY_PATTERN.test(key) || /stack/i.test(key) || /prompt|diff|header/i.test(key)) {
|
|
194
|
+
continue;
|
|
195
|
+
} else {
|
|
196
|
+
out[key] = sanitizePublicDetails(child, seen);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function serializeErrorEnvelope(error, operationId = '') {
|
|
203
|
+
const source = error instanceof DomainError
|
|
204
|
+
? error
|
|
205
|
+
: new DomainError('INVALID_ARGUMENT', 'The operation failed.', { status: 500, operationId });
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
error: {
|
|
209
|
+
code: source.code,
|
|
210
|
+
message: source.message,
|
|
211
|
+
operationId: source.operationId || operationId || '',
|
|
212
|
+
retryable: source.retryable === true,
|
|
213
|
+
details: sanitizePublicDetails(source.details || {}),
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function publicAiProfileView(profile) {
|
|
219
|
+
const source = profile && typeof profile === 'object' ? profile : {};
|
|
220
|
+
const secret = source.apiKey || source.authToken || source.anthropicAuthToken || '';
|
|
221
|
+
const publicView = {};
|
|
222
|
+
for (const [key, value] of Object.entries(source)) {
|
|
223
|
+
if (REDACTION_KEY_PATTERN.test(key)) continue;
|
|
224
|
+
publicView[key] = value;
|
|
225
|
+
}
|
|
226
|
+
publicView.hasApiKey = Boolean(secret);
|
|
227
|
+
publicView.apiKeyMasked = secret ? `****${String(secret).slice(-4)}` : '';
|
|
228
|
+
return publicView;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function publicAiProfilesConfig(config) {
|
|
232
|
+
const source = config && typeof config === 'object' ? config : {};
|
|
233
|
+
return {
|
|
234
|
+
...source,
|
|
235
|
+
profiles: Array.isArray(source.profiles) ? source.profiles.map(publicAiProfileView) : [],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function assertMutableProjectPatch(patch, options = {}) {
|
|
240
|
+
const allowKnowledgePath = options.allowKnowledgePath === true;
|
|
241
|
+
const allowRepoPath = options.allowRepoPath === true;
|
|
242
|
+
for (const key of Object.keys(patch && typeof patch === 'object' ? patch : {})) {
|
|
243
|
+
if (IMMUTABLE_PROJECT_FIELDS.includes(key) && !(allowKnowledgePath && key === 'knowledgePath')) {
|
|
244
|
+
throw new DomainError('IMMUTABLE_FIELD', `Project field is immutable: ${key}.`, { status: 409, details: { field: key } });
|
|
245
|
+
}
|
|
246
|
+
if (!MUTABLE_PROJECT_FIELDS.includes(key)
|
|
247
|
+
&& !(allowKnowledgePath && key === 'knowledgePath')
|
|
248
|
+
&& !(allowRepoPath && key === 'repoPath')) {
|
|
249
|
+
throw new DomainError('INVALID_ARGUMENT', `Unknown project field: ${key}.`, { details: { field: key } });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
module.exports = {
|
|
256
|
+
SCHEMAS,
|
|
257
|
+
SCHEMA_VERSIONS,
|
|
258
|
+
TRIGGERS,
|
|
259
|
+
LOG_LEVELS,
|
|
260
|
+
ANALYSIS_PHASES,
|
|
261
|
+
ERROR_CODES,
|
|
262
|
+
IMMUTABLE_PROJECT_FIELDS,
|
|
263
|
+
MUTABLE_PROJECT_FIELDS,
|
|
264
|
+
REDACTED_VALUE,
|
|
265
|
+
REDACTION_KEY_PATTERN,
|
|
266
|
+
FIELD_LIMITS,
|
|
267
|
+
DomainError,
|
|
268
|
+
createId,
|
|
269
|
+
assertSchema,
|
|
270
|
+
validateTrigger,
|
|
271
|
+
validateLogLevel,
|
|
272
|
+
validateProjectId,
|
|
273
|
+
validateStateTransition,
|
|
274
|
+
sanitizePublicDetails,
|
|
275
|
+
serializeErrorEnvelope,
|
|
276
|
+
publicAiProfileView,
|
|
277
|
+
publicAiProfilesConfig,
|
|
278
|
+
assertMutableProjectPatch,
|
|
279
|
+
};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { validateProjectId } = require('./contracts');
|
|
4
|
+
const AtomicFile = require('./atomic-file');
|
|
5
|
+
|
|
6
|
+
const EXCLUSION_SCHEMA = 'conversation-exclusions/v1';
|
|
7
|
+
const EMBEDDED_ASSISTANT_PREFIX = 'embedded-assistant-';
|
|
8
|
+
const EXPLICIT_PREFIX = 'explicit-';
|
|
9
|
+
const CODEX_CONTEXT_TAGS = new Set([
|
|
10
|
+
'recommended_plugins',
|
|
11
|
+
'environment_context',
|
|
12
|
+
'in-app-browser-context',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* T17: legacy embedded Workbench capture exclusion.
|
|
17
|
+
*
|
|
18
|
+
* Old builds wrote internal Workbench conversations into Development
|
|
19
|
+
* Conversation as `explicit-<requirementId>` + `embedded-assistant-<requirementId>`
|
|
20
|
+
* pairs (rawEventType embedded-claude-result). Those events are excluded from
|
|
21
|
+
* Development Conversation presentation and from NEW commit binding. Nothing
|
|
22
|
+
* is deleted: the JSONL lines stay, immutable snapshots stay untouched, and a
|
|
23
|
+
* manifest is persisted for auditability. A genuine explicit MCP requirement
|
|
24
|
+
* (no embedded-assistant pair) is never excluded.
|
|
25
|
+
*/
|
|
26
|
+
function isEmbeddedAssistantEvent(event) {
|
|
27
|
+
if (!event) return false;
|
|
28
|
+
return String(event.eventId || '').startsWith(EMBEDDED_ASSISTANT_PREFIX)
|
|
29
|
+
|| event.rawEventType === 'embedded-claude-result';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Codex rollout files contain generated context records with role=user. They
|
|
34
|
+
* are transport/control data, not user-authored prompts. Match only complete,
|
|
35
|
+
* known envelopes so ordinary prompts containing similar text survive.
|
|
36
|
+
*/
|
|
37
|
+
function isCodexControlUserEvent(event) {
|
|
38
|
+
if (!event || event.source !== 'codex' || event.role !== 'user' || event.rawEventType !== 'response_item') return false;
|
|
39
|
+
let remaining = String(event.content || '').trim();
|
|
40
|
+
if (/^<turn_aborted>\s*[\s\S]*?\s*<\/turn_aborted>$/.test(remaining)) return true;
|
|
41
|
+
|
|
42
|
+
let removed = false;
|
|
43
|
+
const envelope = /^<([A-Za-z0-9_-]+)(?:\s[^>]*)?>[\s\S]*?<\/\1>\s*/;
|
|
44
|
+
while (remaining) {
|
|
45
|
+
const match = remaining.match(envelope);
|
|
46
|
+
if (!match || !CODEX_CONTEXT_TAGS.has(match[1])) break;
|
|
47
|
+
remaining = remaining.slice(match[0].length).trimStart();
|
|
48
|
+
removed = true;
|
|
49
|
+
}
|
|
50
|
+
return removed && remaining.trim() === '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isCodexAbortEvent(event) {
|
|
54
|
+
return isCodexControlUserEvent(event)
|
|
55
|
+
&& /^<turn_aborted>/.test(String(event.content || '').trim());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function computeConversationExclusions(projectId, events) {
|
|
59
|
+
validateProjectId(projectId);
|
|
60
|
+
const paired = new Set();
|
|
61
|
+
for (const event of events || []) {
|
|
62
|
+
const eventId = String((event && event.eventId) || '');
|
|
63
|
+
if (eventId.startsWith(EMBEDDED_ASSISTANT_PREFIX)) {
|
|
64
|
+
paired.add(eventId.slice(EMBEDDED_ASSISTANT_PREFIX.length));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const excludedEventIds = [];
|
|
68
|
+
for (const event of events || []) {
|
|
69
|
+
if (!event) continue;
|
|
70
|
+
const eventId = String(event.eventId || '');
|
|
71
|
+
if (isEmbeddedAssistantEvent(event)) {
|
|
72
|
+
excludedEventIds.push(eventId);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (isCodexControlUserEvent(event)) {
|
|
76
|
+
excludedEventIds.push(eventId);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (eventId.startsWith(EXPLICIT_PREFIX) && paired.has(eventId.slice(EXPLICIT_PREFIX.length))) {
|
|
80
|
+
excludedEventIds.push(eventId);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
schema: EXCLUSION_SCHEMA,
|
|
85
|
+
projectId,
|
|
86
|
+
excludedEventIds: [...new Set(excludedEventIds)].sort(),
|
|
87
|
+
generatedAt: new Date().toISOString(),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function eventOrder(left, right) {
|
|
92
|
+
if (Number.isInteger(left.sequence) && Number.isInteger(right.sequence)) return left.sequence - right.sequence;
|
|
93
|
+
if (Number.isInteger(left.sequence)) return -1;
|
|
94
|
+
if (Number.isInteger(right.sequence)) return 1;
|
|
95
|
+
return String(left.capturedAt || '').localeCompare(String(right.capturedAt || ''))
|
|
96
|
+
|| String(left.eventId || '').localeCompare(String(right.eventId || ''));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Bridge 0.1.1 did not read Codex's nested turn id, so historical assistant
|
|
101
|
+
* response_item records have turnId=null while each user record received a
|
|
102
|
+
* generated id. Repair that projection without rewriting the append-only
|
|
103
|
+
* JSONL: orphan assistants attach to the latest real user in the same Codex
|
|
104
|
+
* session. A later real prompt or turn_aborted record closes that projected
|
|
105
|
+
* turn, which also lets commit binding ignore stale Bridge open-turn facts.
|
|
106
|
+
*/
|
|
107
|
+
function projectCodexTurns(events, excludedEventIds) {
|
|
108
|
+
const excluded = new Set(excludedEventIds || []);
|
|
109
|
+
const activeBySession = new Map();
|
|
110
|
+
const closedAtByTurn = new Map();
|
|
111
|
+
const projected = [];
|
|
112
|
+
const ordered = [...(events || [])].sort(eventOrder);
|
|
113
|
+
const sessionKey = event => event && event.source === 'codex' && event.sessionId
|
|
114
|
+
? `codex\n${event.sessionId}`
|
|
115
|
+
: null;
|
|
116
|
+
|
|
117
|
+
for (const original of ordered) {
|
|
118
|
+
const eventId = String((original && original.eventId) || '');
|
|
119
|
+
const key = sessionKey(original || {});
|
|
120
|
+
if (excluded.has(eventId)) {
|
|
121
|
+
if (key && isCodexAbortEvent(original)) {
|
|
122
|
+
const active = activeBySession.get(key);
|
|
123
|
+
if (active && Number.isInteger(original.sequence)) closedAtByTurn.set(active, original.sequence);
|
|
124
|
+
activeBySession.delete(key);
|
|
125
|
+
}
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let event = original;
|
|
130
|
+
if (key && original && original.source === 'codex' && original.role === 'user' && original.turnId) {
|
|
131
|
+
const previous = activeBySession.get(key);
|
|
132
|
+
if (previous && previous !== original.turnId && Number.isInteger(original.sequence)) {
|
|
133
|
+
closedAtByTurn.set(previous, original.sequence);
|
|
134
|
+
}
|
|
135
|
+
activeBySession.set(key, original.turnId);
|
|
136
|
+
} else if (key && original && original.source === 'codex' && original.role === 'assistant' && !original.turnId) {
|
|
137
|
+
const active = activeBySession.get(key);
|
|
138
|
+
if (active) event = { ...original, turnId: active };
|
|
139
|
+
}
|
|
140
|
+
projected.push(event);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return projected.map(event => {
|
|
144
|
+
const closedAt = event && event.turnId ? closedAtByTurn.get(event.turnId) : null;
|
|
145
|
+
return Number.isInteger(closedAt)
|
|
146
|
+
? { ...event, developmentTurnClosedAtSequence: closedAt }
|
|
147
|
+
: event;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function manifestPath(layout, projectId) {
|
|
152
|
+
return path.join(layout.getProjectMetadataDir(projectId), 'conversation-exclusions.json');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function readManifest(layout, projectId) {
|
|
156
|
+
try {
|
|
157
|
+
return AtomicFile.readJsonStrict(manifestPath(layout, projectId), {
|
|
158
|
+
category: 'conversation-exclusions',
|
|
159
|
+
validate: value => value,
|
|
160
|
+
});
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Single source of truth for Development Conversation reads: applies durable
|
|
168
|
+
* exclusions and the non-destructive Codex turn compatibility projection for
|
|
169
|
+
* both Conversation Explorer and new CommitConversationBinder runs. The
|
|
170
|
+
* manifest is refreshed idempotently (best effort) so operators can audit
|
|
171
|
+
* what is excluded; read failures never break the read itself.
|
|
172
|
+
*/
|
|
173
|
+
function readDevelopmentEvents(conversationStore, projectId) {
|
|
174
|
+
const events = conversationStore.readEvents(projectId);
|
|
175
|
+
const manifest = computeConversationExclusions(projectId, events);
|
|
176
|
+
if (manifest.excludedEventIds.length) {
|
|
177
|
+
try {
|
|
178
|
+
const layout = conversationStore.layout;
|
|
179
|
+
const dir = layout.getProjectMetadataDir(projectId);
|
|
180
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
181
|
+
const previous = readManifest(layout, projectId);
|
|
182
|
+
const unchanged = previous
|
|
183
|
+
&& Array.isArray(previous.excludedEventIds)
|
|
184
|
+
&& previous.excludedEventIds.length === manifest.excludedEventIds.length
|
|
185
|
+
&& previous.excludedEventIds.every((id, index) => id === manifest.excludedEventIds[index]);
|
|
186
|
+
if (!unchanged) {
|
|
187
|
+
(conversationStore.atomic || AtomicFile).writeJsonAtomic(manifestPath(layout, projectId), manifest);
|
|
188
|
+
}
|
|
189
|
+
} catch {
|
|
190
|
+
// Manifest persistence is best effort; exclusion itself is computed
|
|
191
|
+
// deterministically from the durable events on every read.
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return projectCodexTurns(events, manifest.excludedEventIds);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
module.exports = {
|
|
198
|
+
EXCLUSION_SCHEMA,
|
|
199
|
+
isEmbeddedAssistantEvent,
|
|
200
|
+
isCodexControlUserEvent,
|
|
201
|
+
computeConversationExclusions,
|
|
202
|
+
projectCodexTurns,
|
|
203
|
+
readDevelopmentEvents,
|
|
204
|
+
};
|