@sanqianx/project-knowledge 4.6.1 → 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 -780
- 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/bridge-adapter-test.js +1 -1
- package/_site/_test/bridge-consumer-service-test.js +1 -1
- 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/client-capture-restart-e2e-test.js +4 -4
- package/_site/_test/codex-conversation-projection-test.js +2 -1
- package/_site/_test/commit-boundary-freeze-test.js +1 -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/cross-repo-isolation-e2e-test.js +2 -2
- 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-capture-setup-test.js +1 -1
- 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 +19 -10
- 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 +5 -1
- 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 -10
- 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
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
// Claude workbench regression test.
|
|
2
|
-
//
|
|
3
|
-
// Verifies session metadata and the SDK-only session lifecycle. The legacy
|
|
4
|
-
// `claude -p` subprocess path was removed in the CC-Switch migration, so
|
|
5
|
-
// the pre-turn `requirePermission` flow no longer exists — the SDK path
|
|
6
|
-
// shows permission prompts via canUseTool only when an individual tool
|
|
7
|
-
// is actually invoked. Tool-level prompts are exercised by the chat
|
|
8
|
-
// panel integration tests.
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const runner = require('../lib/claude-cli-runner');
|
|
13
|
-
|
|
14
|
-
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
-
const TEMP_KB = path.join(ROOT, 'projects', 'claude-workbench-test-temp');
|
|
16
|
-
const TEMP_AI = path.join(ROOT, '_site', '_ai', 'claude-workbench-test-temp');
|
|
17
|
-
|
|
18
|
-
function assert(cond, msg) {
|
|
19
|
-
if (!cond) throw new Error(msg);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
(async () => {
|
|
23
|
-
fs.rmSync(TEMP_KB, { recursive: true, force: true });
|
|
24
|
-
fs.rmSync(TEMP_AI, { recursive: true, force: true });
|
|
25
|
-
fs.mkdirSync(TEMP_KB, { recursive: true });
|
|
26
|
-
|
|
27
|
-
// 1. Default initial-analysis turn: SDK is the only mode. The session
|
|
28
|
-
// should be created without any pre-turn permission prompt (the
|
|
29
|
-
// SDK surfaces tool approvals lazily through canUseTool).
|
|
30
|
-
const started = runner.startSession({
|
|
31
|
-
slug: 'claude-workbench-test-temp',
|
|
32
|
-
projectPath: ROOT,
|
|
33
|
-
kbPath: TEMP_KB,
|
|
34
|
-
promptKey: 'initial-analysis',
|
|
35
|
-
aiProfile: {
|
|
36
|
-
id: 'test-profile',
|
|
37
|
-
implementation: 'claude-code-agent',
|
|
38
|
-
mainModel: 'test-model',
|
|
39
|
-
},
|
|
40
|
-
vars: {
|
|
41
|
-
SLUG: 'claude-workbench-test-temp',
|
|
42
|
-
PROJECT_PATH: ROOT,
|
|
43
|
-
PRIMARY_LANGUAGE: 'JavaScript',
|
|
44
|
-
KNOWLEDGE_LANGUAGE: 'zh-CN',
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
assert(started.sessionId, 'startSession should return sessionId');
|
|
49
|
-
assert(!started.pendingPermission,
|
|
50
|
-
'SDK mode should not show a pre-turn UI permission prompt');
|
|
51
|
-
assert(started.runner === 'sdk',
|
|
52
|
-
`startSession should default to runner: 'sdk', got ${started.runner}`);
|
|
53
|
-
|
|
54
|
-
const state = runner.getState(started.sessionId);
|
|
55
|
-
assert(state.runner === 'sdk',
|
|
56
|
-
`session state should record runner: 'sdk', got ${state.runner}`);
|
|
57
|
-
|
|
58
|
-
runner.deleteSession(started.sessionId);
|
|
59
|
-
|
|
60
|
-
// 1b. The embedded terminal should be able to create an idle chat
|
|
61
|
-
// session without reading claude-prompts.json or running an
|
|
62
|
-
// initial-analysis prompt. The user's first typed message starts
|
|
63
|
-
// the actual SDK turn via sendInput.
|
|
64
|
-
const chat = runner.startChatSession({
|
|
65
|
-
slug: 'claude-workbench-test-temp',
|
|
66
|
-
projectPath: ROOT,
|
|
67
|
-
kbPath: TEMP_KB,
|
|
68
|
-
aiProfile: {
|
|
69
|
-
id: 'test-profile',
|
|
70
|
-
implementation: 'claude-code-agent',
|
|
71
|
-
mainModel: 'test-model',
|
|
72
|
-
},
|
|
73
|
-
permissionMode: 'default',
|
|
74
|
-
});
|
|
75
|
-
assert(chat.sessionId, 'startChatSession should return sessionId');
|
|
76
|
-
const chatState = runner.getState(chat.sessionId);
|
|
77
|
-
assert(chatState.promptKey === 'terminal-chat',
|
|
78
|
-
`chat session should use terminal-chat promptKey, got ${chatState.promptKey}`);
|
|
79
|
-
assert(chatState.state === 'idle',
|
|
80
|
-
`chat session should stay idle until user input, got ${chatState.state}`);
|
|
81
|
-
assert(chatState.turns === 0, `chat session should not start a turn, got turns=${chatState.turns}`);
|
|
82
|
-
|
|
83
|
-
// 1c. Switching AI profiles mid-session must not resume the old upstream
|
|
84
|
-
// Claude conversation with the new provider. That used to send the
|
|
85
|
-
// previous model (for example MiniMax-M3) to the new base URL (for
|
|
86
|
-
// example GLM), producing "model not found" API errors.
|
|
87
|
-
const chatSession = runner.getSession(chat.sessionId);
|
|
88
|
-
chatSession.aiProfileId = 'minimax-m3';
|
|
89
|
-
chatSession.model = 'MiniMax-M3';
|
|
90
|
-
chatSession.claudeSessionId = 'old-claude-session-id';
|
|
91
|
-
const switched = runner.applyAiProfileToSession(chatSession, {
|
|
92
|
-
id: 'glm',
|
|
93
|
-
implementation: 'claude-code-agent',
|
|
94
|
-
mainModel: 'glm-5.2',
|
|
95
|
-
});
|
|
96
|
-
const switchedState = runner.getState(chat.sessionId);
|
|
97
|
-
assert(switched.resetConversation === true, 'profile switch should reset the upstream conversation');
|
|
98
|
-
assert(switchedState.claudeSessionId === null, 'profile switch should clear stale claudeSessionId');
|
|
99
|
-
assert(switchedState.aiProfileId === 'glm', `profile switch should update aiProfileId, got ${switchedState.aiProfileId}`);
|
|
100
|
-
assert(switchedState.model === 'glm-5.2', `profile switch should update model, got ${switchedState.model}`);
|
|
101
|
-
runner.deleteSession(chat.sessionId);
|
|
102
|
-
|
|
103
|
-
// Session metadata uses durable atomic replacement, but a disk fault must
|
|
104
|
-
// remain fail-open for the live Workbench session and become observable.
|
|
105
|
-
const AtomicFile = require('../lib/atomic-file');
|
|
106
|
-
const originalAtomicWrite = AtomicFile.writeJsonAtomic;
|
|
107
|
-
const persistenceLogs = [];
|
|
108
|
-
runner.setLogger({ error: async (event, message, payload) => { persistenceLogs.push({ event, message, payload }); } });
|
|
109
|
-
AtomicFile.writeJsonAtomic = () => { throw Object.assign(new Error('simulated disk full'), { code: 'ENOSPC' }); };
|
|
110
|
-
let persistenceFaultSession;
|
|
111
|
-
try {
|
|
112
|
-
persistenceFaultSession = runner.createSession({
|
|
113
|
-
projectSlug: 'claude-workbench-test-temp', projectPath: ROOT, kbPath: TEMP_KB, promptKey: 'terminal-chat',
|
|
114
|
-
});
|
|
115
|
-
assert(persistenceFaultSession.sessionId, 'persistence failure must not interrupt the live session');
|
|
116
|
-
assert(persistenceLogs.some(entry => entry.event === 'claude.session_persist_failed' && entry.payload.error.code === 'ENOSPC'), 'persistence failure must be structured and correlated');
|
|
117
|
-
} finally {
|
|
118
|
-
AtomicFile.writeJsonAtomic = originalAtomicWrite;
|
|
119
|
-
runner.setLogger(null);
|
|
120
|
-
if (persistenceFaultSession) runner.deleteSession(persistenceFaultSession.sessionId);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const executable = await runner.findClaudeExecutableForSdk();
|
|
124
|
-
if (process.platform === 'win32' && executable.cmd) {
|
|
125
|
-
assert(!/\.(cmd|bat|ps1)$/i.test(executable.cmd),
|
|
126
|
-
`SDK executable must not be a Windows shell shim: ${executable.cmd}`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// 2. Automation raw prompt sessions must preserve the selected permission
|
|
130
|
-
// mode. This guards against regressing back to bypassPermissions -> default.
|
|
131
|
-
process.env.KB_AUTOMATION_FAKE_CLAUDE = '1';
|
|
132
|
-
const auto = runner.startAutomationSession({
|
|
133
|
-
slug: 'claude-workbench-test-temp',
|
|
134
|
-
projectPath: ROOT,
|
|
135
|
-
kbPath: TEMP_KB,
|
|
136
|
-
userPrompt: 'automation test prompt',
|
|
137
|
-
systemPrompt: 'automation system prompt',
|
|
138
|
-
aiProfile: {
|
|
139
|
-
id: 'test-profile',
|
|
140
|
-
implementation: 'claude-code-agent',
|
|
141
|
-
mainModel: 'test-model',
|
|
142
|
-
},
|
|
143
|
-
permissionMode: 'bypassPermissions',
|
|
144
|
-
allowedTools: ['Read'],
|
|
145
|
-
safetyPolicy: {
|
|
146
|
-
kind: 'kb-automation',
|
|
147
|
-
kbPath: TEMP_KB,
|
|
148
|
-
knowledgeMode: 'requestApproval',
|
|
149
|
-
allowReadOnlyBash: false,
|
|
150
|
-
allowedTools: ['Read'],
|
|
151
|
-
canWriteKb: false,
|
|
152
|
-
},
|
|
153
|
-
metadata: { automation: true, automationRunId: 'auto-test', source: 'test' },
|
|
154
|
-
});
|
|
155
|
-
const autoState = runner.getState(auto.sessionId);
|
|
156
|
-
assert(autoState.permissionMode === 'bypassPermissions',
|
|
157
|
-
`automation session should preserve bypassPermissions, got ${autoState.permissionMode}`);
|
|
158
|
-
assert(autoState.automation === true, 'automation session should be marked automation=true');
|
|
159
|
-
runner.deleteSession(auto.sessionId);
|
|
160
|
-
delete process.env.KB_AUTOMATION_FAKE_CLAUDE;
|
|
161
|
-
|
|
162
|
-
fs.rmSync(TEMP_KB, { recursive: true, force: true });
|
|
163
|
-
fs.rmSync(TEMP_AI, { recursive: true, force: true });
|
|
164
|
-
console.log('Claude workbench test passed');
|
|
165
|
-
})().catch(err => {
|
|
166
|
-
try { fs.rmSync(TEMP_KB, { recursive: true, force: true }); } catch {}
|
|
167
|
-
try { fs.rmSync(TEMP_AI, { recursive: true, force: true }); } catch {}
|
|
168
|
-
console.error(err);
|
|
169
|
-
process.exit(1);
|
|
170
|
-
});
|
|
1
|
+
// Claude workbench regression test.
|
|
2
|
+
//
|
|
3
|
+
// Verifies session metadata and the SDK-only session lifecycle. The legacy
|
|
4
|
+
// `claude -p` subprocess path was removed in the CC-Switch migration, so
|
|
5
|
+
// the pre-turn `requirePermission` flow no longer exists — the SDK path
|
|
6
|
+
// shows permission prompts via canUseTool only when an individual tool
|
|
7
|
+
// is actually invoked. Tool-level prompts are exercised by the chat
|
|
8
|
+
// panel integration tests.
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const runner = require('../lib/claude-cli-runner');
|
|
13
|
+
|
|
14
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
+
const TEMP_KB = path.join(ROOT, 'projects', 'claude-workbench-test-temp');
|
|
16
|
+
const TEMP_AI = path.join(ROOT, '_site', '_ai', 'claude-workbench-test-temp');
|
|
17
|
+
|
|
18
|
+
function assert(cond, msg) {
|
|
19
|
+
if (!cond) throw new Error(msg);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
(async () => {
|
|
23
|
+
fs.rmSync(TEMP_KB, { recursive: true, force: true });
|
|
24
|
+
fs.rmSync(TEMP_AI, { recursive: true, force: true });
|
|
25
|
+
fs.mkdirSync(TEMP_KB, { recursive: true });
|
|
26
|
+
|
|
27
|
+
// 1. Default initial-analysis turn: SDK is the only mode. The session
|
|
28
|
+
// should be created without any pre-turn permission prompt (the
|
|
29
|
+
// SDK surfaces tool approvals lazily through canUseTool).
|
|
30
|
+
const started = runner.startSession({
|
|
31
|
+
slug: 'claude-workbench-test-temp',
|
|
32
|
+
projectPath: ROOT,
|
|
33
|
+
kbPath: TEMP_KB,
|
|
34
|
+
promptKey: 'initial-analysis',
|
|
35
|
+
aiProfile: {
|
|
36
|
+
id: 'test-profile',
|
|
37
|
+
implementation: 'claude-code-agent',
|
|
38
|
+
mainModel: 'test-model',
|
|
39
|
+
},
|
|
40
|
+
vars: {
|
|
41
|
+
SLUG: 'claude-workbench-test-temp',
|
|
42
|
+
PROJECT_PATH: ROOT,
|
|
43
|
+
PRIMARY_LANGUAGE: 'JavaScript',
|
|
44
|
+
KNOWLEDGE_LANGUAGE: 'zh-CN',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
assert(started.sessionId, 'startSession should return sessionId');
|
|
49
|
+
assert(!started.pendingPermission,
|
|
50
|
+
'SDK mode should not show a pre-turn UI permission prompt');
|
|
51
|
+
assert(started.runner === 'sdk',
|
|
52
|
+
`startSession should default to runner: 'sdk', got ${started.runner}`);
|
|
53
|
+
|
|
54
|
+
const state = runner.getState(started.sessionId);
|
|
55
|
+
assert(state.runner === 'sdk',
|
|
56
|
+
`session state should record runner: 'sdk', got ${state.runner}`);
|
|
57
|
+
|
|
58
|
+
runner.deleteSession(started.sessionId);
|
|
59
|
+
|
|
60
|
+
// 1b. The embedded terminal should be able to create an idle chat
|
|
61
|
+
// session without reading claude-prompts.json or running an
|
|
62
|
+
// initial-analysis prompt. The user's first typed message starts
|
|
63
|
+
// the actual SDK turn via sendInput.
|
|
64
|
+
const chat = runner.startChatSession({
|
|
65
|
+
slug: 'claude-workbench-test-temp',
|
|
66
|
+
projectPath: ROOT,
|
|
67
|
+
kbPath: TEMP_KB,
|
|
68
|
+
aiProfile: {
|
|
69
|
+
id: 'test-profile',
|
|
70
|
+
implementation: 'claude-code-agent',
|
|
71
|
+
mainModel: 'test-model',
|
|
72
|
+
},
|
|
73
|
+
permissionMode: 'default',
|
|
74
|
+
});
|
|
75
|
+
assert(chat.sessionId, 'startChatSession should return sessionId');
|
|
76
|
+
const chatState = runner.getState(chat.sessionId);
|
|
77
|
+
assert(chatState.promptKey === 'terminal-chat',
|
|
78
|
+
`chat session should use terminal-chat promptKey, got ${chatState.promptKey}`);
|
|
79
|
+
assert(chatState.state === 'idle',
|
|
80
|
+
`chat session should stay idle until user input, got ${chatState.state}`);
|
|
81
|
+
assert(chatState.turns === 0, `chat session should not start a turn, got turns=${chatState.turns}`);
|
|
82
|
+
|
|
83
|
+
// 1c. Switching AI profiles mid-session must not resume the old upstream
|
|
84
|
+
// Claude conversation with the new provider. That used to send the
|
|
85
|
+
// previous model (for example MiniMax-M3) to the new base URL (for
|
|
86
|
+
// example GLM), producing "model not found" API errors.
|
|
87
|
+
const chatSession = runner.getSession(chat.sessionId);
|
|
88
|
+
chatSession.aiProfileId = 'minimax-m3';
|
|
89
|
+
chatSession.model = 'MiniMax-M3';
|
|
90
|
+
chatSession.claudeSessionId = 'old-claude-session-id';
|
|
91
|
+
const switched = runner.applyAiProfileToSession(chatSession, {
|
|
92
|
+
id: 'glm',
|
|
93
|
+
implementation: 'claude-code-agent',
|
|
94
|
+
mainModel: 'glm-5.2',
|
|
95
|
+
});
|
|
96
|
+
const switchedState = runner.getState(chat.sessionId);
|
|
97
|
+
assert(switched.resetConversation === true, 'profile switch should reset the upstream conversation');
|
|
98
|
+
assert(switchedState.claudeSessionId === null, 'profile switch should clear stale claudeSessionId');
|
|
99
|
+
assert(switchedState.aiProfileId === 'glm', `profile switch should update aiProfileId, got ${switchedState.aiProfileId}`);
|
|
100
|
+
assert(switchedState.model === 'glm-5.2', `profile switch should update model, got ${switchedState.model}`);
|
|
101
|
+
runner.deleteSession(chat.sessionId);
|
|
102
|
+
|
|
103
|
+
// Session metadata uses durable atomic replacement, but a disk fault must
|
|
104
|
+
// remain fail-open for the live Workbench session and become observable.
|
|
105
|
+
const AtomicFile = require('../lib/atomic-file');
|
|
106
|
+
const originalAtomicWrite = AtomicFile.writeJsonAtomic;
|
|
107
|
+
const persistenceLogs = [];
|
|
108
|
+
runner.setLogger({ error: async (event, message, payload) => { persistenceLogs.push({ event, message, payload }); } });
|
|
109
|
+
AtomicFile.writeJsonAtomic = () => { throw Object.assign(new Error('simulated disk full'), { code: 'ENOSPC' }); };
|
|
110
|
+
let persistenceFaultSession;
|
|
111
|
+
try {
|
|
112
|
+
persistenceFaultSession = runner.createSession({
|
|
113
|
+
projectSlug: 'claude-workbench-test-temp', projectPath: ROOT, kbPath: TEMP_KB, promptKey: 'terminal-chat',
|
|
114
|
+
});
|
|
115
|
+
assert(persistenceFaultSession.sessionId, 'persistence failure must not interrupt the live session');
|
|
116
|
+
assert(persistenceLogs.some(entry => entry.event === 'claude.session_persist_failed' && entry.payload.error.code === 'ENOSPC'), 'persistence failure must be structured and correlated');
|
|
117
|
+
} finally {
|
|
118
|
+
AtomicFile.writeJsonAtomic = originalAtomicWrite;
|
|
119
|
+
runner.setLogger(null);
|
|
120
|
+
if (persistenceFaultSession) runner.deleteSession(persistenceFaultSession.sessionId);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const executable = await runner.findClaudeExecutableForSdk();
|
|
124
|
+
if (process.platform === 'win32' && executable.cmd) {
|
|
125
|
+
assert(!/\.(cmd|bat|ps1)$/i.test(executable.cmd),
|
|
126
|
+
`SDK executable must not be a Windows shell shim: ${executable.cmd}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 2. Automation raw prompt sessions must preserve the selected permission
|
|
130
|
+
// mode. This guards against regressing back to bypassPermissions -> default.
|
|
131
|
+
process.env.KB_AUTOMATION_FAKE_CLAUDE = '1';
|
|
132
|
+
const auto = runner.startAutomationSession({
|
|
133
|
+
slug: 'claude-workbench-test-temp',
|
|
134
|
+
projectPath: ROOT,
|
|
135
|
+
kbPath: TEMP_KB,
|
|
136
|
+
userPrompt: 'automation test prompt',
|
|
137
|
+
systemPrompt: 'automation system prompt',
|
|
138
|
+
aiProfile: {
|
|
139
|
+
id: 'test-profile',
|
|
140
|
+
implementation: 'claude-code-agent',
|
|
141
|
+
mainModel: 'test-model',
|
|
142
|
+
},
|
|
143
|
+
permissionMode: 'bypassPermissions',
|
|
144
|
+
allowedTools: ['Read'],
|
|
145
|
+
safetyPolicy: {
|
|
146
|
+
kind: 'kb-automation',
|
|
147
|
+
kbPath: TEMP_KB,
|
|
148
|
+
knowledgeMode: 'requestApproval',
|
|
149
|
+
allowReadOnlyBash: false,
|
|
150
|
+
allowedTools: ['Read'],
|
|
151
|
+
canWriteKb: false,
|
|
152
|
+
},
|
|
153
|
+
metadata: { automation: true, automationRunId: 'auto-test', source: 'test' },
|
|
154
|
+
});
|
|
155
|
+
const autoState = runner.getState(auto.sessionId);
|
|
156
|
+
assert(autoState.permissionMode === 'bypassPermissions',
|
|
157
|
+
`automation session should preserve bypassPermissions, got ${autoState.permissionMode}`);
|
|
158
|
+
assert(autoState.automation === true, 'automation session should be marked automation=true');
|
|
159
|
+
runner.deleteSession(auto.sessionId);
|
|
160
|
+
delete process.env.KB_AUTOMATION_FAKE_CLAUDE;
|
|
161
|
+
|
|
162
|
+
fs.rmSync(TEMP_KB, { recursive: true, force: true });
|
|
163
|
+
fs.rmSync(TEMP_AI, { recursive: true, force: true });
|
|
164
|
+
console.log('Claude workbench test passed');
|
|
165
|
+
})().catch(err => {
|
|
166
|
+
try { fs.rmSync(TEMP_KB, { recursive: true, force: true }); } catch {}
|
|
167
|
+
try { fs.rmSync(TEMP_AI, { recursive: true, force: true }); } catch {}
|
|
168
|
+
console.error(err);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
});
|
|
@@ -17,10 +17,10 @@ const { ConversationStore } = require('../lib/conversation-store');
|
|
|
17
17
|
const { BridgeAdapter } = require('../lib/bridge-adapter');
|
|
18
18
|
const { BridgeConsumerService } = require('../lib/bridge-consumer-service');
|
|
19
19
|
const { readDevelopmentEvents } = require('../lib/conversation-exclusions');
|
|
20
|
-
const bridgePackage = require('@sanqianx/ai-coding-event-bridge');
|
|
21
|
-
const opencodeEntry = require('@sanqianx/ai-coding-event-bridge/src/connectors/opencode/hook-entry');
|
|
22
|
-
const claudeEntry = require('@sanqianx/ai-coding-event-bridge/src/connectors/claude-code/hook-entry');
|
|
23
|
-
const codexEntry = require('@sanqianx/ai-coding-event-bridge/src/connectors/codex/hook-entry');
|
|
20
|
+
const bridgePackage = require('@sanqianx/ai-coding-event-bridge-console/src/bridge');
|
|
21
|
+
const opencodeEntry = require('@sanqianx/ai-coding-event-bridge-console/src/bridge/connectors/opencode/hook-entry');
|
|
22
|
+
const claudeEntry = require('@sanqianx/ai-coding-event-bridge-console/src/bridge/connectors/claude-code/hook-entry');
|
|
23
|
+
const codexEntry = require('@sanqianx/ai-coding-event-bridge-console/src/bridge/connectors/codex/hook-entry');
|
|
24
24
|
|
|
25
25
|
const temp = fs.mkdtempSync(path.join(os.tmpdir(), `kb-client-e2e-${process.pid}-`));
|
|
26
26
|
const layout = new StorageLayout({ dataDir: path.join(temp, 'data') });
|
|
@@ -52,7 +52,8 @@ assert.strictEqual(projected.find(item => item.eventId === 'next-user').developm
|
|
|
52
52
|
assert.strictEqual(projected.find(item => item.eventId === 'orphan').turnId, null, 'never pair across Codex sessions');
|
|
53
53
|
assert.strictEqual(JSON.stringify(raw), before, 'projection must not rewrite durable source events');
|
|
54
54
|
|
|
55
|
-
const uiSource = fs.readFileSync(path.resolve(__dirname, '..', '..', 'ui', '
|
|
55
|
+
const uiSource = fs.readFileSync(path.resolve(__dirname, '..', '..', 'ui', 'product.js'), 'utf8');
|
|
56
|
+
assert(uiSource.includes('/modules/eventbridge/'), 'conversation rendering must remain in the native event-bridge UI');
|
|
56
57
|
assert(!uiSource.includes('(无用户文本)'), 'UI must not invent a user message for an assistant-only record');
|
|
57
58
|
assert(!uiSource.includes('(尚无回复)'), 'UI must not invent an assistant reply for an incomplete turn');
|
|
58
59
|
|
|
@@ -14,7 +14,7 @@ const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
|
14
14
|
const { ProjectStore } = require('../lib/project-store');
|
|
15
15
|
const { ConversationStore } = require('../lib/conversation-store');
|
|
16
16
|
const { CommitConversationBinder } = require('../lib/commit-conversation-binder');
|
|
17
|
-
const bridgeModule = require('@sanqianx/ai-coding-event-bridge');
|
|
17
|
+
const bridgeModule = require('@sanqianx/ai-coding-event-bridge-console/src/bridge');
|
|
18
18
|
|
|
19
19
|
const temp = fs.mkdtempSync(path.join(os.tmpdir(), `kb-boundary-freeze-${process.pid}-`));
|
|
20
20
|
const layout = new StorageLayout({ dataDir: path.join(temp, 'data') });
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { StorageLayout } = require('../lib/storage-layout');
|
|
6
|
-
const { ProjectStore } = require('../lib/project-store');
|
|
7
|
-
const { ConversationStore } = require('../lib/conversation-store');
|
|
8
|
-
const { CommitConversationBinder } = require('../lib/commit-conversation-binder');
|
|
9
|
-
|
|
10
|
-
(async () => {
|
|
11
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-conversation-binding-'));
|
|
12
|
-
const layout = new StorageLayout({ dataDir: path.join(root, 'data') });
|
|
13
|
-
const projectStore = new ProjectStore({ layout });
|
|
14
|
-
const projectId = 'project-binding';
|
|
15
|
-
const repoIdentity = { commonDir: path.join(root, 'repo', '.git') };
|
|
16
|
-
await projectStore.create(projectId, {
|
|
17
|
-
displayName: 'Binding',
|
|
18
|
-
storageName: 'binding',
|
|
19
|
-
repoPath: path.join(root, 'repo'),
|
|
20
|
-
knowledgePath: path.join(root, 'knowledge'),
|
|
21
|
-
repoIdentity,
|
|
22
|
-
}, { conversationBaselineCursor: 0, conversation: { lastConsumedCursor: 0, captureStatus: 'captured' } });
|
|
23
|
-
const store = new ConversationStore({ layout, projectStore });
|
|
24
|
-
const binder = new CommitConversationBinder({ layout, projectStore, conversationStore: store });
|
|
25
|
-
const c1 = '1'.repeat(40);
|
|
26
|
-
const c2 = '2'.repeat(40);
|
|
27
|
-
const c3 = '3'.repeat(40);
|
|
28
|
-
const cMerge = '4'.repeat(40);
|
|
29
|
-
const cAmbiguous = '5'.repeat(40);
|
|
30
|
-
|
|
31
|
-
const append = input => store.appendEvent(projectId, {
|
|
32
|
-
source: 'codex',
|
|
33
|
-
sessionId: 'session-1',
|
|
34
|
-
projectPath: path.join(root, 'repo'),
|
|
35
|
-
repoIdentity,
|
|
36
|
-
branch: 'main',
|
|
37
|
-
headAtCapture: '0'.repeat(40),
|
|
38
|
-
capturedAt: `2026-08-18T02:${String(input.sequence || 0).padStart(2, '0')}:00.000Z`,
|
|
39
|
-
rawEventType: input.eventType,
|
|
40
|
-
identityConfidence: 'high',
|
|
41
|
-
captureStatus: 'captured',
|
|
42
|
-
...input,
|
|
43
|
-
});
|
|
44
|
-
await append({ eventId: 'r1', sequence: 1, eventType: 'user_prompt', role: 'user', content: 'Requirement before C1.', turnId: 'turn-1' });
|
|
45
|
-
const boundaryC1 = { commitSha: c1, repoIdentity, parentShas: [], branch: 'main', committedAt: '2026-08-18T02:02:00.000Z', bridgeCursorAtCommit: 2, journalSequence: 2, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c1' };
|
|
46
|
-
store.writeBoundary(projectId, boundaryC1);
|
|
47
|
-
assert.strictEqual(store.writeBoundary(projectId, boundaryC1).commitSha, c1, 'identical bridge/hook boundary is idempotent');
|
|
48
|
-
assert.throws(() => store.writeBoundary(projectId, { ...boundaryC1, branch: 'other' }), error => error.code === 'DATA_CORRUPT');
|
|
49
|
-
await append({ eventId: 'a1', sequence: 3, eventType: 'assistant_response', role: 'assistant', content: 'Late assistant before claim.', turnId: 'turn-1' });
|
|
50
|
-
await append({ eventId: 'r2', sequence: 4, eventType: 'user_prompt', role: 'user', content: 'Requirement after C1.', turnId: 'turn-2', headAtCapture: c1 });
|
|
51
|
-
|
|
52
|
-
const frozenC1 = await binder.bind({ projectId, commitSha: c1 });
|
|
53
|
-
assert.strictEqual(frozenC1.status, 'available');
|
|
54
|
-
assert.deepStrictEqual(frozenC1.turns.map(turn => turn.turnId), ['turn-1'], 'future R2 must never bind back to C1');
|
|
55
|
-
assert.deepStrictEqual(frozenC1.turns[0].assistantEvents.map(event => event.eventId), [], 'assistant beyond boundaryEndCursor must never enter the frozen snapshot (I-13)');
|
|
56
|
-
assert.strictEqual(frozenC1.excludedFuturePromptCount, 1);
|
|
57
|
-
const frozenHash = frozenC1.snapshotHash;
|
|
58
|
-
await append({ eventId: 'a1-after-claim', sequence: 6, eventType: 'assistant_response', role: 'assistant', content: 'Assistant arrived after Claim.', turnId: 'turn-1' });
|
|
59
|
-
const retriedC1 = await binder.bind({ projectId, commitSha: c1 });
|
|
60
|
-
assert.strictEqual(retriedC1.snapshotHash, frozenHash, 'retry must reuse the exact Claim-time conversation freeze');
|
|
61
|
-
assert.deepStrictEqual(retriedC1.turns[0].assistantEvents.map(event => event.eventId), [], 'delayed binder execution must not pull post-commit replies into the old snapshot');
|
|
62
|
-
|
|
63
|
-
store.writeBoundary(projectId, { commitSha: c2, repoIdentity, parentShas: [c1], branch: 'main', committedAt: '2026-08-18T02:05:00.000Z', bridgeCursorAtCommit: 5, journalSequence: 5, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c2' });
|
|
64
|
-
const frozenC2 = await binder.bind({ projectId, commitSha: c2 });
|
|
65
|
-
assert.deepStrictEqual(frozenC2.turns.map(turn => [turn.turnId, turn.bindingKind]), [['turn-1', 'shared-spanning'], ['turn-2', 'direct']]);
|
|
66
|
-
assert.deepStrictEqual(frozenC2.turns[0].assistantEvents.map(event => event.eventId), ['a1'], 'the assistant reply inside the C2 window belongs to the spanning turn');
|
|
67
|
-
assert.strictEqual(frozenC2.turns[0].turnId, frozenC1.turns[0].turnId, 'spanning turns must retain one stable identity across commits');
|
|
68
|
-
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
6
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
7
|
+
const { ConversationStore } = require('../lib/conversation-store');
|
|
8
|
+
const { CommitConversationBinder } = require('../lib/commit-conversation-binder');
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-conversation-binding-'));
|
|
12
|
+
const layout = new StorageLayout({ dataDir: path.join(root, 'data') });
|
|
13
|
+
const projectStore = new ProjectStore({ layout });
|
|
14
|
+
const projectId = 'project-binding';
|
|
15
|
+
const repoIdentity = { commonDir: path.join(root, 'repo', '.git') };
|
|
16
|
+
await projectStore.create(projectId, {
|
|
17
|
+
displayName: 'Binding',
|
|
18
|
+
storageName: 'binding',
|
|
19
|
+
repoPath: path.join(root, 'repo'),
|
|
20
|
+
knowledgePath: path.join(root, 'knowledge'),
|
|
21
|
+
repoIdentity,
|
|
22
|
+
}, { conversationBaselineCursor: 0, conversation: { lastConsumedCursor: 0, captureStatus: 'captured' } });
|
|
23
|
+
const store = new ConversationStore({ layout, projectStore });
|
|
24
|
+
const binder = new CommitConversationBinder({ layout, projectStore, conversationStore: store });
|
|
25
|
+
const c1 = '1'.repeat(40);
|
|
26
|
+
const c2 = '2'.repeat(40);
|
|
27
|
+
const c3 = '3'.repeat(40);
|
|
28
|
+
const cMerge = '4'.repeat(40);
|
|
29
|
+
const cAmbiguous = '5'.repeat(40);
|
|
30
|
+
|
|
31
|
+
const append = input => store.appendEvent(projectId, {
|
|
32
|
+
source: 'codex',
|
|
33
|
+
sessionId: 'session-1',
|
|
34
|
+
projectPath: path.join(root, 'repo'),
|
|
35
|
+
repoIdentity,
|
|
36
|
+
branch: 'main',
|
|
37
|
+
headAtCapture: '0'.repeat(40),
|
|
38
|
+
capturedAt: `2026-08-18T02:${String(input.sequence || 0).padStart(2, '0')}:00.000Z`,
|
|
39
|
+
rawEventType: input.eventType,
|
|
40
|
+
identityConfidence: 'high',
|
|
41
|
+
captureStatus: 'captured',
|
|
42
|
+
...input,
|
|
43
|
+
});
|
|
44
|
+
await append({ eventId: 'r1', sequence: 1, eventType: 'user_prompt', role: 'user', content: 'Requirement before C1.', turnId: 'turn-1' });
|
|
45
|
+
const boundaryC1 = { commitSha: c1, repoIdentity, parentShas: [], branch: 'main', committedAt: '2026-08-18T02:02:00.000Z', bridgeCursorAtCommit: 2, journalSequence: 2, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c1' };
|
|
46
|
+
store.writeBoundary(projectId, boundaryC1);
|
|
47
|
+
assert.strictEqual(store.writeBoundary(projectId, boundaryC1).commitSha, c1, 'identical bridge/hook boundary is idempotent');
|
|
48
|
+
assert.throws(() => store.writeBoundary(projectId, { ...boundaryC1, branch: 'other' }), error => error.code === 'DATA_CORRUPT');
|
|
49
|
+
await append({ eventId: 'a1', sequence: 3, eventType: 'assistant_response', role: 'assistant', content: 'Late assistant before claim.', turnId: 'turn-1' });
|
|
50
|
+
await append({ eventId: 'r2', sequence: 4, eventType: 'user_prompt', role: 'user', content: 'Requirement after C1.', turnId: 'turn-2', headAtCapture: c1 });
|
|
51
|
+
|
|
52
|
+
const frozenC1 = await binder.bind({ projectId, commitSha: c1 });
|
|
53
|
+
assert.strictEqual(frozenC1.status, 'available');
|
|
54
|
+
assert.deepStrictEqual(frozenC1.turns.map(turn => turn.turnId), ['turn-1'], 'future R2 must never bind back to C1');
|
|
55
|
+
assert.deepStrictEqual(frozenC1.turns[0].assistantEvents.map(event => event.eventId), [], 'assistant beyond boundaryEndCursor must never enter the frozen snapshot (I-13)');
|
|
56
|
+
assert.strictEqual(frozenC1.excludedFuturePromptCount, 1);
|
|
57
|
+
const frozenHash = frozenC1.snapshotHash;
|
|
58
|
+
await append({ eventId: 'a1-after-claim', sequence: 6, eventType: 'assistant_response', role: 'assistant', content: 'Assistant arrived after Claim.', turnId: 'turn-1' });
|
|
59
|
+
const retriedC1 = await binder.bind({ projectId, commitSha: c1 });
|
|
60
|
+
assert.strictEqual(retriedC1.snapshotHash, frozenHash, 'retry must reuse the exact Claim-time conversation freeze');
|
|
61
|
+
assert.deepStrictEqual(retriedC1.turns[0].assistantEvents.map(event => event.eventId), [], 'delayed binder execution must not pull post-commit replies into the old snapshot');
|
|
62
|
+
|
|
63
|
+
store.writeBoundary(projectId, { commitSha: c2, repoIdentity, parentShas: [c1], branch: 'main', committedAt: '2026-08-18T02:05:00.000Z', bridgeCursorAtCommit: 5, journalSequence: 5, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c2' });
|
|
64
|
+
const frozenC2 = await binder.bind({ projectId, commitSha: c2 });
|
|
65
|
+
assert.deepStrictEqual(frozenC2.turns.map(turn => [turn.turnId, turn.bindingKind]), [['turn-1', 'shared-spanning'], ['turn-2', 'direct']]);
|
|
66
|
+
assert.deepStrictEqual(frozenC2.turns[0].assistantEvents.map(event => event.eventId), ['a1'], 'the assistant reply inside the C2 window belongs to the spanning turn');
|
|
67
|
+
assert.strictEqual(frozenC2.turns[0].turnId, frozenC1.turns[0].turnId, 'spanning turns must retain one stable identity across commits');
|
|
68
|
+
|
|
69
69
|
store.writeBoundary(projectId, { commitSha: c3, repoIdentity, parentShas: [c2], branch: 'main', committedAt: '2026-08-18T02:07:00.000Z', bridgeCursorAtCommit: 7, journalSequence: 7, openTurnIdsAtCommit: ['turn-1'], operationId: 'op-c3' });
|
|
70
70
|
const frozenC3 = await binder.bind({ projectId, commitSha: c3 });
|
|
71
71
|
assert.strictEqual(frozenC3.status, 'no-new-user-prompt');
|
|
72
72
|
assert.deepStrictEqual(frozenC3.turns, [], 'a stale Bridge open-turn id must not copy a closed requirement into a later commit');
|
|
73
|
-
|
|
74
|
-
await append({ eventId: 'r-merge', sequence: 8, eventType: 'user_prompt', role: 'user', content: 'Merge-window requirement.', turnId: 'turn-merge' });
|
|
75
|
-
store.writeBoundary(projectId, { commitSha: cMerge, repoIdentity, parentShas: [c1, c2], branch: 'main', committedAt: '2026-08-18T02:10:00.000Z', bridgeCursorAtCommit: 10, journalSequence: 10, openTurnIdsAtCommit: [], operationId: 'op-merge' });
|
|
76
|
-
const mergeSnapshot = await binder.bind({ projectId, commitSha: cMerge });
|
|
77
|
-
assert.strictEqual(mergeSnapshot.boundaryStartCursor, 7, 'merge window must use previous durable repo boundary, not an arbitrary Git parent');
|
|
78
|
-
assert.deepStrictEqual(mergeSnapshot.turns.map(turn => turn.turnId), ['turn-merge']);
|
|
79
|
-
|
|
80
|
-
await append({ eventId: 'r-ambiguous', sequence: 11, eventType: 'user_prompt', role: 'user', content: 'Identity unavailable.', turnId: null, repoIdentity: null, identityConfidence: 'unknown' });
|
|
81
|
-
store.writeBoundary(projectId, { commitSha: cAmbiguous, repoIdentity, parentShas: [cMerge], branch: 'main', committedAt: '2026-08-18T02:12:00.000Z', bridgeCursorAtCommit: 12, journalSequence: 12, openTurnIdsAtCommit: [], operationId: 'op-ambiguous' });
|
|
82
|
-
const ambiguous = await binder.bind({ projectId, commitSha: cAmbiguous });
|
|
83
|
-
assert.strictEqual(ambiguous.status, 'ambiguous');
|
|
84
|
-
assert.deepStrictEqual(ambiguous.turns, []);
|
|
85
|
-
|
|
86
|
-
const missingBoundary = await binder.bind({ projectId, commitSha: '6'.repeat(40) });
|
|
87
|
-
assert.strictEqual(missingBoundary.status, 'unavailable', 'missing boundary/capture gap must never fall back to timestamp or ancestry guessing');
|
|
88
|
-
|
|
89
|
-
const explicitSha = '7'.repeat(40);
|
|
90
|
-
await append({ eventId: 'explicit-r', sequence: null, eventType: 'user_prompt', role: 'user', content: 'Explicit requirement.', turnId: 'turn-explicit', explicitCommitSha: explicitSha, identityConfidence: 'explicit' });
|
|
91
|
-
const explicit = await binder.bind({ projectId, commitSha: explicitSha });
|
|
92
|
-
assert.strictEqual(explicit.status, 'available');
|
|
93
|
-
assert.strictEqual(explicit.turns[0].bindingKind, 'explicit');
|
|
94
|
-
|
|
95
|
-
console.log('commit-conversation-binding-test PASS');
|
|
96
|
-
})().catch(error => {
|
|
97
|
-
console.error(error.stack || error.message);
|
|
98
|
-
process.exitCode = 1;
|
|
99
|
-
});
|
|
73
|
+
|
|
74
|
+
await append({ eventId: 'r-merge', sequence: 8, eventType: 'user_prompt', role: 'user', content: 'Merge-window requirement.', turnId: 'turn-merge' });
|
|
75
|
+
store.writeBoundary(projectId, { commitSha: cMerge, repoIdentity, parentShas: [c1, c2], branch: 'main', committedAt: '2026-08-18T02:10:00.000Z', bridgeCursorAtCommit: 10, journalSequence: 10, openTurnIdsAtCommit: [], operationId: 'op-merge' });
|
|
76
|
+
const mergeSnapshot = await binder.bind({ projectId, commitSha: cMerge });
|
|
77
|
+
assert.strictEqual(mergeSnapshot.boundaryStartCursor, 7, 'merge window must use previous durable repo boundary, not an arbitrary Git parent');
|
|
78
|
+
assert.deepStrictEqual(mergeSnapshot.turns.map(turn => turn.turnId), ['turn-merge']);
|
|
79
|
+
|
|
80
|
+
await append({ eventId: 'r-ambiguous', sequence: 11, eventType: 'user_prompt', role: 'user', content: 'Identity unavailable.', turnId: null, repoIdentity: null, identityConfidence: 'unknown' });
|
|
81
|
+
store.writeBoundary(projectId, { commitSha: cAmbiguous, repoIdentity, parentShas: [cMerge], branch: 'main', committedAt: '2026-08-18T02:12:00.000Z', bridgeCursorAtCommit: 12, journalSequence: 12, openTurnIdsAtCommit: [], operationId: 'op-ambiguous' });
|
|
82
|
+
const ambiguous = await binder.bind({ projectId, commitSha: cAmbiguous });
|
|
83
|
+
assert.strictEqual(ambiguous.status, 'ambiguous');
|
|
84
|
+
assert.deepStrictEqual(ambiguous.turns, []);
|
|
85
|
+
|
|
86
|
+
const missingBoundary = await binder.bind({ projectId, commitSha: '6'.repeat(40) });
|
|
87
|
+
assert.strictEqual(missingBoundary.status, 'unavailable', 'missing boundary/capture gap must never fall back to timestamp or ancestry guessing');
|
|
88
|
+
|
|
89
|
+
const explicitSha = '7'.repeat(40);
|
|
90
|
+
await append({ eventId: 'explicit-r', sequence: null, eventType: 'user_prompt', role: 'user', content: 'Explicit requirement.', turnId: 'turn-explicit', explicitCommitSha: explicitSha, identityConfidence: 'explicit' });
|
|
91
|
+
const explicit = await binder.bind({ projectId, commitSha: explicitSha });
|
|
92
|
+
assert.strictEqual(explicit.status, 'available');
|
|
93
|
+
assert.strictEqual(explicit.turns[0].bindingKind, 'explicit');
|
|
94
|
+
|
|
95
|
+
console.log('commit-conversation-binding-test PASS');
|
|
96
|
+
})().catch(error => {
|
|
97
|
+
console.error(error.stack || error.message);
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
});
|