Skip to content

Commit 08e57b4

Browse files
committed
fix(memory): canonicalize CP artifact paths
1 parent 7862fdb commit 08e57b4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎mcp/memory-server.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,13 @@ function relativeToActiveRoot(target, filePath) {
776776
return path.relative(target.activeRoot, filePath).replace(/\\/g, '/')
777777
}
778778

779+
function relativeExistingToActiveRoot(target, filePath) {
780+
const realpath = fs.realpathSync.native
781+
? candidate => fs.realpathSync.native(candidate)
782+
: candidate => fs.realpathSync(candidate)
783+
return path.relative(realpath(target.activeRoot), realpath(filePath)).replace(/\\/g, '/')
784+
}
785+
779786
function memoryLinkCapability(target, surface) {
780787
return createLinkCapabilityDecision({
781788
surface,
@@ -2922,7 +2929,7 @@ function handleMemoryCpConfirm(args) {
29222929
throw new Error(`ConfirmBindingGate: artifactPath changed during verification: ${artifactPath}`)
29232930
}
29242931
artifactPath = afterRead.relative
2925-
artifactTargetPath = relativeToActiveRoot(target, afterRead.currentPath)
2932+
artifactTargetPath = relativeExistingToActiveRoot(target, afterRead.currentPath)
29262933
const rootStat = fs.statSync(canonicalRoot)
29272934
artifactAuthority = {
29282935
schemaVersion: 'MemoryCpArtifactAuthorityV1',

‎scripts/test-mcp-servers.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,10 @@ function testMemoryCpConfirmPreservesOrdinaryTables() {
10491049
assert.strictEqual(confirmation.structuredContent.artifactAuthority.rootKind, 'task')
10501050
assert.strictEqual(confirmation.structuredContent.artifactAuthority.canonicalRelativePath, '02-技术方案.md')
10511051
assert.match(confirmation.structuredContent.artifactAuthority.rootIdentity, /^[a-f0-9]{64}$/)
1052+
assert.strictEqual(
1053+
confirmation.structuredContent.artifactLinks.links[0].targetPath,
1054+
'requirements/表格任务/02-技术方案.md'
1055+
)
10521056
let sessions = fs.readFileSync(sessionsPath, 'utf8')
10531057
assert.ok(sessions.startsWith(ordinaryTable.trimEnd()), 'ordinary session table must remain unchanged')
10541058
assert.strictEqual((sessions.match(/^### CP 确认记录$/gm) || []).length, 1)

0 commit comments

Comments
 (0)