solopup-memory 0.21.0-beta.3 → 0.23.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/COMPATIBILITY.md +8 -5
- package/DETECTION.md +139 -0
- package/DREAMING-DESIGN.md +167 -0
- package/README.en.md +64 -6
- package/README.md +67 -5
- package/RELEASE.md +36 -0
- package/SECURITY.md +7 -0
- package/context-history.mjs +20 -3
- package/detect.mjs +441 -0
- package/eval/bench-detect.mjs +107 -0
- package/eval/semantic/cases.json +387 -0
- package/eval/semantic-suite.mjs +156 -0
- package/index.mjs +85 -11
- package/managed-policy.mjs +3 -1
- package/package.json +90 -69
- package/project-stores.mjs +83 -4
- package/scripts/demo-source-recall.mjs +123 -0
- package/scripts/detect.mjs +69 -0
- package/scripts/dream.mjs +205 -0
- package/scripts/probe-history.mjs +92 -0
- package/scripts/probe-load.mjs +1 -1
- package/scripts/probe-package.mjs +6 -2
- package/scripts/projects.mjs +5 -4
- package/scripts/security-check.mjs +177 -0
- package/scripts/soak.mjs +223 -0
- package/scripts/superagent-worktree.mjs +20 -0
- package/scripts/telemetry.mjs +187 -0
- package/scripts/verify.mjs +3 -1
- package/{test-adversarial.mjs → test/test-adversarial.mjs} +5 -5
- package/{test-belief-revision.mjs → test/test-belief-revision.mjs} +7 -7
- package/{test-candidates.mjs → test/test-candidates.mjs} +4 -4
- package/{test-capture-diagnostics.mjs → test/test-capture-diagnostics.mjs} +6 -6
- package/{test-capture-field-lineage.mjs → test/test-capture-field-lineage.mjs} +4 -4
- package/{test-capture-inputs.mjs → test/test-capture-inputs.mjs} +8 -8
- package/{test-capture-jobs.mjs → test/test-capture-jobs.mjs} +5 -5
- package/{test-capture-projections.mjs → test/test-capture-projections.mjs} +12 -12
- package/{test-capture-revision.mjs → test/test-capture-revision.mjs} +6 -6
- package/{test-capture-submission.mjs → test/test-capture-submission.mjs} +3 -3
- package/{test-capture-validation-flow.mjs → test/test-capture-validation-flow.mjs} +5 -5
- package/{test-capture-validation-job.mjs → test/test-capture-validation-job.mjs} +5 -5
- package/{test-capture-validation-lineage.mjs → test/test-capture-validation-lineage.mjs} +2 -2
- package/{test-capture-validation.mjs → test/test-capture-validation.mjs} +2 -2
- package/{test-capture.mjs → test/test-capture.mjs} +20 -20
- package/{test-compaction-compat.mjs → test/test-compaction-compat.mjs} +5 -5
- package/{test-compat.mjs → test/test-compat.mjs} +3 -3
- package/{test-concurrency.mjs → test/test-concurrency.mjs} +3 -3
- package/{test-conflict.mjs → test/test-conflict.mjs} +2 -2
- package/{test-context-history.mjs → test/test-context-history.mjs} +1 -1
- package/{test-control-schema.mjs → test/test-control-schema.mjs} +1 -1
- package/test/test-detect.mjs +125 -0
- package/test/test-dream-plan.mjs +72 -0
- package/test/test-dsh-registration.mjs +111 -0
- package/{test-episodes.mjs → test/test-episodes.mjs} +5 -5
- package/{test-explicit-memory.mjs → test/test-explicit-memory.mjs} +4 -4
- package/{test-field-lineage.mjs → test/test-field-lineage.mjs} +4 -4
- package/{test-history.mjs → test/test-history.mjs} +4 -4
- package/{test-inline-summary.mjs → test/test-inline-summary.mjs} +5 -5
- package/{test-legacy-source-identity.mjs → test/test-legacy-source-identity.mjs} +2 -2
- package/{test-links.mjs → test/test-links.mjs} +4 -4
- package/{test-managed-access.mjs → test/test-managed-access.mjs} +29 -5
- package/{test-managed-activation.mjs → test/test-managed-activation.mjs} +5 -5
- package/{test-meaning.mjs → test/test-meaning.mjs} +6 -6
- package/{test-native-service-lifecycle.mjs → test/test-native-service-lifecycle.mjs} +1 -1
- package/{test-native-write-validation.mjs → test/test-native-write-validation.mjs} +4 -4
- package/{test-packaging.mjs → test/test-packaging.mjs} +32 -5
- package/{test-paired-analysis.mjs → test/test-paired-analysis.mjs} +1 -1
- package/{test-patch.mjs → test/test-patch.mjs} +11 -11
- package/{test-plugin-contract.mjs → test/test-plugin-contract.mjs} +4 -4
- package/{test-privacy.mjs → test/test-privacy.mjs} +3 -3
- package/{test-project-stores.mjs → test/test-project-stores.mjs} +125 -7
- package/{test-publication.mjs → test/test-publication.mjs} +4 -4
- package/{test-restore.mjs → test/test-restore.mjs} +11 -11
- package/{test-retrieval.mjs → test/test-retrieval.mjs} +2 -2
- package/{test-revision-admission.mjs → test/test-revision-admission.mjs} +3 -3
- package/{test-rule-admission.mjs → test/test-rule-admission.mjs} +8 -8
- package/{test-runtime-startup.mjs → test/test-runtime-startup.mjs} +2 -2
- package/{test-schema.mjs → test/test-schema.mjs} +2 -2
- package/{test-security.mjs → test/test-security.mjs} +6 -6
- package/test/test-semantic-suite.mjs +20 -0
- package/{test-service-readiness.mjs → test/test-service-readiness.mjs} +1 -1
- package/{test-smell.mjs → test/test-smell.mjs} +4 -4
- package/{test-snapshots.mjs → test/test-snapshots.mjs} +3 -3
- package/{test-source-completeness.mjs → test/test-source-completeness.mjs} +6 -6
- package/{test-source-key.mjs → test/test-source-key.mjs} +2 -2
- package/{test-source-retirement.mjs → test/test-source-retirement.mjs} +4 -4
- package/{test-status-both.mjs → test/test-status-both.mjs} +12 -4
- package/{test-supersede.mjs → test/test-supersede.mjs} +3 -3
- package/test/test-telemetry.mjs +60 -0
- package/{test-text-admission.mjs → test/test-text-admission.mjs} +6 -6
- package/{test-tool-inputs.mjs → test/test-tool-inputs.mjs} +1 -1
- package/{test-tool-observations.mjs → test/test-tool-observations.mjs} +6 -6
- package/{test-tool-write-guard.mjs → test/test-tool-write-guard.mjs} +3 -3
- package/{test-tool-write-lifecycle.mjs → test/test-tool-write-lifecycle.mjs} +3 -3
- package/{test-usability.mjs → test/test-usability.mjs} +7 -7
- package/{test-validation-source-refs.mjs → test/test-validation-source-refs.mjs} +2 -2
- package/{test-validation-transition-context.mjs → test/test-validation-transition-context.mjs} +1 -1
- package/{test-withdrawal-archives.mjs → test/test-withdrawal-archives.mjs} +6 -6
- package/{test-withdrawal.mjs → test/test-withdrawal.mjs} +2 -2
- package/{test.mjs → test/test.mjs} +4 -4
- package/version.mjs +1 -1
package/index.mjs
CHANGED
|
@@ -47,7 +47,7 @@ import { captureSessionEligible, captureInputDescriptor, enqueueCaptureInput, bi
|
|
|
47
47
|
import { join, resolve, relative } from 'node:path'
|
|
48
48
|
import { DEFAULT_AUTO_CAPTURE, normalizePluginConfig } from './plugin-config.mjs'
|
|
49
49
|
import { optionalService } from './host-services.mjs'
|
|
50
|
-
import { projectStoreDir, inspectProjectStore, migrateProjectStore, recoverProjectStore } from './project-stores.mjs'
|
|
50
|
+
import { projectStoreDir, inspectProjectStore, migrateProjectStore, recoverProjectStore, linkWorktreeProject, unlinkWorktreeProject } from './project-stores.mjs'
|
|
51
51
|
import { watchOptionalService } from './service-readiness.mjs'
|
|
52
52
|
export { Config } from './plugin-config.mjs'
|
|
53
53
|
|
|
@@ -131,6 +131,8 @@ export function storeDirFor(scope, cwd) {
|
|
|
131
131
|
return ensureManagedProject(root,projectStoreDir(root, findProjectRoot(cwd)))
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
export const unlinkProjectWorktree = (worktree, options) => unlinkWorktreeProject(storeRoot(), findProjectRoot(worktree), options)
|
|
135
|
+
export const linkProjectWorktree = (worktree, owner, options) => linkWorktreeProject(storeRoot(), findProjectRoot(worktree), findProjectRoot(owner), options)
|
|
134
136
|
export const reviewProjectStore = cwd => inspectProjectStore(storeRoot(), findProjectRoot(cwd))
|
|
135
137
|
export const migrateLegacyProjectStore = (cwd, options) => migrateProjectStore(storeRoot(), findProjectRoot(cwd), options)
|
|
136
138
|
export const recoverLegacyProjectStore = (cwd, options) => recoverProjectStore(storeRoot(), findProjectRoot(cwd), options)
|
|
@@ -890,7 +892,7 @@ function writeMemoryLocal({ type, dir, line, detail, summary, expires, supersede
|
|
|
890
892
|
}
|
|
891
893
|
|
|
892
894
|
// 相似度闸:改写同一件事却再叠一条,会让新旧两条同时被注入、给出矛盾信息。
|
|
893
|
-
// 0.
|
|
895
|
+
// 0.9 以上直接拒绝并指出候选;0.8–0.9 放行但带警告(避免误伤「相似但不同」的条目)。
|
|
894
896
|
let similarWarning
|
|
895
897
|
// 完全重复走 duplicate 分支(幂等返回),相似度闸只管「像但不是同一句」
|
|
896
898
|
const alias = hasTopicDetail(cleanDetail) ? undefined : routeAlias(cleanLine, type)
|
|
@@ -1224,8 +1226,32 @@ function statusOfLocal(dir) {
|
|
|
1224
1226
|
}
|
|
1225
1227
|
|
|
1226
1228
|
/**
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
+
* L0 检测摘要:把 detect.mjs 的 findings 压成计数,避免状态输出膨胀。
|
|
1230
|
+
* 动态导入是为了不形成 index ↔ detect 的静态循环(detect 依赖本文件的纯函数)。
|
|
1231
|
+
*/
|
|
1232
|
+
async function lintStatus(dir, scope) {
|
|
1233
|
+
try {
|
|
1234
|
+
const { detectStore } = await import('./detect.mjs')
|
|
1235
|
+
const report = detectStore(dir, { scope })
|
|
1236
|
+
const counts = new Map()
|
|
1237
|
+
for (const finding of report.findings) {
|
|
1238
|
+
if (finding.severity === 'info') continue
|
|
1239
|
+
const row = counts.get(finding.id) ?? { id: finding.id, severity: finding.severity, count: 0 }
|
|
1240
|
+
row.count += 1
|
|
1241
|
+
counts.set(finding.id, row)
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
errors: report.summary.errors,
|
|
1245
|
+
warnings: report.summary.warnings,
|
|
1246
|
+
checks: [...counts.values()].sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)),
|
|
1247
|
+
}
|
|
1248
|
+
} catch {
|
|
1249
|
+
// 检测器本身坏了不能伪装成“库没问题”。
|
|
1250
|
+
return { errors: 0, warnings: 1, checks: [{ id: 'lint-unavailable', severity: 'warning', count: 1 }] }
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1229
1255
|
* 存在的原因:索引超上限时,被省略的条目对模型完全不可见(`lookupLinks` 只查索引)。
|
|
1230
1256
|
* 检索是确定性的:归一化后做子串匹配,不做正则、不做模糊。
|
|
1231
1257
|
*
|
|
@@ -2151,6 +2177,29 @@ function defineStatusTool(ctx, sourceInputs) {
|
|
|
2151
2177
|
expired: { type: 'integer' },
|
|
2152
2178
|
duplicateGroups: { type: 'integer' },
|
|
2153
2179
|
storeBytes: { type: 'integer' },
|
|
2180
|
+
// L0 检测摘要:只给计数与检查项;明细走 `node scripts/detect.mjs --json`。
|
|
2181
|
+
lint: {
|
|
2182
|
+
type: 'object',
|
|
2183
|
+
additionalProperties: false,
|
|
2184
|
+
required: ['errors', 'warnings', 'checks'],
|
|
2185
|
+
properties: {
|
|
2186
|
+
errors: { type: 'integer' },
|
|
2187
|
+
warnings: { type: 'integer' },
|
|
2188
|
+
checks: {
|
|
2189
|
+
type: 'array',
|
|
2190
|
+
items: {
|
|
2191
|
+
type: 'object',
|
|
2192
|
+
additionalProperties: false,
|
|
2193
|
+
required: ['id', 'severity', 'count'],
|
|
2194
|
+
properties: {
|
|
2195
|
+
id: { type: 'string' },
|
|
2196
|
+
severity: { type: 'string', enum: ['error', 'warning'] },
|
|
2197
|
+
count: { type: 'integer' },
|
|
2198
|
+
},
|
|
2199
|
+
},
|
|
2200
|
+
},
|
|
2201
|
+
},
|
|
2202
|
+
},
|
|
2154
2203
|
sourceLedger: { type: 'object', additionalProperties: false,
|
|
2155
2204
|
required: ['available', 'fullLimit', 'pendingLimit', 'retiredLimit', 'byteLimit'],
|
|
2156
2205
|
properties: { available: { type: 'boolean' }, fullRecords: { type: 'integer' }, retiredRecords: { type: 'integer' }, pending: { type: 'integer' }, bytes: { type: 'integer' }, fullLimit: { type: 'integer' }, pendingLimit: { type: 'integer' }, retiredLimit: { type: 'integer' }, byteLimit: { type: 'integer' }, reason: { type: 'string', enum: ['source-ledger-unavailable'] } } },
|
|
@@ -2177,7 +2226,8 @@ function defineStatusTool(ctx, sourceInputs) {
|
|
|
2177
2226
|
text:
|
|
2178
2227
|
`索引 ${value.index.lines}/${value.index.limitLines} 行、${value.index.bytes}/${value.index.limitBytes} 字节;` +
|
|
2179
2228
|
`类型:${types};过期 ${value.expired} 条;重复组 ${value.duplicateGroups};` +
|
|
2180
|
-
`主题文件:${topics || '无'};库占用 ${(value.storeBytes / 1024).toFixed(1)}K
|
|
2229
|
+
`主题文件:${topics || '无'};库占用 ${(value.storeBytes / 1024).toFixed(1)}K。` +
|
|
2230
|
+
(value.lint ? `\n检测(L0):error ${value.lint.errors}、warning ${value.lint.warnings}` + (value.lint.checks.length ? ';' + value.lint.checks.map((check) => `${check.id}×${check.count}`).join('、') : '') + '(明细:node scripts/detect.mjs)' : '') + '\n' +
|
|
2181
2231
|
(value.sourceLedger?.available ? `来源记录 ${value.sourceLedger.fullRecords}/${value.sourceLedger.fullLimit};历史来源凭据 ${value.sourceLedger.retiredRecords}/${value.sourceLedger.retiredLimit};待审 ${value.sourceLedger.pending}/${value.sourceLedger.pendingLimit};来源占用 ${(value.sourceLedger.bytes / 1024).toFixed(1)}/${value.sourceLedger.byteLimit / 1024}K。\n` : '来源账本待修复,容量状态未知。\n') + value.dir+(value.capture?'\n捕获诊断(全局保留作业):'+(!value.capture.available?'账本不可用,未知':value.capture.latest?.diagnostic?value.capture.latest.diagnostic.classification+';解析拒绝'+value.capture.latest.diagnostic.parserRejected+',截断'+value.capture.latest.diagnostic.deferred+',准入拒绝'+value.capture.latest.diagnostic.admissionRejected+',写入失败'+value.capture.latest.diagnostic.writeFailures+';不证明没有漏记':value.capture.latest?'旧作业无细分诊断或仍未完成,不能推断空结果':'尚无捕获作业记录;不能推断没有长期信息'):'')+(value.capture?.blockedInput?'\n自动整理未执行:用户来源不完整;没有从截断的前半段建立记忆。':'')+(value.executionObservations?'\n可引用执行结果(复制callId及原文):\n'+value.executionObservations.items.map(item=>JSON.stringify(item)).join('\n')+'\n'+value.executionObservations.note+(value.executionObservations.truncated?'(列表有省略,优先核对最近结果)':''):'') ,
|
|
2182
2232
|
},
|
|
2183
2233
|
]
|
|
@@ -2186,6 +2236,7 @@ function defineStatusTool(ctx, sourceInputs) {
|
|
|
2186
2236
|
async execute(args, exec) {
|
|
2187
2237
|
const dir = resolveStoreDir(ctx, exec, 'memory_status', args.scope)
|
|
2188
2238
|
const value={...statusOf(dir),capture:managedRead(storeRoot(),()=>captureJobStatus(storeRoot()))}
|
|
2239
|
+
value.lint = await lintStatus(dir, dir === storeRoot() ? 'global' : 'project')
|
|
2189
2240
|
if(args.includeObservations!==undefined&&typeof args.includeObservations!=='boolean')throw Error('memory-observation-invalid-list-option')
|
|
2190
2241
|
if(args.includeObservations===true){if(!captureSessionEligible(exec?.agent?.session))throw Error('memory-observation-source-unavailable');return{...value,executionObservations:sourceInputs.availableForExecution(exec)}}
|
|
2191
2242
|
return value
|
|
@@ -2213,7 +2264,7 @@ function defineStatusTool(ctx, sourceInputs) {
|
|
|
2213
2264
|
if(args.scope!=='both')return singleExecute(args,exec)
|
|
2214
2265
|
if(args.includeObservations!==undefined&&typeof args.includeObservations!=='boolean')throw Error('memory-observation-invalid-list-option')
|
|
2215
2266
|
const root=storeRoot()
|
|
2216
|
-
|
|
2267
|
+
const result=managedRead(root,()=>{
|
|
2217
2268
|
const stores=[{scope:'global',available:true,status:statusOf(root)}];let project
|
|
2218
2269
|
if(!exec?.agent||typeof ctx.workingDirectory?.get!=='function')project={scope:'project',available:false,reason:'no-current-project'}
|
|
2219
2270
|
else{
|
|
@@ -2229,10 +2280,14 @@ function defineStatusTool(ctx, sourceInputs) {
|
|
|
2229
2280
|
}catch{project={scope:'project',available:false,reason:'project-status-unavailable'}}
|
|
2230
2281
|
}
|
|
2231
2282
|
stores.push(project)
|
|
2232
|
-
|
|
2233
|
-
if(args.includeObservations===true){if(!captureSessionEligible(exec?.agent?.session))throw Error('memory-observation-source-unavailable');value.executionObservations=sourceInputs.availableForExecution(exec)}
|
|
2234
|
-
return value
|
|
2283
|
+
return {scope:'both',stores,capture:captureJobStatus(root)}
|
|
2235
2284
|
})
|
|
2285
|
+
for(const row of result.stores){
|
|
2286
|
+
if(!row.available)continue
|
|
2287
|
+
row.status.lint=await lintStatus(row.status.dir,row.scope)
|
|
2288
|
+
}
|
|
2289
|
+
if(args.includeObservations===true){if(!captureSessionEligible(exec?.agent?.session))throw Error('memory-observation-source-unavailable');result.executionObservations=sourceInputs.availableForExecution(exec)}
|
|
2290
|
+
return result
|
|
2236
2291
|
}
|
|
2237
2292
|
return definition
|
|
2238
2293
|
}
|
|
@@ -2740,7 +2795,19 @@ function setupAutoCapture(ctx, config) {
|
|
|
2740
2795
|
rememberSession(session)
|
|
2741
2796
|
scheduleRestore(session)
|
|
2742
2797
|
})
|
|
2743
|
-
ctx.on('session/disposed', session => {
|
|
2798
|
+
ctx.on('session/disposed', session => {
|
|
2799
|
+
// 短会话在结构上永远到不了 everyTurns;把“没整理”记成可观测事件,而不是静默丢弃。
|
|
2800
|
+
const state = sessions.get(session?.id)
|
|
2801
|
+
if (state && state.turns > 0 && state.turns < options.everyTurns && !state.running) {
|
|
2802
|
+
try {
|
|
2803
|
+
appendAudit(storeRoot(), { op: 'capture', outcome: 'skipped', reason: 'short-session-below-threshold', sessionId: session.id, turns: state.turns, everyTurns: options.everyTurns })
|
|
2804
|
+
} catch {
|
|
2805
|
+
/* 状态卸载路径上的审计是尽力而为,不能阻断 */
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
observedSessions.delete(session.id)
|
|
2809
|
+
sessions.delete(session.id)
|
|
2810
|
+
})
|
|
2744
2811
|
|
|
2745
2812
|
queryService = watchOptionalService(ctx, 'sessionQuery', state => {
|
|
2746
2813
|
const available = typeof state.value?.observeSession === 'function'
|
|
@@ -2816,8 +2883,14 @@ export function apply(ctx, config = {}) {
|
|
|
2816
2883
|
}
|
|
2817
2884
|
}
|
|
2818
2885
|
|
|
2886
|
+
const history = setupMemoryHistory(ctx, renderForRuntime)
|
|
2887
|
+
// The host waits for apply(): no contexts, tools or success marker are
|
|
2888
|
+
// published until an asynchronous projection registration has succeeded.
|
|
2889
|
+
return typeof history?.then === 'function' ? history.then(activate) : activate(history)
|
|
2890
|
+
|
|
2891
|
+
function activate(memoryHistory) {
|
|
2892
|
+
if (ctx.fiber?.uid === null) return
|
|
2819
2893
|
let calls = 0
|
|
2820
|
-
const memoryHistory = setupMemoryHistory(ctx, renderForRuntime)
|
|
2821
2894
|
|
|
2822
2895
|
ctx.systemPrompt.context({
|
|
2823
2896
|
name: 'memory:protocol', order: CONTEXT_ORDER - 1, required: true,
|
|
@@ -2922,6 +2995,7 @@ export function apply(ctx, config = {}) {
|
|
|
2922
2995
|
} catch {
|
|
2923
2996
|
/* 写不出来就算了:注入不依赖这两个文件 */
|
|
2924
2997
|
}
|
|
2998
|
+
}
|
|
2925
2999
|
}
|
|
2926
3000
|
|
|
2927
3001
|
installManagedMemoryInternals({indexLine,clearCache:()=>cache.clear(),storeRevision:storeRevisionLocal,withdrawManagedSourceKey:withdrawManagedSourceKeyLocal,recoverMemoryPublication:recoverMemoryPublicationLocal})
|
package/managed-policy.mjs
CHANGED
|
@@ -68,7 +68,9 @@ function openDb(paths,{write=false,requireExisting=false}={}){
|
|
|
68
68
|
}
|
|
69
69
|
const before=lstatSync(path);let db
|
|
70
70
|
try{
|
|
71
|
-
|
|
71
|
+
// Managed reads share the writer lock. Let brief contention clear without
|
|
72
|
+
// releasing transaction ownership or waiting indefinitely.
|
|
73
|
+
db=new DatabaseSync(path,{readOnly:!write});db.exec('PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=750;')
|
|
72
74
|
const now=lstatSync(path);if(now.isSymbolicLink()||now.ino!==before.ino||now.dev!==before.dev)fail('changed-database-file')
|
|
73
75
|
if(created){db.exec('BEGIN IMMEDIATE; '+SCHEMA+'; PRAGMA application_id='+APPLICATION_ID+'; PRAGMA user_version=1; COMMIT;')}
|
|
74
76
|
schema(db)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solopup-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0-beta.1",
|
|
4
4
|
"description": "SoloPup Memory — source-linked, layered text memory for DeepSeek Harness. Public beta.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
@@ -25,131 +25,145 @@
|
|
|
25
25
|
"CHANGELOG.md",
|
|
26
26
|
"scripts/",
|
|
27
27
|
"COMPATIBILITY.md",
|
|
28
|
-
"test.mjs",
|
|
29
|
-
"test-security.mjs",
|
|
30
|
-
"test-adversarial.mjs",
|
|
31
|
-
"test-concurrency.mjs",
|
|
32
|
-
"test-supersede.mjs",
|
|
33
|
-
"test-history.mjs",
|
|
34
|
-
"test-smell.mjs",
|
|
35
|
-
"test-links.mjs",
|
|
36
|
-
"test-packaging.mjs",
|
|
37
|
-
"test-patch.mjs",
|
|
38
|
-
"test-compat.mjs",
|
|
28
|
+
"test/test.mjs",
|
|
29
|
+
"test/test-security.mjs",
|
|
30
|
+
"test/test-adversarial.mjs",
|
|
31
|
+
"test/test-concurrency.mjs",
|
|
32
|
+
"test/test-supersede.mjs",
|
|
33
|
+
"test/test-history.mjs",
|
|
34
|
+
"test/test-smell.mjs",
|
|
35
|
+
"test/test-links.mjs",
|
|
36
|
+
"test/test-packaging.mjs",
|
|
37
|
+
"test/test-patch.mjs",
|
|
38
|
+
"test/test-compat.mjs",
|
|
39
39
|
"accept.mjs",
|
|
40
40
|
"worker-write.mjs",
|
|
41
|
-
"test-conflict.mjs",
|
|
42
|
-
"test-usability.mjs",
|
|
43
|
-
"test-compaction-compat.mjs",
|
|
44
|
-
"test-schema.mjs",
|
|
41
|
+
"test/test-conflict.mjs",
|
|
42
|
+
"test/test-usability.mjs",
|
|
43
|
+
"test/test-compaction-compat.mjs",
|
|
44
|
+
"test/test-schema.mjs",
|
|
45
45
|
"scripts/probe-load.mjs",
|
|
46
46
|
"capture.mjs",
|
|
47
47
|
"capture-llm.mjs",
|
|
48
48
|
"capture-evidence.mjs",
|
|
49
49
|
"capture-revision.mjs",
|
|
50
|
-
"test-capture-revision.mjs",
|
|
51
|
-
"test-capture.mjs",
|
|
52
|
-
"test-paired-analysis.mjs",
|
|
50
|
+
"test/test-capture-revision.mjs",
|
|
51
|
+
"test/test-capture.mjs",
|
|
52
|
+
"test/test-paired-analysis.mjs",
|
|
53
53
|
"retrieval.mjs",
|
|
54
|
-
"test-retrieval.mjs",
|
|
54
|
+
"test/test-retrieval.mjs",
|
|
55
55
|
"candidates.mjs",
|
|
56
|
-
"test-candidates.mjs",
|
|
56
|
+
"test/test-candidates.mjs",
|
|
57
57
|
"publication.mjs",
|
|
58
|
-
"test-publication.mjs",
|
|
58
|
+
"test/test-publication.mjs",
|
|
59
59
|
"withdrawal.mjs",
|
|
60
|
-
"test-withdrawal.mjs",
|
|
60
|
+
"test/test-withdrawal.mjs",
|
|
61
61
|
"capture-jobs.mjs",
|
|
62
|
-
"test-capture-jobs.mjs",
|
|
62
|
+
"test/test-capture-jobs.mjs",
|
|
63
63
|
"context-history.mjs",
|
|
64
|
-
"test-context-history.mjs",
|
|
64
|
+
"test/test-context-history.mjs",
|
|
65
65
|
"capture-inputs.mjs",
|
|
66
|
-
"test-capture-inputs.mjs",
|
|
67
|
-
"test-inline-summary.mjs",
|
|
66
|
+
"test/test-capture-inputs.mjs",
|
|
67
|
+
"test/test-inline-summary.mjs",
|
|
68
68
|
"managed-logs.mjs",
|
|
69
|
-
"test-withdrawal-archives.mjs",
|
|
69
|
+
"test/test-withdrawal-archives.mjs",
|
|
70
70
|
"cordis.patch.yml",
|
|
71
71
|
"plugin-config.mjs",
|
|
72
72
|
"host-services.mjs",
|
|
73
|
-
"test-plugin-contract.mjs",
|
|
73
|
+
"test/test-plugin-contract.mjs",
|
|
74
74
|
"project-stores.mjs",
|
|
75
|
-
"test-project-stores.mjs",
|
|
75
|
+
"test/test-project-stores.mjs",
|
|
76
76
|
"service-readiness.mjs",
|
|
77
|
-
"test-service-readiness.mjs",
|
|
77
|
+
"test/test-service-readiness.mjs",
|
|
78
78
|
"tool-inputs.mjs",
|
|
79
79
|
"fixture-host.mjs",
|
|
80
|
-
"test-source-key.mjs",
|
|
81
|
-
"test-tool-inputs.mjs",
|
|
82
|
-
"test-tool-write-lifecycle.mjs",
|
|
83
|
-
"test-tool-write-guard.mjs",
|
|
80
|
+
"test/test-source-key.mjs",
|
|
81
|
+
"test/test-tool-inputs.mjs",
|
|
82
|
+
"test/test-tool-write-lifecycle.mjs",
|
|
83
|
+
"test/test-tool-write-guard.mjs",
|
|
84
84
|
"source-retirement.mjs",
|
|
85
|
-
"test-source-retirement.mjs",
|
|
85
|
+
"test/test-source-retirement.mjs",
|
|
86
86
|
"managed-policy.mjs",
|
|
87
87
|
"managed-hooks.mjs",
|
|
88
88
|
"managed-access.mjs",
|
|
89
89
|
"store-lock-guard.mjs",
|
|
90
|
-
"test-managed-access.mjs",
|
|
90
|
+
"test/test-managed-access.mjs",
|
|
91
91
|
"managed-activation.mjs",
|
|
92
|
-
"test-managed-activation.mjs",
|
|
92
|
+
"test/test-managed-activation.mjs",
|
|
93
93
|
"runtime-startup.mjs",
|
|
94
|
-
"test-runtime-startup.mjs",
|
|
94
|
+
"test/test-runtime-startup.mjs",
|
|
95
95
|
"meaning.mjs",
|
|
96
|
-
"test-meaning.mjs",
|
|
96
|
+
"test/test-meaning.mjs",
|
|
97
97
|
"episodes.mjs",
|
|
98
98
|
"source-record.mjs",
|
|
99
|
-
"test-episodes.mjs",
|
|
99
|
+
"test/test-episodes.mjs",
|
|
100
100
|
"belief-revision.mjs",
|
|
101
|
-
"test-belief-revision.mjs",
|
|
101
|
+
"test/test-belief-revision.mjs",
|
|
102
102
|
"tool-observations.mjs",
|
|
103
|
-
"test-tool-observations.mjs",
|
|
103
|
+
"test/test-tool-observations.mjs",
|
|
104
104
|
"capture-diagnostics.mjs",
|
|
105
|
-
"test-capture-diagnostics.mjs",
|
|
105
|
+
"test/test-capture-diagnostics.mjs",
|
|
106
106
|
"snapshots.mjs",
|
|
107
|
-
"test-snapshots.mjs",
|
|
107
|
+
"test/test-snapshots.mjs",
|
|
108
108
|
"restore.mjs",
|
|
109
109
|
"restoration-lock.mjs",
|
|
110
|
-
"test-restore.mjs",
|
|
111
|
-
"test-status-both.mjs",
|
|
112
|
-
"test-text-admission.mjs",
|
|
110
|
+
"test/test-restore.mjs",
|
|
111
|
+
"test/test-status-both.mjs",
|
|
112
|
+
"test/test-text-admission.mjs",
|
|
113
113
|
"memory-policy.mjs",
|
|
114
114
|
"capture-submission.mjs",
|
|
115
|
-
"test-capture-submission.mjs",
|
|
115
|
+
"test/test-capture-submission.mjs",
|
|
116
116
|
"capture-projections.mjs",
|
|
117
|
-
"test-capture-projections.mjs",
|
|
117
|
+
"test/test-capture-projections.mjs",
|
|
118
118
|
"capture-validation-contract.mjs",
|
|
119
119
|
"capture-validation.mjs",
|
|
120
|
-
"test-capture-validation.mjs",
|
|
120
|
+
"test/test-capture-validation.mjs",
|
|
121
121
|
"capture-validation-job.mjs",
|
|
122
|
-
"test-capture-validation-job.mjs",
|
|
123
|
-
"test-capture-validation-flow.mjs",
|
|
124
|
-
"test-capture-validation-lineage.mjs",
|
|
122
|
+
"test/test-capture-validation-job.mjs",
|
|
123
|
+
"test/test-capture-validation-flow.mjs",
|
|
124
|
+
"test/test-capture-validation-lineage.mjs",
|
|
125
125
|
"native-write-validation.mjs",
|
|
126
|
-
"test-native-write-validation.mjs",
|
|
127
|
-
"test-native-service-lifecycle.mjs",
|
|
126
|
+
"test/test-native-write-validation.mjs",
|
|
127
|
+
"test/test-native-service-lifecycle.mjs",
|
|
128
128
|
"field-lineage.mjs",
|
|
129
|
-
"test-field-lineage.mjs",
|
|
130
|
-
"test-capture-field-lineage.mjs",
|
|
129
|
+
"test/test-field-lineage.mjs",
|
|
130
|
+
"test/test-capture-field-lineage.mjs",
|
|
131
131
|
"validation-transition-context.mjs",
|
|
132
|
-
"test-validation-transition-context.mjs",
|
|
132
|
+
"test/test-validation-transition-context.mjs",
|
|
133
133
|
"memory-scope-policy.mjs",
|
|
134
134
|
"control-schema.mjs",
|
|
135
|
-
"test-control-schema.mjs",
|
|
135
|
+
"test/test-control-schema.mjs",
|
|
136
136
|
"revision-admission.mjs",
|
|
137
|
-
"test-revision-admission.mjs",
|
|
137
|
+
"test/test-revision-admission.mjs",
|
|
138
138
|
"memory-rule-policy.mjs",
|
|
139
|
-
"test-rule-admission.mjs",
|
|
140
|
-
"test-validation-source-refs.mjs",
|
|
141
|
-
"test-source-completeness.mjs",
|
|
139
|
+
"test/test-rule-admission.mjs",
|
|
140
|
+
"test/test-validation-source-refs.mjs",
|
|
141
|
+
"test/test-source-completeness.mjs",
|
|
142
142
|
"source-identity.mjs",
|
|
143
|
-
"test-legacy-source-identity.mjs",
|
|
143
|
+
"test/test-legacy-source-identity.mjs",
|
|
144
144
|
"icon.svg",
|
|
145
145
|
"locale/",
|
|
146
146
|
"README.en.md",
|
|
147
147
|
"RELEASE.md",
|
|
148
148
|
"memory-protocol.mjs",
|
|
149
149
|
"capture-source-aliases.mjs",
|
|
150
|
-
"test-explicit-memory.mjs",
|
|
150
|
+
"test/test-explicit-memory.mjs",
|
|
151
151
|
"privacy.mjs",
|
|
152
|
-
"test-privacy.mjs"
|
|
152
|
+
"test/test-privacy.mjs",
|
|
153
|
+
"detect.mjs",
|
|
154
|
+
"scripts/detect.mjs",
|
|
155
|
+
"scripts/telemetry.mjs",
|
|
156
|
+
"scripts/dream.mjs",
|
|
157
|
+
"eval/semantic-suite.mjs",
|
|
158
|
+
"eval/semantic/cases.json",
|
|
159
|
+
"eval/bench-detect.mjs",
|
|
160
|
+
"test/test-detect.mjs",
|
|
161
|
+
"test/test-telemetry.mjs",
|
|
162
|
+
"test/test-semantic-suite.mjs",
|
|
163
|
+
"test/test-dream-plan.mjs",
|
|
164
|
+
"DETECTION.md",
|
|
165
|
+
"DREAMING-DESIGN.md",
|
|
166
|
+
"test/test-dsh-registration.mjs"
|
|
153
167
|
],
|
|
154
168
|
"engines": {
|
|
155
169
|
"node": ">=24.9",
|
|
@@ -162,7 +176,7 @@
|
|
|
162
176
|
},
|
|
163
177
|
"license": "MIT",
|
|
164
178
|
"scripts": {
|
|
165
|
-
"test": "node --test --test-concurrency=4 test.mjs test-security.mjs test-adversarial.mjs test-concurrency.mjs test-supersede.mjs test-history.mjs test-smell.mjs test-links.mjs test-packaging.mjs test-patch.mjs test-compat.mjs test-conflict.mjs test-usability.mjs test-compaction-compat.mjs test-schema.mjs test-capture.mjs test-paired-analysis.mjs test-retrieval.mjs test-candidates.mjs test-publication.mjs test-withdrawal.mjs test-capture-jobs.mjs test-context-history.mjs test-capture-inputs.mjs test-inline-summary.mjs test-withdrawal-archives.mjs test-plugin-contract.mjs test-project-stores.mjs test-service-readiness.mjs test-source-key.mjs test-tool-inputs.mjs test-tool-write-lifecycle.mjs test-tool-write-guard.mjs test-source-retirement.mjs test-managed-access.mjs test-managed-activation.mjs test-runtime-startup.mjs test-capture-revision.mjs test-meaning.mjs test-episodes.mjs test-belief-revision.mjs test-tool-observations.mjs test-capture-diagnostics.mjs test-snapshots.mjs test-restore.mjs test-status-both.mjs test-text-admission.mjs test-capture-submission.mjs test-capture-projections.mjs test-capture-validation.mjs test-capture-validation-job.mjs test-capture-validation-flow.mjs test-capture-validation-lineage.mjs test-native-write-validation.mjs test-native-service-lifecycle.mjs test-field-lineage.mjs test-capture-field-lineage.mjs test-validation-transition-context.mjs test-control-schema.mjs test-revision-admission.mjs test-rule-admission.mjs test-validation-source-refs.mjs test-source-completeness.mjs test-legacy-source-identity.mjs test-explicit-memory.mjs test-privacy.mjs",
|
|
179
|
+
"test": "node --test --test-concurrency=4 test/test.mjs test/test-security.mjs test/test-adversarial.mjs test/test-concurrency.mjs test/test-supersede.mjs test/test-history.mjs test/test-smell.mjs test/test-links.mjs test/test-packaging.mjs test/test-patch.mjs test/test-compat.mjs test/test-conflict.mjs test/test-usability.mjs test/test-compaction-compat.mjs test/test-schema.mjs test/test-capture.mjs test/test-paired-analysis.mjs test/test-retrieval.mjs test/test-candidates.mjs test/test-publication.mjs test/test-withdrawal.mjs test/test-capture-jobs.mjs test/test-context-history.mjs test/test-capture-inputs.mjs test/test-inline-summary.mjs test/test-withdrawal-archives.mjs test/test-plugin-contract.mjs test/test-project-stores.mjs test/test-service-readiness.mjs test/test-source-key.mjs test/test-tool-inputs.mjs test/test-tool-write-lifecycle.mjs test/test-tool-write-guard.mjs test/test-source-retirement.mjs test/test-managed-access.mjs test/test-managed-activation.mjs test/test-runtime-startup.mjs test/test-capture-revision.mjs test/test-meaning.mjs test/test-episodes.mjs test/test-belief-revision.mjs test/test-tool-observations.mjs test/test-capture-diagnostics.mjs test/test-snapshots.mjs test/test-restore.mjs test/test-status-both.mjs test/test-text-admission.mjs test/test-capture-submission.mjs test/test-capture-projections.mjs test/test-capture-validation.mjs test/test-capture-validation-job.mjs test/test-capture-validation-flow.mjs test/test-capture-validation-lineage.mjs test/test-native-write-validation.mjs test/test-native-service-lifecycle.mjs test/test-field-lineage.mjs test/test-capture-field-lineage.mjs test/test-validation-transition-context.mjs test/test-control-schema.mjs test/test-revision-admission.mjs test/test-rule-admission.mjs test/test-validation-source-refs.mjs test/test-source-completeness.mjs test/test-legacy-source-identity.mjs test/test-explicit-memory.mjs test/test-privacy.mjs test/test-detect.mjs test/test-telemetry.mjs test/test-semantic-suite.mjs test/test-dream-plan.mjs test/test-dsh-registration.mjs",
|
|
166
180
|
"eval": "node eval/run-eval.mjs",
|
|
167
181
|
"gate": "node eval/run-eval.mjs --check",
|
|
168
182
|
"verify": "node scripts/verify.mjs",
|
|
@@ -172,7 +186,14 @@
|
|
|
172
186
|
"probe:package": "node scripts/probe-package.mjs",
|
|
173
187
|
"projects": "node scripts/projects.mjs",
|
|
174
188
|
"control": "node scripts/control.mjs",
|
|
175
|
-
"backup": "node scripts/backup.mjs"
|
|
189
|
+
"backup": "node scripts/backup.mjs",
|
|
190
|
+
"detect": "node scripts/detect.mjs",
|
|
191
|
+
"telemetry": "node scripts/telemetry.mjs",
|
|
192
|
+
"dream": "node scripts/dream.mjs",
|
|
193
|
+
"semantic": "node eval/semantic-suite.mjs --verbose",
|
|
194
|
+
"security": "node scripts/security-check.mjs",
|
|
195
|
+
"soak": "node scripts/soak.mjs",
|
|
196
|
+
"probe:history": "node scripts/probe-history.mjs"
|
|
176
197
|
},
|
|
177
198
|
"dshMemoryRestoreProtocol": 1,
|
|
178
199
|
"dshMemoryDataSchemas": {
|
package/project-stores.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {managedProjectOperation,registerManagedDestination} from './managed-access.mjs'
|
|
2
2
|
/** Collision-resistant project identity and reviewed, recoverable legacy copying. */
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto'
|
|
4
|
-
import {
|
|
4
|
+
import { execFileSync } from 'node:child_process'
|
|
5
|
+
import { constants, lstatSync, openSync, fstatSync, readFileSync, closeSync, readdirSync, renameSync, mkdirSync, rmSync, realpathSync } from 'node:fs'
|
|
5
6
|
import { join, resolve, dirname } from 'node:path'
|
|
6
7
|
import { readSafely, writeSafely, ensureStoreDir, withLock } from './security.mjs'
|
|
7
8
|
import { assertPublicationClear } from './publication.mjs'
|
|
@@ -102,9 +103,76 @@ function migrationLock(dir, run) {
|
|
|
102
103
|
return withLock(dir, run, { timeoutMs: 0 })
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
// Explicit, same-local-Git-worktree mapping. This does not merge existing stores.
|
|
107
|
+
const WORKTREE_LINKS = '.worktree-links.json'
|
|
108
|
+
function worktreeIdentity(root) {
|
|
109
|
+
try {
|
|
110
|
+
const env = { PATH: process.env.PATH, HOME: process.env.HOME, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0' }
|
|
111
|
+
const output = execFileSync('git', ['-C', root, 'rev-parse', '--path-format=absolute', '--show-toplevel', '--git-common-dir'], { env, encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'pipe'] }).trim().split('\n')
|
|
112
|
+
if (output.length !== 2) fail('worktree-unavailable')
|
|
113
|
+
const [worktree, common] = output.map(path => realpathSync(path))
|
|
114
|
+
if (realpathSync(root) !== worktree) fail('worktree-root-required')
|
|
115
|
+
const commonStat = lstatSync(common, { bigint: true })
|
|
116
|
+
if (!commonStat.isDirectory() || commonStat.isSymbolicLink()) fail('worktree-unavailable')
|
|
117
|
+
const commonId = hash(`${commonStat.dev}:${commonStat.ino}:${commonStat.birthtimeNs}`)
|
|
118
|
+
return { worktree, common, commonId }
|
|
119
|
+
} catch (error) { if (error.message?.startsWith('project-store-')) throw error; fail('worktree-unavailable') }
|
|
120
|
+
}
|
|
121
|
+
function readWorktreeLinks(store) {
|
|
122
|
+
safeAncestors(join(store, 'projects'), store)
|
|
123
|
+
const file = join(store, 'projects', WORKTREE_LINKS)
|
|
124
|
+
let raw
|
|
125
|
+
try { raw = readPrivateFile(file).toString('utf8') } catch (error) { if (error.code === 'ENOENT') return { links: [], revision: digest(null) }; throw error }
|
|
126
|
+
let body
|
|
127
|
+
try { body = JSON.parse(raw) } catch { fail('worktree-links-corrupt') }
|
|
128
|
+
if (body?.schema !== 1 || !Array.isArray(body.links) || body.links.length > 128 || body.links.some(row => !row || Object.keys(row).sort().join('|') !== 'common|commonId|owner|worktree' || !hex(row.commonId) || !['common','owner','worktree'].every(key => typeof row[key] === 'string' && row[key].startsWith('/') && resolve(row[key]) === row[key])) || new Set(body.links.map(row => row.worktree)).size !== body.links.length) fail('worktree-links-corrupt')
|
|
129
|
+
return { links: body.links, revision: hash(raw) }
|
|
130
|
+
}
|
|
131
|
+
function linkedRoot(store, root) {
|
|
132
|
+
const links = readWorktreeLinks(store).links, physical = (() => { try { return realpathSync(root) } catch { return resolve(root) } })()
|
|
133
|
+
const link = links.find(row => row.worktree === physical)
|
|
134
|
+
if (!link) return root
|
|
135
|
+
const worker = worktreeIdentity(link.worktree), owner = worktreeIdentity(link.owner)
|
|
136
|
+
if (worker.common !== link.common || owner.common !== link.common || worker.commonId !== link.commonId || owner.commonId !== link.commonId || links.some(row => row.worktree === link.owner)) fail('worktree-link-changed')
|
|
137
|
+
const old = paths(store, link.worktree)
|
|
138
|
+
if (directory(old.target) || directory(old.legacy) || readClaim(old).value) fail('worktree-link-conflict')
|
|
139
|
+
return link.owner
|
|
140
|
+
}
|
|
141
|
+
function unlinkWorktreeLocal(store, worktree, options = {}) {
|
|
142
|
+
if (options.apply !== undefined && typeof options.apply !== 'boolean') fail('invalid-apply')
|
|
143
|
+
let physical
|
|
144
|
+
try { physical = realpathSync(worktree) } catch { physical = resolve(worktree) }
|
|
145
|
+
const current = readWorktreeLinks(store), row = current.links.find(link => link.worktree === physical)
|
|
146
|
+
if (!row) fail('worktree-link-not-found')
|
|
147
|
+
const review = digest({ revision: current.revision, unlink: row })
|
|
148
|
+
if (options.apply !== true) return { applied: false, worktree: row.worktree, owner: row.owner, reviewed: review }
|
|
149
|
+
if (options.reviewed !== review) fail('stale-worktree-link-review')
|
|
150
|
+
writeSafely(join(store, 'projects', WORKTREE_LINKS), JSON.stringify({ schema: 1, links: current.links.filter(link => link.worktree !== physical) }) + '\n')
|
|
151
|
+
return { applied: true, worktree: row.worktree, owner: row.owner, memoryDeleted: false }
|
|
152
|
+
}
|
|
153
|
+
function linkWorktreeLocal(store, worktree, owner, options = {}) {
|
|
154
|
+
if (options.apply !== undefined && typeof options.apply !== 'boolean') fail('invalid-apply')
|
|
155
|
+
const a = worktreeIdentity(worktree), b = worktreeIdentity(owner)
|
|
156
|
+
if (a.worktree === b.worktree || a.common !== b.common || a.commonId !== b.commonId) fail('worktree-not-same-repository')
|
|
157
|
+
const links = readWorktreeLinks(store), prior = links.links.find(row => row.worktree === a.worktree)
|
|
158
|
+
if (links.links.some(row => row.worktree === b.worktree) || links.links.some(row => row.owner === a.worktree)) fail('worktree-link-chain')
|
|
159
|
+
if (prior && (prior.owner !== b.worktree || prior.common !== a.common || prior.commonId !== a.commonId)) fail('worktree-link-conflict')
|
|
160
|
+
const old = paths(store, a.worktree), ownerPaths = paths(store, b.worktree)
|
|
161
|
+
if (directory(old.target) || directory(old.legacy) || readClaim(old).value) fail('worktree-link-conflict')
|
|
162
|
+
if (!directory(ownerPaths.target)) fail('worktree-owner-store-missing')
|
|
163
|
+
projectStoreDirLocal(store, b.worktree)
|
|
164
|
+
const review = digest({ revision: links.revision, worktree: a, owner: b })
|
|
165
|
+
if (options.apply !== true) return { applied: false, worktree: a.worktree, owner: b.worktree, reviewed: review, alreadyLinked: Boolean(prior) }
|
|
166
|
+
if (options.reviewed !== review) fail('stale-worktree-link-review')
|
|
167
|
+
if (prior) return { applied: false, alreadyLinked: true, worktree: a.worktree, owner: b.worktree }
|
|
168
|
+
ensureStoreDir(join(store, 'projects'))
|
|
169
|
+
writeSafely(join(store, 'projects', WORKTREE_LINKS), JSON.stringify({ schema: 1, links: [...links.links, { worktree: a.worktree, owner: b.worktree, common: a.common, commonId: a.commonId }] }) + '\n')
|
|
170
|
+
return { applied: true, worktree: a.worktree, owner: b.worktree }
|
|
171
|
+
}
|
|
172
|
+
|
|
105
173
|
/** No mkdir or metadata writes on normal lookup. Never read an ambiguous old store. */
|
|
106
174
|
function projectStoreDirLocal(store, root) {
|
|
107
|
-
const p = paths(store, root), claim = readClaim(p).value
|
|
175
|
+
const p = paths(store, linkedRoot(store, root)), claim = readClaim(p).value
|
|
108
176
|
if (directory(p.target) && lstatExists(join(p.target, IDENTITY)) && !identityMatches(p)) fail('identity-mismatch')
|
|
109
177
|
if (claim?.projectId === p.id) {
|
|
110
178
|
if (claim.state !== 'complete') fail('migration-needs-recovery')
|
|
@@ -120,9 +188,10 @@ function lstatExists(path) {
|
|
|
120
188
|
}
|
|
121
189
|
|
|
122
190
|
function inspectProjectStoreLocal(store, root) {
|
|
123
|
-
const
|
|
191
|
+
const effectiveRoot = linkedRoot(store, root)
|
|
192
|
+
const p = paths(store, effectiveRoot), claim = readClaim(p), source = tree(p.legacy), targetExists = directory(p.target)
|
|
124
193
|
if (source) assertPublicationClear(p.legacy)
|
|
125
|
-
return { applied: false, projectId: p.id, legacyDir: p.legacy, targetDir: p.target, reviewedClaim: claim.revision,
|
|
194
|
+
return { applied: false, ...(effectiveRoot !== root ? { linkedWorktree: resolve(root), linkedOwner: effectiveRoot } : {}), projectId: p.id, legacyDir: p.legacy, targetDir: p.target, reviewedClaim: claim.revision,
|
|
126
195
|
reviewedTree: source?.sha256, files: source?.files.length ?? 0, bytes: source?.bytes ?? 0, targetExists,
|
|
127
196
|
state: claim.value ? claim.value.projectId !== p.id ? 'legacy-owned-by-another-project' : claim.value.state === 'prepared' ? 'needs-recovery' : 'migrated' : source ? 'legacy-needs-review' : 'fresh',
|
|
128
197
|
sourceChangedSinceMigration: claim.value?.projectId === p.id && source ? source.sha256 !== claim.value.sourceHash : false }
|
|
@@ -130,6 +199,7 @@ function inspectProjectStoreLocal(store, root) {
|
|
|
130
199
|
|
|
131
200
|
/** Copies, never merges or deletes the old library. Both revisions are required. */
|
|
132
201
|
function migrateProjectStoreLocal(store, root, options = {}) {
|
|
202
|
+
if (linkedRoot(store, root) !== root) fail('worktree-unlink-before-migration')
|
|
133
203
|
if (options.apply !== undefined && typeof options.apply !== 'boolean') fail('invalid-apply')
|
|
134
204
|
if (options.apply !== true) return inspectProjectStore(store, root)
|
|
135
205
|
const p = paths(store, root)
|
|
@@ -179,6 +249,7 @@ function migrateProjectStoreLocal(store, root, options = {}) {
|
|
|
179
249
|
}
|
|
180
250
|
|
|
181
251
|
function recoverProjectStoreLocal(store, root, options = {}) {
|
|
252
|
+
if (linkedRoot(store, root) !== root) fail('worktree-unlink-before-migration')
|
|
182
253
|
if (options.apply !== undefined && typeof options.apply !== 'boolean') fail('invalid-apply')
|
|
183
254
|
const p = paths(store, root), claim = readClaim(p)
|
|
184
255
|
if (!claim.value || claim.value.projectId !== p.id) fail('no-owned-migration')
|
|
@@ -220,3 +291,11 @@ export function projectStoreDir(store,...args){return managedProjectOperation(st
|
|
|
220
291
|
export function inspectProjectStore(store,...args){return managedProjectOperation(store,()=>inspectProjectStoreLocal(store,...args))}
|
|
221
292
|
export function migrateProjectStore(store,root,options={}){return managedProjectOperation(store,()=>options.apply===true?finishManagedMigration(store,root,()=>migrateProjectStoreLocal(store,root,options)):migrateProjectStoreLocal(store,root,options),{write:options.apply===true})}
|
|
222
293
|
export function recoverProjectStore(store,root,options={}){return managedProjectOperation(store,()=>options.apply===true?finishManagedMigration(store,root,()=>recoverProjectStoreLocal(store,root,options)):recoverProjectStoreLocal(store,root,options),{write:options.apply===true})}
|
|
294
|
+
|
|
295
|
+
function changeWorktreeLinks(store, run) {
|
|
296
|
+
const dir = join(store, 'projects')
|
|
297
|
+
safeAncestors(dir, store); ensureStoreDir(dir)
|
|
298
|
+
return migrationLock(dir, run)
|
|
299
|
+
}
|
|
300
|
+
export function linkWorktreeProject(store,worktree,owner,options={}){return managedProjectOperation(store,()=>options.apply===true?changeWorktreeLinks(store,()=>linkWorktreeLocal(store,worktree,owner,options)):linkWorktreeLocal(store,worktree,owner,options),{write:options.apply===true})}
|
|
301
|
+
export function unlinkWorktreeProject(store,worktree,options={}){return managedProjectOperation(store,()=>options.apply===true?changeWorktreeLinks(store,()=>unlinkWorktreeLocal(store,worktree,options)):unlinkWorktreeLocal(store,worktree,options),{write:options.apply===true})}
|