@sanqianx/project-knowledge 5.0.19 → 5.0.20-rc.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/.agents/plugins/marketplace.json +3 -3
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +5 -0
- package/LICENSE +201 -201
- package/NOTICE +5 -5
- package/README.md +349 -349
- package/_modules/knowledge-engine/README.md +4 -0
- package/_modules/knowledge-engine/src/analysis-failures.js +39 -0
- package/_modules/knowledge-engine/src/analysis-worker.js +6 -2
- package/_modules/knowledge-engine/src/coordinator.js +7 -0
- package/_modules/knowledge-engine/src/headless-analyzer.js +2 -1
- package/_modules/knowledge-engine/src/server.js +1 -1
- package/_site/_test/agent-capture-mcp-ui-test.js +67 -67
- package/_site/_test/ai-profile-test.js +75 -75
- package/_site/_test/ai-vendor-presets-test.js +91 -91
- package/_site/_test/automatic-context-test.js +70 -70
- package/_site/_test/bin-cli-test.js +230 -230
- package/_site/_test/bridge-adapter-test.js +95 -95
- package/_site/_test/bridge-consumer-service-test.js +310 -310
- package/_site/_test/candidate-bin-content-test.js +35 -35
- package/_site/_test/candidate-product-assets-test.js +13 -13
- package/_site/_test/candidate-release-contract-test.js +14 -14
- package/_site/_test/capture-hook-dedup-test.js +158 -158
- package/_site/_test/claude-executable-discovery-test.js +28 -28
- package/_site/_test/claude-session-lifecycle-sweep-test.js +252 -252
- package/_site/_test/cli-instance-management-test.js +62 -62
- package/_site/_test/client-capture-restart-e2e-test.js +189 -189
- package/_site/_test/codex-conversation-projection-test.js +60 -60
- package/_site/_test/codex-marketplace-scoped-path-test.js +186 -186
- package/_site/_test/codex-notify-capture-e2e-test.js +101 -101
- package/_site/_test/codex-notify-fanout-test.js +134 -134
- package/_site/_test/codex-notify-upgrade-test.js +253 -253
- package/_site/_test/commit-boundary-freeze-test.js +147 -147
- package/_site/_test/commit-conversation-binding-test.js +4 -4
- package/_site/_test/configuration-generation-test.js +22 -22
- package/_site/_test/context-pack-test.js +200 -200
- package/_site/_test/conversation-api-test.js +10 -10
- package/_site/_test/conversation-origin-test.js +15 -15
- package/_site/_test/cross-repo-isolation-e2e-test.js +187 -187
- package/_site/_test/embedding-config-test.js +32 -32
- package/_site/_test/fixtures/fake-browser-exit.js +10 -10
- package/_site/_test/fixtures/fake-browser-hang.js +10 -10
- package/_site/_test/fixtures/integration-busy-worker.cjs +6 -6
- package/_site/_test/fixtures/make-git-repos.js +92 -92
- package/_site/_test/fixtures/retrieval-gold-queries.json +32 -32
- package/_site/_test/fresh-hook-reimport-test.js +53 -53
- package/_site/_test/fresh-product-data-test.js +56 -56
- package/_site/_test/git-path-compatibility-test.js +80 -80
- package/_site/_test/git-validation-test.js +81 -81
- package/_site/_test/hook-worktree-test.js +42 -42
- package/_site/_test/index-builder-test.js +41 -41
- package/_site/_test/index-error-display-contract-test.js +10 -10
- package/_site/_test/integration-adapters-test.js +67 -67
- package/_site/_test/integration-capture-setup-test.js +118 -118
- package/_site/_test/integration-runtime-binding-a2-test.js +566 -566
- package/_site/_test/integration-runtime-binding-a3-test.js +227 -227
- package/_site/_test/integration-runtime-binding-test.js +473 -473
- package/_site/_test/integration-status-scan-test.js +29 -29
- package/_site/_test/kb-framework-test.js +57 -57
- package/_site/_test/kbpath-follow-test.js +63 -63
- package/_site/_test/knowledge-db-test.js +144 -144
- package/_site/_test/knowledge-engine-client-test.js +109 -109
- package/_site/_test/knowledge-maintenance-test.js +40 -40
- package/_site/_test/knowledge-panel-ui-contract-test.js +112 -0
- package/_site/_test/knowledge-scopes-test.js +37 -37
- package/_site/_test/knowledge-storage-location-test.js +28 -28
- package/_site/_test/launcher-readiness-test.js +80 -80
- package/_site/_test/legacy-claude-session-alias-test.js +106 -106
- package/_site/_test/legacy-routes-removed-test.js +47 -47
- package/_site/_test/legacy-workbench-exclusion-test.js +92 -92
- package/_site/_test/live-gateway-test.js +48 -48
- package/_site/_test/local-marketplace-test.js +16 -16
- package/_site/_test/log-redaction-test.js +58 -58
- package/_site/_test/markdown-maintenance-test.js +11 -11
- package/_site/_test/model-context-windows-test.js +89 -89
- package/_site/_test/module-agent-start-proxy-test.js +65 -65
- package/_site/_test/module-artifact-integrity-test.js +27 -27
- package/_site/_test/module-boundary-test.js +30 -30
- package/_site/_test/module-bridge-eventbridge-test.js +202 -202
- package/_site/_test/module-dynamic-port-test.js +118 -118
- package/_site/_test/module-index-proxy-test.js +33 -33
- package/_site/_test/module-model-configuration-test.js +44 -44
- package/_site/_test/module-process-lifecycle-test.js +35 -35
- package/_site/_test/module-stream-proxy-test.js +34 -34
- package/_site/_test/module-terminal-restart-test.js +63 -63
- package/_site/_test/module-wiring-unbind-race-test.js +59 -59
- package/_site/_test/native-context-integrations-test.js +86 -86
- package/_site/_test/orphaned-claim-recovery-test.js +80 -80
- package/_site/_test/package-boundary-test.js +43 -42
- package/_site/_test/package-startup-test.js +56 -56
- package/_site/_test/packaged-ui-smoke-test.js +88 -88
- package/_site/_test/pr-consumer-contract-test.js +55 -55
- package/_site/_test/product-brand-contract-test.js +25 -25
- package/_site/_test/product-diagnostics-ui-test.js +93 -93
- package/_site/_test/product-import-ui-test.js +104 -104
- package/_site/_test/product-progress-status-test.js +12 -1
- package/_site/_test/project-remove-running-guard-test.js +79 -79
- package/_site/_test/project-store-test.js +90 -90
- package/_site/_test/registry-events-test.js +38 -38
- package/_site/_test/release-version-sync-test.js +115 -115
- package/_site/_test/requirement-binding-test.js +113 -113
- package/_site/_test/runtime-endpoint-test.js +64 -64
- package/_site/_test/scanner-test.js +83 -83
- package/_site/_test/server-security-test.js +96 -96
- package/_site/_test/sessions-stream-test.js +93 -93
- package/_site/_test/shared-scope-root-binding-test.js +67 -67
- package/_site/_test/simple-import-test.js +98 -98
- package/_site/_test/startup-analysis-disabled-test.js +6 -6
- package/_site/_test/team-knowledge-store-sparse-checkout-test.js +196 -196
- package/_site/_test/team-knowledge-store-test.js +132 -132
- package/_site/_test/test-server-cleanup-test.js +35 -35
- package/_site/_test/test-server-module-isolation-test.js +37 -37
- package/_site/_test/tracking-start-test.js +35 -35
- package/_site/_test/workbench-context-receipts-test.js +22 -22
- package/_site/_test/workspace-ui-contract-test.js +31 -31
- package/_site/_test/zcode-capture-integration-test.js +108 -108
- package/_site/lib/ai-vendor-presets.js +83 -83
- package/_site/lib/ai-workspace.js +3 -3
- package/_site/lib/atomic-file.js +204 -204
- package/_site/lib/bridge-adapter.js +260 -260
- package/_site/lib/capture-hook-config.js +108 -108
- package/_site/lib/claude-cli-runner.js +89 -89
- package/_site/lib/cli-instances.js +43 -43
- package/_site/lib/codex-context-status.js +17 -17
- package/_site/lib/codex-notify-config.js +193 -193
- package/_site/lib/commit-conversation-binder.js +12 -12
- package/_site/lib/commit-reconciler.js +38 -38
- package/_site/lib/context-pack-builder.js +299 -299
- package/_site/lib/conversation-exclusions.js +204 -204
- package/_site/lib/conversation-query-service.js +17 -17
- package/_site/lib/data-dir.js +13 -13
- package/_site/lib/embedding-service.js +85 -85
- package/_site/lib/engine-connection.js +93 -93
- package/_site/lib/engine-knowledge-client.js +72 -72
- package/_site/lib/folder-picker-output.js +3 -3
- package/_site/lib/git-path.js +14 -14
- package/_site/lib/github-team-store.js +3 -3
- package/_site/lib/index-builder.js +157 -157
- package/_site/lib/integration-status-scan.js +99 -99
- package/_site/lib/integration-status-worker.js +14 -14
- package/_site/lib/kb-framework.js +15 -15
- package/_site/lib/knowledge-db.js +363 -363
- package/_site/lib/knowledge-schema.js +121 -121
- package/_site/lib/live-gateway.js +78 -78
- package/_site/lib/llm-client.js +12 -12
- package/_site/lib/model-context-windows.js +82 -82
- package/_site/lib/module-bridge.js +874 -874
- package/_site/lib/module-port-resolver.js +57 -57
- package/_site/lib/post-commit-automation.js +54 -54
- package/_site/lib/product-data.js +35 -35
- package/_site/lib/project-lifecycle-service.js +14 -14
- package/_site/lib/project-registry-store.js +129 -129
- package/_site/lib/prompt-registry.js +148 -148
- package/_site/lib/registry-events.js +16 -16
- package/_site/lib/requirement-adapters.js +10 -10
- package/_site/lib/requirement-binder.js +112 -112
- package/_site/lib/runtime-control.js +89 -89
- package/_site/lib/runtime-endpoint.js +5 -5
- package/_site/lib/zcode-context-integration.js +60 -60
- package/_site/scripts/codex-notify-fanout.cjs +95 -95
- package/_site/scripts/install-module-candidates.js +69 -69
- package/_site/scripts/pack-module-candidates.js +89 -89
- package/_site/scripts/sync-product-content.js +28 -28
- package/_site/scripts/sync-release-version.js +164 -164
- package/_site/scripts/vendor-modules.js +49 -49
- package/_site/scripts/verify-module-runtime.js +50 -50
- package/_site/scripts/verify-product-runtime.js +36 -36
- package/_site/scripts/verify-retrieval-gold.js +83 -83
- package/_site/server.js +15 -15
- package/_site/start.bat +26 -26
- package/_site/stop.bat +11 -11
- package/bin/project-knowledge-integrations.js +254 -254
- package/bin/project-knowledge-kb.js +67 -67
- package/bin/project-knowledge-mcp.js +8 -8
- package/bin/project-knowledge.js +170 -170
- package/claude-prompts.json +21 -21
- package/docs/README.zh-CN.md +205 -205
- package/docs/assets/architecture.svg +181 -181
- package/docs/assets/logo.svg +49 -49
- package/docs/fresh-v5-start.md +42 -42
- package/docs/leader-glm-workbench-playbook.md +122 -122
- package/docs/project-registry-schema.md +11 -11
- package/docs/release-5.0.16-acceptance.md +176 -176
- package/docs/release-5.0.17-acceptance.md +117 -117
- package/docs/release-5.0.19-acceptance.md +39 -25
- package/docs/team-knowledge-mode-a-plan.md +73 -73
- package/module-runtime-manifest.json +53 -33
- package/package.json +3 -2
- 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/change.md +30 -30
- package/templates/project-readme.md +18 -18
- package/ui/index.html +1 -1
- package/ui/knowledge-panel.html +118 -0
- package/ui/product.css +8 -0
- package/ui/product.js +146 -4
- package/vendor-manifest.json +55 -54
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Dynamic module URL resolution.
|
|
4
|
-
//
|
|
5
|
-
// Managed modules used to bind fixed default ports (terminal 5760,
|
|
6
|
-
// vector-hub 8787, event-bridge 8790, engine 5790). When a foreign process
|
|
7
|
-
// occupied one of those ports the module crash-looped and the feature stayed
|
|
8
|
-
// degraded. This resolver picks the final URL BEFORE any module is spawned:
|
|
9
|
-
//
|
|
10
|
-
// explicit env/option URL -> external service, untouched (legacy behavior)
|
|
11
|
-
// healthy identity match -> reused (standalone module keeps running)
|
|
12
|
-
// otherwise -> first free port from preferred +0..+19
|
|
13
|
-
// all busy -> NO_FREE_MODULE_PORT (loud, never silent)
|
|
14
|
-
|
|
15
|
-
function invalidUrl(value) {
|
|
16
|
-
return Object.assign(new Error(`Invalid module URL: ${value}`), { code: 'INVALID_MODULE_URL' });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function parsePreferredUrl(value) {
|
|
20
|
-
let parsed;
|
|
21
|
-
try { parsed = new URL(String(value)); } catch { throw invalidUrl(value); }
|
|
22
|
-
const port = Number(parsed.port);
|
|
23
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) throw invalidUrl(value);
|
|
24
|
-
return { parsed, port };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function rebuildUrl(parsed, port) {
|
|
28
|
-
const host = parsed.hostname.includes(':') ? `[${parsed.hostname}]` : parsed.hostname;
|
|
29
|
-
return `${parsed.protocol}//${host}:${port}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {object} options
|
|
34
|
-
* @param {string} options.kind module kind, used in errors/logs only
|
|
35
|
-
* @param {string} options.preferredUrl default URL with an explicit port
|
|
36
|
-
* @param {boolean} options.explicit true when the URL was injected explicitly
|
|
37
|
-
* @param {(port: number) => Promise<boolean>} options.portFree TCP bind probe
|
|
38
|
-
* @param {(url: string) => Promise<'module'|'foreign'|'unreachable'>} options.probe
|
|
39
|
-
* @param {number} [options.scanRange] candidate count starting at the preferred port
|
|
40
|
-
* @returns {Promise<{url: string, source: 'external'|'reused'|'dynamic', port: number, offset: number}>}
|
|
41
|
-
*/
|
|
42
|
-
async function resolveModuleUrl({ kind, preferredUrl, explicit, portFree, probe, scanRange = 20 }) {
|
|
43
|
-
const { parsed, port } = parsePreferredUrl(preferredUrl);
|
|
44
|
-
if (explicit) return { url: preferredUrl, source: 'external', port, offset: 0 };
|
|
45
|
-
if (await probe(preferredUrl) === 'module') return { url: preferredUrl, source: 'reused', port, offset: 0 };
|
|
46
|
-
const range = Math.max(1, Number.isInteger(scanRange) ? scanRange : 20);
|
|
47
|
-
for (let offset = 0; offset < range && port + offset <= 65535; offset++) {
|
|
48
|
-
const candidate = port + offset;
|
|
49
|
-
if (await portFree(candidate)) {
|
|
50
|
-
return { url: rebuildUrl(parsed, candidate), source: 'dynamic', port: candidate, offset };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const last = Math.min(port + range - 1, 65535);
|
|
54
|
-
throw Object.assign(new Error(`No free port found for ${kind} in ${port}-${last}.`), { code: 'NO_FREE_MODULE_PORT' });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = { resolveModuleUrl };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Dynamic module URL resolution.
|
|
4
|
+
//
|
|
5
|
+
// Managed modules used to bind fixed default ports (terminal 5760,
|
|
6
|
+
// vector-hub 8787, event-bridge 8790, engine 5790). When a foreign process
|
|
7
|
+
// occupied one of those ports the module crash-looped and the feature stayed
|
|
8
|
+
// degraded. This resolver picks the final URL BEFORE any module is spawned:
|
|
9
|
+
//
|
|
10
|
+
// explicit env/option URL -> external service, untouched (legacy behavior)
|
|
11
|
+
// healthy identity match -> reused (standalone module keeps running)
|
|
12
|
+
// otherwise -> first free port from preferred +0..+19
|
|
13
|
+
// all busy -> NO_FREE_MODULE_PORT (loud, never silent)
|
|
14
|
+
|
|
15
|
+
function invalidUrl(value) {
|
|
16
|
+
return Object.assign(new Error(`Invalid module URL: ${value}`), { code: 'INVALID_MODULE_URL' });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parsePreferredUrl(value) {
|
|
20
|
+
let parsed;
|
|
21
|
+
try { parsed = new URL(String(value)); } catch { throw invalidUrl(value); }
|
|
22
|
+
const port = Number(parsed.port);
|
|
23
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw invalidUrl(value);
|
|
24
|
+
return { parsed, port };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function rebuildUrl(parsed, port) {
|
|
28
|
+
const host = parsed.hostname.includes(':') ? `[${parsed.hostname}]` : parsed.hostname;
|
|
29
|
+
return `${parsed.protocol}//${host}:${port}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {object} options
|
|
34
|
+
* @param {string} options.kind module kind, used in errors/logs only
|
|
35
|
+
* @param {string} options.preferredUrl default URL with an explicit port
|
|
36
|
+
* @param {boolean} options.explicit true when the URL was injected explicitly
|
|
37
|
+
* @param {(port: number) => Promise<boolean>} options.portFree TCP bind probe
|
|
38
|
+
* @param {(url: string) => Promise<'module'|'foreign'|'unreachable'>} options.probe
|
|
39
|
+
* @param {number} [options.scanRange] candidate count starting at the preferred port
|
|
40
|
+
* @returns {Promise<{url: string, source: 'external'|'reused'|'dynamic', port: number, offset: number}>}
|
|
41
|
+
*/
|
|
42
|
+
async function resolveModuleUrl({ kind, preferredUrl, explicit, portFree, probe, scanRange = 20 }) {
|
|
43
|
+
const { parsed, port } = parsePreferredUrl(preferredUrl);
|
|
44
|
+
if (explicit) return { url: preferredUrl, source: 'external', port, offset: 0 };
|
|
45
|
+
if (await probe(preferredUrl) === 'module') return { url: preferredUrl, source: 'reused', port, offset: 0 };
|
|
46
|
+
const range = Math.max(1, Number.isInteger(scanRange) ? scanRange : 20);
|
|
47
|
+
for (let offset = 0; offset < range && port + offset <= 65535; offset++) {
|
|
48
|
+
const candidate = port + offset;
|
|
49
|
+
if (await portFree(candidate)) {
|
|
50
|
+
return { url: rebuildUrl(parsed, candidate), source: 'dynamic', port: candidate, offset };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const last = Math.min(port + range - 1, 65535);
|
|
54
|
+
throw Object.assign(new Error(`No free port found for ${kind} in ${port}-${last}.`), { code: 'NO_FREE_MODULE_PORT' });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { resolveModuleUrl };
|
|
@@ -77,7 +77,7 @@ async function handlePostCommitEvent(event = {}, deps = {}) {
|
|
|
77
77
|
return reconciler.processCommitEvent({ projectId, commitSha, branch: event.branch || '', operationId: deps.operationId || event.operationId || '' });
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function cleanupOrphanedRuns(_projects, deps = {}) {
|
|
80
|
+
function cleanupOrphanedRuns(_projects, deps = {}) {
|
|
81
81
|
if (!deps.projectStore && !deps.registryStore && !deps.layout) {
|
|
82
82
|
return { activeClaims: 0, recoveredFromFrozenClaims: 0, legacyStoreSkipped: true };
|
|
83
83
|
}
|
|
@@ -86,56 +86,56 @@ function cleanupOrphanedRuns(_projects, deps = {}) {
|
|
|
86
86
|
for (const projectId of resolved.registryStore.listIds()) {
|
|
87
87
|
if (resolved.projectStore.readState(projectId).analysis.activeClaim) activeClaims += 1;
|
|
88
88
|
}
|
|
89
|
-
return { activeClaims, recoveredFromFrozenClaims: activeClaims };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async function recoverOrphanedClaims(deps = {}) {
|
|
93
|
-
const resolved = stores(deps);
|
|
94
|
-
const recovered = [];
|
|
95
|
-
for (const projectId of resolved.registryStore.listIds()) {
|
|
96
|
-
const state = resolved.projectStore.readState(projectId);
|
|
97
|
-
const orphaned = state.analysis.activeClaim;
|
|
98
|
-
if (!orphaned) continue;
|
|
99
|
-
if (orphaned.phase === 'failed' && orphaned.error && orphaned.error.code === 'ORPHANED_CLAIM') continue;
|
|
100
|
-
const recoveredAt = typeof deps.now === 'function' ? deps.now() : new Date().toISOString();
|
|
101
|
-
const error = {
|
|
102
|
-
code: 'ORPHANED_CLAIM',
|
|
103
|
-
message: 'Commit analysis was interrupted by a previous process exit.',
|
|
104
|
-
phase: String(orphaned.phase || state.analysis.status || 'unknown'),
|
|
105
|
-
retryable: false,
|
|
106
|
-
ts: recoveredAt,
|
|
107
|
-
};
|
|
108
|
-
await resolved.projectStore.updateState(projectId, draft => {
|
|
109
|
-
if (!draft.analysis.activeClaim) return;
|
|
110
|
-
draft.analysis.activeClaim.phase = 'failed';
|
|
111
|
-
draft.analysis.activeClaim.error = error;
|
|
112
|
-
draft.analysis.status = 'failed';
|
|
113
|
-
draft.analysis.lastError = error;
|
|
114
|
-
}, { expectedRevision: state.revision });
|
|
115
|
-
recovered.push({
|
|
116
|
-
projectId,
|
|
117
|
-
commitSha: String(orphaned.commitSha || ''),
|
|
118
|
-
runId: String(orphaned.runId || ''),
|
|
119
|
-
previousPhase: error.phase,
|
|
120
|
-
});
|
|
121
|
-
if (deps.logger && typeof deps.logger.warn === 'function') {
|
|
122
|
-
await deps.logger.warn('reconcile.orphaned_claim_recovered', 'An interrupted commit claim was made terminal without retrying analysis.', {
|
|
123
|
-
projectId,
|
|
124
|
-
commitSha: String(orphaned.commitSha || ''),
|
|
125
|
-
runId: String(orphaned.runId || ''),
|
|
126
|
-
phase: 'recovery',
|
|
127
|
-
context: { previousPhase: error.phase },
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return recovered;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
module.exports = {
|
|
135
|
-
CommitReconciler,
|
|
136
|
-
cleanupOrphanedRuns,
|
|
137
|
-
handlePostCommitEvent,
|
|
138
|
-
recoverOrphanedClaims,
|
|
139
|
-
reconcileProjectCommits,
|
|
140
|
-
renderCommitPrompt,
|
|
141
|
-
};
|
|
89
|
+
return { activeClaims, recoveredFromFrozenClaims: activeClaims };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function recoverOrphanedClaims(deps = {}) {
|
|
93
|
+
const resolved = stores(deps);
|
|
94
|
+
const recovered = [];
|
|
95
|
+
for (const projectId of resolved.registryStore.listIds()) {
|
|
96
|
+
const state = resolved.projectStore.readState(projectId);
|
|
97
|
+
const orphaned = state.analysis.activeClaim;
|
|
98
|
+
if (!orphaned) continue;
|
|
99
|
+
if (orphaned.phase === 'failed' && orphaned.error && orphaned.error.code === 'ORPHANED_CLAIM') continue;
|
|
100
|
+
const recoveredAt = typeof deps.now === 'function' ? deps.now() : new Date().toISOString();
|
|
101
|
+
const error = {
|
|
102
|
+
code: 'ORPHANED_CLAIM',
|
|
103
|
+
message: 'Commit analysis was interrupted by a previous process exit.',
|
|
104
|
+
phase: String(orphaned.phase || state.analysis.status || 'unknown'),
|
|
105
|
+
retryable: false,
|
|
106
|
+
ts: recoveredAt,
|
|
107
|
+
};
|
|
108
|
+
await resolved.projectStore.updateState(projectId, draft => {
|
|
109
|
+
if (!draft.analysis.activeClaim) return;
|
|
110
|
+
draft.analysis.activeClaim.phase = 'failed';
|
|
111
|
+
draft.analysis.activeClaim.error = error;
|
|
112
|
+
draft.analysis.status = 'failed';
|
|
113
|
+
draft.analysis.lastError = error;
|
|
114
|
+
}, { expectedRevision: state.revision });
|
|
115
|
+
recovered.push({
|
|
116
|
+
projectId,
|
|
117
|
+
commitSha: String(orphaned.commitSha || ''),
|
|
118
|
+
runId: String(orphaned.runId || ''),
|
|
119
|
+
previousPhase: error.phase,
|
|
120
|
+
});
|
|
121
|
+
if (deps.logger && typeof deps.logger.warn === 'function') {
|
|
122
|
+
await deps.logger.warn('reconcile.orphaned_claim_recovered', 'An interrupted commit claim was made terminal without retrying analysis.', {
|
|
123
|
+
projectId,
|
|
124
|
+
commitSha: String(orphaned.commitSha || ''),
|
|
125
|
+
runId: String(orphaned.runId || ''),
|
|
126
|
+
phase: 'recovery',
|
|
127
|
+
context: { previousPhase: error.phase },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return recovered;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = {
|
|
135
|
+
CommitReconciler,
|
|
136
|
+
cleanupOrphanedRuns,
|
|
137
|
+
handlePostCommitEvent,
|
|
138
|
+
recoverOrphanedClaims,
|
|
139
|
+
reconcileProjectCommits,
|
|
140
|
+
renderCommitPrompt,
|
|
141
|
+
};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const AtomicFile = require('./atomic-file');
|
|
4
|
-
const { DomainError } = require('./contracts');
|
|
5
|
-
|
|
6
|
-
const DATA_SCHEMA = 'project-knowledge/fresh-product-data/v1';
|
|
7
|
-
|
|
8
|
-
function hasData(file) {
|
|
9
|
-
return fs.existsSync(file) && (!fs.statSync(file).isDirectory() || fs.readdirSync(file).length > 0);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function initializeProductData(dataPath) {
|
|
13
|
-
const marker = path.join(dataPath, 'product-data.json');
|
|
14
|
-
if (fs.existsSync(marker)) {
|
|
15
|
-
const value = AtomicFile.readJsonStrict(marker);
|
|
16
|
-
if (value.schema !== DATA_SCHEMA) throw new DomainError('SCHEMA_UNSUPPORTED', '数据目录格式不受支持,请使用新的空目录重新导入项目。', { status: 409 });
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// Old registries and unfinished claims must never become fresh product work.
|
|
20
|
-
const oldData = ['settings.json', 'projects.json', 'projects', 'knowledge-engine', 'workbench', 'vectorhub', 'events', 'knowledge-store.json', 'ai-profiles.json', 'embedding-config.json']
|
|
21
|
-
.filter(name => hasData(path.join(dataPath, name)));
|
|
22
|
-
const runtimePath = path.join(dataPath, 'runtime');
|
|
23
|
-
if (fs.existsSync(runtimePath)) {
|
|
24
|
-
if (!fs.statSync(runtimePath).isDirectory()) oldData.push('runtime');
|
|
25
|
-
else for (const name of fs.readdirSync(runtimePath)) {
|
|
26
|
-
// Unregistered legacy chat records cannot be resumed by a fresh registry.
|
|
27
|
-
// They are neither knowledge nor pending maintenance, and stay untouched.
|
|
28
|
-
if (name !== 'claude-sessions' && hasData(path.join(runtimePath, name))) oldData.push(`runtime/${name}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (oldData.length) throw new DomainError('SCHEMA_UNSUPPORTED', `数据目录 ${dataPath} 包含旧版业务数据(${oldData.join('、')})。新版不会迁移或删除它们;请将 KB_DATA_DIR 指向新的空目录,然后重新导入项目。`, { status: 409, details: { dataPath, entries: oldData } });
|
|
32
|
-
AtomicFile.writeJsonAtomic(marker, { schema: DATA_SCHEMA, createdAt: new Date().toISOString() });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = { initializeProductData, DATA_SCHEMA };
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const AtomicFile = require('./atomic-file');
|
|
4
|
+
const { DomainError } = require('./contracts');
|
|
5
|
+
|
|
6
|
+
const DATA_SCHEMA = 'project-knowledge/fresh-product-data/v1';
|
|
7
|
+
|
|
8
|
+
function hasData(file) {
|
|
9
|
+
return fs.existsSync(file) && (!fs.statSync(file).isDirectory() || fs.readdirSync(file).length > 0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function initializeProductData(dataPath) {
|
|
13
|
+
const marker = path.join(dataPath, 'product-data.json');
|
|
14
|
+
if (fs.existsSync(marker)) {
|
|
15
|
+
const value = AtomicFile.readJsonStrict(marker);
|
|
16
|
+
if (value.schema !== DATA_SCHEMA) throw new DomainError('SCHEMA_UNSUPPORTED', '数据目录格式不受支持,请使用新的空目录重新导入项目。', { status: 409 });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Old registries and unfinished claims must never become fresh product work.
|
|
20
|
+
const oldData = ['settings.json', 'projects.json', 'projects', 'knowledge-engine', 'workbench', 'vectorhub', 'events', 'knowledge-store.json', 'ai-profiles.json', 'embedding-config.json']
|
|
21
|
+
.filter(name => hasData(path.join(dataPath, name)));
|
|
22
|
+
const runtimePath = path.join(dataPath, 'runtime');
|
|
23
|
+
if (fs.existsSync(runtimePath)) {
|
|
24
|
+
if (!fs.statSync(runtimePath).isDirectory()) oldData.push('runtime');
|
|
25
|
+
else for (const name of fs.readdirSync(runtimePath)) {
|
|
26
|
+
// Unregistered legacy chat records cannot be resumed by a fresh registry.
|
|
27
|
+
// They are neither knowledge nor pending maintenance, and stay untouched.
|
|
28
|
+
if (name !== 'claude-sessions' && hasData(path.join(runtimePath, name))) oldData.push(`runtime/${name}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (oldData.length) throw new DomainError('SCHEMA_UNSUPPORTED', `数据目录 ${dataPath} 包含旧版业务数据(${oldData.join('、')})。新版不会迁移或删除它们;请将 KB_DATA_DIR 指向新的空目录,然后重新导入项目。`, { status: 409, details: { dataPath, entries: oldData } });
|
|
32
|
+
AtomicFile.writeJsonAtomic(marker, { schema: DATA_SCHEMA, createdAt: new Date().toISOString() });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { initializeProductData, DATA_SCHEMA };
|
|
@@ -73,20 +73,20 @@ class ProjectLifecycleService {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// Check 2: git repository or can be initialized.
|
|
76
|
-
let repoInspection = null;
|
|
77
|
-
let plannedGitInit = false;
|
|
78
|
-
if (checks.path.ok) {
|
|
79
|
-
const inside = runGit(localPath, ['rev-parse', '--is-inside-work-tree'], { allowFailure: true });
|
|
80
|
-
const top = inside.ok ? runGit(localPath, ['rev-parse', '--show-toplevel'], { allowFailure: true }) : null;
|
|
81
|
-
// A folder merely nested below another repository is not itself an
|
|
82
|
-
// importable Git project. This matters on CI workspaces and prevents a
|
|
83
|
-
// selected plain folder from silently inheriting its parent's history.
|
|
84
|
-
const isRepoRoot = Boolean(top && top.ok && path.resolve(top.stdout) === path.resolve(localPath));
|
|
85
|
-
if (!inside.ok || !isRepoRoot) {
|
|
86
|
-
plannedGitInit = true;
|
|
87
|
-
checks.git = { ok: false, status: 'non-git', plannedInit: true, message: 'Directory is not a Git repository. Import will run `git init` before proceeding.' };
|
|
88
|
-
} else {
|
|
89
|
-
const head = runGit(localPath, ['rev-parse', '--verify', 'HEAD'], { allowFailure: true });
|
|
76
|
+
let repoInspection = null;
|
|
77
|
+
let plannedGitInit = false;
|
|
78
|
+
if (checks.path.ok) {
|
|
79
|
+
const inside = runGit(localPath, ['rev-parse', '--is-inside-work-tree'], { allowFailure: true });
|
|
80
|
+
const top = inside.ok ? runGit(localPath, ['rev-parse', '--show-toplevel'], { allowFailure: true }) : null;
|
|
81
|
+
// A folder merely nested below another repository is not itself an
|
|
82
|
+
// importable Git project. This matters on CI workspaces and prevents a
|
|
83
|
+
// selected plain folder from silently inheriting its parent's history.
|
|
84
|
+
const isRepoRoot = Boolean(top && top.ok && path.resolve(top.stdout) === path.resolve(localPath));
|
|
85
|
+
if (!inside.ok || !isRepoRoot) {
|
|
86
|
+
plannedGitInit = true;
|
|
87
|
+
checks.git = { ok: false, status: 'non-git', plannedInit: true, message: 'Directory is not a Git repository. Import will run `git init` before proceeding.' };
|
|
88
|
+
} else {
|
|
89
|
+
const head = runGit(localPath, ['rev-parse', '--verify', 'HEAD'], { allowFailure: true });
|
|
90
90
|
const commonDir = runGit(localPath, ['rev-parse', '--git-common-dir']);
|
|
91
91
|
const branch = runGit(localPath, ['branch', '--show-current'], { allowFailure: true });
|
|
92
92
|
repoInspection = {
|
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
const { SCHEMAS, DomainError, validateProjectId } = require('./contracts');
|
|
2
|
-
const AtomicFile = require('./atomic-file');
|
|
3
|
-
const { StorageLayout } = require('./storage-layout');
|
|
4
|
-
|
|
5
|
-
function emptyRegistry() {
|
|
6
|
-
return {
|
|
7
|
-
schema: SCHEMAS.projectRegistry,
|
|
8
|
-
schemaVersion: 2,
|
|
9
|
-
projectOrder: [],
|
|
10
|
-
projects: {},
|
|
11
|
-
revision: 0,
|
|
12
|
-
updatedAt: '',
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function validateRegistry(registry) {
|
|
17
|
-
if (!registry || typeof registry !== 'object' || Array.isArray(registry)) {
|
|
18
|
-
throw new DomainError('DATA_CORRUPT', 'Project registry must be an object.', { status: 500 });
|
|
19
|
-
}
|
|
20
|
-
if (registry.schema !== SCHEMAS.projectRegistry || registry.schemaVersion !== 2) {
|
|
21
|
-
throw new DomainError('SCHEMA_UNSUPPORTED', 'Unsupported project registry schema.', { status: 409 });
|
|
22
|
-
}
|
|
23
|
-
if (!Array.isArray(registry.projectOrder) || !registry.projects || typeof registry.projects !== 'object') {
|
|
24
|
-
throw new DomainError('DATA_CORRUPT', 'Project registry index is invalid.', { status: 500 });
|
|
25
|
-
}
|
|
26
|
-
const ordered = new Set();
|
|
27
|
-
for (const projectId of registry.projectOrder) {
|
|
28
|
-
validateProjectId(projectId);
|
|
29
|
-
if (ordered.has(projectId) || !registry.projects[projectId]) {
|
|
30
|
-
throw new DomainError('DATA_CORRUPT', 'Project registry order is inconsistent.', { status: 500 });
|
|
31
|
-
}
|
|
32
|
-
ordered.add(projectId);
|
|
33
|
-
}
|
|
34
|
-
for (const projectId of Object.keys(registry.projects)) {
|
|
35
|
-
validateProjectId(projectId);
|
|
36
|
-
if (!ordered.has(projectId)) throw new DomainError('DATA_CORRUPT', 'Project registry contains an unordered project.', { status: 500 });
|
|
37
|
-
}
|
|
38
|
-
return registry;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class ProjectRegistryStore {
|
|
42
|
-
constructor(options = {}) {
|
|
43
|
-
this.layout = options.layout || new StorageLayout(options);
|
|
44
|
-
this.atomic = options.atomic || AtomicFile;
|
|
45
|
-
this.filePath = options.filePath || this.layout.getProjectRegistryPath();
|
|
46
|
-
this.lockPath = options.lockPath || this.layout.getRegistryLockPath();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
read(options = {}) {
|
|
50
|
-
return this.atomic.readJsonStrict(this.filePath, {
|
|
51
|
-
allowMissing: options.allowMissing === true,
|
|
52
|
-
defaultValue: emptyRegistry(),
|
|
53
|
-
category: 'project-registry',
|
|
54
|
-
validate: validateRegistry,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async initialize() {
|
|
59
|
-
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
60
|
-
let existing;
|
|
61
|
-
try { existing = this.read(); } catch (error) { if (!error || error.code !== 'ENOENT') throw error; }
|
|
62
|
-
if (existing) return existing;
|
|
63
|
-
const registry = emptyRegistry();
|
|
64
|
-
registry.updatedAt = new Date().toISOString();
|
|
65
|
-
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
66
|
-
return registry;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
listIds() { return [...this.read({ allowMissing: true }).projectOrder]; }
|
|
71
|
-
|
|
72
|
-
readDisplaySnapshot(projectId) {
|
|
73
|
-
validateProjectId(projectId);
|
|
74
|
-
const registry = this.read({ allowMissing: true });
|
|
75
|
-
return registry.projects[projectId] || null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async add(projectId, snapshot = {}) {
|
|
79
|
-
validateProjectId(projectId);
|
|
80
|
-
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
81
|
-
const registry = this.read({ allowMissing: true });
|
|
82
|
-
if (registry.projects[projectId]) {
|
|
83
|
-
throw new DomainError('INVALID_ARGUMENT', 'Project is already registered.', { status: 409 });
|
|
84
|
-
}
|
|
85
|
-
registry.projects[projectId] = {
|
|
86
|
-
createdAt: String(snapshot.createdAt || new Date().toISOString()),
|
|
87
|
-
displayNameSnapshot: String(snapshot.displayNameSnapshot || snapshot.displayName || projectId),
|
|
88
|
-
};
|
|
89
|
-
registry.projectOrder.push(projectId);
|
|
90
|
-
registry.revision = Number(registry.revision || 0) + 1;
|
|
91
|
-
registry.updatedAt = new Date().toISOString();
|
|
92
|
-
validateRegistry(registry);
|
|
93
|
-
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
94
|
-
return registry.projects[projectId];
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async remove(projectId) {
|
|
99
|
-
validateProjectId(projectId);
|
|
100
|
-
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
101
|
-
const registry = this.read({ allowMissing: true });
|
|
102
|
-
if (!registry.projects[projectId]) return false;
|
|
103
|
-
delete registry.projects[projectId];
|
|
104
|
-
registry.projectOrder = registry.projectOrder.filter(id => id !== projectId);
|
|
105
|
-
registry.revision = Number(registry.revision || 0) + 1;
|
|
106
|
-
registry.updatedAt = new Date().toISOString();
|
|
107
|
-
validateRegistry(registry);
|
|
108
|
-
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
109
|
-
return true;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async reorder(projectIds) {
|
|
114
|
-
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
115
|
-
const registry = this.read({ allowMissing: true });
|
|
116
|
-
const next = Array.isArray(projectIds) ? projectIds.map(validateProjectId) : [];
|
|
117
|
-
if (next.length !== registry.projectOrder.length || new Set(next).size !== next.length || next.some(id => !registry.projects[id])) {
|
|
118
|
-
throw new DomainError('INVALID_ARGUMENT', 'Reorder must contain every registered project exactly once.');
|
|
119
|
-
}
|
|
120
|
-
registry.projectOrder = next;
|
|
121
|
-
registry.revision = Number(registry.revision || 0) + 1;
|
|
122
|
-
registry.updatedAt = new Date().toISOString();
|
|
123
|
-
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
124
|
-
return [...next];
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
module.exports = { ProjectRegistryStore, emptyRegistry, validateRegistry };
|
|
1
|
+
const { SCHEMAS, DomainError, validateProjectId } = require('./contracts');
|
|
2
|
+
const AtomicFile = require('./atomic-file');
|
|
3
|
+
const { StorageLayout } = require('./storage-layout');
|
|
4
|
+
|
|
5
|
+
function emptyRegistry() {
|
|
6
|
+
return {
|
|
7
|
+
schema: SCHEMAS.projectRegistry,
|
|
8
|
+
schemaVersion: 2,
|
|
9
|
+
projectOrder: [],
|
|
10
|
+
projects: {},
|
|
11
|
+
revision: 0,
|
|
12
|
+
updatedAt: '',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function validateRegistry(registry) {
|
|
17
|
+
if (!registry || typeof registry !== 'object' || Array.isArray(registry)) {
|
|
18
|
+
throw new DomainError('DATA_CORRUPT', 'Project registry must be an object.', { status: 500 });
|
|
19
|
+
}
|
|
20
|
+
if (registry.schema !== SCHEMAS.projectRegistry || registry.schemaVersion !== 2) {
|
|
21
|
+
throw new DomainError('SCHEMA_UNSUPPORTED', 'Unsupported project registry schema.', { status: 409 });
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(registry.projectOrder) || !registry.projects || typeof registry.projects !== 'object') {
|
|
24
|
+
throw new DomainError('DATA_CORRUPT', 'Project registry index is invalid.', { status: 500 });
|
|
25
|
+
}
|
|
26
|
+
const ordered = new Set();
|
|
27
|
+
for (const projectId of registry.projectOrder) {
|
|
28
|
+
validateProjectId(projectId);
|
|
29
|
+
if (ordered.has(projectId) || !registry.projects[projectId]) {
|
|
30
|
+
throw new DomainError('DATA_CORRUPT', 'Project registry order is inconsistent.', { status: 500 });
|
|
31
|
+
}
|
|
32
|
+
ordered.add(projectId);
|
|
33
|
+
}
|
|
34
|
+
for (const projectId of Object.keys(registry.projects)) {
|
|
35
|
+
validateProjectId(projectId);
|
|
36
|
+
if (!ordered.has(projectId)) throw new DomainError('DATA_CORRUPT', 'Project registry contains an unordered project.', { status: 500 });
|
|
37
|
+
}
|
|
38
|
+
return registry;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class ProjectRegistryStore {
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.layout = options.layout || new StorageLayout(options);
|
|
44
|
+
this.atomic = options.atomic || AtomicFile;
|
|
45
|
+
this.filePath = options.filePath || this.layout.getProjectRegistryPath();
|
|
46
|
+
this.lockPath = options.lockPath || this.layout.getRegistryLockPath();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
read(options = {}) {
|
|
50
|
+
return this.atomic.readJsonStrict(this.filePath, {
|
|
51
|
+
allowMissing: options.allowMissing === true,
|
|
52
|
+
defaultValue: emptyRegistry(),
|
|
53
|
+
category: 'project-registry',
|
|
54
|
+
validate: validateRegistry,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async initialize() {
|
|
59
|
+
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
60
|
+
let existing;
|
|
61
|
+
try { existing = this.read(); } catch (error) { if (!error || error.code !== 'ENOENT') throw error; }
|
|
62
|
+
if (existing) return existing;
|
|
63
|
+
const registry = emptyRegistry();
|
|
64
|
+
registry.updatedAt = new Date().toISOString();
|
|
65
|
+
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
66
|
+
return registry;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
listIds() { return [...this.read({ allowMissing: true }).projectOrder]; }
|
|
71
|
+
|
|
72
|
+
readDisplaySnapshot(projectId) {
|
|
73
|
+
validateProjectId(projectId);
|
|
74
|
+
const registry = this.read({ allowMissing: true });
|
|
75
|
+
return registry.projects[projectId] || null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async add(projectId, snapshot = {}) {
|
|
79
|
+
validateProjectId(projectId);
|
|
80
|
+
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
81
|
+
const registry = this.read({ allowMissing: true });
|
|
82
|
+
if (registry.projects[projectId]) {
|
|
83
|
+
throw new DomainError('INVALID_ARGUMENT', 'Project is already registered.', { status: 409 });
|
|
84
|
+
}
|
|
85
|
+
registry.projects[projectId] = {
|
|
86
|
+
createdAt: String(snapshot.createdAt || new Date().toISOString()),
|
|
87
|
+
displayNameSnapshot: String(snapshot.displayNameSnapshot || snapshot.displayName || projectId),
|
|
88
|
+
};
|
|
89
|
+
registry.projectOrder.push(projectId);
|
|
90
|
+
registry.revision = Number(registry.revision || 0) + 1;
|
|
91
|
+
registry.updatedAt = new Date().toISOString();
|
|
92
|
+
validateRegistry(registry);
|
|
93
|
+
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
94
|
+
return registry.projects[projectId];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async remove(projectId) {
|
|
99
|
+
validateProjectId(projectId);
|
|
100
|
+
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
101
|
+
const registry = this.read({ allowMissing: true });
|
|
102
|
+
if (!registry.projects[projectId]) return false;
|
|
103
|
+
delete registry.projects[projectId];
|
|
104
|
+
registry.projectOrder = registry.projectOrder.filter(id => id !== projectId);
|
|
105
|
+
registry.revision = Number(registry.revision || 0) + 1;
|
|
106
|
+
registry.updatedAt = new Date().toISOString();
|
|
107
|
+
validateRegistry(registry);
|
|
108
|
+
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async reorder(projectIds) {
|
|
114
|
+
return this.atomic.withFileLock(this.lockPath, async () => {
|
|
115
|
+
const registry = this.read({ allowMissing: true });
|
|
116
|
+
const next = Array.isArray(projectIds) ? projectIds.map(validateProjectId) : [];
|
|
117
|
+
if (next.length !== registry.projectOrder.length || new Set(next).size !== next.length || next.some(id => !registry.projects[id])) {
|
|
118
|
+
throw new DomainError('INVALID_ARGUMENT', 'Reorder must contain every registered project exactly once.');
|
|
119
|
+
}
|
|
120
|
+
registry.projectOrder = next;
|
|
121
|
+
registry.revision = Number(registry.revision || 0) + 1;
|
|
122
|
+
registry.updatedAt = new Date().toISOString();
|
|
123
|
+
this.atomic.writeJsonAtomic(this.filePath, registry);
|
|
124
|
+
return [...next];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { ProjectRegistryStore, emptyRegistry, validateRegistry };
|